comparison src/video/windx5/SDL_dx5video.c @ 833:31fa08b36380

Added support for SDL_VIDEO_WINDOW_POS and SDL_VIDEO_CENTERED on Windows
author Sam Lantinga <slouken@libsdl.org>
date Mon, 16 Feb 2004 21:09:24 +0000
parents 58b074c1bc59
children fd4a6847ddc0
comparison
equal deleted inserted replaced
832:f003714db2f4 833:31fa08b36380
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;
1006 DDSURFACEDESC ddsd; 1007 DDSURFACEDESC ddsd;
1007 LPDIRECTDRAWSURFACE dd_surface1; 1008 LPDIRECTDRAWSURFACE dd_surface1;
1008 LPDIRECTDRAWSURFACE3 dd_surface3; 1009 LPDIRECTDRAWSURFACE3 dd_surface3;
1009 BOOL was_visible;
1010 1010
1011 #ifdef DDRAW_DEBUG 1011 #ifdef DDRAW_DEBUG
1012 fprintf(stderr, "Setting %dx%dx%d video mode\n", width, height, bpp); 1012 fprintf(stderr, "Setting %dx%dx%d video mode\n", width, height, bpp);
1013 #endif 1013 #endif
1014 /* See whether or not we should center the window */
1015 was_visible = IsWindowVisible(SDL_Window);
1016
1017 /* Clean up any previous DirectDraw surfaces */ 1014 /* Clean up any previous DirectDraw surfaces */
1018 if ( current->hwdata ) { 1015 if ( current->hwdata ) {
1019 this->FreeHWSurface(this, current); 1016 this->FreeHWSurface(this, current);
1020 current->hwdata = NULL; 1017 current->hwdata = NULL;
1021 } 1018 }
1132 } 1129 }
1133 #if WS_MAXIMIZE 1130 #if WS_MAXIMIZE
1134 if (IsZoomed(SDL_Window)) style |= WS_MAXIMIZE; 1131 if (IsZoomed(SDL_Window)) style |= WS_MAXIMIZE;
1135 #endif 1132 #endif
1136 } 1133 }
1137 SetWindowLong(SDL_Window, GWL_STYLE, style); 1134
1135 /* DJM: Don't piss of anyone who has setup his own window */
1136 if ( SDL_windowid == NULL )
1137 SetWindowLong(SDL_Window, GWL_STYLE, style);
1138 1138
1139 /* Resize the window (copied from SDL WinDIB driver) */ 1139 /* Resize the window (copied from SDL WinDIB driver) */
1140 if ( SDL_windowid == NULL ) { 1140 if ( SDL_windowid == NULL ) {
1141 HWND top; 1141 HWND top;
1142 UINT swp_flags; 1142 UINT swp_flags;
1143 const char *window = getenv("SDL_VIDEO_WINDOW_POS");
1144 const char *center = getenv("SDL_VIDEO_CENTERED");
1145
1146 if ( !SDL_windowX && !SDL_windowY ) {
1147 if ( window ) {
1148 if ( sscanf(window, "%d,%d", &x, &y) == 2 ) {
1149 SDL_windowX = x;
1150 SDL_windowY = y;
1151 }
1152 if ( strcmp(window, "center") == 0 ) {
1153 center = window;
1154 window = NULL;
1155 }
1156 }
1157 }
1158 swp_flags = (SWP_NOCOPYBITS | SWP_SHOWWINDOW);
1143 1159
1144 SDL_resizing = 1; 1160 SDL_resizing = 1;
1145 bounds.top = 0; 1161 bounds.left = SDL_windowX;
1146 bounds.bottom = video->h; 1162 bounds.top = SDL_windowY;
1147 bounds.left = 0; 1163 bounds.right = SDL_windowX+video->w;
1148 bounds.right = video->w; 1164 bounds.bottom = SDL_windowY+video->h;
1149 AdjustWindowRectEx(&bounds, GetWindowLong(SDL_Window, GWL_STYLE), FALSE, 0); 1165 AdjustWindowRectEx(&bounds, GetWindowLong(SDL_Window, GWL_STYLE), FALSE, 0);
1150 width = bounds.right-bounds.left; 1166 width = bounds.right-bounds.left;
1151 height = bounds.bottom-bounds.top; 1167 height = bounds.bottom-bounds.top;
1152 x = (GetSystemMetrics(SM_CXSCREEN)-width)/2; 1168 if ( (flags & SDL_FULLSCREEN) ) {
1153 y = (GetSystemMetrics(SM_CYSCREEN)-height)/2; 1169 x = (GetSystemMetrics(SM_CXSCREEN)-width)/2;
1170 y = (GetSystemMetrics(SM_CYSCREEN)-height)/2;
1171 } else if ( SDL_windowX || SDL_windowY || window ) {
1172 x = bounds.left;
1173 y = bounds.top;
1174 } else if ( center ) {
1175 x = (GetSystemMetrics(SM_CXSCREEN)-width)/2;
1176 y = (GetSystemMetrics(SM_CYSCREEN)-height)/2;
1177 } else {
1178 x = y = -1;
1179 swp_flags |= SWP_NOMOVE;
1180 }
1154 if ( y < 0 ) { /* Cover up title bar for more client area */ 1181 if ( y < 0 ) { /* Cover up title bar for more client area */
1155 y -= GetSystemMetrics(SM_CYCAPTION)/2; 1182 y -= GetSystemMetrics(SM_CYCAPTION)/2;
1156 } 1183 }
1157 swp_flags = (SWP_NOCOPYBITS | SWP_FRAMECHANGED | SWP_SHOWWINDOW); 1184 if ( flags & SDL_FULLSCREEN ) {
1158 if ( was_visible && !(video->flags & SDL_FULLSCREEN) ) {
1159 swp_flags |= SWP_NOMOVE;
1160 }
1161 if ( video->flags & SDL_FULLSCREEN ) {
1162 top = HWND_TOPMOST; 1185 top = HWND_TOPMOST;
1163 } else { 1186 } else {
1164 top = HWND_NOTOPMOST; 1187 top = HWND_NOTOPMOST;
1165 } 1188 }
1166 SetWindowPos(SDL_Window, top, x, y, width, height, swp_flags); 1189 SetWindowPos(SDL_Window, top, x, y, width, height, swp_flags);
1175 video->flags |= SDL_OPENGL; 1198 video->flags |= SDL_OPENGL;
1176 return(video); 1199 return(video);
1177 } 1200 }
1178 1201
1179 /* Set the appropriate window style */ 1202 /* Set the appropriate window style */
1203 windowX = SDL_windowX;
1204 windowY = SDL_windowY;
1180 style = GetWindowLong(SDL_Window, GWL_STYLE); 1205 style = GetWindowLong(SDL_Window, GWL_STYLE);
1181 style &= ~(resizestyle|WS_MAXIMIZE); 1206 style &= ~(resizestyle|WS_MAXIMIZE);
1182 if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { 1207 if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) {
1183 style &= ~windowstyle; 1208 style &= ~windowstyle;
1184 style |= directstyle; 1209 style |= directstyle;
1195 } 1220 }
1196 #if WS_MAXIMIZE 1221 #if WS_MAXIMIZE
1197 if (IsZoomed(SDL_Window)) style |= WS_MAXIMIZE; 1222 if (IsZoomed(SDL_Window)) style |= WS_MAXIMIZE;
1198 #endif 1223 #endif
1199 } 1224 }
1200 SetWindowLong(SDL_Window, GWL_STYLE, style); 1225 /* DJM: Don't piss of anyone who has setup his own window */
1226 if ( SDL_windowid == NULL )
1227 SetWindowLong(SDL_Window, GWL_STYLE, style);
1201 1228
1202 /* Set DirectDraw sharing mode.. exclusive when fullscreen */ 1229 /* Set DirectDraw sharing mode.. exclusive when fullscreen */
1203 if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { 1230 if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) {
1204 sharemode = DDSCL_FULLSCREEN|DDSCL_EXCLUSIVE|DDSCL_ALLOWREBOOT; 1231 sharemode = DDSCL_FULLSCREEN|DDSCL_EXCLUSIVE|DDSCL_ALLOWREBOOT;
1205 } else { 1232 } else {
1208 result = IDirectDraw2_SetCooperativeLevel(ddraw2,SDL_Window,sharemode); 1235 result = IDirectDraw2_SetCooperativeLevel(ddraw2,SDL_Window,sharemode);
1209 if ( result != DD_OK ) { 1236 if ( result != DD_OK ) {
1210 SetDDerror("DirectDraw2::SetCooperativeLevel", result); 1237 SetDDerror("DirectDraw2::SetCooperativeLevel", result);
1211 return(NULL); 1238 return(NULL);
1212 } 1239 }
1240 SDL_windowX = windowX;
1241 SDL_windowY = windowY;
1213 1242
1214 /* Set the display mode, if we are in fullscreen mode */ 1243 /* Set the display mode, if we are in fullscreen mode */
1215 if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { 1244 if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) {
1245 RECT bounds;
1216 struct DX5EnumRect *rect; 1246 struct DX5EnumRect *rect;
1217 int maxRefreshRate; 1247 int maxRefreshRate;
1218 1248
1219 /* Cover up desktop during mode change */ 1249 /* Cover up desktop during mode change */
1220 SDL_resizing = 1; 1250 SDL_resizing = 1;
1221 SetWindowPos(SDL_Window, NULL, 0, 0, 1251 bounds.left = 0;
1222 GetSystemMetrics(SM_CXSCREEN), 1252 bounds.top = 0;
1223 GetSystemMetrics(SM_CYSCREEN), 1253 bounds.right = GetSystemMetrics(SM_CXSCREEN);
1224 (SWP_NOCOPYBITS | SWP_NOZORDER)); 1254 bounds.bottom = GetSystemMetrics(SM_CYSCREEN);
1255 AdjustWindowRectEx(&bounds, GetWindowLong(SDL_Window, GWL_STYLE), FALSE, 0);
1256 SetWindowPos(SDL_Window, HWND_TOPMOST,
1257 bounds.left, bounds.top,
1258 bounds.right - bounds.left,
1259 bounds.bottom - bounds.top, SWP_NOCOPYBITS);
1225 SDL_resizing = 0; 1260 SDL_resizing = 0;
1226 ShowWindow(SDL_Window, SW_SHOW); 1261 ShowWindow(SDL_Window, SW_SHOW);
1227 while ( GetForegroundWindow() != SDL_Window ) { 1262 while ( GetForegroundWindow() != SDL_Window ) {
1228 SetForegroundWindow(SDL_Window); 1263 SetForegroundWindow(SDL_Window);
1229 SDL_Delay(100); 1264 SDL_Delay(100);
1483 /* Make our window the proper size, set the clipper, then show it */ 1518 /* Make our window the proper size, set the clipper, then show it */
1484 if ( (flags & SDL_FULLSCREEN) != SDL_FULLSCREEN ) { 1519 if ( (flags & SDL_FULLSCREEN) != SDL_FULLSCREEN ) {
1485 RECT bounds; 1520 RECT bounds;
1486 int x, y; 1521 int x, y;
1487 UINT swp_flags; 1522 UINT swp_flags;
1523 const char *window = getenv("SDL_VIDEO_WINDOW_POS");
1524 const char *center = getenv("SDL_VIDEO_CENTERED");
1488 1525
1489 /* Create and set a clipper on our primary surface */ 1526 /* Create and set a clipper on our primary surface */
1490 if ( SDL_clipper == NULL ) { 1527 if ( SDL_clipper == NULL ) {
1491 result = IDirectDraw2_CreateClipper(ddraw2, 1528 result = IDirectDraw2_CreateClipper(ddraw2,
1492 0, &SDL_clipper, NULL); 1529 0, &SDL_clipper, NULL);
1514 } 1551 }
1515 SetDDerror("DirectDrawSurface3::SetClipper", result); 1552 SetDDerror("DirectDrawSurface3::SetClipper", result);
1516 return(NULL); 1553 return(NULL);
1517 } 1554 }
1518 1555
1519 /* Set the size of the window, centering and adjusting */ 1556 if ( !SDL_windowX && !SDL_windowY ) {
1557 if ( window ) {
1558 if ( sscanf(window, "%d,%d", &x, &y) == 2 ) {
1559 SDL_windowX = x;
1560 SDL_windowY = y;
1561 }
1562 if ( strcmp(window, "center") == 0 ) {
1563 center = window;
1564 window = NULL;
1565 }
1566 }
1567 }
1568 swp_flags = SWP_NOCOPYBITS;
1569
1520 SDL_resizing = 1; 1570 SDL_resizing = 1;
1521 bounds.top = 0; 1571 bounds.left = SDL_windowX;
1522 bounds.bottom = video->h; 1572 bounds.top = SDL_windowY;
1523 bounds.left = 0; 1573 bounds.right = SDL_windowX+video->w;
1524 bounds.right = video->w; 1574 bounds.bottom = SDL_windowY+video->h;
1525 AdjustWindowRectEx(&bounds, GetWindowLong(SDL_Window, GWL_STYLE), FALSE, 0); 1575 AdjustWindowRectEx(&bounds, GetWindowLong(SDL_Window, GWL_STYLE), FALSE, 0);
1526 width = bounds.right-bounds.left; 1576 width = bounds.right-bounds.left;
1527 height = bounds.bottom-bounds.top; 1577 height = bounds.bottom-bounds.top;
1528 x = (GetSystemMetrics(SM_CXSCREEN)-width)/2; 1578 if ( (flags & SDL_FULLSCREEN) ) {
1529 y = (GetSystemMetrics(SM_CYSCREEN)-height)/2; 1579 x = (GetSystemMetrics(SM_CXSCREEN)-width)/2;
1580 y = (GetSystemMetrics(SM_CYSCREEN)-height)/2;
1581 } else if ( SDL_windowX || SDL_windowY || window ) {
1582 x = bounds.left;
1583 y = bounds.top;
1584 } else if ( center ) {
1585 x = (GetSystemMetrics(SM_CXSCREEN)-width)/2;
1586 y = (GetSystemMetrics(SM_CYSCREEN)-height)/2;
1587 } else {
1588 x = y = -1;
1589 swp_flags |= SWP_NOMOVE;
1590 }
1530 if ( y < 0 ) { /* Cover up title bar for more client area */ 1591 if ( y < 0 ) { /* Cover up title bar for more client area */
1531 y -= GetSystemMetrics(SM_CYCAPTION)/2; 1592 y -= GetSystemMetrics(SM_CYCAPTION)/2;
1532 } 1593 }
1533 swp_flags = (SWP_NOCOPYBITS | SWP_NOZORDER); 1594 SetWindowPos(SDL_Window, HWND_NOTOPMOST, x, y, width, height, swp_flags);
1534 if ( was_visible ) {
1535 swp_flags |= SWP_NOMOVE;
1536 }
1537 SetWindowPos(SDL_Window, NULL, x, y, width, height, swp_flags);
1538 SDL_resizing = 0; 1595 SDL_resizing = 0;
1596
1539 } 1597 }
1540 ShowWindow(SDL_Window, SW_SHOW); 1598 ShowWindow(SDL_Window, SW_SHOW);
1541 SetForegroundWindow(SDL_Window); 1599 SetForegroundWindow(SDL_Window);
1542 1600
1543 /* We're live! */ 1601 /* We're live! */