comparison src/video/windx5/SDL_dx5video.c @ 1290:c4a5a772c5d9

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. :)
author Sam Lantinga <slouken@libsdl.org>
date Sun, 29 Jan 2006 18:17:35 +0000
parents ea3888b472bf
children 31331c444ea2
comparison
equal deleted inserted replaced
1289:c07c6ef7c93e 1290:c4a5a772c5d9
1001 (WS_POPUP); 1001 (WS_POPUP);
1002 const DWORD windowstyle = 1002 const DWORD windowstyle =
1003 (WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX); 1003 (WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX);
1004 const DWORD resizestyle = 1004 const DWORD resizestyle =
1005 (WS_THICKFRAME|WS_MAXIMIZEBOX); 1005 (WS_THICKFRAME|WS_MAXIMIZEBOX);
1006 int windowX, windowY;
1007 DDSURFACEDESC ddsd; 1006 DDSURFACEDESC ddsd;
1008 LPDIRECTDRAWSURFACE dd_surface1; 1007 LPDIRECTDRAWSURFACE dd_surface1;
1009 LPDIRECTDRAWSURFACE3 dd_surface3; 1008 LPDIRECTDRAWSURFACE3 dd_surface3;
1010 1009
1011 #ifdef DDRAW_DEBUG 1010 #ifdef DDRAW_DEBUG
1034 WIN_GL_ShutDown(this); 1033 WIN_GL_ShutDown(this);
1035 } 1034 }
1036 1035
1037 /* If we are setting a GL mode, use GDI, not DirectX (yuck) */ 1036 /* If we are setting a GL mode, use GDI, not DirectX (yuck) */
1038 if ( flags & SDL_OPENGL ) { 1037 if ( flags & SDL_OPENGL ) {
1039 RECT bounds;
1040 int x, y;
1041 Uint32 Rmask, Gmask, Bmask; 1038 Uint32 Rmask, Gmask, Bmask;
1042 1039
1043 /* Recalculate the bitmasks if necessary */ 1040 /* Recalculate the bitmasks if necessary */
1044 if ( bpp == current->format->BitsPerPixel ) { 1041 if ( bpp == current->format->BitsPerPixel ) {
1045 video = current; 1042 video = current;
1135 /* DJM: Don't piss of anyone who has setup his own window */ 1132 /* DJM: Don't piss of anyone who has setup his own window */
1136 if ( !SDL_windowid ) 1133 if ( !SDL_windowid )
1137 SetWindowLong(SDL_Window, GWL_STYLE, style); 1134 SetWindowLong(SDL_Window, GWL_STYLE, style);
1138 1135
1139 /* Resize the window (copied from SDL WinDIB driver) */ 1136 /* Resize the window (copied from SDL WinDIB driver) */
1140 if ( !SDL_windowid ) { 1137 if ( !SDL_windowid && !IsZoomed(SDL_Window) ) {
1138 RECT bounds;
1139 int x, y;
1141 HWND top; 1140 HWND top;
1142 UINT swp_flags; 1141 UINT swp_flags;
1143 const char *window = getenv("SDL_VIDEO_WINDOW_POS"); 1142 const char *window = NULL;
1144 const char *center = getenv("SDL_VIDEO_CENTERED"); 1143 const char *center = NULL;
1145 1144
1146 if ( !SDL_windowX && !SDL_windowY ) { 1145 if ( !SDL_windowX && !SDL_windowY ) {
1146 window = getenv("SDL_VIDEO_WINDOW_POS");
1147 center = getenv("SDL_VIDEO_CENTERED");
1147 if ( window ) { 1148 if ( window ) {
1148 if ( sscanf(window, "%d,%d", &x, &y) == 2 ) { 1149 if ( sscanf(window, "%d,%d", &x, &y) == 2 ) {
1149 SDL_windowX = x; 1150 SDL_windowX = x;
1150 SDL_windowY = y; 1151 SDL_windowY = y;
1151 } 1152 }
1152 if ( strcmp(window, "center") == 0 ) { 1153 if ( strcmp(window, "center") == 0 ) {
1153 center = window; 1154 center = window;
1154 window = NULL;
1155 } 1155 }
1156 } 1156 }
1157 } 1157 }
1158 swp_flags = (SWP_NOCOPYBITS | SWP_SHOWWINDOW); 1158 swp_flags = (SWP_NOCOPYBITS | SWP_SHOWWINDOW);
1159 1159
1176 y = bounds.top; 1176 y = bounds.top;
1177 } else { 1177 } else {
1178 x = y = -1; 1178 x = y = -1;
1179 swp_flags |= SWP_NOMOVE; 1179 swp_flags |= SWP_NOMOVE;
1180 } 1180 }
1181 if ( y < 0 ) { /* Cover up title bar for more client area */
1182 y -= GetSystemMetrics(SM_CYCAPTION)/2;
1183 }
1184 if ( flags & SDL_FULLSCREEN ) { 1181 if ( flags & SDL_FULLSCREEN ) {
1185 top = HWND_TOPMOST; 1182 top = HWND_TOPMOST;
1186 } else { 1183 } else {
1187 top = HWND_NOTOPMOST; 1184 top = HWND_NOTOPMOST;
1188 } 1185 }
1198 video->flags |= SDL_OPENGL; 1195 video->flags |= SDL_OPENGL;
1199 return(video); 1196 return(video);
1200 } 1197 }
1201 1198
1202 /* Set the appropriate window style */ 1199 /* Set the appropriate window style */
1203 windowX = SDL_windowX;
1204 windowY = SDL_windowY;
1205 style = GetWindowLong(SDL_Window, GWL_STYLE); 1200 style = GetWindowLong(SDL_Window, GWL_STYLE);
1206 style &= ~(resizestyle|WS_MAXIMIZE); 1201 style &= ~(resizestyle|WS_MAXIMIZE);
1207 if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { 1202 if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) {
1208 style &= ~windowstyle; 1203 style &= ~windowstyle;
1209 style |= directstyle; 1204 style |= directstyle;
1235 result = IDirectDraw2_SetCooperativeLevel(ddraw2,SDL_Window,sharemode); 1230 result = IDirectDraw2_SetCooperativeLevel(ddraw2,SDL_Window,sharemode);
1236 if ( result != DD_OK ) { 1231 if ( result != DD_OK ) {
1237 SetDDerror("DirectDraw2::SetCooperativeLevel", result); 1232 SetDDerror("DirectDraw2::SetCooperativeLevel", result);
1238 return(NULL); 1233 return(NULL);
1239 } 1234 }
1240 SDL_windowX = windowX;
1241 SDL_windowY = windowY;
1242 1235
1243 /* Set the display mode, if we are in fullscreen mode */ 1236 /* Set the display mode, if we are in fullscreen mode */
1244 if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { 1237 if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) {
1245 RECT bounds; 1238 RECT bounds;
1246 struct DX5EnumRect *rect; 1239 struct DX5EnumRect *rect;
1511 this->UpdateRects = DX5_WindowUpdate; 1504 this->UpdateRects = DX5_WindowUpdate;
1512 } 1505 }
1513 1506
1514 /* Make our window the proper size, set the clipper, then show it */ 1507 /* Make our window the proper size, set the clipper, then show it */
1515 if ( (flags & SDL_FULLSCREEN) != SDL_FULLSCREEN ) { 1508 if ( (flags & SDL_FULLSCREEN) != SDL_FULLSCREEN ) {
1516 RECT bounds;
1517 int x, y;
1518 UINT swp_flags;
1519 const char *window = getenv("SDL_VIDEO_WINDOW_POS");
1520 const char *center = getenv("SDL_VIDEO_CENTERED");
1521
1522 /* Create and set a clipper on our primary surface */ 1509 /* Create and set a clipper on our primary surface */
1523 if ( SDL_clipper == NULL ) { 1510 if ( SDL_clipper == NULL ) {
1524 result = IDirectDraw2_CreateClipper(ddraw2, 1511 result = IDirectDraw2_CreateClipper(ddraw2,
1525 0, &SDL_clipper, NULL); 1512 0, &SDL_clipper, NULL);
1526 if ( result != DD_OK ) { 1513 if ( result != DD_OK ) {
1547 } 1534 }
1548 SetDDerror("DirectDrawSurface3::SetClipper", result); 1535 SetDDerror("DirectDrawSurface3::SetClipper", result);
1549 return(NULL); 1536 return(NULL);
1550 } 1537 }
1551 1538
1552 if ( !SDL_windowX && !SDL_windowY ) { 1539 /* Resize the window (copied from SDL WinDIB driver) */
1553 if ( window ) { 1540 if ( !SDL_windowid && !IsZoomed(SDL_Window) ) {
1554 if ( sscanf(window, "%d,%d", &x, &y) == 2 ) { 1541 RECT bounds;
1555 SDL_windowX = x; 1542 int x, y;
1556 SDL_windowY = y; 1543 UINT swp_flags;
1544 const char *window = NULL;
1545 const char *center = NULL;
1546
1547 if ( !SDL_windowX && !SDL_windowY ) {
1548 window = getenv("SDL_VIDEO_WINDOW_POS");
1549 center = getenv("SDL_VIDEO_CENTERED");
1550 if ( window ) {
1551 if ( sscanf(window, "%d,%d", &x, &y) == 2 ) {
1552 SDL_windowX = x;
1553 SDL_windowY = y;
1554 }
1555 if ( strcmp(window, "center") == 0 ) {
1556 center = window;
1557 }
1557 } 1558 }
1558 if ( strcmp(window, "center") == 0 ) { 1559 }
1559 center = window; 1560 swp_flags = SWP_NOCOPYBITS;
1560 window = NULL; 1561
1561 } 1562 SDL_resizing = 1;
1562 } 1563 bounds.left = SDL_windowX;
1563 } 1564 bounds.top = SDL_windowY;
1564 swp_flags = SWP_NOCOPYBITS; 1565 bounds.right = SDL_windowX+video->w;
1565 1566 bounds.bottom = SDL_windowY+video->h;
1566 SDL_resizing = 1; 1567 AdjustWindowRectEx(&bounds, GetWindowLong(SDL_Window, GWL_STYLE), FALSE, 0);
1567 bounds.left = SDL_windowX; 1568 width = bounds.right-bounds.left;
1568 bounds.top = SDL_windowY; 1569 height = bounds.bottom-bounds.top;
1569 bounds.right = SDL_windowX+video->w; 1570 if ( center ) {
1570 bounds.bottom = SDL_windowY+video->h; 1571 x = (GetSystemMetrics(SM_CXSCREEN)-width)/2;
1571 AdjustWindowRectEx(&bounds, GetWindowLong(SDL_Window, GWL_STYLE), FALSE, 0); 1572 y = (GetSystemMetrics(SM_CYSCREEN)-height)/2;
1572 width = bounds.right-bounds.left; 1573 } else if ( SDL_windowX || SDL_windowY || window ) {
1573 height = bounds.bottom-bounds.top; 1574 x = bounds.left;
1574 if ( (flags & SDL_FULLSCREEN) ) { 1575 y = bounds.top;
1575 x = (GetSystemMetrics(SM_CXSCREEN)-width)/2; 1576 } else {
1576 y = (GetSystemMetrics(SM_CYSCREEN)-height)/2; 1577 x = y = -1;
1577 } else if ( center ) { 1578 swp_flags |= SWP_NOMOVE;
1578 x = (GetSystemMetrics(SM_CXSCREEN)-width)/2; 1579 }
1579 y = (GetSystemMetrics(SM_CYSCREEN)-height)/2; 1580 SetWindowPos(SDL_Window, HWND_NOTOPMOST, x, y, width, height, swp_flags);
1580 } else if ( SDL_windowX || SDL_windowY || window ) { 1581 SDL_resizing = 0;
1581 x = bounds.left; 1582 }
1582 y = bounds.top;
1583 } else {
1584 x = y = -1;
1585 swp_flags |= SWP_NOMOVE;
1586 }
1587 if ( y < 0 ) { /* Cover up title bar for more client area */
1588 y -= GetSystemMetrics(SM_CYCAPTION)/2;
1589 }
1590 SetWindowPos(SDL_Window, HWND_NOTOPMOST, x, y, width, height, swp_flags);
1591 SDL_resizing = 0;
1592 1583
1593 } 1584 }
1594 ShowWindow(SDL_Window, SW_SHOW); 1585 ShowWindow(SDL_Window, SW_SHOW);
1595 SetForegroundWindow(SDL_Window); 1586 SetForegroundWindow(SDL_Window);
1596 1587