A few more cleanups relating to Common::Size vs. separate components.

This commit is contained in:
Stephen Anthony 2020-10-13 21:26:05 -02:30
parent e5ac81392c
commit 01b23e4116
8 changed files with 44 additions and 55 deletions

View File

@ -69,12 +69,17 @@ struct Size
} }
bool valid() const { return w > 0 && h > 0; } 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; } 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) { friend ostream& operator<<(ostream& os, const Size& s) {
os << s.w << "x" << s.h; os << s.w << "x" << s.h;

View File

@ -90,21 +90,18 @@ Debugger::~Debugger()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Debugger::initialize() 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(); const Common::Size& d = myOSystem.frameBuffer().desktopSize();
myWidth = s.w; myHeight = s.h;
// The debugger dialog is resizable, within certain bounds // The debugger dialog is resizable, within certain bounds
// We check those bounds now // We check those bounds now
myWidth = std::max(myWidth, uInt32(DebuggerDialog::kSmallFontMinW)); mySize.clamp(uInt32(DebuggerDialog::kSmallFontMinW), d.w,
myHeight = std::max(myHeight, uInt32(DebuggerDialog::kSmallFontMinH)); uInt32(DebuggerDialog::kSmallFontMinH), d.h);
myWidth = std::min(myWidth, uInt32(d.w));
myHeight = std::min(myHeight, uInt32(d.h));
myOSystem.settings().setValue("dbg.res", Common::Size(myWidth, myHeight)); myOSystem.settings().setValue("dbg.res", mySize);
delete myDialog; myDialog = nullptr; 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())); myCartDebug->setDebugWidget(&(myDialog->cartDebug()));
@ -115,8 +112,9 @@ void Debugger::initialize()
FBInitStatus Debugger::initializeVideo() FBInitStatus Debugger::initializeVideo()
{ {
string title = string("Stella ") + STELLA_VERSION + ": Debugger mode"; string title = string("Stella ") + STELLA_VERSION + ": Debugger mode";
return myOSystem.frameBuffer().createDisplay(title, FrameBuffer::BufferType::Debugger, return myOSystem.frameBuffer().createDisplay(
myWidth, myHeight); title, FrameBuffer::BufferType::Debugger, mySize
);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -44,6 +44,7 @@ class RewindManager;
#include <map> #include <map>
#include "Base.hxx" #include "Base.hxx"
#include "Rect.hxx"
#include "DialogContainer.hxx" #include "DialogContainer.hxx"
#include "DebuggerDialog.hxx" #include "DebuggerDialog.hxx"
#include "FrameBufferConstants.hxx" #include "FrameBufferConstants.hxx"
@ -352,8 +353,8 @@ class Debugger : public DialogContainer
FunctionDefMap myFunctionDefs; FunctionDefMap myFunctionDefs;
// Dimensions of the entire debugger window // Dimensions of the entire debugger window
uInt32 myWidth{DebuggerDialog::kSmallFontMinW}; Common::Size mySize{DebuggerDialog::kSmallFontMinW,
uInt32 myHeight{DebuggerDialog::kSmallFontMinH}; DebuggerDialog::kSmallFontMinH};
// Various builtin functions and operations // Various builtin functions and operations
struct BuiltinFunction { struct BuiltinFunction {

View File

@ -626,20 +626,11 @@ FBInitStatus Console::initializeVideo(bool full)
Common::Size(TIAConstants::viewableWidth, TIAConstants::viewableHeight) : Common::Size(TIAConstants::viewableWidth, TIAConstants::viewableHeight) :
Common::Size(2 * myTIA->width(), myTIA->height()); 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"); bool devSettings = myOSystem.settings().getBool("dev.settings");
const string& title = string("Stella ") + STELLA_VERSION + const string& title = string("Stella ") + STELLA_VERSION +
": \"" + myProperties.get(PropType::Cart_Name) + "\""; ": \"" + myProperties.get(PropType::Cart_Name) + "\"";
fbstatus = myOSystem.frameBuffer().createDisplay(title, FrameBuffer::BufferType::Emulator, fbstatus = myOSystem.frameBuffer().createDisplay(title,
width, height, false); FrameBuffer::BufferType::Emulator, size, false);
if(fbstatus != FBInitStatus::Success) if(fbstatus != FBInitStatus::Success)
return fbstatus; return fbstatus;

View File

@ -207,8 +207,7 @@ FontDesc FrameBuffer::getFontDesc(const string& name) const
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
FBInitStatus FrameBuffer::createDisplay(const string& title, BufferType type, FBInitStatus FrameBuffer::createDisplay(const string& title, BufferType type,
uInt32 width, uInt32 height, Common::Size size, bool honourHiDPI)
bool honourHiDPI)
{ {
// always save, maybe only the mode of the window has changed // always save, maybe only the mode of the window has changed
saveCurrentWindowPosition(); saveCurrentWindowPosition();
@ -220,8 +219,8 @@ FBInitStatus FrameBuffer::createDisplay(const string& title, BufferType type,
// In HiDPI mode, all created displays must be scaled appropriately // In HiDPI mode, all created displays must be scaled appropriately
if(honourHiDPI && hidpiEnabled()) if(honourHiDPI && hidpiEnabled())
{ {
width *= hidpiScaleFactor(); size.w *= hidpiScaleFactor();
height *= hidpiScaleFactor(); size.h *= hidpiScaleFactor();
} }
// A 'windowed' system is defined as one where the window size can be // 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 // can be relaxed
// Otherwise, we treat the system as if WINDOWED_SUPPORT is not defined // Otherwise, we treat the system as if WINDOWED_SUPPORT is not defined
if(myDesktopSize.w < FBMinimum::Width && myDesktopSize.h < FBMinimum::Height && if(myDesktopSize.w < FBMinimum::Width && myDesktopSize.h < FBMinimum::Height &&
(myDesktopSize.w < width || myDesktopSize.h < height)) size > myDesktopSize)
return FBInitStatus::FailTooLarge; return FBInitStatus::FailTooLarge;
#else #else
// Make sure this mode is even possible // Make sure this mode is even possible
// We only really need to worry about it in non-windowed environments, // 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 // 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; return FBInitStatus::FailTooLarge;
#endif #endif
// Initialize video mode handler, so it can know what video modes are // Initialize video mode handler, so it can know what video modes are
// appropriate for this framebuffer // appropriate for this framebuffer
myVidModeHandler.setImageSize(Common::Size(width, height)); myVidModeHandler.setImageSize(size);
// Initialize video subsystem (make sure we get a valid mode) // Initialize video subsystem (make sure we get a valid mode)
string pre_about = about(); string pre_about = about();
myActiveVidMode = buildVideoMode(); 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 // Changing the video mode can take some time, during which the last
// sound played may get 'stuck' // sound played may get 'stuck'

View File

@ -91,8 +91,7 @@ class FrameBuffer
calls are made to derived methods. calls are made to derived methods.
@param title The title of the application / window @param title The title of the application / window
@param width The width of the framebuffer @param size The dimensions of the display
@param height The height of the framebuffer
@param honourHiDPI If true, consult the 'hidpi' setting and enlarge @param honourHiDPI If true, consult the 'hidpi' setting and enlarge
the display size accordingly; if false, use the the display size accordingly; if false, use the
exact dimensions as given exact dimensions as given
@ -100,8 +99,7 @@ class FrameBuffer
@return Status of initialization (see FBInitStatus 'enum') @return Status of initialization (see FBInitStatus 'enum')
*/ */
FBInitStatus createDisplay(const string& title, BufferType type, FBInitStatus createDisplay(const string& title, BufferType type,
uInt32 width, uInt32 height, Common::Size size, bool honourHiDPI = true);
bool honourHiDPI = true);
/** /**
Updates the display, which depending on the current mode could mean Updates the display, which depending on the current mode could mean

View File

@ -29,24 +29,20 @@
Launcher::Launcher(OSystem& osystem) Launcher::Launcher(OSystem& osystem)
: DialogContainer(osystem) : DialogContainer(osystem)
{ {
const Common::Size& s = myOSystem.settings().getSize("launcherres"); mySize = myOSystem.settings().getSize("launcherres");
const Common::Size& d = myOSystem.frameBuffer().desktopSize(); const Common::Size& d = myOSystem.frameBuffer().desktopSize();
double overscan = 1 - myOSystem.settings().getInt("tia.fs_overscan") / 100.0; 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 // The launcher dialog is resizable, within certain bounds
// We check those bounds now // We check those bounds now
myWidth = std::max(myWidth, FBMinimum::Width); mySize.clamp(FBMinimum::Width, d.w, FBMinimum::Height, d.h);
myHeight = std::max(myHeight, FBMinimum::Height); // Do not include overscan when launcher saving size
myWidth = std::min(myWidth, d.w); myOSystem.settings().setValue("launcherres", mySize);
myHeight = std::min(myHeight, d.h); // Now make overscan effective
// do not include overscan when launcher saving size mySize.w = std::min(mySize.w, uInt32(d.w * overscan));
myOSystem.settings().setValue("launcherres", Common::Size(myWidth, myHeight)); mySize.h = std::min(mySize.h, uInt32(d.h * overscan));
// now make overscan effective
myWidth = std::min(myWidth, uInt32(d.w * overscan));
myHeight = std::min(myHeight, 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() FBInitStatus Launcher::initializeVideo()
{ {
string title = string("Stella ") + STELLA_VERSION; string title = string("Stella ") + STELLA_VERSION;
return myOSystem.frameBuffer().createDisplay(title, FrameBuffer::BufferType::Launcher, return myOSystem.frameBuffer().createDisplay(
myWidth, myHeight); title, FrameBuffer::BufferType::Launcher, mySize
);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -22,6 +22,7 @@ class Properties;
class OSystem; class OSystem;
class FilesystemNode; class FilesystemNode;
#include "Rect.hxx"
#include "FrameBufferConstants.hxx" #include "FrameBufferConstants.hxx"
#include "DialogContainer.hxx" #include "DialogContainer.hxx"
@ -72,9 +73,8 @@ class Launcher : public DialogContainer
private: private:
Dialog* myBaseDialog{nullptr}; Dialog* myBaseDialog{nullptr};
// The width and height of this dialog // The dimensions of this dialog
uInt32 myWidth{0}; Common::Size mySize;
uInt32 myHeight{0};
private: private:
// Following constructors and assignment operators not supported // Following constructors and assignment operators not supported