mirror of
https://github.com/hedge-dev/UnleashedRecomp.git
synced 2025-10-30 07:11:05 +00:00
window: use SDL flags to determine centred window config
This commit is contained in:
parent
3c4a8f5ee5
commit
f96b2ad16c
4 changed files with 32 additions and 17 deletions
|
|
@ -26,8 +26,8 @@ public:
|
||||||
CONFIG_DEFINE("Audio", bool, WerehogBattleMusic, true);
|
CONFIG_DEFINE("Audio", bool, WerehogBattleMusic, true);
|
||||||
|
|
||||||
CONFIG_DEFINE_ENUM("Video", EGraphicsAPI, GraphicsAPI, EGraphicsAPI::D3D12);
|
CONFIG_DEFINE_ENUM("Video", EGraphicsAPI, GraphicsAPI, EGraphicsAPI::D3D12);
|
||||||
CONFIG_DEFINE_HIDE("Video", int32_t, WindowX, -1);
|
CONFIG_DEFINE_HIDE("Video", int32_t, WindowX, WINDOWPOS_CENTRED);
|
||||||
CONFIG_DEFINE_HIDE("Video", int32_t, WindowY, -1);
|
CONFIG_DEFINE_HIDE("Video", int32_t, WindowY, WINDOWPOS_CENTRED);
|
||||||
CONFIG_DEFINE("Video", int32_t, WindowWidth, 1280);
|
CONFIG_DEFINE("Video", int32_t, WindowWidth, 1280);
|
||||||
CONFIG_DEFINE("Video", int32_t, WindowHeight, 720);
|
CONFIG_DEFINE("Video", int32_t, WindowHeight, 720);
|
||||||
CONFIG_DEFINE_ENUM_HIDE("Video", EWindowState, WindowState, EWindowState::Normal);
|
CONFIG_DEFINE_ENUM_HIDE("Video", EWindowState, WindowState, EWindowState::Normal);
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,8 @@
|
||||||
#define CONFIG_GET_DEFAULT(name) Config::name.DefaultValue
|
#define CONFIG_GET_DEFAULT(name) Config::name.DefaultValue
|
||||||
#define CONFIG_SET_DEFAULT(name) Config::name.MakeDefault();
|
#define CONFIG_SET_DEFAULT(name) Config::name.MakeDefault();
|
||||||
|
|
||||||
|
#define WINDOWPOS_CENTRED 0x2FFF0000
|
||||||
|
|
||||||
class ConfigDefBase
|
class ConfigDefBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,17 @@ int Window_OnSDLEvent(void*, SDL_Event* event)
|
||||||
Config::Fullscreen = Window::SetFullscreen(false);
|
Config::Fullscreen = Window::SetFullscreen(false);
|
||||||
Window::SetDimensions(SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, DEFAULT_WIDTH, DEFAULT_HEIGHT);
|
Window::SetDimensions(SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, DEFAULT_WIDTH, DEFAULT_HEIGHT);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
// Recentre window on F3.
|
||||||
|
case SDLK_F3:
|
||||||
|
{
|
||||||
|
if (Window::IsFullscreen())
|
||||||
|
break;
|
||||||
|
|
||||||
|
Window::SetDimensions(SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, Window::s_width, Window::s_height);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
@ -128,28 +139,21 @@ void Window::Init()
|
||||||
s_width = Config::WindowWidth;
|
s_width = Config::WindowWidth;
|
||||||
s_height = Config::WindowHeight;
|
s_height = Config::WindowHeight;
|
||||||
|
|
||||||
auto isPositionValid = IsPositionValid();
|
if (!IsPositionValid())
|
||||||
|
|
||||||
if (!isPositionValid)
|
|
||||||
{
|
{
|
||||||
s_x = SDL_WINDOWPOS_CENTERED;
|
s_x = SDL_WINDOWPOS_CENTERED;
|
||||||
s_y = SDL_WINDOWPOS_CENTERED;
|
s_y = SDL_WINDOWPOS_CENTERED;
|
||||||
s_width = DEFAULT_WIDTH;
|
s_width = DEFAULT_WIDTH;
|
||||||
s_height = DEFAULT_HEIGHT;
|
s_height = DEFAULT_HEIGHT;
|
||||||
|
|
||||||
|
Config::WindowX = s_x;
|
||||||
|
Config::WindowY = s_y;
|
||||||
|
Config::WindowWidth = s_width;
|
||||||
|
Config::WindowHeight = s_height;
|
||||||
}
|
}
|
||||||
|
|
||||||
s_pWindow = SDL_CreateWindow("SWA", s_x, s_y, s_width, s_height, GetWindowFlags());
|
s_pWindow = SDL_CreateWindow("SWA", s_x, s_y, s_width, s_height, GetWindowFlags());
|
||||||
|
|
||||||
if (!isPositionValid)
|
|
||||||
{
|
|
||||||
auto rect = Window::GetDimensions();
|
|
||||||
|
|
||||||
Config::WindowX = rect.x;
|
|
||||||
Config::WindowY = rect.y;
|
|
||||||
Config::WindowWidth = rect.w;
|
|
||||||
Config::WindowHeight = rect.h;
|
|
||||||
}
|
|
||||||
|
|
||||||
SetIcon();
|
SetIcon();
|
||||||
SetTitle();
|
SetTitle();
|
||||||
SDL_SetWindowMinimumSize(s_pWindow, 640, 480);
|
SDL_SetWindowMinimumSize(s_pWindow, 640, 480);
|
||||||
|
|
|
||||||
|
|
@ -148,8 +148,17 @@ public:
|
||||||
SDL_Rect bounds;
|
SDL_Rect bounds;
|
||||||
if (SDL_GetDisplayBounds(i, &bounds) == 0)
|
if (SDL_GetDisplayBounds(i, &bounds) == 0)
|
||||||
{
|
{
|
||||||
if (s_x >= bounds.x && s_x < bounds.x + bounds.w &&
|
auto x = s_x;
|
||||||
s_y >= bounds.y && s_y < bounds.y + bounds.h)
|
auto y = s_y;
|
||||||
|
|
||||||
|
if (x == SDL_WINDOWPOS_CENTERED)
|
||||||
|
x = bounds.w / 2 - s_width / 2;
|
||||||
|
|
||||||
|
if (y == SDL_WINDOWPOS_CENTERED)
|
||||||
|
y = bounds.h / 2 - s_height / 2;
|
||||||
|
|
||||||
|
if (x >= bounds.x && x < bounds.x + bounds.w &&
|
||||||
|
y >= bounds.y && y < bounds.y + bounds.h)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue