Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
The window position is display relative, at least for now...
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Dec 6, 2009
1 parent 0d71b13 commit 3e5f8f1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
17 changes: 10 additions & 7 deletions src/video/cocoa/SDL_cocoawindow.m
Expand Up @@ -298,7 +298,8 @@ - (BOOL)canBecomeMainWindow
{
NSAutoreleasePool *pool;
SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
SDL_DisplayData *displaydata = (SDL_DisplayData *) SDL_GetDisplayFromWindow(window)->driverdata;
SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
SDL_DisplayData *displaydata = (SDL_DisplayData *) display->driverdata;
SDL_WindowData *data;

/* Allocate the window data */
Expand All @@ -321,10 +322,12 @@ - (BOOL)canBecomeMainWindow

/* Fill in the SDL window with the window data */
{
SDL_Rect bounds;
NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
ConvertNSRect(&rect);
window->x = (int)rect.origin.x;
window->y = (int)rect.origin.y;
Cocoa_GetDisplayBounds(_this, display, &bounds);
window->x = (int)rect.origin.x - bounds.x;
window->y = (int)rect.origin.y - bounds.y;
window->w = (int)rect.size.width;
window->h = (int)rect.size.height;
}
Expand Down Expand Up @@ -392,15 +395,15 @@ - (BOOL)canBecomeMainWindow
} else if (window->x == SDL_WINDOWPOS_UNDEFINED) {
rect.origin.x = bounds.x;
} else {
rect.origin.x = window->x;
rect.origin.x = bounds.x + window->x;
}
if ((window->flags & SDL_WINDOW_FULLSCREEN)
|| window->y == SDL_WINDOWPOS_CENTERED) {
rect.origin.y = bounds.y + (bounds.h - window->h) / 2;
} else if (window->x == SDL_WINDOWPOS_UNDEFINED) {
rect.origin.y = bounds.y;
} else {
rect.origin.y = window->y;
rect.origin.y = bounds.y + window->y;
}
rect.size.width = window->w;
rect.size.height = window->h;
Expand Down Expand Up @@ -496,13 +499,13 @@ - (BOOL)canBecomeMainWindow
|| window->x == SDL_WINDOWPOS_CENTERED) {
rect.origin.x = bounds.x + (bounds.w - window->w) / 2;
} else {
rect.origin.x = window->x;
rect.origin.x = bounds.x + window->x;
}
if ((window->flags & SDL_WINDOW_FULLSCREEN)
|| window->y == SDL_WINDOWPOS_CENTERED) {
rect.origin.y = bounds.y + (bounds.h - window->h) / 2;
} else {
rect.origin.y = window->y;
rect.origin.y = bounds.y + window->y;
}
rect.size.width = window->w;
rect.size.height = window->h;
Expand Down
15 changes: 9 additions & 6 deletions src/video/win32/SDL_win32window.c
Expand Up @@ -86,6 +86,7 @@ static int
SetupWindowData(_THIS, SDL_Window * window, HWND hwnd, SDL_bool created)
{
SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
SDL_WindowData *data;

/* Allocate the window data */
Expand Down Expand Up @@ -123,8 +124,10 @@ SetupWindowData(_THIS, SDL_Window * window, HWND hwnd, SDL_bool created)
point.x = 0;
point.y = 0;
if (ClientToScreen(hwnd, &point)) {
window->x = point.x;
window->y = point.y;
SDL_Rect bounds;
WIN_GetDisplayBounds(_this, display, &bounds);
window->x = point.x - bounds.x;
window->y = point.y - bounds.y;
}
}
{
Expand Down Expand Up @@ -232,7 +235,7 @@ WIN_CreateWindow(_THIS, SDL_Window * window)
x = bounds.x;
}
} else {
x = window->x + rect.left;
x = bounds.x + window->x + rect.left;
}
if ((window->flags & SDL_WINDOW_FULLSCREEN)
|| window->y == SDL_WINDOWPOS_CENTERED) {
Expand All @@ -244,7 +247,7 @@ WIN_CreateWindow(_THIS, SDL_Window * window)
y = bounds.y;
}
} else {
y = window->y + rect.top;
y = bounds.y + window->y + rect.top;
}

hwnd =
Expand Down Expand Up @@ -459,13 +462,13 @@ WIN_SetWindowPosition(_THIS, SDL_Window * window)
|| window->x == SDL_WINDOWPOS_CENTERED) {
x = bounds.x + (bounds.w - window->w) / 2;
} else {
x = window->x + rect.left;
x = bounds.x + window->x + rect.left;
}
if ((window->flags & SDL_WINDOW_FULLSCREEN)
|| window->y == SDL_WINDOWPOS_CENTERED) {
y = bounds.y + (bounds.h - window->h) / 2;
} else {
y = window->y + rect.top;
y = bounds.y + window->y + rect.top;
}

SetWindowPos(hwnd, top, x, y, 0, 0, (SWP_NOCOPYBITS | SWP_NOSIZE));
Expand Down

0 comments on commit 3e5f8f1

Please sign in to comment.