Split up graphics settings initializers
This commit is contained in:
parent
0e2aac8cfe
commit
cf9b5ae79d
8 changed files with 93 additions and 82 deletions
|
|
@ -57,7 +57,7 @@ Uint16 GetViewportHeight()
|
|||
namespace {
|
||||
|
||||
#ifndef USE_SDL1
|
||||
void CalculatePreferdWindowSize(int &width, int &height)
|
||||
void CalculatePreferredWindowSize(int &width, int &height)
|
||||
{
|
||||
SDL_DisplayMode mode;
|
||||
if (SDL_GetDesktopDisplayMode(0, &mode) != 0) {
|
||||
|
|
@ -104,7 +104,7 @@ Size GetPreferredWindowSize()
|
|||
|
||||
#ifndef USE_SDL1
|
||||
if (*sgOptions.Graphics.upscale && *sgOptions.Graphics.fitToScreen) {
|
||||
CalculatePreferdWindowSize(windowSize.width, windowSize.height);
|
||||
CalculatePreferredWindowSize(windowSize.width, windowSize.height);
|
||||
}
|
||||
#endif
|
||||
AdjustToScreenGeometry(windowSize);
|
||||
|
|
@ -228,18 +228,18 @@ bool SpawnWindow(const char *lpWindowName)
|
|||
|
||||
#ifdef USE_SDL1
|
||||
SDL_WM_SetCaption(lpWindowName, WINDOW_ICON_NAME);
|
||||
SetVideoModeToPrimary(!gbForceWindowed && *sgOptions.Graphics.fullscreen, windowSize.width, windowSize.height);
|
||||
SetVideoModeToPrimary(*sgOptions.Graphics.fullscreen, windowSize.width, windowSize.height);
|
||||
if (*sgOptions.Gameplay.grabInput)
|
||||
SDL_WM_GrabInput(SDL_GRAB_ON);
|
||||
atexit(SDL_VideoQuit); // Without this video mode is not restored after fullscreen.
|
||||
#else
|
||||
int flags = SDL_WINDOW_ALLOW_HIGHDPI;
|
||||
if (*sgOptions.Graphics.upscale) {
|
||||
if (!gbForceWindowed && *sgOptions.Graphics.fullscreen) {
|
||||
if (*sgOptions.Graphics.fullscreen) {
|
||||
flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
|
||||
}
|
||||
flags |= SDL_WINDOW_RESIZABLE;
|
||||
} else if (!gbForceWindowed && *sgOptions.Graphics.fullscreen) {
|
||||
} else if (*sgOptions.Graphics.fullscreen) {
|
||||
flags |= SDL_WINDOW_FULLSCREEN;
|
||||
}
|
||||
|
||||
|
|
@ -268,6 +268,7 @@ bool SpawnWindow(const char *lpWindowName)
|
|||
return ghMainWnd != nullptr;
|
||||
}
|
||||
|
||||
#ifndef USE_SDL1
|
||||
void ReinitializeTexture()
|
||||
{
|
||||
if (texture)
|
||||
|
|
@ -279,6 +280,19 @@ void ReinitializeTexture()
|
|||
texture = SDLWrap::CreateTexture(renderer, SDL_PIXELFORMAT_RGB888, SDL_TEXTUREACCESS_STREAMING, gnScreenWidth, gnScreenHeight);
|
||||
}
|
||||
|
||||
void ReinitializeIntegerScale()
|
||||
{
|
||||
if (*sgOptions.Graphics.fitToScreen) {
|
||||
ResizeWindow();
|
||||
return;
|
||||
}
|
||||
|
||||
if (renderer != nullptr && SDL_RenderSetIntegerScale(renderer, *sgOptions.Graphics.integerScaling ? SDL_TRUE : SDL_FALSE) < 0) {
|
||||
ErrSdl();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void ReinitializeRenderer()
|
||||
{
|
||||
if (ghMainWnd == nullptr)
|
||||
|
|
@ -289,6 +303,9 @@ void ReinitializeRenderer()
|
|||
Size windowSize = { current.current_w, current.current_h };
|
||||
AdjustToScreenGeometry(windowSize);
|
||||
#else
|
||||
if (texture)
|
||||
texture.reset();
|
||||
|
||||
if (renderer != nullptr) {
|
||||
SDL_DestroyRenderer(renderer);
|
||||
renderer = nullptr;
|
||||
|
|
@ -322,7 +339,7 @@ void ReinitializeRenderer()
|
|||
|
||||
ReinitializeTexture();
|
||||
|
||||
if (*sgOptions.Graphics.integerScaling && SDL_RenderSetIntegerScale(renderer, SDL_TRUE) < 0) {
|
||||
if (SDL_RenderSetIntegerScale(renderer, *sgOptions.Graphics.integerScaling ? SDL_TRUE : SDL_FALSE) < 0) {
|
||||
ErrSdl();
|
||||
}
|
||||
|
||||
|
|
@ -342,6 +359,34 @@ void ReinitializeRenderer()
|
|||
#endif
|
||||
}
|
||||
|
||||
void SetFullscreenMode()
|
||||
{
|
||||
#ifdef USE_SDL1
|
||||
Uint32 flags = ghMainWnd->flags ^ SDL_FULLSCREEN;
|
||||
if (*sgOptions.Graphics.fullscreen) {
|
||||
flags |= SDL_FULLSCREEN;
|
||||
}
|
||||
ghMainWnd = SDL_SetVideoMode(0, 0, 0, flags);
|
||||
if (ghMainWnd == NULL) {
|
||||
ErrSdl();
|
||||
}
|
||||
#else
|
||||
Uint32 flags = 0;
|
||||
if (*sgOptions.Graphics.fullscreen) {
|
||||
flags = renderer != nullptr ? SDL_WINDOW_FULLSCREEN_DESKTOP : SDL_WINDOW_FULLSCREEN;
|
||||
}
|
||||
if (SDL_SetWindowFullscreen(ghMainWnd, flags) != 0) {
|
||||
ErrSdl();
|
||||
}
|
||||
if (renderer != nullptr && !*sgOptions.Graphics.fullscreen) {
|
||||
SDL_RestoreWindow(ghMainWnd); // Avoid window being maximized before resizing
|
||||
Size windowSize = GetPreferredWindowSize();
|
||||
SDL_SetWindowSize(ghMainWnd, windowSize.width, windowSize.height);
|
||||
}
|
||||
#endif
|
||||
force_redraw = 255;
|
||||
}
|
||||
|
||||
void ResizeWindow()
|
||||
{
|
||||
if (ghMainWnd == nullptr)
|
||||
|
|
@ -350,25 +395,19 @@ void ResizeWindow()
|
|||
Size windowSize = GetPreferredWindowSize();
|
||||
|
||||
#ifdef USE_SDL1
|
||||
SetVideoModeToPrimary(!gbForceWindowed && *sgOptions.Graphics.fullscreen, windowSize.width, windowSize.height);
|
||||
SetVideoModeToPrimary(*sgOptions.Graphics.fullscreen, windowSize.width, windowSize.height);
|
||||
#else
|
||||
int flags = 0;
|
||||
if (*sgOptions.Graphics.upscale) {
|
||||
if (!gbForceWindowed && *sgOptions.Graphics.fullscreen) {
|
||||
flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
|
||||
}
|
||||
SDL_SetWindowResizable(ghMainWnd, SDL_TRUE);
|
||||
} else if (!gbForceWindowed && *sgOptions.Graphics.fullscreen) {
|
||||
flags |= SDL_WINDOW_FULLSCREEN;
|
||||
SDL_SetWindowResizable(ghMainWnd, SDL_FALSE);
|
||||
}
|
||||
SDL_SetWindowFullscreen(ghMainWnd, flags);
|
||||
|
||||
SDL_SetWindowSize(ghMainWnd, windowSize.width, windowSize.height);
|
||||
#endif
|
||||
|
||||
ReinitializeRenderer();
|
||||
dx_resize();
|
||||
|
||||
#ifndef USE_SDL1
|
||||
SDL_SetWindowResizable(ghMainWnd, renderer != nullptr ? SDL_TRUE : SDL_FALSE);
|
||||
#endif
|
||||
|
||||
CreateBackBuffer();
|
||||
force_redraw = 255;
|
||||
}
|
||||
|
||||
SDL_Surface *GetOutputSurface()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue