nJoy: Don't allow input when Dolphin is not in focus (supports both the

rendering to main window and render to separate window options)

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2062 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
John Peterson 2009-02-01 16:29:35 +00:00
parent ad995a68ea
commit 8c9d07b26b
3 changed files with 35 additions and 4 deletions

View File

@ -462,7 +462,7 @@ void ConfigBox::UpdateGUI(int _notebookpage)
m_textDpadLeft[_notebookpage]->Show(!Hat); m_textDpadLeft[_notebookpage]->Show(!Hat);
m_textDpadRight[_notebookpage]->Show(!Hat); m_textDpadRight[_notebookpage]->Show(!Hat);
m_textDpadDown[_notebookpage]->SetLabel(Hat ? wxT("Select hat") : wxT("Up")); m_textDpadDown[_notebookpage]->SetLabel(Hat ? wxT("Select hat") : wxT("Down"));
m_bJoyDpadDown[_notebookpage]->SetToolTip(Hat ? m_bJoyDpadDown[_notebookpage]->SetToolTip(Hat ?
wxT("Select a hat by pressing the hat in any direction") : wxT("")); wxT("Select a hat by pressing the hat in any direction") : wxT(""));

View File

@ -90,6 +90,7 @@ CONTROLLER_MAPPING PadMapping[4];
bool emulator_running = false; bool emulator_running = false;
int NumPads = 0, NumGoodPads = 0; int NumPads = 0, NumGoodPads = 0;
HWND m_hWnd; // Handle to window HWND m_hWnd; // Handle to window
SPADInitialize *g_PADInitialize;
// TODO: fix this dirty hack to stop missing symbols // TODO: fix this dirty hack to stop missing symbols
void __Log(int log, const char *format, ...) {} void __Log(int log, const char *format, ...) {}
@ -239,7 +240,7 @@ void Initialize(void *init)
// Debugging // Debugging
//Console::Open(); //Console::Open();
Console::Print("Initialize: %i\n", SDL_WasInit(0)); Console::Print("Initialize: %i\n", SDL_WasInit(0));
SPADInitialize *_PADInitialize = (SPADInitialize*)init; g_PADInitialize = (SPADInitialize*)init;
emulator_running = true; emulator_running = true;
#ifdef _DEBUG #ifdef _DEBUG
@ -247,7 +248,7 @@ void Initialize(void *init)
#endif #endif
#ifdef _WIN32 #ifdef _WIN32
m_hWnd = (HWND)_PADInitialize->hWnd; m_hWnd = (HWND)g_PADInitialize->hWnd;
#endif #endif
NumPads = Search_Devices(); // Populate joyinfo for all attached devices NumPads = Search_Devices(); // Populate joyinfo for all attached devices
@ -259,7 +260,7 @@ void Initialize(void *init)
|| (PadMapping[2].enabled && PadState[2].joy == NULL) || (PadMapping[2].enabled && PadState[2].joy == NULL)
|| (PadMapping[3].enabled && PadState[3].joy == NULL)) || (PadMapping[3].enabled && PadState[3].joy == NULL))
{ {
_PADInitialize->padNumber = -1; g_PADInitialize->padNumber = -1;
Console::Print("%s\n", SDL_GetError()); Console::Print("%s\n", SDL_GetError());
} }
} }
@ -398,6 +399,9 @@ void Shutdown()
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯ // ¯¯¯¯¯¯¯¯¯¯¯¯¯¯
void PAD_Input(u16 _Key, u8 _UpDown) void PAD_Input(u16 _Key, u8 _UpDown)
{ {
// Check that Dolphin is in focus, otherwise don't update the pad status
if (!IsFocus()) return;
// Check if the keys are interesting, and then update it // Check if the keys are interesting, and then update it
for(int i = 0; i < 4; i++) for(int i = 0; i < 4; i++)
{ {
@ -606,6 +610,29 @@ unsigned int PAD_GetAttachedPads()
//******************************************************************************
// Supporting functions
//******************************************************************************
//////////////////////////////////////////////////////////////////////////////////////////
// Check if Dolphin is in focus
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
bool IsFocus()
{
#ifdef _WIN32
HWND Parent = GetParent(g_PADInitialize->hWnd);
HWND TopLevel = GetParent(Parent);
// Support both rendering to main window and not
if (GetForegroundWindow() == TopLevel || GetForegroundWindow() == g_PADInitialize->hWnd)
return true;
else
return false;
#else
return true;
#endif
}
////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////
// Convert stick values // Convert stick values
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ // ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
@ -747,6 +774,9 @@ void ReadButton(int controller, int button)
for a virtual controller 0 to 3. */ for a virtual controller 0 to 3. */
void GetJoyState(int controller) void GetJoyState(int controller)
{ {
// Check that Dolphin is in focus, otherwise don't update the pad status
if (!IsFocus()) return;
// Update the gamepad status // Update the gamepad status
SDL_JoystickUpdate(); SDL_JoystickUpdate();

View File

@ -243,6 +243,7 @@ void GetJoyState(int controller);
int Search_Devices(); int Search_Devices();
void DEBUG_INIT(); void DEBUG_INIT();
void DEBUG_QUIT(); void DEBUG_QUIT();
bool IsFocus();
void Pad_Use_Rumble(u8 _numPAD, SPADStatus* _pPADStatus); // Rumble void Pad_Use_Rumble(u8 _numPAD, SPADStatus* _pPADStatus); // Rumble
int Pad_Convert(int _val); // Value conversion int Pad_Convert(int _val); // Value conversion