From 04f410d5ca5928a8b83e3bdfb2a0d92f251a6245 Mon Sep 17 00:00:00 2001 From: Dimitris Panokostas Date: Sun, 16 Apr 2017 23:13:55 +0200 Subject: [PATCH] Added ShowMessage version for custom key mapping --- src/osdep/gui/ShowMessage.cpp | 57 +++++++++++++++++++++++++++++++++++ src/osdep/gui/gui_handling.h | 1 + 2 files changed, 58 insertions(+) diff --git a/src/osdep/gui/ShowMessage.cpp b/src/osdep/gui/ShowMessage.cpp index 5e96c808..247d5b58 100644 --- a/src/osdep/gui/ShowMessage.cpp +++ b/src/osdep/gui/ShowMessage.cpp @@ -18,6 +18,7 @@ static bool dialogResult = false; static bool dialogFinished = false; +static SDL_Keycode dialogButtonPressed; static gcn::Window* wndShowMessage; static gcn::Button* cmdOK; @@ -94,6 +95,44 @@ static void ExitShowMessage() delete wndShowMessage; } +static void ShowMessageWaitButtonLoop() +{ + while (!dialogFinished) + { + //const Uint8 *keys = SDL_GetKeyboardState(nullptr); + SDL_Event event; + while (SDL_PollEvent(&event)) + { + if (event.type == SDL_KEYDOWN) + { + switch (event.key.keysym.scancode) + { + case VK_ESCAPE: + dialogFinished = true; + break; + + default: + dialogButtonPressed = event.key.keysym.sym; + dialogFinished = true; + break; + } + } + + //------------------------------------------------- + // Send event to guisan-controls + //------------------------------------------------- + gui_input->pushInput(event); + } + + // Now we let the Gui object perform its logic. + uae_gui->logic(); + // Now we let the Gui object draw itself. + uae_gui->draw(); + // Finally we update the screen. + + UpdateGuiScreen(); + } +} static void ShowMessageLoop() { @@ -124,6 +163,7 @@ static void ShowMessageLoop() case VK_Red: case VK_Green: + 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 @@ -172,3 +212,20 @@ bool ShowMessage(const char* title, const char* line1, const char* line2, const return dialogResult; } + +SDL_Keycode ShowMessage(const char* title, const char* line1, const char* button1) +{ + dialogResult = false; + dialogFinished = false; + + InitShowMessage(); + wndShowMessage->setCaption(title); + lblText1->setCaption(line1); + cmdOK->setVisible(false); + cmdCancel->setCaption(button1); + + ShowMessageWaitButtonLoop(); + ExitShowMessage(); + + return dialogButtonPressed; +} diff --git a/src/osdep/gui/gui_handling.h b/src/osdep/gui/gui_handling.h index a16913d1..c45ed872 100644 --- a/src/osdep/gui/gui_handling.h +++ b/src/osdep/gui/gui_handling.h @@ -103,6 +103,7 @@ void RegisterRefreshFunc(void (*func)(void)); void DisableResume(void); bool ShowMessage(const char* title, const char* line1, const char* line2, const char* button1, const char* button2); +SDL_Keycode ShowMessage(const char* title, const char* line1, const char* button1); bool SelectFolder(const char* title, char* value); bool SelectFile(const char* title, char* value, const char* filter[], bool create = false); bool EditFilesysVirtual(int unit_no);