Commit a2d7ac18 authored by Stephen Anthony's avatar Stephen Anthony
Browse files

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
parent 0b61a71e
......@@ -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.
......
......@@ -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 ||
......
......@@ -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;
}
}
......@@ -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 { }
......
......@@ -136,7 +136,6 @@ OptionsDialog::OptionsDialog(OSystem& osystem, DialogContainer& parent,
#ifdef CHEATCODE_SUPPORT
myCheatCodeDialog = make_unique<CheatCodeDialog>(osystem, parent, _font);
#endif
myLoggerDialog = make_unique<LoggerDialog>(osystem, parent, _font, max_w, max_h);
myDeveloperDialog = make_unique<DeveloperDialog>(osystem, parent, _font, max_w, max_h);
myHelpDialog = make_unique<HelpDialog>(osystem, parent, _font);
myAboutDialog = make_unique<AboutDialog>(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<VideoDialog>(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<SnapshotDialog>(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<ConfigPathDialog>(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<LoggerDialog>(instance(), parent(),
instance().frameBuffer().font(), w, h, uselargefont);
}
myLoggerDialog->open();
break;
}
case kDevelopCmd:
myDeveloperDialog->open();
......
......@@ -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 ||
......
......@@ -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<TimeMachineDialog*>(myBaseDialog)->getEnterWinds();
delete myBaseDialog;
......
......@@ -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
......
......@@ -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);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment