⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sdl_dibvideo.c

📁 Simple DirectMedia Layer - Simple DirectMedia Layer 是一个跨平台的多媒体库设计用来提供快速图形framebuffer和音频驱动。应用MPEG为软件
💻 C
📖 第 1 页 / 共 2 页
字号:
				Bmask = 0x00000000;				break;		}		video = SDL_CreateRGBSurface(SDL_SWSURFACE,					0, 0, bpp, Rmask, Gmask, Bmask, 0);		if ( video == NULL ) {			SDL_OutOfMemory();			return(NULL);		}	}	/* Fill in part of the video surface */	prev_flags = video->flags;	video->flags = 0;	/* Clear flags */	video->w = width;	video->h = height;	video->pitch = SDL_CalculatePitch(video);#ifdef WIN32_PLATFORM_PSPC	 /* Stuff to hide that $#!^%#$ WinCE taskbar in fullscreen... */	if ( flags & SDL_FULLSCREEN ) {		if ( !(prev_flags & SDL_FULLSCREEN) ) {			SHFullScreen(SDL_Window, SHFS_HIDETASKBAR);			SHFullScreen(SDL_Window, SHFS_HIDESIPBUTTON);			ShowWindow(FindWindow(TEXT("HHTaskBar"),NULL),SW_HIDE);		}		video->flags |= SDL_FULLSCREEN;	} else {		if ( prev_flags & SDL_FULLSCREEN ) {			SHFullScreen(SDL_Window, SHFS_SHOWTASKBAR);			SHFullScreen(SDL_Window, SHFS_SHOWSIPBUTTON);			ShowWindow(FindWindow(TEXT("HHTaskBar"),NULL),SW_SHOWNORMAL);		}	}#endif#ifndef NO_CHANGEDISPLAYSETTINGS	/* Set fullscreen mode if appropriate */	if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) {		DEVMODE settings;		memset(&settings, 0, sizeof(DEVMODE));		settings.dmSize = sizeof(DEVMODE);		settings.dmBitsPerPel = video->format->BitsPerPixel;		settings.dmPelsWidth = width;		settings.dmPelsHeight = height;		settings.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL;		if ( ChangeDisplaySettings(&settings, CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL ) {			video->flags |= SDL_FULLSCREEN;			SDL_fullscreen_mode = settings;		}	}#endif /* !NO_CHANGEDISPLAYSETTINGS */	/* Reset the palette and create a new one if necessary */	if ( screen_pal != NULL ) {	/*	RJR: March 28, 2000		delete identity palette if switching from a palettized mode */		DeleteObject(screen_pal);		screen_pal = NULL;	}	if ( bpp <= 8 )	{	/*	RJR: March 28, 2000		create identity palette switching to a palettized mode */		screen_pal = DIB_CreatePalette(bpp);	}	style = GetWindowLong(SDL_Window, GWL_STYLE);	style &= ~(resizestyle|WS_MAXIMIZE);	if ( (video->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) {		style &= ~windowstyle;		style |= directstyle;	} else {#ifndef NO_CHANGEDISPLAYSETTINGS		if ( (prev_flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) {			ChangeDisplaySettings(NULL, 0);		}#endif		if ( flags & SDL_NOFRAME ) {			style &= ~windowstyle;			style |= directstyle;			video->flags |= SDL_NOFRAME;		} else {			style &= ~directstyle;			style |= windowstyle;			if ( flags & SDL_RESIZABLE ) {				style |= resizestyle;				video->flags |= SDL_RESIZABLE;			}		}#if WS_MAXIMIZE		if (IsZoomed(SDL_Window)) style |= WS_MAXIMIZE;#endif	}	/* DJM: Don't piss of anyone who has setup his own window */	if (!SDL_windowid)		SetWindowLong(SDL_Window, GWL_STYLE, style);	/* Delete the old bitmap if necessary */	if ( screen_bmp != NULL ) {		DeleteObject(screen_bmp);	}	if ( ! (flags & SDL_OPENGL) ) {		BOOL is16bitmode = (video->format->BytesPerPixel == 2);		/* Suss out the bitmap info header */		binfo_size = sizeof(*binfo);		if( is16bitmode ) {			/* 16bit modes, palette area used for rgb bitmasks */			binfo_size += 3*sizeof(DWORD);		} else if ( video->format->palette ) {			binfo_size += video->format->palette->ncolors *							sizeof(RGBQUAD);		}		binfo = (BITMAPINFO *)malloc(binfo_size);		if ( ! binfo ) {			if ( video != current ) {				SDL_FreeSurface(video);			}			SDL_OutOfMemory();			return(NULL);		}		binfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);		binfo->bmiHeader.biWidth = video->w;		binfo->bmiHeader.biHeight = -video->h;	/* -ve for topdown bitmap */		binfo->bmiHeader.biPlanes = 1;		binfo->bmiHeader.biSizeImage = video->h * video->pitch;		binfo->bmiHeader.biXPelsPerMeter = 0;		binfo->bmiHeader.biYPelsPerMeter = 0;		binfo->bmiHeader.biClrUsed = 0;		binfo->bmiHeader.biClrImportant = 0;		binfo->bmiHeader.biBitCount = video->format->BitsPerPixel;		if ( is16bitmode ) {			/* BI_BITFIELDS tells CreateDIBSection about the rgb masks in the palette */			binfo->bmiHeader.biCompression = BI_BITFIELDS;			((Uint32*)binfo->bmiColors)[0] = video->format->Rmask;			((Uint32*)binfo->bmiColors)[1] = video->format->Gmask;			((Uint32*)binfo->bmiColors)[2] = video->format->Bmask;		} else {			binfo->bmiHeader.biCompression = BI_RGB;	/* BI_BITFIELDS for 565 vs 555 */			if ( video->format->palette ) {				memset(binfo->bmiColors, 0,					video->format->palette->ncolors*sizeof(RGBQUAD));			}		}		/* Create the offscreen bitmap buffer */		hdc = GetDC(SDL_Window);		screen_bmp = CreateDIBSection(hdc, binfo, DIB_RGB_COLORS,					(void **)(&video->pixels), NULL, 0);		ReleaseDC(SDL_Window, hdc);		free(binfo);		if ( screen_bmp == NULL ) {			if ( video != current ) {				SDL_FreeSurface(video);			}			SDL_SetError("Couldn't create DIB section");			return(NULL);		}		this->UpdateRects = DIB_NormalUpdate;		/* Set video surface flags */		if ( bpp <= 8 ) {			/* BitBlt() maps colors for us */			video->flags |= SDL_HWPALETTE;		}	}	/* Resize the window */	if ( SDL_windowid == NULL ) {		HWND top;		UINT swp_flags;		SDL_resizing = 1;		bounds.left = 0;		bounds.top = 0;		bounds.right = video->w;		bounds.bottom = video->h;		AdjustWindowRectEx(&bounds, GetWindowLong(SDL_Window, GWL_STYLE), FALSE, 0);		width = bounds.right-bounds.left;		height = bounds.bottom-bounds.top;		x = (GetSystemMetrics(SM_CXSCREEN)-width)/2;		y = (GetSystemMetrics(SM_CYSCREEN)-height)/2;		if ( y < 0 ) { /* Cover up title bar for more client area */			y -= GetSystemMetrics(SM_CYCAPTION)/2;		}		swp_flags = (SWP_NOCOPYBITS | SWP_FRAMECHANGED | SWP_SHOWWINDOW);		if ( was_visible && !(flags & SDL_FULLSCREEN) ) {			swp_flags |= SWP_NOMOVE;		}		if ( flags & SDL_FULLSCREEN ) {			top = HWND_TOPMOST;		} else {			top = HWND_NOTOPMOST;		}		SetWindowPos(SDL_Window, top, x, y, width, height, swp_flags);		SDL_resizing = 0;		SetForegroundWindow(SDL_Window);	}	/* Set up for OpenGL */	if ( flags & SDL_OPENGL ) {		if ( WIN_GL_SetupWindow(this) < 0 ) {			return(NULL);		}		video->flags |= SDL_OPENGL;	}	/* 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);}int DIB_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors){	RGBQUAD *pal;	int i;#ifndef _WIN32_WCE	HDC hdc, mdc;#else	HDC hdc;#endif	/* Update the display palette */	hdc = GetDC(SDL_Window);	if ( screen_pal ) {		PALETTEENTRY *entries;		entries = (PALETTEENTRY *)alloca(ncolors*sizeof(PALETTEENTRY));		for ( i=0; i<ncolors; ++i ) {			entries[i].peRed   = colors[i].r;			entries[i].peGreen = colors[i].g;			entries[i].peBlue  = colors[i].b;			entries[i].peFlags = PC_NOCOLLAPSE;		}		SetPaletteEntries(screen_pal, firstcolor, ncolors, entries);		SelectPalette(hdc, screen_pal, FALSE);		RealizePalette(hdc);	}	/* Copy palette colors into DIB palette */	pal = (RGBQUAD *)alloca(ncolors*sizeof(RGBQUAD));	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 */#ifndef _WIN32_WCE	mdc = CreateCompatibleDC(hdc);	SelectObject(mdc, screen_bmp);	SetDIBColorTable(mdc, firstcolor, ncolors, pal);	BitBlt(hdc, 0, 0, this->screen->w, this->screen->h,	       mdc, 0, 0, SRCCOPY);	DeleteDC(mdc);#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 */		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 *)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 */}static void FlushMessageQueue(){	MSG  msg;	while ( PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) ) {		if ( msg.message == WM_QUIT ) break;		TranslateMessage( &msg );		DispatchMessage( &msg );	}}void DIB_VideoQuit(_THIS){	/* Destroy the window and everything associated with it */	if ( SDL_Window ) {		/* Delete the screen bitmap (also frees screen->pixels) */		if ( this->screen ) {#ifdef WIN32_PLATFORM_PSPC			if ( this->screen->flags & SDL_FULLSCREEN ) {				/* Unhide taskbar, etc. */				SHFullScreen(SDL_Window, SHFS_SHOWTASKBAR);				SHFullScreen(SDL_Window, SHFS_SHOWSIPBUTTON);				ShowWindow(FindWindow(TEXT("HHTaskBar"),NULL),SW_SHOWNORMAL);			}#endif#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_bmp ) {			DeleteObject(screen_bmp);			screen_bmp = NULL;		}		if ( screen_icn ) {			DestroyIcon(screen_icn);			screen_icn = NULL;		}		DIB_QuitGamma(this);		DIB_DestroyWindow(this);		FlushMessageQueue();		SDL_Window = NULL;	}}/* Exported for the windows message loop only */static void DIB_FocusPalette(_THIS, int foreground){	if ( screen_pal != NULL ) {		HDC hdc;		hdc = GetDC(SDL_Window);		SelectPalette(hdc, screen_pal, FALSE);		if ( RealizePalette(hdc) )			InvalidateRect(SDL_Window, NULL, FALSE);		ReleaseDC(SDL_Window, hdc);	}}static void DIB_RealizePalette(_THIS){	DIB_FocusPalette(this, 1);}static void DIB_PaletteChanged(_THIS, HWND window){	if ( window != SDL_Window ) {		DIB_FocusPalette(this, 0);	}}/* 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 */#ifndef ENABLE_DIRECTXvoid DX5_SoundFocus(HWND hwnd){	return;}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -