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

View File

@ -220,7 +220,7 @@ void RomWidget::handleCommand(CommandSender* sender, int cmd, int data, int id)
else
{
saveROM(rom);
parent().removeDialog();
dialog().close();
}
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
// title is temporarily visible when re-using the browser for different
// purposes
parent().addDialog(this);
open();
_title->setLabel(title);
_cmd = cmd;

View File

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

View File

@ -86,7 +86,7 @@ void ContextMenu::show(uInt32 x, uInt32 y, int item)
_yorig = y;
recalc(instance().frameBuffer().imageRect());
parent().addDialog(this);
open();
setSelected(item);
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
// Technically, this shouldn't be needed until drawDialog(), but some
@ -89,10 +89,12 @@ void Dialog::open()
buildCurrentFocusList();
_visible = true;
parent().addDialog(this, refresh);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Dialog::close()
void Dialog::close(bool refresh)
{
if (_mouseWidget)
{
@ -101,9 +103,10 @@ void Dialog::close()
}
releaseFocus();
parent().removeDialog();
_visible = false;
parent().removeDialog(refresh);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

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

View File

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

View File

@ -42,6 +42,7 @@ class OSystem;
class DialogContainer
{
friend class EventHandler;
friend class Dialog;
public:
/**
@ -124,16 +125,6 @@ class DialogContainer
*/
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.
*/
@ -147,6 +138,16 @@ class DialogContainer
private:
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:
OSystem* myOSystem;
Dialog* myBaseDialog;

View File

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

View File

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

View File

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

View File

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

View File

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