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; }
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; }
friend ostream& operator<<(ostream& os, const Size& s) {
os << s.w << "x" << s.h;

View File

@ -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
);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -44,6 +44,7 @@ class RewindManager;
#include <map>
#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 {

View File

@ -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;

View File

@ -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'

View File

@ -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

View File

@ -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
);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -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