From 49585250fdfc47c9ad40dc88a49cca5158ea8944 Mon Sep 17 00:00:00 2001 From: thrust26 Date: Sat, 18 May 2019 09:04:06 +0200 Subject: [PATCH] add another cleanup remembering last windowed position code --- src/common/FrameBufferSDL2.cxx | 12 +++++------- src/common/FrameBufferSDL2.hxx | 3 +-- src/common/Rect.hxx | 6 +++--- src/common/Variant.hxx | 2 ++ src/emucore/Settings.cxx | 3 +-- src/emucore/Settings.hxx | 1 + 6 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/common/FrameBufferSDL2.cxx b/src/common/FrameBufferSDL2.cxx index 3949bf3e0..a87f9891a 100644 --- a/src/common/FrameBufferSDL2.cxx +++ b/src/common/FrameBufferSDL2.cxx @@ -52,8 +52,7 @@ FrameBufferSDL2::FrameBufferSDL2(OSystem& osystem) // been created myPixelFormat = SDL_AllocFormat(SDL_PIXELFORMAT_ARGB8888); - myPosX = myOSystem.settings().getInt("pos.x"); - myPosY = myOSystem.settings().getInt("pos.y"); + myWindowedPos = myOSystem.settings().getPoint("windowedpos"); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -175,9 +174,8 @@ void FrameBufferSDL2::updateWindowedPos() if (!myCenter && myWindow && !(SDL_GetWindowFlags(myWindow) & SDL_WINDOW_FULLSCREEN_DESKTOP)) { // save current windowed position - SDL_GetWindowPosition(myWindow, &myPosX, &myPosY); - myOSystem.settings().setValue("pos.x", myPosX); - myOSystem.settings().setValue("pos.y", myPosY); + SDL_GetWindowPosition(myWindow, &myWindowedPos.x, &myWindowedPos.y); + myOSystem.settings().setValue("windowedpos", myWindowedPos); } } @@ -223,8 +221,8 @@ bool FrameBufferSDL2::setVideoMode(const string& title, const VideoMode& mode) posX = posY = SDL_WINDOWPOS_CENTERED_DISPLAY(displayIndex); else { - posX = myPosX, - posY = myPosY; + posX = myWindowedPos.x, + posY = myWindowedPos.y; } uInt32 flags = mode.fsIndex != -1 ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0; diff --git a/src/common/FrameBufferSDL2.hxx b/src/common/FrameBufferSDL2.hxx index 2dac0c1ec..f1b23d8fa 100644 --- a/src/common/FrameBufferSDL2.hxx +++ b/src/common/FrameBufferSDL2.hxx @@ -193,8 +193,7 @@ class FrameBufferSDL2 : public FrameBuffer bool myCenter; // last position of windowed window - int myPosX; - int myPosY; + Common::Point myWindowedPos; private: // Following constructors and assignment operators not supported diff --git a/src/common/Rect.hxx b/src/common/Rect.hxx index 832d95e88..97251b5cd 100644 --- a/src/common/Rect.hxx +++ b/src/common/Rect.hxx @@ -32,12 +32,12 @@ namespace Common { */ struct Point { - uInt32 x; //!< The horizontal part of the point - uInt32 y; //!< The vertical part of the point + Int32 x; //!< The horizontal part of the point + Int32 y; //!< The vertical part of the point Point() : x(0), y(0) { } Point(const Point& p) : x(p.x), y(p.y) { } - explicit Point(uInt32 x1, uInt32 y1) : x(x1), y(y1) { } + explicit Point(Int32 x1, Int32 y1) : x(x1), y(y1) { } explicit Point(const string& p) : x(0), y(0) { char c = '\0'; istringstream buf(p); diff --git a/src/common/Variant.hxx b/src/common/Variant.hxx index 8be83e957..df6c64239 100644 --- a/src/common/Variant.hxx +++ b/src/common/Variant.hxx @@ -53,6 +53,7 @@ class Variant Variant(double d) { buf().str(""); buf() << d; data = buf().str(); } Variant(bool b) { buf().str(""); buf() << b; data = buf().str(); } Variant(const Common::Size& s) { buf().str(""); buf() << s; data = buf().str(); } + Variant(const Common::Point& s) { buf().str(""); buf() << s; data = buf().str(); } // Conversion methods const string& toString() const { return data; } @@ -73,6 +74,7 @@ class Variant } bool toBool() const { return data == "1" || data == "true"; } Common::Size toSize() const { return Common::Size(data); } + Common::Point toPoint() const { return Common::Point(data); } // Comparison bool operator==(const Variant& v) const { return data == v.data; } diff --git a/src/emucore/Settings.cxx b/src/emucore/Settings.cxx index 78c88891e..936a4a20c 100644 --- a/src/emucore/Settings.cxx +++ b/src/emucore/Settings.cxx @@ -38,8 +38,7 @@ Settings::Settings() setPermanent("speed", "1.0"); setPermanent("vsync", "true"); setPermanent("center", "true"); - setPermanent("pos.x", 50); - setPermanent("pos.y", 50); + setPermanent("windowedpos", Common::Point(50, 50)); setPermanent("display", 0); setPermanent("palette", "standard"); setPermanent("uimessages", "true"); diff --git a/src/emucore/Settings.hxx b/src/emucore/Settings.hxx index 7cf1bd082..f151dd814 100644 --- a/src/emucore/Settings.hxx +++ b/src/emucore/Settings.hxx @@ -101,6 +101,7 @@ class Settings bool getBool(const string& key) const { return value(key).toBool(); } const string& getString(const string& key) const { return value(key).toString(); } const Common::Size getSize(const string& key) const { return value(key).toSize(); } + const Common::Point getPoint(const string& key) const { return value(key).toPoint(); } protected: /**