More gtk removals and Onepad dialog tweaks (#3525)

* Improve secondary dialogs in Onepad. I'll do gtk stuff in this branch, too, I promise...

* More fiddling with onepad's secondary dialogs.

* Rework config.inl to use wx, getting the rest of the null plugins.

* Remove some unnecessary includes, and convert SysMessage to wx in onepad.

* Add in tellowkrinkle's Mac OS fixes.
This commit is contained in:
arcum42 2020-07-19 19:11:42 -07:00 committed by GitHub
parent b00c603e0b
commit e42b9ce110
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 213 additions and 488 deletions

View File

@ -1,142 +0,0 @@
/* PCSX2 - PS2 Emulator for PCs
* Copyright (C) 2002-2010 PCSX2 Dev Team
*
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with PCSX2.
* If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
// ----------------------------------------------------------------------------
// gtkGuiTools.h
//
// This file is meant to contain utility classes for users of GTK, for purposes
// of GTK 2/3 compatibility, and other helpful routines to help avoid repeatedly
// implementing the same code.
//
// ----------------------------------------------------------------------------
#include <gtk/gtk.h>
#include <cstring>
// They've gotten rid of the GtkHBox and GtkVBox in GTK3 in favor of using the
// more general GtkBox and supplying an orientation. While this is probably a
// move in the right direction, for compatability, it's easier to define our
// own hbox and vbox routines that invoke the old or the new version, depending
// on what it's built for.
//
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-function"
#endif
static GtkWidget *ps_gtk_hbox_new(int padding = 5)
{
#if GTK_MAJOR_VERSION < 3
return gtk_hbox_new(false, padding);
#else
return gtk_box_new(GTK_ORIENTATION_HORIZONTAL, padding);
#endif
}
static GtkWidget *ps_gtk_vbox_new(int padding = 5)
{
#if GTK_MAJOR_VERSION < 3
return gtk_vbox_new(false, padding);
#else
return gtk_box_new(GTK_ORIENTATION_VERTICAL, padding);
#endif
}
// Similarly, GtkHScale and GtkVScale make way for GtkScale.
static GtkWidget *ps_gtk_hscale_new_with_range(double g_min, double g_max, int g_step = 5)
{
#if GTK_MAJOR_VERSION < 3
return gtk_hscale_new_with_range(g_min, g_max, g_step);
#else
return gtk_scale_new_with_range(GTK_ORIENTATION_HORIZONTAL, g_min, g_max, g_step);
#endif
}
static GtkWidget *ps_gtk_vscale_new_with_range(double g_min, double g_max, int g_step = 5)
{
#if GTK_MAJOR_VERSION < 3
return gtk_vscale_new_with_range(g_min, g_max, g_step);
#else
return gtk_scale_new_with_range(GTK_ORIENTATION_VERTICAL, g_min, g_max, g_step);
#endif
}
// And so on and so forth...
static GtkWidget *ps_gtk_hseparator_new()
{
#if GTK_MAJOR_VERSION < 3
return gtk_hseparator_new();
#else
return gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
#endif
}
static GtkWidget *ps_gtk_vseparator_new()
{
#if GTK_MAJOR_VERSION < 3
return gtk_vseparator_new();
#else
return gtk_separator_new(GTK_ORIENTATION_VERTICAL);
#endif
}
// These two routines have been rewritten over and over. May as well include a copy.
// Renaming so as not to interfere with existing versions.
static void pcsx2_message(const char *fmt, ...)
{
va_list list;
char msg[512];
va_start(list, fmt);
vsprintf(msg, fmt, list);
va_end(list);
if (msg[strlen(msg) - 1] == '\n')
msg[strlen(msg) - 1] = 0;
GtkWidget *dialog;
dialog = gtk_message_dialog_new(NULL,
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_INFO,
GTK_BUTTONS_OK,
"%s", msg);
gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
}
static void pcsx2_message(const wchar_t *fmt, ...)
{
va_list list;
va_start(list, fmt);
wxString msg;
msg.PrintfV(fmt, list);
va_end(list);
GtkWidget *dialog;
dialog = gtk_message_dialog_new(NULL,
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_INFO,
GTK_BUTTONS_OK,
"%s", msg.ToUTF8().data());
gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
}
#ifdef __clang__
#pragma clang diagnostic pop
#endif

View File

@ -17,8 +17,8 @@
#if defined(_WIN32)
#include <windows.h>
#include "resource.h"
#elif defined(__unix__)
#include <gtk/gtk.h>
#elif defined(__unix__) || defined(__APPLE__)
#include <wx/wx.h>
#endif
#include <string>
@ -65,33 +65,33 @@ void ConfigureLogging()
DialogBox(s_hinstance, MAKEINTRESOURCE(IDD_DIALOG), GetActiveWindow(), ConfigureDialogProc);
}
#elif defined(__unix__)
#elif defined(__unix__) || defined(__APPLE__)
void ConfigureLogging()
{
GtkDialogFlags flags = static_cast<GtkDialogFlags>(GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT);
GtkWidget *dialog = gtk_dialog_new_with_buttons("Config", nullptr, flags,
"Cancel", GTK_RESPONSE_REJECT,
"Ok", GTK_RESPONSE_ACCEPT,
nullptr);
auto *dialog = new wxDialog;
dialog->Create(nullptr, wxID_ANY, "Config", wxDefaultPosition, wxDefaultSize, wxCAPTION | wxCLOSE_BOX);
GtkWidget *console_checkbox = gtk_check_button_new_with_label("Log to console");
GtkWidget *file_checkbox = gtk_check_button_new_with_label("Log to file");
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(console_checkbox), g_plugin_log.WriteToConsole);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(file_checkbox), g_plugin_log.WriteToFile);
auto *main_sizer = new wxBoxSizer(wxVERTICAL);
auto *sizer = dialog->CreateButtonSizer(wxOK | wxCANCEL);
GtkWidget *content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
gtk_container_add(GTK_CONTAINER(content_area), console_checkbox);
gtk_container_add(GTK_CONTAINER(content_area), file_checkbox);
auto *log_check = new wxCheckBox(dialog, wxID_ANY, "Log to Console");
auto *file_check = new wxCheckBox(dialog, wxID_ANY, "Log to File");
log_check->SetValue(g_plugin_log.WriteToConsole);
file_check->SetValue(g_plugin_log.WriteToFile);
gtk_widget_show_all(dialog);
main_sizer->Add(log_check);
main_sizer->Add(file_check);
main_sizer->Add(sizer);
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
g_plugin_log.WriteToConsole = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(console_checkbox)) == TRUE;
g_plugin_log.WriteToFile = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(file_checkbox)) == TRUE;
dialog->SetSizerAndFit(main_sizer);
if ( dialog->ShowModal() == wxID_OK )
{
g_plugin_log.WriteToConsole = log_check->GetValue();
g_plugin_log.WriteToFile = file_check->GetValue();
}
gtk_widget_destroy(dialog);
wxDELETE(dialog);
}
#else

View File

@ -56,7 +56,6 @@ set(UtilitiesHeaders
../../include/Utilities/EventSource.h
../../include/Utilities/Exceptions.h
../../include/Utilities/FixedPointTypes.h
../../include/Utilities/gtkGuiTools.h
../../include/Utilities/General.h
../../include/Utilities/MakeUnique.h
../../include/Utilities/MemcpyFast.h

View File

@ -48,7 +48,7 @@ set(FWnullFinalSources
)
set(FWnullFinalLibs
${GTK2_LIBRARIES}
${wxWidgets_LIBRARIES}
)
if(BUILTIN_FW)

View File

@ -45,9 +45,6 @@ static HRESULT s_hr = E_FAIL;
#include "Window/GSWndOGL.h"
#include "Window/GSWndEGL.h"
#include <gtk/gtk.h>
#include <gdk/gdkx.h>
extern bool RunLinuxDialog();
#endif

View File

@ -49,6 +49,7 @@ set(USBnullFinalSources
set(USBnullFinalLibs
${GTK2_LIBRARIES}
${wxWidgets_LIBRARIES}
)
if(BUILTIN_USB)

View File

@ -38,8 +38,6 @@
#else
#include <gtk/gtk.h>
#define __inline inline
#endif

View File

@ -47,7 +47,7 @@ set(dev9nullFinalSources
)
set(dev9nullFinalLibs
${GTK2_LIBRARIES}
${wxWidgets_LIBRARIES}
)
if(BUILTIN_DEV9)

View File

@ -28,7 +28,6 @@
extern const unsigned char version;
extern const unsigned char revision;
extern const unsigned char build;
extern const unsigned int minor;
extern void (*DEV9irq)(int);

View File

@ -25,7 +25,6 @@
#include "state_management.h"
#include <string.h>
#include <gtk/gtk.h>
#include "wx_dialog/dialog.h"
#ifndef __APPLE__
@ -33,7 +32,7 @@ Display *GSdsp;
Window GSwin;
#endif
void SysMessage(const char *fmt, ...)
static void SysMessage(const char *fmt, ...)
{
va_list list;
char msg[512];
@ -45,14 +44,8 @@ void SysMessage(const char *fmt, ...)
if (msg[strlen(msg) - 1] == '\n')
msg[strlen(msg) - 1] = 0;
GtkWidget *dialog;
dialog = gtk_message_dialog_new(NULL,
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_INFO,
GTK_BUTTONS_OK,
"%s", msg);
gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
wxMessageDialog dialog(nullptr, msg, "Info", wxOK);
dialog.ShowModal();
}
EXPORT_C_(void)

View File

@ -19,100 +19,49 @@
#include "GamepadConfiguration.h"
// Construtor of GamepadConfiguration
GamepadConfiguration::GamepadConfiguration(int pad, wxWindow *parent)
: wxDialog(
parent, // Parent
wxID_ANY, // ID
_T("Gamepad configuration"), // Title
wxDefaultPosition, // Position
wxSize(400, 270), // Width + Length
// Style
wxSYSTEM_MENU |
wxCAPTION |
wxCLOSE_BOX |
wxCLIP_CHILDREN)
: wxDialog(parent, wxID_ANY, _T("Gamepad"), wxDefaultPosition, wxDefaultSize,
wxSYSTEM_MENU | wxCAPTION | wxCLOSE_BOX | wxCLIP_CHILDREN)
{
m_pad_id = pad;
m_pan_gamepad_config = new wxPanel(
this, // Parent
wxID_ANY, // ID
wxDefaultPosition, // Position
wxSize(300, 230) // Size
);
m_cb_rumble = new wxCheckBox(
m_pan_gamepad_config, // Parent
wxID_ANY, // ID
_T("&Enable rumble"), // Label
wxPoint(20, 20) // Position
);
wxBoxSizer *gamepad_box = new wxBoxSizer(wxVERTICAL);
wxArrayString choices;
for (const auto &j : s_vgamePad) {
choices.Add(j->GetName());
}
m_joy_map = new wxChoice(
m_pan_gamepad_config, // Parent
wxID_ANY, // ID
wxPoint(20, 50), // Position
wxDefaultSize, // Size
choices);
wxString txt_rumble = wxT("Rumble intensity");
m_lbl_rumble_intensity = new wxStaticText(
m_pan_gamepad_config, // Parent
wxID_ANY, // ID
txt_rumble, // Text which must be displayed
wxPoint(20, 90), // Position
wxDefaultSize // Size
);
m_joy_map = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, choices);
m_cb_rumble = new wxCheckBox(this, enable_rumble_id, _T("&Enable rumble"));
m_sl_rumble_intensity = new wxSlider(
m_pan_gamepad_config, // Parent
wxID_ANY, // ID
0, // value
0, // min value 0x0000
0x7FFF, // max value 0x7FFF
wxPoint(150, 83), // Position
wxSize(200, 50), // Size
wxSL_HORIZONTAL | wxSL_LABELS | wxSL_BOTTOM
);
wxStaticBoxSizer *rumble_box = new wxStaticBoxSizer(wxVERTICAL, this, wxT("Rumble intensity"));
m_sl_rumble_intensity = new wxSlider(this, rumble_slider_id, 0, 0, 0x7FFF, wxDefaultPosition, wxDefaultSize,
wxSL_HORIZONTAL | wxSL_LABELS | wxSL_BOTTOM);
wxString txt_joystick = wxT("Joystick sensibility");
m_lbl_rumble_intensity = new wxStaticText(
m_pan_gamepad_config, // Parent
wxID_ANY, // ID
txt_joystick, // Text which must be displayed
wxPoint(20, 150), // Position
wxDefaultSize // Size
);
wxStaticBoxSizer *joy_box = new wxStaticBoxSizer(wxVERTICAL, this, wxT("Joystick sensibility"));
m_sl_joystick_sensibility = new wxSlider(this, joy_slider_id, 0, 0, 200, wxDefaultPosition, wxDefaultSize,
wxSL_HORIZONTAL | wxSL_LABELS | wxSL_BOTTOM);
m_sl_joystick_sensibility = new wxSlider(
m_pan_gamepad_config, // Parent
wxID_ANY, // ID
0, // value
0, // min value
200, // max value
wxPoint(150, 143), // Position
wxSize(200, 50), // Size
wxSL_HORIZONTAL | wxSL_LABELS | wxSL_BOTTOM
);
gamepad_box->Add(m_joy_map, wxSizerFlags().Expand().Border(wxALL, 5));
gamepad_box->Add(m_cb_rumble, wxSizerFlags().Expand());
m_bt_ok = new wxButton(
m_pan_gamepad_config, // Parent
wxID_ANY, // ID
_T("&OK"), // Label
wxPoint(320, 210), // Position
wxSize(60, 25) // Size
);
rumble_box->Add(m_sl_rumble_intensity, wxSizerFlags().Expand().Border(wxALL, 5));
joy_box->Add(m_sl_joystick_sensibility, wxSizerFlags().Expand().Border(wxALL, 5));
Bind(wxEVT_BUTTON, &GamepadConfiguration::OnButtonClicked, this);
gamepad_box->Add(rumble_box, wxSizerFlags().Expand().Border(wxALL, 5));
gamepad_box->Add(joy_box, wxSizerFlags().Expand().Border(wxALL, 5));
gamepad_box->Add(CreateSeparatedButtonSizer(wxOK), wxSizerFlags().Right().Border(wxALL, 5));
Bind(wxEVT_BUTTON, &GamepadConfiguration::OnOk, this, wxID_OK);
Bind(wxEVT_SCROLL_THUMBRELEASE, &GamepadConfiguration::OnSliderReleased, this);
Bind(wxEVT_CHECKBOX, &GamepadConfiguration::OnCheckboxChange, this);
Bind(wxEVT_CHOICE, &GamepadConfiguration::OnChoiceChange, this);
repopulate();
SetSizerAndFit(gamepad_box);
}
/**
@ -126,7 +75,7 @@ void GamepadConfiguration::InitGamepadConfiguration()
/*
* Check if there exist at least one pad available
* if the pad id is 0, you need at least 1 gamepad connected,
* if the pad id is 1, you need at least 2 gamepad connected,
* if the pad id is 1, you need at least 2 gamepads connected,
* Prevent to use a none initialized value on s_vgamePad (core dump)
*/
if (s_vgamePad.size() >= m_pad_id + 1) {
@ -150,21 +99,9 @@ void GamepadConfiguration::InitGamepadConfiguration()
}
}
/****************************************/
/*********** Events functions ***********/
/****************************************/
/**
* Button event, called when a button is clicked
*/
void GamepadConfiguration::OnButtonClicked(wxCommandEvent &event)
void GamepadConfiguration::OnOk(wxCommandEvent &event)
{
// Affichage d'un message à chaque clic sur le bouton
wxButton *bt_tmp = (wxButton *)event.GetEventObject(); // get the button object
int bt_id = bt_tmp->GetId(); // get the real ID
if (bt_id == m_bt_ok->GetId()) { // If the button ID is equals to the Ok button ID
Close(); // Close the window
}
Destroy();
}
/**
@ -174,28 +111,20 @@ void GamepadConfiguration::OnButtonClicked(wxCommandEvent &event)
*/
void GamepadConfiguration::OnSliderReleased(wxCommandEvent &event)
{
wxSlider *sl_tmp = (wxSlider *)event.GetEventObject(); // get the slider object
int sl_id = sl_tmp->GetId(); // slider id
if (sl_id == m_sl_rumble_intensity->GetId()) { // if this is the rumble intensity slider
u32 intensity = m_sl_rumble_intensity->GetValue(); // get the new value
g_conf.set_ff_intensity(intensity); // and set the force feedback intensity value with it
// get the rumble intensity
float strength = m_sl_rumble_intensity->GetValue();
/*
* convert in a float value between 0 and 1, and run rumble feedback
* 1 -> 0x7FFF
* 0 -> 0x0000
* x -> ?
*
* formula : strength = x*1/0x7FFF
* x : intensity variable
* 0x7FFF : maximum intensity
* 1 : maximum value of the intensity for the sdl rumble test
*/
s_vgamePad[m_pad_id]->TestForce(strength / 0x7FFF);
} else if (sl_id == m_sl_joystick_sensibility->GetId()) {
u32 sensibility = m_sl_joystick_sensibility->GetValue(); // get the new value
g_conf.set_sensibility(sensibility); // and set the joystick sensibility
wxSlider *sl_tmp = (wxSlider *)event.GetEventObject();
int sl_id = sl_tmp->GetId();
if (sl_id == rumble_slider_id)
{
g_conf.set_ff_intensity(m_sl_rumble_intensity->GetValue());
// convert in a float value between 0 and 1, and run rumble feedback.
// 0 to 1 scales to 0x0 to 0x7FFF
s_vgamePad[m_pad_id]->TestForce(m_sl_rumble_intensity->GetValue() / 0x7FFF);
}
else if (sl_id == joy_slider_id)
{
g_conf.set_sensibility(m_sl_joystick_sensibility->GetValue());
}
}
@ -206,12 +135,17 @@ void GamepadConfiguration::OnCheckboxChange(wxCommandEvent &event)
{
wxCheckBox *cb_tmp = (wxCheckBox *)event.GetEventObject(); // get the slider object
int cb_id = cb_tmp->GetId();
if (cb_id == m_cb_rumble->GetId()) {
if (cb_id == enable_rumble_id)
{
g_conf.pad_options[m_pad_id].forcefeedback = (m_cb_rumble->GetValue()) ? (u32)1 : (u32)0;
if (m_cb_rumble->GetValue()) {
if (m_cb_rumble->GetValue())
{
s_vgamePad[m_pad_id]->TestForce();
m_sl_rumble_intensity->Enable();
} else {
}
else
{
m_sl_rumble_intensity->Disable();
}
}
@ -224,9 +158,9 @@ void GamepadConfiguration::OnChoiceChange(wxCommandEvent &event)
{
wxChoice *choice_tmp = (wxChoice *)event.GetEventObject();
int id = choice_tmp->GetSelection();
if (id != wxNOT_FOUND) {
size_t uid = GamePad::index_to_uid(id);
g_conf.set_joy_uid(m_pad_id, uid);
if (id != wxNOT_FOUND)
{
g_conf.set_joy_uid(m_pad_id, GamePad::index_to_uid(id));
}
}
@ -237,22 +171,15 @@ void GamepadConfiguration::OnChoiceChange(wxCommandEvent &event)
// Set button values
void GamepadConfiguration::repopulate()
{
bool val = g_conf.pad_options[m_pad_id].forcefeedback;
m_cb_rumble->SetValue(val);
m_cb_rumble->SetValue(g_conf.pad_options[m_pad_id].forcefeedback);
int tmp = g_conf.get_ff_intensity();
m_sl_rumble_intensity->SetValue(tmp);
tmp = g_conf.get_sensibility();
m_sl_joystick_sensibility->SetValue(tmp);
m_sl_rumble_intensity->SetValue(g_conf.get_ff_intensity());
m_sl_joystick_sensibility->SetValue(g_conf.get_sensibility());
u32 joyid = GamePad::uid_to_index(m_pad_id);
if (joyid < m_joy_map->GetCount() && !m_joy_map->IsEmpty())
m_joy_map->SetSelection(joyid);
// enable rumble intensity slider if the checkbox is checked
if (m_cb_rumble->GetValue())
m_sl_rumble_intensity->Enable();
else // disable otherwise
m_sl_rumble_intensity->Disable();
m_sl_rumble_intensity->Enable(m_cb_rumble->GetValue());
}

View File

@ -23,31 +23,28 @@
#define __GAMEPADCONFIGURATION_H__
#include <wx/wx.h>
#include <wx/frame.h>
#include <wx/window.h>
#include <wx/button.h>
#include <wx/checkbox.h>
#include <wx/slider.h>
#include "../GamePad.h"
#include "../keyboard.h"
#include "../onepad.h"
static const s32 rumble_slider_id = wxID_HIGHEST + 200 + 1;
static const s32 joy_slider_id = wxID_HIGHEST + 200 + 2;
static const s32 enable_rumble_id = wxID_HIGHEST + 200 + 3;
class GamepadConfiguration : public wxDialog
{
wxPanel *m_pan_gamepad_config;
wxCheckBox *m_cb_rumble;
wxSlider *m_sl_rumble_intensity, *m_sl_joystick_sensibility;
wxButton *m_bt_ok;
wxStaticText *m_lbl_rumble_intensity;
wxChoice *m_joy_map;
u32 m_pad_id;
// methods
// Methods
void repopulate();
// Events
void OnButtonClicked(wxCommandEvent &);
void OnOk(wxCommandEvent &);
void OnSliderReleased(wxCommandEvent &);
void OnCheckboxChange(wxCommandEvent &);
void OnChoiceChange(wxCommandEvent &);

View File

@ -19,106 +19,53 @@
#include "JoystickConfiguration.h"
// Construtor of JoystickConfiguration
// Constructor of JoystickConfiguration
JoystickConfiguration::JoystickConfiguration(int pad, bool left, wxWindow *parent)
: wxDialog(
parent, // Parent
wxID_ANY, // ID
_T("Gamepad configuration"), // Title
wxDefaultPosition, // Position
wxSize(400, 200), // Width + Lenght
// Style
wxSYSTEM_MENU |
wxCAPTION |
wxCLOSE_BOX |
wxCLIP_CHILDREN)
: wxDialog(parent, wxID_ANY, _T("Joystick configuration"), wxDefaultPosition, wxDefaultSize,
wxSYSTEM_MENU | wxCAPTION | wxCLOSE_BOX | wxCLIP_CHILDREN)
{
m_init_reverse_Lx = false;
m_init_reverse_Ly = false;
m_init_reverse_Rx = false;
m_init_reverse_Ry = false;
m_init_mouse_Ljoy = false;
m_init_mouse_Rjoy = false;
m_init_reverse_Lx = m_init_reverse_Ly =
m_init_reverse_Rx = m_init_reverse_Ry =
m_init_mouse_Ljoy = m_init_mouse_Rjoy = false;
m_pad_id = pad;
m_isForLeftJoystick = left;
m_pan_joystick_config = new wxPanel(
this, // Parent
wxID_ANY, // ID
wxDefaultPosition, // Prosition
wxSize(300, 200) // Size
);
if (m_isForLeftJoystick) {
m_cb_reverse_Lx = new wxCheckBox(
m_pan_joystick_config, // Parent
wxID_ANY, // ID
_T("Reverse Lx"), // Label
wxPoint(20, 20) // Position
);
wxBoxSizer *joy_conf_box = new wxBoxSizer(wxVERTICAL);
m_cb_reverse_Ly = new wxCheckBox(
m_pan_joystick_config, // Parent
wxID_ANY, // ID
_T("Reverse Ly"), // Label
wxPoint(20, 40) // Position
);
if (m_isForLeftJoystick)
{
m_cb_reverse_Lx = new wxCheckBox(this, Lx_check_id, _T("Reverse Lx"));
m_cb_reverse_Ly = new wxCheckBox(this, Ly_check_id, _T("Reverse Ly"));
m_cb_mouse_Ljoy = new wxCheckBox(this, Ljoy_check_id, _T("Use mouse for left analog joystick"));
m_cb_mouse_Ljoy = new wxCheckBox(
m_pan_joystick_config, // Parent
wxID_ANY, // ID
_T("Use mouse for left analog joystick"), // Label
wxPoint(20, 60) // Position
);
joy_conf_box->Add(m_cb_reverse_Lx, wxSizerFlags().Expand().Border(wxLEFT | wxRIGHT, 5));
joy_conf_box->Add(m_cb_reverse_Ly, wxSizerFlags().Expand().Border(wxLEFT | wxRIGHT, 5));
joy_conf_box->Add(m_cb_mouse_Ljoy, wxSizerFlags().Expand().Border(wxLEFT | wxRIGHT, 5));
m_cb_reverse_Rx = nullptr;
m_cb_reverse_Ry = nullptr;
m_cb_mouse_Rjoy = nullptr;
} else {
m_cb_reverse_Rx = new wxCheckBox(
m_pan_joystick_config, // Parent
wxID_ANY, // ID
_T("Reverse Rx"), // Label
wxPoint(20, 20) // Position
);
m_cb_reverse_Rx = m_cb_reverse_Ry = m_cb_mouse_Rjoy = nullptr;
m_cb_reverse_Ry = new wxCheckBox(
m_pan_joystick_config, // Parent
wxID_ANY, // ID
_T("Reverse Ry"), // Label
wxPoint(20, 40) // Position
);
}
else
{
m_cb_reverse_Rx = new wxCheckBox(this, Rx_check_id, _T("Reverse Rx"));
m_cb_reverse_Ry = new wxCheckBox(this, Ry_check_id, _T("Reverse Ry"));
m_cb_mouse_Rjoy = new wxCheckBox(this, Rjoy_check_id, _T("Use mouse for right analog joystick"));
m_cb_mouse_Rjoy = new wxCheckBox(
m_pan_joystick_config, // Parent
wxID_ANY, // ID
_T("Use mouse for right analog joystick"), // Label
wxPoint(20, 60) // Position
);
joy_conf_box->Add(m_cb_reverse_Rx, wxSizerFlags().Expand().Border(wxLEFT | wxRIGHT, 5));
joy_conf_box->Add(m_cb_reverse_Ry, wxSizerFlags().Expand().Border(wxLEFT | wxRIGHT, 5));
joy_conf_box->Add(m_cb_mouse_Rjoy, wxSizerFlags().Expand().Border(wxLEFT | wxRIGHT, 5));
m_cb_reverse_Lx = nullptr;
m_cb_reverse_Ly = nullptr;
m_cb_mouse_Ljoy = nullptr;
m_cb_reverse_Lx = m_cb_reverse_Ly = m_cb_mouse_Ljoy = nullptr;
}
m_bt_ok = new wxButton(
m_pan_joystick_config, // Parent
wxID_ANY, // ID
_T("&OK"), // Label
wxPoint(250, 130), // Position
wxSize(60, 25) // Size
);
joy_conf_box->Add(CreateSeparatedButtonSizer(wxOK | wxCANCEL), wxSizerFlags().Border(wxALL, 5).Right());
m_bt_cancel = new wxButton(
m_pan_joystick_config, // Parent
wxID_ANY, // ID
_T("&Cancel"), // Label
wxPoint(320, 130), // Position
wxSize(60, 25) // Size
);
Bind(wxEVT_BUTTON, &JoystickConfiguration::OnButtonClicked, this);
Bind(wxEVT_BUTTON, &JoystickConfiguration::OnOk, this, wxID_OK);
Bind(wxEVT_BUTTON, &JoystickConfiguration::OnCancel, this, wxID_CANCEL);
Bind(wxEVT_CHECKBOX, &JoystickConfiguration::OnCheckboxChange, this);
SetSizerAndFit(joy_conf_box);
}
/**
@ -131,7 +78,7 @@ void JoystickConfiguration::InitJoystickConfiguration()
/*
* Check if there exist at least one pad available
* if the pad id is 0, you need at least 1 gamepad connected,
* if the pad id is 1, you need at least 2 gamepad connected,
* if the pad id is 1, you need at least 2 gamepads connected,
* Prevent to use a none initialized value on s_vgamePad (core dump)
*/
if (s_vgamePad.size() < m_pad_id + 1) {
@ -140,35 +87,29 @@ void JoystickConfiguration::InitJoystickConfiguration()
else
wxMessageBox(L"No second gamepad detected.");
// disable all checkbox
if (m_isForLeftJoystick) {
// disable all checkboxes
if (m_isForLeftJoystick)
{
m_cb_reverse_Lx->Disable();
m_cb_reverse_Ly->Disable();
} else {
}
else
{
m_cb_reverse_Rx->Disable();
m_cb_reverse_Ry->Disable();
}
}
}
/****************************************/
/*********** Events functions ***********/
/****************************************/
/**
* Button event, called when a button is clicked
*/
void JoystickConfiguration::OnButtonClicked(wxCommandEvent &event)
void JoystickConfiguration::OnOk(wxCommandEvent &event)
{
// Affichage d'un message à chaque clic sur le bouton
wxButton *bt_tmp = (wxButton *)event.GetEventObject(); // get the button object
int bt_id = bt_tmp->GetId(); // get the real ID
if (bt_id == m_bt_ok->GetId()) { // If the button ID is equals to the Ok button ID
Close(); // Close the window
} else if (bt_id == m_bt_cancel->GetId()) { // If the button ID is equals to the cancel button ID
reset(); // reinitialize the value of each parameters
Close(); // Close the window
}
Destroy();
}
void JoystickConfiguration::OnCancel(wxCommandEvent &event)
{
reset();
Destroy();
}
/**
@ -178,28 +119,45 @@ void JoystickConfiguration::OnCheckboxChange(wxCommandEvent &event)
{
wxCheckBox *cb_tmp = (wxCheckBox *)event.GetEventObject(); // get the slider object
int cb_id = cb_tmp->GetId();
bool val;
if (m_isForLeftJoystick) {
if (cb_id == m_cb_reverse_Ly->GetId()) {
val = m_cb_reverse_Ly->GetValue();
g_conf.pad_options[m_pad_id].reverse_ly = val;
} else if (cb_id == m_cb_reverse_Lx->GetId()) {
val = m_cb_reverse_Lx->GetValue();
g_conf.pad_options[m_pad_id].reverse_lx = val;
} else if (cb_id == m_cb_mouse_Ljoy->GetId()) {
val = m_cb_mouse_Ljoy->GetValue();
g_conf.pad_options[m_pad_id].mouse_l = val;
if (m_isForLeftJoystick)
{
switch (cb_id)
{
case Lx_check_id:
g_conf.pad_options[m_pad_id].reverse_lx = m_cb_reverse_Lx->GetValue();
break;
case Ly_check_id:
g_conf.pad_options[m_pad_id].reverse_ly = m_cb_reverse_Ly->GetValue();
break;
case Ljoy_check_id:
g_conf.pad_options[m_pad_id].mouse_l = m_cb_mouse_Ljoy->GetValue();
break;
default:
break;
}
} else {
if (cb_id == m_cb_reverse_Ry->GetId()) {
val = m_cb_reverse_Ry->GetValue();
g_conf.pad_options[m_pad_id].reverse_ry = val;
} else if (cb_id == m_cb_reverse_Rx->GetId()) {
val = m_cb_reverse_Rx->GetValue();
g_conf.pad_options[m_pad_id].reverse_rx = val;
} else if (cb_id == m_cb_mouse_Rjoy->GetId()) {
val = m_cb_mouse_Rjoy->GetValue();
g_conf.pad_options[m_pad_id].mouse_r = val;
}
else
{
switch (cb_id)
{
case Rx_check_id:
g_conf.pad_options[m_pad_id].reverse_rx = m_cb_reverse_Rx->GetValue();
break;
case Ry_check_id:
g_conf.pad_options[m_pad_id].reverse_ry = m_cb_reverse_Ry->GetValue();
break;
case Rjoy_check_id:
g_conf.pad_options[m_pad_id].mouse_r = m_cb_mouse_Rjoy->GetValue();
break;
default:
break;
}
}
}
@ -211,11 +169,14 @@ void JoystickConfiguration::OnCheckboxChange(wxCommandEvent &event)
// Reset checkbox and slider values
void JoystickConfiguration::reset()
{
if (m_isForLeftJoystick) {
if (m_isForLeftJoystick)
{
m_cb_reverse_Lx->SetValue(m_init_reverse_Lx);
m_cb_reverse_Ly->SetValue(m_init_reverse_Ly);
m_cb_mouse_Ljoy->SetValue(m_init_mouse_Ljoy);
} else {
}
else
{
m_cb_reverse_Rx->SetValue(m_init_reverse_Rx);
m_cb_reverse_Ry->SetValue(m_init_reverse_Ry);
m_cb_mouse_Rjoy->SetValue(m_init_mouse_Rjoy);
@ -225,30 +186,26 @@ void JoystickConfiguration::reset()
// Set button values
void JoystickConfiguration::repopulate()
{
bool val;
if (m_isForLeftJoystick) {
val = g_conf.pad_options[m_pad_id].reverse_lx;
m_init_reverse_Lx = val;
m_cb_reverse_Lx->SetValue(val);
if (m_isForLeftJoystick)
{
m_init_reverse_Lx = g_conf.pad_options[m_pad_id].reverse_lx;
m_cb_reverse_Lx->SetValue(m_init_reverse_Lx);
val = g_conf.pad_options[m_pad_id].reverse_ly;
m_init_reverse_Ly = val;
m_cb_reverse_Ly->SetValue(val);
m_init_reverse_Ly = g_conf.pad_options[m_pad_id].reverse_ly;
m_cb_reverse_Ly->SetValue(m_init_reverse_Ly);
val = g_conf.pad_options[m_pad_id].mouse_l;
m_init_mouse_Ljoy = val;
m_cb_mouse_Ljoy->SetValue(val);
} else {
val = g_conf.pad_options[m_pad_id].reverse_rx;
m_init_reverse_Rx = val;
m_cb_reverse_Rx->SetValue(val);
m_init_mouse_Ljoy = g_conf.pad_options[m_pad_id].mouse_l;
m_cb_mouse_Ljoy->SetValue(m_init_mouse_Ljoy);
}
else
{
m_init_reverse_Rx = g_conf.pad_options[m_pad_id].reverse_rx;
m_cb_reverse_Rx->SetValue(m_init_reverse_Rx);
val = g_conf.pad_options[m_pad_id].reverse_ry;
m_init_reverse_Ry = val;
m_cb_reverse_Ry->SetValue(val);
m_init_reverse_Ry = g_conf.pad_options[m_pad_id].reverse_ry;
m_cb_reverse_Ry->SetValue(m_init_reverse_Ry);
val = g_conf.pad_options[m_pad_id].mouse_r;
m_init_mouse_Rjoy = val;
m_cb_mouse_Rjoy->SetValue(val);
m_init_mouse_Rjoy = g_conf.pad_options[m_pad_id].mouse_r;
m_cb_mouse_Rjoy->SetValue(m_init_mouse_Rjoy);
}
}

View File

@ -23,19 +23,21 @@
#define __JOYSTICKCONFIGURATION_H__
#include <wx/wx.h>
#include <wx/frame.h>
#include <wx/window.h>
#include <wx/button.h>
#include <wx/checkbox.h>
#include <wx/slider.h>
#include "../GamePad.h"
#include "../keyboard.h"
#include "../onepad.h"
static const s32 Lx_check_id = wxID_HIGHEST + 100 + 1;
static const s32 Ly_check_id = wxID_HIGHEST + 100 + 2;
static const s32 Ljoy_check_id = wxID_HIGHEST + 100 + 3;
static const s32 Rx_check_id = wxID_HIGHEST + 100 + 4;
static const s32 Ry_check_id = wxID_HIGHEST + 100 + 5;
static const s32 Rjoy_check_id = wxID_HIGHEST + 100 + 6;
class JoystickConfiguration : public wxDialog
{
wxPanel *m_pan_joystick_config;
wxCheckBox *m_cb_reverse_Lx, *m_cb_reverse_Ly, *m_cb_reverse_Rx, *m_cb_reverse_Ry,
*m_cb_mouse_Ljoy, // Use mouse for left joystick
*m_cb_mouse_Rjoy; // Use mouse for right joystick
@ -46,12 +48,14 @@ class JoystickConfiguration : public wxDialog
bool m_init_reverse_Lx, m_init_reverse_Ly, m_init_reverse_Rx, m_init_reverse_Ry,
m_init_mouse_Ljoy, m_init_mouse_Rjoy, m_isForLeftJoystick;
// methods
// Methods
void repopulate();
void reset();
// Events
void OnButtonClicked(wxCommandEvent &);
void OnCheckboxChange(wxCommandEvent &);
void OnOk(wxCommandEvent &);
void OnCancel(wxCommandEvent &);
public:
JoystickConfiguration(int, bool, wxWindow *);

View File

@ -25,13 +25,13 @@
#include "state_management.h"
#include <string.h>
#include <gtk/gtk.h>
#include "linux.h"
#include <wx/wx.h>
Display *GSdsp;
Window GSwin;
void SysMessage(const char *fmt, ...)
static void SysMessage(const char *fmt, ...)
{
va_list list;
char msg[512];
@ -43,16 +43,11 @@ void SysMessage(const char *fmt, ...)
if (msg[strlen(msg) - 1] == '\n')
msg[strlen(msg) - 1] = 0;
GtkWidget *dialog;
dialog = gtk_message_dialog_new(NULL,
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_INFO,
GTK_BUTTONS_OK,
"%s", msg);
gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
wxMessageDialog dialog(nullptr, msg, "Info", wxOK);
dialog.ShowModal();
}
EXPORT_C_(void) PADabout()
{
SysMessage("OnePad is a rewrite of Zerofrog's ZeroPad, done by arcum42.");