📄 sdl_dibvideo.c
字号:
SDL_resizing = 0; /* Set up for OpenGL */ if ( flags & SDL_OPENGL ) { if ( WIN_GL_SetupWindow(this) < 0 ) { return(NULL); } video->flags |= SDL_OPENGL; } /* JC 14 Mar 2006 Flush the message loop or this can cause big problems later Especially if the user decides to use dialog boxes or assert()! */ WIN_FlushMessageQueue(); /* We're live! */ return(video);}/* We don't actually allow hardware surfaces in the DIB driver */static int DIB_AllocHWSurface(_THIS, SDL_Surface *surface){ return(-1);}static void DIB_FreeHWSurface(_THIS, SDL_Surface *surface){ return;}static int DIB_LockHWSurface(_THIS, SDL_Surface *surface){ return(0);}static void DIB_UnlockHWSurface(_THIS, SDL_Surface *surface){ return;}static void DIB_NormalUpdate(_THIS, int numrects, SDL_Rect *rects){ HDC hdc, mdc; int i; hdc = GetDC(SDL_Window); if ( screen_pal ) { SelectPalette(hdc, screen_pal, FALSE); } mdc = CreateCompatibleDC(hdc); SelectObject(mdc, screen_bmp); for ( i=0; i<numrects; ++i ) { BitBlt(hdc, rects[i].x, rects[i].y, rects[i].w, rects[i].h, mdc, rects[i].x, rects[i].y, SRCCOPY); } DeleteDC(mdc); ReleaseDC(SDL_Window, hdc);}static int FindPaletteIndex(LOGPALETTE *pal, BYTE r, BYTE g, BYTE b){ PALETTEENTRY *entry; int i; int nentries = pal->palNumEntries; for ( i = 0; i < nentries; ++i ) { entry = &pal->palPalEntry[i]; if ( entry->peRed == r && entry->peGreen == g && entry->peBlue == b ) { return i; } } return -1;}static BOOL CheckPaletteEntry(LOGPALETTE *pal, int index, BYTE r, BYTE g, BYTE b){ PALETTEENTRY *entry; BOOL moved = 0; entry = &pal->palPalEntry[index]; if ( entry->peRed != r || entry->peGreen != g || entry->peBlue != b ) { int found = FindPaletteIndex(pal, r, g, b); if ( found >= 0 ) { pal->palPalEntry[found] = *entry; } entry->peRed = r; entry->peGreen = g; entry->peBlue = b; moved = 1; } entry->peFlags = 0; return moved;}int DIB_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors){#if !defined(_WIN32_WCE) || (_WIN32_WCE >= 400) HDC hdc, mdc; RGBQUAD *pal;#else HDC hdc;#endif int i; int moved_entries = 0; /* Update the display palette */ hdc = GetDC(SDL_Window); if ( screen_pal ) { PALETTEENTRY *entry; for ( i=0; i<ncolors; ++i ) { entry = &screen_logpal->palPalEntry[firstcolor+i]; entry->peRed = colors[i].r; entry->peGreen = colors[i].g; entry->peBlue = colors[i].b; entry->peFlags = PC_NOCOLLAPSE; }#ifdef SYSPAL_NOSTATIC /* Check to make sure black and white are in position */ if ( GetSystemPaletteUse(hdc) != SYSPAL_NOSTATIC256 ) { moved_entries += CheckPaletteEntry(screen_logpal, 0, 0x00, 0x00, 0x00); moved_entries += CheckPaletteEntry(screen_logpal, screen_logpal->palNumEntries-1, 0xff, 0xff, 0xff); } /* FIXME: If we don't have full access to the palette, what we really want to do is find the 236 most diverse colors in the desired palette, set those entries (10-245) and then map everything into the new system palette. */#endif#ifndef _WIN32_WCE /* Copy the entries into the system palette */ UnrealizeObject(screen_pal);#endif SetPaletteEntries(screen_pal, 0, screen_logpal->palNumEntries, screen_logpal->palPalEntry); SelectPalette(hdc, screen_pal, FALSE); RealizePalette(hdc); }#if !defined(_WIN32_WCE) || (_WIN32_WCE >= 400) /* Copy palette colors into DIB palette */ pal = SDL_stack_alloc(RGBQUAD, ncolors); for ( i=0; i<ncolors; ++i ) { pal[i].rgbRed = colors[i].r; pal[i].rgbGreen = colors[i].g; pal[i].rgbBlue = colors[i].b; pal[i].rgbReserved = 0; } /* Set the DIB palette and update the display */ mdc = CreateCompatibleDC(hdc); SelectObject(mdc, screen_bmp); SetDIBColorTable(mdc, firstcolor, ncolors, pal); if ( moved_entries || !grab_palette ) { BitBlt(hdc, 0, 0, this->screen->w, this->screen->h, mdc, 0, 0, SRCCOPY); } DeleteDC(mdc); SDL_stack_free(pal);#endif ReleaseDC(SDL_Window, hdc); return(1);}static void DIB_CheckGamma(_THIS){#ifndef NO_GAMMA_SUPPORT HDC hdc; WORD ramp[3*256]; /* If we fail to get gamma, disable gamma control */ hdc = GetDC(SDL_Window); if ( ! GetDeviceGammaRamp(hdc, ramp) ) { this->GetGammaRamp = NULL; this->SetGammaRamp = NULL; } ReleaseDC(SDL_Window, hdc);#endif /* !NO_GAMMA_SUPPORT */}void DIB_SwapGamma(_THIS){#ifndef NO_GAMMA_SUPPORT HDC hdc; if ( gamma_saved ) { hdc = GetDC(SDL_Window); if ( SDL_GetAppState() & SDL_APPINPUTFOCUS ) { /* About to leave active state, restore gamma */ SetDeviceGammaRamp(hdc, gamma_saved); } else { /* About to enter active state, set game gamma */ GetDeviceGammaRamp(hdc, gamma_saved); SetDeviceGammaRamp(hdc, this->gamma); } ReleaseDC(SDL_Window, hdc); }#endif /* !NO_GAMMA_SUPPORT */}void DIB_QuitGamma(_THIS){#ifndef NO_GAMMA_SUPPORT if ( gamma_saved ) { /* Restore the original gamma if necessary */ if ( SDL_GetAppState() & SDL_APPINPUTFOCUS ) { HDC hdc; hdc = GetDC(SDL_Window); SetDeviceGammaRamp(hdc, gamma_saved); ReleaseDC(SDL_Window, hdc); } /* Free the saved gamma memory */ SDL_free(gamma_saved); gamma_saved = 0; }#endif /* !NO_GAMMA_SUPPORT */}int DIB_SetGammaRamp(_THIS, Uint16 *ramp){#ifdef NO_GAMMA_SUPPORT SDL_SetError("SDL compiled without gamma ramp support"); return -1;#else HDC hdc; BOOL succeeded; /* Set the ramp for the display */ if ( ! gamma_saved ) { gamma_saved = (WORD *)SDL_malloc(3*256*sizeof(*gamma_saved)); if ( ! gamma_saved ) { SDL_OutOfMemory(); return -1; } hdc = GetDC(SDL_Window); GetDeviceGammaRamp(hdc, gamma_saved); ReleaseDC(SDL_Window, hdc); } if ( SDL_GetAppState() & SDL_APPINPUTFOCUS ) { hdc = GetDC(SDL_Window); succeeded = SetDeviceGammaRamp(hdc, ramp); ReleaseDC(SDL_Window, hdc); } else { succeeded = TRUE; } return succeeded ? 0 : -1;#endif /* !NO_GAMMA_SUPPORT */}int DIB_GetGammaRamp(_THIS, Uint16 *ramp){#ifdef NO_GAMMA_SUPPORT SDL_SetError("SDL compiled without gamma ramp support"); return -1;#else HDC hdc; BOOL succeeded; /* Get the ramp from the display */ hdc = GetDC(SDL_Window); succeeded = GetDeviceGammaRamp(hdc, ramp); ReleaseDC(SDL_Window, hdc); return succeeded ? 0 : -1;#endif /* !NO_GAMMA_SUPPORT */}void DIB_VideoQuit(_THIS){ int i, j; /* Destroy the window and everything associated with it */ if ( SDL_Window ) { /* Delete the screen bitmap (also frees screen->pixels) */ if ( this->screen ) { if ( grab_palette ) { DIB_ReleaseStaticColors(SDL_Window); }#ifndef NO_CHANGEDISPLAYSETTINGS if ( this->screen->flags & SDL_FULLSCREEN ) { ChangeDisplaySettings(NULL, 0); ShowWindow(SDL_Window, SW_HIDE); }#endif if ( this->screen->flags & SDL_OPENGL ) { WIN_GL_ShutDown(this); } this->screen->pixels = NULL; } if ( screen_pal != NULL ) { DeleteObject(screen_pal); screen_pal = NULL; } if ( screen_logpal != NULL ) { SDL_free(screen_logpal); screen_logpal = NULL; } if ( screen_bmp ) { DeleteObject(screen_bmp); screen_bmp = NULL; } if ( screen_icn ) { DestroyIcon(screen_icn); screen_icn = NULL; } DIB_QuitGamma(this); DIB_DestroyWindow(this); SDL_Window = NULL;#if defined(_WIN32_WCE)// Unload wince aygshell library to prevent leak if( aygshell ) { FreeLibrary(aygshell); aygshell = NULL; }#endif } for ( i=0; i < SDL_arraysize(SDL_modelist); ++i ) { if ( !SDL_modelist[i] ) { continue; } for ( j=0; SDL_modelist[i][j]; ++j ) { SDL_free(SDL_modelist[i][j]); } SDL_free(SDL_modelist[i]); SDL_modelist[i] = NULL; SDL_nummodes[i] = 0; }}/* Exported for the windows message loop only */static void DIB_GrabStaticColors(HWND window){#ifdef SYSPAL_NOSTATIC HDC hdc; hdc = GetDC(window); SetSystemPaletteUse(hdc, SYSPAL_NOSTATIC256); if ( GetSystemPaletteUse(hdc) != SYSPAL_NOSTATIC256 ) { SetSystemPaletteUse(hdc, SYSPAL_NOSTATIC); } ReleaseDC(window, hdc);#endif}static void DIB_ReleaseStaticColors(HWND window){#ifdef SYSPAL_NOSTATIC HDC hdc; hdc = GetDC(window); SetSystemPaletteUse(hdc, SYSPAL_STATIC); ReleaseDC(window, hdc);#endif}static void DIB_Activate(_THIS, BOOL active, BOOL minimized){ if ( grab_palette ) { if ( !active ) { DIB_ReleaseStaticColors(SDL_Window); DIB_RealizePalette(this); } else if ( !minimized ) { DIB_GrabStaticColors(SDL_Window); DIB_RealizePalette(this); } }}static void DIB_RealizePalette(_THIS){ if ( screen_pal != NULL ) { HDC hdc; hdc = GetDC(SDL_Window);#ifndef _WIN32_WCE UnrealizeObject(screen_pal);#endif SelectPalette(hdc, screen_pal, FALSE); if ( RealizePalette(hdc) ) { InvalidateRect(SDL_Window, NULL, FALSE); } ReleaseDC(SDL_Window, hdc); }}static void DIB_PaletteChanged(_THIS, HWND window){ if ( window != SDL_Window ) { DIB_RealizePalette(this); }}/* Exported for the windows message loop only */static void DIB_WinPAINT(_THIS, HDC hdc){ HDC mdc; if ( screen_pal ) { SelectPalette(hdc, screen_pal, FALSE); } mdc = CreateCompatibleDC(hdc); SelectObject(mdc, screen_bmp); BitBlt(hdc, 0, 0, SDL_VideoSurface->w, SDL_VideoSurface->h, mdc, 0, 0, SRCCOPY); DeleteDC(mdc);}/* Stub in case DirectX isn't available */#if !SDL_AUDIO_DRIVER_DSOUNDvoid DX5_SoundFocus(HWND hwnd){ return;}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -