Window Mode Centered on Screen
I saw a lot of posts about the wrong window position (7-pixel offset and similar bugs), but none of them actually fixed it for me.
So I wrote a quick and clean solution — simple but works 100%.
Code is wrapped in
#ifdef ENABLE_WINDOW_START_CENTER_FRATELLO
so you can toggle it easily.
Windowed mode: starts centered on the screen
Fullscreen: starts at (0, 0)
Without define: keeps the default behavior (bAnotherWindow bottom-right)
Nothing fancy, just practical saved me some time, maybe it’ll save yours too.
Step 1:
defines.h / locale_inc.h
#define ENABLE_WINDOW_START_CENTER_FRATELLO
Step 2:
SEARCH
Userinterface/Pythonapplication.cpp
if (Windowed)
{
m_isWindowed = true;
if (bAnotherWindow)
{
RECT rc;
GetClientRect(&rc);
int windowWidth = rc.right - rc.left;
int windowHeight = (rc.bottom - rc.top);
CMSApplication::SetPosition(GetScreenWidth() - windowWidth, GetScreenHeight() - 60 - windowHeight);
}
}
else
{
m_isWindowed = false;
SetPosition(0, 0);
}
Step 3:
replace
#ifdef ENABLE_WINDOW_START_CENTER_FRATELLO
if (Windowed)
{
m_isWindowed = true;
RECT rcScreen;
::GetWindowRect(GetDesktopWindow(), &rcScreen);
int screenW = rcScreen.right - rcScreen.left;
int screenH = rcScreen.bottom - rcScreen.top;
RECT rcWindow;
::GetWindowRect(GetWindowHandle(), &rcWindow);
int windowW = rcWindow.right - rcWindow.left;
int windowH = rcWindow.bottom - rcWindow.top;
int posX = (screenW - windowW) / 2;
int posY = (screenH - windowH) / 2;
SetPosition(posX, posY);
}
else
{
m_isWindowed = false;
SetPosition(0, 0);
}
#else
if (Windowed)
{
m_isWindowed = true;
if (bAnotherWindow)
{
RECT rc;
GetClientRect(&rc);
int windowWidth = rc.right - rc.left;
int windowHeight = (rc.bottom - rc.top);
CMSApplication::SetPosition(GetScreenWidth() - windowWidth, GetScreenHeight() - 60 - windowHeight);
}
}
else
{
m_isWindowed = false;
SetPosition(0, 0);
}
#endif
FINISH