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
This commit is contained in:
Stephen Anthony 2019-05-11 22:16:23 -02:30
parent 7072afdf1f
commit 6f8a5dda28
15 changed files with 117 additions and 42 deletions

View File

@ -86,6 +86,7 @@ Debugger::Debugger(OSystem& osystem, Console& console)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Debugger::~Debugger() Debugger::~Debugger()
{ {
delete myDialog; myDialog = nullptr;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -104,9 +105,8 @@ void Debugger::initialize()
myOSystem.settings().setValue("dbg.res", Common::Size(myWidth, myHeight)); 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); myDialog = new DebuggerDialog(myOSystem, *this, 0, 0, myWidth, myHeight);
myBaseDialog = myDialog;
myCartDebug->setDebugWidget(&(myDialog->cartDebug())); myCartDebug->setDebugWidget(&(myDialog->cartDebug()));
@ -796,7 +796,7 @@ void Debugger::unlockSystem()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool Debugger::canExit() const bool Debugger::canExit() const
{ {
return !myDialogStack.empty() && myDialogStack.top() == baseDialog(); return baseDialogIsActive();
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -245,6 +245,11 @@ class Debugger : public DialogContainer
*/ */
bool canExit() const; bool canExit() const;
/**
Return (and possibly create) the bottom-most dialog of this container.
*/
Dialog* baseDialog() override { return myDialog; }
private: private:
/** /**
Save state of each debugger subsystem and, by default, mark all Save state of each debugger subsystem and, by default, mark all

View File

@ -121,7 +121,7 @@ string DebuggerParser::run(const string& command)
} }
if(commands[i].refreshRequired) if(commands[i].refreshRequired)
debugger.myBaseDialog->loadConfig(); debugger.baseDialog()->loadConfig();
return commandResult.str(); return commandResult.str();
} }
@ -1690,7 +1690,7 @@ void DebuggerParser::executeRunTo()
// disassembly, since this may be a time-consuming operation // disassembly, since this may be a time-consuming operation
ostringstream buf; ostringstream buf;
buf << "RunTo searching through " << max_iterations << " disassembled instructions"; 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); progress.setRange(0, max_iterations, 5);
bool done = false; bool done = false;

View File

@ -34,14 +34,13 @@ class TiaZoomWidget;
class CartDebugWidget; class CartDebugWidget;
class CartRamWidget; class CartRamWidget;
class OptionsDialog; namespace Common {
namespace GUI {
class MessageBox;
struct Rect; struct Rect;
} }
#include "Dialog.hxx" #include "Dialog.hxx"
#include "MessageBox.hxx"
#include "OptionsDialog.hxx"
class DebuggerDialog : public Dialog class DebuggerDialog : public Dialog
{ {

View File

@ -709,10 +709,13 @@ void FrameBuffer::setFullscreen(bool enable)
switch(myOSystem.eventHandler().state()) switch(myOSystem.eventHandler().state())
{ {
case EventHandlerState::EMULATION: case EventHandlerState::EMULATION:
case EventHandlerState::LAUNCHER:
case EventHandlerState::DEBUGGER:
case EventHandlerState::PAUSE: case EventHandlerState::PAUSE:
break; // continue with processing (aka, allow a mode switch) 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: default:
return; return;
} }

View File

@ -22,10 +22,23 @@
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CommandMenu::CommandMenu(OSystem& osystem) CommandMenu::CommandMenu(OSystem& osystem)
: DialogContainer(osystem) : DialogContainer(osystem),
myBaseDialog(nullptr)
{ {
if (osystem.settings().getBool("minimal_ui")) if (osystem.settings().getBool("minimal_ui"))
myBaseDialog = new MinUICommandDialog(myOSystem, *this); myBaseDialog = new MinUICommandDialog(myOSystem, *this);
else else
myBaseDialog = new CommandDialog(myOSystem, *this); myBaseDialog = new CommandDialog(myOSystem, *this);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CommandMenu::~CommandMenu()
{
delete myBaseDialog; myBaseDialog = nullptr;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Dialog* CommandMenu::baseDialog()
{
return myBaseDialog;
}

View File

@ -35,7 +35,15 @@ class CommandMenu : public DialogContainer
Create a new menu stack Create a new menu stack
*/ */
explicit CommandMenu(OSystem& osystem); 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: private:
// Following constructors and assignment operators not supported // Following constructors and assignment operators not supported

View File

@ -28,7 +28,6 @@
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
DialogContainer::DialogContainer(OSystem& osystem) DialogContainer::DialogContainer(OSystem& osystem)
: myOSystem(osystem), : myOSystem(osystem),
myBaseDialog(nullptr),
myTime(0), myTime(0),
myKeyRepeatTime(0), myKeyRepeatTime(0),
myClickRepeatTime(0), myClickRepeatTime(0),
@ -39,12 +38,6 @@ DialogContainer::DialogContainer(OSystem& osystem)
reset(); reset();
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
DialogContainer::~DialogContainer()
{
delete myBaseDialog;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void DialogContainer::updateTime(uInt64 time) void DialogContainer::updateTime(uInt64 time)
{ {
@ -125,6 +118,12 @@ bool DialogContainer::needsRedraw() const
return !myDialogStack.empty() ? myDialogStack.top()->isDirty() : false; return !myDialogStack.empty() ? myDialogStack.top()->isDirty() : false;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool DialogContainer::baseDialogIsActive() const
{
return myDialogStack.size() == 1;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
int DialogContainer::addDialog(Dialog* d) int DialogContainer::addDialog(Dialog* d)
{ {
@ -158,7 +157,7 @@ void DialogContainer::reStack()
while(!myDialogStack.empty()) while(!myDialogStack.empty())
myDialogStack.top()->close(); myDialogStack.top()->close();
getBaseDialog()->open(); baseDialog()->open();
// Reset all continuous events // Reset all continuous events
reset(); reset();

View File

@ -47,7 +47,7 @@ class DialogContainer
Create a new DialogContainer stack Create a new DialogContainer stack
*/ */
explicit DialogContainer(OSystem& osystem); explicit DialogContainer(OSystem& osystem);
virtual ~DialogContainer(); virtual ~DialogContainer() = default;
public: public:
/** /**
@ -131,21 +131,17 @@ class DialogContainer
*/ */
bool needsRedraw() const; 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. Reset dialog stack to the main configuration menu.
*/ */
void reStack(); 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 Inform the container that it should resize according to the current
screen dimensions. We make this virtual, since the container may or screen dimensions. We make this virtual, since the container may or
@ -154,6 +150,11 @@ class DialogContainer
*/ */
virtual void requestResize() { } virtual void requestResize() { }
/**
Return (and possibly create) the bottom-most dialog of this container.
*/
virtual Dialog* baseDialog() = 0;
private: private:
void reset(); void reset();
@ -169,7 +170,6 @@ class DialogContainer
protected: protected:
OSystem& myOSystem; OSystem& myOSystem;
Dialog* myBaseDialog;
Common::FixedStack<Dialog*> myDialogStack; Common::FixedStack<Dialog*> myDialogStack;
private: private:

View File

@ -27,7 +27,8 @@
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Launcher::Launcher(OSystem& osystem) Launcher::Launcher(OSystem& osystem)
: DialogContainer(osystem) : DialogContainer(osystem),
myBaseDialog(nullptr)
{ {
const Common::Size& s = myOSystem.settings().getSize("launcherres"); const Common::Size& s = myOSystem.settings().getSize("launcherres");
const Common::Size& d = myOSystem.frameBuffer().desktopSize(); const Common::Size& d = myOSystem.frameBuffer().desktopSize();
@ -45,6 +46,12 @@ Launcher::Launcher(OSystem& osystem)
myBaseDialog = new LauncherDialog(myOSystem, *this, 0, 0, myWidth, myHeight); myBaseDialog = new LauncherDialog(myOSystem, *this, 0, 0, myWidth, myHeight);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Launcher::~Launcher()
{
delete myBaseDialog; myBaseDialog = nullptr;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
FBInitStatus Launcher::initializeVideo() FBInitStatus Launcher::initializeVideo()
{ {
@ -75,3 +82,9 @@ void Launcher::reload()
{ {
(static_cast<LauncherDialog*>(myBaseDialog))->reload(); (static_cast<LauncherDialog*>(myBaseDialog))->reload();
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Dialog* Launcher::baseDialog()
{
return myBaseDialog;
}

View File

@ -37,7 +37,7 @@ class Launcher : public DialogContainer
Create a new menu stack Create a new menu stack
*/ */
explicit Launcher(OSystem& osystem); explicit Launcher(OSystem& osystem);
virtual ~Launcher() = default; virtual ~Launcher();
/** /**
Initialize the video subsystem wrt this class. Initialize the video subsystem wrt this class.
@ -64,7 +64,14 @@ class Launcher : public DialogContainer
*/ */
void reload(); void reload();
/**
Return (and possibly create) the bottom-most dialog of this container.
*/
Dialog* baseDialog() override;
private: private:
Dialog* myBaseDialog;
// The width and height of this dialog // The width and height of this dialog
uInt32 myWidth; uInt32 myWidth;
uInt32 myHeight; uInt32 myHeight;

View File

@ -28,9 +28,18 @@ Menu::Menu(OSystem& osystem)
: DialogContainer(osystem), : DialogContainer(osystem),
stellaSettingDialog(nullptr), stellaSettingDialog(nullptr),
optionsDialog(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")) if (myOSystem.settings().getBool("basic_settings"))
{ {
@ -47,4 +56,3 @@ Dialog* Menu::getBaseDialog()
return optionsDialog; return optionsDialog;
} }
} }

View File

@ -39,13 +39,13 @@ class Menu : public DialogContainer
Create a new menu stack Create a new menu stack
*/ */
explicit Menu(OSystem& osystem); explicit Menu(OSystem& osystem);
virtual ~Menu() = default; virtual ~Menu();
private:
Dialog* baseDialog() override;
StellaSettingsDialog* stellaSettingDialog; StellaSettingsDialog* stellaSettingDialog;
OptionsDialog* optionsDialog; OptionsDialog* optionsDialog;
Dialog* getBaseDialog() override;
private: private:
// Following constructors and assignment operators not supported // Following constructors and assignment operators not supported
Menu() = delete; Menu() = delete;

View File

@ -23,11 +23,18 @@
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
TimeMachine::TimeMachine(OSystem& osystem) TimeMachine::TimeMachine(OSystem& osystem)
: DialogContainer(osystem), : DialogContainer(osystem),
myBaseDialog(nullptr),
myWidth(FBMinimum::Width) myWidth(FBMinimum::Width)
{ {
myBaseDialog = new TimeMachineDialog(myOSystem, *this, myWidth); myBaseDialog = new TimeMachineDialog(myOSystem, *this, myWidth);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
TimeMachine::~TimeMachine()
{
delete myBaseDialog; myBaseDialog = nullptr;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void TimeMachine::requestResize() void TimeMachine::requestResize()
{ {
@ -56,6 +63,12 @@ void TimeMachine::requestResize()
} }
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Dialog* TimeMachine::baseDialog()
{
return myBaseDialog;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void TimeMachine::setEnterWinds(Int32 numWinds) void TimeMachine::setEnterWinds(Int32 numWinds)
{ {

View File

@ -31,7 +31,7 @@ class TimeMachine : public DialogContainer
{ {
public: public:
explicit TimeMachine(OSystem& osystem); explicit TimeMachine(OSystem& osystem);
virtual ~TimeMachine() = default; virtual ~TimeMachine();
/** /**
This dialog has an adjustable size. We need to make sure the This dialog has an adjustable size. We need to make sure the
@ -39,12 +39,19 @@ class TimeMachine : public DialogContainer
*/ */
void requestResize() override; 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. Set number of winds when entering the dialog.
*/ */
void setEnterWinds(Int32 numWinds); void setEnterWinds(Int32 numWinds);
private: private:
Dialog* myBaseDialog;
uInt32 myWidth; uInt32 myWidth;
private: private: