X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/puzzles/blobdiff_plain/60aa1c7413ef8ba2c4889628170f00bf180039f0..63ed24043747435fc5b67339248426ca236e0739:/windows.c diff --git a/windows.c b/windows.c index 32c3322..2a2262b 100644 --- a/windows.c +++ b/windows.c @@ -195,6 +195,7 @@ struct frontend { HBRUSH *brushes; HPEN *pens; HRGN clip; + HMENU gamemenu, typemenu; UINT timer; DWORD timer_last_tickcount; int npresets; @@ -220,6 +221,9 @@ struct frontend { int xmin, ymin; }; +static void update_type_menu_tick(frontend *fe); +static void update_copy_menu_greying(frontend *fe); + void fatal(char *fmt, ...) { char buf[2048]; @@ -584,10 +588,11 @@ static void win_draw_text(void *handle, int x, int y, int fonttype, xy.y -= tm.tmAscent; } #ifndef _WIN32_WCE - if (GetTextExtentPoint32(fe->hdc, text, strlen(text), &size)) { + if (GetTextExtentPoint32(fe->hdc, text, strlen(text), &size)) #else - if (GetTextExtentPoint32(fe->hdc, wText, wcslen(wText), &size)) { + if (GetTextExtentPoint32(fe->hdc, wText, wcslen(wText), &size)) #endif + { if (align & ALIGN_HCENTRE) xy.x -= size.cx / 2; else if (align & ALIGN_HRIGHT) @@ -834,7 +839,7 @@ static void win_begin_puzzle(void *handle, float xm, float xc, * Work out what that comes to in pixels. */ pox = (int)(mmox * (float)ppw / mmpw); - poy = (int)(mmoy * (float)ppw / mmpw); + poy = (int)(mmoy * (float)pph / mmph); /* * And determine the scale. @@ -1569,6 +1574,7 @@ static frontend *new_window(HINSTANCE inst, char *game_id, char **error) HMENU menu = SHGetSubMenu(SHFindMenuBar(fe->hwnd), ID_GAME); DeleteMenu(menu, 0, MF_BYPOSITION); #endif + fe->gamemenu = menu; AppendMenu(menu, MF_ENABLED, IDM_NEW, TEXT("&New")); AppendMenu(menu, MF_ENABLED, IDM_RESTART, TEXT("&Restart")); #ifndef _WIN32_WCE @@ -1613,7 +1619,10 @@ static frontend *new_window(HINSTANCE inst, char *game_id, char **error) if (thegame.can_configure) { AppendMenu(sub, MF_ENABLED, IDM_CONFIG, TEXT("&Custom...")); } - } + + fe->typemenu = sub; + } else + fe->typemenu = INVALID_HANDLE_VALUE; AppendMenu(menu, MF_SEPARATOR, 0, 0); #ifndef _WIN32_WCE @@ -1628,7 +1637,7 @@ static frontend *new_window(HINSTANCE inst, char *game_id, char **error) AppendMenu(menu, MF_ENABLED, IDM_UNDO, TEXT("Undo")); AppendMenu(menu, MF_ENABLED, IDM_REDO, TEXT("Redo")); #ifndef _WIN32_WCE - if (thegame.can_format_as_text) { + if (thegame.can_format_as_text_ever) { AppendMenu(menu, MF_SEPARATOR, 0, 0); AppendMenu(menu, MF_ENABLED, IDM_COPY, TEXT("&Copy")); } @@ -1672,6 +1681,9 @@ static frontend *new_window(HINSTANCE inst, char *game_id, char **error) ShowWindow(fe->hwnd, SW_SHOWNORMAL); SetForegroundWindow(fe->hwnd); + update_type_menu_tick(fe); + update_copy_menu_greying(fe); + midend_redraw(fe->me); return fe; @@ -2628,10 +2640,39 @@ static void adjust_game_size(frontend *fe, RECT *proposed, int isedge, *wx_r = wx; *wy_r = wy; } +static void update_type_menu_tick(frontend *fe) +{ + int total, n, i; + + if (fe->typemenu == INVALID_HANDLE_VALUE) + return; + + total = GetMenuItemCount(fe->typemenu); + n = midend_which_preset(fe->me); + if (n < 0) + n = total - 1; /* "Custom" item */ + + for (i = 0; i < total; i++) { + int flag = (i == n ? MF_CHECKED : MF_UNCHECKED); + CheckMenuItem(fe->typemenu, i, MF_BYPOSITION | flag); + } + + DrawMenuBar(fe->hwnd); +} + +static void update_copy_menu_greying(frontend *fe) +{ + UINT enable = (midend_can_format_as_text_now(fe->me) ? + MF_ENABLED : MF_GRAYED); + EnableMenuItem(fe->gamemenu, IDM_COPY, MF_BYCOMMAND | enable); +} + static void new_game_type(frontend *fe) { midend_new_game(fe->me); new_game_size(fe); + update_type_menu_tick(fe); + update_copy_menu_greying(fe); } static int is_alt_pressed(void)