Dialogs do remember their wanted size, so that OptionsDialog's dialogs are recreated only when necessary.

This commit is contained in:
thrust26 2018-12-30 18:47:35 +01:00
parent b1811f5a9f
commit e2a0fe9ffb
12 changed files with 105 additions and 48 deletions

View File

@ -48,8 +48,7 @@ ConfigPathDialog::ConfigPathDialog(
ButtonWidget* b; ButtonWidget* b;
// Set real dimensions // Set real dimensions
_w = std::min(64 * fontWidth + HBORDER*2, max_w); setSize(64 * fontWidth + HBORDER * 2, 9 * (lineHeight + V_GAP) + VBORDER, max_w, max_h);
_h = 9 * (lineHeight + V_GAP) + VBORDER;
xpos = HBORDER; ypos = VBORDER; xpos = HBORDER; ypos = VBORDER;

View File

@ -55,8 +55,7 @@ DeveloperDialog::DeveloperDialog(OSystem& osystem, DialogContainer& parent,
int xpos, ypos; int xpos, ypos;
// Set real dimensions // Set real dimensions
_w = std::min(53 * fontWidth + 10, max_w); setSize(53 * fontWidth + 10, 15 * (lineHeight + VGAP) + 14 + _th, max_w, max_h);
_h = std::min(15 * (lineHeight + VGAP) + 14 + _th, max_h);
// The tab widget // The tab widget
xpos = 2; ypos = 4; xpos = 2; ypos = 4;

View File

@ -62,7 +62,9 @@ Dialog::Dialog(OSystem& instance, DialogContainer& parent, const GUI::Font& font
_th(0), _th(0),
_surface(nullptr), _surface(nullptr),
_tabID(0), _tabID(0),
_flags(WIDGET_ENABLED | WIDGET_BORDER | WIDGET_CLEARBG) _flags(WIDGET_ENABLED | WIDGET_BORDER | WIDGET_CLEARBG),
_max_w(0),
_max_h(0)
{ {
setTitle(title); setTitle(title);
setDirty(); setDirty();
@ -825,3 +827,24 @@ bool Dialog::getDynamicBounds(uInt32& w, uInt32& h) const
return true; return true;
} }
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Dialog::setSize(uInt32 w, uInt32 h, uInt32 max_w, uInt32 max_h)
{
_w = std::min(w, max_w);
_max_w = w;
_h = std::min(h, max_h);
_max_h = h;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool Dialog::shouldResize(uInt32& w, uInt32& h) const
{
getDynamicBounds(w, h);
// returns true if the current size is larger than the allowed size or
// if the current size is smaller than the allowed and wanted size
return (uInt32(_w) > w || uInt32(_h) > h ||
(uInt32(_w) < w && uInt32(_w) < _max_w) ||
(uInt32(_h) < h && uInt32(_h) < _max_h));
}

View File

@ -100,7 +100,7 @@ class Dialog : public GuiObject
/** /**
Determine the maximum width/height of a dialog based on the minimum Determine the maximum width/height of a dialog based on the minimum
allowable bounds, also taking into account the current window size. allowable bounds, also taking into account the current window size.
Currently scales the width/height to 90% of allowable area when possible. Currently scales the width/height to 95% of allowable area when possible.
NOTE: This method is meant to be used for dynamic, resizeable dialogs. NOTE: This method is meant to be used for dynamic, resizeable dialogs.
That is, those that can change size during a program run, and That is, those that can change size during a program run, and
@ -115,6 +115,16 @@ class Dialog : public GuiObject
*/ */
bool getDynamicBounds(uInt32& w, uInt32& h) const; bool getDynamicBounds(uInt32& w, uInt32& h) const;
/**
Checks if the dialogs fits into the actual sizes.
@param w The resulting width to use for the dialog
@param h The resulting height to use for the dialog
@return True if the dialog should be resized
*/
bool shouldResize(uInt32& w, uInt32& h) const;
protected: protected:
virtual void draw() override { } virtual void draw() override { }
void releaseFocus() override; void releaseFocus() override;
@ -149,6 +159,9 @@ class Dialog : public GuiObject
void processCancelWithoutWidget(bool state) { _processCancel = state; } void processCancelWithoutWidget(bool state) { _processCancel = state; }
/** Define the size (allowed) for the dialog. */
void setSize(uInt32 w, uInt32 h, uInt32 max_w, uInt32 max_h);
private: private:
void buildCurrentFocusList(int tabID = -1); void buildCurrentFocusList(int tabID = -1);
bool handleNavEvent(Event::Type e); bool handleNavEvent(Event::Type e);
@ -212,6 +225,8 @@ class Dialog : public GuiObject
int _tabID; int _tabID;
int _flags; int _flags;
bool _dirty; bool _dirty;
uInt32 _max_w; // maximum wanted width
uInt32 _max_h; // maximum wanted height
private: private:
// Following constructors and assignment operators not supported // Following constructors and assignment operators not supported

View File

@ -43,7 +43,7 @@
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
GameInfoDialog::GameInfoDialog( GameInfoDialog::GameInfoDialog(
OSystem& osystem, DialogContainer& parent, const GUI::Font& font, OSystem& osystem, DialogContainer& parent, const GUI::Font& font,
GuiObject* boss) GuiObject* boss, int max_w, int max_h)
: Dialog(osystem, parent, font, "Game properties"), : Dialog(osystem, parent, font, "Game properties"),
CommandSender(boss) CommandSender(boss)
{ {
@ -62,8 +62,9 @@ GameInfoDialog::GameInfoDialog(
StaticTextWidget* t; StaticTextWidget* t;
// Set real dimensions // Set real dimensions
_w = 53 * fontWidth + 8; setSize(53 * fontWidth + 8,
_h = 8 * (lineHeight + VGAP) + VBORDER * 2 + _th + buttonHeight + fontHeight + ifont.getLineHeight() + 20; 8 * (lineHeight + VGAP) + VBORDER * 2 + _th + buttonHeight + fontHeight + ifont.getLineHeight() + 20,
max_w, max_h);
// The tab widget // The tab widget
myTab = new TabWidget(this, font, 2, 4 + _th, _w - 2 * 2, myTab = new TabWidget(this, font, 2, 4 + _th, _w - 2 * 2,

View File

@ -35,7 +35,7 @@ class GameInfoDialog : public Dialog, public CommandSender
{ {
public: public:
GameInfoDialog(OSystem& osystem, DialogContainer& parent, GameInfoDialog(OSystem& osystem, DialogContainer& parent,
const GUI::Font& font, GuiObject* boss); const GUI::Font& font, GuiObject* boss, int max_w, int max_h);
virtual ~GameInfoDialog() = default; virtual ~GameInfoDialog() = default;
private: private:

View File

@ -51,8 +51,7 @@ InputDialog::InputDialog(OSystem& osystem, DialogContainer& parent,
StringList actions; StringList actions;
// Set real dimensions // Set real dimensions
_w = std::min(50 * fontWidth + 10, max_w); setSize(50 * fontWidth + 10, 16 * (lineHeight + 4) + 16 + _th, max_w, max_h);
_h = std::min(16 * (lineHeight + 4) + 16 + _th, max_h);
// The tab widget // The tab widget
xpos = 2; ypos = vBorder + _th; xpos = 2; ypos = vBorder + _th;

View File

@ -44,8 +44,7 @@ LoggerDialog::LoggerDialog(OSystem& osystem, DialogContainer& parent,
// Set real dimensions // Set real dimensions
// This is one dialog that can take as much space as is available // This is one dialog that can take as much space as is available
_w = max_w; setSize(4000, 4000, max_w, max_h);
_h = max_h;
// Test listing of the log output // Test listing of the log output
xpos = 10; ypos = 10 + _th; xpos = 10; ypos = 10 + _th;

View File

@ -131,12 +131,12 @@ OptionsDialog::OptionsDialog(OSystem& osystem, DialogContainer& parent,
myUIDialog = make_unique<UIDialog>(osystem, parent, _font); myUIDialog = make_unique<UIDialog>(osystem, parent, _font);
mySnapshotDialog = make_unique<SnapshotDialog>(osystem, parent, _font, max_w, max_h); mySnapshotDialog = make_unique<SnapshotDialog>(osystem, parent, _font, max_w, max_h);
myConfigPathDialog = make_unique<ConfigPathDialog>(osystem, parent, _font, boss, max_w, max_h); myConfigPathDialog = make_unique<ConfigPathDialog>(osystem, parent, _font, boss, max_w, max_h);
myRomAuditDialog = make_unique<RomAuditDialog>(osystem, parent, _font, max_w, max_h); myDeveloperDialog = make_unique<DeveloperDialog>(osystem, parent, _font, max_w, max_h);
myGameInfoDialog = make_unique<GameInfoDialog>(osystem, parent, _font, this); myGameInfoDialog = make_unique<GameInfoDialog>(osystem, parent, _font, this, max_w, max_h);
#ifdef CHEATCODE_SUPPORT #ifdef CHEATCODE_SUPPORT
myCheatCodeDialog = make_unique<CheatCodeDialog>(osystem, parent, _font); myCheatCodeDialog = make_unique<CheatCodeDialog>(osystem, parent, _font);
#endif #endif
myDeveloperDialog = make_unique<DeveloperDialog>(osystem, parent, _font, max_w, max_h); myRomAuditDialog = make_unique<RomAuditDialog>(osystem, parent, _font, max_w, max_h);
myHelpDialog = make_unique<HelpDialog>(osystem, parent, _font); myHelpDialog = make_unique<HelpDialog>(osystem, parent, _font);
myAboutDialog = make_unique<AboutDialog>(osystem, parent, _font); myAboutDialog = make_unique<AboutDialog>(osystem, parent, _font);
@ -191,13 +191,11 @@ void OptionsDialog::handleCommand(CommandSender* sender, int cmd,
// This dialog is resizable under certain conditions, so we need // This dialog is resizable under certain conditions, so we need
// to re-create it as necessary // to re-create it as necessary
uInt32 w = 0, h = 0; uInt32 w = 0, h = 0;
getDynamicBounds(w, h);
if(myVideoDialog == nullptr || if(myVideoDialog == nullptr || myVideoDialog->shouldResize(w, h))
uInt32(myVideoDialog->getWidth()) > w ||
uInt32(myVideoDialog->getHeight()) > h)
{ {
myVideoDialog = make_unique<VideoDialog>(instance(), parent(), instance().frameBuffer().font(), w, h); myVideoDialog = make_unique<VideoDialog>(instance(), parent(),
instance().frameBuffer().font(), w, h);
} }
myVideoDialog->open(); myVideoDialog->open();
break; break;
@ -208,8 +206,20 @@ void OptionsDialog::handleCommand(CommandSender* sender, int cmd,
break; break;
case kInptCmd: case kInptCmd:
{
// This dialog is resizable under certain conditions, so we need
// to re-create it as necessary
uInt32 w = 0, h = 0;
if(myInputDialog == nullptr || myInputDialog->shouldResize(w, h))
{
myInputDialog = make_unique<InputDialog>(instance(), parent(),
instance().frameBuffer().font(), w, h);
}
myInputDialog->open(); myInputDialog->open();
break; break;
}
case kUsrIfaceCmd: case kUsrIfaceCmd:
myUIDialog->open(); myUIDialog->open();
@ -220,13 +230,11 @@ void OptionsDialog::handleCommand(CommandSender* sender, int cmd,
// This dialog is resizable under certain conditions, so we need // This dialog is resizable under certain conditions, so we need
// to re-create it as necessary // to re-create it as necessary
uInt32 w = 0, h = 0; uInt32 w = 0, h = 0;
getDynamicBounds(w, h);
if(mySnapshotDialog == nullptr || if(mySnapshotDialog == nullptr || mySnapshotDialog->shouldResize(w, h))
uInt32(mySnapshotDialog->getWidth()) > w ||
uInt32(mySnapshotDialog->getHeight()) > h)
{ {
mySnapshotDialog = make_unique<SnapshotDialog>(instance(), parent(), instance().frameBuffer().font(), w, h); mySnapshotDialog = make_unique<SnapshotDialog>(instance(), parent(),
instance().frameBuffer().font(), w, h);
} }
mySnapshotDialog->open(); mySnapshotDialog->open();
break; break;
@ -237,11 +245,8 @@ void OptionsDialog::handleCommand(CommandSender* sender, int cmd,
// This dialog is resizable under certain conditions, so we need // This dialog is resizable under certain conditions, so we need
// to re-create it as necessary // to re-create it as necessary
uInt32 w = 0, h = 0; uInt32 w = 0, h = 0;
getDynamicBounds(w, h);
if(myConfigPathDialog == nullptr || if(myConfigPathDialog == nullptr || myConfigPathDialog->shouldResize(w, h))
uInt32(myConfigPathDialog->getWidth()) > w ||
uInt32(myConfigPathDialog->getHeight()) > h)
{ {
myConfigPathDialog = make_unique<ConfigPathDialog>(instance(), parent(), myConfigPathDialog = make_unique<ConfigPathDialog>(instance(), parent(),
instance().frameBuffer().font(), _boss, w, h); instance().frameBuffer().font(), _boss, w, h);
@ -250,13 +255,35 @@ void OptionsDialog::handleCommand(CommandSender* sender, int cmd,
break; break;
} }
case kAuditCmd: case kDevelopCmd:
myRomAuditDialog->open(); {
// This dialog is resizable under certain conditions, so we need
// to re-create it as necessary
uInt32 w = 0, h = 0;
if(myDeveloperDialog == nullptr || myDeveloperDialog->shouldResize(w, h))
{
myDeveloperDialog = make_unique<DeveloperDialog>(instance(), parent(),
instance().frameBuffer().font(), w, h);
}
myDeveloperDialog->open();
break; break;
}
case kInfoCmd: case kInfoCmd:
{
// This dialog is resizable under certain conditions, so we need
// to re-create it as necessary
uInt32 w = 0, h = 0;
if(myGameInfoDialog == nullptr || myGameInfoDialog->shouldResize(w, h))
{
myGameInfoDialog = make_unique<GameInfoDialog>(instance(), parent(),
instance().frameBuffer().font(), this, w, h);
}
myGameInfoDialog->open(); myGameInfoDialog->open();
break; break;
}
#ifdef CHEATCODE_SUPPORT #ifdef CHEATCODE_SUPPORT
case kCheatCmd: case kCheatCmd:
@ -264,6 +291,10 @@ void OptionsDialog::handleCommand(CommandSender* sender, int cmd,
break; break;
#endif #endif
case kAuditCmd:
myRomAuditDialog->open();
break;
case kLoggerCmd: case kLoggerCmd:
{ {
// This dialog is resizable under certain conditions, so we need // This dialog is resizable under certain conditions, so we need
@ -271,22 +302,15 @@ void OptionsDialog::handleCommand(CommandSender* sender, int cmd,
uInt32 w = 0, h = 0; uInt32 w = 0, h = 0;
bool uselargefont = getDynamicBounds(w, h); bool uselargefont = getDynamicBounds(w, h);
if(myLoggerDialog == nullptr || if(myLoggerDialog == nullptr || myLoggerDialog->shouldResize(w, h))
uInt32(myLoggerDialog->getWidth()) != w ||
uInt32(myLoggerDialog->getHeight()) != h)
{ {
myLoggerDialog = make_unique<LoggerDialog>(instance(), parent(), myLoggerDialog = make_unique<LoggerDialog>(instance(), parent(),
instance().frameBuffer().font(), w, h, uselargefont); instance().frameBuffer().font(), w, h, uselargefont);
} }
myLoggerDialog->open(); myLoggerDialog->open();
break; break;
} }
case kDevelopCmd:
myDeveloperDialog->open();
break;
case kHelpCmd: case kHelpCmd:
myHelpDialog->open(); myHelpDialog->open();
break; break;

View File

@ -68,13 +68,13 @@ class OptionsDialog : public Dialog
unique_ptr<UIDialog> myUIDialog; unique_ptr<UIDialog> myUIDialog;
unique_ptr<SnapshotDialog> mySnapshotDialog; unique_ptr<SnapshotDialog> mySnapshotDialog;
unique_ptr<ConfigPathDialog> myConfigPathDialog; unique_ptr<ConfigPathDialog> myConfigPathDialog;
unique_ptr<RomAuditDialog> myRomAuditDialog; unique_ptr<DeveloperDialog> myDeveloperDialog;
unique_ptr<GameInfoDialog> myGameInfoDialog; unique_ptr<GameInfoDialog> myGameInfoDialog;
#ifdef CHEATCODE_SUPPORT #ifdef CHEATCODE_SUPPORT
unique_ptr<CheatCodeDialog> myCheatCodeDialog; unique_ptr<CheatCodeDialog> myCheatCodeDialog;
#endif #endif
unique_ptr<RomAuditDialog> myRomAuditDialog;
unique_ptr<LoggerDialog> myLoggerDialog; unique_ptr<LoggerDialog> myLoggerDialog;
unique_ptr<DeveloperDialog> myDeveloperDialog;
unique_ptr<HelpDialog> myHelpDialog; unique_ptr<HelpDialog> myHelpDialog;
unique_ptr<AboutDialog> myAboutDialog; unique_ptr<AboutDialog> myAboutDialog;

View File

@ -43,8 +43,7 @@ SnapshotDialog::SnapshotDialog(OSystem& osystem, DialogContainer& parent,
ButtonWidget* b; ButtonWidget* b;
// Set real dimensions // Set real dimensions
_w = std::min(max_w, 64 * fontWidth + HBORDER * 2); setSize(64 * fontWidth + HBORDER * 2, 9 * (lineHeight + 4) + VBORDER + _th, max_w, max_h);
_h = 9 * (lineHeight + 4) + VBORDER + _th;
xpos = HBORDER; ypos = VBORDER + _th; xpos = HBORDER; ypos = VBORDER + _th;

View File

@ -94,8 +94,7 @@ VideoDialog::VideoDialog(OSystem& osystem, DialogContainer& parent,
VariantList items; VariantList items;
// Set real dimensions // Set real dimensions
_w = std::min(55 * fontWidth + HBORDER * 2, max_w); setSize(55 * fontWidth + HBORDER * 2, 14 * (lineHeight + VGAP) + 14 + _th, max_w, max_h);
_h = std::min(14 * (lineHeight + VGAP) + 14 + _th, max_h);
// The tab widget // The tab widget
xpos = 2; ypos = 4; xpos = 2; ypos = 4;