From 39d3eefcef2d647bd4e629f6d4bb05179ee870d8 Mon Sep 17 00:00:00 2001 From: thrust26 Date: Sat, 4 May 2019 12:55:39 +0200 Subject: [PATCH] make 'Cancel' work in command dialogs --- src/gui/CommandDialog.cxx | 10 ++++ src/gui/CommandDialog.hxx | 1 + src/gui/Dialog.cxx | 2 +- src/gui/Dialog.hxx | 1 + src/gui/MinUICommandDialog.cxx | 10 ++++ src/gui/MinUICommandDialog.hxx | 101 +++++++++++++++++---------------- 6 files changed, 74 insertions(+), 51 deletions(-) diff --git a/src/gui/CommandDialog.cxx b/src/gui/CommandDialog.cxx index 224d76714..d213fb2d3 100644 --- a/src/gui/CommandDialog.cxx +++ b/src/gui/CommandDialog.cxx @@ -101,6 +101,10 @@ CommandDialog::CommandDialog(OSystem& osystem, DialogContainer& parent) wid.push_back(bw); addToFocusList(wid); + + // We don't have a close/cancel button, but we still want the cancel + // event to be processed + processCancelWithoutWidget(true); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -233,6 +237,12 @@ void CommandDialog::handleCommand(CommandSender* sender, int cmd, instance().eventHandler().handleEvent(event); } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void CommandDialog::processCancel() +{ + instance().eventHandler().leaveMenuMode(); +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void CommandDialog::updateSlot(int slot) { diff --git a/src/gui/CommandDialog.hxx b/src/gui/CommandDialog.hxx index d3c1925c2..fc084fe2e 100644 --- a/src/gui/CommandDialog.hxx +++ b/src/gui/CommandDialog.hxx @@ -37,6 +37,7 @@ class CommandDialog : public Dialog void updateSlot(int slot); void updateTVFormat(); void updatePalette(); + void processCancel() override; // column 0 ButtonWidget* myColorButton; diff --git a/src/gui/Dialog.cxx b/src/gui/Dialog.cxx index 773c70bec..1b43e9f89 100644 --- a/src/gui/Dialog.cxx +++ b/src/gui/Dialog.cxx @@ -722,7 +722,7 @@ bool Dialog::handleNavEvent(Event::Type e) { // Some dialogs want the ability to cancel without actually having // a corresponding cancel button - close(); + processCancel(); return true; } break; diff --git a/src/gui/Dialog.hxx b/src/gui/Dialog.hxx index c52fd207a..e14124e0e 100644 --- a/src/gui/Dialog.hxx +++ b/src/gui/Dialog.hxx @@ -159,6 +159,7 @@ class Dialog : public GuiObject bool focusOKButton = true); void processCancelWithoutWidget(bool state) { _processCancel = state; } + virtual void processCancel() { close(); } /** Define the size (allowed) for the dialog. */ void setSize(uInt32 w, uInt32 h, uInt32 max_w, uInt32 max_h); diff --git a/src/gui/MinUICommandDialog.cxx b/src/gui/MinUICommandDialog.cxx index 1c3a397ba..704e7190b 100644 --- a/src/gui/MinUICommandDialog.cxx +++ b/src/gui/MinUICommandDialog.cxx @@ -104,6 +104,10 @@ MinUICommandDialog::MinUICommandDialog(OSystem& osystem, DialogContainer& parent wid.push_back(bw); addToFocusList(wid); + + // We don't have a close/cancel button, but we still want the cancel + // event to be processed + processCancelWithoutWidget(true); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -248,6 +252,12 @@ void MinUICommandDialog::handleCommand(CommandSender* sender, int cmd, instance().eventHandler().handleEvent(event); } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void MinUICommandDialog::processCancel() +{ + instance().eventHandler().leaveMenuMode(); +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void MinUICommandDialog::updateSlot(int slot) { diff --git a/src/gui/MinUICommandDialog.hxx b/src/gui/MinUICommandDialog.hxx index e569a9835..a73aa848c 100644 --- a/src/gui/MinUICommandDialog.hxx +++ b/src/gui/MinUICommandDialog.hxx @@ -30,63 +30,64 @@ class OptionsDialog; class MinUICommandDialog : public Dialog { public: - MinUICommandDialog(OSystem& osystem, DialogContainer& parent); - virtual ~MinUICommandDialog() = default; + MinUICommandDialog(OSystem& osystem, DialogContainer& parent); + virtual ~MinUICommandDialog() = default; protected: - void loadConfig() override; - void handleKeyDown(StellaKey key, StellaMod mod) override; - void handleCommand(CommandSender* sender, int cmd, int data, int id) override; - void updateSlot(int slot); - void updateWinds(); - void updateTVFormat(); - void openSettings(); + void loadConfig() override; + void handleKeyDown(StellaKey key, StellaMod mod) override; + void handleCommand(CommandSender* sender, int cmd, int data, int id) override; + void updateSlot(int slot); + void updateWinds(); + void updateTVFormat(); + void openSettings(); + void processCancel() override; - // column 0 - ButtonWidget* myColorButton; - ButtonWidget* myLeftDiffButton; - ButtonWidget* myRightDiffButton; - // column 1 - ButtonWidget* mySaveStateButton; - ButtonWidget* myStateSlotButton; - ButtonWidget* myLoadStateButton; - ButtonWidget* myRewindButton; - ButtonWidget* myUnwindButton; - // column 2 - ButtonWidget* myTVFormatButton; - ButtonWidget* myStretchButton; - ButtonWidget* myPhosphorButton; + // column 0 + ButtonWidget* myColorButton; + ButtonWidget* myLeftDiffButton; + ButtonWidget* myRightDiffButton; + // column 1 + ButtonWidget* mySaveStateButton; + ButtonWidget* myStateSlotButton; + ButtonWidget* myLoadStateButton; + ButtonWidget* myRewindButton; + ButtonWidget* myUnwindButton; + // column 2 + ButtonWidget* myTVFormatButton; + ButtonWidget* myStretchButton; + ButtonWidget* myPhosphorButton; - unique_ptr myStellaSettingsDialog; - unique_ptr myOptionsDialog; + unique_ptr myStellaSettingsDialog; + unique_ptr myOptionsDialog; - enum - { - kSelectCmd = 'Csel', - kResetCmd = 'Cres', - kColorCmd = 'Ccol', - kLeftDiffCmd = 'Cldf', - kRightDiffCmd = 'Crdf', - kSaveStateCmd = 'Csst', - kStateSlotCmd = 'Ccst', - kLoadStateCmd = 'Clst', - kSnapshotCmd = 'Csnp', - kRewindCmd = 'Crew', - kUnwindCmd = 'Cunw', - kFormatCmd = 'Cfmt', - kStretchCmd = 'Cstr', - kPhosphorCmd = 'Cpho', - kSettings = 'Cscn', - kExitGameCmd = 'Cext', - }; + enum + { + kSelectCmd = 'Csel', + kResetCmd = 'Cres', + kColorCmd = 'Ccol', + kLeftDiffCmd = 'Cldf', + kRightDiffCmd = 'Crdf', + kSaveStateCmd = 'Csst', + kStateSlotCmd = 'Ccst', + kLoadStateCmd = 'Clst', + kSnapshotCmd = 'Csnp', + kRewindCmd = 'Crew', + kUnwindCmd = 'Cunw', + kFormatCmd = 'Cfmt', + kStretchCmd = 'Cstr', + kPhosphorCmd = 'Cpho', + kSettings = 'Cscn', + kExitGameCmd = 'Cext', + }; private: - // Following constructors and assignment operators not supported - MinUICommandDialog() = delete; - MinUICommandDialog(const MinUICommandDialog&) = delete; - MinUICommandDialog(MinUICommandDialog&&) = delete; - MinUICommandDialog& operator=(const MinUICommandDialog&) = delete; - MinUICommandDialog& operator=(MinUICommandDialog&&) = delete; + // Following constructors and assignment operators not supported + MinUICommandDialog() = delete; + MinUICommandDialog(const MinUICommandDialog&) = delete; + MinUICommandDialog(MinUICommandDialog&&) = delete; + MinUICommandDialog& operator=(const MinUICommandDialog&) = delete; + MinUICommandDialog& operator=(MinUICommandDialog&&) = delete; }; #endif