X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/puzzles/blobdiff_plain/6b12623f922c0fb69ccdc553652984933a6226c4..d3fc6146c0fd38562c28eac50bc932b2992b97a5:/windows.c diff --git a/windows.c b/windows.c index 1117ade..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]; @@ -398,12 +402,14 @@ static void win_text_colour(frontend *fe, int colour) if (fe->drawstatus == PRINTING) { int hatch; float r, g, b; - print_get_colour(fe->dr, colour, &hatch, &r, &g, &b); - if (fe->printcolour) - SetTextColor(fe->hdc, RGB(r * 255, g * 255, b * 255)); - else - SetTextColor(fe->hdc, - hatch == HATCH_CLEAR ? RGB(255,255,255) : RGB(0,0,0)); + print_get_colour(fe->dr, colour, fe->printcolour, &hatch, &r, &g, &b); + + /* + * Displaying text in hatched colours is not permitted. + */ + assert(hatch < 0); + + SetTextColor(fe->hdc, RGB(r * 255, g * 255, b * 255)); } else { SetTextColor(fe->hdc, fe->colours[colour]); } @@ -417,14 +423,10 @@ static void win_set_brush(frontend *fe, int colour) if (fe->drawstatus == PRINTING) { int hatch; float r, g, b; - print_get_colour(fe->dr, colour, &hatch, &r, &g, &b); + print_get_colour(fe->dr, colour, fe->printcolour, &hatch, &r, &g, &b); - if (fe->printcolour) { + if (hatch < 0) { br = CreateSolidBrush(RGB(r * 255, g * 255, b * 255)); - } else if (hatch == HATCH_SOLID) { - br = CreateSolidBrush(RGB(0,0,0)); - } else if (hatch == HATCH_CLEAR) { - br = CreateSolidBrush(RGB(255,255,255)); } else { #ifdef _WIN32_WCE /* @@ -469,18 +471,12 @@ static void win_set_pen(frontend *fe, int colour, int thin) float r, g, b; int width = thin ? 0 : fe->linewidth; - print_get_colour(fe->dr, colour, &hatch, &r, &g, &b); - if (fe->printcolour) - pen = CreatePen(PS_SOLID, width, - RGB(r * 255, g * 255, b * 255)); - else if (hatch == HATCH_SOLID) - pen = CreatePen(PS_SOLID, width, RGB(0, 0, 0)); - else if (hatch == HATCH_CLEAR) - pen = CreatePen(PS_SOLID, width, RGB(255,255,255)); - else { - assert(!"This shouldn't happen"); - pen = CreatePen(PS_SOLID, 1, RGB(0, 0, 0)); - } + print_get_colour(fe->dr, colour, fe->printcolour, &hatch, &r, &g, &b); + /* + * Stroking in hatched colours is not permitted. + */ + assert(hatch < 0); + pen = CreatePen(PS_SOLID, width, RGB(r * 255, g * 255, b * 255)); } else { pen = fe->pens[colour]; } @@ -592,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) @@ -842,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. @@ -1312,7 +1309,7 @@ static void get_menu_size(HWND wh, RECT *r) static int check_window_resize(frontend *fe, int cx, int cy, int *px, int *py, - int *wx, int *wy, int expand) + int *wx, int *wy, int resize) { RECT r; int x, y, sy = get_statusbar_height(fe), changed = 0; @@ -1325,7 +1322,7 @@ static int check_window_resize(frontend *fe, int cx, int cy, * See if we actually got the window size we wanted, and adjust * the puzzle size if not. */ - midend_size(fe->me, &x, &y, expand); + midend_size(fe->me, &x, &y, resize); if (x != cx || y != cy) { /* * Resize the window, now we know what size we _really_ @@ -1577,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 @@ -1621,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 @@ -1636,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")); } @@ -1659,7 +1660,7 @@ static frontend *new_window(HINSTANCE inst, char *game_id, char **error) if (help_topic) { char *item; assert(thegame.name); - item = snewn(9+strlen(thegame.name), char); /*ick*/ + item = snewn(10+strlen(thegame.name), char); /*ick*/ sprintf(item, "&Help on %s", thegame.name); AppendMenu(menu, MF_ENABLED, IDM_GAMEHELP, item); sfree(item); @@ -1680,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; @@ -2222,7 +2226,7 @@ static void about(frontend *fe) y += height/2; /* extra space before OK */ mkctrl(fe, width*2, maxwid+width*2, y, y+height*7/4, "BUTTON", - BS_PUSHBUTTON | BS_NOTIFY | WS_TABSTOP | BS_DEFPUSHBUTTON, 0, + BS_PUSHBUTTON | WS_TABSTOP | BS_DEFPUSHBUTTON, 0, "OK", IDOK); SendMessage(fe->cfgbox, WM_INITDIALOG, 0, 0); @@ -2465,10 +2469,10 @@ static int get_config(frontend *fe, int which) y += height/2; /* extra space before OK and Cancel */ mkctrl(fe, col1l, (col1l+col2r)/2-width, y, y+height*7/4, "BUTTON", - BS_PUSHBUTTON | BS_NOTIFY | WS_TABSTOP | BS_DEFPUSHBUTTON, 0, + BS_PUSHBUTTON | WS_TABSTOP | BS_DEFPUSHBUTTON, 0, "OK", IDOK); mkctrl(fe, (col1l+col2r)/2+width, col2r, y, y+height*7/4, "BUTTON", - BS_PUSHBUTTON | BS_NOTIFY | WS_TABSTOP, 0, "Cancel", IDCANCEL); + BS_PUSHBUTTON | WS_TABSTOP, 0, "Cancel", IDCANCEL); SendMessage(fe->cfgbox, WM_INITDIALOG, 0, 0); @@ -2636,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)