From 6d939e1b236290d03e7498e4e86c95085c3e8c27 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 29 Jan 2006 18:17:35 +0000 Subject: [PATCH] The event code was fine, and calculated the SDL_windowX/Y correctly. What we really needed to do was avoid doing client rect adjustment on zoomed windows. :) --- src/video/wincommon/SDL_sysevents.c | 4 +- src/video/windib/SDL_dibvideo.c | 12 ++-- src/video/windx5/SDL_dx5video.c | 103 +++++++++++++--------------- 3 files changed, 54 insertions(+), 65 deletions(-) diff --git a/src/video/wincommon/SDL_sysevents.c b/src/video/wincommon/SDL_sysevents.c index 93be09a3a..44ebad698 100644 --- a/src/video/wincommon/SDL_sysevents.c +++ b/src/video/wincommon/SDL_sysevents.c @@ -566,13 +566,13 @@ LONG CALLBACK WinMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) int w, h; GetClientRect(SDL_Window, &SDL_bounds); + ClientToScreen(SDL_Window, (LPPOINT)&SDL_bounds); + ClientToScreen(SDL_Window, (LPPOINT)&SDL_bounds+1); SDL_windowX = SDL_bounds.left; SDL_windowY = SDL_bounds.top; w = SDL_bounds.right-SDL_bounds.left; h = SDL_bounds.bottom-SDL_bounds.top; if ( this->input_grab != SDL_GRAB_OFF ) { - ClientToScreen(SDL_Window, (LPPOINT)&SDL_bounds); - ClientToScreen(SDL_Window, (LPPOINT)&SDL_bounds+1); ClipCursor(&SDL_bounds); } if ( SDL_PublicSurface && diff --git a/src/video/windib/SDL_dibvideo.c b/src/video/windib/SDL_dibvideo.c index 5e6e4d79e..42836c86f 100644 --- a/src/video/windib/SDL_dibvideo.c +++ b/src/video/windib/SDL_dibvideo.c @@ -665,13 +665,15 @@ SDL_Surface *DIB_SetVideoMode(_THIS, SDL_Surface *current, } /* Resize the window */ - if ( !SDL_windowid ) { + if ( !SDL_windowid && !IsZoomed(SDL_Window) ) { HWND top; UINT swp_flags; - const char *window = getenv("SDL_VIDEO_WINDOW_POS"); - const char *center = getenv("SDL_VIDEO_CENTERED"); + const char *window = NULL; + const char *center = NULL; if ( !SDL_windowX && !SDL_windowY ) { + window = getenv("SDL_VIDEO_WINDOW_POS"); + center = getenv("SDL_VIDEO_CENTERED"); if ( window ) { if ( sscanf(window, "%d,%d", &x, &y) == 2 ) { SDL_windowX = x; @@ -679,7 +681,6 @@ SDL_Surface *DIB_SetVideoMode(_THIS, SDL_Surface *current, } if ( strcmp(window, "center") == 0 ) { center = window; - window = NULL; } } } @@ -706,9 +707,6 @@ SDL_Surface *DIB_SetVideoMode(_THIS, SDL_Surface *current, x = y = -1; swp_flags |= SWP_NOMOVE; } - if ( y < 0 ) { /* Cover up title bar for more client area */ - y -= GetSystemMetrics(SM_CYCAPTION)/2; - } if ( flags & SDL_FULLSCREEN ) { top = HWND_TOPMOST; } else { diff --git a/src/video/windx5/SDL_dx5video.c b/src/video/windx5/SDL_dx5video.c index fe7705a9d..29baf8f4b 100644 --- a/src/video/windx5/SDL_dx5video.c +++ b/src/video/windx5/SDL_dx5video.c @@ -1003,7 +1003,6 @@ SDL_Surface *DX5_SetVideoMode(_THIS, SDL_Surface *current, (WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX); const DWORD resizestyle = (WS_THICKFRAME|WS_MAXIMIZEBOX); - int windowX, windowY; DDSURFACEDESC ddsd; LPDIRECTDRAWSURFACE dd_surface1; LPDIRECTDRAWSURFACE3 dd_surface3; @@ -1036,8 +1035,6 @@ SDL_Surface *DX5_SetVideoMode(_THIS, SDL_Surface *current, /* If we are setting a GL mode, use GDI, not DirectX (yuck) */ if ( flags & SDL_OPENGL ) { - RECT bounds; - int x, y; Uint32 Rmask, Gmask, Bmask; /* Recalculate the bitmasks if necessary */ @@ -1137,13 +1134,17 @@ SDL_Surface *DX5_SetVideoMode(_THIS, SDL_Surface *current, SetWindowLong(SDL_Window, GWL_STYLE, style); /* Resize the window (copied from SDL WinDIB driver) */ - if ( !SDL_windowid ) { + if ( !SDL_windowid && !IsZoomed(SDL_Window) ) { + RECT bounds; + int x, y; HWND top; UINT swp_flags; - const char *window = getenv("SDL_VIDEO_WINDOW_POS"); - const char *center = getenv("SDL_VIDEO_CENTERED"); + const char *window = NULL; + const char *center = NULL; if ( !SDL_windowX && !SDL_windowY ) { + window = getenv("SDL_VIDEO_WINDOW_POS"); + center = getenv("SDL_VIDEO_CENTERED"); if ( window ) { if ( sscanf(window, "%d,%d", &x, &y) == 2 ) { SDL_windowX = x; @@ -1151,7 +1152,6 @@ SDL_Surface *DX5_SetVideoMode(_THIS, SDL_Surface *current, } if ( strcmp(window, "center") == 0 ) { center = window; - window = NULL; } } } @@ -1178,9 +1178,6 @@ SDL_Surface *DX5_SetVideoMode(_THIS, SDL_Surface *current, x = y = -1; swp_flags |= SWP_NOMOVE; } - if ( y < 0 ) { /* Cover up title bar for more client area */ - y -= GetSystemMetrics(SM_CYCAPTION)/2; - } if ( flags & SDL_FULLSCREEN ) { top = HWND_TOPMOST; } else { @@ -1200,8 +1197,6 @@ SDL_Surface *DX5_SetVideoMode(_THIS, SDL_Surface *current, } /* Set the appropriate window style */ - windowX = SDL_windowX; - windowY = SDL_windowY; style = GetWindowLong(SDL_Window, GWL_STYLE); style &= ~(resizestyle|WS_MAXIMIZE); if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { @@ -1237,8 +1232,6 @@ SDL_Surface *DX5_SetVideoMode(_THIS, SDL_Surface *current, SetDDerror("DirectDraw2::SetCooperativeLevel", result); return(NULL); } - SDL_windowX = windowX; - SDL_windowY = windowY; /* Set the display mode, if we are in fullscreen mode */ if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { @@ -1513,12 +1506,6 @@ SDL_Surface *DX5_SetVideoMode(_THIS, SDL_Surface *current, /* Make our window the proper size, set the clipper, then show it */ if ( (flags & SDL_FULLSCREEN) != SDL_FULLSCREEN ) { - RECT bounds; - int x, y; - UINT swp_flags; - const char *window = getenv("SDL_VIDEO_WINDOW_POS"); - const char *center = getenv("SDL_VIDEO_CENTERED"); - /* Create and set a clipper on our primary surface */ if ( SDL_clipper == NULL ) { result = IDirectDraw2_CreateClipper(ddraw2, @@ -1549,46 +1536,50 @@ SDL_Surface *DX5_SetVideoMode(_THIS, SDL_Surface *current, return(NULL); } - if ( !SDL_windowX && !SDL_windowY ) { - if ( window ) { - if ( sscanf(window, "%d,%d", &x, &y) == 2 ) { - SDL_windowX = x; - SDL_windowY = y; - } - if ( strcmp(window, "center") == 0 ) { - center = window; - window = NULL; + /* Resize the window (copied from SDL WinDIB driver) */ + if ( !SDL_windowid && !IsZoomed(SDL_Window) ) { + RECT bounds; + int x, y; + UINT swp_flags; + const char *window = NULL; + const char *center = NULL; + + if ( !SDL_windowX && !SDL_windowY ) { + window = getenv("SDL_VIDEO_WINDOW_POS"); + center = getenv("SDL_VIDEO_CENTERED"); + if ( window ) { + if ( sscanf(window, "%d,%d", &x, &y) == 2 ) { + SDL_windowX = x; + SDL_windowY = y; + } + if ( strcmp(window, "center") == 0 ) { + center = window; + } } } - } - swp_flags = SWP_NOCOPYBITS; + swp_flags = SWP_NOCOPYBITS; - SDL_resizing = 1; - bounds.left = SDL_windowX; - bounds.top = SDL_windowY; - bounds.right = SDL_windowX+video->w; - bounds.bottom = SDL_windowY+video->h; - AdjustWindowRectEx(&bounds, GetWindowLong(SDL_Window, GWL_STYLE), FALSE, 0); - width = bounds.right-bounds.left; - height = bounds.bottom-bounds.top; - if ( (flags & SDL_FULLSCREEN) ) { - x = (GetSystemMetrics(SM_CXSCREEN)-width)/2; - y = (GetSystemMetrics(SM_CYSCREEN)-height)/2; - } else if ( center ) { - x = (GetSystemMetrics(SM_CXSCREEN)-width)/2; - y = (GetSystemMetrics(SM_CYSCREEN)-height)/2; - } else if ( SDL_windowX || SDL_windowY || window ) { - x = bounds.left; - y = bounds.top; - } else { - x = y = -1; - swp_flags |= SWP_NOMOVE; - } - if ( y < 0 ) { /* Cover up title bar for more client area */ - y -= GetSystemMetrics(SM_CYCAPTION)/2; + SDL_resizing = 1; + bounds.left = SDL_windowX; + bounds.top = SDL_windowY; + bounds.right = SDL_windowX+video->w; + bounds.bottom = SDL_windowY+video->h; + AdjustWindowRectEx(&bounds, GetWindowLong(SDL_Window, GWL_STYLE), FALSE, 0); + width = bounds.right-bounds.left; + height = bounds.bottom-bounds.top; + if ( center ) { + x = (GetSystemMetrics(SM_CXSCREEN)-width)/2; + y = (GetSystemMetrics(SM_CYSCREEN)-height)/2; + } else if ( SDL_windowX || SDL_windowY || window ) { + x = bounds.left; + y = bounds.top; + } else { + x = y = -1; + swp_flags |= SWP_NOMOVE; + } + SetWindowPos(SDL_Window, HWND_NOTOPMOST, x, y, width, height, swp_flags); + SDL_resizing = 0; } - SetWindowPos(SDL_Window, HWND_NOTOPMOST, x, y, width, height, swp_flags); - SDL_resizing = 0; } ShowWindow(SDL_Window, SW_SHOW);