diff --git a/src/gui/ConfigPathDialog.cxx b/src/gui/ConfigPathDialog.cxx index 9b509253f..796f6199d 100644 --- a/src/gui/ConfigPathDialog.cxx +++ b/src/gui/ConfigPathDialog.cxx @@ -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; diff --git a/src/gui/DeveloperDialog.cxx b/src/gui/DeveloperDialog.cxx index 2a7387d5e..1e1d07c6d 100644 --- a/src/gui/DeveloperDialog.cxx +++ b/src/gui/DeveloperDialog.cxx @@ -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; diff --git a/src/gui/Dialog.cxx b/src/gui/Dialog.cxx index ebd65591e..81da3a41a 100644 --- a/src/gui/Dialog.cxx +++ b/src/gui/Dialog.cxx @@ -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)); +} diff --git a/src/gui/Dialog.hxx b/src/gui/Dialog.hxx index ba0de57d9..fae008475 100644 --- a/src/gui/Dialog.hxx +++ b/src/gui/Dialog.hxx @@ -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 diff --git a/src/gui/GameInfoDialog.cxx b/src/gui/GameInfoDialog.cxx index f5179f3c8..510eca531 100644 --- a/src/gui/GameInfoDialog.cxx +++ b/src/gui/GameInfoDialog.cxx @@ -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, diff --git a/src/gui/GameInfoDialog.hxx b/src/gui/GameInfoDialog.hxx index b59f8b1f4..e243d79b9 100644 --- a/src/gui/GameInfoDialog.hxx +++ b/src/gui/GameInfoDialog.hxx @@ -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: diff --git a/src/gui/InputDialog.cxx b/src/gui/InputDialog.cxx index 82a1a5b3b..0c7eaeb08 100644 --- a/src/gui/InputDialog.cxx +++ b/src/gui/InputDialog.cxx @@ -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; diff --git a/src/gui/LoggerDialog.cxx b/src/gui/LoggerDialog.cxx index 3b0276511..fcecb6d9b 100644 --- a/src/gui/LoggerDialog.cxx +++ b/src/gui/LoggerDialog.cxx @@ -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; diff --git a/src/gui/OptionsDialog.cxx b/src/gui/OptionsDialog.cxx index 4648e5e7a..b620191ef 100644 --- a/src/gui/OptionsDialog.cxx +++ b/src/gui/OptionsDialog.cxx @@ -131,12 +131,12 @@ OptionsDialog::OptionsDialog(OSystem& osystem, DialogContainer& parent, myUIDialog = make_unique(osystem, parent, _font); mySnapshotDialog = make_unique(osystem, parent, _font, max_w, max_h); myConfigPathDialog = make_unique(osystem, parent, _font, boss, max_w, max_h); - myRomAuditDialog = make_unique(osystem, parent, _font, max_w, max_h); - myGameInfoDialog = make_unique(osystem, parent, _font, this); + myDeveloperDialog = make_unique(osystem, parent, _font, max_w, max_h); + myGameInfoDialog = make_unique(osystem, parent, _font, this, max_w, max_h); #ifdef CHEATCODE_SUPPORT myCheatCodeDialog = make_unique(osystem, parent, _font); #endif - myDeveloperDialog = make_unique(osystem, parent, _font, max_w, max_h); + myRomAuditDialog = make_unique(osystem, parent, _font, max_w, max_h); myHelpDialog = make_unique(osystem, parent, _font); myAboutDialog = make_unique(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(instance(), parent(), instance().frameBuffer().font(), w, h); + myVideoDialog = make_unique(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(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(instance(), parent(), instance().frameBuffer().font(), w, h); + mySnapshotDialog = make_unique(instance(), parent(), + instance().frameBuffer().font(), w, h); } mySnapshotDialog->open(); break; @@ -237,26 +245,45 @@ 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(instance(), parent(), - instance().frameBuffer().font(), _boss, w, h); + instance().frameBuffer().font(), _boss, w, h); } myConfigPathDialog->open(); 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(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(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(instance(), parent(), instance().frameBuffer().font(), w, h, uselargefont); } - myLoggerDialog->open(); break; } - case kDevelopCmd: - myDeveloperDialog->open(); - break; - case kHelpCmd: myHelpDialog->open(); break; diff --git a/src/gui/OptionsDialog.hxx b/src/gui/OptionsDialog.hxx index e5965067f..5ceb65e24 100644 --- a/src/gui/OptionsDialog.hxx +++ b/src/gui/OptionsDialog.hxx @@ -68,13 +68,13 @@ class OptionsDialog : public Dialog unique_ptr myUIDialog; unique_ptr mySnapshotDialog; unique_ptr myConfigPathDialog; - unique_ptr myRomAuditDialog; + unique_ptr myDeveloperDialog; unique_ptr myGameInfoDialog; #ifdef CHEATCODE_SUPPORT unique_ptr myCheatCodeDialog; #endif + unique_ptr myRomAuditDialog; unique_ptr myLoggerDialog; - unique_ptr myDeveloperDialog; unique_ptr myHelpDialog; unique_ptr myAboutDialog; diff --git a/src/gui/SnapshotDialog.cxx b/src/gui/SnapshotDialog.cxx index 155c5a3b8..37db52ec1 100644 --- a/src/gui/SnapshotDialog.cxx +++ b/src/gui/SnapshotDialog.cxx @@ -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; diff --git a/src/gui/VideoDialog.cxx b/src/gui/VideoDialog.cxx index cd6f2e889..4f1fb77c8 100644 --- a/src/gui/VideoDialog.cxx +++ b/src/gui/VideoDialog.cxx @@ -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;