From bff503a001043a1a55e8ce089e26ddcda31fc740 Mon Sep 17 00:00:00 2001 From: Stephen Anthony Date: Sat, 11 May 2019 22:16:23 -0230 Subject: [PATCH] Refactor DialogContainer and child classes. - instead of using a protected instance variable, each derived class now has its own private variable - each derived class also takes responsibility for deleting its private variable - various API cleanups --- src/debugger/Debugger.cxx | 6 +++--- src/debugger/Debugger.hxx | 5 +++++ src/debugger/DebuggerParser.cxx | 4 ++-- src/debugger/gui/DebuggerDialog.hxx | 7 +++---- src/emucore/FrameBuffer.cxx | 7 +++++-- src/gui/CommandMenu.cxx | 15 ++++++++++++++- src/gui/CommandMenu.hxx | 10 +++++++++- src/gui/DialogContainer.cxx | 15 +++++++-------- src/gui/DialogContainer.hxx | 24 ++++++++++++------------ src/gui/Launcher.cxx | 15 ++++++++++++++- src/gui/Launcher.hxx | 9 ++++++++- src/gui/Menu.cxx | 14 +++++++++++--- src/gui/Menu.hxx | 6 +++--- src/gui/TimeMachine.cxx | 13 +++++++++++++ src/gui/TimeMachine.hxx | 9 ++++++++- 15 files changed, 117 insertions(+), 42 deletions(-) diff --git a/src/debugger/Debugger.cxx b/src/debugger/Debugger.cxx index bb7fe799e..f3803321a 100644 --- a/src/debugger/Debugger.cxx +++ b/src/debugger/Debugger.cxx @@ -86,6 +86,7 @@ Debugger::Debugger(OSystem& osystem, Console& console) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Debugger::~Debugger() { + delete myDialog; myDialog = nullptr; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -104,9 +105,8 @@ void Debugger::initialize() myOSystem.settings().setValue("dbg.res", Common::Size(myWidth, myHeight)); - delete myBaseDialog; myBaseDialog = myDialog = nullptr; + delete myDialog; myDialog = nullptr; myDialog = new DebuggerDialog(myOSystem, *this, 0, 0, myWidth, myHeight); - myBaseDialog = myDialog; myCartDebug->setDebugWidget(&(myDialog->cartDebug())); @@ -796,7 +796,7 @@ void Debugger::unlockSystem() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool Debugger::canExit() const { - return !myDialogStack.empty() && myDialogStack.top() == baseDialog(); + return baseDialogIsActive(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/debugger/Debugger.hxx b/src/debugger/Debugger.hxx index d76fd0ac8..8a403006d 100644 --- a/src/debugger/Debugger.hxx +++ b/src/debugger/Debugger.hxx @@ -245,6 +245,11 @@ class Debugger : public DialogContainer */ bool canExit() const; + /** + Return (and possibly create) the bottom-most dialog of this container. + */ + Dialog* baseDialog() override { return myDialog; } + private: /** Save state of each debugger subsystem and, by default, mark all diff --git a/src/debugger/DebuggerParser.cxx b/src/debugger/DebuggerParser.cxx index 766db3a29..77a0420e1 100644 --- a/src/debugger/DebuggerParser.cxx +++ b/src/debugger/DebuggerParser.cxx @@ -121,7 +121,7 @@ string DebuggerParser::run(const string& command) } if(commands[i].refreshRequired) - debugger.myBaseDialog->loadConfig(); + debugger.baseDialog()->loadConfig(); return commandResult.str(); } @@ -1690,7 +1690,7 @@ void DebuggerParser::executeRunTo() // disassembly, since this may be a time-consuming operation ostringstream buf; buf << "RunTo searching through " << max_iterations << " disassembled instructions"; - ProgressDialog progress(debugger.myBaseDialog, debugger.lfont(), buf.str()); + ProgressDialog progress(debugger.baseDialog(), debugger.lfont(), buf.str()); progress.setRange(0, max_iterations, 5); bool done = false; diff --git a/src/debugger/gui/DebuggerDialog.hxx b/src/debugger/gui/DebuggerDialog.hxx index d9daa9801..5826172f6 100644 --- a/src/debugger/gui/DebuggerDialog.hxx +++ b/src/debugger/gui/DebuggerDialog.hxx @@ -34,14 +34,13 @@ class TiaZoomWidget; class CartDebugWidget; class CartRamWidget; -class OptionsDialog; - -namespace GUI { - class MessageBox; +namespace Common { struct Rect; } #include "Dialog.hxx" +#include "MessageBox.hxx" +#include "OptionsDialog.hxx" class DebuggerDialog : public Dialog { diff --git a/src/emucore/FrameBuffer.cxx b/src/emucore/FrameBuffer.cxx index 1cb4142ed..9aa6ea12a 100644 --- a/src/emucore/FrameBuffer.cxx +++ b/src/emucore/FrameBuffer.cxx @@ -709,10 +709,13 @@ void FrameBuffer::setFullscreen(bool enable) switch(myOSystem.eventHandler().state()) { case EventHandlerState::EMULATION: - case EventHandlerState::LAUNCHER: - case EventHandlerState::DEBUGGER: case EventHandlerState::PAUSE: break; // continue with processing (aka, allow a mode switch) + case EventHandlerState::DEBUGGER: + case EventHandlerState::LAUNCHER: + if(myOSystem.eventHandler().overlay().baseDialogIsActive()) + break; // allow a mode switch when there is only one dialog + [[fallthrough]]; default: return; } diff --git a/src/gui/CommandMenu.cxx b/src/gui/CommandMenu.cxx index 131ab1924..664aefc18 100644 --- a/src/gui/CommandMenu.cxx +++ b/src/gui/CommandMenu.cxx @@ -22,10 +22,23 @@ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - CommandMenu::CommandMenu(OSystem& osystem) - : DialogContainer(osystem) + : DialogContainer(osystem), + myBaseDialog(nullptr) { if (osystem.settings().getBool("minimal_ui")) myBaseDialog = new MinUICommandDialog(myOSystem, *this); else myBaseDialog = new CommandDialog(myOSystem, *this); } + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +CommandMenu::~CommandMenu() +{ + delete myBaseDialog; myBaseDialog = nullptr; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Dialog* CommandMenu::baseDialog() +{ + return myBaseDialog; +} diff --git a/src/gui/CommandMenu.hxx b/src/gui/CommandMenu.hxx index 7dcb37dc7..f8d431942 100644 --- a/src/gui/CommandMenu.hxx +++ b/src/gui/CommandMenu.hxx @@ -35,7 +35,15 @@ class CommandMenu : public DialogContainer Create a new menu stack */ explicit CommandMenu(OSystem& osystem); - virtual ~CommandMenu() = default; + virtual ~CommandMenu(); + + /** + Return (and possibly create) the bottom-most dialog of this container. + */ + Dialog* baseDialog() override; + + private: + Dialog* myBaseDialog; private: // Following constructors and assignment operators not supported diff --git a/src/gui/DialogContainer.cxx b/src/gui/DialogContainer.cxx index 16bdf681b..f4497a076 100644 --- a/src/gui/DialogContainer.cxx +++ b/src/gui/DialogContainer.cxx @@ -28,7 +28,6 @@ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - DialogContainer::DialogContainer(OSystem& osystem) : myOSystem(osystem), - myBaseDialog(nullptr), myTime(0), myKeyRepeatTime(0), myClickRepeatTime(0), @@ -39,12 +38,6 @@ DialogContainer::DialogContainer(OSystem& osystem) reset(); } -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -DialogContainer::~DialogContainer() -{ - delete myBaseDialog; -} - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void DialogContainer::updateTime(uInt64 time) { @@ -125,6 +118,12 @@ bool DialogContainer::needsRedraw() const return !myDialogStack.empty() ? myDialogStack.top()->isDirty() : false; } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool DialogContainer::baseDialogIsActive() const +{ + return myDialogStack.size() == 1; +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - int DialogContainer::addDialog(Dialog* d) { @@ -158,7 +157,7 @@ void DialogContainer::reStack() while(!myDialogStack.empty()) myDialogStack.top()->close(); - getBaseDialog()->open(); + baseDialog()->open(); // Reset all continuous events reset(); diff --git a/src/gui/DialogContainer.hxx b/src/gui/DialogContainer.hxx index acb2aa8db..7a9176f51 100644 --- a/src/gui/DialogContainer.hxx +++ b/src/gui/DialogContainer.hxx @@ -47,7 +47,7 @@ class DialogContainer Create a new DialogContainer stack */ explicit DialogContainer(OSystem& osystem); - virtual ~DialogContainer(); + virtual ~DialogContainer() = default; public: /** @@ -131,21 +131,17 @@ class DialogContainer */ bool needsRedraw() const; + /** + Answers whether the base dialog is currently active + (ie, there are no overlaid dialogs other than the bottom one) + */ + bool baseDialogIsActive() const; + /** Reset dialog stack to the main configuration menu. */ void reStack(); - /** - Return the bottom-most dialog of this container. - */ - const Dialog* baseDialog() const { return myBaseDialog; } - - /** - Return the bottom-most dialog of this container. Can be overwritten. - */ - virtual Dialog* getBaseDialog() { return myBaseDialog; } - /** Inform the container that it should resize according to the current screen dimensions. We make this virtual, since the container may or @@ -154,6 +150,11 @@ class DialogContainer */ virtual void requestResize() { } + /** + Return (and possibly create) the bottom-most dialog of this container. + */ + virtual Dialog* baseDialog() = 0; + private: void reset(); @@ -169,7 +170,6 @@ class DialogContainer protected: OSystem& myOSystem; - Dialog* myBaseDialog; Common::FixedStack myDialogStack; private: diff --git a/src/gui/Launcher.cxx b/src/gui/Launcher.cxx index 35fb29211..c6478292c 100644 --- a/src/gui/Launcher.cxx +++ b/src/gui/Launcher.cxx @@ -27,7 +27,8 @@ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Launcher::Launcher(OSystem& osystem) - : DialogContainer(osystem) + : DialogContainer(osystem), + myBaseDialog(nullptr) { const Common::Size& s = myOSystem.settings().getSize("launcherres"); const Common::Size& d = myOSystem.frameBuffer().desktopSize(); @@ -45,6 +46,12 @@ Launcher::Launcher(OSystem& osystem) myBaseDialog = new LauncherDialog(myOSystem, *this, 0, 0, myWidth, myHeight); } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Launcher::~Launcher() +{ + delete myBaseDialog; myBaseDialog = nullptr; +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - FBInitStatus Launcher::initializeVideo() { @@ -75,3 +82,9 @@ void Launcher::reload() { (static_cast(myBaseDialog))->reload(); } + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Dialog* Launcher::baseDialog() +{ + return myBaseDialog; +} diff --git a/src/gui/Launcher.hxx b/src/gui/Launcher.hxx index 15cee2598..537ff61ef 100644 --- a/src/gui/Launcher.hxx +++ b/src/gui/Launcher.hxx @@ -37,7 +37,7 @@ class Launcher : public DialogContainer Create a new menu stack */ explicit Launcher(OSystem& osystem); - virtual ~Launcher() = default; + virtual ~Launcher(); /** Initialize the video subsystem wrt this class. @@ -64,7 +64,14 @@ class Launcher : public DialogContainer */ void reload(); + /** + Return (and possibly create) the bottom-most dialog of this container. + */ + Dialog* baseDialog() override; + private: + Dialog* myBaseDialog; + // The width and height of this dialog uInt32 myWidth; uInt32 myHeight; diff --git a/src/gui/Menu.cxx b/src/gui/Menu.cxx index 782549d3f..f50fd5200 100644 --- a/src/gui/Menu.cxx +++ b/src/gui/Menu.cxx @@ -28,9 +28,18 @@ Menu::Menu(OSystem& osystem) : DialogContainer(osystem), stellaSettingDialog(nullptr), optionsDialog(nullptr) -{} +{ +} -Dialog* Menu::getBaseDialog() +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Menu::~Menu() +{ + delete stellaSettingDialog; stellaSettingDialog = nullptr; + delete optionsDialog; optionsDialog = nullptr; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Dialog* Menu::baseDialog() { if (myOSystem.settings().getBool("basic_settings")) { @@ -47,4 +56,3 @@ Dialog* Menu::getBaseDialog() return optionsDialog; } } - diff --git a/src/gui/Menu.hxx b/src/gui/Menu.hxx index eaa1dc9c8..cc9da0daa 100644 --- a/src/gui/Menu.hxx +++ b/src/gui/Menu.hxx @@ -39,13 +39,13 @@ class Menu : public DialogContainer Create a new menu stack */ explicit Menu(OSystem& osystem); - virtual ~Menu() = default; + virtual ~Menu(); + private: + Dialog* baseDialog() override; StellaSettingsDialog* stellaSettingDialog; OptionsDialog* optionsDialog; - Dialog* getBaseDialog() override; - private: // Following constructors and assignment operators not supported Menu() = delete; diff --git a/src/gui/TimeMachine.cxx b/src/gui/TimeMachine.cxx index 0abe5d62c..629c49392 100644 --- a/src/gui/TimeMachine.cxx +++ b/src/gui/TimeMachine.cxx @@ -23,11 +23,18 @@ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - TimeMachine::TimeMachine(OSystem& osystem) : DialogContainer(osystem), + myBaseDialog(nullptr), myWidth(FBMinimum::Width) { myBaseDialog = new TimeMachineDialog(myOSystem, *this, myWidth); } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +TimeMachine::~TimeMachine() +{ + delete myBaseDialog; myBaseDialog = nullptr; +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void TimeMachine::requestResize() { @@ -56,6 +63,12 @@ void TimeMachine::requestResize() } } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Dialog* TimeMachine::baseDialog() +{ + return myBaseDialog; +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void TimeMachine::setEnterWinds(Int32 numWinds) { diff --git a/src/gui/TimeMachine.hxx b/src/gui/TimeMachine.hxx index d3035d6f8..22a339d91 100644 --- a/src/gui/TimeMachine.hxx +++ b/src/gui/TimeMachine.hxx @@ -31,7 +31,7 @@ class TimeMachine : public DialogContainer { public: explicit TimeMachine(OSystem& osystem); - virtual ~TimeMachine() = default; + virtual ~TimeMachine(); /** This dialog has an adjustable size. We need to make sure the @@ -39,12 +39,19 @@ class TimeMachine : public DialogContainer */ void requestResize() override; + /** + Return (and possibly create) the bottom-most dialog of this container. + */ + Dialog* baseDialog() override; + /** Set number of winds when entering the dialog. */ void setEnterWinds(Int32 numWinds); private: + Dialog* myBaseDialog; + uInt32 myWidth; private: