Cleaned up the API for adding/removing dialogs in the GUI. It's strange

how one thing leads to another.  This started when I noticed that exiting
the debugger with a context menu still onscreen locked that widget, and
it couldn't be selected again ...


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@2708 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2013-04-24 20:30:16 +00:00
parent 0d7df2d0ae
commit 3839b54d22
14 changed files with 55 additions and 50 deletions

View File

@ -230,7 +230,7 @@ void RamWidget::handleCommand(CommandSender* sender, int cmd, int data, int id)
if(result != "") if(result != "")
myInputBox->setTitle(result); myInputBox->setTitle(result);
else else
parent().removeDialog(); dialog().close();
break; break;
} }
@ -240,7 +240,7 @@ void RamWidget::handleCommand(CommandSender* sender, int cmd, int data, int id)
if(result != "") if(result != "")
myInputBox->setTitle(result); myInputBox->setTitle(result);
else else
parent().removeDialog(); dialog().close();
break; break;
} }

View File

@ -220,7 +220,7 @@ void RomWidget::handleCommand(CommandSender* sender, int cmd, int data, int id)
else else
{ {
saveROM(rom); saveROM(rom);
parent().removeDialog(); dialog().close();
} }
break; break;
} }

View File

@ -133,7 +133,7 @@ void BrowserDialog::show(const string& title, const string& startpath,
// Doing it this way has the unfortunate side effect that a previous // Doing it this way has the unfortunate side effect that a previous
// title is temporarily visible when re-using the browser for different // title is temporarily visible when re-using the browser for different
// purposes // purposes
parent().addDialog(this); open();
_title->setLabel(title); _title->setLabel(title);
_cmd = cmd; _cmd = cmd;

View File

@ -102,7 +102,7 @@ void ComboDialog::show(Event::Type event, const string& name)
{ {
myComboEvent = event; myComboEvent = event;
myComboName->setLabel("Add events for " + name); myComboName->setLabel("Add events for " + name);
parent().addDialog(this); open();
} }
else else
myComboEvent = Event::NoType; myComboEvent = Event::NoType;

View File

@ -86,7 +86,7 @@ void ContextMenu::show(uInt32 x, uInt32 y, int item)
_yorig = y; _yorig = y;
recalc(instance().frameBuffer().imageRect()); recalc(instance().frameBuffer().imageRect());
parent().addDialog(this); open();
setSelected(item); setSelected(item);
moveToSelected(); moveToSelected();
} }

View File

@ -64,7 +64,7 @@ Dialog::~Dialog()
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Dialog::open() void Dialog::open(bool refresh)
{ {
// Make sure we have a valid surface to draw into // Make sure we have a valid surface to draw into
// Technically, this shouldn't be needed until drawDialog(), but some // Technically, this shouldn't be needed until drawDialog(), but some
@ -89,10 +89,12 @@ void Dialog::open()
buildCurrentFocusList(); buildCurrentFocusList();
_visible = true; _visible = true;
parent().addDialog(this, refresh);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Dialog::close() void Dialog::close(bool refresh)
{ {
if (_mouseWidget) if (_mouseWidget)
{ {
@ -101,9 +103,10 @@ void Dialog::close()
} }
releaseFocus(); releaseFocus();
parent().removeDialog();
_visible = false; _visible = false;
parent().removeDialog(refresh);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -51,11 +51,12 @@ class Dialog : public GuiObject
virtual ~Dialog(); virtual ~Dialog();
void open(bool refresh = true);
void close(bool refresh = true);
bool isVisible() const { return _visible; } bool isVisible() const { return _visible; }
bool isBase() const { return _isBase; } bool isBase() const { return _isBase; }
virtual void open();
virtual void close();
virtual void center(); virtual void center();
virtual void drawDialog(); virtual void drawDialog();
virtual void loadConfig() {} virtual void loadConfig() {}

View File

@ -108,33 +108,30 @@ void DialogContainer::draw(bool full)
} }
} }
else if(!myDialogStack.empty()) else if(!myDialogStack.empty())
{
myDialogStack.top()->drawDialog(); myDialogStack.top()->drawDialog();
}
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void DialogContainer::addDialog(Dialog* d) void DialogContainer::addDialog(Dialog* d, bool refresh)
{ {
const GUI::Rect& screen = myOSystem->frameBuffer().screenRect(); const GUI::Rect& screen = myOSystem->frameBuffer().screenRect();
assert(d->getWidth() <= screen.width() && d->getHeight() <= screen.height()); assert(d->getWidth() <= screen.width() && d->getHeight() <= screen.height());
myDialogStack.push(d); myDialogStack.push(d);
d->open();
myOSystem->frameBuffer().refresh(); if(refresh)
myOSystem->frameBuffer().refresh();
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void DialogContainer::removeDialog() void DialogContainer::removeDialog(bool refresh)
{ {
if(!myDialogStack.empty()) if(!myDialogStack.empty())
{ {
myDialogStack.pop(); myDialogStack.pop();
// We need to redraw the entire screen contents, since we don't know if(refresh)
// what was obscured myOSystem->frameBuffer().refresh();
myOSystem->frameBuffer().refresh();
} }
} }
@ -143,8 +140,11 @@ void DialogContainer::reStack()
{ {
// Pop all items from the stack, and then add the base menu // Pop all items from the stack, and then add the base menu
while(!myDialogStack.empty()) while(!myDialogStack.empty())
myDialogStack.pop(); myDialogStack.top()->close(false); // don't force a refresh
addDialog(myBaseDialog);
myBaseDialog->open(false); // don't force a refresh
myOSystem->frameBuffer().refresh();
// Reset all continuous events // Reset all continuous events
reset(); reset();

View File

@ -42,6 +42,7 @@ class OSystem;
class DialogContainer class DialogContainer
{ {
friend class EventHandler; friend class EventHandler;
friend class Dialog;
public: public:
/** /**
@ -124,16 +125,6 @@ class DialogContainer
*/ */
void draw(bool full = false); void draw(bool full = false);
/**
Add a dialog box to the stack.
*/
void addDialog(Dialog* d);
/**
Remove the topmost dialog box from the stack.
*/
void removeDialog();
/** /**
Reset dialog stack to the main configuration menu. Reset dialog stack to the main configuration menu.
*/ */
@ -147,6 +138,16 @@ class DialogContainer
private: private:
void reset(); void reset();
/**
Add a dialog box to the stack.
*/
void addDialog(Dialog* d, bool refresh);
/**
Remove the topmost dialog box from the stack.
*/
void removeDialog(bool refresh);
protected: protected:
OSystem* myOSystem; OSystem* myOSystem;
Dialog* myBaseDialog; Dialog* myBaseDialog;

View File

@ -103,7 +103,7 @@ InputTextDialog::~InputTextDialog()
void InputTextDialog::show() void InputTextDialog::show()
{ {
myEnableCenter = true; myEnableCenter = true;
parent().addDialog(this); open();
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -112,7 +112,7 @@ void InputTextDialog::show(uInt32 x, uInt32 y)
myXOrig = x; myXOrig = x;
myYOrig = y; myYOrig = y;
myEnableCenter = false; myEnableCenter = false;
parent().addDialog(this); open();
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -414,11 +414,11 @@ void LauncherDialog::handleContextMenu()
if(cmd == "override") if(cmd == "override")
{ {
parent().addDialog(myGlobalProps); myGlobalProps->open();
} }
else if(cmd == "filter") else if(cmd == "filter")
{ {
parent().addDialog(myFilters); myFilters->open();
} }
else if(cmd == "reload") else if(cmd == "reload")
{ {
@ -562,7 +562,7 @@ void LauncherDialog::handleCommand(CommandSender* sender, int cmd,
} }
case kOptionsCmd: case kOptionsCmd:
parent().addDialog(myOptions); myOptions->open();
break; break;
case kPrevDirCmd: case kPrevDirCmd:

View File

@ -46,7 +46,7 @@ class MessageBox : public Dialog, public CommandSender
virtual ~MessageBox(); virtual ~MessageBox();
/** Place the input dialog onscreen and center it */ /** Place the input dialog onscreen and center it */
void show() { parent().addDialog(this); } void show() { open(); }
private: private:
void addText(const GUI::Font& font, const StringList& text); void addText(const GUI::Font& font, const StringList& text);

View File

@ -199,49 +199,49 @@ void OptionsDialog::handleCommand(CommandSender* sender, int cmd,
switch(cmd) switch(cmd)
{ {
case kVidCmd: case kVidCmd:
parent().addDialog(myVideoDialog); myVideoDialog->open();
break; break;
case kAudCmd: case kAudCmd:
parent().addDialog(myAudioDialog); myAudioDialog->open();
break; break;
case kInptCmd: case kInptCmd:
parent().addDialog(myInputDialog); myInputDialog->open();
break; break;
case kUsrIfaceCmd: case kUsrIfaceCmd:
parent().addDialog(myUIDialog); myUIDialog->open();
break; break;
case kFileSnapCmd: case kFileSnapCmd:
parent().addDialog(myFileSnapDialog); myFileSnapDialog->open();
break; break;
case kAuditCmd: case kAuditCmd:
parent().addDialog(myRomAuditDialog); myRomAuditDialog->open();
break; break;
case kInfoCmd: case kInfoCmd:
parent().addDialog(myGameInfoDialog); myGameInfoDialog->open();
break; break;
#ifdef CHEATCODE_SUPPORT #ifdef CHEATCODE_SUPPORT
case kCheatCmd: case kCheatCmd:
parent().addDialog(myCheatCodeDialog); myCheatCodeDialog->open();
break; break;
#endif #endif
case kLoggerCmd: case kLoggerCmd:
parent().addDialog(myLoggerDialog); myLoggerDialog->open();
break; break;
case kHelpCmd: case kHelpCmd:
parent().addDialog(myHelpDialog); myHelpDialog->open();
break; break;
case kAboutCmd: case kAboutCmd:
parent().addDialog(myAboutDialog); open();
break; break;
case kExitCmd: case kExitCmd:

View File

@ -58,7 +58,7 @@ ProgressDialog::ProgressDialog(GuiObject* boss, const GUI::Font& font,
mySlider->setMinValue(1); mySlider->setMinValue(1);
mySlider->setMaxValue(100); mySlider->setMaxValue(100);
parent().addDialog(this); open();
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -