📄 ui_win32.c
字号:
char *data; if (!hData) { x_error ("Out of memory"); free (c); return; } if (!(data = GlobalLock (hData))) { x_error ("Out of memory"); free (c); return; } memcpy (hData, c, strlen (c) + 1); GlobalUnlock (hData); if (OpenClipboard (hWnd)) { EmptyClipboard (); SetClipboardData (clipboard_format, hData); } free (c);}static voidwin32_paste (void){ if (OpenClipboard (hWnd)) { HANDLE hClipData; char *text; if (!(hClipData = GetClipboardData (clipboard_format))) { CloseClipboard (); return; } if (!(text = GlobalLock (hClipData))) { x_error ("Out of memory"); CloseClipboard (); } ui_loadstr (strdup (text)); GlobalUnlock (hClipData); CloseClipboard (); }}#define MAX_MENUITEMS_I18N 20static menuitem menuitems_i18n[MAX_MENUITEMS_I18N];int uiw_no_menuitems_i18n = 0, uiw_no_cutpasteitems_i18n;static menuitem *cutpasteitems;static voidadd_cutpasteitems (){ // General method (not needed currently): int no_menuitems_i18n = uiw_no_menuitems_i18n; /* This variable must be local. */ MENUSEPARATOR_I ("edit"); MENUNOP_I ("edit", NULL, gettext ("Copy"), "copy", 0, win32_copy); MENUNOP_I ("edit", NULL, gettext ("Paste"), "paste", 0, win32_paste); MENUSEPARATOR_I ("helpmenu"); MENUNOP_I ("helpmenu", NULL, gettext ("About"), "about", 0, AboutBox); no_menuitems_i18n -= uiw_no_menuitems_i18n; cutpasteitems = &(menuitems_i18n[uiw_no_menuitems_i18n]); uiw_no_cutpasteitems_i18n = no_menuitems_i18n; menu_add (cutpasteitems, uiw_no_cutpasteitems_i18n); uiw_no_menuitems_i18n += no_menuitems_i18n;}static intwin32_init (void){ int r;#ifdef DDRAW_DRIVER directX = 0;#endif r = Init (); if (!r) return r; win32_driver.textwidth = fontWidth; win32_driver.textheight = fontHeight; getres (&win32_driver.width, &win32_driver.height); win32_createrootmenu (); add_cutpasteitems (); return r;}static voidwin32_uninitialize (void){ DeInitWindow (); menu_delete (cutpasteitems, uiw_no_cutpasteitems_i18n);}static voidwin32_getsize (int *width, int *height){ resized = 0; *width = displayX; *height = displayY; switch (bitDepth) { case 8: win32_driver.imagetype = UI_C256; break; case 16: /* Windows seems to always use 15bpp mode */ win32_driver.imagetype = UI_TRUECOLOR16; win32_driver.rmask = 31 * 32 * 32; win32_driver.gmask = 31 * 32; win32_driver.bmask = 31; break; case 24: win32_driver.imagetype = UI_TRUECOLOR24; win32_driver.rmask = 0xff0000; win32_driver.gmask = 0x00ff00; win32_driver.bmask = 0x0000ff; break; case 32: win32_driver.imagetype = UI_TRUECOLOR; win32_driver.rmask = 0xff0000; win32_driver.gmask = 0x00ff00; win32_driver.bmask = 0x0000ff; break; } CalculateBITMAPINFO ();}static voidwin32_display (){ HDC hDC = GetDC (hWnd); if (IsWindowVisible (hWnd)) Paint (hDC); ReleaseDC (hWnd, hDC);}static intwin32_alloc_buffers (char **b1, char **b2){ currentbuff = 0; // calculate DWORD aligned line length lineSize = displayX * ((bitDepth + 7) / 8); lineSize += 3 - ((lineSize - 1) & 3); buffer1 = (char *) malloc (displayY * lineSize); buffer2 = (char *) malloc (displayY * lineSize); *b1 = buffer1; *b2 = buffer2; initialized = 1; return lineSize;}static voidwin32_free_buffers (char *b1, char *b2){ initialized = 0; free (buffer1); free (buffer2); buffer1 = buffer2 = NULL;}static CONST char *CONST dx_depth[] = { "8bpp (256 colors)", "16bpp (65536 colors)", "24bpp (16777216 colors)", "32bpp (16777216 colors)", NULL};#ifdef DDRAW_DRIVERstatic menudialog dx_resdialog[] = { DIALOGCHOICE ("Resolution", resstr, 0), DIALOGCHOICE ("Depth", dx_depth, 0), {NULL}};static menudialog *dx_resizedialog (struct uih_context *c){ int i; switch (bitDepth) { case 8: dx_resdialog[1].defint = 0; break; case 16: dx_resdialog[1].defint = 1; break; case 24: dx_resdialog[1].defint = 2; break; case 32: dx_resdialog[1].defint = 3; } for (i = 0; i < MAXRESOLUTIONS; i++) if (displayX == ressize[i].width && displayY == ressize[i].height) { dx_resdialog[0].defint = i; break; } return dx_resdialog;}static voiddx_resize (struct uih_context *c, dialogparam * p){ static char s[10]; CONST static char *CONST st[] = { "8", "16", "24", "32" }; sprintf (s, "%sx%s", resstr[p[0].dint], st[p[1].dint]); dxsize = s; resized = 1; ui_call_resize ();}int uiw_no_resizeitems_i18n;static menuitem *resizeitems;static voidadd_resizeitems (){ // General method, it's needed: int no_menuitems_i18n = uiw_no_menuitems_i18n; /* This variable must be local. */ MENUCDIALOG_I ("ui", "=", gettext ("Resize"), "resize", 0, dx_resize, dx_resizedialog); MENUNOP_I ("misc", NULL, "Generate .dlg files", "genresources", 0, win32_genresources); no_menuitems_i18n -= uiw_no_menuitems_i18n; resizeitems = &(menuitems_i18n[uiw_no_menuitems_i18n]); uiw_no_resizeitems_i18n = no_menuitems_i18n; menu_add (resizeitems, uiw_no_resizeitems_i18n); uiw_no_menuitems_i18n += no_menuitems_i18n;}static intdx_alloc_buffers (char **b1, char **b2){ DWORD ddrval; DDSURFACEDESC ddsd; int i; currentbuff = 0; memset (surface, 0, sizeof (DDSURFACEDESC) * 2); memset (&ddsd, 0, sizeof (DDSURFACEDESC)); ddsd.dwSize = sizeof (ddsd); if (IDirectDrawSurface_GetSurfaceDesc (lpSurfaces[0], &ddsd) != DD_OK) { DeInitDD (); x_error ("Failed to get pixel format"); return 0; } for (i = 0; i < 2; i++) { ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS; ddsd.dwWidth = displayX; ddsd.dwHeight = displayY; ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY; ddrval = IDirectDraw_CreateSurface (lpDD, &ddsd, &BackSurface[i], NULL); if (ddrval != DD_OK) { DeInitDD (); x_error ("Failed to create back surface"); return 0; } } for (i = 0; i < 2; i++) { surface[i].dwSize = sizeof (DDSURFACEDESC); ddrval = IDirectDrawSurface_Lock (BackSurface[i], NULL, surface + i, DDLOCK_WAIT, NULL); if (ddrval != DD_OK) { DeInitDD (); x_fatalerror ("Failed to lock offscreen surfaces"); } } buffer1 = *b1 = (char *) surface[0].lpSurface; buffer2 = *b2 = (char *) surface[1].lpSurface; lineSize = surface[0].u1.lPitch; initialized = 1; return lineSize;}static voiddx_free_buffers (char *b1, char *b2){ IDirectDrawSurface_Unlock (BackSurface[0], surface[0].lpSurface); IDirectDrawSurface_Unlock (BackSurface[1], surface[1].lpSurface); if (BackSurface[0]) IDirectDrawSurface_Release (BackSurface[0]); if (BackSurface[1]) IDirectDrawSurface_Release (BackSurface[1]); BackSurface[0] = NULL; BackSurface[1] = NULL; initialized = 0; buffer1 = buffer2 = NULL;}static intdx_imgparams (void){ DDSURFACEDESC s; memset (&s, 0, sizeof (s)); s.dwSize = sizeof (s); if (IDirectDrawSurface_GetSurfaceDesc (lpSurfaces[0], &s) != DD_OK) { DeInitDD (); x_error ("Failed to get pixel format"); return 0; } switch (s.ddpfPixelFormat.u1.dwRGBBitCount) { case 8: dxw_driver.imagetype = UI_C256; dxf_driver.imagetype = UI_C256; break; case 16: case 15: dxw_driver.imagetype = UI_TRUECOLOR16; dxf_driver.imagetype = UI_TRUECOLOR16; break; case 24: dxw_driver.imagetype = UI_TRUECOLOR24; dxf_driver.imagetype = UI_TRUECOLOR24; break; case 32: dxw_driver.imagetype = UI_TRUECOLOR; dxf_driver.imagetype = UI_TRUECOLOR; break; default: x_fatalerror ("Unsupported bit depth! Only 8bpp, 16bpp, 24bpp and 32bpp modes supported\n"); return 0; } dxw_driver.rmask = s.ddpfPixelFormat.u2.dwRBitMask; dxw_driver.gmask = s.ddpfPixelFormat.u3.dwGBitMask; dxw_driver.bmask = s.ddpfPixelFormat.u4.dwBBitMask; dxf_driver.rmask = s.ddpfPixelFormat.u2.dwRBitMask; dxf_driver.gmask = s.ddpfPixelFormat.u3.dwGBitMask; dxf_driver.bmask = s.ddpfPixelFormat.u4.dwBBitMask; dxf_driver.textwidth = fontWidth; dxf_driver.textheight = fontHeight; dxw_driver.textwidth = fontWidth; dxw_driver.textheight = fontHeight; return 1;}static intdxw_init (void){ int r; r = InitDD (0); if (!r) return r; if (!dx_imgparams ()) return 0; win32_createrootmenu (); getres (&dxw_driver.width, &dxw_driver.height); add_cutpasteitems (); return r;}static intdxf_init (void){ int r; getdimens (&dxf_driver.width, &dxf_driver.height); r = InitDD (1); if (!r) return r; if (!dx_imgparams ()) return 0; add_resizeitems (); add_cutpasteitems (); return r;}static voiddx_uninitialize (void){ if (directX == DXFULLSCREEN) menu_delete (resizeitems, uiw_no_resizeitems_i18n); menu_delete (cutpasteitems, uiw_no_cutpasteitems_i18n); DeInitDD ();}static voiddx_getsize (int *width, int *height){ if (resized) { resized = 0; if (!ResizeDD (directX == DXFULLSCREEN)) { DeInitDD (); x_fatalerror ("Failed to resize"); } if (!dx_imgparams ()) { DeInitDD (); x_fatalerror ("Internal program error #34234"); } } *width = displayX; *height = displayY; CalculateBITMAPINFO ();}static voiddx_mousetype (int type){ switch (type) { default: case 0: mousepointer = mouse_pointer_data; break; case 1: mousepointer = wait_pointer_data; break; case 2: mousepointer = replay_pointer_data; break; } UpdateMouseDD ();}#endifvoidwin32_help (struct uih_context *c, CONST char *name){ FILE *f; char *n; if (helpname == NULL) { if (!strcmp (name, "main")) name = "Contents"; if (directX == DXFULLSCREEN) ShowWindow (hWnd, SW_MINIMIZE); n = xio_fixpath ("\01\\help\\xaoswin.hlp"); if ((f = fopen (n, "r"))) { fclose (f); } else { free (n); n = xio_fixpath ("\01\\..\\help\\xaoswin.hlp"); if ((f = fopen (n, "r"))) { fclose (f); } else n = strdup ("..\\help\\xaoswin.hlp"); } helpname = n; } if (!WinHelp (hWnd, helpname, HELP_PARTIALKEY, (ULONG) (CONST char *) name)) { x_error ("Failed to start WinHelp on topic %s", name); }}static struct params params[] = { {"", P_HELP, NULL, "Win32 driver options:"}, {"-size", P_STRING, &size, "Window size in format WIDTHxHEIGHT (320x200)"}, {NULL, 0, NULL, NULL}};static struct params dxfparams[] = { {"", P_HELP, NULL, "DirectX fullscreen driver options:"}, {"-mode", P_STRING, &dxsize, "Select preffered graphics mode in format WIDTHxHEIGHTxDEPTH (320x200x8)"}, {NULL, 0, NULL, NULL}};static struct params dxwparams[] = { {"", P_HELP, NULL, "DirectX windowed driver options:"}, {"-size", P_STRING, &size, "Window size in format WIDTHxHEIGHT (320x200)"}, {NULL, 0, NULL, NULL}};extern int XaoS_main (int argc, char **argv);int STDCALLWinMain (HINSTANCE hInstance1, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){ static char name0[256]; static char *argv[256]; int argc = 1; int i; GetModuleFileName (hInstance1, name0, 256); /* Allocate everything virtually - be on the safe side */ argv[0] = strdup (name0); lpCmdLine = strdup (lpCmdLine); for (i = 0; lpCmdLine[i]; i++) { if (lpCmdLine[i] == ' ' || lpCmdLine[i] == '\t') lpCmdLine[i] = 0; else if (!i || !lpCmdLine[i - 1]) argv[argc] = lpCmdLine + i, argc++; } hInstance = hInstance1; return XaoS_main (argc, argv);}static CONST struct gui_driver win32_gui_driver = { win32_dorootmenu, win32_enabledisable, win32_menu, win32_dialog, win32_help};static CONST struct gui_driver win32_fullscreen_gui_driver = { NULL, NULL, NULL, NULL, win32_help};struct ui_driver win32_driver = { "win32", win32_init, win32_getsize, processevents, getmouse, win32_uninitialize, NULL, // win32_set_color, set_palette, print, win32_display, win32_alloc_buffers, win32_free_buffers, flip_buffers, mousetype, NULL, 16 + 16, 12, params, PIXELSIZE | UPDATE_AFTER_PALETTE, 0.0, 0.0, 0, 0, UI_C256, 0, 256, 255, 0, 0, 0, &win32_gui_driver};#ifdef DDRAW_DRIVERstruct ui_driver dxw_driver = { "dX-window", dxw_init, dx_getsize, processevents, getmouse, dx_uninitialize, NULL, // dx_set_color, set_palette, print, PaintDD, dx_alloc_buffers, dx_free_buffers, flip_buffers, mousetype, NULL, 16 + 16, 12, dxwparams, PIXELSIZE, 0.0, 0.0, 0, 0, UI_C256, 0, 256, 255, 0, 0, 0, &win32_gui_driver};struct ui_driver dxf_driver = { "dX-fullscreen", dxf_init, dx_getsize, processevents, getmouse, dx_uninitialize, NULL, // dx_set_color, set_palette, print, PaintDD, dx_alloc_buffers, dx_free_buffers, flip_buffers, dx_mousetype, NULL, 16 + 16, 12, dxfparams, FULLSCREEN | SCREENSIZE, 0.0, 0.0, 0, 0, UI_C256, 0, 256, 255, 0, 0, 0, &win32_fullscreen_gui_driver};#endifvoidx_message (const char *text, ...){ va_list ap; char buf[4096]; va_start (ap, text); vsprintf (buf, text, ap); if (directX == DXFULLSCREEN) ShowWindow (hWnd, SW_MINIMIZE); MessageBox (NULL, buf, "XaoS", MB_OK | MB_ICONINFORMATION); va_end (ap);}voidx_error (const char *text, ...){ va_list ap; char buf[4096]; va_start (ap, text); vsprintf (buf, text, ap); if (directX == DXFULLSCREEN) ShowWindow (hWnd, SW_MINIMIZE); MessageBox (NULL, buf, "XaoS have problem", MB_OK | MB_ICONEXCLAMATION); va_end (ap);}voidx_fatalerror (const char *text, ...){ va_list ap; char buf[4096]; va_start (ap, text); vsprintf (buf, text, ap); if (directX == DXFULLSCREEN) ShowWindow (hWnd, SW_MINIMIZE); MessageBox (NULL, buf, "Unrecovable XaoS error", MB_OK | MB_ICONSTOP); va_end (ap); exit (1);}#endif /* WIN32_DRIVER */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -