From 59f80f9d9b255f3ea17165d4ea30867d74c57182 Mon Sep 17 00:00:00 2001 From: Dimitris Panokostas Date: Sun, 3 Dec 2017 12:26:52 +0100 Subject: [PATCH] Code cleanup and minor improvements, brought back FocusBugWorkaround (still needed in guisan) --- .../Amiberry/Amiberry-Debug.vgdbsettings | 27 +++ VisualGDB/guisan/guisan.vcxproj | 2 + src/osdep/amiberry_filesys.cpp | 171 ++++++++--------- src/osdep/gui/EditFilesysHardfile.cpp | 174 +++++++++--------- src/osdep/gui/EditFilesysVirtual.cpp | 131 +++++++------ src/osdep/gui/PanelHD.cpp | 6 +- src/osdep/gui/SelectFile.cpp | 158 ++++++++-------- src/osdep/gui/SelectFolder.cpp | 159 ++++++++-------- src/osdep/gui/SelectorEntry.cpp | 12 +- src/osdep/gui/SelectorEntry.hpp | 2 +- src/osdep/gui/ShowHelp.cpp | 62 ++++--- src/osdep/gui/ShowMessage.cpp | 75 ++++---- src/osdep/gui/main_window.cpp | 46 ++--- 13 files changed, 545 insertions(+), 480 deletions(-) diff --git a/VisualGDB/Amiberry/Amiberry-Debug.vgdbsettings b/VisualGDB/Amiberry/Amiberry-Debug.vgdbsettings index cecbe61b..e97229df 100644 --- a/VisualGDB/Amiberry/Amiberry-Debug.vgdbsettings +++ b/VisualGDB/Amiberry/Amiberry-Debug.vgdbsettings @@ -6,11 +6,38 @@ MinGWUnixSlash + + None + 192.168.1.189 SSH pi + + false + + None + + $(ProjectDir) + /tmp/VisualGDB/$(ProjectDirUnixStyle) + + *.cpp + *.h + *.hpp + *.c + *.cc + *.cxx + *.mak + Makefile + *.txt + *.cmake + + true + true + false + true + false false false diff --git a/VisualGDB/guisan/guisan.vcxproj b/VisualGDB/guisan/guisan.vcxproj index 6e7d12cf..72d1ceaa 100644 --- a/VisualGDB/guisan/guisan.vcxproj +++ b/VisualGDB/guisan/guisan.vcxproj @@ -45,6 +45,7 @@ GNUPP14 =/usr/local/include/SDL2;=/opt/vc/include;=/opt/vc/include/interface/vcos/pthreads;=/opt/vc/include/interface/vmcs_host/linux;../../src/guisan/include;%(ClCompile.AdditionalIncludeDirectories) DEBUG=1;_REENTRANT;%(ClCompile.PreprocessorDefinitions) + -march=armv8-a -mfpu=neon-fp-armv8 -mfloat-abi=hard %(AdditionalOptions) ;%(Link.AdditionalLinkerInputs) @@ -58,6 +59,7 @@ GNUPP14 =/usr/local/include/SDL2;=/opt/vc/include;=/opt/vc/include/interface/vcos/pthreads;=/opt/vc/include/interface/vmcs_host/linux;../../src/guisan/include;%(ClCompile.AdditionalIncludeDirectories) NDEBUG=1;RELEASE=1;_REENTRANT;%(ClCompile.PreprocessorDefinitions) + -march=armv8-a -mfpu=neon-fp-armv8 -mfloat-abi=hard %(AdditionalOptions) ;%(Link.AdditionalLinkerInputs) diff --git a/src/osdep/amiberry_filesys.cpp b/src/osdep/amiberry_filesys.cpp index 078aa37b..d0548562 100644 --- a/src/osdep/amiberry_filesys.cpp +++ b/src/osdep/amiberry_filesys.cpp @@ -8,199 +8,199 @@ #include "options.h" -int my_setcurrentdir (const TCHAR *curdir, TCHAR *oldcur) +int my_setcurrentdir(const TCHAR* curdir, TCHAR* oldcur) { - int ret = 0; + const int ret = 0; if (oldcur) getcwd(oldcur, MAX_DPATH); if (curdir) - chdir (curdir); + chdir(curdir); return ret; } -int my_mkdir (const char*name) +int my_mkdir(const char* name) { - return mkdir(name, 0777); + return mkdir(name, 0777); } -int my_rmdir (const char*name) +int my_rmdir(const char* name) { - return rmdir(name); + return rmdir(name); } -int my_unlink (const char* name) +int my_unlink(const char* name) { - return unlink(name); + return unlink(name); } -int my_rename (const char* oldname, const char* newname) +int my_rename(const char* oldname, const char* newname) { - return rename(oldname, newname); + return rename(oldname, newname); } -struct my_opendir_s +struct my_opendir_s { - void *h; + void* h; }; -struct my_opendir_s *my_opendir (const char* name) +struct my_opendir_s* my_opendir(const char* name) { - struct my_opendir_s *mod; + struct my_opendir_s* mod; mod = xmalloc (struct my_opendir_s, 1); if (!mod) - return NULL; - mod->h = opendir(name); - if (mod->h == NULL) { + return nullptr; + mod->h = opendir(name); + if (mod->h == nullptr) + { xfree (mod); - return NULL; + return nullptr; } return mod; } -void my_closedir (struct my_opendir_s *mod) +void my_closedir(struct my_opendir_s* mod) { if (mod) - closedir((DIR *) mod->h); + closedir(static_cast(mod->h)); xfree (mod); } -int my_readdir (struct my_opendir_s *mod, char* name) +int my_readdir(struct my_opendir_s* mod, char* name) { - struct dirent *de; - - if (!mod) - return 0; - - de = readdir((DIR *) mod->h); - if(de == 0) - return 0; + if (!mod) + return 0; + + struct dirent * de = readdir(static_cast(mod->h)); + if (de == nullptr) + return 0; strncpy(name, de->d_name, MAX_PATH); return 1; } -struct my_openfile_s +struct my_openfile_s { - void *h; + void* h; }; -void my_close (struct my_openfile_s *mos) +void my_close(struct my_openfile_s* mos) { - if(mos) - close((int) mos->h); - xfree (mos); + if (mos) + close(int(mos->h)); + xfree (mos); } -uae_s64 int my_lseek (struct my_openfile_s *mos, uae_s64 int offset, int pos) +uae_s64 int my_lseek(struct my_openfile_s* mos,const uae_s64 int offset, const int pos) { - return lseek((int) mos->h, offset, pos); + return lseek(int(mos->h), offset, pos); } -uae_s64 int my_fsize (struct my_openfile_s *mos) +uae_s64 int my_fsize(struct my_openfile_s* mos) { - uae_s64 pos = lseek((int) mos->h, 0, SEEK_CUR); - uae_s64 size = lseek((int) mos->h, 0, SEEK_END); - lseek((int) mos->h, pos, SEEK_SET); + uae_s64 pos = lseek(int(mos->h), 0, SEEK_CUR); + uae_s64 size = lseek(int(mos->h), 0, SEEK_END); + lseek(int(mos->h), pos, SEEK_SET); return size; } -unsigned int my_read (struct my_openfile_s *mos, void *b, unsigned int size) +unsigned int my_read(struct my_openfile_s* mos, void* b, unsigned int size) { - return read((int) mos->h, b, size); + return read(int(mos->h), b, size); } -unsigned int my_write (struct my_openfile_s *mos, void *b, unsigned int size) +unsigned int my_write(struct my_openfile_s* mos, void* b, unsigned int size) { - return write((int) mos->h, b, size); + return write(int(mos->h), b, size); } -int my_existsfile (const char *name) +int my_existsfile(const char* name) { struct stat st; - if (lstat (name, &st) == -1) { + if (lstat(name, &st) == -1) + { return 0; - } else { - if (!S_ISDIR(st.st_mode)) - return 1; } - return 0; + if (!S_ISDIR(st.st_mode)) + return 1; + return 0; } -int my_existsdir(const char *name) +int my_existsdir(const char* name) { - struct stat st; + struct stat st; - if(lstat(name, &st) == -1) { - return 0; - } else { - if (S_ISDIR(st.st_mode)) - return 1; - } - return 0; + if (lstat(name, &st) == -1) + { + return 0; + } + if (S_ISDIR(st.st_mode)) + return 1; + return 0; } -struct my_openfile_s *my_open (const TCHAR *name, int flags) +struct my_openfile_s* my_open(const TCHAR* name, const int flags) { - struct my_openfile_s *mos; + struct my_openfile_s* mos; mos = xmalloc (struct my_openfile_s, 1); if (!mos) - return NULL; + return nullptr; if (flags & O_CREAT) mos->h = reinterpret_cast(open(name, flags, 0660)); else mos->h = reinterpret_cast(open(name, flags)); - if (!mos->h) { + if (!mos->h) + { xfree (mos); - mos = NULL; - } - return mos; + mos = nullptr; + } + return mos; } -int my_truncate (const TCHAR *name, uae_u64 len) +int my_truncate(const TCHAR* name, uae_u64 len) { - return truncate(name, len); + return truncate(name, len); } -int my_getvolumeinfo (const char *root) +int my_getvolumeinfo(const char* root) { - struct stat st; - int ret = 0; + struct stat st; + const int ret = 0; - if (lstat (root, &st) == -1) - return -1; - if (!S_ISDIR(st.st_mode)) - return -2; - return ret; + if (lstat(root, &st) == -1) + return -1; + if (!S_ISDIR(st.st_mode)) + return -2; + return ret; } -FILE *my_opentext (const TCHAR *name) +FILE* my_opentext(const TCHAR* name) { - return fopen (name, "r"); + return fopen(name, "r"); } -bool my_issamepath(const TCHAR *path1, const TCHAR *path2) +bool my_issamepath(const TCHAR* path1, const TCHAR* path2) { if (!_tcsicmp(path1, path2)) return true; @@ -208,9 +208,9 @@ bool my_issamepath(const TCHAR *path1, const TCHAR *path2) } -const TCHAR *my_getfilepart(const TCHAR *filename) +const TCHAR* my_getfilepart(const TCHAR* filename) { - const TCHAR *p; + const TCHAR* p; p = _tcsrchr(filename, '\\'); if (p) @@ -223,8 +223,9 @@ const TCHAR *my_getfilepart(const TCHAR *filename) /* Returns 1 if an actual volume-name was found, 2 if no volume-name (so uses some defaults) */ -int target_get_volume_name(struct uaedev_mount_info *mtinf, struct uaedev_config_info *ci, bool inserted, bool fullcheck, int cnt) +int target_get_volume_name(struct uaedev_mount_info* mtinf, struct uaedev_config_info* ci, bool inserted, + bool fullcheck, int cnt) { sprintf(ci->volname, "DH_%c", ci->rootdir[0]); - return 2; + return 2; } diff --git a/src/osdep/gui/EditFilesysHardfile.cpp b/src/osdep/gui/EditFilesysHardfile.cpp index 5d1c86ac..cadf7e42 100644 --- a/src/osdep/gui/EditFilesysHardfile.cpp +++ b/src/osdep/gui/EditFilesysHardfile.cpp @@ -27,19 +27,21 @@ #define DIALOG_WIDTH 620 #define DIALOG_HEIGHT 272 -static SDL_Joystick *GUIjoy; +static SDL_Joystick* GUIjoy; extern struct host_input_button host_input_buttons[MAX_INPUT_DEVICES]; static const char* harddisk_filter[] = {".hdf", "\0"}; -struct controller_map { +struct controller_map +{ int type; char display[64]; }; + static struct controller_map controller[] = { - { HD_CONTROLLER_TYPE_UAE, "UAE" }, - { HD_CONTROLLER_TYPE_IDE_FIRST, "A600/A1200/A4000 IDE" }, - { -1 } + {HD_CONTROLLER_TYPE_UAE, "UAE"}, + {HD_CONTROLLER_TYPE_IDE_FIRST, "A600/A1200/A4000 IDE"}, + {-1} }; static bool dialogResult = false; @@ -67,13 +69,13 @@ static gcn::Label* lblSectors; static gcn::TextField* txtSectors; static gcn::Label* lblBlocksize; static gcn::TextField* txtBlocksize; -static gcn::Label *lblController; +static gcn::Label* lblController; static gcn::UaeDropDown* cboController; static gcn::UaeDropDown* cboUnit; static void check_rdb(const TCHAR* filename) { - bool isrdb = hardfile_testrdb(filename); + const bool isrdb = hardfile_testrdb(filename); if (isrdb) { txtSectors->setText("0"); @@ -100,13 +102,14 @@ public: return 2; } - std::string getElementAt(int i) override + string getElementAt(const int i) override { if (i < 0 || i >= 2) return "---"; return controller[i].display; } }; + static ControllerListModel controllerListModel; @@ -122,7 +125,7 @@ public: return 4; } - std::string getElementAt(int i) override + string getElementAt(int i) override { char num[8]; @@ -132,6 +135,7 @@ public: return num; } }; + static UnitListModel unitListModel; class FilesysHardfileActionListener : public gcn::ActionListener @@ -153,8 +157,10 @@ public: wndEditFilesysHardfile->requestModalFocus(); cmdPath->requestFocus(); } - else if (actionEvent.getSource() == cboController) { - switch (controller[cboController->getSelected()].type) { + else if (actionEvent.getSource() == cboController) + { + switch (controller[cboController->getSelected()].type) + { case HD_CONTROLLER_TYPE_UAE: cboUnit->setSelected(0); cboUnit->setEnabled(false); @@ -190,11 +196,15 @@ static FilesysHardfileActionListener* filesysHardfileActionListener; static void InitEditFilesysHardfile() { - for (int i = 0; expansionroms[i].name; i++) { - const struct expansionromtype *erc = &expansionroms[i]; - if (erc->deviceflags & EXPANSIONTYPE_IDE) { - for (int j = 0; controller[j].type >= 0; ++j) { - if (!strcmp(erc->friendlyname, controller[j].display)) { + for (int i = 0; expansionroms[i].name; i++) + { + const struct expansionromtype* erc = &expansionroms[i]; + if (erc->deviceflags & EXPANSIONTYPE_IDE) + { + for (int j = 0; controller[j].type >= 0; ++j) + { + if (!strcmp(erc->friendlyname, controller[j].display)) + { controller[j].type = HD_CONTROLLER_TYPE_IDE_EXPANSION_FIRST + i; break; } @@ -213,14 +223,16 @@ static void InitEditFilesysHardfile() cmdOK = new gcn::Button("Ok"); cmdOK->setSize(BUTTON_WIDTH, BUTTON_HEIGHT); - cmdOK->setPosition(DIALOG_WIDTH - DISTANCE_BORDER - 2 * BUTTON_WIDTH - DISTANCE_NEXT_X, DIALOG_HEIGHT - 2 * DISTANCE_BORDER - BUTTON_HEIGHT - 10); + cmdOK->setPosition(DIALOG_WIDTH - DISTANCE_BORDER - 2 * BUTTON_WIDTH - DISTANCE_NEXT_X, + DIALOG_HEIGHT - 2 * DISTANCE_BORDER - BUTTON_HEIGHT - 10); cmdOK->setBaseColor(gui_baseCol); cmdOK->setId("hdfOK"); cmdOK->addActionListener(filesysHardfileActionListener); cmdCancel = new gcn::Button("Cancel"); cmdCancel->setSize(BUTTON_WIDTH, BUTTON_HEIGHT); - cmdCancel->setPosition(DIALOG_WIDTH - DISTANCE_BORDER - BUTTON_WIDTH, DIALOG_HEIGHT - 2 * DISTANCE_BORDER - BUTTON_HEIGHT - 10); + cmdCancel->setPosition(DIALOG_WIDTH - DISTANCE_BORDER - BUTTON_WIDTH, + DIALOG_HEIGHT - 2 * DISTANCE_BORDER - BUTTON_HEIGHT - 10); cmdCancel->setBaseColor(gui_baseCol); cmdCancel->setId("hdfCancel"); cmdCancel->addActionListener(filesysHardfileActionListener); @@ -386,8 +398,8 @@ static void ExitEditFilesysHardfile() static void EditFilesysHardfileLoop() { - // TODO: Check if this is needed in Guisan? - //FocusBugWorkaround(wndEditFilesysHardfile); + FocusBugWorkaround(wndEditFilesysHardfile); + GUIjoy = SDL_JoystickOpen(0); while (!dialogFinished) @@ -433,67 +445,62 @@ static void EditFilesysHardfileLoop() break; } } - else if (event.type == SDL_JOYBUTTONDOWN || event.type == SDL_JOYHATMOTION) - { - gcn::FocusHandler* focusHdl; - gcn::Widget* activeWidget; + else if (event.type == SDL_JOYBUTTONDOWN || event.type == SDL_JOYHATMOTION) + { + gcn::FocusHandler* focusHdl; + gcn::Widget* activeWidget; - 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(HandleNavigation(DIRECTION_UP)) - continue; // Don't change value when enter Slider -> don't send event to control - else - {PushFakeKey(SDLK_UP);} - break; - - } - else 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 - else - {PushFakeKey(SDLK_DOWN);} - break; - } - else 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 - else - {PushFakeKey(SDLK_RIGHT);} - break; - } - else 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 - else - {PushFakeKey(SDLK_LEFT);} - break; - } - - else if (SDL_JoystickGetButton(GUIjoy,host_input_buttons[0].south_button)) // need this to be X button - { - PushFakeKey(SDLK_RETURN); - continue; } - - else 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 - { dialogFinished = true; - break;} - } - //------------------------------------------------- - // Send event to guichan-controls - //------------------------------------------------- + if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_up) || (hat & SDL_HAT_UP)) // dpad + { + if (HandleNavigation(DIRECTION_UP)) + 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_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); + break; + } + 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 + { + dialogFinished = true; + break; + } + } + //------------------------------------------------- + // Send event to guichan-controls + //------------------------------------------------- #ifdef ANDROIDSDL - androidsdl_event(event, gui_input); + androidsdl_event(event, gui_input); #else - gui_input->pushInput(event); + gui_input->pushInput(event); #endif - } + } // Now we let the Gui object perform its logic. uae_gui->logic(); @@ -506,7 +513,7 @@ static void EditFilesysHardfileLoop() } -bool EditFilesysHardfile(int unit_no) +bool EditFilesysHardfile(const int unit_no) { struct mountedinfo mi; struct uaedev_config_data* uci; @@ -521,7 +528,7 @@ bool EditFilesysHardfile(int unit_no) if (unit_no >= 0) { uci = &changed_prefs.mountconfig[unit_no]; - struct uaedev_config_info * ci = &uci->ci; + struct uaedev_config_info* ci = &uci->ci; get_filesys_unitconfig(&changed_prefs, unit_no, &mi); strdevname.assign(ci->devname); @@ -543,7 +550,8 @@ bool EditFilesysHardfile(int unit_no) snprintf(tmp, sizeof tmp, "%d", ci->blocksize); txtBlocksize->setText(tmp); int selIndex = 0; - for (int i = 0; i < 2; ++i) { + for (int i = 0; i < 2; ++i) + { if (controller[i].type == ci->controller_type) selIndex = i; } @@ -575,12 +583,12 @@ bool EditFilesysHardfile(int unit_no) if (dialogResult) { struct uaedev_config_info ci; - int bp = tweakbootpri(atoi(txtBootPri->getText().c_str()), chkAutoboot->isSelected() ? 1 : 0, 0); + const int bp = tweakbootpri(atoi(txtBootPri->getText().c_str()), chkAutoboot->isSelected() ? 1 : 0, 0); extractPath(const_cast(txtPath->getText().c_str()), currentDir); uci_set_defaults(&ci, false); - strncpy(ci.devname, (char *) txtDevice->getText().c_str(), MAX_DPATH); - strncpy(ci.rootdir, (char *) txtPath->getText().c_str(), MAX_DPATH); + strncpy(ci.devname, const_cast(txtDevice->getText().c_str()), MAX_DPATH); + strncpy(ci.rootdir, const_cast(txtPath->getText().c_str()), MAX_DPATH); ci.type = UAEDEV_HDF; ci.controller_type = controller[cboController->getSelected()].type; ci.controller_type_unit = 0; @@ -599,7 +607,7 @@ bool EditFilesysHardfile(int unit_no) uci = add_filesys_config(&changed_prefs, unit_no, &ci); if (uci) { - struct hardfiledata *hfd = get_hardfile_data(uci->configoffset); + struct hardfiledata* hfd = get_hardfile_data(uci->configoffset); if (hfd) hardfile_media_change(hfd, &ci, true, false); else diff --git a/src/osdep/gui/EditFilesysVirtual.cpp b/src/osdep/gui/EditFilesysVirtual.cpp index 28f54f5a..be742ca1 100644 --- a/src/osdep/gui/EditFilesysVirtual.cpp +++ b/src/osdep/gui/EditFilesysVirtual.cpp @@ -27,10 +27,10 @@ #define DIALOG_WIDTH 520 #define DIALOG_HEIGHT 202 -static SDL_Joystick *GUIjoy; +static SDL_Joystick* GUIjoy; extern struct host_input_button host_input_buttons[MAX_INPUT_DEVICES]; -extern std::string volName; +extern string volName; static bool dialogResult = false; static bool dialogFinished = false; @@ -106,14 +106,16 @@ static void InitEditFilesysVirtual() cmdOK = new gcn::Button("Ok"); cmdOK->setSize(BUTTON_WIDTH, BUTTON_HEIGHT); - cmdOK->setPosition(DIALOG_WIDTH - DISTANCE_BORDER - 2 * BUTTON_WIDTH - DISTANCE_NEXT_X, DIALOG_HEIGHT - 2 * DISTANCE_BORDER - BUTTON_HEIGHT - 10); + cmdOK->setPosition(DIALOG_WIDTH - DISTANCE_BORDER - 2 * BUTTON_WIDTH - DISTANCE_NEXT_X, + DIALOG_HEIGHT - 2 * DISTANCE_BORDER - BUTTON_HEIGHT - 10); cmdOK->setBaseColor(gui_baseCol); cmdOK->setId("virtOK"); cmdOK->addActionListener(filesysVirtualActionListener); cmdCancel = new gcn::Button("Cancel"); cmdCancel->setSize(BUTTON_WIDTH, BUTTON_HEIGHT); - cmdCancel->setPosition(DIALOG_WIDTH - DISTANCE_BORDER - BUTTON_WIDTH, DIALOG_HEIGHT - 2 * DISTANCE_BORDER - BUTTON_HEIGHT - 10); + cmdCancel->setPosition(DIALOG_WIDTH - DISTANCE_BORDER - BUTTON_WIDTH, + DIALOG_HEIGHT - 2 * DISTANCE_BORDER - BUTTON_HEIGHT - 10); cmdCancel->setBaseColor(gui_baseCol); cmdCancel->setId("virtCancel"); cmdCancel->addActionListener(filesysVirtualActionListener); @@ -221,6 +223,8 @@ static void ExitEditFilesysVirtual() static void EditFilesysVirtualLoop() { + FocusBugWorkaround(wndEditFilesysVirtual); + GUIjoy = SDL_JoystickOpen(0); while (!dialogFinished) { @@ -265,67 +269,62 @@ static void EditFilesysVirtualLoop() break; } } - else if (event.type == SDL_JOYBUTTONDOWN || event.type == SDL_JOYHATMOTION) - { - gcn::FocusHandler* focusHdl; - gcn::Widget* activeWidget; + else if (event.type == SDL_JOYBUTTONDOWN || event.type == SDL_JOYHATMOTION) + { + gcn::FocusHandler* focusHdl; + gcn::Widget* activeWidget; - 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(HandleNavigation(DIRECTION_UP)) - continue; // Don't change value when enter Slider -> don't send event to control - else - {PushFakeKey(SDLK_UP);} - break; - - } - else 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 - else - {PushFakeKey(SDLK_DOWN);} - break; - } - else 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 - else - {PushFakeKey(SDLK_RIGHT);} - break; - } - else 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 - else - {PushFakeKey(SDLK_LEFT);} - break; - } - - else if (SDL_JoystickGetButton(GUIjoy,host_input_buttons[0].south_button)) // need this to be X button - { - PushFakeKey(SDLK_RETURN); - continue; } - - else 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 - { dialogFinished = true; - break;} - } - //------------------------------------------------- - // Send event to guichan-controls - //------------------------------------------------- + if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_up) || (hat & SDL_HAT_UP)) // dpad + { + if (HandleNavigation(DIRECTION_UP)) + 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_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); + break; + } + 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 + { + dialogFinished = true; + break; + } + } + //------------------------------------------------- + // Send event to guichan-controls + //------------------------------------------------- #ifdef ANDROIDSDL - androidsdl_event(event, gui_input); + androidsdl_event(event, gui_input); #else - gui_input->pushInput(event); + gui_input->pushInput(event); #endif - } + } // Now we let the Gui object perform its logic. uae_gui->logic(); @@ -338,7 +337,7 @@ static void EditFilesysVirtualLoop() } -bool EditFilesysVirtual(int unit_no) +bool EditFilesysVirtual(const int unit_no) { struct mountedinfo mi; struct uaedev_config_data* uci; @@ -353,7 +352,7 @@ bool EditFilesysVirtual(int unit_no) if (unit_no >= 0) { uci = &changed_prefs.mountconfig[unit_no]; - struct uaedev_config_info * ci = &uci->ci; + struct uaedev_config_info* ci = &uci->ci; get_filesys_unitconfig(&changed_prefs, unit_no, &mi); strdevname.assign(ci->devname); @@ -383,13 +382,13 @@ bool EditFilesysVirtual(int unit_no) if (dialogResult) { struct uaedev_config_info ci; - int bp = tweakbootpri(atoi(txtBootPri->getText().c_str()), chkAutoboot->isSelected() ? 1 : 0, 0); + const int bp = tweakbootpri(atoi(txtBootPri->getText().c_str()), chkAutoboot->isSelected() ? 1 : 0, 0); extractPath(const_cast(txtPath->getText().c_str()), currentDir); uci_set_defaults(&ci, true); - strncpy(ci.devname, (char *) txtDevice->getText().c_str(), MAX_DPATH); - strncpy(ci.volname, (char *) txtVolume->getText().c_str(), MAX_DPATH); - strncpy(ci.rootdir, (char *) txtPath->getText().c_str(), MAX_DPATH); + strncpy(ci.devname, const_cast(txtDevice->getText().c_str()), MAX_DPATH); + strncpy(ci.volname, const_cast(txtVolume->getText().c_str()), MAX_DPATH); + strncpy(ci.rootdir, const_cast(txtPath->getText().c_str()), MAX_DPATH); ci.type = UAEDEV_DIR; ci.readonly = !chkReadWrite->isSelected(); ci.bootpri = bp; diff --git a/src/osdep/gui/PanelHD.cpp b/src/osdep/gui/PanelHD.cpp index df6bdb31..65223be8 100644 --- a/src/osdep/gui/PanelHD.cpp +++ b/src/osdep/gui/PanelHD.cpp @@ -65,7 +65,7 @@ static gcn::Label* lblCDVolInfo; static gcn::Slider* sldCDVol; -static int GetHDType(int index) +static int GetHDType(const int index) { struct mountedinfo mi; @@ -273,7 +273,7 @@ public: { if (actionEvent.getSource() == sldCDVol) { - int newvol = 100 - (int)sldCDVol->getValue(); + const int newvol = 100 - int(sldCDVol->getValue()); if (changed_prefs.sound_volume_cd != newvol) { changed_prefs.sound_volume_cd = newvol; @@ -301,7 +301,7 @@ public: //--------------------------------------- if (!bIgnoreListChange) { - int idx = cboCDFile->getSelected(); + const int idx = cboCDFile->getSelected(); if (idx < 0) { diff --git a/src/osdep/gui/SelectFile.cpp b/src/osdep/gui/SelectFile.cpp index 96595ca9..106a5e1b 100644 --- a/src/osdep/gui/SelectFile.cpp +++ b/src/osdep/gui/SelectFile.cpp @@ -28,7 +28,7 @@ #define FILE_SELECT_KEEP_POSITION #endif -static SDL_Joystick *GUIjoy; +static SDL_Joystick* GUIjoy; extern struct host_input_button host_input_buttons[MAX_INPUT_DEVICES]; static bool dialogResult = false; @@ -98,14 +98,14 @@ public: { if (actionEvent.getSource() == cmdOK) { - int selected_item = lstFiles->getSelected(); + const int selected_item = lstFiles->getSelected(); if (createNew) { char tmp[MAX_PATH]; if (txtFilename->getText().length() <= 0) return; strncpy(tmp, workingDir, MAX_PATH - 1); - strncat(tmp, "/", MAX_PATH - 1); + strncat(tmp, "/", MAX_PATH - 1); strncat(tmp, txtFilename->getText().c_str(), MAX_PATH - 1); if (strstr(tmp, filefilter[0]) == nullptr) strncat(tmp, filefilter[0], MAX_PATH - 1); @@ -119,7 +119,7 @@ public: if (fileList->isDir(selected_item)) return; // Directory selected -> Ok not possible strncat(workingDir, "/", MAX_PATH - 1); - strncat(workingDir, fileList->getElementAt(selected_item).c_str(), MAX_PATH - 1); + strncat(workingDir, fileList->getElementAt(selected_item).c_str(), MAX_PATH - 1); dialogResult = true; } } @@ -138,7 +138,7 @@ static void checkfoldername(char* current) if ((dir = opendir(current))) { fileList->changeDir(current); - char * ptr = realpath(current, actualpath); + char* ptr = realpath(current, actualpath); strncpy(workingDir, ptr, MAX_PATH); closedir(dir); } @@ -170,10 +170,10 @@ public: { char foldername[MAX_PATH] = ""; - int selected_item = lstFiles->getSelected(); + const int selected_item = lstFiles->getSelected(); strncpy(foldername, workingDir, MAX_PATH); - strncat(foldername, "/", MAX_PATH - 1); - strncat(foldername, fileList->getElementAt(selected_item).c_str(), MAX_PATH - 1); + strncat(foldername, "/", MAX_PATH - 1); + strncat(foldername, fileList->getElementAt(selected_item).c_str(), MAX_PATH - 1); if (fileList->isDir(selected_item)) checkfoldername(foldername); else if (!createNew) @@ -201,13 +201,15 @@ static void InitSelectFile(const char* title) cmdOK = new gcn::Button("Ok"); cmdOK->setSize(BUTTON_WIDTH, BUTTON_HEIGHT); - cmdOK->setPosition(DIALOG_WIDTH - DISTANCE_BORDER - 2 * BUTTON_WIDTH - DISTANCE_NEXT_X, DIALOG_HEIGHT - 2 * DISTANCE_BORDER - BUTTON_HEIGHT - 10); + cmdOK->setPosition(DIALOG_WIDTH - DISTANCE_BORDER - 2 * BUTTON_WIDTH - DISTANCE_NEXT_X, + DIALOG_HEIGHT - 2 * DISTANCE_BORDER - BUTTON_HEIGHT - 10); cmdOK->setBaseColor(gui_baseCol); cmdOK->addActionListener(fileButtonActionListener); cmdCancel = new gcn::Button("Cancel"); cmdCancel->setSize(BUTTON_WIDTH, BUTTON_HEIGHT); - cmdCancel->setPosition(DIALOG_WIDTH - DISTANCE_BORDER - BUTTON_WIDTH, DIALOG_HEIGHT - 2 * DISTANCE_BORDER - BUTTON_HEIGHT - 10); + cmdCancel->setPosition(DIALOG_WIDTH - DISTANCE_BORDER - BUTTON_WIDTH, + DIALOG_HEIGHT - 2 * DISTANCE_BORDER - BUTTON_HEIGHT - 10); cmdCancel->setBaseColor(gui_baseCol); cmdCancel->addActionListener(fileButtonActionListener); @@ -287,9 +289,9 @@ static void ExitSelectFile() static void SelectFileLoop() { -//TODO: is this needed in guisan? - //FocusBugWorkaround(wndSelectFile); - GUIjoy = SDL_JoystickOpen(0); + FocusBugWorkaround(wndSelectFile); + + GUIjoy = SDL_JoystickOpen(0); while (!dialogFinished) { @@ -319,7 +321,6 @@ static void SelectFileLoop() lstFiles->requestFocus(); else if (activeWidget == txtFilename) lstFiles->requestFocus(); - continue; } break; @@ -338,7 +339,6 @@ static void SelectFileLoop() lstFiles->requestFocus(); else if (activeWidget == cmdOK) cmdCancel->requestFocus(); - continue; } break; @@ -348,78 +348,78 @@ static void SelectFileLoop() gui_input->pushInput(event); // Fire key down event.type = SDL_KEYUP; // and the key up break; - default: + default: + break; + } + } + else if (event.type == SDL_JOYBUTTONDOWN || event.type == SDL_JOYHATMOTION) + { + const int hat = SDL_JoystickGetHat(GUIjoy, 0); + + if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].south_button)) + { + PushFakeKey(SDLK_RETURN); + break; + } + if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].east_button) || + SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].start_button)) + { + dialogFinished = true; + break; + } + if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_left) || (hat & SDL_HAT_LEFT)) + { + gcn::FocusHandler* focusHdl = gui_top->_getFocusHandler(); + gcn::Widget* activeWidget = focusHdl->getFocused(); + if (activeWidget == lstFiles) + cmdCancel->requestFocus(); + else if (activeWidget == cmdCancel) + cmdOK->requestFocus(); + else if (activeWidget == cmdOK) + if (createNew) + txtFilename->requestFocus(); + else + lstFiles->requestFocus(); + else if (activeWidget == txtFilename) + lstFiles->requestFocus(); + break; + } + if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_right) || (hat & SDL_HAT_RIGHT)) + { + gcn::FocusHandler* focusHdl = gui_top->_getFocusHandler(); + gcn::Widget* activeWidget = focusHdl->getFocused(); + if (activeWidget == lstFiles) + if (createNew) + txtFilename->requestFocus(); + else + cmdOK->requestFocus(); + else if (activeWidget == txtFilename) + cmdOK->requestFocus(); + else if (activeWidget == cmdCancel) + lstFiles->requestFocus(); + else if (activeWidget == cmdOK) + cmdCancel->requestFocus(); + break; + } + if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_up) || (hat & SDL_HAT_UP)) + { + PushFakeKey(SDLK_UP); + break; + } + if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_down) || (hat & SDL_HAT_DOWN)) + { + PushFakeKey(SDLK_DOWN); break; } } - else if (event.type == SDL_JOYBUTTONDOWN || event.type == SDL_JOYHATMOTION) - { - int hat = SDL_JoystickGetHat(GUIjoy, 0); - - if (SDL_JoystickGetButton(GUIjoy,host_input_buttons[0].south_button)) - {PushFakeKey(SDLK_RETURN); - break;} - - else if (SDL_JoystickGetButton(GUIjoy,host_input_buttons[0].east_button) || - SDL_JoystickGetButton(GUIjoy,host_input_buttons[0].start_button)) - {dialogFinished = true; - break;} - - else if (SDL_JoystickGetButton(GUIjoy,host_input_buttons[0].dpad_left) || (hat & SDL_HAT_LEFT)) - { - gcn::FocusHandler* focusHdl = gui_top->_getFocusHandler(); - gcn::Widget* activeWidget = focusHdl->getFocused(); - if(activeWidget == lstFiles) - cmdCancel->requestFocus(); - else if(activeWidget == cmdCancel) - cmdOK->requestFocus(); - else if(activeWidget == cmdOK) - if(createNew) - txtFilename->requestFocus(); - else - lstFiles->requestFocus(); - else if(activeWidget == txtFilename) - lstFiles->requestFocus(); - continue; - } - - - else if (SDL_JoystickGetButton(GUIjoy,host_input_buttons[0].dpad_right) || (hat & SDL_HAT_RIGHT)) - { - gcn::FocusHandler* focusHdl = gui_top->_getFocusHandler(); - gcn::Widget* activeWidget = focusHdl->getFocused(); - if(activeWidget == lstFiles) - if(createNew) - txtFilename->requestFocus(); - else - cmdOK->requestFocus(); - else if(activeWidget == txtFilename) - cmdOK->requestFocus(); - else if(activeWidget == cmdCancel) - lstFiles->requestFocus(); - else if(activeWidget == cmdOK) - cmdCancel->requestFocus(); - continue; - } - - else if (SDL_JoystickGetButton(GUIjoy,host_input_buttons[0].dpad_up) || (hat & SDL_HAT_UP)) - {PushFakeKey(SDLK_UP); - break;} - - else if (SDL_JoystickGetButton(GUIjoy,host_input_buttons[0].dpad_down) || (hat & SDL_HAT_DOWN)) - {PushFakeKey(SDLK_DOWN); - break;} - - - } //------------------------------------------------- // Send event to guisan-controls //------------------------------------------------- #ifdef ANDROIDSDL - androidsdl_event(event, gui_input); + androidsdl_event(event, gui_input); #else - gui_input->pushInput(event); + gui_input->pushInput(event); #endif } @@ -444,7 +444,7 @@ static void SelectFileLoop() static int Already_init = 0; #endif -bool SelectFile(const char* title, char* value, const char* filter[], bool create) +bool SelectFile(const char* title, char* value, const char* filter[], const bool create) { dialogResult = false; dialogFinished = false; diff --git a/src/osdep/gui/SelectFolder.cpp b/src/osdep/gui/SelectFolder.cpp index 1de82655..cbcafa8d 100644 --- a/src/osdep/gui/SelectFolder.cpp +++ b/src/osdep/gui/SelectFolder.cpp @@ -23,12 +23,12 @@ #define DIALOG_WIDTH 520 #define DIALOG_HEIGHT 400 -std::string volName; +string volName; static bool dialogResult = false; static bool dialogFinished = false; static char workingDir[MAX_PATH]; -static SDL_Joystick *GUIjoy; +static SDL_Joystick* GUIjoy; extern struct host_input_button host_input_buttons[MAX_INPUT_DEVICES]; static gcn::Window* wndSelectFolder; static gcn::Button* cmdOK; @@ -95,7 +95,7 @@ static void checkfoldername(char* current) if ((dir = opendir(current))) { dirList = current; - char * ptr = realpath(current, actualpath); + char* ptr = realpath(current, actualpath); strncpy(workingDir, ptr, MAX_PATH); closedir(dir); } @@ -112,7 +112,7 @@ public: { char foldername[MAX_PATH] = ""; - int selected_item = lstFolders->getSelected(); + const int selected_item = lstFolders->getSelected(); strncpy(foldername, workingDir, MAX_PATH - 1); strncat(foldername, "/", MAX_PATH - 1); strncat(foldername, dirList.getElementAt(selected_item).c_str(), MAX_PATH - 1); @@ -137,13 +137,15 @@ static void InitSelectFolder(const char* title) cmdOK = new gcn::Button("Ok"); cmdOK->setSize(BUTTON_WIDTH, BUTTON_HEIGHT); - cmdOK->setPosition(DIALOG_WIDTH - DISTANCE_BORDER - 2 * BUTTON_WIDTH - DISTANCE_NEXT_X, DIALOG_HEIGHT - 2 * DISTANCE_BORDER - BUTTON_HEIGHT - 10); + cmdOK->setPosition(DIALOG_WIDTH - DISTANCE_BORDER - 2 * BUTTON_WIDTH - DISTANCE_NEXT_X, + DIALOG_HEIGHT - 2 * DISTANCE_BORDER - BUTTON_HEIGHT - 10); cmdOK->setBaseColor(gui_baseCol); cmdOK->addActionListener(buttonActionListener); cmdCancel = new gcn::Button("Cancel"); cmdCancel->setSize(BUTTON_WIDTH, BUTTON_HEIGHT); - cmdCancel->setPosition(DIALOG_WIDTH - DISTANCE_BORDER - BUTTON_WIDTH, DIALOG_HEIGHT - 2 * DISTANCE_BORDER - BUTTON_HEIGHT - 10); + cmdCancel->setPosition(DIALOG_WIDTH - DISTANCE_BORDER - BUTTON_WIDTH, + DIALOG_HEIGHT - 2 * DISTANCE_BORDER - BUTTON_HEIGHT - 10); cmdCancel->setBaseColor(gui_baseCol); cmdCancel->addActionListener(buttonActionListener); @@ -198,30 +200,32 @@ static void ExitSelectFolder() } static void navigate_right(void) -{ gcn::FocusHandler* focusHdl = gui_top->_getFocusHandler(); - gcn::Widget* activeWidget = focusHdl->getFocused(); - if(activeWidget == lstFolders) - cmdOK->requestFocus(); - else if(activeWidget == cmdCancel) - lstFolders->requestFocus(); - else if(activeWidget == cmdOK) - cmdCancel->requestFocus(); - } +{ + gcn::FocusHandler* focusHdl = gui_top->_getFocusHandler(); + gcn::Widget* activeWidget = focusHdl->getFocused(); + if (activeWidget == lstFolders) + cmdOK->requestFocus(); + else if (activeWidget == cmdCancel) + lstFolders->requestFocus(); + else if (activeWidget == cmdOK) + cmdCancel->requestFocus(); +} static void navigate_left(void) - { - gcn::FocusHandler* focusHdl = gui_top->_getFocusHandler(); - gcn::Widget* activeWidget = focusHdl->getFocused(); - if(activeWidget == lstFolders) - cmdCancel->requestFocus(); - else if(activeWidget == cmdCancel) - cmdOK->requestFocus(); - else if(activeWidget == cmdOK) - lstFolders->requestFocus(); - } +{ + gcn::FocusHandler* focusHdl = gui_top->_getFocusHandler(); + gcn::Widget* activeWidget = focusHdl->getFocused(); + if (activeWidget == lstFolders) + cmdCancel->requestFocus(); + else if (activeWidget == cmdCancel) + cmdOK->requestFocus(); + else if (activeWidget == cmdOK) + lstFolders->requestFocus(); +} + static void SelectFolderLoop() { - //FocusBugWorkaround(wndSelectFolder); + FocusBugWorkaround(wndSelectFolder); while (!dialogFinished) { @@ -268,62 +272,73 @@ static void SelectFolderLoop() gui_input->pushInput(event); // Fire key down event.type = SDL_KEYUP; // and the key up break; - default: + default: break; } } -else if (event.type == SDL_JOYBUTTONDOWN || event.type == SDL_JOYHATMOTION) - { - int hat = SDL_JoystickGetHat(GUIjoy, 0); - - if (SDL_JoystickGetButton(GUIjoy,host_input_buttons[0].south_button)) - {PushFakeKey(SDLK_RETURN); - break;} - - else if (SDL_JoystickGetButton(GUIjoy,host_input_buttons[0].east_button) || - SDL_JoystickGetButton(GUIjoy,host_input_buttons[0].start_button)) - {dialogFinished = true; - break;} + else if (event.type == SDL_JOYBUTTONDOWN || event.type == SDL_JOYHATMOTION) + { + const int hat = SDL_JoystickGetHat(GUIjoy, 0); - else if (SDL_JoystickGetButton(GUIjoy,host_input_buttons[0].dpad_left) || (hat & SDL_HAT_LEFT)) - { gcn::FocusHandler* focusHdl = gui_top->_getFocusHandler(); - gcn::Widget* activeWidget = focusHdl->getFocused(); - if(activeWidget == lstFolders) - cmdCancel->requestFocus(); - else if(activeWidget == cmdCancel) - cmdOK->requestFocus(); - else if(activeWidget == cmdOK) - lstFolders->requestFocus(); - continue;} - - - else if (SDL_JoystickGetButton(GUIjoy,host_input_buttons[0].dpad_right) || (hat & SDL_HAT_RIGHT)) - { gcn::FocusHandler* focusHdl = gui_top->_getFocusHandler(); - gcn::Widget* activeWidget = focusHdl->getFocused(); - if(activeWidget == lstFolders) - cmdOK->requestFocus(); - else if(activeWidget == cmdCancel) - lstFolders->requestFocus(); - else if(activeWidget == cmdOK) - cmdCancel->requestFocus(); - continue;} - - else if (SDL_JoystickGetButton(GUIjoy,host_input_buttons[0].dpad_up) || (hat & SDL_HAT_UP)) - {PushFakeKey(SDLK_UP); - break;} - - else if (SDL_JoystickGetButton(GUIjoy,host_input_buttons[0].dpad_down) || (hat & SDL_HAT_DOWN)) - {PushFakeKey(SDLK_DOWN); - break;} - } + if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].south_button)) + { + PushFakeKey(SDLK_RETURN); + break; + } + + if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].east_button) || + SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].start_button)) + { + dialogFinished = true; + break; + } + + if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_left) || (hat & SDL_HAT_LEFT)) + { + gcn::FocusHandler* focusHdl = gui_top->_getFocusHandler(); + gcn::Widget* activeWidget = focusHdl->getFocused(); + if (activeWidget == lstFolders) + cmdCancel->requestFocus(); + else if (activeWidget == cmdCancel) + cmdOK->requestFocus(); + else if (activeWidget == cmdOK) + lstFolders->requestFocus(); + break; + } + + if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_right) || (hat & SDL_HAT_RIGHT)) + { + gcn::FocusHandler* focusHdl = gui_top->_getFocusHandler(); + gcn::Widget* activeWidget = focusHdl->getFocused(); + if (activeWidget == lstFolders) + cmdOK->requestFocus(); + else if (activeWidget == cmdCancel) + lstFolders->requestFocus(); + else if (activeWidget == cmdOK) + cmdCancel->requestFocus(); + break; + } + + if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_up) || (hat & SDL_HAT_UP)) + { + PushFakeKey(SDLK_UP); + break; + } + + if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_down) || (hat & SDL_HAT_DOWN)) + { + PushFakeKey(SDLK_DOWN); + break; + } + } //------------------------------------------------- // Send event to guisan-controls //------------------------------------------------- #ifdef ANDROIDSDL - androidsdl_event(event, gui_input); + androidsdl_event(event, gui_input); #else - gui_input->pushInput(event); + gui_input->pushInput(event); #endif } diff --git a/src/osdep/gui/SelectorEntry.cpp b/src/osdep/gui/SelectorEntry.cpp index db1bcdcf..1f4db9cd 100644 --- a/src/osdep/gui/SelectorEntry.cpp +++ b/src/osdep/gui/SelectorEntry.cpp @@ -13,14 +13,14 @@ namespace gcn active = false; - container = new gcn::Container(); + container = new Container(); container->setOpaque(true); - label = new gcn::Label(caption); + label = new Label(caption); label->setHeight(16); - gcn::Image* img = gcn::Image::load(imagepath); - icon = new gcn::Icon(img); + Image* img = Image::load(imagepath); + icon = new Icon(img); icon->setSize(16, 16); container->add(icon, 4, 4); @@ -65,7 +65,7 @@ namespace gcn } - void SelectorEntry::setActive(bool active) + void SelectorEntry::setActive(const bool active) { this->active = active; if (active) @@ -75,7 +75,7 @@ namespace gcn } - bool SelectorEntry::getActive() + bool SelectorEntry::getActive() const { return active; } diff --git a/src/osdep/gui/SelectorEntry.hpp b/src/osdep/gui/SelectorEntry.hpp index 07e77e48..3f19e4f7 100644 --- a/src/osdep/gui/SelectorEntry.hpp +++ b/src/osdep/gui/SelectorEntry.hpp @@ -29,7 +29,7 @@ namespace gcn void setInactiveColor(const Color& color); void setActiveColor(const Color& color); void setActive(bool active); - bool getActive(); + bool getActive() const; void widgetResized(const Event& event) override; diff --git a/src/osdep/gui/ShowHelp.cpp b/src/osdep/gui/ShowHelp.cpp index 70ff9995..a1ece462 100644 --- a/src/osdep/gui/ShowHelp.cpp +++ b/src/osdep/gui/ShowHelp.cpp @@ -20,7 +20,7 @@ #include "androidsdl_event.h" #endif -static SDL_Joystick *GUIjoy; +static SDL_Joystick* GUIjoy; extern struct host_input_button host_input_buttons[MAX_INPUT_DEVICES]; @@ -29,7 +29,7 @@ extern struct host_input_button host_input_buttons[MAX_INPUT_DEVICES]; static bool dialogFinished = false; -static gcn::Window *wndShowHelp; +static gcn::Window* wndShowHelp; static gcn::Button* cmdOK; static gcn::ListBox* lstHelp; static gcn::ScrollArea* scrAreaHelp; @@ -37,10 +37,10 @@ static gcn::ScrollArea* scrAreaHelp; class HelpListModel : public gcn::ListModel { - std::vector lines; + vector lines; public: - HelpListModel(std::vector helptext) + HelpListModel(const vector helptext) { lines = helptext; } @@ -50,14 +50,15 @@ public: return lines.size(); } - std::string getElementAt(int i) override + string getElementAt(int i) override { if (i >= 0 && i < lines.size()) return lines[i]; return ""; } }; -static HelpListModel *helpList; + +static HelpListModel* helpList; class ShowHelpActionListener : public gcn::ActionListener @@ -68,10 +69,11 @@ public: dialogFinished = true; } }; + static ShowHelpActionListener* showHelpActionListener; -static void InitShowHelp(const std::vector& helptext) +static void InitShowHelp(const vector& helptext) { wndShowHelp = new gcn::Window("Help"); wndShowHelp->setSize(DIALOG_WIDTH, DIALOG_HEIGHT); @@ -84,7 +86,8 @@ static void InitShowHelp(const std::vector& helptext) helpList = new HelpListModel(helptext); lstHelp = new gcn::ListBox(helpList); - lstHelp->setSize(DIALOG_WIDTH - 2 * DISTANCE_BORDER - 4, DIALOG_HEIGHT - 3 * DISTANCE_BORDER - BUTTON_HEIGHT - DISTANCE_NEXT_Y - 10); + lstHelp->setSize(DIALOG_WIDTH - 2 * DISTANCE_BORDER - 4, + DIALOG_HEIGHT - 3 * DISTANCE_BORDER - BUTTON_HEIGHT - DISTANCE_NEXT_Y - 10); lstHelp->setPosition(DISTANCE_BORDER, DISTANCE_BORDER); lstHelp->setBaseColor(gui_baseCol + 0x202020); lstHelp->setBackgroundColor(gui_baseCol); @@ -93,14 +96,16 @@ static void InitShowHelp(const std::vector& helptext) scrAreaHelp = new gcn::ScrollArea(lstHelp); scrAreaHelp->setBorderSize(1); scrAreaHelp->setPosition(DISTANCE_BORDER, 10 + TEXTFIELD_HEIGHT + 10); - scrAreaHelp->setSize(DIALOG_WIDTH - 2 * DISTANCE_BORDER - 4, DIALOG_HEIGHT - 3 * DISTANCE_BORDER - BUTTON_HEIGHT - DISTANCE_NEXT_Y - 10); + scrAreaHelp->setSize(DIALOG_WIDTH - 2 * DISTANCE_BORDER - 4, + DIALOG_HEIGHT - 3 * DISTANCE_BORDER - BUTTON_HEIGHT - DISTANCE_NEXT_Y - 10); scrAreaHelp->setScrollbarWidth(20); scrAreaHelp->setBaseColor(gui_baseCol + 0x202020); scrAreaHelp->setBackgroundColor(gui_baseCol); cmdOK = new gcn::Button("Ok"); cmdOK->setSize(BUTTON_WIDTH, BUTTON_HEIGHT); - cmdOK->setPosition(DIALOG_WIDTH - DISTANCE_BORDER - BUTTON_WIDTH, DIALOG_HEIGHT - 2 * DISTANCE_BORDER - BUTTON_HEIGHT - 10); + cmdOK->setPosition(DIALOG_WIDTH - DISTANCE_BORDER - BUTTON_WIDTH, + DIALOG_HEIGHT - 2 * DISTANCE_BORDER - BUTTON_HEIGHT - 10); cmdOK->setBaseColor(gui_baseCol); cmdOK->addActionListener(showHelpActionListener); @@ -132,8 +137,8 @@ static void ExitShowHelp(void) static void ShowHelpLoop(void) { -//TODO: Check if this is needed in guisan? - //FocusBugWorkaround(wndShowHelp); + FocusBugWorkaround(wndShowHelp); + GUIjoy = SDL_JoystickOpen(0); while (!dialogFinished) @@ -154,31 +159,34 @@ static void ShowHelpLoop(void) case SDL_SCANCODE_RETURN: event.key.keysym.scancode = SDL_SCANCODE_RETURN; gui_input->pushInput(event); // Fire key down - event.type = SDL_KEYUP; // and the key up + event.type = SDL_KEYUP; // and the key up break; default: break; } } -else if (event.type == SDL_JOYBUTTONDOWN) - { - if (SDL_JoystickGetButton(GUIjoy,host_input_buttons[0].south_button)) - {PushFakeKey(SDLK_RETURN); - break;} - - else if (SDL_JoystickGetButton(GUIjoy,host_input_buttons[0].east_button) || - SDL_JoystickGetButton(GUIjoy,host_input_buttons[0].start_button)) - {dialogFinished = true; - break;} - } + else if (event.type == SDL_JOYBUTTONDOWN) + { + if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].south_button)) + { + PushFakeKey(SDLK_RETURN); + break; + } + if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].east_button) || + SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].start_button)) + { + dialogFinished = true; + break; + } + } //------------------------------------------------- // Send event to guisan-controls //------------------------------------------------- #ifdef ANDROIDSDL - androidsdl_event(event, gui_input); + androidsdl_event(event, gui_input); #else - gui_input->pushInput(event); + gui_input->pushInput(event); #endif } @@ -193,7 +201,7 @@ else if (event.type == SDL_JOYBUTTONDOWN) } -void ShowHelp(const char *title, const std::vector& text) +void ShowHelp(const char* title, const vector& text) { dialogFinished = false; diff --git a/src/osdep/gui/ShowMessage.cpp b/src/osdep/gui/ShowMessage.cpp index 70dd9e43..dc962bc5 100644 --- a/src/osdep/gui/ShowMessage.cpp +++ b/src/osdep/gui/ShowMessage.cpp @@ -25,7 +25,7 @@ static bool dialogResult = false; static bool dialogFinished = false; -static SDL_Joystick *GUIjoy; +static SDL_Joystick* GUIjoy; extern struct host_input_button host_input_buttons[MAX_INPUT_DEVICES]; static const char* dialogControlPressed; static Uint8 dialogButtonPressed; @@ -71,13 +71,15 @@ static void InitShowMessage() cmdOK = new gcn::Button("Ok"); cmdOK->setSize(BUTTON_WIDTH, BUTTON_HEIGHT); - cmdOK->setPosition(DIALOG_WIDTH - DISTANCE_BORDER - 2 * BUTTON_WIDTH - DISTANCE_NEXT_X, DIALOG_HEIGHT - 2 * DISTANCE_BORDER - BUTTON_HEIGHT - 10); + cmdOK->setPosition(DIALOG_WIDTH - DISTANCE_BORDER - 2 * BUTTON_WIDTH - DISTANCE_NEXT_X, + DIALOG_HEIGHT - 2 * DISTANCE_BORDER - BUTTON_HEIGHT - 10); cmdOK->setBaseColor(gui_baseCol); cmdOK->addActionListener(showMessageActionListener); cmdCancel = new gcn::Button("Cancel"); cmdCancel->setSize(BUTTON_WIDTH, BUTTON_HEIGHT); - cmdCancel->setPosition(DIALOG_WIDTH - DISTANCE_BORDER - BUTTON_WIDTH, DIALOG_HEIGHT - 2 * DISTANCE_BORDER - BUTTON_HEIGHT - 10); + cmdCancel->setPosition(DIALOG_WIDTH - DISTANCE_BORDER - BUTTON_WIDTH, + DIALOG_HEIGHT - 2 * DISTANCE_BORDER - BUTTON_HEIGHT - 10); cmdCancel->setBaseColor(gui_baseCol); cmdCancel->addActionListener(showMessageActionListener); @@ -110,7 +112,7 @@ static void ExitShowMessage() static void ShowMessageWaitInputLoop() { - //FocusBugWorkaround(wndShowMessage); + FocusBugWorkaround(wndShowMessage); while (!dialogFinished) { @@ -157,8 +159,8 @@ static void ShowMessageWaitInputLoop() static void ShowMessageLoop() { -//TODO: Check if this is needed in guisan - //FocusBugWorkaround(wndShowMessage); + FocusBugWorkaround(wndShowMessage); + GUIjoy = SDL_JoystickOpen(0); while (!dialogFinished) @@ -183,7 +185,6 @@ static void ShowMessageLoop() cmdOK->requestFocus(); else if (activeWidget == cmdOK) cmdCancel->requestFocus(); - continue; } break; @@ -198,40 +199,44 @@ static void ShowMessageLoop() break; } } - else if (event.type == SDL_JOYBUTTONDOWN || event.type == SDL_JOYHATMOTION) - { - int hat = SDL_JoystickGetHat(GUIjoy, 0); - - if (SDL_JoystickGetButton(GUIjoy,host_input_buttons[0].south_button)) - {PushFakeKey(SDLK_RETURN); - break;} - - else if (SDL_JoystickGetButton(GUIjoy,host_input_buttons[0].east_button) || - SDL_JoystickGetButton(GUIjoy,host_input_buttons[0].start_button)) - {dialogFinished = true; - break;} - - else if (SDL_JoystickGetButton(GUIjoy,host_input_buttons[0].dpad_left) || - SDL_JoystickGetButton(GUIjoy,host_input_buttons[0].dpad_right) || - (hat & SDL_HAT_LEFT) || - (hat & SDL_HAT_RIGHT) ) - - {gcn::FocusHandler* focusHdl = gui_top->_getFocusHandler(); - gcn::Widget* activeWidget = focusHdl->getFocused(); - if(activeWidget == cmdCancel) - cmdOK->requestFocus(); - else if(activeWidget == cmdOK) - cmdCancel->requestFocus(); - continue;} - } + else if (event.type == SDL_JOYBUTTONDOWN || event.type == SDL_JOYHATMOTION) + { + const int hat = SDL_JoystickGetHat(GUIjoy, 0); + + if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].south_button)) + { + PushFakeKey(SDLK_RETURN); + break; + } + if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].east_button) || + SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].start_button)) + { + dialogFinished = true; + break; + } + if (SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_left) || + SDL_JoystickGetButton(GUIjoy, host_input_buttons[0].dpad_right) || + (hat & SDL_HAT_LEFT) || + (hat & SDL_HAT_RIGHT)) + + { + gcn::FocusHandler* focusHdl = gui_top->_getFocusHandler(); + gcn::Widget* activeWidget = focusHdl->getFocused(); + if (activeWidget == cmdCancel) + cmdOK->requestFocus(); + else if (activeWidget == cmdOK) + cmdCancel->requestFocus(); + break; + } + } //------------------------------------------------- // Send event to guisan-controls //------------------------------------------------- #ifdef ANDROIDSDL - androidsdl_event(event, gui_input); + androidsdl_event(event, gui_input); #else - gui_input->pushInput(event); + gui_input->pushInput(event); #endif } diff --git a/src/osdep/gui/main_window.cpp b/src/osdep/gui/main_window.cpp index 7cbd904b..cd3e93b2 100644 --- a/src/osdep/gui/main_window.cpp +++ b/src/osdep/gui/main_window.cpp @@ -183,20 +183,20 @@ void RegisterRefreshFunc(void (*func)(void)) refreshFuncAfterDraw = func; } -//void FocusBugWorkaround(gcn::Window* wnd) -//{ -// // When modal dialog opens via mouse, the dialog will not -// // have the focus unless there is a mouse click. We simulate the click... -// SDL_Event event; -// event.type = SDL_MOUSEBUTTONDOWN; -// event.button.button = SDL_BUTTON_LEFT; -// event.button.state = SDL_PRESSED; -// event.button.x = wnd->getX() + 2; -// event.button.y = wnd->getY() + 2; -// gui_input->pushInput(event); -// event.type = SDL_MOUSEBUTTONUP; -// gui_input->pushInput(event); -//} +void FocusBugWorkaround(gcn::Window* wnd) +{ + // When modal dialog opens via mouse, the dialog will not + // have the focus unless there is a mouse click. We simulate the click... + SDL_Event event; + event.type = SDL_MOUSEBUTTONDOWN; + event.button.button = SDL_BUTTON_LEFT; + event.button.state = SDL_PRESSED; + event.button.x = wnd->getX() + 2; + event.button.y = wnd->getY() + 2; + gui_input->pushInput(event); + event.type = SDL_MOUSEBUTTONUP; + gui_input->pushInput(event); +} static void ShowHelpRequested() { @@ -849,8 +849,8 @@ void DisableResume() void run_gui() { #ifdef ANDROIDSDL - SDL_ANDROID_SetScreenKeyboardShown(0); - SDL_ANDROID_SetSystemMousePointerVisible(1); + SDL_ANDROID_SetScreenKeyboardShown(0); + SDL_ANDROID_SetSystemMousePointerVisible(1); #endif gui_running = true; gui_rtarea_flags_onenter = gui_create_rtarea_flag(&currprefs); @@ -870,13 +870,13 @@ void run_gui() sdl::gui_run(); widgets::gui_halt(); sdl::gui_halt(); - #ifdef ANDROIDSDL - if (currprefs.onScreen!=0) - { - SDL_ANDROID_SetScreenKeyboardShown(1); - SDL_ANDROID_SetSystemMousePointerVisible(0); - } - #endif +#ifdef ANDROIDSDL + if (currprefs.onScreen != 0) + { + SDL_ANDROID_SetScreenKeyboardShown(1); + SDL_ANDROID_SetSystemMousePointerVisible(0); + } +#endif } // Catch all guisan exceptions.