nJoy: First implementation of an analog stick radius adjustment. Converting a square radius to a circle radius.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1698 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
John Peterson 2008-12-27 11:32:03 +00:00
parent fb5b4d026a
commit 15cff48f5a
10 changed files with 971 additions and 842 deletions

View File

@ -207,7 +207,7 @@
RuntimeLibrary="0"
UsePrecompiledHeader="0"
WarningLevel="3"
WarnAsError="true"
WarnAsError="false"
DebugInformationFormat="3"
/>
<Tool
@ -364,7 +364,7 @@
RuntimeLibrary="0"
UsePrecompiledHeader="0"
WarningLevel="3"
WarnAsError="true"
WarnAsError="false"
DebugInformationFormat="3"
/>
<Tool
@ -505,6 +505,10 @@
RelativePath=".\Src\Config.cpp"
>
</File>
<File
RelativePath=".\Src\Config.h"
>
</File>
<File
RelativePath=".\Src\nJoy.cpp"
>
@ -541,6 +545,10 @@
RelativePath=".\Src\GUI\ConfigBox.h"
>
</File>
<File
RelativePath=".\Src\GUI\ConfigJoypad.cpp"
>
</File>
</Filter>
<File
RelativePath=".\readme.txt"

View File

@ -35,6 +35,12 @@
// ¯¯¯¯¯¯¯¯¯
#include "nJoy.h"
Config g_Config;
Config::Config()
{
memset(this, 0, sizeof(Config)); // Clear the memory
}
// Enable output log
@ -76,41 +82,90 @@ void DEBUG_QUIT()
fclose(pFile);
}
/* Check for duplicate Joypad names. An alternative to this would be to only notify the user
that he has multiple virtual controllers assigned to the same physical controller
and that only one of them will be saved if he has attached settings to a controller ID */
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
std::string Config::CheckForDuplicateNames(std::string _Name, std::vector<std::string> &Duplicates)
{
// Count the number of duplicate names
int NumDuplicates = 0;
for(int i = 0; i < Duplicates.size(); i++)
if(_Name == Duplicates.at(i)) NumDuplicates++;
Duplicates.push_back(_Name); // Add the name
// Return an amended name if we found a duplicate
if(NumDuplicates > 0)
return StringFromFormat("%s (%i)", _Name.c_str(), NumDuplicates);
else
return _Name;
}
// Save settings to file
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
void SaveConfig()
void Config::Save()
{
IniFile file;
file.Load("nJoy.ini");
std::vector<std::string> Duplicates;
file.Set("General", "SaveByID", g_Config.bSaveByID);
file.Set("General", "ShowAdvanced", g_Config.bShowAdvanced);
for (int i = 0; i < 4; i++)
{
char SectionName[32];
sprintf(SectionName, "PAD%i", i+1);
std::string SectionName = StringFromFormat("PAD%i", i+1);
file.Set(SectionName.c_str(), "joy_id", joysticks[i].ID);
file.Set(SectionName.c_str(), "enabled", joysticks[i].enabled);
file.Set(SectionName, "l_shoulder", joysticks[i].buttons[CTL_L_SHOULDER]);
file.Set(SectionName, "r_shoulder", joysticks[i].buttons[CTL_R_SHOULDER]);
file.Set(SectionName, "a_button", joysticks[i].buttons[CTL_A_BUTTON]);
file.Set(SectionName, "b_button", joysticks[i].buttons[CTL_B_BUTTON]);
file.Set(SectionName, "x_button", joysticks[i].buttons[CTL_X_BUTTON]);
file.Set(SectionName, "y_button", joysticks[i].buttons[CTL_Y_BUTTON]);
file.Set(SectionName, "z_trigger", joysticks[i].buttons[CTL_Z_TRIGGER]);
file.Set(SectionName, "start_button", joysticks[i].buttons[CTL_START]);
file.Set(SectionName, "dpad", joysticks[i].dpad);
file.Set(SectionName, "dpad_up", joysticks[i].dpad2[CTL_D_PAD_UP]);
file.Set(SectionName, "dpad_down", joysticks[i].dpad2[CTL_D_PAD_DOWN]);
file.Set(SectionName, "dpad_left", joysticks[i].dpad2[CTL_D_PAD_LEFT]);
file.Set(SectionName, "dpad_right", joysticks[i].dpad2[CTL_D_PAD_RIGHT]);
file.Set(SectionName, "main_x", joysticks[i].axis[CTL_MAIN_X]);
file.Set(SectionName, "main_y", joysticks[i].axis[CTL_MAIN_Y]);
file.Set(SectionName, "sub_x", joysticks[i].axis[CTL_SUB_X]);
file.Set(SectionName, "sub_y", joysticks[i].axis[CTL_SUB_Y]);
file.Set(SectionName, "enabled", joysticks[i].enabled);
file.Set(SectionName, "deadzone", joysticks[i].deadzone);
file.Set(SectionName, "halfpress", joysticks[i].halfpress);
file.Set(SectionName, "joy_id", joysticks[i].ID);
file.Set(SectionName, "controllertype", joysticks[i].controllertype);
file.Set(SectionName, "eventnum", joysticks[i].eventnum);
//////////////////////////////////////
// Save joypad specific settings
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
// Current joypad device ID: joysticks[i].ID
// Current joypad name: joyinfo[joysticks[i].ID].Name
if(g_Config.bSaveByID)
{
/* Save joypad specific settings. Check for "joysticks[i].ID < SDL_NumJoysticks()" to
avoid reading a joyinfo that does't exist */
if(joysticks[i].ID >= SDL_NumJoysticks()) continue;
//PanicAlert("%i", m_frame->m_Joyname[0]->GetSelection());
//if(i == 0) PanicAlert("%i", joysticks[i].buttons[CTL_START]);
//PanicAlert("%s", joyinfo[joysticks[i].ID].Name);
// Create a section name
SectionName = CheckForDuplicateNames(joyinfo[joysticks[i].ID].Name, Duplicates);
}
file.Set(SectionName.c_str(), "l_shoulder", joysticks[i].buttons[CTL_L_SHOULDER]);
file.Set(SectionName.c_str(), "r_shoulder", joysticks[i].buttons[CTL_R_SHOULDER]);
file.Set(SectionName.c_str(), "a_button", joysticks[i].buttons[CTL_A_BUTTON]);
file.Set(SectionName.c_str(), "b_button", joysticks[i].buttons[CTL_B_BUTTON]);
file.Set(SectionName.c_str(), "x_button", joysticks[i].buttons[CTL_X_BUTTON]);
file.Set(SectionName.c_str(), "y_button", joysticks[i].buttons[CTL_Y_BUTTON]);
file.Set(SectionName.c_str(), "z_trigger", joysticks[i].buttons[CTL_Z_TRIGGER]);
file.Set(SectionName.c_str(), "start_button", joysticks[i].buttons[CTL_START]);
file.Set(SectionName.c_str(), "dpad", joysticks[i].dpad);
file.Set(SectionName.c_str(), "dpad_up", joysticks[i].dpad2[CTL_D_PAD_UP]);
file.Set(SectionName.c_str(), "dpad_down", joysticks[i].dpad2[CTL_D_PAD_DOWN]);
file.Set(SectionName.c_str(), "dpad_left", joysticks[i].dpad2[CTL_D_PAD_LEFT]);
file.Set(SectionName.c_str(), "dpad_right", joysticks[i].dpad2[CTL_D_PAD_RIGHT]);
file.Set(SectionName.c_str(), "main_x", joysticks[i].axis[CTL_MAIN_X]);
file.Set(SectionName.c_str(), "main_y", joysticks[i].axis[CTL_MAIN_Y]);
file.Set(SectionName.c_str(), "sub_x", joysticks[i].axis[CTL_SUB_X]);
file.Set(SectionName.c_str(), "sub_y", joysticks[i].axis[CTL_SUB_Y]);
file.Set(SectionName.c_str(), "deadzone", joysticks[i].deadzone);
file.Set(SectionName.c_str(), "halfpress", joysticks[i].halfpress);
file.Set(SectionName.c_str(), "controllertype", joysticks[i].controllertype);
file.Set(SectionName.c_str(), "eventnum", joysticks[i].eventnum);
file.Set(SectionName.c_str(), "Diagonal", g_Config.SDiagonal);
file.Set(SectionName.c_str(), "SquareToCircle", g_Config.bSquareToCircle);
}
file.Save("nJoy.ini");
@ -118,39 +173,69 @@ void SaveConfig()
// Load settings from file
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
void LoadConfig()
void Config::Load(bool Config)
{
IniFile file;
file.Load("nJoy.ini");
std::vector<std::string> Duplicates;
file.Get("General", "SaveByID", &g_Config.bSaveByID, false);
file.Get("General", "ShowAdvanced", &g_Config.bShowAdvanced, false);
for (int i = 0; i < 4; i++)
{
char SectionName[32];
sprintf(SectionName, "PAD%i", i+1);
std::string SectionName = StringFromFormat("PAD%i", i+1);
file.Get(SectionName, "l_shoulder", &joysticks[i].buttons[CTL_L_SHOULDER], 4);
file.Get(SectionName, "r_shoulder", &joysticks[i].buttons[CTL_R_SHOULDER], 5);
file.Get(SectionName, "a_button", &joysticks[i].buttons[CTL_A_BUTTON], 0);
file.Get(SectionName, "b_button", &joysticks[i].buttons[CTL_B_BUTTON], 1);
file.Get(SectionName, "x_button", &joysticks[i].buttons[CTL_X_BUTTON], 3);
file.Get(SectionName, "y_button", &joysticks[i].buttons[CTL_Y_BUTTON], 2);
file.Get(SectionName, "z_trigger", &joysticks[i].buttons[CTL_Z_TRIGGER], 7);
file.Get(SectionName, "start_button", &joysticks[i].buttons[CTL_START], 9);
file.Get(SectionName, "dpad", &joysticks[i].dpad, 0);
file.Get(SectionName, "dpad_up", &joysticks[i].dpad2[CTL_D_PAD_UP], 0);
file.Get(SectionName, "dpad_down", &joysticks[i].dpad2[CTL_D_PAD_DOWN], 0);
file.Get(SectionName, "dpad_left", &joysticks[i].dpad2[CTL_D_PAD_LEFT], 0);
file.Get(SectionName, "dpad_right", &joysticks[i].dpad2[CTL_D_PAD_RIGHT], 0);
file.Get(SectionName, "main_x", &joysticks[i].axis[CTL_MAIN_X], 0);
file.Get(SectionName, "main_y", &joysticks[i].axis[CTL_MAIN_Y], 1);
file.Get(SectionName, "sub_x", &joysticks[i].axis[CTL_SUB_X], 2);
file.Get(SectionName, "sub_y", &joysticks[i].axis[CTL_SUB_Y], 3);
file.Get(SectionName, "enabled", &joysticks[i].enabled, 1);
file.Get(SectionName, "deadzone", &joysticks[i].deadzone, 9);
file.Get(SectionName, "halfpress", &joysticks[i].halfpress, 6);
file.Get(SectionName, "joy_id", &joysticks[i].ID, 0);
file.Get(SectionName, "controllertype", &joysticks[i].controllertype, 0);
file.Get(SectionName, "eventnum", &joysticks[i].eventnum, 0);
// Don't update this when we are loading settings from the ConfigBox
if(!Config)
{
file.Get(SectionName.c_str(), "joy_id", &joysticks[i].ID, 0);
file.Get(SectionName.c_str(), "enabled", &joysticks[i].enabled, 1);
}
//////////////////////////////////////
// Load joypad specific settings
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
// Current joypad device ID: joysticks[i].ID
// Current joypad name: joyinfo[joysticks[i].ID].Name
if(g_Config.bSaveByID)
{
/* Prevent a crash from illegal access to joyinfo that will only have values for
the current amount of connected joysticks */
if(joysticks[i].ID >= SDL_NumJoysticks()) continue;
//PanicAlert("%i %i",joysticks[i].ID, SDL_NumJoysticks());
//PanicAlert("%s", joyinfo[joysticks[i].ID].Name);
// Create a section name
SectionName = CheckForDuplicateNames(joyinfo[joysticks[i].ID].Name, Duplicates);
}
file.Get(SectionName.c_str(), "l_shoulder", &joysticks[i].buttons[CTL_L_SHOULDER], 4);
file.Get(SectionName.c_str(), "r_shoulder", &joysticks[i].buttons[CTL_R_SHOULDER], 5);
file.Get(SectionName.c_str(), "a_button", &joysticks[i].buttons[CTL_A_BUTTON], 0);
file.Get(SectionName.c_str(), "b_button", &joysticks[i].buttons[CTL_B_BUTTON], 1);
file.Get(SectionName.c_str(), "x_button", &joysticks[i].buttons[CTL_X_BUTTON], 3);
file.Get(SectionName.c_str(), "y_button", &joysticks[i].buttons[CTL_Y_BUTTON], 2);
file.Get(SectionName.c_str(), "z_trigger", &joysticks[i].buttons[CTL_Z_TRIGGER], 7);
file.Get(SectionName.c_str(), "start_button", &joysticks[i].buttons[CTL_START], 9);
file.Get(SectionName.c_str(), "dpad", &joysticks[i].dpad, 0);
file.Get(SectionName.c_str(), "dpad_up", &joysticks[i].dpad2[CTL_D_PAD_UP], 0);
file.Get(SectionName.c_str(), "dpad_down", &joysticks[i].dpad2[CTL_D_PAD_DOWN], 0);
file.Get(SectionName.c_str(), "dpad_left", &joysticks[i].dpad2[CTL_D_PAD_LEFT], 0);
file.Get(SectionName.c_str(), "dpad_right", &joysticks[i].dpad2[CTL_D_PAD_RIGHT], 0);
file.Get(SectionName.c_str(), "main_x", &joysticks[i].axis[CTL_MAIN_X], 0);
file.Get(SectionName.c_str(), "main_y", &joysticks[i].axis[CTL_MAIN_Y], 1);
file.Get(SectionName.c_str(), "sub_x", &joysticks[i].axis[CTL_SUB_X], 2);
file.Get(SectionName.c_str(), "sub_y", &joysticks[i].axis[CTL_SUB_Y], 3);
file.Get(SectionName.c_str(), "deadzone", &joysticks[i].deadzone, 9);
file.Get(SectionName.c_str(), "halfpress", &joysticks[i].halfpress, 6);
file.Get(SectionName.c_str(), "controllertype", &joysticks[i].controllertype, 0);
file.Get(SectionName.c_str(), "eventnum", &joysticks[i].eventnum, 0);
file.Get(SectionName.c_str(), "Diagonal", &g_Config.SDiagonal, "100%");
file.Get(SectionName.c_str(), "SquareToCircle", &g_Config.bSquareToCircle, false);
}
}

View File

@ -0,0 +1,39 @@
// Copyright (C) 2003-2008 Dolphin Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0.
// This program 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 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#ifndef _CONFIG_H
#define _CONFIG_H
struct Config
{
Config();
void Load(bool Config = false);
void Save();
std::string CheckForDuplicateNames(std::string _Name, std::vector<std::string> &Duplicates);
// General
bool bShowAdvanced; // Only allow one of these
bool bSaveByID;
// Joystick
std::string SDiagonal;
bool bSquareToCircle;
};
extern Config g_Config;
#endif // _CONFIG_H

View File

@ -41,71 +41,96 @@ extern CONTROLLER_INFO *joyinfo;
extern bool emulator_running;
////////////////////////
int main_stick_x = 0;
/* If we don't use this hack m_MainSizer->GetMinSize().GetWidth() will not change
when we enable and disable bShowAdvanced */
bool StrangeHack = true;
// Set PAD status
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯
void ConfigBox::PadGetStatus()
{
//
int _numPAD = 0;
if (!joysticks[_numPAD].enabled)
// Return if it's not enabled
if (!joysticks[notebookpage].enabled)
{
m_TStatusIn[notebookpage]->SetLabel(wxT("Not enabled"));
return;
// Clear pad status
//memset(_pPADStatus, 0, sizeof(SPADStatus));
}
// Get pad status
GetJoyState(_numPAD);
GetJoyState(notebookpage);
// Reset!
/*
int base = 0x80;
_pPADStatus->stickY = base;
_pPADStatus->stickX = base;
_pPADStatus->substickX = base;
_pPADStatus->substickY = base;
_pPADStatus->button |= PAD_USE_ORIGIN;
*/
// Set analog controllers
// Set Deadzones perhaps out of function
//int deadzone = (int)(((float)(128.00/100.00)) * (float)(joysticks[_numPAD].deadzone+1));
//int deadzone2 = (int)(((float)(-128.00/100.00)) * (float)(joysticks[_numPAD].deadzone+1));
// Adjust range
// The value returned by SDL_JoystickGetAxis is a signed integer (-32768 to 32768)
// The value used for the gamecube controller is an unsigned char (0 to 255)
int main_stick_x = (joystate[_numPAD].axis[CTL_MAIN_X] >> 8);
int main_stick_y = -(joystate[_numPAD].axis[CTL_MAIN_Y] >> 8);
//int sub_stick_x = (joystate[_numPAD].axis[CTL_SUB_X] >> 8);
//int sub_stick_y = -(joystate[_numPAD].axis[CTL_SUB_Y] >> 8);
// Get original values
int main_x = joystate[notebookpage].axis[CTL_MAIN_X];
int main_y = joystate[notebookpage].axis[CTL_MAIN_Y];
//int sub_x = (joystate[_numPAD].axis[CTL_SUB_X];
//int sub_y = -(joystate[_numPAD].axis[CTL_SUB_Y];
if (joystate[_numPAD].buttons[CTL_A_BUTTON])
// Get adjusted values
int main_x_after = main_x, main_y_after = main_y;
if(g_Config.bSquareToCircle)
{
PanicAlert("");
//_pPADStatus->button |= PAD_BUTTON_A;
//_pPADStatus->analogA = 255; // Perhaps support pressure?
for(int i=0; i<4 ;i++)
{
m_bmpDot[i]->SetPosition(wxPoint(main_stick_x += 3, main_stick_y));
}
std::vector<int> main_xy = Pad_Square_to_Circle(main_x, main_y);
main_x_after = main_xy.at(0);
main_y_after = main_xy.at(1);
}
for(int i=0; i<4 ;i++)
{
//m_bmpDot[i]->SetPosition(wxPoint(main_stick_x / 4, main_stick_y / 4));
}
//
float f_x = main_x / 32767.0;
float f_y = main_y / 32767.0;
float f_x_aft = main_x_after / 32767.0;
float f_y_aft = main_y_after / 32767.0;
/*
m_pStatusBar->SetLabel(wxString::Format(
"ID:%i | %i %i = %1.2f %1.2f | %i %i = %1.2f %1.2f",
ID,
main_x, main_y,
f_x, f_y,
main_x_after, main_y_after,
f_x_aft, f_y_aft
));*/
m_TStatusIn[notebookpage]->SetLabel(wxString::Format(
wxT("x:%1.2f y:%1.2f"),
f_x, f_y
));
m_TStatusOut[notebookpage]->SetLabel(wxString::Format(
wxT("x:%1.2f y:%1.2f"),
f_x_aft, f_y_aft
));
// Adjust the values for the plot
int BoxW_ = BoxW - 2; int BoxH_ = BoxH - 2; // Border adjustment
main_x = (BoxW_ / 2) + (main_x * BoxW_ / (32767 * 2));
main_y = (BoxH_ / 2) + (main_y * BoxH_ / (32767 * 2));
int main_x_out = (BoxW_ / 2) + (main_x_after * BoxW_ / (32767 * 2));
int main_y_out = (BoxH_ / 2) + (main_y_after * BoxH_ / (32767 * 2));
// Adjust the dot
m_bmpDot[notebookpage]->SetPosition(wxPoint(main_x, main_y));
m_bmpDotOut[notebookpage]->SetPosition(wxPoint(main_x_out, main_y_out));
}
// Populate the advanced tab
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
void ConfigBox::Update()
{
//PadGetStatus();
if(StrangeHack) PadGetStatus();
if(!g_Config.bShowAdvanced) StrangeHack = false; else StrangeHack = true;
/*
m_pStatusBar->SetLabel(wxString::Format(
"ID: %i %i %i",
m_Joyname[0]->GetSelection(), (int)StrangeHack, (int)g_Config.bShowAdvanced
));*/
}
@ -113,33 +138,43 @@ void ConfigBox::Update()
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
void ConfigBox::CreateAdvancedControls(int i)
{
m_pInStatus[i] = new wxPanel(m_Notebook, ID_INSTATUS1 + i, wxDefaultPosition, wxDefaultSize);
m_pInStatus[i] = new wxPanel(m_Controller[i], ID_INSTATUS1 + i, wxDefaultPosition, wxDefaultSize);
m_bmpSquare[i] = new wxStaticBitmap(m_pInStatus[i], ID_STATUSBMP1 + i, CreateBitmap(),
//wxPoint(4, 15), wxSize(70,70));
//wxPoint(4, 20), wxDefaultSize);
wxDefaultPosition, wxDefaultSize);
m_bmpDot[i] = new wxStaticBitmap(m_pInStatus[i], ID_STATUSDOTBMP1 + i, CreateBitmapDot(),
wxPoint(40, 40), wxDefaultSize);
wxPoint(BoxW / 2, BoxH / 2), wxDefaultSize);
m_pOutStatus[i] = new wxPanel(m_Controller[i], ID_INSTATUS1 + i, wxDefaultPosition, wxDefaultSize);
m_bmpSquareOut[i] = new wxStaticBitmap(m_pOutStatus[i], ID_STATUSBMP1 + i, CreateBitmap(),
//wxPoint(4, 15), wxSize(70,70));
//wxPoint(4, 20), wxDefaultSize);
wxDefaultPosition, wxDefaultSize);
m_bmpDotOut[i] = new wxStaticBitmap(m_pOutStatus[i], ID_STATUSDOTBMP1 + i, CreateBitmapDot(),
wxPoint(BoxW / 2, BoxH / 2), wxDefaultSize);
}
wxBitmap ConfigBox::CreateBitmap() // Create box
{
int w = 70, h = 70;
wxBitmap bitmap(w, h);
BoxW = 70, BoxH = 70;
wxBitmap bitmap(BoxW, BoxH);
wxMemoryDC dc;
dc.SelectObject(bitmap);
// Set outline and fill colors
wxBrush LightBlueBrush(_T("#0383f0"));
wxPen LightBluePen(_T("#80c5fd"));
wxPen LightGrayPen(_T("#909090"));
dc.SetPen(LightGrayPen);
//wxBrush LightBlueBrush(_T("#0383f0"));
//wxPen LightBluePen(_T("#80c5fd"));
//wxPen LightGrayPen(_T("#909090"));
wxPen LightBluePen(_T("#7f9db9")); // Windows XP color
dc.SetPen(LightBluePen);
dc.SetBrush(*wxWHITE_BRUSH);
dc.Clear();
dc.DrawRectangle(0, 0, w, h);
dc.DrawRectangle(0, 0, BoxW, BoxH);
dc.SelectObject(wxNullBitmap);
return bitmap;
}
@ -152,11 +187,11 @@ wxBitmap ConfigBox::CreateBitmapDot() // Create dot
dc.SelectObject(bitmap);
// Set outline and fill colors
wxBrush LightBlueBrush(_T("#0383f0"));
wxPen LightBluePen(_T("#80c5fd"));
wxPen LightGrayPen(_T("#909090"));
dc.SetPen(LightGrayPen);
dc.SetBrush(*wxWHITE_BRUSH);
//wxBrush RedBrush(_T("#0383f0"));
//wxPen RedPen(_T("#80c5fd"));
//wxPen LightGrayPen(_T("#909090"));
dc.SetPen(*wxRED_PEN);
dc.SetBrush(*wxRED_BRUSH);
dc.Clear();
dc.DrawRectangle(0, 0, w, h);

View File

@ -33,7 +33,9 @@
//////////////////////////////////////////////////////////////////////////////////////////
// Include
// ¯¯¯¯¯¯¯¯¯
#include "ConfigBox.h"
#include "math.h" // System
#include "ConfigBox.h" // Local
#include "../nJoy.h"
#include "Images/controller.xpm"
@ -61,8 +63,14 @@ BEGIN_EVENT_TABLE(ConfigBox,wxDialog)
EVT_BUTTON(ID_CANCEL, ConfigBox::CancelClick)
EVT_COMBOBOX(IDC_JOYNAME, ConfigBox::ChangeJoystick)
EVT_COMBOBOX(IDC_CONTROLTYPE, ConfigBox::ChangeControllertype)
EVT_CHECKBOX(IDC_JOYATTACH, ConfigBox::EnableDisable)
EVT_NOTEBOOK_PAGE_CHANGED(ID_NOTEBOOK, ConfigBox::NotebookPageChanged)
EVT_CHECKBOX(IDC_SAVEBYID, ConfigBox::ChangeSettings) // Settings
EVT_CHECKBOX(IDC_SHOWADVANCED, ConfigBox::ChangeSettings)
EVT_COMBOBOX(IDCB_MAINSTICK_DIAGONAL, ConfigBox::ChangeSettings)
EVT_CHECKBOX(IDCB_MAINSTICK_S_TO_C, ConfigBox::ChangeSettings)
EVT_BUTTON(IDB_SHOULDER_L, ConfigBox::GetButtons)
EVT_BUTTON(IDB_SHOULDER_R, ConfigBox::GetButtons)
EVT_BUTTON(IDB_BUTTON_A, ConfigBox::GetButtons)
@ -94,33 +102,199 @@ ConfigBox::ConfigBox(wxWindow *parent, wxWindowID id, const wxString &title,
, m_timer(this)
#endif
{
notebookpage = 0;
CreateGUIControls();
#if wxUSE_TIMER
m_timer.Start(1000);
m_timer.Start( floor((double)(1000 / 30)) );
#endif
}
ConfigBox::~ConfigBox()
{
// empty
}
// Close window
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
void ConfigBox::OnClose(wxCloseEvent& /*event*/)
{
EndModal(0);
if(!emulator_running) PAD_Shutdown(); // Close pads, unless we are running a game
}
// Call about dialog
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
void ConfigBox::AboutClick(wxCommandEvent& event)
{
#ifdef _WIN32
wxWindow win;
win.SetHWND((WXHWND)this->GetHWND());
win.Enable(false);
AboutBox frame(&win);
frame.ShowModal();
win.Enable(true);
win.SetHWND(0);
#else
AboutBox frame(NULL);
frame.ShowModal();
#endif
}
// Click OK
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
void ConfigBox::OKClick(wxCommandEvent& event)
{
if (event.GetId() == ID_OK)
{
for(int i=0; i<4 ;i++) GetControllerAll(i); // Update joysticks array
g_Config.Save(); // Save settings
g_Config.Load(); // Reload settings
Close(); // Call OnClose()
}
}
// Click Cancel
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
void ConfigBox::CancelClick(wxCommandEvent& event)
{
if (event.GetId() == ID_CANCEL)
{
g_Config.Load(); // Reload settings
Close(); // Call OnClose()
}
}
//////////////////////////////////
// Change settings
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
void ConfigBox::ChangeSettings( wxCommandEvent& event )
{
switch(event.GetId())
{
case IDC_SAVEBYID:
g_Config.bSaveByID = m_CBSaveByID[notebookpage]->IsChecked();
break;
case IDC_SHOWADVANCED:
g_Config.bShowAdvanced = m_CBShowAdvanced[notebookpage]->IsChecked();
for(int i = 0; i < 4; i++)
{
m_CBShowAdvanced[i]->SetValue(g_Config.bShowAdvanced);
m_sMainRight[i]->Show(g_Config.bShowAdvanced);
}
SizeWindow();
break;
case IDCB_MAINSTICK_DIAGONAL:
g_Config.SDiagonal = m_CoBDiagonal[notebookpage]->GetLabel().mb_str();
case IDCB_MAINSTICK_S_TO_C:
g_Config.bSquareToCircle = m_CBS_to_C[notebookpage]->IsChecked();
}
}
// Enable or disable joystick and update the GUI
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
void ConfigBox::EnableDisable(wxCommandEvent& event)
{
// Update the enable / disable status
DoEnableDisable(notebookpage);
}
void ConfigBox::DoEnableDisable(int _notebookpage)
{
#ifdef _WIN32 // There is no FindItem in linux so this doesn't work
// Update the enable / disable status
joysticks[_notebookpage].enabled = m_Joyattach[_notebookpage]->GetValue();
// Enable or disable all buttons
for(int i = IDB_SHOULDER_L; i < (IDB_SHOULDER_L + 13 + 4); i++)
{
m_Controller[_notebookpage]->FindItem(i)->Enable(joysticks[_notebookpage].enabled);
}
// Enable or disable settings controls
m_Controller[_notebookpage]->FindItem(IDC_DEADZONE)->Enable(joysticks[_notebookpage].enabled);
m_Controller[_notebookpage]->FindItem(IDC_CONTROLTYPE)->Enable(joysticks[_notebookpage].enabled);
// General settings
m_CBSaveByID[_notebookpage]->SetValue(g_Config.bSaveByID);
m_CBShowAdvanced[_notebookpage]->SetValue(g_Config.bShowAdvanced);
// Advanced settings
m_CoBDiagonal[notebookpage]->SetValue(wxString::FromAscii(g_Config.SDiagonal.c_str()));
m_CBS_to_C[notebookpage]->SetValue(g_Config.bSquareToCircle);
m_Controller[_notebookpage]->Refresh(); // Repaint the background
#endif
}
// Notebook page changed
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
void ConfigBox::NotebookPageChanged(wxNotebookEvent& event)
{
notebookpage = event.GetSelection();
}
// Change Joystick. Load saved settings.
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
void ConfigBox::ChangeJoystick(wxCommandEvent& event)
{
// Save potential changes
if(g_Config.bSaveByID)
{
int Tmp = joysticks[notebookpage].ID; // Don't update the ID
GetControllerAll(notebookpage);
joysticks[notebookpage].ID = Tmp;
g_Config.Save();
}
//PanicAlert("%i", m_Joyname[notebookpage]->GetSelection());
// Update the ID for the virtual device to a new physical device
joysticks[notebookpage].ID = m_Joyname[notebookpage]->GetSelection();
//PanicAlert("%i %i", joysticks[notebookpage].ID, notebookpage);
// Load device settings
if(g_Config.bSaveByID)
{
g_Config.Load(true); // Then load the current
SetControllerAll(notebookpage);
}
// Remap the controller to
if (joysticks[notebookpage].enabled)
{
if (SDL_JoystickOpened(notebookpage)) SDL_JoystickClose(joystate[notebookpage].joy);
joystate[notebookpage].joy = SDL_JoystickOpen(joysticks[notebookpage].ID);
}
}
// Populate the config window
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
void ConfigBox::OnPaint( wxPaintEvent &event )
{
event.Skip();
for(int i=0; i<4 ;i++)
{
wxPaintDC dcWin(m_pKeys[i]);
wxPaintDC dcWin(m_pKeys[notebookpage]);
PrepareDC( dcWin );
if(joysticks[notebookpage].enabled)
dcWin.DrawBitmap( WxStaticBitmap1_BITMAP, 94, 0, true );
}
else
dcWin.DrawBitmap( WxStaticBitmap1_BITMAPGray, 94, 0, true );
}
// Populate the config window
@ -136,9 +310,6 @@ void ConfigBox::CreateGUIControls()
SetIcon(wxNullIcon);
//WxStaticBitmap1_BITMAP(ConfigBox_WxStaticBitmap1_XPM);
//WxStaticBitmap1_BITMAP = new WxStaticBitmap1_BITMAP(ConfigBox_WxStaticBitmap1_XPM);
#ifndef _WIN32
@ -165,13 +336,20 @@ void ConfigBox::CreateGUIControls()
m_Controller[3] = new wxPanel(m_Notebook, ID_CONTROLLERPAGE4, wxDefaultPosition, wxDefaultSize);
m_Notebook->AddPage(m_Controller[3], wxT("Controller 4"));
// Add controls
wxArrayString arrayStringFor_Joyname;
wxArrayString arrayStringFor_Controltype;
wxArrayString arrayStringFor_Deadzone;
// Search for devices and add the to the device list
if(Search_Devices())
// Define bitmap for EVT_PAINT
WxStaticBitmap1_BITMAP = wxBitmap(ConfigBox_WxStaticBitmap1_XPM);
// Gray version
wxImage WxImageGray = WxStaticBitmap1_BITMAP.ConvertToImage();
WxImageGray = WxImageGray.ConvertToGreyscale();
WxStaticBitmap1_BITMAPGray = wxBitmap(WxImageGray);
// --------------------------------------------------------------------
// Search for devices and add them to the device list
// -----------------------------
wxArrayString arrayStringFor_Joyname; // The string array
if(SDL_NumJoysticks() > 0)
{
for(int x = 0; x < SDL_NumJoysticks(); x++)
{
@ -183,21 +361,27 @@ void ConfigBox::CreateGUIControls()
arrayStringFor_Joyname.Add(wxString::FromAscii("No Joystick detected!"));
}
// --------------------------------------------------------------------
// Populate the controller type list
// -----------------------------
wxArrayString arrayStringFor_Controltype;
arrayStringFor_Controltype.Add(wxString::FromAscii(ControllerType[CTL_TYPE_JOYSTICK]));
arrayStringFor_Controltype.Add(wxString::FromAscii(ControllerType[CTL_TYPE_JOYSTICK_NO_HAT]));
// arrayStringFor_Controltype.Add(wxString::FromAscii(ControllerType[CTL_TYPE_JOYSTICK_XBOX360]));
// arrayStringFor_Controltype.Add(wxString::FromAscii(ControllerType[CTL_TYPE_KEYBOARD]));
// --------------------------------------------------------------------
// Populate the deadzone list
// -----------------------------
char buffer [8];
wxArrayString arrayStringFor_Deadzone;
for(int x = 1; x <= 100; x++)
{
sprintf (buffer, "%d %%", x);
arrayStringFor_Deadzone.Add(wxString::FromAscii(buffer));
}
// Define bitmap for EVT_PAINT
WxStaticBitmap1_BITMAP = wxBitmap(ConfigBox_WxStaticBitmap1_XPM);
// Populate all four pages
for(int i=0; i<4 ;i++)
@ -319,12 +503,13 @@ void ConfigBox::CreateGUIControls()
// -----------------------------
// Groups
#ifdef _WIN32
m_Joyname[i] = new wxComboBox(m_Controller[i], IDC_JOYNAME, wxEmptyString, wxDefaultPosition, wxSize(476, 21), arrayStringFor_Joyname, 0, wxDefaultValidator, wxT("m_Joyname"));
m_Joyattach[i] = new wxCheckBox(m_Controller[i], IDC_JOYATTACH, wxT("Controller attached"), wxDefaultPosition, wxSize(109, 25), 0, wxDefaultValidator, wxT("Controller attached"));
m_Joyname[i] = new wxComboBox(m_Controller[i], IDC_JOYNAME, arrayStringFor_Joyname[0], wxDefaultPosition, wxSize(476, 21), arrayStringFor_Joyname, wxCB_READONLY);
m_Joyattach[i] = new wxCheckBox(m_Controller[i], IDC_JOYATTACH, wxT("Controller attached"), wxDefaultPosition, wxSize(109, 25));
#else
m_Joyname[i] = new wxComboBox(m_Controller[i], IDC_JOYNAME, wxEmptyString, wxDefaultPosition, wxSize(450, 25), arrayStringFor_Joyname, 0, wxDefaultValidator, wxT("m_Joyname"));
m_Joyname[i] = new wxComboBox(m_Controller[i], IDC_JOYNAME, arrayStringFor_Joyname[0], wxDefaultPosition, wxSize(450, 25), arrayStringFor_Joyname, 0, wxDefaultValidator, wxT("m_Joyname"));
m_Joyattach[i] = new wxCheckBox(m_Controller[i], IDC_JOYATTACH, wxT("Controller attached"), wxDefaultPosition, wxSize(140, 25), 0, wxDefaultValidator, wxT("Controller attached"));
#endif
m_Joyattach[i]->SetToolTip(wxString::Format(wxT("Decide if Controller %i shall be detected by the game."), i + 1));
m_gJoyname[i] = new wxStaticBoxSizer (wxHORIZONTAL, m_Controller[i], wxT("Controller:"));
m_gJoyname[i]->Add(m_Joyname[i], 0, (wxLEFT | wxRIGHT), 5);
@ -360,38 +545,113 @@ void ConfigBox::CreateGUIControls()
// Populate controller typ
m_gControllertype[i] = new wxStaticBoxSizer( wxVERTICAL, m_Controller[i], wxT("Controller type"));
#ifdef _WIN32
m_Controltype[i] = new wxComboBox(m_Controller[i], IDC_CONTROLTYPE, wxEmptyString, wxDefaultPosition, wxSize(131, 21), arrayStringFor_Controltype, 0, wxDefaultValidator, wxT("m_Controltype"));
#else
m_Controltype[i] = new wxComboBox(m_Controller[i], IDC_CONTROLTYPE, wxEmptyString, wxDefaultPosition, wxSize(150, 25), arrayStringFor_Controltype, 0, wxDefaultValidator, wxT("m_Controltype"));
#endif
m_Controltype[i] = new wxComboBox(m_Controller[i], IDC_CONTROLTYPE, arrayStringFor_Controltype[0], wxDefaultPosition, wxDefaultSize, arrayStringFor_Controltype, wxCB_READONLY);
m_gControllertype[i]->Add(m_Controltype[i], 0, wxEXPAND | wxALL, 3);
// Populate input status
/*
m_gStatusIn[i] = new wxStaticBoxSizer( wxVERTICAL, m_Controller[i], wxT("In"));
CreateAdvancedControls(i);
m_gStatusIn[i]->Add(m_pInStatus[i], 0, wxALL, 0);
*/
// Populate general settings
m_gGenSettings[i] = new wxStaticBoxSizer( wxVERTICAL, m_Controller[i], wxT("Settings") );
m_CBSaveByID[i] = new wxCheckBox(m_Controller[i], IDC_SAVEBYID, wxT("Save by ID"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
m_CBShowAdvanced[i] = new wxCheckBox(m_Controller[i], IDC_SHOWADVANCED, wxT("Show advanced settings"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
m_gGenSettings[i]->Add(m_CBSaveByID[i], 0, wxEXPAND | wxALL, 3);
m_gGenSettings[i]->Add(m_CBShowAdvanced[i], 0, wxEXPAND | wxALL, 3);
m_CBSaveByID[i]->SetToolTip(wxString::Format(wxT(
"Map these settings to the selected controller device instead of to the"
"\nselected controller number (%i). This may be a more convenient way"
"\nto save your settings if you have multiple controllers.")
, i+1
));
// Populate settings
m_sSettings[i] = new wxBoxSizer ( wxHORIZONTAL );
m_sSettings[i]->Add(m_gExtrasettings[i], 0, wxEXPAND | wxALL, 0);
m_sSettings[i]->Add(m_gControllertype[i], 0, wxEXPAND | wxLEFT, 5);
//m_sSettings[i]->Add(m_gStatusIn[i], 0, wxLEFT, 5);
m_sSettings[i]->Add(m_gGenSettings[i], 0, wxEXPAND | wxLEFT, 5);
//////////////////////////////////////
// Populate advanced settings
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
// Populate input status
/**/
// Input status text
m_TStatusIn[i] = new wxStaticText(m_Controller[i], IDT_STATUS_IN, wxT("In"));
m_TStatusOut[i] = new wxStaticText(m_Controller[i], IDT_STATUS_OUT, wxT("Out"));
m_gStatusIn[i] = new wxStaticBoxSizer( wxHORIZONTAL, m_Controller[i], wxT("Main-stick (In) (Out)"));
CreateAdvancedControls(i);
m_GBAdvancedMainStick[i] = new wxGridBagSizer(0, 0);
m_GBAdvancedMainStick[i]->Add(m_pInStatus[i], wxGBPosition(0, 0), wxGBSpan(1, 1), wxALL, 0);
m_GBAdvancedMainStick[i]->Add(m_pOutStatus[i], wxGBPosition(0, 1), wxGBSpan(1, 1), wxLEFT, 5);
m_GBAdvancedMainStick[i]->Add(m_TStatusIn[i], wxGBPosition(1, 0), wxGBSpan(1, 1), wxALL, 0);
m_GBAdvancedMainStick[i]->Add(m_TStatusOut[i], wxGBPosition(1, 1), wxGBSpan(1, 1), wxLEFT, 5);
m_gStatusIn[i]->Add(m_GBAdvancedMainStick[i], 0, wxLEFT, 5);
// Populate input status settings
// The label
m_STDiagonal[i] = new wxStaticText(m_Controller[i], IDT_MAINSTICK_DIAGONAL, wxT("Diagonal"));
m_STDiagonal[i]->SetToolTip(wxT(
"To produce a smooth circle in the 'Out' window you have to manually set"
"\nyour diagonal values here from the 'In' window."
));
// The drop down menu
m_gStatusInSettings[i] = new wxStaticBoxSizer( wxVERTICAL, m_Controller[i], wxT("Main-stick settings"));
m_gStatusInSettingsH[i] = new wxBoxSizer(wxHORIZONTAL);
wxArrayString asStatusInSet;
asStatusInSet.Add(wxT("100%"));
asStatusInSet.Add(wxT("95%"));
asStatusInSet.Add(wxT("90%"));
asStatusInSet.Add(wxT("85%"));
m_CoBDiagonal[i] = new wxComboBox(m_Controller[i], IDCB_MAINSTICK_DIAGONAL, asStatusInSet[0], wxDefaultPosition, wxDefaultSize, asStatusInSet, wxCB_READONLY);
// The checkbox
m_CBS_to_C[i] = new wxCheckBox(m_Controller[i], IDCB_MAINSTICK_S_TO_C, wxT("Square-to-circle"));
m_gStatusInSettings[i]->Add(m_CBS_to_C[i], 0, (wxALL), 4);
m_gStatusInSettings[i]->Add(m_gStatusInSettingsH[i], 0, (wxLEFT | wxRIGHT | wxBOTTOM), 4);
m_gStatusInSettingsH[i]->Add(m_STDiagonal[i], 0, wxTOP, 3);
m_gStatusInSettingsH[i]->Add(m_CoBDiagonal[i], 0, wxLEFT, 3);
//////////////////////////////////////
// Populate sizers
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
// --------------------------------------------------------------------
// Populate main left sizer
// -----------------------------
m_sMainLeft[i] = new wxBoxSizer(wxVERTICAL);
m_sMainLeft[i]->Add(m_gJoyname[i], 0, wxEXPAND | (wxALL), 5);
m_sMainLeft[i]->Add(m_sKeys[i], 1, wxEXPAND | (wxLEFT | wxRIGHT), 5);
m_sMainLeft[i]->Add(m_sSettings[i], 0, wxEXPAND | (wxALL), 5);
// --------------------------------------------------------------------
// Populate main right sizer
// -----------------------------
m_sMainRight[i] = new wxBoxSizer(wxVERTICAL);
m_sMainRight[i]->Add(m_gStatusIn[i], 0, wxEXPAND | (wxLEFT), 2);
m_sMainRight[i]->Add(m_gStatusInSettings[i], 0, wxEXPAND | (wxLEFT | wxTOP), 2);
// --------------------------------------------------------------------
// Populate main sizer
// -----------------------------
m_sMain[i] = new wxBoxSizer(wxVERTICAL);
m_sMain[i]->Add(m_gJoyname[i], 0, wxEXPAND | (wxALL), 5);
m_sMain[i]->Add(m_sKeys[i], 1, wxEXPAND | (wxLEFT | wxRIGHT), 5);
m_sMain[i]->Add(m_sSettings[i], 0, wxEXPAND | (wxALL), 5);
m_sMain[i] = new wxBoxSizer(wxHORIZONTAL);
m_sMain[i]->Add(m_sMainLeft[i], 0, wxEXPAND | (wxALL), 0);
m_sMain[i]->Add(m_sMainRight[i], 0, wxEXPAND | (wxRIGHT | wxTOP), 5);
m_Controller[i]->SetSizer(m_sMain[i]); // Set the main sizer
// Show or hide it. We have to do this after we add it to its sizer
m_sMainRight[i]->Show(g_Config.bShowAdvanced);
// Disable when running
// Don't allow these changes when running
if(emulator_running)
{
m_Joyname[i]->Enable(false);
@ -399,8 +659,11 @@ void ConfigBox::CreateGUIControls()
m_Controltype[i]->Enable(false);
}
// Set dialog items
// Set dialog items from saved values
SetControllerAll(i);
// Update GUI
DoEnableDisable(i);
} // end of loop
@ -417,516 +680,26 @@ void ConfigBox::CreateGUIControls()
// --------------------------------------------------------------------
// Populate master sizer.
// -----------------------------
wxBoxSizer * m_MainSizer = new wxBoxSizer(wxVERTICAL);
m_MainSizer = new wxBoxSizer(wxVERTICAL);
m_MainSizer->Add(m_Notebook, 0, wxEXPAND | wxALL, 5);
m_MainSizer->Add(m_sButtons, 1, wxEXPAND | ( wxLEFT | wxRIGHT | wxBOTTOM), 5);
this->SetSizer(m_MainSizer);
// --------------------------------------------------------------------
// Debugging
// -----------------------------
//m_pStatusBar = new wxStaticText(this, IDT_DEBUGGING, wxT("Debugging"), wxPoint(100, 510), wxDefaultSize);
//m_pStatusBar2 = new wxStaticText(this, IDT_DEBUGGING2, wxT("Debugging2"), wxPoint(100, 530), wxDefaultSize);
//m_pStatusBar->SetLabel(wxString::Format("Debugging text"));
// --------------------------------------------------------------------
// Set window size
SetClientSize(m_MainSizer->GetMinSize().GetWidth(), m_MainSizer->GetMinSize().GetHeight());
// -----------------------------
SizeWindow();
Center();
}
// Close window
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
void ConfigBox::OnClose(wxCloseEvent& /*event*/)
void ConfigBox::SizeWindow()
{
EndModal(0);
}
// Call about dialog
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
void ConfigBox::AboutClick(wxCommandEvent& event)
{
#ifdef _WIN32
wxWindow win;
win.SetHWND((WXHWND)this->GetHWND());
win.Enable(false);
AboutBox frame(&win);
frame.ShowModal();
win.Enable(true);
win.SetHWND(0);
#else
AboutBox frame(NULL);
frame.ShowModal();
#endif
}
void ConfigBox::OKClick(wxCommandEvent& event)
{
if (event.GetId() == ID_OK)
{
for(int i=0; i<4 ;i++)
GetControllerAll(i);
SaveConfig(); // save settings
LoadConfig(); // reload settings
Close();
}
}
void ConfigBox::CancelClick(wxCommandEvent& event)
{
if (event.GetId() == ID_CANCEL)
{
LoadConfig(); // reload settings
Close();
}
}
// Set dialog items
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
void ConfigBox::SetControllerAll(int controller)
{
// http://wiki.wxwidgets.org/Converting_everything_to_and_from_wxString
wxString tmp;
m_Joyname[controller]->SetSelection(joysticks[controller].ID);
tmp << joysticks[controller].buttons[CTL_L_SHOULDER]; m_JoyShoulderL[controller]->SetValue(tmp); tmp.clear();
tmp << joysticks[controller].buttons[CTL_R_SHOULDER]; m_JoyShoulderR[controller]->SetValue(tmp); tmp.clear();
tmp << joysticks[controller].buttons[CTL_A_BUTTON]; m_JoyButtonA[controller]->SetValue(tmp); tmp.clear();
tmp << joysticks[controller].buttons[CTL_B_BUTTON]; m_JoyButtonB[controller]->SetValue(tmp); tmp.clear();
tmp << joysticks[controller].buttons[CTL_X_BUTTON]; m_JoyButtonX[controller]->SetValue(tmp); tmp.clear();
tmp << joysticks[controller].buttons[CTL_Y_BUTTON]; m_JoyButtonY[controller]->SetValue(tmp); tmp.clear();
tmp << joysticks[controller].buttons[CTL_Z_TRIGGER]; m_JoyButtonZ[controller]->SetValue(tmp); tmp.clear();
tmp << joysticks[controller].buttons[CTL_START]; m_JoyButtonStart[controller]->SetValue(tmp); tmp.clear();
tmp << joysticks[controller].halfpress; m_JoyButtonHalfpress[controller]->SetValue(tmp); tmp.clear();
tmp << joysticks[controller].axis[CTL_MAIN_X]; m_JoyAnalogMainX[controller]->SetValue(tmp); tmp.clear();
tmp << joysticks[controller].axis[CTL_MAIN_Y]; m_JoyAnalogMainY[controller]->SetValue(tmp); tmp.clear();
tmp << joysticks[controller].axis[CTL_SUB_X]; m_JoyAnalogSubX[controller]->SetValue(tmp); tmp.clear();
tmp << joysticks[controller].axis[CTL_SUB_Y]; m_JoyAnalogSubY[controller]->SetValue(tmp); tmp.clear();
if(joysticks[controller].enabled)
m_Joyattach[controller]->SetValue(TRUE);
else
m_Joyattach[controller]->SetValue(FALSE);
m_Controltype[controller]->SetSelection(joysticks[controller].controllertype);
m_Deadzone[controller]->SetSelection(joysticks[controller].deadzone);
UpdateVisibleItems(controller);
if(joysticks[controller].controllertype == CTL_TYPE_JOYSTICK)
{
tmp << joysticks[controller].dpad; m_JoyDpadUp[controller]->SetValue(tmp); tmp.clear();
}
else
{
tmp << joysticks[controller].dpad2[CTL_D_PAD_UP]; m_JoyDpadUp[controller]->SetValue(tmp); tmp.clear();
tmp << joysticks[controller].dpad2[CTL_D_PAD_DOWN]; m_JoyDpadDown[controller]->SetValue(tmp); tmp.clear();
tmp << joysticks[controller].dpad2[CTL_D_PAD_LEFT]; m_JoyDpadLeft[controller]->SetValue(tmp); tmp.clear();
tmp << joysticks[controller].dpad2[CTL_D_PAD_RIGHT]; m_JoyDpadRight[controller]->SetValue(tmp); tmp.clear();
}
}
// Get dialog items. Collect button identification.
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
void ConfigBox::GetControllerAll(int controller)
{
wxString tmp;
long value;
joysticks[controller].ID = m_Joyname[controller]->GetSelection();
m_JoyShoulderL[controller]->GetValue().ToLong(&value); joysticks[controller].buttons[CTL_L_SHOULDER] = value; tmp.clear();
m_JoyShoulderR[controller]->GetValue().ToLong(&value); joysticks[controller].buttons[CTL_R_SHOULDER] = value; tmp.clear();
m_JoyButtonA[controller]->GetValue().ToLong(&value); joysticks[controller].buttons[CTL_A_BUTTON] = value; tmp.clear();
m_JoyButtonB[controller]->GetValue().ToLong(&value); joysticks[controller].buttons[CTL_B_BUTTON] = value; tmp.clear();
m_JoyButtonX[controller]->GetValue().ToLong(&value); joysticks[controller].buttons[CTL_X_BUTTON] = value; tmp.clear();
m_JoyButtonY[controller]->GetValue().ToLong(&value); joysticks[controller].buttons[CTL_Y_BUTTON] = value; tmp.clear();
m_JoyButtonZ[controller]->GetValue().ToLong(&value); joysticks[controller].buttons[CTL_Z_TRIGGER] = value; tmp.clear();
m_JoyButtonStart[controller]->GetValue().ToLong(&value); joysticks[controller].buttons[CTL_START] = value; tmp.clear();
m_JoyButtonHalfpress[controller]->GetValue().ToLong(&value); joysticks[controller].halfpress = value; tmp.clear();
if(joysticks[controller].controllertype == CTL_TYPE_JOYSTICK)
{
m_JoyDpadUp[controller]->GetValue().ToLong(&value); joysticks[controller].dpad = value; tmp.clear();
}
else
{
m_JoyDpadUp[controller]->GetValue().ToLong(&value); joysticks[controller].dpad2[CTL_D_PAD_UP] = value; tmp.clear();
m_JoyDpadDown[controller]->GetValue().ToLong(&value); joysticks[controller].dpad2[CTL_D_PAD_DOWN] = value; tmp.clear();
m_JoyDpadLeft[controller]->GetValue().ToLong(&value); joysticks[controller].dpad2[CTL_D_PAD_LEFT] = value; tmp.clear();
m_JoyDpadRight[controller]->GetValue().ToLong(&value); joysticks[controller].dpad2[CTL_D_PAD_RIGHT] = value; tmp.clear();
}
m_JoyAnalogMainX[controller]->GetValue().ToLong(&value); joysticks[controller].axis[CTL_MAIN_X] = value; tmp.clear();
m_JoyAnalogMainY[controller]->GetValue().ToLong(&value); joysticks[controller].axis[CTL_MAIN_Y] = value; tmp.clear();
m_JoyAnalogSubX[controller]->GetValue().ToLong(&value); joysticks[controller].axis[CTL_SUB_X] = value; tmp.clear();
m_JoyAnalogSubY[controller]->GetValue().ToLong(&value); joysticks[controller].axis[CTL_SUB_Y] = value; tmp.clear();
joysticks[controller].enabled = m_Joyattach[controller]->GetValue();
joysticks[controller].controllertype = m_Controltype[controller]->GetSelection();
joysticks[controller].deadzone = m_Deadzone[controller]->GetSelection();
}
void ConfigBox::UpdateVisibleItems(int controller)
{
if(joysticks[controller].controllertype)
{
m_JoyDpadDown[controller]->Show(TRUE);
m_JoyDpadLeft[controller]->Show(TRUE);
m_JoyDpadRight[controller]->Show(TRUE);
m_bJoyDpadDown[controller]->Show(TRUE);
m_bJoyDpadLeft[controller]->Show(TRUE);
m_bJoyDpadRight[controller]->Show(TRUE);
m_textDpadUp[controller]->Show(TRUE);
m_textDpadDown[controller]->Show(TRUE);
m_textDpadLeft[controller]->Show(TRUE);
m_textDpadRight[controller]->Show(TRUE);
}
else
{
m_JoyDpadDown[controller]->Show(FALSE);
m_JoyDpadLeft[controller]->Show(FALSE);
m_JoyDpadRight[controller]->Show(FALSE);
m_bJoyDpadDown[controller]->Show(FALSE);
m_bJoyDpadLeft[controller]->Show(FALSE);
m_bJoyDpadRight[controller]->Show(FALSE);
m_textDpadUp[controller]->Show(FALSE);
m_textDpadDown[controller]->Show(FALSE);
m_textDpadLeft[controller]->Show(FALSE);
m_textDpadRight[controller]->Show(FALSE);
}
}
void ConfigBox::ChangeJoystick(wxCommandEvent& event)
{
joysticks[0].ID = m_Joyname[0]->GetSelection();
joysticks[1].ID = m_Joyname[1]->GetSelection();
joysticks[2].ID = m_Joyname[2]->GetSelection();
joysticks[3].ID = m_Joyname[3]->GetSelection();
}
void ConfigBox::ChangeControllertype(wxCommandEvent& event)
{
joysticks[0].controllertype = m_Controltype[0]->GetSelection();
joysticks[1].controllertype = m_Controltype[1]->GetSelection();
joysticks[2].controllertype = m_Controltype[2]->GetSelection();
joysticks[3].controllertype = m_Controltype[3]->GetSelection();
for(int i=0; i<4 ;i++) UpdateVisibleItems(i);
}
void ConfigBox::NotebookPageChanged(wxNotebookEvent& event)
{
notebookpage = event.GetSelection();
}
void ConfigBox::SetButtonText(int id, char text[128])
{
int controller = notebookpage;
switch(id)
{
case IDB_SHOULDER_L:
{
m_JoyShoulderL[controller]->SetValue(wxString::FromAscii(text));
}
break;
case IDB_SHOULDER_R:
{
m_JoyShoulderR[controller]->SetValue(wxString::FromAscii(text));
}
break;
case IDB_BUTTON_A:
{
m_JoyButtonA[controller]->SetValue(wxString::FromAscii(text));
}
break;
case IDB_BUTTON_B:
{
m_JoyButtonB[controller]->SetValue(wxString::FromAscii(text));
}
break;
case IDB_BUTTON_X:
{
m_JoyButtonX[controller]->SetValue(wxString::FromAscii(text));
}
break;
case IDB_BUTTON_Y:
{
m_JoyButtonY[controller]->SetValue(wxString::FromAscii(text));
}
break;
case IDB_BUTTON_Z:
{
m_JoyButtonZ[controller]->SetValue(wxString::FromAscii(text));
}
break;
case IDB_BUTTONSTART:
{
m_JoyButtonStart[controller]->SetValue(wxString::FromAscii(text));
}
break;
case IDB_BUTTONHALFPRESS:
{
m_JoyButtonHalfpress[controller]->SetValue(wxString::FromAscii(text));
}
break;
case IDB_DPAD_UP:
{
m_JoyDpadUp[controller]->SetValue(wxString::FromAscii(text));
}
break;
case IDB_DPAD_DOWN:
{
m_JoyDpadDown[controller]->SetValue(wxString::FromAscii(text));
}
break;
case IDB_DPAD_LEFT:
{
m_JoyDpadLeft[controller]->SetValue(wxString::FromAscii(text));
}
break;
case IDB_DPAD_RIGHT:
{
m_JoyDpadRight[controller]->SetValue(wxString::FromAscii(text));
}
break;
case IDB_ANALOG_MAIN_X:
{
m_JoyAnalogMainX[controller]->SetValue(wxString::FromAscii(text));
}
break;
case IDB_ANALOG_MAIN_Y:
{
m_JoyAnalogMainY[controller]->SetValue(wxString::FromAscii(text));
}
break;
case IDB_ANALOG_SUB_X:
{
m_JoyAnalogSubX[controller]->SetValue(wxString::FromAscii(text));
}
break;
case IDB_ANALOG_SUB_Y:
{
m_JoyAnalogSubY[controller]->SetValue(wxString::FromAscii(text));
}
break;
default:
break;
}
}
// Wait for button press
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
void ConfigBox::GetButtons(wxCommandEvent& event)
{
int ID = event.GetId();
int controller = notebookpage;
// DPAD type check!
if(ID == IDB_DPAD_UP)
if(joysticks[controller].controllertype == 0)
{
GetHats(ID);
return;
}
SDL_Joystick *joy = SDL_JoystickOpen(joysticks[controller].ID);
char format[128];
int buttons = SDL_JoystickNumButtons(joy);
bool waiting = true;
bool succeed = false;
int pressed = 0;
int counter1 = 0;
int counter2 = 10;
sprintf(format, "[%d]", counter2);
SetButtonText(ID, format);
wxWindow::Update(); // win only? doesnt seem to work in linux...
while(waiting)
{
SDL_JoystickUpdate();
for(int b = 0; b < buttons; b++)
{
if(SDL_JoystickGetButton(joy, b))
{
pressed = b;
waiting = false;
succeed = true;
break;
}
}
counter1++;
if(counter1==100)
{
counter1=0;
counter2--;
sprintf(format, "[%d]", counter2);
SetButtonText(ID, format);
wxWindow::Update(); // win only? doesnt seem to work in linux...
if(counter2<0)
waiting = false;
}
SLEEP(10);
}
sprintf(format, "%d", succeed ? pressed : -1);
SetButtonText(ID, format);
if(SDL_JoystickOpened(joysticks[controller].ID))
SDL_JoystickClose(joy);
}
// Wait for D-Pad
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯
void ConfigBox::GetHats(int ID)
{
int controller = notebookpage;
SDL_Joystick *joy;
joy=SDL_JoystickOpen(joysticks[controller].ID);
char format[128];
int hats = SDL_JoystickNumHats(joy);
bool waiting = true;
bool succeed = false;
int pressed = 0;
int counter1 = 0;
int counter2 = 10;
sprintf(format, "[%d]", counter2);
SetButtonText(ID, format);
wxWindow::Update(); // win only? doesnt seem to work in linux...
while(waiting)
{
SDL_JoystickUpdate();
for(int b = 0; b < hats; b++)
{
if(SDL_JoystickGetHat(joy, b))
{
pressed = b;
waiting = false;
succeed = true;
break;
}
}
counter1++;
if(counter1==100)
{
counter1=0;
counter2--;
sprintf(format, "[%d]", counter2);
SetButtonText(ID, format);
wxWindow::Update(); // win only? doesnt seem to work in linux...
if(counter2<0)
waiting = false;
}
SLEEP(10);
}
sprintf(format, "%d", succeed ? pressed : -1);
SetButtonText(ID, format);
if(SDL_JoystickOpened(joysticks[controller].ID))
SDL_JoystickClose(joy);
}
// Wait for Analog
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
void ConfigBox::GetAxis(wxCommandEvent& event)
{
int ID = event.GetId();
int controller = notebookpage;
SDL_Joystick *joy;
joy=SDL_JoystickOpen(joysticks[controller].ID);
char format[128];
int axes = SDL_JoystickNumAxes(joy);
bool waiting = true;
bool succeed = false;
int pressed = 0;
Sint16 value;
int counter1 = 0;
int counter2 = 10;
sprintf(format, "[%d]", counter2);
SetButtonText(ID, format);
wxWindow::Update(); // win only? doesnt seem to work in linux...
while(waiting)
{
SDL_JoystickUpdate();
for(int b = 0; b < axes; b++)
{
value = SDL_JoystickGetAxis(joy, b);
if(value < -10000 || value > 10000)
{
pressed = b;
waiting = false;
succeed = true;
break;
}
}
counter1++;
if(counter1==100)
{
counter1=0;
counter2--;
sprintf(format, "[%d]", counter2);
SetButtonText(ID, format);
wxWindow::Update(); // win only? doesnt seem to work in linux...
if(counter2<0)
waiting = false;
}
SLEEP(10);
}
sprintf(format, "%d", succeed ? pressed : -1);
SetButtonText(ID, format);
if(SDL_JoystickOpened(joysticks[controller].ID))
SDL_JoystickClose(joy);
SetClientSize(m_MainSizer->GetMinSize().GetWidth(), m_MainSizer->GetMinSize().GetHeight());
}

View File

@ -66,18 +66,30 @@ class ConfigBox : public wxDialog
wxTimer m_timer;
#endif
// Debugging
wxStaticText* m_pStatusBar, * m_pStatusBar2;
// Status window
int BoxW, BoxH;
private:
wxButton *m_About;
wxButton *m_OK;
wxButton *m_Cancel;
wxPanel *m_Controller[4];
wxPanel *m_Controller[4]; // Main containers
wxNotebook *m_Notebook;
wxBoxSizer * m_MainSizer;
wxPanel * m_pKeys[4], * m_pInStatus[4];
wxBitmap WxStaticBitmap1_BITMAP;
wxPanel * m_pKeys[4], * m_pInStatus[4], * m_pOutStatus[4];
wxBitmap WxStaticBitmap1_BITMAP, WxStaticBitmap1_BITMAPGray;
wxStaticBoxSizer * m_sKeys[4];
wxBoxSizer * m_sMain[4], * m_sSettings[4];
wxBoxSizer *m_sMain[4], *m_sMainLeft[4], *m_sMainRight[4];
/////////////////////////////
// Settings
// ¯¯¯¯¯¯¯¯¯
wxComboBox *m_Joyname[4];
wxComboBox *m_Controltype[4];
@ -86,9 +98,24 @@ class ConfigBox : public wxDialog
wxCheckBox *m_Joyattach[4];
wxStaticBoxSizer *m_gJoyname[4];
wxStaticBoxSizer *m_gExtrasettings[4]; wxGridBagSizer * m_gGBExtrasettings[4]; // Settings
wxBoxSizer* m_sSettings[4]; // Settings
wxStaticBoxSizer *m_gExtrasettings[4]; wxGridBagSizer * m_gGBExtrasettings[4]; // Extra settings
wxStaticBoxSizer *m_gControllertype[4];
wxStaticBoxSizer *m_gStatusIn[4];
wxStaticBoxSizer *m_gGenSettings[4]; // General settings
wxCheckBox *m_CBSaveByID[4], *m_CBShowAdvanced[4];
wxStaticBoxSizer *m_gStatusIn[4], *m_gStatusInSettings[4]; // Advanced settings
wxBoxSizer *m_gStatusInSettingsH[4];
wxGridBagSizer * m_GBAdvancedMainStick[4];
wxStaticText *m_TStatusIn[4], *m_TStatusOut[4];
wxComboBox *m_CoBDiagonal[4]; wxCheckBox *m_CBS_to_C[4]; wxStaticText *m_STDiagonal[4];
/////////////////////////////
// Keys
// ¯¯¯¯¯¯¯¯¯
wxTextCtrl *m_JoyShoulderL[4];
wxTextCtrl *m_JoyShoulderR[4];
@ -145,7 +172,8 @@ class ConfigBox : public wxDialog
wxStaticText *m_textWebsite[4];
wxTextCtrl *m_PlaceholderBMP[4];
wxStaticBitmap *m_controllerimage[4], *m_bmpSquare[4], *m_bmpDot[4];
wxStaticBitmap *m_controllerimage[4],
*m_bmpSquare[4], *m_bmpDot[4], *m_bmpSquareOut[4], *m_bmpDotOut[4];
int notebookpage;
private:
@ -159,23 +187,32 @@ class ConfigBox : public wxDialog
ID_CONTROLLERPAGE2,
ID_CONTROLLERPAGE3,
ID_CONTROLLERPAGE4,
ID_INSTATUS1, ID_INSTATUS2, ID_INSTATUS3, ID_INSTATUS4, // Advanced status
ID_CONTROLLERPICTURE, // Background picture
ID_KEYSPANEL1, ID_KEYSPANEL2, ID_KEYSPANEL3, ID_KEYSPANEL4,
IDC_JOYNAME,
IDC_CONTROLTYPE,
IDC_DEADZONE,
IDG_JOYSTICK, IDC_JOYNAME, IDC_JOYATTACH, // Controller attached
IDC_JOYATTACH,
IDG_JOYSTICK,
IDG_EXTRASETTINGS,
IDG_CONTROLLERTYPE,
ID_CONTROLLERPICTURE,
IDG_EXTRASETTINGS, IDC_DEADZONE, // Extra settings
IDG_CONTROLLERTYPE, IDC_CONTROLTYPE, // Controller type
IDC_SAVEBYID, IDC_SHOWADVANCED, // Settings
ID_INSTATUS1, ID_INSTATUS2, ID_INSTATUS3, ID_INSTATUS4, // Advanced status
ID_STATUSBMP1, ID_STATUSBMP2, ID_STATUSBMP3, ID_STATUSBMP4,
ID_STATUSDOTBMP1, ID_STATUSDOTBMP2, ID_STATUSDOTBMP3, ID_STATUSDOTBMP4,
IDT_STATUS_IN, IDT_STATUS_OUT,
// Advaced settings
IDCB_MAINSTICK_DIAGONAL, IDCB_MAINSTICK_S_TO_C, IDT_MAINSTICK_DIAGONAL,
// --------------------------------------------------------------------
// Keys objects
// -----------------------------
// Text controls
ID_SHOULDER_L = 2000,
ID_SHOULDER_R,
@ -197,6 +234,7 @@ class ConfigBox : public wxDialog
ID_DPAD_LEFT,
ID_DPAD_RIGHT,
// Buttons controls
IDB_SHOULDER_L = 3000,
IDB_SHOULDER_R,
@ -218,6 +256,7 @@ class ConfigBox : public wxDialog
IDB_DPAD_LEFT,
IDB_DPAD_RIGHT,
// Text controls
IDT_ANALOG_MAIN_X = 4000,
IDT_ANALOG_MAIN_Y,
IDT_DPAD_UP,
@ -229,6 +268,7 @@ class ConfigBox : public wxDialog
IDT_ANALOG_SUB_X,
IDT_ANALOG_SUB_Y,
IDT_WEBSITE,
IDT_DEBUGGING, IDT_DEBUGGING2,
ID_DUMMY_VALUE_ //don't remove this value unless you have other enum values
};
@ -240,9 +280,14 @@ class ConfigBox : public wxDialog
void ChangeJoystick(wxCommandEvent& event);
void ChangeControllertype(wxCommandEvent& event);
void EnableDisable(wxCommandEvent& event); void DoEnableDisable(int _notebookpage);
void ChangeSettings(wxCommandEvent& event); // Settings
void ComboChange(wxCommandEvent& event);
void OnClose(wxCloseEvent& event);
void CreateGUIControls(); void CreateAdvancedControls(int i);
void SizeWindow();
wxBitmap CreateBitmap(); wxBitmap CreateBitmapDot();
void PadGetStatus(); void Update();

View File

@ -143,7 +143,7 @@ void PAD_Rumble(u8 _numPAD, unsigned int _uType, unsigned int _uStrength)
// Use PAD rumble
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯
void PAD_Use_Rumble(u8 _numPAD, SPADStatus* _pPADStatus)
void Pad_Use_Rumble(u8 _numPAD, SPADStatus* _pPADStatus)
{
#ifdef _WIN32
#ifdef USE_RUMBLE_DINPUT_HACK

View File

@ -19,6 +19,7 @@ if padenv['HAVE_WX']:
files += [
'GUI/AboutBox.cpp',
'GUI/ConfigAdvanced.cpp',
'GUI/ConfigJoypad.cpp',
'GUI/ConfigBox.cpp',
]

View File

@ -1,6 +1,6 @@
//////////////////////////////////////////////////////////////////////////////////////////
// Project description
//
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
// Name: nJoy
// Description: A Dolphin Compatible Input Plugin
//
@ -30,18 +30,42 @@
//////////////////////////////////////////////////////////////////////////////////////////
////////////////////////
////////////////////////////////////////////////////////////////////////////////////////
// Variables guide
/* ¯¯¯¯¯¯¯¯¯
The arrays joysticks[] and joystate[] are numbered 0 to 3 for the four different virtual
controllers. Joysticks[].ID will have the number of the inputs device mapped to that controller,
this value can be between 0 and the total number of connected physical devices. The mapping
is done by PAD_Initialize(), if we want to change that we have to run PAD_Shutdown() and then
run PAD_Initialize() again.
The joyinfo[] array is for a certain physical device. It's therefore used as
joyinfo[joysticks[controller].ID].
////////////////////////*/
//////////////////////////////////////////////////////////////////////////////////////////
// Include
//
// ¯¯¯¯¯¯¯¯¯
#include "nJoy.h"
// Declare config window so that we can write debugging info to it from functions in this file
#if defined(HAVE_WX) && HAVE_WX
ConfigBox* m_frame;
#endif
/////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
// Variables
//
// ¯¯¯¯¯¯¯¯¯
// Rumble in windows
#define _CONTROLLER_STATE_H // avoid certain declarations in nJoy.h
#define _CONTROLLER_STATE_H // Avoid certain declarations in nJoy.h
FILE *pFile;
HINSTANCE nJoy_hInst = NULL;
CONTROLLER_INFO *joyinfo = 0;
@ -64,7 +88,7 @@ void __Logv(int log, int v, const char *format, ...) {}
//////////////////////////////////////////////////////////////////////////////////////////
// wxWidgets
//
// ¯¯¯¯¯¯¯¯¯
#if defined(HAVE_WX) && HAVE_WX
class wxDLLApp : public wxApp
{
@ -81,7 +105,7 @@ void __Logv(int log, int v, const char *format, ...) {}
//////////////////////////////////////////////////////////////////////////////////////////
// DllMain
//
// ¯¯¯¯¯¯¯
#ifdef _WIN32
BOOL APIENTRY DllMain( HINSTANCE hinstDLL, // DLL module handle
DWORD dwReason, // reason called
@ -117,10 +141,10 @@ BOOL APIENTRY DllMain( HINSTANCE hinstDLL, // DLL module handle
//////////////////////////////////////////////////////////////////////////////////////////
// Input Plugin Functions (from spec's)
//
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
// Get properties of plugin
//
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
void GetDllInfo(PLUGIN_INFO* _PluginInfo)
{
_PluginInfo->Version = 0x0100;
@ -138,7 +162,7 @@ void GetDllInfo(PLUGIN_INFO* _PluginInfo)
}
// Call config dialog
//
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
void DllConfig(HWND _hParent)
{
#ifdef _WIN32
@ -148,13 +172,26 @@ void DllConfig(HWND _hParent)
return;
}
LoadConfig(); // load settings
// Start the pads so we can use them in the configuration and advanced controls
if(!emulator_running)
{
SPADInitialize _PADInitialize;
_PADInitialize.hWnd = NULL;
_PADInitialize.pLog = NULL;
PAD_Initialize(_PADInitialize);
emulator_running = FALSE; // Set it back to false
}
wxWindow win;
win.SetHWND(_hParent);
ConfigBox frame(&win);
frame.ShowModal();
win.SetHWND(0);
g_Config.Load(); // Load settings
// We don't need a parent for this wxDialog
//wxWindow win;
//win.SetHWND(_hParent);
//ConfigBox frame(&win);
//win.SetHWND(0);
m_frame = new ConfigBox(NULL);
m_frame->ShowModal();
#else
if (SDL_Init(SDL_INIT_JOYSTICK ) < 0)
@ -163,7 +200,7 @@ void DllConfig(HWND _hParent)
return;
}
LoadConfig(); // load settings
g_Config.Load(); // load settings
#if defined(HAVE_WX) && HAVE_WX
ConfigBox frame(NULL);
@ -176,8 +213,9 @@ void DllConfig(HWND _hParent)
void DllDebugger(HWND _hParent, bool Show) {
}
// Init PAD (start emulation)
//
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
void PAD_Initialize(SPADInitialize _PADInitialize)
{
emulator_running = TRUE;
@ -199,8 +237,8 @@ void PAD_Initialize(SPADInitialize _PADInitialize)
m_hWnd = (HWND)_PADInitialize.hWnd;
#endif
LoadConfig(); // Load joystick mapping
Search_Devices();
Search_Devices(); // Populate joyinfo for all attached devices
g_Config.Load(); // Load joystick mapping, joysticks[].ID etc
if (joysticks[0].enabled)
joystate[0].joy = SDL_JoystickOpen(joysticks[0].ID);
if (joysticks[1].enabled)
@ -211,8 +249,74 @@ void PAD_Initialize(SPADInitialize _PADInitialize)
joystate[3].joy = SDL_JoystickOpen(joysticks[3].ID);
}
// Search attached devices. Populate joyinfo for all attached physical devices.
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
int Search_Devices()
{
// load config
#ifdef _DEBUG
DEBUG_INIT();
#endif
int numjoy = SDL_NumJoysticks();
if (joyinfo)
{
delete [] joyinfo;
joyinfo = new CONTROLLER_INFO [numjoy];
}
else
{
joyinfo = new CONTROLLER_INFO [numjoy];
}
// Warn the user if no joysticks are detected
if (numjoy == 0)
{
#ifdef _WIN32
//MessageBox(NULL, "No Joystick detected!", NULL, MB_ICONWARNING);
#else
printf("No Joystick detected!\n");
#endif
return 0;
}
#ifdef _DEBUG
fprintf(pFile, "Scanning for devices\n");
fprintf(pFile, "¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯\n");
#endif
for(int i = 0; i < numjoy; i++ )
{
// Open the device to be able to read the values
joyinfo[i].joy = SDL_JoystickOpen(i);
joyinfo[i].ID = i;
joyinfo[i].NumAxes = SDL_JoystickNumAxes(joyinfo[i].joy);
joyinfo[i].NumButtons = SDL_JoystickNumButtons(joyinfo[i].joy);
joyinfo[i].NumBalls = SDL_JoystickNumBalls(joyinfo[i].joy);
joyinfo[i].NumHats = SDL_JoystickNumHats(joyinfo[i].joy);
joyinfo[i].Name = SDL_JoystickName(i);
#ifdef _DEBUG
fprintf(pFile, "ID: %d\n", i);
fprintf(pFile, "Name: %s\n", joyinfo[i].Name);
fprintf(pFile, "Buttons: %d\n", joyinfo[i].NumButtons);
fprintf(pFile, "Axes: %d\n", joyinfo[i].NumAxes);
fprintf(pFile, "Hats: %d\n", joyinfo[i].NumHats);
fprintf(pFile, "Balls: %d\n\n", joyinfo[i].NumBalls);
#endif
// We have now read the values we need so we close the device
if (SDL_JoystickOpened(i)) SDL_JoystickClose(joyinfo[i].joy);
}
return numjoy;
}
// Shutdown PAD (stop emulation)
//
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
void PAD_Shutdown()
{
if (joysticks[0].enabled)
@ -244,8 +348,8 @@ void PAD_Shutdown()
}
// Set PAD status
//
// Set PAD status. This is called from SerialInterface_Devices.cpp
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯
void PAD_GetStatus(u8 _numPAD, SPADStatus* _pPADStatus)
{
if (!joysticks[_numPAD].enabled)
@ -257,57 +361,53 @@ void PAD_GetStatus(u8 _numPAD, SPADStatus* _pPADStatus)
// Get pad status
GetJoyState(_numPAD);
// Reset!
int base = 0x80;
_pPADStatus->stickY = base;
_pPADStatus->stickX = base;
_pPADStatus->substickX = base;
_pPADStatus->substickY = base;
_pPADStatus->button |= PAD_USE_ORIGIN;
///////////////////////////////////////////////////
// Set analog controllers
// -----------
// Read values
int i_main_stick_x = joystate[_numPAD].axis[CTL_MAIN_X];
int i_main_stick_y = -joystate[_numPAD].axis[CTL_MAIN_Y];
int i_sub_stick_x = joystate[_numPAD].axis[CTL_SUB_X];
int i_sub_stick_y = -joystate[_numPAD].axis[CTL_SUB_Y];
// Check if we should make adjustments
if(g_Config.bSquareToCircle)
{
std::vector<int> main_xy = Pad_Square_to_Circle(i_main_stick_x, i_main_stick_y);
i_main_stick_x = main_xy.at(0);
i_main_stick_y = main_xy.at(1);
}
// Convert button values from 0xffff to 0xff
u8 main_stick_x = Pad_Convert(i_main_stick_x);
u8 main_stick_y = Pad_Convert(i_main_stick_y);
u8 sub_stick_x = Pad_Convert(i_sub_stick_x);
u8 sub_stick_y = Pad_Convert(i_sub_stick_y);
// Set Deadzones perhaps out of function
int deadzone = (int)(((float)(128.00/100.00)) * (float)(joysticks[_numPAD].deadzone + 1));
int deadzone2 = (int)(((float)(-128.00/100.00)) * (float)(joysticks[_numPAD].deadzone + 1));
// Adjust range
// The value returned by SDL_JoystickGetAxis is a signed integer (-32768 to 32768)
// The value used for the gamecube controller is an unsigned char (0 to 255)
int main_stick_x = (joystate[_numPAD].axis[CTL_MAIN_X] >> 8);
int main_stick_y = -(joystate[_numPAD].axis[CTL_MAIN_Y] >> 8);
int sub_stick_x = (joystate[_numPAD].axis[CTL_SUB_X] >> 8);
int sub_stick_y = -(joystate[_numPAD].axis[CTL_SUB_Y] >> 8);
// Send values to Dolpin if they are outside the deadzone
if ((main_stick_x < deadzone2) || (main_stick_x > deadzone)) _pPADStatus->stickX = main_stick_x;
if ((main_stick_y < deadzone2) || (main_stick_y > deadzone)) _pPADStatus->stickY = main_stick_y;
if ((sub_stick_x < deadzone2) || (sub_stick_x > deadzone)) _pPADStatus->substickX = sub_stick_x;
if ((sub_stick_y < deadzone2) || (sub_stick_y > deadzone)) _pPADStatus->substickY = sub_stick_y;
// Quick fix
if (main_stick_x > 127)
main_stick_x = 127;
if (main_stick_y > 127)
main_stick_y = 127;
if (sub_stick_x > 127)
sub_stick_x = 127;
if (sub_stick_y > 127)
sub_stick_y = 127;
if (main_stick_x < -128)
main_stick_x = -128;
if (main_stick_y < -128)
main_stick_y = -128;
if (sub_stick_x < -128)
sub_stick_x = -128;
if (sub_stick_y < -128)
sub_stick_y = -128;
// Send values to Dolpin
if ((main_stick_x < deadzone2) || (main_stick_x > deadzone)) _pPADStatus->stickX += main_stick_x;
if ((main_stick_y < deadzone2) || (main_stick_y > deadzone)) _pPADStatus->stickY += main_stick_y;
if ((sub_stick_x < deadzone2) || (sub_stick_x > deadzone)) _pPADStatus->substickX += sub_stick_x;
if ((sub_stick_y < deadzone2) || (sub_stick_y > deadzone)) _pPADStatus->substickY += sub_stick_y;
int triggervalue = 255;
if (joystate[_numPAD].halfpress)
triggervalue = 100;
///////////////////////////////////////////////////
// Set buttons
// -----------
// The L and R trigger values
int triggervalue = 255;
if (joystate[_numPAD].halfpress) triggervalue = 100;
// Neutral button value, no button pressed
_pPADStatus->button |= PAD_USE_ORIGIN;
if (joystate[_numPAD].buttons[CTL_L_SHOULDER])
{
_pPADStatus->button|=PAD_TRIGGER_L;
@ -358,28 +458,130 @@ void PAD_GetStatus(u8 _numPAD, SPADStatus* _pPADStatus)
_pPADStatus->err = PAD_ERR_NONE;
// Use rumble
PAD_Use_Rumble(_numPAD, _pPADStatus);
Pad_Use_Rumble(_numPAD, _pPADStatus);
}
//////////////////////////////////////////////////////////////////////////////////////////
// Convert stick values, for example from circle to square analog stick radius
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
/* Convert stick values.
The value returned by SDL_JoystickGetAxis is a signed integer s16
(-32768 to 32767). The value used for the gamecube controller is an unsigned
char u8 (0 to 255) with neutral at 0x80 (128), so that it's equivalent to a signed
-128 to 127. */
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
u8 Pad_Convert(int _val)
{
/* If the limits on joystate[].axis[] actually is a u16 then we don't need this
but if it's not actually limited to that we need to apply these limits */
if(_val > 32767) _val = 32767; // upper limit
if(_val < -32768) _val = -32768; // lower limit
// Convert (-32768 to 32767) to (-128 to 127)
_val = _val >> 8;
// Convert (-128 to 127) to (0 to 255)
u8 val = 0x80 + _val;
return val;
}
/* Convert the stick raidus from a circular to a square. I don't know what input values
the actual GC controller produce for the GC, it may be a square, a circle or something
in between. But one thing that is certain is that PC pads differ in their output (as
shown in the list below), so it may be beneficiary to convert whatever radius they
produce to the radius the GC games expect. This is the first implementation of this
that convert a square radius to a circual radius. Use the advanced settings to enable
and calibrate it.
Observed diagonals:
Perfect circle: 71% = sin(45)
Logitech Dual Action: 100%
Dual Shock 2 (Original) with Super Dual Box Pro: 90%
XBox 360 Wireless: 85%
GameCube Controller (Third Party) with EMS TrioLinker Plus II: 60%
*/
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
float SquareDistance(float deg)
{
// See if we have to adjust the angle
deg = abs(deg);
if( (deg > 45 && deg < 135) ) deg = deg - 90;
float rad = deg * M_PI / 180;
float val = abs(cos(rad));
float dist = 1 / val; // Calculate distance from center
//m_frame->m_pStatusBar2->SetLabel(wxString::Format("Deg:%f Val:%f Dist:%f", deg, val, dist));
return dist;
}
std::vector<int> Pad_Square_to_Circle(int _x, int _y)
{
/* Do we need this? */
if(_x > 32767) _x = 32767; if(_y > 32767) _y = 32767; // upper limit
if(_x < -32768) _x = -32768; if(_y > 32767) _y = 32767; // lower limit
///////////////////////////////////////////////////
// Convert to circle
// -----------
int Tmp = atoi (g_Config.SDiagonal.substr(0, g_Config.SDiagonal.length() - 1).c_str());
float Diagonal = Tmp / 100.0;
// First make a perfect square in case we don't have one already
float OrigDist = sqrt( pow((float)_y, 2) + pow((float)_x, 2) ); // Get current distance
float rad = atan2((float)_y, (float)_x); // Get current angle
float deg = rad * 180 / M_PI;
// A diagonal of 85% means a distance of 1.20
float corner_circle_dist = ( Diagonal / sin(45 * M_PI / 180) );
float SquareDist = SquareDistance(deg);
float adj_ratio1; // The original-to-square distance adjustment
float adj_ratio2 = SquareDist; // The circle-to-square distance adjustment
float final_ratio; // The final adjustment to the current distance
float result_dist; // The resulting distance
// Calculate the corner-to-square adjustment ratio
if(corner_circle_dist < SquareDist) adj_ratio1 = SquareDist / corner_circle_dist;
else adj_ratio1 = 1;
// Calculate the resulting distance
result_dist = OrigDist * adj_ratio1 / adj_ratio2;
float x = result_dist * cos(rad); // calculate x
float y = result_dist * sin(rad); // calculate y
int int_x = (int)floor(x);
int int_y = (int)floor(y);
// Debugging
//m_frame->m_pStatusBar2->SetLabel(wxString::Format("%f %f %i", corner_circle_dist, Diagonal, Tmp));
std::vector<int> vec;
vec.push_back(int_x);
vec.push_back(int_y);
return vec;
}
//////////////////////////////////////////////////////////////////////////////////////////
// Set PAD attached pads
//
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
unsigned int PAD_GetAttachedPads()
{
unsigned int connected = 0;
LoadConfig();
g_Config.Load();
if (joysticks[0].enabled)
connected |= 1;
if (joysticks[1].enabled)
connected |= 2;
if (joysticks[2].enabled)
connected |= 4;
if (joysticks[3].enabled)
connected |= 8;
if (joysticks[0].enabled) connected |= 1;
if (joysticks[1].enabled) connected |= 2;
if (joysticks[2].enabled) connected |= 4;
if (joysticks[3].enabled) connected |= 8;
return connected;
}
@ -387,11 +589,11 @@ unsigned int PAD_GetAttachedPads()
//////////////////////////////////////////////////////////////////////////////////////////
// Custom Functions
//
// Read current joystick status
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
// Read buttons status. Called from GetJoyState().
//
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
void ReadButton(int controller, int button)
{
int ctl_button = joysticks[controller].buttons[button];
@ -401,8 +603,8 @@ void ReadButton(int controller, int button)
}
}
// Request joystick state
//
// Request joystick state. The input value "controller" is for a virtual controller 0 to 3.
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
void GetJoyState(int controller)
{
SDL_JoystickUpdate();
@ -420,8 +622,6 @@ void GetJoyState(int controller)
ReadButton(controller, CTL_Y_BUTTON);
ReadButton(controller, CTL_Z_TRIGGER);
ReadButton(controller, CTL_START);
// Is there a purpose to this alert?
// PanicAlert("%i", CTL_A_BUTTON);
//
if (joysticks[controller].halfpress < joyinfo[controller].NumButtons)
@ -440,67 +640,4 @@ void GetJoyState(int controller)
joystate[controller].dpad2[CTL_D_PAD_RIGHT] = SDL_JoystickGetButton(joystate[controller].joy, joysticks[controller].dpad2[CTL_D_PAD_RIGHT]);
}
}
// Search attached devices
//
int Search_Devices()
{
// load config
#ifdef _DEBUG
DEBUG_INIT();
#endif
int numjoy = SDL_NumJoysticks();
if (joyinfo)
{
delete [] joyinfo;
joyinfo = new CONTROLLER_INFO [numjoy];
}
else
{
joyinfo = new CONTROLLER_INFO [numjoy];
}
// Warn the user of no joysticks are detected
if (numjoy == 0)
{
#ifdef _WIN32
MessageBox(NULL, "No Joystick detected!", NULL, MB_ICONWARNING);
#else
printf("No Joystick detected!\n");
#endif
return 0;
}
#ifdef _DEBUG
fprintf(pFile, "Scanning for devices\n");
fprintf(pFile, "\n");
#endif
for(int i = 0; i < numjoy; i++ )
{
joyinfo[i].joy = SDL_JoystickOpen(i);
joyinfo[i].ID = i;
joyinfo[i].NumAxes = SDL_JoystickNumAxes(joyinfo[i].joy);
joyinfo[i].NumButtons = SDL_JoystickNumButtons(joyinfo[i].joy);
joyinfo[i].NumBalls = SDL_JoystickNumBalls(joyinfo[i].joy);
joyinfo[i].NumHats = SDL_JoystickNumHats(joyinfo[i].joy);
joyinfo[i].Name = SDL_JoystickName(i);
#ifdef _DEBUG
fprintf(pFile, "ID: %d\n", i);
fprintf(pFile, "Name: %s\n", joyinfo[i].Name);
fprintf(pFile, "Buttons: %d\n", joyinfo[i].NumButtons);
fprintf(pFile, "Axes: %d\n", joyinfo[i].NumAxes);
fprintf(pFile, "Hats: %d\n", joyinfo[i].NumHats);
fprintf(pFile, "Balls: %d\n\n", joyinfo[i].NumBalls);
#endif
// Close if opened
if (SDL_JoystickOpened(i))
SDL_JoystickClose(joyinfo[i].joy);
}
return numjoy;
}
//////////////////////////////////////////////////////////////////////////////////////////

View File

@ -32,18 +32,21 @@
// Set this if you want to use the rumble 'hack' for controller one
//#define USE_RUMBLE_DINPUT_HACK
#include <vector>
#include <vector> // System
#include <stdio.h>
#include <time.h>
#include <SDL.h>
#include "Common.h"
#include "Common.h" // Common
#include "pluginspecs_pad.h"
#include "IniFile.h"
#include "Config.h" // Local
#if defined(HAVE_WX) && HAVE_WX
#include "GUI/AboutBox.h"
#include "GUI/ConfigBox.h"
//extern ConfigBox* m_frame;
#endif
#ifdef _WIN32
@ -167,6 +170,7 @@ enum
// ¯¯¯¯¯¯¯¯¯
#ifndef _CONTROLLER_STATE_H
extern FILE *pFile;
extern CONTROLLER_INFO *joyinfo;
extern CONTROLLER_STATE joystate[4];
extern CONTROLLER_MAPPING joysticks[4];
extern HWND m_hWnd; // Handle to window
@ -182,7 +186,9 @@ int Search_Devices();
void DEBUG_INIT();
void DEBUG_QUIT();
void PAD_Use_Rumble(u8 _numPAD, SPADStatus* _pPADStatus); // Rumble
void Pad_Use_Rumble(u8 _numPAD, SPADStatus* _pPADStatus); // Rumble
u8 Pad_Convert(int _val); // Value conversion
std::vector<int> Pad_Square_to_Circle(int _x, int _y); // Value conversion
void SaveConfig();
void LoadConfig();
//void SaveConfig();
//void LoadConfig();