This commit is contained in:
WaywardHeart 2025-03-19 18:26:57 -03:00 committed by GitHub
commit 734c90d172
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 59 additions and 5 deletions

View file

@ -1717,7 +1717,19 @@ double Graphics::getScale() const {
void Graphics::setScale(double factor) {
p->threadData->rqWindowAdjust.wait();
factor = clamp(factor, 0.5, 4.0);
int displayIndex = SDL_GetWindowDisplayIndex(shState->sdlWindow());
SDL_Rect displayRect;
SDL_GetDisplayUsableBounds(displayIndex, &displayRect);
int top, bottom, left, right;
SDL_GetWindowBordersSize(shState->sdlWindow(), &top, &bottom, &left, &right);
double maxWidth = displayRect.w;
double maxHeight = displayRect.h - top;
double maxScale = std::min(maxWidth / p->scRes.x, maxHeight / p->scRes.y);
factor = clamp(factor, 0.5, maxScale);
if (factor == getScale())
return;

View file

@ -491,10 +491,30 @@ void EventThread::process(RGSSThreadData &rtData)
break;
case REQUEST_WINRESIZE :
SDL_SetWindowSize(win, event.window.data1, event.window.data2);
{
int displayIndex = SDL_GetWindowDisplayIndex(shState->sdlWindow());
SDL_Rect displayRect;
SDL_GetDisplayUsableBounds(displayIndex, &displayRect);
int top, bottom, left, right;
SDL_GetWindowBordersSize(shState->sdlWindow(), &top, &bottom, &left, &right);
int maxWidth = displayRect.w;
int maxHeight = displayRect.h - top;
int x, y;
SDL_GetWindowPosition(win, &x, &y);
int newWidth = std::min(event.window.data1, maxWidth);
int newHeight = std::min(event.window.data2, maxHeight);
SDL_SetWindowSize(win, newWidth, newHeight);
// Adjust the position to have the same center,
// but don't let it go past the top of the screen.
SDL_SetWindowPosition(win,
x + ((winW - newWidth)/2),
std::max(y + ((winH - newHeight)/2), displayRect.y + top));
rtData.rqWindowAdjust.clear();
break;
}
case REQUEST_WINREPOSITION :
SDL_SetWindowPosition(win, event.window.data1, event.window.data2);
rtData.rqWindowAdjust.clear();
@ -503,9 +523,16 @@ void EventThread::process(RGSSThreadData &rtData)
case REQUEST_WINCENTER :
rc = SDL_GetDesktopDisplayMode(SDL_GetWindowDisplayIndex(win), &dm);
if (!rc)
{
int displayIndex = SDL_GetWindowDisplayIndex(shState->sdlWindow());
SDL_Rect displayRect;
SDL_GetDisplayUsableBounds(displayIndex, &displayRect);
int top, bottom, left, right;
SDL_GetWindowBordersSize(shState->sdlWindow(), &top, &bottom, &left, &right);
SDL_SetWindowPosition(win,
(dm.w / 2) - (winW / 2),
(dm.h / 2) - (winH / 2));
displayRect.x + ((displayRect.w - winW) / 2),
displayRect.y + ((displayRect.h + top - winH) / 2));
}
rtData.rqWindowAdjust.clear();
break;

View file

@ -427,6 +427,21 @@ int main(int argc, char *argv[]) {
int winW, winH, drwW, drwH;
SDL_GetWindowSize(win, &winW, &winH);
int displayIndex = SDL_GetWindowDisplayIndex(win);
SDL_Rect displayRect;
SDL_GetDisplayUsableBounds(displayIndex, &displayRect);
int top, bottom, left, right;
SDL_GetWindowBordersSize(win, &top, &bottom, &left, &right);
int maxWidth = displayRect.w;
int maxHeight = displayRect.h - top;
winW = std::min(winW, maxWidth);
winH = std::min(winH, maxHeight);
SDL_SetWindowSize(win, winW, winH);
SDL_SetWindowPosition(win,
displayRect.x + ((displayRect.w - winW) / 2),
displayRect.y + ((displayRect.h + top - winH) / 2));
rtData.windowSizeMsg.post(Vec2i(winW, winH));
SDL_GL_GetDrawableSize(win, &drwW, &drwH);