From a2d7ac188b3e6a625a32edc5a8d3b4b71f8f92a1 Mon Sep 17 00:00:00 2001 From: Stephen Anthony Date: Wed, 29 Aug 2018 11:40:21 -0230 Subject: [PATCH] Dynamic dialogs are now correctly sized according to the current window size. - This fixes issue 367, and allows Logger and Browser dialogs to be displayed --- Changes.txt | 2 +- src/gui/ConfigPathDialog.cxx | 2 +- src/gui/Dialog.cxx | 18 ++++--------- src/gui/Dialog.hxx | 19 ++++++++++--- src/gui/OptionsDialog.cxx | 52 +++++++++++++++++++++++------------- src/gui/SnapshotDialog.cxx | 2 +- src/gui/TimeMachine.cxx | 16 +++-------- src/gui/TimeMachine.hxx | 2 +- src/gui/UIDialog.cxx | 3 +-- 9 files changed, 64 insertions(+), 52 deletions(-) diff --git a/Changes.txt b/Changes.txt index 9e1ea0f24..e5c335a76 100644 --- a/Changes.txt +++ b/Changes.txt @@ -72,7 +72,7 @@ * Updated PAL palette. - * Aspect ratio now affects height instead of width (like on a real CRT) + * Aspect ratio now affects height instead of width (like on a real CRT). * For UNIX systems: in the ROM launcher, when using symlinks use the symlink pathname instead of the underlying filesystem pathname. diff --git a/src/gui/ConfigPathDialog.cxx b/src/gui/ConfigPathDialog.cxx index 90c4ab7b7..9b509253f 100644 --- a/src/gui/ConfigPathDialog.cxx +++ b/src/gui/ConfigPathDialog.cxx @@ -291,7 +291,7 @@ void ConfigPathDialog::handleCommand(CommandSender* sender, int cmd, void ConfigPathDialog::createBrowser(const string& title) { uInt32 w = 0, h = 0; - getResizableBounds(w, h); + getDynamicBounds(w, h); // Create file browser dialog if(!myBrowser || uInt32(myBrowser->getWidth()) != w || diff --git a/src/gui/Dialog.cxx b/src/gui/Dialog.cxx index 94fcbc059..16599262e 100644 --- a/src/gui/Dialog.cxx +++ b/src/gui/Dialog.cxx @@ -798,28 +798,20 @@ Widget* Dialog::TabFocus::getNewFocus() } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool Dialog::getResizableBounds(uInt32& w, uInt32& h) const +bool Dialog::getDynamicBounds(uInt32& w, uInt32& h) const { const GUI::Rect& r = instance().frameBuffer().imageRect(); - bool ntsc = true; - - if(instance().hasConsole()) - { - ntsc = instance().console().tia().frameLayout() == FrameLayout::ntsc; - } - - uInt32 aspect = instance().settings().getInt(ntsc ?"tia.aspectn" : "tia.aspectp"); if(r.width() <= FrameBuffer::kFBMinW || r.height() <= FrameBuffer::kFBMinH) { - w = uInt32(aspect * FrameBuffer::kTIAMinW) * 2 / 100; - h = FrameBuffer::kTIAMinH * 2; + w = r.width(); + h = r.height(); return false; } else { - w = std::max(uInt32(aspect * r.width() / 100), uInt32(FrameBuffer::kFBMinW)); - h = std::max(uInt32(aspect * r.height() / 100), uInt32(FrameBuffer::kFBMinH)); + w = uInt32(0.9 * r.width()); + h = uInt32(0.9 * r.height()); return true; } } diff --git a/src/gui/Dialog.hxx b/src/gui/Dialog.hxx index 3c7965a2a..ba0de57d9 100644 --- a/src/gui/Dialog.hxx +++ b/src/gui/Dialog.hxx @@ -97,10 +97,23 @@ class Dialog : public GuiObject void setTitle(const string& title); bool hasTitle() { return !_title.empty(); } - /** Determine the maximum bounds based on the given width and height - Returns whether or not a large font can be used within these bounds. + /** + 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. + + NOTE: This method is meant to be used for dynamic, resizeable dialogs. + That is, those that can change size during a program run, and + *have* to take the current window size into account. + + @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 fits in the current window (scaled to 90%) + False if the dialog is smaller than the current window, and + has to be scaled down */ - bool getResizableBounds(uInt32& w, uInt32& h) const; + bool getDynamicBounds(uInt32& w, uInt32& h) const; protected: virtual void draw() override { } diff --git a/src/gui/OptionsDialog.cxx b/src/gui/OptionsDialog.cxx index 584e414b0..b8685fb5f 100644 --- a/src/gui/OptionsDialog.cxx +++ b/src/gui/OptionsDialog.cxx @@ -136,7 +136,6 @@ OptionsDialog::OptionsDialog(OSystem& osystem, DialogContainer& parent, #ifdef CHEATCODE_SUPPORT myCheatCodeDialog = make_unique(osystem, parent, _font); #endif - myLoggerDialog = make_unique(osystem, parent, _font, max_w, max_h); myDeveloperDialog = make_unique(osystem, parent, _font, max_w, max_h); myHelpDialog = make_unique(osystem, parent, _font); myAboutDialog = make_unique(osystem, parent, _font); @@ -188,17 +187,21 @@ void OptionsDialog::handleCommand(CommandSender* sender, int cmd, switch(cmd) { case kVidCmd: + { // This dialog is resizable under certain conditions, so we need // to re-create it as necessary - if(myMode != launcher) - { - uInt32 w = 0, h = 0; + uInt32 w = 0, h = 0; + getDynamicBounds(w, h); - getResizableBounds(w, h); + if(myVideoDialog == nullptr || + uInt32(myVideoDialog->getWidth()) != w || + uInt32(myVideoDialog->getHeight()) != h) + { myVideoDialog = make_unique(instance(), parent(), instance().frameBuffer().font(), w, h); } myVideoDialog->open(); break; + } case kAudCmd: myAudioDialog->open(); @@ -213,31 +216,39 @@ void OptionsDialog::handleCommand(CommandSender* sender, int cmd, break; case kSnapCmd: + { // This dialog is resizable under certain conditions, so we need // to re-create it as necessary - if(myMode != launcher) - { - uInt32 w = 0, h = 0; + uInt32 w = 0, h = 0; + getDynamicBounds(w, h); - getResizableBounds(w, h); + if(mySnapshotDialog == nullptr || + uInt32(mySnapshotDialog->getWidth()) != w || + uInt32(mySnapshotDialog->getHeight()) != h) + { mySnapshotDialog = make_unique(instance(), parent(), instance().frameBuffer().font(), w, h); } mySnapshotDialog->open(); break; + } case kCfgPathsCmd: + { // This dialog is resizable under certain conditions, so we need // to re-create it as necessary - if(myMode != launcher) - { - uInt32 w = 0, h = 0; + uInt32 w = 0, h = 0; + getDynamicBounds(w, h); - getResizableBounds(w, h); + if(myConfigPathDialog == nullptr || + uInt32(myConfigPathDialog->getWidth()) != w || + uInt32(myConfigPathDialog->getHeight()) != 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(); @@ -254,18 +265,23 @@ void OptionsDialog::handleCommand(CommandSender* sender, int cmd, #endif case kLoggerCmd: + { // This dialog is resizable under certain conditions, so we need // to re-create it as necessary - if(myMode != launcher) - { - uInt32 w = 0, h = 0; - bool uselargefont = getResizableBounds(w, h); + uInt32 w = 0, h = 0; + bool uselargefont = getDynamicBounds(w, h); + if(myLoggerDialog == nullptr || + uInt32(myLoggerDialog->getWidth()) != w || + uInt32(myLoggerDialog->getHeight()) != h) + { myLoggerDialog = make_unique(instance(), parent(), instance().frameBuffer().font(), w, h, uselargefont); } + myLoggerDialog->open(); break; + } case kDevelopCmd: myDeveloperDialog->open(); diff --git a/src/gui/SnapshotDialog.cxx b/src/gui/SnapshotDialog.cxx index 96525c7b3..155c5a3b8 100644 --- a/src/gui/SnapshotDialog.cxx +++ b/src/gui/SnapshotDialog.cxx @@ -180,7 +180,7 @@ void SnapshotDialog::handleCommand(CommandSender* sender, int cmd, void SnapshotDialog::createBrowser(const string& title) { uInt32 w = 0, h = 0; - getResizableBounds(w, h); + getDynamicBounds(w, h); // Create file browser dialog if(!myBrowser || uInt32(myBrowser->getWidth()) != w || diff --git a/src/gui/TimeMachine.cxx b/src/gui/TimeMachine.cxx index 6df6cd5cf..c34fab0be 100644 --- a/src/gui/TimeMachine.cxx +++ b/src/gui/TimeMachine.cxx @@ -31,21 +31,13 @@ TimeMachine::TimeMachine(OSystem& osystem) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void TimeMachine::requestResize() { - uInt32 w, h; - myBaseDialog->getResizableBounds(w, h); - - // If dialog is too large for given area, we need to resize it - // Otherwise, make it 80% of the allowable width - int newWidth = myWidth; - if(w < FrameBuffer::kFBMinW) - newWidth = w; - else if(myBaseDialog->getWidth() != 0.8 * w) - newWidth = uInt32(0.8 * w); + uInt32 w = 0, h = 0; + myBaseDialog->getDynamicBounds(w, h); // Only re-create when absolutely necessary - if(myWidth != newWidth) + if(myWidth != w) { - myWidth = newWidth; + myWidth = w; Dialog* oldPtr = myBaseDialog; Int32 enterWinds = static_cast(myBaseDialog)->getEnterWinds(); delete myBaseDialog; diff --git a/src/gui/TimeMachine.hxx b/src/gui/TimeMachine.hxx index e33639c9e..10adfb063 100644 --- a/src/gui/TimeMachine.hxx +++ b/src/gui/TimeMachine.hxx @@ -45,7 +45,7 @@ class TimeMachine : public DialogContainer void setEnterWinds(Int32 numWinds); private: - int myWidth; + uInt32 myWidth; private: // Following constructors and assignment operators not supported diff --git a/src/gui/UIDialog.cxx b/src/gui/UIDialog.cxx index 7ca574954..dc1303b13 100644 --- a/src/gui/UIDialog.cxx +++ b/src/gui/UIDialog.cxx @@ -396,7 +396,7 @@ void UIDialog::handleRomViewer() void UIDialog::createBrowser(const string& title) { uInt32 w = 0, h = 0; - getResizableBounds(w, h); + getDynamicBounds(w, h); // Create file browser dialog if(!myBrowser || uInt32(myBrowser->getWidth()) != w || @@ -405,4 +405,3 @@ void UIDialog::createBrowser(const string& title) else myBrowser->setTitle(title); } -