mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2024-12-23 01:59:43 +01:00
Persist windowed mode size through fullscreen mode
Previously, the game would not store the size of the window itself, and would always call SDL_GetRendererOutputSize() (via Screen::GetWindowSize()) to figure out the size of the window. The only problem is, this would return the size of the whole monitor if the game was in fullscreen mode. And the only place where the original windowed mode size was stored would be in SDL itself, but that wouldn't persist after the game was closed. So, if you exited the game while in fullscreen mode, then your window size would get set to the size of your monitor (1920 by 1080 in my case). Then when you opened the game and toggled fullscreen off, it would go back to the default window size, which is 640 by 480. This is made worse, however, if you were in forced fullscreen mode when you previously exited the game in windowed mode. In that case, the game saves the size of 1920 by 1080, but doesn't save that you were in fullscreen mode, so opening the game not in forced fullscreen mode would result in you having a 1920 by 1080 window, but in windowed mode. Meaning that not even fullscreening and unfullscreening would put the game window back to normal size. The solution, of course, is to just store the window size ourselves, like any other screen setting, and only use GetWindowSize() if needed. And just to make things clear, I've also renamed the GetWindowSize() function to GetScreenSize(), because if it was named "window" it could lead one to think that it would always return the size of the screen in windowed mode, when in fact it returns the size of the screen whatever mode it is in - fullscreen size if in fullscreen mode and window size if in windowed mode. And doing this also fixes the FIXME above Screen::isForcedFullscreen().
This commit is contained in:
parent
e1e9e47d95
commit
54990638fd
3 changed files with 20 additions and 24 deletions
|
@ -2073,10 +2073,10 @@ void editorinput(void)
|
||||||
ed.tiley=(game.my - (game.my%8))/8;
|
ed.tiley=(game.my - (game.my%8))/8;
|
||||||
if (gameScreen.scalingMode == SCALING_STRETCH) {
|
if (gameScreen.scalingMode == SCALING_STRETCH) {
|
||||||
// In this mode specifically, we have to fix the mouse coordinates
|
// In this mode specifically, we have to fix the mouse coordinates
|
||||||
int winwidth, winheight;
|
int screenwidth, screenheight;
|
||||||
gameScreen.GetWindowSize(&winwidth, &winheight);
|
gameScreen.GetScreenSize(&screenwidth, &screenheight);
|
||||||
ed.tilex = ed.tilex * 320 / winwidth;
|
ed.tilex = ed.tilex * 320 / screenwidth;
|
||||||
ed.tiley = ed.tiley * 240 / winheight;
|
ed.tiley = ed.tiley * 240 / screenheight;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool up_pressed = key.isDown(SDLK_UP) || key.isDown(SDL_CONTROLLER_BUTTON_DPAD_UP);
|
bool up_pressed = key.isDown(SDLK_UP) || key.isDown(SDL_CONTROLLER_BUTTON_DPAD_UP);
|
||||||
|
|
|
@ -29,9 +29,12 @@ void Screen::init(const struct ScreenSettings* settings)
|
||||||
{
|
{
|
||||||
m_window = NULL;
|
m_window = NULL;
|
||||||
m_renderer = NULL;
|
m_renderer = NULL;
|
||||||
|
windowWidth = settings->windowWidth;
|
||||||
|
windowHeight = settings->windowHeight;
|
||||||
isWindowed = !settings->fullscreen;
|
isWindowed = !settings->fullscreen;
|
||||||
scalingMode = settings->scalingMode;
|
scalingMode = settings->scalingMode;
|
||||||
isFiltered = settings->linearFilter;
|
isFiltered = settings->linearFilter;
|
||||||
|
badSignalEffect = settings->badSignal;
|
||||||
vsync = settings->useVsync;
|
vsync = settings->useVsync;
|
||||||
|
|
||||||
SDL_SetHintWithPriority(
|
SDL_SetHintWithPriority(
|
||||||
|
@ -86,9 +89,7 @@ void Screen::init(const struct ScreenSettings* settings)
|
||||||
|
|
||||||
LoadIcon();
|
LoadIcon();
|
||||||
|
|
||||||
badSignalEffect = settings->badSignal;
|
ResizeScreen(windowWidth, windowHeight);
|
||||||
|
|
||||||
ResizeScreen(settings->windowWidth, settings->windowHeight);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Screen::destroy(void)
|
void Screen::destroy(void)
|
||||||
|
@ -100,11 +101,8 @@ void Screen::destroy(void)
|
||||||
|
|
||||||
void Screen::GetSettings(struct ScreenSettings* settings)
|
void Screen::GetSettings(struct ScreenSettings* settings)
|
||||||
{
|
{
|
||||||
int width, height;
|
settings->windowWidth = windowWidth;
|
||||||
GetWindowSize(&width, &height);
|
settings->windowHeight = windowHeight;
|
||||||
|
|
||||||
settings->windowWidth = width;
|
|
||||||
settings->windowHeight = height;
|
|
||||||
|
|
||||||
settings->fullscreen = !isWindowed;
|
settings->fullscreen = !isWindowed;
|
||||||
settings->useVsync = vsync;
|
settings->useVsync = vsync;
|
||||||
|
@ -136,13 +134,11 @@ void Screen::LoadIcon(void)
|
||||||
|
|
||||||
void Screen::ResizeScreen(int x, int y)
|
void Screen::ResizeScreen(int x, int y)
|
||||||
{
|
{
|
||||||
static int resX = SCREEN_WIDTH_PIXELS;
|
|
||||||
static int resY = SCREEN_HEIGHT_PIXELS;
|
|
||||||
if (x != -1 && y != -1)
|
if (x != -1 && y != -1)
|
||||||
{
|
{
|
||||||
// This is a user resize!
|
// This is a user resize!
|
||||||
resX = x;
|
windowWidth = x;
|
||||||
resY = y;
|
windowHeight = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isWindowed || isForcedFullscreen())
|
if (!isWindowed || isForcedFullscreen())
|
||||||
|
@ -166,7 +162,7 @@ void Screen::ResizeScreen(int x, int y)
|
||||||
}
|
}
|
||||||
if (x != -1 && y != -1)
|
if (x != -1 && y != -1)
|
||||||
{
|
{
|
||||||
SDL_SetWindowSize(m_window, resX, resY);
|
SDL_SetWindowSize(m_window, windowWidth, windowHeight);
|
||||||
SDL_SetWindowPosition(m_window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
|
SDL_SetWindowPosition(m_window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -175,7 +171,7 @@ void Screen::ResizeScreen(int x, int y)
|
||||||
void Screen::ResizeToNearestMultiple(void)
|
void Screen::ResizeToNearestMultiple(void)
|
||||||
{
|
{
|
||||||
int w, h;
|
int w, h;
|
||||||
GetWindowSize(&w, &h);
|
GetScreenSize(&w, &h);
|
||||||
|
|
||||||
// Check aspect ratio first
|
// Check aspect ratio first
|
||||||
bool using_width;
|
bool using_width;
|
||||||
|
@ -229,7 +225,7 @@ void Screen::ResizeToNearestMultiple(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Screen::GetWindowSize(int* x, int* y)
|
void Screen::GetScreenSize(int* x, int* y)
|
||||||
{
|
{
|
||||||
if (SDL_GetRendererOutputSize(m_renderer, x, y) != 0)
|
if (SDL_GetRendererOutputSize(m_renderer, x, y) != 0)
|
||||||
{
|
{
|
||||||
|
@ -246,7 +242,7 @@ void Screen::UpdateScaling(void)
|
||||||
int height;
|
int height;
|
||||||
if (scalingMode == SCALING_STRETCH)
|
if (scalingMode == SCALING_STRETCH)
|
||||||
{
|
{
|
||||||
GetWindowSize(&width, &height);
|
GetScreenSize(&width, &height);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -280,7 +276,7 @@ void Screen::RenderPresent(void)
|
||||||
void Screen::toggleFullScreen(void)
|
void Screen::toggleFullScreen(void)
|
||||||
{
|
{
|
||||||
isWindowed = !isWindowed;
|
isWindowed = !isWindowed;
|
||||||
ResizeScreen(-1, -1);
|
ResizeScreen(windowWidth, windowHeight);
|
||||||
|
|
||||||
if (game.currentmenuname == Menu::graphicoptions)
|
if (game.currentmenuname == Menu::graphicoptions)
|
||||||
{
|
{
|
||||||
|
@ -348,8 +344,6 @@ void Screen::recacheTextures(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* FIXME: Launching in forced fullscreen then exiting and relaunching in normal
|
|
||||||
* mode will result in the window having fullscreen size but being windowed. */
|
|
||||||
bool Screen::isForcedFullscreen(void)
|
bool Screen::isForcedFullscreen(void)
|
||||||
{
|
{
|
||||||
/* This is just a check to see if we're on a desktop or tenfoot setup.
|
/* This is just a check to see if we're on a desktop or tenfoot setup.
|
||||||
|
|
|
@ -17,7 +17,7 @@ public:
|
||||||
|
|
||||||
void ResizeScreen(int x, int y);
|
void ResizeScreen(int x, int y);
|
||||||
void ResizeToNearestMultiple(void);
|
void ResizeToNearestMultiple(void);
|
||||||
void GetWindowSize(int* x, int* y);
|
void GetScreenSize(int* x, int* y);
|
||||||
|
|
||||||
void UpdateScaling(void);
|
void UpdateScaling(void);
|
||||||
void RenderPresent(void);
|
void RenderPresent(void);
|
||||||
|
@ -31,6 +31,8 @@ public:
|
||||||
|
|
||||||
bool isForcedFullscreen(void);
|
bool isForcedFullscreen(void);
|
||||||
|
|
||||||
|
int windowWidth;
|
||||||
|
int windowHeight;
|
||||||
bool isWindowed;
|
bool isWindowed;
|
||||||
bool isFiltered;
|
bool isFiltered;
|
||||||
bool badSignalEffect;
|
bool badSignalEffect;
|
||||||
|
|
Loading…
Reference in a new issue