mirror of
https://github.com/mkxp-z/mkxp-z.git
synced 2025-04-21 21:52:04 +02:00
Merge 15a7b8e40c
into 68a344afcf
This commit is contained in:
commit
734c90d172
3 changed files with 59 additions and 5 deletions
|
@ -1717,7 +1717,19 @@ double Graphics::getScale() const {
|
||||||
|
|
||||||
void Graphics::setScale(double factor) {
|
void Graphics::setScale(double factor) {
|
||||||
p->threadData->rqWindowAdjust.wait();
|
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())
|
if (factor == getScale())
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -491,10 +491,30 @@ void EventThread::process(RGSSThreadData &rtData)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case REQUEST_WINRESIZE :
|
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();
|
rtData.rqWindowAdjust.clear();
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case REQUEST_WINREPOSITION :
|
case REQUEST_WINREPOSITION :
|
||||||
SDL_SetWindowPosition(win, event.window.data1, event.window.data2);
|
SDL_SetWindowPosition(win, event.window.data1, event.window.data2);
|
||||||
rtData.rqWindowAdjust.clear();
|
rtData.rqWindowAdjust.clear();
|
||||||
|
@ -503,9 +523,16 @@ void EventThread::process(RGSSThreadData &rtData)
|
||||||
case REQUEST_WINCENTER :
|
case REQUEST_WINCENTER :
|
||||||
rc = SDL_GetDesktopDisplayMode(SDL_GetWindowDisplayIndex(win), &dm);
|
rc = SDL_GetDesktopDisplayMode(SDL_GetWindowDisplayIndex(win), &dm);
|
||||||
if (!rc)
|
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,
|
SDL_SetWindowPosition(win,
|
||||||
(dm.w / 2) - (winW / 2),
|
displayRect.x + ((displayRect.w - winW) / 2),
|
||||||
(dm.h / 2) - (winH / 2));
|
displayRect.y + ((displayRect.h + top - winH) / 2));
|
||||||
|
}
|
||||||
rtData.rqWindowAdjust.clear();
|
rtData.rqWindowAdjust.clear();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
15
src/main.cpp
15
src/main.cpp
|
@ -427,6 +427,21 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
int winW, winH, drwW, drwH;
|
int winW, winH, drwW, drwH;
|
||||||
SDL_GetWindowSize(win, &winW, &winH);
|
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));
|
rtData.windowSizeMsg.post(Vec2i(winW, winH));
|
||||||
|
|
||||||
SDL_GL_GetDrawableSize(win, &drwW, &drwH);
|
SDL_GL_GetDrawableSize(win, &drwW, &drwH);
|
||||||
|
|
Loading…
Add table
Reference in a new issue