Fixed bug 1167 (SDL_WINDOWPOS_CENTERED doesn't work if used right after fullscreen -> windowed switch)
The top level code handles SDL_WINDOWPOS_CENTERED now, and the Cocoa SetWindowPosition call will clear the moveHack before adjusting the window position.
This commit is contained in:
parent
06a33455ca
commit
0eb0a30eca
5 changed files with 27 additions and 65 deletions
|
@ -1413,6 +1413,20 @@ SDL_SetWindowPosition(SDL_Window * window, int x, int y)
|
|||
if (!SDL_WINDOWPOS_ISUNDEFINED(y)) {
|
||||
window->y = y;
|
||||
}
|
||||
if (SDL_WINDOWPOS_ISCENTERED(x) || SDL_WINDOWPOS_ISCENTERED(y)) {
|
||||
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
|
||||
int displayIndex;
|
||||
SDL_Rect bounds;
|
||||
|
||||
displayIndex = SDL_GetIndexOfDisplay(display);
|
||||
SDL_GetDisplayBounds(displayIndex, &bounds);
|
||||
if (SDL_WINDOWPOS_ISCENTERED(x)) {
|
||||
window->x = bounds.x + (bounds.w - window->w) / 2;
|
||||
}
|
||||
if (SDL_WINDOWPOS_ISCENTERED(y)) {
|
||||
window->y = bounds.y + (bounds.h - window->h) / 2;
|
||||
}
|
||||
}
|
||||
if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
|
||||
if (_this->SetWindowPosition) {
|
||||
_this->SetWindowPosition(_this, window);
|
||||
|
|
|
@ -670,26 +670,20 @@ Cocoa_SetWindowPosition(_THIS, SDL_Window * window)
|
|||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
|
||||
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
|
||||
NSRect rect;
|
||||
SDL_Rect bounds;
|
||||
Uint32 moveHack;
|
||||
|
||||
Cocoa_GetDisplayBounds(_this, display, &bounds);
|
||||
if (SDL_WINDOWPOS_ISCENTERED(window->x)) {
|
||||
rect.origin.x = bounds.x + (bounds.w - window->w) / 2;
|
||||
} else {
|
||||
rect.origin.x = window->x;
|
||||
}
|
||||
if (SDL_WINDOWPOS_ISCENTERED(window->y)) {
|
||||
rect.origin.y = bounds.y + (bounds.h - window->h) / 2;
|
||||
} else {
|
||||
rect.origin.y = window->y;
|
||||
}
|
||||
rect.size.width = window->w;
|
||||
rect.size.height = window->h;
|
||||
ConvertNSRect(&rect);
|
||||
rect = [nswindow frameRectForContentRect:rect];
|
||||
|
||||
moveHack = s_moveHack;
|
||||
s_moveHack = 0;
|
||||
[nswindow setFrameOrigin:rect.origin];
|
||||
s_moveHack = moveHack;
|
||||
|
||||
[pool release];
|
||||
}
|
||||
|
||||
|
|
|
@ -260,29 +260,11 @@ void
|
|||
DirectFB_SetWindowPosition(_THIS, SDL_Window * window)
|
||||
{
|
||||
SDL_DFB_WINDOWDATA(window);
|
||||
SDL_DFB_DISPLAYDATA(window);
|
||||
int x, y;
|
||||
|
||||
if (SDL_WINDOWPOS_ISCENTERED(window->x)) {
|
||||
x = (dispdata->cw - window->w) / 2;
|
||||
} else if (SDL_WINDOWPOS_ISUNDEFINED(window->x)) {
|
||||
x = 0;
|
||||
} else {
|
||||
x = window->x;
|
||||
}
|
||||
|
||||
if (SDL_WINDOWPOS_ISCENTERED(window->y)) {
|
||||
y = (dispdata->ch - window->h) / 2;
|
||||
} else if (SDL_WINDOWPOS_ISUNDEFINED(window->y)) {
|
||||
y = 0;
|
||||
} else {
|
||||
y = window->y;
|
||||
}
|
||||
|
||||
if (window->flags & SDL_WINDOW_FULLSCREEN) {
|
||||
x = 0;
|
||||
y = 0;
|
||||
}
|
||||
DirectFB_WM_AdjustWindowLayout(window, window->flags, window->w, window->h);
|
||||
SDL_DFB_CHECK(windata->dfbwin->MoveTo(windata->dfbwin, x, y));
|
||||
}
|
||||
|
|
|
@ -371,18 +371,8 @@ WIN_SetWindowPosition(_THIS, SDL_Window * window)
|
|||
AdjustWindowRectEx(&rect, style, menu, 0);
|
||||
w = (rect.right - rect.left);
|
||||
h = (rect.bottom - rect.top);
|
||||
|
||||
WIN_GetDisplayBounds(_this, display, &bounds);
|
||||
if (SDL_WINDOWPOS_ISCENTERED(window->x)) {
|
||||
x = bounds.x + (bounds.w - w) / 2;
|
||||
} else {
|
||||
x = window->x + rect.left;
|
||||
}
|
||||
if (SDL_WINDOWPOS_ISCENTERED(window->y)) {
|
||||
y = bounds.y + (bounds.h - h) / 2;
|
||||
} else {
|
||||
y = window->y + rect.top;
|
||||
}
|
||||
|
||||
SetWindowPos(hwnd, top, x, y, 0, 0, (SWP_NOCOPYBITS | SWP_NOSIZE));
|
||||
}
|
||||
|
|
|
@ -756,27 +756,9 @@ X11_SetWindowPosition(_THIS, SDL_Window * window)
|
|||
{
|
||||
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
|
||||
Display *display = data->videodata->display;
|
||||
SDL_bool oldstyle_fullscreen;
|
||||
int x, y;
|
||||
|
||||
/* ICCCM2.0-compliant window managers can handle fullscreen windows */
|
||||
oldstyle_fullscreen = X11_IsWindowOldFullscreen(_this, window);
|
||||
|
||||
if (oldstyle_fullscreen
|
||||
|| SDL_WINDOWPOS_ISCENTERED(window->x)) {
|
||||
X11_GetDisplaySize(_this, window, &x, NULL);
|
||||
x = (x - window->w) / 2;
|
||||
} else {
|
||||
x = window->x;
|
||||
}
|
||||
if (oldstyle_fullscreen
|
||||
|| SDL_WINDOWPOS_ISCENTERED(window->y)) {
|
||||
X11_GetDisplaySize(_this, window, NULL, &y);
|
||||
y = (y - window->h) / 2;
|
||||
} else {
|
||||
y = window->y;
|
||||
}
|
||||
XMoveWindow(display, data->xwindow, x, y);
|
||||
XMoveWindow(display, data->xwindow, window->x, window->y);
|
||||
XFlush(display);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue