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 c37e245c7a
commit bff503a001
15 changed files with 117 additions and 42 deletions

View File

@ -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();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -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

View File

@ -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;

View File

@ -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
{

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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

View File

@ -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();

View File

@ -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<Dialog*> myDialogStack;
private:

View File

@ -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<LauncherDialog*>(myBaseDialog))->reload();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Dialog* Launcher::baseDialog()
{
return myBaseDialog;
}

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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;

View File

@ -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)
{

View File

@ -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: