|
|
|
@ -57,7 +57,7 @@ Uint16 GetViewportHeight() |
|
|
|
namespace { |
|
|
|
namespace { |
|
|
|
|
|
|
|
|
|
|
|
#ifndef USE_SDL1 |
|
|
|
#ifndef USE_SDL1 |
|
|
|
void CalculatePreferdWindowSize(int &width, int &height) |
|
|
|
void CalculatePreferredWindowSize(int &width, int &height) |
|
|
|
{ |
|
|
|
{ |
|
|
|
SDL_DisplayMode mode; |
|
|
|
SDL_DisplayMode mode; |
|
|
|
if (SDL_GetDesktopDisplayMode(0, &mode) != 0) { |
|
|
|
if (SDL_GetDesktopDisplayMode(0, &mode) != 0) { |
|
|
|
@ -104,7 +104,7 @@ Size GetPreferredWindowSize() |
|
|
|
|
|
|
|
|
|
|
|
#ifndef USE_SDL1 |
|
|
|
#ifndef USE_SDL1 |
|
|
|
if (*sgOptions.Graphics.upscale && *sgOptions.Graphics.fitToScreen) { |
|
|
|
if (*sgOptions.Graphics.upscale && *sgOptions.Graphics.fitToScreen) { |
|
|
|
CalculatePreferdWindowSize(windowSize.width, windowSize.height); |
|
|
|
CalculatePreferredWindowSize(windowSize.width, windowSize.height); |
|
|
|
} |
|
|
|
} |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
AdjustToScreenGeometry(windowSize); |
|
|
|
AdjustToScreenGeometry(windowSize); |
|
|
|
@ -228,18 +228,18 @@ bool SpawnWindow(const char *lpWindowName) |
|
|
|
|
|
|
|
|
|
|
|
#ifdef USE_SDL1 |
|
|
|
#ifdef USE_SDL1 |
|
|
|
SDL_WM_SetCaption(lpWindowName, WINDOW_ICON_NAME); |
|
|
|
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) |
|
|
|
if (*sgOptions.Gameplay.grabInput) |
|
|
|
SDL_WM_GrabInput(SDL_GRAB_ON); |
|
|
|
SDL_WM_GrabInput(SDL_GRAB_ON); |
|
|
|
atexit(SDL_VideoQuit); // Without this video mode is not restored after fullscreen.
|
|
|
|
atexit(SDL_VideoQuit); // Without this video mode is not restored after fullscreen.
|
|
|
|
#else |
|
|
|
#else |
|
|
|
int flags = SDL_WINDOW_ALLOW_HIGHDPI; |
|
|
|
int flags = SDL_WINDOW_ALLOW_HIGHDPI; |
|
|
|
if (*sgOptions.Graphics.upscale) { |
|
|
|
if (*sgOptions.Graphics.upscale) { |
|
|
|
if (!gbForceWindowed && *sgOptions.Graphics.fullscreen) { |
|
|
|
if (*sgOptions.Graphics.fullscreen) { |
|
|
|
flags |= SDL_WINDOW_FULLSCREEN_DESKTOP; |
|
|
|
flags |= SDL_WINDOW_FULLSCREEN_DESKTOP; |
|
|
|
} |
|
|
|
} |
|
|
|
flags |= SDL_WINDOW_RESIZABLE; |
|
|
|
flags |= SDL_WINDOW_RESIZABLE; |
|
|
|
} else if (!gbForceWindowed && *sgOptions.Graphics.fullscreen) { |
|
|
|
} else if (*sgOptions.Graphics.fullscreen) { |
|
|
|
flags |= SDL_WINDOW_FULLSCREEN; |
|
|
|
flags |= SDL_WINDOW_FULLSCREEN; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -268,6 +268,7 @@ bool SpawnWindow(const char *lpWindowName) |
|
|
|
return ghMainWnd != nullptr; |
|
|
|
return ghMainWnd != nullptr; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef USE_SDL1 |
|
|
|
void ReinitializeTexture() |
|
|
|
void ReinitializeTexture() |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (texture) |
|
|
|
if (texture) |
|
|
|
@ -279,6 +280,19 @@ void ReinitializeTexture() |
|
|
|
texture = SDLWrap::CreateTexture(renderer, SDL_PIXELFORMAT_RGB888, SDL_TEXTUREACCESS_STREAMING, gnScreenWidth, gnScreenHeight); |
|
|
|
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() |
|
|
|
void ReinitializeRenderer() |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (ghMainWnd == nullptr) |
|
|
|
if (ghMainWnd == nullptr) |
|
|
|
@ -289,6 +303,9 @@ void ReinitializeRenderer() |
|
|
|
Size windowSize = { current.current_w, current.current_h }; |
|
|
|
Size windowSize = { current.current_w, current.current_h }; |
|
|
|
AdjustToScreenGeometry(windowSize); |
|
|
|
AdjustToScreenGeometry(windowSize); |
|
|
|
#else |
|
|
|
#else |
|
|
|
|
|
|
|
if (texture) |
|
|
|
|
|
|
|
texture.reset(); |
|
|
|
|
|
|
|
|
|
|
|
if (renderer != nullptr) { |
|
|
|
if (renderer != nullptr) { |
|
|
|
SDL_DestroyRenderer(renderer); |
|
|
|
SDL_DestroyRenderer(renderer); |
|
|
|
renderer = nullptr; |
|
|
|
renderer = nullptr; |
|
|
|
@ -322,7 +339,7 @@ void ReinitializeRenderer() |
|
|
|
|
|
|
|
|
|
|
|
ReinitializeTexture(); |
|
|
|
ReinitializeTexture(); |
|
|
|
|
|
|
|
|
|
|
|
if (*sgOptions.Graphics.integerScaling && SDL_RenderSetIntegerScale(renderer, SDL_TRUE) < 0) { |
|
|
|
if (SDL_RenderSetIntegerScale(renderer, *sgOptions.Graphics.integerScaling ? SDL_TRUE : SDL_FALSE) < 0) { |
|
|
|
ErrSdl(); |
|
|
|
ErrSdl(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -342,6 +359,34 @@ void ReinitializeRenderer() |
|
|
|
#endif |
|
|
|
#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() |
|
|
|
void ResizeWindow() |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (ghMainWnd == nullptr) |
|
|
|
if (ghMainWnd == nullptr) |
|
|
|
@ -350,25 +395,19 @@ void ResizeWindow() |
|
|
|
Size windowSize = GetPreferredWindowSize(); |
|
|
|
Size windowSize = GetPreferredWindowSize(); |
|
|
|
|
|
|
|
|
|
|
|
#ifdef USE_SDL1 |
|
|
|
#ifdef USE_SDL1 |
|
|
|
SetVideoModeToPrimary(!gbForceWindowed && *sgOptions.Graphics.fullscreen, windowSize.width, windowSize.height); |
|
|
|
SetVideoModeToPrimary(*sgOptions.Graphics.fullscreen, windowSize.width, windowSize.height); |
|
|
|
#else |
|
|
|
#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); |
|
|
|
SDL_SetWindowSize(ghMainWnd, windowSize.width, windowSize.height); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
ReinitializeRenderer(); |
|
|
|
ReinitializeRenderer(); |
|
|
|
dx_resize(); |
|
|
|
|
|
|
|
|
|
|
|
#ifndef USE_SDL1 |
|
|
|
|
|
|
|
SDL_SetWindowResizable(ghMainWnd, renderer != nullptr ? SDL_TRUE : SDL_FALSE); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CreateBackBuffer(); |
|
|
|
|
|
|
|
force_redraw = 255; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
SDL_Surface *GetOutputSurface() |
|
|
|
SDL_Surface *GetOutputSurface() |
|
|
|
|