cleanup remembering last windowed position code

This commit is contained in:
thrust26 2019-05-18 08:43:02 +02:00
parent 22b15d7f37
commit 53597938b6
4 changed files with 30 additions and 30 deletions

View File

@ -51,6 +51,9 @@ FrameBufferSDL2::FrameBufferSDL2(OSystem& osystem)
// since the structure may be needed before any FBSurface's have
// been created
myPixelFormat = SDL_AllocFormat(SDL_PIXELFORMAT_ARGB8888);
myPosX = myOSystem.settings().getInt("pos.x");
myPosY = myOSystem.settings().getInt("pos.y");
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -164,23 +167,17 @@ Int32 FrameBufferSDL2::getCurrentDisplayIndex()
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FrameBufferSDL2::getCurrentWindowPos(int& x, int&y)
void FrameBufferSDL2::updateWindowedPos()
{
ASSERT_MAIN_THREAD;
if (myCenter ||
!myWindow || (SDL_GetWindowFlags(myWindow) & SDL_WINDOW_FULLSCREEN_DESKTOP))
// only save if the window is not centered and not in full screen mode
if (!myCenter && myWindow && !(SDL_GetWindowFlags(myWindow) & SDL_WINDOW_FULLSCREEN_DESKTOP))
{
// restore to last saved window position
x = myOSystem.settings().getInt("pos.x");
y = myOSystem.settings().getInt("pos.y");
}
else
{
// save current window position
SDL_GetWindowPosition(myWindow, &x, &y);
myOSystem.settings().setValue("pos.x", x);
myOSystem.settings().setValue("pos.y", y);
// save current windowed position
SDL_GetWindowPosition(myWindow, &myPosX, &myPosY);
myOSystem.settings().setValue("pos.x", myPosX);
myOSystem.settings().setValue("pos.y", myPosY);
}
}
@ -209,9 +206,8 @@ bool FrameBufferSDL2::setVideoMode(const string& title, const VideoMode& mode)
}
}
// get current windows position
int posX, posY;
getCurrentWindowPos(posX, posY);
// save and get last windowed window's position
updateWindowedPos();
// Always recreate renderer (some systems need this)
if(myRenderer)
@ -220,9 +216,16 @@ bool FrameBufferSDL2::setVideoMode(const string& title, const VideoMode& mode)
myRenderer = nullptr;
}
int posX, posY;
myCenter = myOSystem.settings().getBool("center");
if (myCenter)
posX = posY = SDL_WINDOWPOS_CENTERED_DISPLAY(displayIndex);
else
{
posX = myPosX,
posY = myPosY;
}
uInt32 flags = mode.fsIndex != -1 ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0;
// macOS seems to have issues with destroying the window, and wants to
@ -257,7 +260,7 @@ bool FrameBufferSDL2::setVideoMode(const string& title, const VideoMode& mode)
{
SDL_SetWindowFullscreen(myWindow, flags);
SDL_SetWindowSize(myWindow, mode.screen.w, mode.screen.h);
SDL_SetWindowPosition(myWindow, pos, pos);
SDL_SetWindowPosition(myWindow, posX, posY);
SDL_SetWindowTitle(myWindow, title.c_str());
}
#endif

View File

@ -107,12 +107,9 @@ class FrameBufferSDL2 : public FrameBuffer
Int32 getCurrentDisplayIndex() override;
/**
This method is called to query the current window position.
@param x The x-position retrieved
@param y The y-position retrieved
This method is called to preserve the last current windowed position.
*/
void getCurrentWindowPos(int& x, int& y) override;
void updateWindowedPos() override;
/**
Clear the frame buffer
@ -195,6 +192,10 @@ class FrameBufferSDL2 : public FrameBuffer
// center setting of curent window
bool myCenter;
// last position of windowed window
int myPosX;
int myPosY;
private:
// Following constructors and assignment operators not supported
FrameBufferSDL2() = delete;

View File

@ -345,12 +345,9 @@ class FrameBuffer
virtual Int32 getCurrentDisplayIndex() = 0;
/**
This method is called to query the current window position.
@param x The x-position retrieved
@param y The y-position retrieved
This method is called to preserve the last current windowed position.
*/
virtual void getCurrentWindowPos(int& x, int& y) = 0;
virtual void updateWindowedPos() = 0;
/**
Clear the framebuffer.

View File

@ -233,9 +233,8 @@ void OSystem::loadConfig(const Settings::Options& options)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void OSystem::saveConfig()
{
// Save the current window position and display on system shutdown
int x, y;
myFrameBuffer->getCurrentWindowPos(x, y);
// Save the last windowed position and display on system shutdown
myFrameBuffer->updateWindowedPos();
settings().setValue("display", myFrameBuffer->getCurrentDisplayIndex());
// Ask all subsystems to save their settings