mirror of https://github.com/stella-emu/stella.git
Dialogs do remember their wanted size, so that OptionsDialog's dialogs are recreated only when necessary.
This commit is contained in:
parent
b1811f5a9f
commit
e2a0fe9ffb
|
@ -48,8 +48,7 @@ ConfigPathDialog::ConfigPathDialog(
|
|||
ButtonWidget* b;
|
||||
|
||||
// Set real dimensions
|
||||
_w = std::min(64 * fontWidth + HBORDER*2, max_w);
|
||||
_h = 9 * (lineHeight + V_GAP) + VBORDER;
|
||||
setSize(64 * fontWidth + HBORDER * 2, 9 * (lineHeight + V_GAP) + VBORDER, max_w, max_h);
|
||||
|
||||
xpos = HBORDER; ypos = VBORDER;
|
||||
|
||||
|
|
|
@ -55,8 +55,7 @@ DeveloperDialog::DeveloperDialog(OSystem& osystem, DialogContainer& parent,
|
|||
int xpos, ypos;
|
||||
|
||||
// Set real dimensions
|
||||
_w = std::min(53 * fontWidth + 10, max_w);
|
||||
_h = std::min(15 * (lineHeight + VGAP) + 14 + _th, max_h);
|
||||
setSize(53 * fontWidth + 10, 15 * (lineHeight + VGAP) + 14 + _th, max_w, max_h);
|
||||
|
||||
// The tab widget
|
||||
xpos = 2; ypos = 4;
|
||||
|
|
|
@ -62,7 +62,9 @@ Dialog::Dialog(OSystem& instance, DialogContainer& parent, const GUI::Font& font
|
|||
_th(0),
|
||||
_surface(nullptr),
|
||||
_tabID(0),
|
||||
_flags(WIDGET_ENABLED | WIDGET_BORDER | WIDGET_CLEARBG)
|
||||
_flags(WIDGET_ENABLED | WIDGET_BORDER | WIDGET_CLEARBG),
|
||||
_max_w(0),
|
||||
_max_h(0)
|
||||
{
|
||||
setTitle(title);
|
||||
setDirty();
|
||||
|
@ -825,3 +827,24 @@ bool Dialog::getDynamicBounds(uInt32& w, uInt32& h) const
|
|||
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));
|
||||
}
|
||||
|
|
|
@ -100,7 +100,7 @@ class Dialog : public GuiObject
|
|||
/**
|
||||
Determine the maximum width/height of a dialog based on the minimum
|
||||
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.
|
||||
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;
|
||||
|
||||
/**
|
||||
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:
|
||||
virtual void draw() override { }
|
||||
void releaseFocus() override;
|
||||
|
@ -149,6 +159,9 @@ class Dialog : public GuiObject
|
|||
|
||||
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:
|
||||
void buildCurrentFocusList(int tabID = -1);
|
||||
bool handleNavEvent(Event::Type e);
|
||||
|
@ -212,6 +225,8 @@ class Dialog : public GuiObject
|
|||
int _tabID;
|
||||
int _flags;
|
||||
bool _dirty;
|
||||
uInt32 _max_w; // maximum wanted width
|
||||
uInt32 _max_h; // maximum wanted height
|
||||
|
||||
private:
|
||||
// Following constructors and assignment operators not supported
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
GameInfoDialog::GameInfoDialog(
|
||||
OSystem& osystem, DialogContainer& parent, const GUI::Font& font,
|
||||
GuiObject* boss)
|
||||
GuiObject* boss, int max_w, int max_h)
|
||||
: Dialog(osystem, parent, font, "Game properties"),
|
||||
CommandSender(boss)
|
||||
{
|
||||
|
@ -62,8 +62,9 @@ GameInfoDialog::GameInfoDialog(
|
|||
StaticTextWidget* t;
|
||||
|
||||
// Set real dimensions
|
||||
_w = 53 * fontWidth + 8;
|
||||
_h = 8 * (lineHeight + VGAP) + VBORDER * 2 + _th + buttonHeight + fontHeight + ifont.getLineHeight() + 20;
|
||||
setSize(53 * fontWidth + 8,
|
||||
8 * (lineHeight + VGAP) + VBORDER * 2 + _th + buttonHeight + fontHeight + ifont.getLineHeight() + 20,
|
||||
max_w, max_h);
|
||||
|
||||
// The tab widget
|
||||
myTab = new TabWidget(this, font, 2, 4 + _th, _w - 2 * 2,
|
||||
|
|
|
@ -35,7 +35,7 @@ class GameInfoDialog : public Dialog, public CommandSender
|
|||
{
|
||||
public:
|
||||
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;
|
||||
|
||||
private:
|
||||
|
|
|
@ -51,8 +51,7 @@ InputDialog::InputDialog(OSystem& osystem, DialogContainer& parent,
|
|||
StringList actions;
|
||||
|
||||
// Set real dimensions
|
||||
_w = std::min(50 * fontWidth + 10, max_w);
|
||||
_h = std::min(16 * (lineHeight + 4) + 16 + _th, max_h);
|
||||
setSize(50 * fontWidth + 10, 16 * (lineHeight + 4) + 16 + _th, max_w, max_h);
|
||||
|
||||
// The tab widget
|
||||
xpos = 2; ypos = vBorder + _th;
|
||||
|
|
|
@ -44,8 +44,7 @@ LoggerDialog::LoggerDialog(OSystem& osystem, DialogContainer& parent,
|
|||
|
||||
// Set real dimensions
|
||||
// This is one dialog that can take as much space as is available
|
||||
_w = max_w;
|
||||
_h = max_h;
|
||||
setSize(4000, 4000, max_w, max_h);
|
||||
|
||||
// Test listing of the log output
|
||||
xpos = 10; ypos = 10 + _th;
|
||||
|
|
|
@ -131,12 +131,12 @@ OptionsDialog::OptionsDialog(OSystem& osystem, DialogContainer& parent,
|
|||
myUIDialog = make_unique<UIDialog>(osystem, parent, _font);
|
||||
mySnapshotDialog = make_unique<SnapshotDialog>(osystem, parent, _font, 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);
|
||||
myGameInfoDialog = make_unique<GameInfoDialog>(osystem, parent, _font, this);
|
||||
myDeveloperDialog = make_unique<DeveloperDialog>(osystem, parent, _font, max_w, max_h);
|
||||
myGameInfoDialog = make_unique<GameInfoDialog>(osystem, parent, _font, this, max_w, max_h);
|
||||
#ifdef CHEATCODE_SUPPORT
|
||||
myCheatCodeDialog = make_unique<CheatCodeDialog>(osystem, parent, _font);
|
||||
#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);
|
||||
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
|
||||
// to re-create it as necessary
|
||||
uInt32 w = 0, h = 0;
|
||||
getDynamicBounds(w, h);
|
||||
|
||||
if(myVideoDialog == nullptr ||
|
||||
uInt32(myVideoDialog->getWidth()) > w ||
|
||||
uInt32(myVideoDialog->getHeight()) > h)
|
||||
if(myVideoDialog == nullptr || myVideoDialog->shouldResize(w, 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();
|
||||
break;
|
||||
|
@ -208,8 +206,20 @@ void OptionsDialog::handleCommand(CommandSender* sender, int cmd,
|
|||
break;
|
||||
|
||||
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();
|
||||
break;
|
||||
}
|
||||
|
||||
case kUsrIfaceCmd:
|
||||
myUIDialog->open();
|
||||
|
@ -220,13 +230,11 @@ void OptionsDialog::handleCommand(CommandSender* sender, int cmd,
|
|||
// This dialog is resizable under certain conditions, so we need
|
||||
// to re-create it as necessary
|
||||
uInt32 w = 0, h = 0;
|
||||
getDynamicBounds(w, h);
|
||||
|
||||
if(mySnapshotDialog == nullptr ||
|
||||
uInt32(mySnapshotDialog->getWidth()) > w ||
|
||||
uInt32(mySnapshotDialog->getHeight()) > h)
|
||||
if(mySnapshotDialog == nullptr || mySnapshotDialog->shouldResize(w, 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();
|
||||
break;
|
||||
|
@ -237,11 +245,8 @@ void OptionsDialog::handleCommand(CommandSender* sender, int cmd,
|
|||
// This dialog is resizable under certain conditions, so we need
|
||||
// to re-create it as necessary
|
||||
uInt32 w = 0, h = 0;
|
||||
getDynamicBounds(w, h);
|
||||
|
||||
if(myConfigPathDialog == nullptr ||
|
||||
uInt32(myConfigPathDialog->getWidth()) > w ||
|
||||
uInt32(myConfigPathDialog->getHeight()) > h)
|
||||
if(myConfigPathDialog == nullptr || myConfigPathDialog->shouldResize(w, h))
|
||||
{
|
||||
myConfigPathDialog = make_unique<ConfigPathDialog>(instance(), parent(),
|
||||
instance().frameBuffer().font(), _boss, w, h);
|
||||
|
@ -250,13 +255,35 @@ void OptionsDialog::handleCommand(CommandSender* sender, int cmd,
|
|||
break;
|
||||
}
|
||||
|
||||
case kAuditCmd:
|
||||
myRomAuditDialog->open();
|
||||
case kDevelopCmd:
|
||||
{
|
||||
// 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;
|
||||
}
|
||||
|
||||
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();
|
||||
break;
|
||||
}
|
||||
|
||||
#ifdef CHEATCODE_SUPPORT
|
||||
case kCheatCmd:
|
||||
|
@ -264,6 +291,10 @@ void OptionsDialog::handleCommand(CommandSender* sender, int cmd,
|
|||
break;
|
||||
#endif
|
||||
|
||||
case kAuditCmd:
|
||||
myRomAuditDialog->open();
|
||||
break;
|
||||
|
||||
case kLoggerCmd:
|
||||
{
|
||||
// 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;
|
||||
bool uselargefont = getDynamicBounds(w, h);
|
||||
|
||||
if(myLoggerDialog == nullptr ||
|
||||
uInt32(myLoggerDialog->getWidth()) != w ||
|
||||
uInt32(myLoggerDialog->getHeight()) != h)
|
||||
if(myLoggerDialog == nullptr || myLoggerDialog->shouldResize(w, h))
|
||||
{
|
||||
myLoggerDialog = make_unique<LoggerDialog>(instance(), parent(),
|
||||
instance().frameBuffer().font(), w, h, uselargefont);
|
||||
}
|
||||
|
||||
myLoggerDialog->open();
|
||||
break;
|
||||
}
|
||||
|
||||
case kDevelopCmd:
|
||||
myDeveloperDialog->open();
|
||||
break;
|
||||
|
||||
case kHelpCmd:
|
||||
myHelpDialog->open();
|
||||
break;
|
||||
|
|
|
@ -68,13 +68,13 @@ class OptionsDialog : public Dialog
|
|||
unique_ptr<UIDialog> myUIDialog;
|
||||
unique_ptr<SnapshotDialog> mySnapshotDialog;
|
||||
unique_ptr<ConfigPathDialog> myConfigPathDialog;
|
||||
unique_ptr<RomAuditDialog> myRomAuditDialog;
|
||||
unique_ptr<DeveloperDialog> myDeveloperDialog;
|
||||
unique_ptr<GameInfoDialog> myGameInfoDialog;
|
||||
#ifdef CHEATCODE_SUPPORT
|
||||
unique_ptr<CheatCodeDialog> myCheatCodeDialog;
|
||||
#endif
|
||||
unique_ptr<RomAuditDialog> myRomAuditDialog;
|
||||
unique_ptr<LoggerDialog> myLoggerDialog;
|
||||
unique_ptr<DeveloperDialog> myDeveloperDialog;
|
||||
unique_ptr<HelpDialog> myHelpDialog;
|
||||
unique_ptr<AboutDialog> myAboutDialog;
|
||||
|
||||
|
|
|
@ -43,8 +43,7 @@ SnapshotDialog::SnapshotDialog(OSystem& osystem, DialogContainer& parent,
|
|||
ButtonWidget* b;
|
||||
|
||||
// Set real dimensions
|
||||
_w = std::min(max_w, 64 * fontWidth + HBORDER * 2);
|
||||
_h = 9 * (lineHeight + 4) + VBORDER + _th;
|
||||
setSize(64 * fontWidth + HBORDER * 2, 9 * (lineHeight + 4) + VBORDER + _th, max_w, max_h);
|
||||
|
||||
xpos = HBORDER; ypos = VBORDER + _th;
|
||||
|
||||
|
|
|
@ -94,8 +94,7 @@ VideoDialog::VideoDialog(OSystem& osystem, DialogContainer& parent,
|
|||
VariantList items;
|
||||
|
||||
// Set real dimensions
|
||||
_w = std::min(55 * fontWidth + HBORDER * 2, max_w);
|
||||
_h = std::min(14 * (lineHeight + VGAP) + 14 + _th, max_h);
|
||||
setSize(55 * fontWidth + HBORDER * 2, 14 * (lineHeight + VGAP) + 14 + _th, max_w, max_h);
|
||||
|
||||
// The tab widget
|
||||
xpos = 2; ypos = 4;
|
||||
|
|
Loading…
Reference in New Issue