📄 grwin32.c
字号:
LOG(( " -- output bitmap =\n" ));
LOG(( " -- mode = %d\n", bitmap->mode ));
LOG(( " -- grays = %d\n", bitmap->grays ));
LOG(( " -- width = %d\n", bitmap->width ));
LOG(( " -- height = %d\n", bitmap->rows ));
bitmap->pitch = -bitmap->pitch;
surface->root.bitmap = *bitmap;
/* initialize the header to appropriate values */
memset( pbmi, 0, sizeof ( BITMAPINFO ) + sizeof ( RGBQUAD ) * 256 );
pbmi->bmiHeader.biSize = sizeof ( BITMAPINFOHEADER );
pbmi->bmiHeader.biWidth = bitmap->width;
pbmi->bmiHeader.biHeight = bitmap->rows;
pbmi->bmiHeader.biPlanes = 1;
switch ( bitmap->mode )
{
case gr_pixel_mode_mono:
pbmi->bmiHeader.biBitCount = 1;
pbmi->bmiColors[0] = white;
pbmi->bmiColors[1] = black;
break;
case gr_pixel_mode_rgb24:
pbmi->bmiHeader.biBitCount = 24;
pbmi->bmiHeader.biCompression = BI_RGB;
break;
case gr_pixel_mode_gray:
pbmi->bmiHeader.biBitCount = 8;
pbmi->bmiHeader.biClrUsed = bitmap->grays;
{
int count = bitmap->grays;
int x;
RGBQUAD* color = pbmi->bmiColors;
for ( x = 0; x < count; x++, color++ )
{
color->rgbRed =
color->rgbGreen =
color->rgbBlue = (unsigned char)(((count-x)*255)/count);
color->rgbReserved = 0;
}
}
break;
default:
return 0; /* Unknown mode */
}
surface->window_width = bitmap->width;
surface->window_height = bitmap->rows;
surface->window = CreateWindow(
/* LPCSTR lpszClassName; */ "FreeTypeTestGraphicDriver",
/* LPCSTR lpszWindowName; */ "FreeType Test Graphic Driver",
/* DWORD dwStyle; */ WS_OVERLAPPED | WS_SYSMENU,
/* int x; */ CW_USEDEFAULT,
/* int y; */ CW_USEDEFAULT,
/* int nWidth; */ bitmap->width + 2*GetSystemMetrics(SM_CXBORDER),
/* int nHeight; */ bitmap->rows + GetSystemMetrics(SM_CYBORDER)
+ GetSystemMetrics(SM_CYCAPTION),
/* HWND hwndParent; */ HWND_DESKTOP,
/* HMENU hmenu; */ 0,
/* HINSTANCE hinst; */ GetModuleHandle( NULL ),
/* void FAR* lpvParam; */ surface );
if ( surface->window == 0 )
return 0;
surface->root.done = (grDoneSurfaceFunc) gr_win32_surface_done;
surface->root.refresh_rect = (grRefreshRectFunc) gr_win32_surface_refresh_rectangle;
surface->root.set_title = (grSetTitleFunc) gr_win32_surface_set_title;
surface->root.listen_event = (grListenEventFunc) gr_win32_surface_listen_event;
return surface;
}
/* ---- Windows-specific stuff ------------------------------------------- */
/* Message processing for our Windows class */
LRESULT CALLBACK Message_Process( HWND handle, UINT mess,
WPARAM wParam, LPARAM lParam )
{
grWin32Surface* surface = NULL;
if ( mess == WM_CREATE )
{
/* WM_CREATE is the first message sent to this function, and the */
/* surface handle is available from the 'lParam' parameter. We */
/* save its value in a window property.. */
/* */
surface = ((LPCREATESTRUCT)lParam)->lpCreateParams;
SetProp( handle, (LPCSTR)(LONG)ourAtom, surface );
}
else
{
/* for other calls, we retrieve the surface handle from the window */
/* property.. ugly, isn't it ?? */
/* */
surface = (grWin32Surface*) GetProp( handle, (LPCSTR)(LONG)ourAtom );
}
switch( mess )
{
case WM_DESTROY:
/* warn the main thread to quit if it didn't know */
surface->ourevent.type = gr_event_key;
surface->ourevent.key = grKeyEsc;
surface->eventToProcess = 1;
surface->window = 0;
PostQuitMessage ( 0 );
DeleteObject ( surface->hbm );
return 0;
case WM_CREATE:
{
HDC hDC;
LPBITMAPINFO pbmi = surface->pbmi;
hDC = GetDC ( handle );
surface->hbm = CreateDIBitmap (
/* HDC hdc; handle of device context */ hDC,
/* BITMAPINFOHEADER FAR* lpbmih; addr.of header*/ &pbmi->bmiHeader,
/* DWORD dwInit; CBM_INIT to initialize bitmap */ 0,
/* const void FAR* lpvBits; address of values */ NULL,
/* BITMAPINFO FAR* lpbmi; addr.of bitmap data */ pbmi,
/* UINT fnColorUse; RGB or palette indices */ DIB_RGB_COLORS);
ReleaseDC ( handle, hDC );
break;
}
case WM_PAINT:
{
HDC hDC, memDC;
HANDLE oldbm;
PAINTSTRUCT ps;
hDC = BeginPaint ( handle, &ps );
memDC = CreateCompatibleDC( hDC );
oldbm = SelectObject( memDC, surface->hbm );
BitBlt ( hDC, 0, 0, surface->window_width, surface->window_height,
memDC, 0, 0, SRCCOPY);
ReleaseDC ( handle, hDC );
SelectObject ( memDC, oldbm );
DeleteObject ( memDC );
EndPaint ( handle, &ps );
return 0;
}
case WM_SYSKEYDOWN:
{
int count = sizeof( syskey_translators )/sizeof( syskey_translators[0] );
Translator* trans = syskey_translators;
Translator* limit = trans + count;
for ( ; trans < limit; trans++ )
if ( wParam == trans->winkey )
{
surface->ourevent.key = trans->grkey;
goto Do_Key_Event;
}
return DefWindowProc( handle, mess, wParam, lParam );
}
case WM_KEYDOWN:
switch ( wParam )
{
case VK_ESCAPE:
surface->ourevent.type = gr_event_key;
surface->ourevent.key = grKeyEsc;
surface->eventToProcess = 1;
PostQuitMessage ( 0 );
return 0;
default:
/* lookup list of translated keys */
{
int count = sizeof( key_translators )/sizeof( key_translators[0] );
Translator* trans = key_translators;
Translator* limit = trans + count;
for ( ; trans < limit; trans++ )
if ( wParam == trans->winkey )
{
surface->ourevent.key = trans->grkey;
goto Do_Key_Event;
}
}
/* the key isn't found, default processing */
/* return DefWindowProc( handle, mess, wParam, lParam ); */
return DefWindowProc( handle, mess, wParam, lParam );
}
case WM_CHAR:
{
surface->ourevent.key = wParam;
Do_Key_Event:
surface->ourevent.type = gr_event_key;
surface->eventToProcess = 1;
}
break;
default:
return DefWindowProc( handle, mess, wParam, lParam );
}
return 0;
}
static int
gr_win32_device_init( void )
{
WNDCLASS ourClass = {
/* UINT style */ 0,
/* WNDPROC lpfnWndProc */ Message_Process,
/* int cbClsExtra */ 0,
/* int cbWndExtra */ 0,
/* HANDLE hInstance */ 0,
/* HICON hIcon */ 0,
/* HCURSOR hCursor */ 0,
/* HBRUSH hbrBackground*/ 0,
/* LPCTSTR lpszMenuName */ NULL,
/* LPCTSTR lpszClassName*/ "FreeTypeTestGraphicDriver"
};
/* register window class */
ourClass.hInstance = GetModuleHandle( NULL );
ourClass.hIcon = LoadIcon(0, IDI_APPLICATION);
ourClass.hCursor = LoadCursor(0, IDC_ARROW);
ourClass.hbrBackground= GetStockObject(BLACK_BRUSH);
if ( RegisterClass(&ourClass) == 0 )
return -1;
/* add global atom */
ourAtom = GlobalAddAtom( "FreeType.Surface" );
return 0;
}
static void
gr_win32_device_done( void )
{
GlobalDeleteAtom( ourAtom );
}
grDevice gr_win32_device =
{
sizeof( grWin32Surface ),
"win32",
gr_win32_device_init,
gr_win32_device_done,
(grDeviceInitSurfaceFunc) gr_win32_surface_init,
0,
0
};
/* End */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -