GUI navigation improvements, only initializing game controller once now

This commit is contained in:
Dimitris Panokostas 2017-12-19 00:13:35 +01:00
parent 3f8a881cfb
commit 0f6617d3dd
10 changed files with 343 additions and 321 deletions

View file

@ -36,7 +36,6 @@
#define DIALOG_WIDTH 620 #define DIALOG_WIDTH 620
#define DIALOG_HEIGHT 202 #define DIALOG_HEIGHT 202
static SDL_Joystick* GUIjoy;
extern struct host_input_button host_input_buttons[MAX_INPUT_DEVICES]; extern struct host_input_button host_input_buttons[MAX_INPUT_DEVICES];
static const char* harddisk_filter[] = {".hdf", "\0"}; static const char* harddisk_filter[] = {".hdf", "\0"};
@ -225,7 +224,6 @@ static void CreateFilesysHardfileLoop()
{ {
FocusBugWorkaround(wndCreateFilesysHardfile); FocusBugWorkaround(wndCreateFilesysHardfile);
GUIjoy = SDL_JoystickOpen(0);
while (!dialogFinished) while (!dialogFinished)
{ {
SDL_Event event; SDL_Event event;
@ -282,47 +280,51 @@ static void CreateFilesysHardfileLoop()
gcn::FocusHandler* focusHdl; gcn::FocusHandler* focusHdl;
gcn::Widget* activeWidget; gcn::Widget* activeWidget;
const int hat = SDL_JoystickGetHat(GUIjoy, 0); if (GUIjoy)
{
const int hat = SDL_JoystickGetHat(GUIjoy, 0);
if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_up) || (hat & SDL_HAT_UP)) // dpad if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_up) || (hat & SDL_HAT_UP)) // dpad
{ {
if (HandleNavigation(DIRECTION_UP)) if (HandleNavigation(DIRECTION_UP))
continue; // Don't change value when enter Slider -> don't send event to control continue; // Don't change value when enter Slider -> don't send event to control
PushFakeKey(SDLK_UP); PushFakeKey(SDLK_UP);
break; break;
} }
if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_down) || (hat & SDL_HAT_DOWN)) // dpad if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_down) || (hat & SDL_HAT_DOWN)) // dpad
{ {
if (HandleNavigation(DIRECTION_DOWN)) if (HandleNavigation(DIRECTION_DOWN))
continue; // Don't change value when enter Slider -> don't send event to control continue; // Don't change value when enter Slider -> don't send event to control
PushFakeKey(SDLK_DOWN); PushFakeKey(SDLK_DOWN);
break; break;
} }
if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_right) || (hat & SDL_HAT_RIGHT)) // dpad if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_right) || (hat & SDL_HAT_RIGHT)) // dpad
{ {
if (HandleNavigation(DIRECTION_RIGHT)) if (HandleNavigation(DIRECTION_RIGHT))
continue; // Don't change value when enter Slider -> don't send event to control continue; // Don't change value when enter Slider -> don't send event to control
PushFakeKey(SDLK_RIGHT); PushFakeKey(SDLK_RIGHT);
break; break;
} }
if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_left) || (hat & SDL_HAT_LEFT)) // dpad if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_left) || (hat & SDL_HAT_LEFT)) // dpad
{ {
if (HandleNavigation(DIRECTION_LEFT)) if (HandleNavigation(DIRECTION_LEFT))
continue; // Don't change value when enter Slider -> don't send event to control continue; // Don't change value when enter Slider -> don't send event to control
PushFakeKey(SDLK_LEFT); PushFakeKey(SDLK_LEFT);
break; break;
} }
if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].south_button)) // need this to be X button if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].south_button)) // need this to be X button
{ {
PushFakeKey(SDLK_RETURN); PushFakeKey(SDLK_RETURN);
continue; continue;
} }
if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].east_button) || if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].east_button) ||
SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].start_button)) // need this to be START button SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].start_button)) // need this to be START button
{ {
dialogFinished = true; dialogFinished = true;
break; break;
}
} }
break;
} }
//------------------------------------------------- //-------------------------------------------------

View file

@ -34,7 +34,6 @@
#define DIALOG_WIDTH 620 #define DIALOG_WIDTH 620
#define DIALOG_HEIGHT 272 #define DIALOG_HEIGHT 272
static SDL_Joystick* GUIjoy;
extern struct host_input_button host_input_buttons[MAX_INPUT_DEVICES]; extern struct host_input_button host_input_buttons[MAX_INPUT_DEVICES];
static const char* harddisk_filter[] = {".hdf", "\0"}; static const char* harddisk_filter[] = {".hdf", "\0"};
@ -455,47 +454,51 @@ static void EditFilesysHardfileLoop()
gcn::FocusHandler* focusHdl; gcn::FocusHandler* focusHdl;
gcn::Widget* activeWidget; gcn::Widget* activeWidget;
const int hat = SDL_JoystickGetHat(GUIjoy, 0); if (GUIjoy)
{
const int hat = SDL_JoystickGetHat(GUIjoy, 0);
if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_up) || (hat & SDL_HAT_UP)) // dpad if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_up) || (hat & SDL_HAT_UP)) // dpad
{ {
if (HandleNavigation(DIRECTION_UP)) if (HandleNavigation(DIRECTION_UP))
continue; // Don't change value when enter Slider -> don't send event to control continue; // Don't change value when enter Slider -> don't send event to control
PushFakeKey(SDLK_UP); PushFakeKey(SDLK_UP);
break; break;
} }
if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_down) || (hat & SDL_HAT_DOWN)) // dpad if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_down) || (hat & SDL_HAT_DOWN)) // dpad
{ {
if (HandleNavigation(DIRECTION_DOWN)) if (HandleNavigation(DIRECTION_DOWN))
continue; // Don't change value when enter Slider -> don't send event to control continue; // Don't change value when enter Slider -> don't send event to control
PushFakeKey(SDLK_DOWN); PushFakeKey(SDLK_DOWN);
break; break;
} }
if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_right) || (hat & SDL_HAT_RIGHT)) // dpad if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_right) || (hat & SDL_HAT_RIGHT)) // dpad
{ {
if (HandleNavigation(DIRECTION_RIGHT)) if (HandleNavigation(DIRECTION_RIGHT))
continue; // Don't change value when enter Slider -> don't send event to control continue; // Don't change value when enter Slider -> don't send event to control
PushFakeKey(SDLK_RIGHT); PushFakeKey(SDLK_RIGHT);
break; break;
} }
if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_left) || (hat & SDL_HAT_LEFT)) // dpad if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_left) || (hat & SDL_HAT_LEFT)) // dpad
{ {
if (HandleNavigation(DIRECTION_LEFT)) if (HandleNavigation(DIRECTION_LEFT))
continue; // Don't change value when enter Slider -> don't send event to control continue; // Don't change value when enter Slider -> don't send event to control
PushFakeKey(SDLK_LEFT); PushFakeKey(SDLK_LEFT);
break; break;
} }
if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].south_button)) // need this to be X button if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].south_button)) // need this to be X button
{ {
PushFakeKey(SDLK_RETURN); PushFakeKey(SDLK_RETURN);
break; break;
} }
if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].east_button) || if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].east_button) ||
SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].start_button)) // need this to be START button SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].start_button)) // need this to be START button
{ {
dialogFinished = true; dialogFinished = true;
break; break;
}
} }
break;
} }
//------------------------------------------------- //-------------------------------------------------
// Send event to guichan-controls // Send event to guichan-controls

View file

@ -34,7 +34,6 @@
#define DIALOG_WIDTH 520 #define DIALOG_WIDTH 520
#define DIALOG_HEIGHT 202 #define DIALOG_HEIGHT 202
static SDL_Joystick* GUIjoy;
extern struct host_input_button host_input_buttons[MAX_INPUT_DEVICES]; extern struct host_input_button host_input_buttons[MAX_INPUT_DEVICES];
extern string volName; extern string volName;
@ -284,47 +283,51 @@ static void EditFilesysVirtualLoop()
gcn::FocusHandler* focusHdl; gcn::FocusHandler* focusHdl;
gcn::Widget* activeWidget; gcn::Widget* activeWidget;
const int hat = SDL_JoystickGetHat(GUIjoy, 0); if (GUIjoy)
{
const int hat = SDL_JoystickGetHat(GUIjoy, 0);
if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_up) || (hat & SDL_HAT_UP)) // dpad if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_up) || (hat & SDL_HAT_UP)) // dpad
{ {
if (HandleNavigation(DIRECTION_UP)) if (HandleNavigation(DIRECTION_UP))
continue; // Don't change value when enter Slider -> don't send event to control continue; // Don't change value when enter Slider -> don't send event to control
PushFakeKey(SDLK_UP); PushFakeKey(SDLK_UP);
break; break;
} }
if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_down) || (hat & SDL_HAT_DOWN)) // dpad if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_down) || (hat & SDL_HAT_DOWN)) // dpad
{ {
if (HandleNavigation(DIRECTION_DOWN)) if (HandleNavigation(DIRECTION_DOWN))
continue; // Don't change value when enter Slider -> don't send event to control continue; // Don't change value when enter Slider -> don't send event to control
PushFakeKey(SDLK_DOWN); PushFakeKey(SDLK_DOWN);
break; break;
} }
if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_right) || (hat & SDL_HAT_RIGHT)) // dpad if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_right) || (hat & SDL_HAT_RIGHT)) // dpad
{ {
if (HandleNavigation(DIRECTION_RIGHT)) if (HandleNavigation(DIRECTION_RIGHT))
continue; // Don't change value when enter Slider -> don't send event to control continue; // Don't change value when enter Slider -> don't send event to control
PushFakeKey(SDLK_RIGHT); PushFakeKey(SDLK_RIGHT);
break; break;
} }
if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_left) || (hat & SDL_HAT_LEFT)) // dpad if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_left) || (hat & SDL_HAT_LEFT)) // dpad
{ {
if (HandleNavigation(DIRECTION_LEFT)) if (HandleNavigation(DIRECTION_LEFT))
continue; // Don't change value when enter Slider -> don't send event to control continue; // Don't change value when enter Slider -> don't send event to control
PushFakeKey(SDLK_LEFT); PushFakeKey(SDLK_LEFT);
break; break;
} }
if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].south_button)) // need this to be X button if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].south_button)) // need this to be X button
{ {
PushFakeKey(SDLK_RETURN); PushFakeKey(SDLK_RETURN);
break; break;
} }
if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].east_button) || if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].east_button) ||
SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].start_button)) // need this to be START button SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].start_button)) // need this to be START button
{ {
dialogFinished = true; dialogFinished = true;
break; break;
}
} }
break;
} }
//------------------------------------------------- //-------------------------------------------------
// Send event to guichan-controls // Send event to guichan-controls

View file

@ -29,7 +29,6 @@
#include "androidsdl_event.h" #include "androidsdl_event.h"
#endif #endif
static SDL_Joystick *GUIjoy;
extern struct host_input_button host_input_buttons[MAX_INPUT_DEVICES]; extern struct host_input_button host_input_buttons[MAX_INPUT_DEVICES];
extern SDL_Surface* screen; extern SDL_Surface* screen;
@ -89,7 +88,6 @@ void checkInput()
//------------------------------------------------- //-------------------------------------------------
// Check user input // Check user input
//------------------------------------------------- //-------------------------------------------------
GUIjoy = SDL_JoystickOpen(0);
while (SDL_PollEvent(&msg_event)) while (SDL_PollEvent(&msg_event))
{ {
if (msg_event.type == SDL_KEYDOWN) if (msg_event.type == SDL_KEYDOWN)
@ -107,13 +105,15 @@ void checkInput()
} }
else if (msg_event.type == SDL_JOYBUTTONDOWN) else if (msg_event.type == SDL_JOYBUTTONDOWN)
{ {
if (GUIjoy)
if (SDL_JoystickGetButton(GUIjoy,host_input_buttons[0].east_button) || {
SDL_JoystickGetButton(GUIjoy,host_input_buttons[0].start_button) || if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].east_button) ||
SDL_JoystickGetButton(GUIjoy,host_input_buttons[0].east_button)) SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].start_button) ||
SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].east_button))
msg_done = 1;
break; msg_done = 1;
}
break;
} }
//------------------------------------------------- //-------------------------------------------------

View file

@ -35,7 +35,6 @@
#define FILE_SELECT_KEEP_POSITION #define FILE_SELECT_KEEP_POSITION
#endif #endif
static SDL_Joystick* GUIjoy;
extern struct host_input_button host_input_buttons[MAX_INPUT_DEVICES]; extern struct host_input_button host_input_buttons[MAX_INPUT_DEVICES];
static bool dialogResult = false; static bool dialogResult = false;
@ -335,8 +334,6 @@ static void SelectFileLoop()
{ {
FocusBugWorkaround(wndSelectFile); FocusBugWorkaround(wndSelectFile);
GUIjoy = SDL_JoystickOpen(0);
while (!dialogFinished) while (!dialogFinished)
{ {
SDL_Event event; SDL_Event event;
@ -378,39 +375,43 @@ static void SelectFileLoop()
} }
else if (event.type == SDL_JOYBUTTONDOWN || event.type == SDL_JOYHATMOTION) else if (event.type == SDL_JOYBUTTONDOWN || event.type == SDL_JOYHATMOTION)
{ {
const int hat = SDL_JoystickGetHat(GUIjoy, 0); if (GUIjoy)
{
const int hat = SDL_JoystickGetHat(GUIjoy, 0);
if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].south_button)) if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].south_button))
{ {
PushFakeKey(SDLK_RETURN); PushFakeKey(SDLK_RETURN);
break; break;
} }
if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].east_button) || if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].east_button) ||
SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].start_button)) SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].start_button))
{ {
dialogFinished = true; dialogFinished = true;
break; break;
} }
if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_left) || (hat & SDL_HAT_LEFT)) if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_left) || (hat & SDL_HAT_LEFT))
{ {
navigate_left(); navigate_left();
break; break;
} }
if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_right) || (hat & SDL_HAT_RIGHT)) if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_right) || (hat & SDL_HAT_RIGHT))
{ {
navigate_right(); navigate_right();
break; break;
} }
if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_up) || (hat & SDL_HAT_UP)) if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_up) || (hat & SDL_HAT_UP))
{ {
PushFakeKey(SDLK_UP); PushFakeKey(SDLK_UP);
break; break;
} }
if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_down) || (hat & SDL_HAT_DOWN)) if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_down) || (hat & SDL_HAT_DOWN))
{ {
PushFakeKey(SDLK_DOWN); PushFakeKey(SDLK_DOWN);
break; break;
}
} }
break;
} }
//------------------------------------------------- //-------------------------------------------------

View file

@ -35,7 +35,6 @@ static bool dialogResult = false;
static bool dialogFinished = false; static bool dialogFinished = false;
static char workingDir[MAX_DPATH]; static char workingDir[MAX_DPATH];
static SDL_Joystick* GUIjoy;
extern struct host_input_button host_input_buttons[MAX_INPUT_DEVICES]; extern struct host_input_button host_input_buttons[MAX_INPUT_DEVICES];
static gcn::Window* wndSelectFolder; static gcn::Window* wndSelectFolder;
static gcn::Button* cmdOK; static gcn::Button* cmdOK;
@ -279,44 +278,48 @@ static void SelectFolderLoop()
} }
else if (event.type == SDL_JOYBUTTONDOWN || event.type == SDL_JOYHATMOTION) else if (event.type == SDL_JOYBUTTONDOWN || event.type == SDL_JOYHATMOTION)
{ {
const int hat = SDL_JoystickGetHat(GUIjoy, 0); if (GUIjoy)
if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].south_button))
{ {
PushFakeKey(SDLK_RETURN); const int hat = SDL_JoystickGetHat(GUIjoy, 0);
break;
}
if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].east_button) || if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].south_button))
SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].start_button)) {
{ PushFakeKey(SDLK_RETURN);
dialogFinished = true; break;
break; }
}
if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_left) || (hat & SDL_HAT_LEFT)) if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].east_button) ||
{ SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].start_button))
navigate_left(); {
break; dialogFinished = true;
} break;
}
if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_right) || (hat & SDL_HAT_RIGHT)) if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_left) || (hat & SDL_HAT_LEFT))
{ {
navigate_right(); navigate_left();
break; break;
} }
if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_up) || (hat & SDL_HAT_UP)) if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_right) || (hat & SDL_HAT_RIGHT))
{ {
PushFakeKey(SDLK_UP); navigate_right();
break; break;
} }
if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_down) || (hat & SDL_HAT_DOWN)) if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_up) || (hat & SDL_HAT_UP))
{ {
PushFakeKey(SDLK_DOWN); PushFakeKey(SDLK_UP);
break; break;
}
if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_down) || (hat & SDL_HAT_DOWN))
{
PushFakeKey(SDLK_DOWN);
break;
}
} }
break;
} }
//------------------------------------------------- //-------------------------------------------------

View file

@ -27,10 +27,8 @@
#include "androidsdl_event.h" #include "androidsdl_event.h"
#endif #endif
static SDL_Joystick* GUIjoy;
extern struct host_input_button host_input_buttons[MAX_INPUT_DEVICES]; extern struct host_input_button host_input_buttons[MAX_INPUT_DEVICES];
#define DIALOG_WIDTH 760 #define DIALOG_WIDTH 760
#define DIALOG_HEIGHT 420 #define DIALOG_HEIGHT 420
@ -150,8 +148,6 @@ static void ShowHelpLoop(void)
{ {
FocusBugWorkaround(wndShowHelp); FocusBugWorkaround(wndShowHelp);
GUIjoy = SDL_JoystickOpen(0);
while (!dialogFinished) while (!dialogFinished)
{ {
SDL_Event event; SDL_Event event;
@ -187,17 +183,21 @@ static void ShowHelpLoop(void)
} }
else if (event.type == SDL_JOYBUTTONDOWN) else if (event.type == SDL_JOYBUTTONDOWN)
{ {
if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].south_button)) if (GUIjoy)
{ {
PushFakeKey(SDLK_RETURN); if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].south_button))
break; {
} PushFakeKey(SDLK_RETURN);
if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].east_button) || break;
SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].start_button)) }
{ if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].east_button) ||
dialogFinished = true; SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].start_button))
break; {
dialogFinished = true;
break;
}
} }
break;
} }
//------------------------------------------------- //-------------------------------------------------

View file

@ -32,7 +32,6 @@
static bool dialogResult = false; static bool dialogResult = false;
static bool dialogFinished = false; static bool dialogFinished = false;
static SDL_Joystick* GUIjoy;
extern struct host_input_button host_input_buttons[MAX_INPUT_DEVICES]; extern struct host_input_button host_input_buttons[MAX_INPUT_DEVICES];
static const char* dialogControlPressed; static const char* dialogControlPressed;
static Uint8 dialogButtonPressed; static Uint8 dialogButtonPressed;
@ -179,8 +178,6 @@ static void ShowMessageLoop()
{ {
FocusBugWorkaround(wndShowMessage); FocusBugWorkaround(wndShowMessage);
GUIjoy = SDL_JoystickOpen(0);
while (!dialogFinished) while (!dialogFinished)
{ {
SDL_Event event; SDL_Event event;
@ -221,28 +218,32 @@ static void ShowMessageLoop()
} }
else if (event.type == SDL_JOYBUTTONDOWN || event.type == SDL_JOYHATMOTION) else if (event.type == SDL_JOYBUTTONDOWN || event.type == SDL_JOYHATMOTION)
{ {
const int hat = SDL_JoystickGetHat(GUIjoy, 0); if (GUIjoy)
{
const int hat = SDL_JoystickGetHat(GUIjoy, 0);
if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].south_button)) if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].south_button))
{ {
PushFakeKey(SDLK_RETURN); PushFakeKey(SDLK_RETURN);
break; break;
} }
if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].east_button) || if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].east_button) ||
SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].start_button)) SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].start_button))
{ {
dialogFinished = true; dialogFinished = true;
break; break;
} }
if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_left) || if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_left) ||
SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_right) || SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_right) ||
(hat & SDL_HAT_LEFT) || (hat & SDL_HAT_LEFT) ||
(hat & SDL_HAT_RIGHT)) (hat & SDL_HAT_RIGHT))
{ {
navigate_left_right(); navigate_left_right();
break; break;
}
} }
break;
} }
//------------------------------------------------- //-------------------------------------------------

View file

@ -41,6 +41,7 @@ extern gcn::Color gui_baseCol;
extern gcn::Color colTextboxBackground; extern gcn::Color colTextboxBackground;
extern gcn::SDLInput* gui_input; extern gcn::SDLInput* gui_input;
extern SDL_Surface* gui_screen; extern SDL_Surface* gui_screen;
extern SDL_Joystick* GUIjoy;
extern char currentDir[MAX_DPATH]; extern char currentDir[MAX_DPATH];
extern char last_loaded_config[MAX_DPATH]; extern char last_loaded_config[MAX_DPATH];

View file

@ -31,7 +31,7 @@
#include <android/log.h> #include <android/log.h>
#endif #endif
static SDL_Joystick* GUIjoy; SDL_Joystick* GUIjoy;
extern struct host_input_button host_input_buttons[MAX_INPUT_DEVICES]; extern struct host_input_button host_input_buttons[MAX_INPUT_DEVICES];
bool gui_running = false; bool gui_running = false;
@ -62,15 +62,13 @@ ConfigCategory categories[] = {
{ "Display", "data/screen.ico", nullptr, nullptr, InitPanelDisplay, ExitPanelDisplay, RefreshPanelDisplay, HelpPanelDisplay }, { "Display", "data/screen.ico", nullptr, nullptr, InitPanelDisplay, ExitPanelDisplay, RefreshPanelDisplay, HelpPanelDisplay },
{ "Sound", "data/sound.ico", nullptr, nullptr, InitPanelSound, ExitPanelSound, RefreshPanelSound, HelpPanelSound }, { "Sound", "data/sound.ico", nullptr, nullptr, InitPanelSound, ExitPanelSound, RefreshPanelSound, HelpPanelSound },
{ "Input", "data/joystick.ico", nullptr, nullptr, InitPanelInput, ExitPanelInput, RefreshPanelInput, HelpPanelInput }, { "Input", "data/joystick.ico", nullptr, nullptr, InitPanelInput, ExitPanelInput, RefreshPanelInput, HelpPanelInput },
#ifndef PANDORA { "Custom controls", "data/controller.png", NULL, NULL, InitPanelCustom, ExitPanelCustom, RefreshPanelCustom, HelpPanelCustom },
{ "Custom controls", "data/controller.png", NULL, NULL, InitPanelCustom, ExitPanelCustom, RefreshPanelCustom, HelpPanelCustom }, { "Miscellaneous", "data/misc.ico", NULL, NULL, InitPanelMisc, ExitPanelMisc, RefreshPanelMisc, HelpPanelMisc },
#endif { "Savestates", "data/savestate.png", NULL, NULL, InitPanelSavestate, ExitPanelSavestate, RefreshPanelSavestate, HelpPanelSavestate },
{ "Miscellaneous", "data/misc.ico", NULL, NULL, InitPanelMisc, ExitPanelMisc, RefreshPanelMisc, HelpPanelMisc },
{ "Savestates", "data/savestate.png", NULL, NULL, InitPanelSavestate, ExitPanelSavestate, RefreshPanelSavestate, HelpPanelSavestate },
#ifdef ANDROIDSDL #ifdef ANDROIDSDL
{ "OnScreen", "data/screen.ico", NULL, NULL, InitPanelOnScreen, ExitPanelOnScreen, RefreshPanelOnScreen, HelpPanelOnScreen }, { "OnScreen", "data/screen.ico", NULL, NULL, InitPanelOnScreen, ExitPanelOnScreen, RefreshPanelOnScreen, HelpPanelOnScreen },
#endif #endif
{ NULL, NULL, NULL, NULL, NULL, NULL, NULL } { NULL, NULL, NULL, NULL, NULL, NULL, NULL }
}; };
enum enum
@ -280,7 +278,7 @@ namespace sdl
void gui_init() void gui_init()
{ {
#ifdef USE_SDL1 #ifdef PANDORA
//------------------------------------------------- //-------------------------------------------------
// Set layer for GUI screen // Set layer for GUI screen
//------------------------------------------------- //-------------------------------------------------
@ -294,10 +292,10 @@ namespace sdl
// Create new screen for GUI // Create new screen for GUI
//------------------------------------------------- //-------------------------------------------------
#ifdef USE_SDL1 #ifdef USE_SDL1
const SDL_VideoInfo* videoInfo = SDL_GetVideoInfo();
gui_screen = SDL_SetVideoMode(GUI_WIDTH, GUI_HEIGHT, 16, SDL_SWSURFACE | SDL_FULLSCREEN); gui_screen = SDL_SetVideoMode(GUI_WIDTH, GUI_HEIGHT, 16, SDL_SWSURFACE | SDL_FULLSCREEN);
SDL_EnableUNICODE(1); SDL_EnableUNICODE(1);
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
SDL_ShowCursor(SDL_ENABLE);
#endif #endif
#ifdef USE_SDL2 #ifdef USE_SDL2
setup_cursor(); setup_cursor();
@ -350,14 +348,18 @@ namespace sdl
delete gui_input; delete gui_input;
delete gui_graphics; delete gui_graphics;
#ifdef USE_SDL1
if (gui_screen != nullptr) if (gui_screen != nullptr)
{
SDL_FreeSurface(gui_screen); SDL_FreeSurface(gui_screen);
#elif USE_SDL2 gui_screen = nullptr;
SDL_FreeSurface(gui_screen); }
SDL_DestroyTexture(gui_texture); #ifdef USE_SDL2
gui_texture = nullptr; if (gui_texture != nullptr)
{
SDL_DestroyTexture(gui_texture);
gui_texture = nullptr;
}
if (cursor) if (cursor)
{ {
@ -370,7 +372,6 @@ namespace sdl
cursorSurface = nullptr; cursorSurface = nullptr;
} }
#endif #endif
gui_screen = nullptr;
} }
void checkInput() void checkInput()
@ -399,77 +400,81 @@ namespace sdl
gcn::FocusHandler* focusHdl; gcn::FocusHandler* focusHdl;
gcn::Widget* activeWidget; gcn::Widget* activeWidget;
const int hat = SDL_JoystickGetHat(GUIjoy, 0); if (GUIjoy)
if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_up) || (hat & SDL_HAT_UP)) // dpad
{ {
if (HandleNavigation(DIRECTION_UP)) const int hat = SDL_JoystickGetHat(GUIjoy, 0);
continue; // Don't change value when enter Slider -> don't send event to control
PushFakeKey(SDLK_UP);
break;
}
if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_down) || (hat & SDL_HAT_DOWN)) // dpad
{
if (HandleNavigation(DIRECTION_DOWN))
continue; // Don't change value when enter Slider -> don't send event to control
PushFakeKey(SDLK_DOWN);
break;
}
if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_up) || (hat & SDL_HAT_UP)) // dpad
if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].left_shoulder)) // dpad
{
for (int z = 0; z<10; ++z)
{ {
if (HandleNavigation(DIRECTION_UP))
continue; // Don't change value when enter Slider -> don't send event to control
PushFakeKey(SDLK_UP); PushFakeKey(SDLK_UP);
break;
} }
} if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_down) || (hat & SDL_HAT_DOWN)) // dpad
if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].right_shoulder)) // dpad
{
for (int z = 0; z<10; ++z)
{ {
if (HandleNavigation(DIRECTION_DOWN))
continue; // Don't change value when enter Slider -> don't send event to control
PushFakeKey(SDLK_DOWN); PushFakeKey(SDLK_DOWN);
break;
}
if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].left_shoulder)) // dpad
{
for (int z = 0; z<10; ++z)
{
PushFakeKey(SDLK_UP);
}
}
if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].right_shoulder)) // dpad
{
for (int z = 0; z<10; ++z)
{
PushFakeKey(SDLK_DOWN);
}
}
if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_right) || (hat & SDL_HAT_RIGHT)) // dpad
{
if (HandleNavigation(DIRECTION_RIGHT))
continue; // Don't change value when enter Slider -> don't send event to control
PushFakeKey(SDLK_RIGHT);
break;
}
if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_left) || (hat & SDL_HAT_LEFT)) // dpad
{
if (HandleNavigation(DIRECTION_LEFT))
continue; // Don't change value when enter Slider -> don't send event to control
PushFakeKey(SDLK_LEFT);
break;
}
if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].south_button)) // need this to be X button
{
PushFakeKey(SDLK_RETURN);
continue;
}
if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].quit_button) &&
SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].hotkey_button)) // use the HOTKEY button
{
uae_quit();
gui_running = false;
break;
}
if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].left_trigger))
{
ShowHelpRequested();
widgets::cmdHelp->requestFocus();
break;
}
if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].menu_button)) // use the HOTKEY button
{
gui_running = false;
} }
} }
break;
if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_right) || (hat & SDL_HAT_RIGHT)) // dpad
{
if (HandleNavigation(DIRECTION_RIGHT))
continue; // Don't change value when enter Slider -> don't send event to control
PushFakeKey(SDLK_RIGHT);
break;
}
if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_left) || (hat & SDL_HAT_LEFT)) // dpad
{
if (HandleNavigation(DIRECTION_LEFT))
continue; // Don't change value when enter Slider -> don't send event to control
PushFakeKey(SDLK_LEFT);
break;
}
if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].south_button)) // need this to be X button
{
PushFakeKey(SDLK_RETURN);
continue;
}
if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].quit_button) &&
SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].hotkey_button)) // use the HOTKEY button
{
uae_quit();
gui_running = false;
break;
}
if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].left_trigger))
{
ShowHelpRequested();
widgets::cmdHelp->requestFocus();
break;
}
if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].menu_button)) // use the HOTKEY button
{
gui_running = false;
}
} }
if (gui_event.type == SDL_KEYDOWN) if (gui_event.type == SDL_KEYDOWN)
@ -562,9 +567,9 @@ namespace sdl
#elif USE_SDL2 #elif USE_SDL2
case SDL_SCANCODE_F1: case SDL_SCANCODE_F1:
#endif #endif
ShowHelpRequested(); ShowHelpRequested();
widgets::cmdHelp->requestFocus(); widgets::cmdHelp->requestFocus();
break; break;
default: default:
break; break;
@ -584,7 +589,8 @@ namespace sdl
void gui_run() void gui_run()
{ {
GUIjoy = SDL_JoystickOpen(0); if (SDL_NumJoysticks() > 0)
GUIjoy = SDL_JoystickOpen(0);
//------------------------------------------------- //-------------------------------------------------
// The main loop // The main loop
@ -607,16 +613,17 @@ namespace sdl
if (refreshFuncAfterDraw != nullptr) if (refreshFuncAfterDraw != nullptr)
{ {
void (*currFunc)() = refreshFuncAfterDraw; void(*currFunc)() = refreshFuncAfterDraw;
refreshFuncAfterDraw = nullptr; refreshFuncAfterDraw = nullptr;
currFunc(); currFunc();
} }
} }
SDL_JoystickClose(GUIjoy);
if (GUIjoy)
SDL_JoystickClose(GUIjoy);
} }
} }
namespace widgets namespace widgets
{ {
class MainButtonActionListener : public gcn::ActionListener class MainButtonActionListener : public gcn::ActionListener
@ -851,7 +858,7 @@ namespace widgets
gui_top->add(cmdStart, GUI_WIDTH - DISTANCE_BORDER - BUTTON_WIDTH, GUI_HEIGHT - DISTANCE_BORDER - BUTTON_HEIGHT); gui_top->add(cmdStart, GUI_WIDTH - DISTANCE_BORDER - BUTTON_WIDTH, GUI_HEIGHT - DISTANCE_BORDER - BUTTON_HEIGHT);
gui_top->add(selectors, DISTANCE_BORDER + 1, DISTANCE_BORDER + 1); gui_top->add(selectors, DISTANCE_BORDER + 1, DISTANCE_BORDER + 1);
for (i = 0 , yPos = 0; categories[i].category != nullptr; ++i , yPos += 24) for (i = 0, yPos = 0; categories[i].category != nullptr; ++i, yPos += 24)
{ {
selectors->add(categories[i].selector, 0, yPos); selectors->add(categories[i].selector, 0, yPos);
gui_top->add(categories[i].panel, panelStartX, DISTANCE_BORDER + 1); gui_top->add(categories[i].panel, panelStartX, DISTANCE_BORDER + 1);
@ -936,7 +943,8 @@ void run_gui()
{ {
sdl::gui_init(); sdl::gui_init();
widgets::gui_init(); widgets::gui_init();
if (_tcslen(startup_message) > 0) { if (_tcslen(startup_message) > 0)
{
ShowMessage(startup_title, startup_message, _T(""), _T("Ok"), _T("")); ShowMessage(startup_title, startup_message, _T(""), _T("Ok"), _T(""));
_tcscpy(startup_title, _T("")); _tcscpy(startup_title, _T(""));
_tcscpy(startup_message, _T("")); _tcscpy(startup_message, _T(""));
@ -953,7 +961,7 @@ void run_gui()
} }
#endif #endif
} }
// Catch all GUI framework exceptions. // Catch all GUI framework exceptions.
catch (gcn::Exception e) catch (gcn::Exception e)
{ {
@ -967,14 +975,14 @@ void run_gui()
cout << "Std exception: " << e.what() << endl; cout << "Std exception: " << e.what() << endl;
uae_quit(); uae_quit();
} }
// Catch all unknown exceptions. // Catch all unknown exceptions.
catch (...) catch (...)
{ {
cout << "Unknown exception" << endl; cout << "Unknown exception" << endl;
uae_quit(); uae_quit();
} }
expansion_generate_autoconfig_info(&changed_prefs); expansion_generate_autoconfig_info(&changed_prefs);
cfgfile_compatibility_romtype(&changed_prefs); cfgfile_compatibility_romtype(&changed_prefs);