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,6 +280,8 @@ static void CreateFilesysHardfileLoop()
gcn::FocusHandler* focusHdl; gcn::FocusHandler* focusHdl;
gcn::Widget* activeWidget; gcn::Widget* activeWidget;
if (GUIjoy)
{
const int hat = SDL_JoystickGetHat(GUIjoy, 0); 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
@ -324,6 +324,8 @@ static void CreateFilesysHardfileLoop()
break; break;
} }
} }
break;
}
//------------------------------------------------- //-------------------------------------------------
// Send event to guisan-controls // Send event to guisan-controls

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,6 +454,8 @@ static void EditFilesysHardfileLoop()
gcn::FocusHandler* focusHdl; gcn::FocusHandler* focusHdl;
gcn::Widget* activeWidget; gcn::Widget* activeWidget;
if (GUIjoy)
{
const int hat = SDL_JoystickGetHat(GUIjoy, 0); 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
@ -497,6 +498,8 @@ static void EditFilesysHardfileLoop()
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,6 +283,8 @@ static void EditFilesysVirtualLoop()
gcn::FocusHandler* focusHdl; gcn::FocusHandler* focusHdl;
gcn::Widget* activeWidget; gcn::Widget* activeWidget;
if (GUIjoy)
{
const int hat = SDL_JoystickGetHat(GUIjoy, 0); 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
@ -326,6 +327,8 @@ static void EditFilesysVirtualLoop()
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,12 +105,14 @@ 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) || 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) ||
SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].east_button)) SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].east_button))
msg_done = 1; msg_done = 1;
}
break; 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;
@ -377,6 +374,8 @@ static void SelectFileLoop()
} }
} }
else if (event.type == SDL_JOYBUTTONDOWN || event.type == SDL_JOYHATMOTION) else if (event.type == SDL_JOYBUTTONDOWN || event.type == SDL_JOYHATMOTION)
{
if (GUIjoy)
{ {
const int hat = SDL_JoystickGetHat(GUIjoy, 0); const int hat = SDL_JoystickGetHat(GUIjoy, 0);
@ -412,6 +411,8 @@ static void SelectFileLoop()
break; break;
} }
} }
break;
}
//------------------------------------------------- //-------------------------------------------------
// Send event to guisan-controls // Send event to guisan-controls

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;
@ -278,6 +277,8 @@ static void SelectFolderLoop()
} }
} }
else if (event.type == SDL_JOYBUTTONDOWN || event.type == SDL_JOYHATMOTION) else if (event.type == SDL_JOYBUTTONDOWN || event.type == SDL_JOYHATMOTION)
{
if (GUIjoy)
{ {
const int hat = SDL_JoystickGetHat(GUIjoy, 0); const int hat = SDL_JoystickGetHat(GUIjoy, 0);
@ -318,6 +319,8 @@ static void SelectFolderLoop()
break; break;
} }
} }
break;
}
//------------------------------------------------- //-------------------------------------------------
// Send event to guisan-controls // Send event to guisan-controls

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;
@ -186,6 +182,8 @@ static void ShowHelpLoop(void)
} }
} }
else if (event.type == SDL_JOYBUTTONDOWN) else if (event.type == SDL_JOYBUTTONDOWN)
{
if (GUIjoy)
{ {
if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].south_button)) if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].south_button))
{ {
@ -199,6 +197,8 @@ static void ShowHelpLoop(void)
break; break;
} }
} }
break;
}
//------------------------------------------------- //-------------------------------------------------
// Send event to guisan-controls // Send event to guisan-controls

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;
@ -220,6 +217,8 @@ static void ShowMessageLoop()
} }
} }
else if (event.type == SDL_JOYBUTTONDOWN || event.type == SDL_JOYHATMOTION) else if (event.type == SDL_JOYBUTTONDOWN || event.type == SDL_JOYHATMOTION)
{
if (GUIjoy)
{ {
const int hat = SDL_JoystickGetHat(GUIjoy, 0); const int hat = SDL_JoystickGetHat(GUIjoy, 0);
@ -244,6 +243,8 @@ static void ShowMessageLoop()
break; break;
} }
} }
break;
}
//------------------------------------------------- //-------------------------------------------------
// Send event to guisan-controls // Send event to guisan-controls

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,9 +62,7 @@ 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 },
#endif
{ "Miscellaneous", "data/misc.ico", NULL, NULL, InitPanelMisc, ExitPanelMisc, RefreshPanelMisc, HelpPanelMisc }, { "Miscellaneous", "data/misc.ico", NULL, NULL, InitPanelMisc, ExitPanelMisc, RefreshPanelMisc, HelpPanelMisc },
{ "Savestates", "data/savestate.png", NULL, NULL, InitPanelSavestate, ExitPanelSavestate, RefreshPanelSavestate, HelpPanelSavestate }, { "Savestates", "data/savestate.png", NULL, NULL, InitPanelSavestate, ExitPanelSavestate, RefreshPanelSavestate, HelpPanelSavestate },
#ifdef ANDROIDSDL #ifdef ANDROIDSDL
@ -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); }
#ifdef USE_SDL2
if (gui_texture != nullptr)
{
SDL_DestroyTexture(gui_texture); SDL_DestroyTexture(gui_texture);
gui_texture = nullptr; 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,6 +400,8 @@ namespace sdl
gcn::FocusHandler* focusHdl; gcn::FocusHandler* focusHdl;
gcn::Widget* activeWidget; gcn::Widget* activeWidget;
if (GUIjoy)
{
const int hat = SDL_JoystickGetHat(GUIjoy, 0); 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
@ -471,6 +474,8 @@ namespace sdl
gui_running = false; gui_running = false;
} }
} }
break;
}
if (gui_event.type == SDL_KEYDOWN) if (gui_event.type == SDL_KEYDOWN)
{ {
@ -584,6 +589,7 @@ namespace sdl
void gui_run() void gui_run()
{ {
if (SDL_NumJoysticks() > 0)
GUIjoy = SDL_JoystickOpen(0); GUIjoy = SDL_JoystickOpen(0);
//------------------------------------------------- //-------------------------------------------------
@ -612,11 +618,12 @@ namespace sdl
currFunc(); currFunc();
} }
} }
if (GUIjoy)
SDL_JoystickClose(GUIjoy); SDL_JoystickClose(GUIjoy);
} }
} }
namespace widgets namespace widgets
{ {
class MainButtonActionListener : public gcn::ActionListener class MainButtonActionListener : public gcn::ActionListener
@ -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(""));