comparison src/video/windx5/SDL_dx5video.c @ 453:a6fa62b1be09

Updated for embedded Visual C++ 4.0
author Sam Lantinga <slouken@libsdl.org>
date Tue, 20 Aug 2002 00:20:06 +0000
parents 323c766f5a46
children 0b0c2e63eb27
comparison
equal deleted inserted replaced
452:4c5c10383201 453:a6fa62b1be09
49 #include "SDL_sysmouse_c.h" 49 #include "SDL_sysmouse_c.h"
50 #include "SDL_dx5events_c.h" 50 #include "SDL_dx5events_c.h"
51 #include "SDL_dx5yuv_c.h" 51 #include "SDL_dx5yuv_c.h"
52 #include "SDL_wingl_c.h" 52 #include "SDL_wingl_c.h"
53 53
54 #ifdef _WIN32_WCE
55 #define NO_CHANGEDISPLAYSETTINGS
56 #endif
57 #ifndef WS_MAXIMIZE
58 #define WS_MAXIMIZE 0
59 #endif
60 #ifndef SWP_NOCOPYBITS
61 #define SWP_NOCOPYBITS 0
62 #endif
63 #ifndef PC_NOCOLLAPSE
64 #define PC_NOCOLLAPSE 0
65 #endif
66
54 67
55 /* DirectX function pointers for video and events */ 68 /* DirectX function pointers for video and events */
56 HRESULT (WINAPI *DDrawCreate)( GUID FAR *lpGUID, LPDIRECTDRAW FAR *lplpDD, IUnknown FAR *pUnkOuter ); 69 HRESULT (WINAPI *DDrawCreate)( GUID FAR *lpGUID, LPDIRECTDRAW FAR *lplpDD, IUnknown FAR *pUnkOuter );
57 HRESULT (WINAPI *DInputCreate)(HINSTANCE hinst, DWORD dwVersion, LPDIRECTINPUTA *ppDI, LPUNKNOWN punkOuter); 70 HRESULT (WINAPI *DInputCreate)(HINSTANCE hinst, DWORD dwVersion, LPDIRECTINPUT *ppDI, LPUNKNOWN punkOuter);
58 71
59 /* This is the rect EnumModes2 uses */ 72 /* This is the rect EnumModes2 uses */
60 struct DX5EnumRect { 73 struct DX5EnumRect {
61 SDL_Rect r; 74 SDL_Rect r;
62 struct DX5EnumRect* next; 75 struct DX5EnumRect* next;
441 int dinput_ok; 454 int dinput_ok;
442 int ddraw_ok; 455 int ddraw_ok;
443 456
444 /* Version check DINPUT.DLL and DDRAW.DLL (Is DirectX okay?) */ 457 /* Version check DINPUT.DLL and DDRAW.DLL (Is DirectX okay?) */
445 dinput_ok = 0; 458 dinput_ok = 0;
446 DInputDLL = LoadLibrary("DINPUT.DLL"); 459 DInputDLL = LoadLibrary(TEXT("DINPUT.DLL"));
447 if ( DInputDLL != NULL ) { 460 if ( DInputDLL != NULL ) {
448 dinput_ok = 1; 461 dinput_ok = 1;
449 FreeLibrary(DInputDLL); 462 FreeLibrary(DInputDLL);
450 } 463 }
451 ddraw_ok = 0; 464 ddraw_ok = 0;
452 DDrawDLL = LoadLibrary("DDRAW.DLL"); 465 DDrawDLL = LoadLibrary(TEXT("DDRAW.DLL"));
453 if ( DDrawDLL != NULL ) { 466 if ( DDrawDLL != NULL ) {
454 HRESULT (WINAPI *DDrawCreate)(GUID *,LPDIRECTDRAW *,IUnknown *); 467 HRESULT (WINAPI *DDrawCreate)(GUID *,LPDIRECTDRAW *,IUnknown *);
455 LPDIRECTDRAW DDraw; 468 LPDIRECTDRAW DDraw;
456 469
457 /* Try to create a valid DirectDraw object */ 470 /* Try to create a valid DirectDraw object */
458 DDrawCreate = (void *)GetProcAddress(DDrawDLL, "DirectDrawCreate"); 471 DDrawCreate = (void *)GetProcAddress(DDrawDLL, TEXT("DirectDrawCreate"));
459 if ( (DDrawCreate != NULL) 472 if ( (DDrawCreate != NULL)
460 && !FAILED(DDrawCreate(NULL, &DDraw, NULL)) ) { 473 && !FAILED(DDrawCreate(NULL, &DDraw, NULL)) ) {
461 if ( !FAILED(IDirectDraw_SetCooperativeLevel(DDraw, 474 if ( !FAILED(IDirectDraw_SetCooperativeLevel(DDraw,
462 NULL, DDSCL_NORMAL)) ) { 475 NULL, DDSCL_NORMAL)) ) {
463 DDSURFACEDESC desc; 476 DDSURFACEDESC desc;
509 static int DX5_Load(void) 522 static int DX5_Load(void)
510 { 523 {
511 int status; 524 int status;
512 525
513 DX5_Unload(); 526 DX5_Unload();
514 DDrawDLL = LoadLibrary("DDRAW.DLL"); 527 DDrawDLL = LoadLibrary(TEXT("DDRAW.DLL"));
515 if ( DDrawDLL != NULL ) { 528 if ( DDrawDLL != NULL ) {
516 DDrawCreate = (void *)GetProcAddress(DDrawDLL, 529 DDrawCreate = (void *)GetProcAddress(DDrawDLL,
517 "DirectDrawCreate"); 530 TEXT("DirectDrawCreate"));
518 } 531 }
519 DInputDLL = LoadLibrary("DINPUT.DLL"); 532 DInputDLL = LoadLibrary(TEXT("DINPUT.DLL"));
520 if ( DInputDLL != NULL ) { 533 if ( DInputDLL != NULL ) {
521 DInputCreate = (void *)GetProcAddress(DInputDLL, 534 DInputCreate = (void *)GetProcAddress(DInputDLL,
522 "DirectInputCreateA"); 535 TEXT("DirectInputCreateA"));
523 } 536 }
524 if ( DDrawDLL && DDrawCreate && DInputDLL && DInputCreate ) { 537 if ( DDrawDLL && DDrawCreate && DInputDLL && DInputCreate ) {
525 status = 0; 538 status = 0;
526 } else { 539 } else {
527 DX5_Unload(); 540 DX5_Unload();
594 device->FlipHWSurface = DX5_FlipHWSurface; 607 device->FlipHWSurface = DX5_FlipHWSurface;
595 device->FreeHWSurface = DX5_FreeHWSurface; 608 device->FreeHWSurface = DX5_FreeHWSurface;
596 device->SetGammaRamp = DX5_SetGammaRamp; 609 device->SetGammaRamp = DX5_SetGammaRamp;
597 device->GetGammaRamp = DX5_GetGammaRamp; 610 device->GetGammaRamp = DX5_GetGammaRamp;
598 #ifdef HAVE_OPENGL 611 #ifdef HAVE_OPENGL
599 device->GL_LoadLibrary = WIN_GL_LoadLibrary; 612 device->GL_LoadLibrary = WIN_GL_LoadLibrary;
600 device->GL_GetProcAddress = WIN_GL_GetProcAddress; 613 device->GL_GetProcAddress = WIN_GL_GetProcAddress;
601 device->GL_GetAttribute = WIN_GL_GetAttribute; 614 device->GL_GetAttribute = WIN_GL_GetAttribute;
602 device->GL_MakeCurrent = WIN_GL_MakeCurrent; 615 device->GL_MakeCurrent = WIN_GL_MakeCurrent;
603 device->GL_SwapBuffers = WIN_GL_SwapBuffers; 616 device->GL_SwapBuffers = WIN_GL_SwapBuffers;
604 #endif 617 #endif
605 device->SetCaption = WIN_SetWMCaption; 618 device->SetCaption = WIN_SetWMCaption;
606 device->SetIcon = WIN_SetWMIcon; 619 device->SetIcon = WIN_SetWMIcon;
607 device->IconifyWindow = WIN_IconifyWindow; 620 device->IconifyWindow = WIN_IconifyWindow;
608 device->GrabInput = WIN_GrabInput; 621 device->GrabInput = WIN_GrabInput;
668 } 681 }
669 682
670 void SetDDerror(const char *function, int code) 683 void SetDDerror(const char *function, int code)
671 { 684 {
672 static char *error; 685 static char *error;
673 static char errbuf[BUFSIZ]; 686 static char errbuf[1024];
674 687
675 errbuf[0] = 0; 688 errbuf[0] = 0;
676 switch (code) { 689 switch (code) {
677 case DDERR_GENERIC: 690 case DDERR_GENERIC:
678 error = "Undefined error!"; 691 error = "Undefined error!";
992 if ( SDL_primary != NULL ) { 1005 if ( SDL_primary != NULL ) {
993 IDirectDrawSurface3_Release(SDL_primary); 1006 IDirectDrawSurface3_Release(SDL_primary);
994 SDL_primary = NULL; 1007 SDL_primary = NULL;
995 } 1008 }
996 1009
1010 #ifndef NO_CHANGEDISPLAYSETTINGS
997 /* Unset any previous OpenGL fullscreen mode */ 1011 /* Unset any previous OpenGL fullscreen mode */
998 if ( (current->flags & (SDL_OPENGL|SDL_FULLSCREEN)) == 1012 if ( (current->flags & (SDL_OPENGL|SDL_FULLSCREEN)) ==
999 (SDL_OPENGL|SDL_FULLSCREEN) ) { 1013 (SDL_OPENGL|SDL_FULLSCREEN) ) {
1000 ChangeDisplaySettings(NULL, 0); 1014 ChangeDisplaySettings(NULL, 0);
1001 } 1015 }
1016 #endif
1002 1017
1003 /* Clean up any GL context that may be hanging around */ 1018 /* Clean up any GL context that may be hanging around */
1004 if ( current->flags & SDL_OPENGL ) { 1019 if ( current->flags & SDL_OPENGL ) {
1005 WIN_GL_ShutDown(this); 1020 WIN_GL_ShutDown(this);
1006 } 1021 }
1055 video->flags = 0; /* Clear flags */ 1070 video->flags = 0; /* Clear flags */
1056 video->w = width; 1071 video->w = width;
1057 video->h = height; 1072 video->h = height;
1058 video->pitch = SDL_CalculatePitch(video); 1073 video->pitch = SDL_CalculatePitch(video);
1059 1074
1075 #ifndef NO_CHANGEDISPLAYSETTINGS
1060 /* Set fullscreen mode if appropriate. 1076 /* Set fullscreen mode if appropriate.
1061 Ugh, since our list of valid video modes comes from 1077 Ugh, since our list of valid video modes comes from
1062 the DirectX driver, we may not actually be able to 1078 the DirectX driver, we may not actually be able to
1063 change to the desired resolution here. 1079 change to the desired resolution here.
1064 FIXME: Should we do a closest match? 1080 FIXME: Should we do a closest match?
1075 if ( ChangeDisplaySettings(&settings, CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL ) { 1091 if ( ChangeDisplaySettings(&settings, CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL ) {
1076 video->flags |= SDL_FULLSCREEN; 1092 video->flags |= SDL_FULLSCREEN;
1077 SDL_fullscreen_mode = settings; 1093 SDL_fullscreen_mode = settings;
1078 } 1094 }
1079 } 1095 }
1096 #endif /* !NO_CHANGEDISPLAYSETTINGS */
1080 1097
1081 style = GetWindowLong(SDL_Window, GWL_STYLE); 1098 style = GetWindowLong(SDL_Window, GWL_STYLE);
1082 style &= ~(resizestyle|WS_MAXIMIZE); 1099 style &= ~(resizestyle|WS_MAXIMIZE);
1083 if ( video->flags & SDL_FULLSCREEN ) { 1100 if ( video->flags & SDL_FULLSCREEN ) {
1084 style &= ~windowstyle; 1101 style &= ~windowstyle;
1094 if ( flags & SDL_RESIZABLE ) { 1111 if ( flags & SDL_RESIZABLE ) {
1095 style |= resizestyle; 1112 style |= resizestyle;
1096 video->flags |= SDL_RESIZABLE; 1113 video->flags |= SDL_RESIZABLE;
1097 } 1114 }
1098 } 1115 }
1116 #if WS_MAXIMIZE
1099 if (IsZoomed(SDL_Window)) style |= WS_MAXIMIZE; 1117 if (IsZoomed(SDL_Window)) style |= WS_MAXIMIZE;
1118 #endif
1100 } 1119 }
1101 SetWindowLong(SDL_Window, GWL_STYLE, style); 1120 SetWindowLong(SDL_Window, GWL_STYLE, style);
1102 1121
1103 /* Resize the window (copied from SDL WinDIB driver) */ 1122 /* Resize the window (copied from SDL WinDIB driver) */
1104 if ( SDL_windowid == NULL ) { 1123 if ( SDL_windowid == NULL ) {
1108 SDL_resizing = 1; 1127 SDL_resizing = 1;
1109 bounds.left = 0; 1128 bounds.left = 0;
1110 bounds.top = 0; 1129 bounds.top = 0;
1111 bounds.right = video->w; 1130 bounds.right = video->w;
1112 bounds.bottom = video->h; 1131 bounds.bottom = video->h;
1113 AdjustWindowRect(&bounds, GetWindowLong(SDL_Window, GWL_STYLE), FALSE); 1132 AdjustWindowRectEx(&bounds, GetWindowLong(SDL_Window, GWL_STYLE), FALSE, 0);
1114 width = bounds.right-bounds.left; 1133 width = bounds.right-bounds.left;
1115 height = bounds.bottom-bounds.top; 1134 height = bounds.bottom-bounds.top;
1116 x = (GetSystemMetrics(SM_CXSCREEN)-width)/2; 1135 x = (GetSystemMetrics(SM_CXSCREEN)-width)/2;
1117 y = (GetSystemMetrics(SM_CYSCREEN)-height)/2; 1136 y = (GetSystemMetrics(SM_CYSCREEN)-height)/2;
1118 if ( y < 0 ) { /* Cover up title bar for more client area */ 1137 if ( y < 0 ) { /* Cover up title bar for more client area */
1155 style |= windowstyle; 1174 style |= windowstyle;
1156 if ( flags & SDL_RESIZABLE ) { 1175 if ( flags & SDL_RESIZABLE ) {
1157 style |= resizestyle; 1176 style |= resizestyle;
1158 } 1177 }
1159 } 1178 }
1179 #if WS_MAXIMIZE
1160 if (IsZoomed(SDL_Window)) style |= WS_MAXIMIZE; 1180 if (IsZoomed(SDL_Window)) style |= WS_MAXIMIZE;
1181 #endif
1161 } 1182 }
1162 SetWindowLong(SDL_Window, GWL_STYLE, style); 1183 SetWindowLong(SDL_Window, GWL_STYLE, style);
1163 1184
1164 /* Set DirectDraw sharing mode.. exclusive when fullscreen */ 1185 /* Set DirectDraw sharing mode.. exclusive when fullscreen */
1165 if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { 1186 if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) {
1464 SDL_resizing = 1; 1485 SDL_resizing = 1;
1465 bounds.left = 0; 1486 bounds.left = 0;
1466 bounds.top = 0; 1487 bounds.top = 0;
1467 bounds.right = video->w; 1488 bounds.right = video->w;
1468 bounds.bottom = video->h; 1489 bounds.bottom = video->h;
1469 AdjustWindowRect(&bounds, GetWindowLong(SDL_Window, GWL_STYLE), 1490 AdjustWindowRectEx(&bounds, GetWindowLong(SDL_Window, GWL_STYLE), FALSE, 0);
1470 FALSE);
1471 width = bounds.right-bounds.left; 1491 width = bounds.right-bounds.left;
1472 height = bounds.bottom-bounds.top; 1492 height = bounds.bottom-bounds.top;
1473 x = (GetSystemMetrics(SM_CXSCREEN)-width)/2; 1493 x = (GetSystemMetrics(SM_CXSCREEN)-width)/2;
1474 y = (GetSystemMetrics(SM_CYSCREEN)-height)/2; 1494 y = (GetSystemMetrics(SM_CYSCREEN)-height)/2;
1475 if ( y < 0 ) { /* Cover up title bar for more client area */ 1495 if ( y < 0 ) { /* Cover up title bar for more client area */
2233 { 2253 {
2234 int i, j; 2254 int i, j;
2235 2255
2236 /* If we're fullscreen GL, we need to reset the display */ 2256 /* If we're fullscreen GL, we need to reset the display */
2237 if ( this->screen != NULL ) { 2257 if ( this->screen != NULL ) {
2258 #ifndef NO_CHANGEDISPLAYSETTINGS
2238 if ( (this->screen->flags & (SDL_OPENGL|SDL_FULLSCREEN)) == 2259 if ( (this->screen->flags & (SDL_OPENGL|SDL_FULLSCREEN)) ==
2239 (SDL_OPENGL|SDL_FULLSCREEN) ) { 2260 (SDL_OPENGL|SDL_FULLSCREEN) ) {
2240 ChangeDisplaySettings(NULL, 0); 2261 ChangeDisplaySettings(NULL, 0);
2241 ShowWindow(SDL_Window, SW_HIDE); 2262 ShowWindow(SDL_Window, SW_HIDE);
2242 } 2263 }
2264 #endif
2243 if ( this->screen->flags & SDL_OPENGL ) { 2265 if ( this->screen->flags & SDL_OPENGL ) {
2244 WIN_GL_ShutDown(this); 2266 WIN_GL_ShutDown(this);
2245 } 2267 }
2246 } 2268 }
2247 2269