From ed75c68be85dc3a76f2ecd547f28264a2400181a Mon Sep 17 00:00:00 2001 From: Stephen Anthony Date: Tue, 13 Oct 2020 21:26:05 -0230 Subject: [PATCH] A few more cleanups relating to Common::Size vs. separate components. --- src/common/Rect.hxx | 11 ++++++++--- src/debugger/Debugger.cxx | 18 ++++++++---------- src/debugger/Debugger.hxx | 5 +++-- src/emucore/Console.cxx | 13 ++----------- src/emucore/FrameBuffer.cxx | 15 +++++++-------- src/emucore/FrameBuffer.hxx | 6 ++---- src/gui/Launcher.cxx | 25 +++++++++++-------------- src/gui/Launcher.hxx | 6 +++--- 8 files changed, 44 insertions(+), 55 deletions(-) diff --git a/src/common/Rect.hxx b/src/common/Rect.hxx index 5243740f2..faf6677b6 100644 --- a/src/common/Rect.hxx +++ b/src/common/Rect.hxx @@ -69,12 +69,17 @@ struct Size } bool valid() const { return w > 0 && h > 0; } + void clamp(uInt32 lower_w, uInt32 upper_w, uInt32 lower_h, uInt32 upper_h) { + w = BSPF::clamp(w, lower_w, upper_w); + h = BSPF::clamp(h, lower_h, upper_h); + } + bool operator==(const Size& s) const { return w == s.w && h == s.h; } bool operator!=(const Size& s) const { return w != s.w || h != s.h; } - bool operator<(const Size& s) const { return w < s.w && h < s.h; } + bool operator<(const Size& s) const { return w < s.w && h < s.h; } bool operator<=(const Size& s) const { return w <= s.w && h <= s.h; } - bool operator>(const Size& s) const { return w > s.w && h > s.h; } - bool operator>=(const Size& s) const { return w >= s.w && h >= s.h; } + bool operator>(const Size& s) const { return w > s.w || h > s.h; } + bool operator>=(const Size& s) const { return w >= s.w || h >= s.h; } friend ostream& operator<<(ostream& os, const Size& s) { os << s.w << "x" << s.h; diff --git a/src/debugger/Debugger.cxx b/src/debugger/Debugger.cxx index c15c35eac..0a4846c76 100644 --- a/src/debugger/Debugger.cxx +++ b/src/debugger/Debugger.cxx @@ -90,21 +90,18 @@ Debugger::~Debugger() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Debugger::initialize() { - const Common::Size& s = myOSystem.settings().getSize("dbg.res"); + mySize = myOSystem.settings().getSize("dbg.res"); const Common::Size& d = myOSystem.frameBuffer().desktopSize(); - myWidth = s.w; myHeight = s.h; // The debugger dialog is resizable, within certain bounds // We check those bounds now - myWidth = std::max(myWidth, uInt32(DebuggerDialog::kSmallFontMinW)); - myHeight = std::max(myHeight, uInt32(DebuggerDialog::kSmallFontMinH)); - myWidth = std::min(myWidth, uInt32(d.w)); - myHeight = std::min(myHeight, uInt32(d.h)); + mySize.clamp(uInt32(DebuggerDialog::kSmallFontMinW), d.w, + uInt32(DebuggerDialog::kSmallFontMinH), d.h); - myOSystem.settings().setValue("dbg.res", Common::Size(myWidth, myHeight)); + myOSystem.settings().setValue("dbg.res", mySize); delete myDialog; myDialog = nullptr; - myDialog = new DebuggerDialog(myOSystem, *this, 0, 0, myWidth, myHeight); + myDialog = new DebuggerDialog(myOSystem, *this, 0, 0, mySize.w, mySize.h); myCartDebug->setDebugWidget(&(myDialog->cartDebug())); @@ -115,8 +112,9 @@ void Debugger::initialize() FBInitStatus Debugger::initializeVideo() { string title = string("Stella ") + STELLA_VERSION + ": Debugger mode"; - return myOSystem.frameBuffer().createDisplay(title, FrameBuffer::BufferType::Debugger, - myWidth, myHeight); + return myOSystem.frameBuffer().createDisplay( + title, FrameBuffer::BufferType::Debugger, mySize + ); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/debugger/Debugger.hxx b/src/debugger/Debugger.hxx index 91abdd879..e7096cd4d 100644 --- a/src/debugger/Debugger.hxx +++ b/src/debugger/Debugger.hxx @@ -44,6 +44,7 @@ class RewindManager; #include #include "Base.hxx" +#include "Rect.hxx" #include "DialogContainer.hxx" #include "DebuggerDialog.hxx" #include "FrameBufferConstants.hxx" @@ -352,8 +353,8 @@ class Debugger : public DialogContainer FunctionDefMap myFunctionDefs; // Dimensions of the entire debugger window - uInt32 myWidth{DebuggerDialog::kSmallFontMinW}; - uInt32 myHeight{DebuggerDialog::kSmallFontMinH}; + Common::Size mySize{DebuggerDialog::kSmallFontMinW, + DebuggerDialog::kSmallFontMinH}; // Various builtin functions and operations struct BuiltinFunction { diff --git a/src/emucore/Console.cxx b/src/emucore/Console.cxx index 2d4f0f5a6..f12592428 100644 --- a/src/emucore/Console.cxx +++ b/src/emucore/Console.cxx @@ -626,20 +626,11 @@ FBInitStatus Console::initializeVideo(bool full) Common::Size(TIAConstants::viewableWidth, TIAConstants::viewableHeight) : Common::Size(2 * myTIA->width(), myTIA->height()); - uInt32 width, height; - if (!myOSystem.settings().getBool("tia.correct_aspect")) { - width = 2 * myTIA->width(); - height = myTIA->height(); - } else { - width = TIAConstants::viewableWidth; - height = TIAConstants::viewableHeight; - } - bool devSettings = myOSystem.settings().getBool("dev.settings"); const string& title = string("Stella ") + STELLA_VERSION + ": \"" + myProperties.get(PropType::Cart_Name) + "\""; - fbstatus = myOSystem.frameBuffer().createDisplay(title, FrameBuffer::BufferType::Emulator, - width, height, false); + fbstatus = myOSystem.frameBuffer().createDisplay(title, + FrameBuffer::BufferType::Emulator, size, false); if(fbstatus != FBInitStatus::Success) return fbstatus; diff --git a/src/emucore/FrameBuffer.cxx b/src/emucore/FrameBuffer.cxx index 420826bf3..66fe8196a 100644 --- a/src/emucore/FrameBuffer.cxx +++ b/src/emucore/FrameBuffer.cxx @@ -207,8 +207,7 @@ FontDesc FrameBuffer::getFontDesc(const string& name) const // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - FBInitStatus FrameBuffer::createDisplay(const string& title, BufferType type, - uInt32 width, uInt32 height, - bool honourHiDPI) + Common::Size size, bool honourHiDPI) { // always save, maybe only the mode of the window has changed saveCurrentWindowPosition(); @@ -220,8 +219,8 @@ FBInitStatus FrameBuffer::createDisplay(const string& title, BufferType type, // In HiDPI mode, all created displays must be scaled appropriately if(honourHiDPI && hidpiEnabled()) { - width *= hidpiScaleFactor(); - height *= hidpiScaleFactor(); + size.w *= hidpiScaleFactor(); + size.h *= hidpiScaleFactor(); } // A 'windowed' system is defined as one where the window size can be @@ -240,24 +239,24 @@ FBInitStatus FrameBuffer::createDisplay(const string& title, BufferType type, // can be relaxed // Otherwise, we treat the system as if WINDOWED_SUPPORT is not defined if(myDesktopSize.w < FBMinimum::Width && myDesktopSize.h < FBMinimum::Height && - (myDesktopSize.w < width || myDesktopSize.h < height)) + size > myDesktopSize) return FBInitStatus::FailTooLarge; #else // Make sure this mode is even possible // We only really need to worry about it in non-windowed environments, // where requesting a window that's too large will probably cause a crash - if(myDesktopSize.w < width || myDesktopSize.h < height) + if(size > myDesktopSize) return FBInitStatus::FailTooLarge; #endif // Initialize video mode handler, so it can know what video modes are // appropriate for this framebuffer - myVidModeHandler.setImageSize(Common::Size(width, height)); + myVidModeHandler.setImageSize(size); // Initialize video subsystem (make sure we get a valid mode) string pre_about = about(); myActiveVidMode = buildVideoMode(); - if(width <= myActiveVidMode.screen.w && height <= myActiveVidMode.screen.h) + if(size <= myActiveVidMode.screen) { // Changing the video mode can take some time, during which the last // sound played may get 'stuck' diff --git a/src/emucore/FrameBuffer.hxx b/src/emucore/FrameBuffer.hxx index ce9040795..a2d55fe25 100644 --- a/src/emucore/FrameBuffer.hxx +++ b/src/emucore/FrameBuffer.hxx @@ -91,8 +91,7 @@ class FrameBuffer calls are made to derived methods. @param title The title of the application / window - @param width The width of the framebuffer - @param height The height of the framebuffer + @param size The dimensions of the display @param honourHiDPI If true, consult the 'hidpi' setting and enlarge the display size accordingly; if false, use the exact dimensions as given @@ -100,8 +99,7 @@ class FrameBuffer @return Status of initialization (see FBInitStatus 'enum') */ FBInitStatus createDisplay(const string& title, BufferType type, - uInt32 width, uInt32 height, - bool honourHiDPI = true); + Common::Size size, bool honourHiDPI = true); /** Updates the display, which depending on the current mode could mean diff --git a/src/gui/Launcher.cxx b/src/gui/Launcher.cxx index 315a14f41..6c88cd384 100644 --- a/src/gui/Launcher.cxx +++ b/src/gui/Launcher.cxx @@ -29,24 +29,20 @@ Launcher::Launcher(OSystem& osystem) : DialogContainer(osystem) { - const Common::Size& s = myOSystem.settings().getSize("launcherres"); + mySize = myOSystem.settings().getSize("launcherres"); const Common::Size& d = myOSystem.frameBuffer().desktopSize(); double overscan = 1 - myOSystem.settings().getInt("tia.fs_overscan") / 100.0; - myWidth = s.w; myHeight = s.h; // The launcher dialog is resizable, within certain bounds // We check those bounds now - myWidth = std::max(myWidth, FBMinimum::Width); - myHeight = std::max(myHeight, FBMinimum::Height); - myWidth = std::min(myWidth, d.w); - myHeight = std::min(myHeight, d.h); - // do not include overscan when launcher saving size - myOSystem.settings().setValue("launcherres", Common::Size(myWidth, myHeight)); - // now make overscan effective - myWidth = std::min(myWidth, uInt32(d.w * overscan)); - myHeight = std::min(myHeight, uInt32(d.h * overscan)); + mySize.clamp(FBMinimum::Width, d.w, FBMinimum::Height, d.h); + // Do not include overscan when launcher saving size + myOSystem.settings().setValue("launcherres", mySize); + // Now make overscan effective + mySize.w = std::min(mySize.w, uInt32(d.w * overscan)); + mySize.h = std::min(mySize.h, uInt32(d.h * overscan)); - myBaseDialog = new LauncherDialog(myOSystem, *this, 0, 0, myWidth, myHeight); + myBaseDialog = new LauncherDialog(myOSystem, *this, 0, 0, mySize.w, mySize.h); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -59,8 +55,9 @@ Launcher::~Launcher() FBInitStatus Launcher::initializeVideo() { string title = string("Stella ") + STELLA_VERSION; - return myOSystem.frameBuffer().createDisplay(title, FrameBuffer::BufferType::Launcher, - myWidth, myHeight); + return myOSystem.frameBuffer().createDisplay( + title, FrameBuffer::BufferType::Launcher, mySize + ); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/gui/Launcher.hxx b/src/gui/Launcher.hxx index 4148db945..9f5cecaa4 100644 --- a/src/gui/Launcher.hxx +++ b/src/gui/Launcher.hxx @@ -22,6 +22,7 @@ class Properties; class OSystem; class FilesystemNode; +#include "Rect.hxx" #include "FrameBufferConstants.hxx" #include "DialogContainer.hxx" @@ -72,9 +73,8 @@ class Launcher : public DialogContainer private: Dialog* myBaseDialog{nullptr}; - // The width and height of this dialog - uInt32 myWidth{0}; - uInt32 myHeight{0}; + // The dimensions of this dialog + Common::Size mySize; private: // Following constructors and assignment operators not supported