X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/puzzles/blobdiff_plain/8c1fd9740e4de65fff05f3635491e23d67d065e8..11c44cf574b43cec747d490cb264829a535ed42a:/windows.c diff --git a/windows.c b/windows.c index 90d96d2..80a929d 100644 --- a/windows.c +++ b/windows.c @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -309,7 +310,7 @@ void activate_timer(frontend *fe) } } -static frontend *new_window(HINSTANCE inst) +static frontend *new_window(HINSTANCE inst, char *game_id, char **error) { frontend *fe; int x, y; @@ -322,12 +323,24 @@ static frontend *new_window(HINSTANCE inst) time(&t); fe->me = midend_new(fe, &t, sizeof(t)); + if (game_id) { + *error = midend_game_id(fe->me, game_id, FALSE); + if (*error) { + midend_free(fe->me); + sfree(fe); + return NULL; + } + } + fe->inst = inst; midend_new_game(fe->me); midend_size(fe->me, &x, &y); fe->timer = 0; + fe->fonts = NULL; + fe->nfonts = fe->fontsize = 0; + { int i, ncolours; float *colours; @@ -684,6 +697,7 @@ static int get_config(frontend *fe, int which) mkctrl(fe, col1l, col2r, y, y+height, "BUTTON", BS_NOTIFY | BS_AUTOCHECKBOX | WS_TABSTOP, 0, i->name, (j->ctlid = id++)); + CheckDlgButton(fe->cfgbox, j->ctlid, (i->ival != 0)); y += height; break; @@ -935,7 +949,50 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, button = LEFT_BUTTON; else button = RIGHT_BUTTON; - + + if (!midend_process_key(fe->me, LOWORD(lParam), + HIWORD(lParam), button)) + PostQuitMessage(0); + + SetCapture(hwnd); + } + break; + case WM_LBUTTONUP: + case WM_RBUTTONUP: + case WM_MBUTTONUP: + { + int button; + + /* + * Shift-clicks count as middle-clicks, since otherwise + * two-button Windows users won't have any kind of + * middle click to use. + */ + if (message == WM_MBUTTONUP || (wParam & MK_SHIFT)) + button = MIDDLE_RELEASE; + else if (message == WM_LBUTTONUP) + button = LEFT_RELEASE; + else + button = RIGHT_RELEASE; + + if (!midend_process_key(fe->me, LOWORD(lParam), + HIWORD(lParam), button)) + PostQuitMessage(0); + + ReleaseCapture(); + } + break; + case WM_MOUSEMOVE: + { + int button; + + if (wParam & (MK_MBUTTON | MK_SHIFT)) + button = MIDDLE_DRAG; + else if (wParam & MK_LBUTTON) + button = LEFT_DRAG; + else + button = RIGHT_DRAG; + if (!midend_process_key(fe->me, LOWORD(lParam), HIWORD(lParam), button)) PostQuitMessage(0); @@ -961,6 +1018,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) { MSG msg; + char *error; InitCommonControls(); @@ -981,7 +1039,15 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) RegisterClass(&wndclass); } - new_window(inst); + while (*cmdline && isspace(*cmdline)) + cmdline++; + + if (!new_window(inst, *cmdline ? cmdline : NULL, &error)) { + char buf[128]; + sprintf(buf, "%.100s Error", game_name); + MessageBox(NULL, error, buf, MB_OK|MB_ICONERROR); + return 1; + } while (GetMessage(&msg, NULL, 0, 0)) { DispatchMessage(&msg);