From 0aa6e9c8a64e8b65f546ed89673f538b4d303386 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laci=20b=C3=A1?= Date: Tue, 16 Nov 2021 19:38:31 +0100 Subject: [PATCH] Finish the changeable iconset --- src/86box.c | 3 + src/config.c | 11 +++ src/include/86box/86box.h | 1 + src/include/86box/plat.h | 5 ++ src/include/86box/resource.h | 2 + src/include/86box/win.h | 4 -- src/unix/unix.c | 25 +++++++ src/win/languages/cs-CZ.rc | 1 + src/win/languages/de-DE.rc | 1 + src/win/languages/dialogs.rc | 14 ++-- src/win/languages/en-US.rc | 1 + src/win/languages/hr-HR.rc | 1 + src/win/languages/hu-HU.rc | 1 + src/win/languages/it-IT.rc | 1 + src/win/languages/pt-BR.rc | 1 + src/win/languages/pt-PT.rc | 1 + src/win/win_icon.c | 33 +++++---- src/win/win_lang.c | 125 +++++++++++++++++++++++++++++++++++ src/win/win_stbar.c | 2 +- src/win/win_ui.c | 2 +- 20 files changed, 210 insertions(+), 25 deletions(-) diff --git a/src/86box.c b/src/86box.c index 8f9338920..964e885bc 100644 --- a/src/86box.c +++ b/src/86box.c @@ -715,6 +715,9 @@ usage: if (lang_init) set_language(lang_init); + /* Load the desired iconset */ + plat_load_icon_set(); + /* All good! */ return(1); } diff --git a/src/config.c b/src/config.c index 57bdf5508..e302b0b48 100644 --- a/src/config.c +++ b/src/config.c @@ -573,6 +573,12 @@ load_general(void) lang_id = plat_language_code(p); } + p = config_get_string(cat, "iconset", NULL); + if (p != NULL) + strcpy(icon_set, p); + else + strcpy(icon_set, ""); + #if USE_DISCORD enable_discord = !!config_get_int(cat, "enable_discord", 0); #endif @@ -2230,6 +2236,11 @@ save_general(void) plat_language_code_r(lang_id, buffer, 511); config_set_string(cat, "language", buffer); } + + if (!strcmp(icon_set, "")) + config_delete_var(cat, "iconset"); + else + config_set_string(cat, "iconset", icon_set); #if USE_DISCORD if (enable_discord) diff --git a/src/include/86box/86box.h b/src/include/86box/86box.h index c27f1d93e..f56757f38 100644 --- a/src/include/86box/86box.h +++ b/src/include/86box/86box.h @@ -97,6 +97,7 @@ extern int window_w, window_h, /* (C) window size and */ invert_display, /* (C) invert the display */ suppress_overscan; /* (C) suppress overscans */ extern uint32_t lang_id; /* (C) language code identifier */ +extern char icon_set[256]; /* (C) iconset identifier */ extern int scale; /* (C) screen scale factor */ extern int dpi_scale; /* (C) DPI scaling of the emulated screen */ extern int vid_api; /* (C) video renderer */ diff --git a/src/include/86box/plat.h b/src/include/86box/plat.h index ca116a684..8d0d4c4ef 100644 --- a/src/include/86box/plat.h +++ b/src/include/86box/plat.h @@ -125,6 +125,11 @@ extern void plat_vid_reload_options(void); extern uint32_t plat_language_code(char* langcode); extern void plat_language_code_r(uint32_t lcid, char* outbuf, int len); +extern void plat_clear_icon_set(); +extern void plat_system_icon_set(); +extern void plat_load_icon_set(); +extern void plat_get_icons_path(char* path_root); + /* Resource management. */ extern void set_language(uint32_t id); extern wchar_t *plat_get_string(int id); diff --git a/src/include/86box/resource.h b/src/include/86box/resource.h index 2a13b01f1..d05409e0d 100644 --- a/src/include/86box/resource.h +++ b/src/include/86box/resource.h @@ -265,8 +265,10 @@ #define IDC_COMBO_RPM_MODE 1202 #define IDC_COMBO_LANG 1009 /* change language dialog */ +#define IDC_COMBO_ICON 1010 #define IDC_CHECKBOX_GLOBAL 1300 #define IDC_BUTTON_DEFAULT 1302 +#define IDC_BUTTON_DEFICON 1304 /* For the DeviceConfig code, re-do later. */ #define IDC_CONFIG_BASE 1300 diff --git a/src/include/86box/win.h b/src/include/86box/win.h index f4d592756..3a287a11b 100644 --- a/src/include/86box/win.h +++ b/src/include/86box/win.h @@ -149,10 +149,6 @@ extern int win_get_system_metrics(int i, int dpi); extern LPARAM win_get_string(int id); -extern void win_clear_icon_set(); -extern void win_system_icon_set(HINSTANCE hInst); -extern void win_load_icon_set(HINSTANCE hInst); - extern intptr_t fdd_type_to_icon(int type); #ifdef EMU_DEVICE_H diff --git a/src/unix/unix.c b/src/unix/unix.c index ae786f8ad..0c4696d56 100644 --- a/src/unix/unix.c +++ b/src/unix/unix.c @@ -51,6 +51,7 @@ SDL_threadID eventthread; static int exit_event = 0; static int fullscreen_pending = 0; uint32_t lang_id = 0x0409, lang_sys = 0x0409; // Multilangual UI variables, for now all set to LCID of en-US +char icon_set[256] = ""; /* name of the iconset to be used */ static const uint16_t sdl_to_xt[0x200] = { @@ -1244,6 +1245,30 @@ plat_language_code_r(uint32_t lcid, char* outbuf, int len) return; } +void +plat_clear_icon_set() +{ + return; +} + +void +plat_system_icon_set() +{ + return; +} + +void +plat_load_icon_set() +{ + return; +} + +void +plat_get_icons_path(char* path_root) +{ + return; +} + void joystick_init(void) {} void joystick_close(void) {} diff --git a/src/win/languages/cs-CZ.rc b/src/win/languages/cs-CZ.rc index 24f41ba6a..60a234827 100644 --- a/src/win/languages/cs-CZ.rc +++ b/src/win/languages/cs-CZ.rc @@ -284,6 +284,7 @@ END #define STR_GLOBAL "Uložit toto nastavení jako &globální výchozí stav" #define STR_DEFAULT "&Výchozí" #define STR_LANGUAGE "Jazyk:" +#define STR_ICONSET "Sada ikon:" #define STR_GAIN "Zesílení" diff --git a/src/win/languages/de-DE.rc b/src/win/languages/de-DE.rc index ef737c2e3..3e50191a6 100644 --- a/src/win/languages/de-DE.rc +++ b/src/win/languages/de-DE.rc @@ -284,6 +284,7 @@ END #define STR_GLOBAL "Einstellungen als &globalen Standard speichern" #define STR_DEFAULT "&Standard" #define STR_LANGUAGE "Sprache:" +#define STR_ICONSET "Ikonensatz:" #define STR_GAIN "Verstärkung" diff --git a/src/win/languages/dialogs.rc b/src/win/languages/dialogs.rc index 6645c462d..9862a5080 100644 --- a/src/win/languages/dialogs.rc +++ b/src/win/languages/dialogs.rc @@ -1,14 +1,17 @@ -DLG_PROG_SETT DIALOG DISCARDABLE 0, 0, 240, 86 +DLG_PROG_SETT DIALOG DISCARDABLE 0, 0, 240, 118 STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION STR_PROG_SETT FONT 9, "Segoe UI" BEGIN - DEFPUSHBUTTON STR_OK, IDOK, 123, 65, 50, 14 - PUSHBUTTON STR_CANCEL, IDCANCEL, 179, 65, 50, 14 + DEFPUSHBUTTON STR_OK, IDOK, 123, 97, 50, 14 + PUSHBUTTON STR_CANCEL, IDCANCEL, 179, 97, 50, 14 COMBOBOX IDC_COMBO_LANG, 13, 18, 213, 22, CBS_DROPDOWNLIST | CBS_HASSTRINGS - AUTOCHECKBOX STR_GLOBAL, IDC_CHECKBOX_GLOBAL, 13, 50, 217, 8 , WS_DISABLED PUSHBUTTON STR_DEFAULT, IDC_BUTTON_DEFAULT, 162, 32, 60, 14 - LTEXT STR_LANGUAGE, 0, 13, 8, 34, 8 + COMBOBOX IDC_COMBO_ICON, 13, 50, 213, 22, CBS_DROPDOWNLIST | CBS_HASSTRINGS + PUSHBUTTON STR_DEFAULT, IDC_BUTTON_DEFICON, 162, 64, 60, 14 + AUTOCHECKBOX STR_GLOBAL, IDC_CHECKBOX_GLOBAL, 13, 82, 217, 8 , WS_DISABLED + LTEXT STR_LANGUAGE, 0, 13, 8, 100, 8 + LTEXT STR_ICONSET, 0, 13, 40, 100, 8 END DLG_SND_GAIN DIALOG DISCARDABLE 0, 0, 113, 136 @@ -468,6 +471,7 @@ END #undef STR_GLOBAL #undef STR_DEFAULT #undef STR_LANGUAGE +#undef STR_ICONSET #undef STR_GAIN diff --git a/src/win/languages/en-US.rc b/src/win/languages/en-US.rc index 443d0debc..2b3ad1e94 100644 --- a/src/win/languages/en-US.rc +++ b/src/win/languages/en-US.rc @@ -284,6 +284,7 @@ END #define STR_GLOBAL "Save these settings as &global defaults" #define STR_DEFAULT "&Default" #define STR_LANGUAGE "Language:" +#define STR_ICONSET "Iconset:" #define STR_GAIN "Gain" diff --git a/src/win/languages/hr-HR.rc b/src/win/languages/hr-HR.rc index e71a3b10b..699c353e8 100644 --- a/src/win/languages/hr-HR.rc +++ b/src/win/languages/hr-HR.rc @@ -284,6 +284,7 @@ END #define STR_GLOBAL "Spremite ove postavke kao &globalne zadane postavke" #define STR_DEFAULT "&Standard" #define STR_LANGUAGE "Jezik:" +#define STR_ICONSET "Skup ikona:" #define STR_GAIN "Pojačavanje" diff --git a/src/win/languages/hu-HU.rc b/src/win/languages/hu-HU.rc index fdda601a6..569f3b616 100644 --- a/src/win/languages/hu-HU.rc +++ b/src/win/languages/hu-HU.rc @@ -287,6 +287,7 @@ END #define STR_GLOBAL "Beállítások mentése &globális alapértékként" #define STR_DEFAULT "&Alapértelmezett" #define STR_LANGUAGE "Nyelv:" +#define STR_ICONSET "Ikonkészlet:" #define STR_GAIN "Hangerő" diff --git a/src/win/languages/it-IT.rc b/src/win/languages/it-IT.rc index b988a40c5..8feaeccf7 100644 --- a/src/win/languages/it-IT.rc +++ b/src/win/languages/it-IT.rc @@ -284,6 +284,7 @@ END #define STR_GLOBAL "Salva queste impostazioni come &predefinite globali" #define STR_DEFAULT "&Predefinito" #define STR_LANGUAGE "Lingua:" +#define STR_ICONSET "Set di Icone:" #define STR_GAIN "Guadagno" diff --git a/src/win/languages/pt-BR.rc b/src/win/languages/pt-BR.rc index 4e6b97981..a9024321b 100644 --- a/src/win/languages/pt-BR.rc +++ b/src/win/languages/pt-BR.rc @@ -285,6 +285,7 @@ END #define STR_GLOBAL "Usar estas configurações como &padrões globais" #define STR_DEFAULT "&Padrão" #define STR_LANGUAGE "Idioma:" +#define STR_ICONSET "Conjunto de ícones:" #define STR_GAIN "Ganho" diff --git a/src/win/languages/pt-PT.rc b/src/win/languages/pt-PT.rc index 8efc1aa29..aaeed8dc5 100644 --- a/src/win/languages/pt-PT.rc +++ b/src/win/languages/pt-PT.rc @@ -284,6 +284,7 @@ END #define STR_GLOBAL "Guardar estas definições como padrões &globais" #define STR_DEFAULT "&Padrão" #define STR_LANGUAGE "Idioma:" +#define STR_ICONSET "Conjunto de ícones:" #define STR_GAIN "Ganho" diff --git a/src/win/win_icon.c b/src/win/win_icon.c index 14ac454e6..345d028af 100644 --- a/src/win/win_icon.c +++ b/src/win/win_icon.c @@ -28,9 +28,9 @@ #include <86box/win.h> HICON hIcon[256]; /* icon data loaded from resources */ -char icon_set[256] = "winbox"; /* name of the iconset to be used */ +char icon_set[256] = ""; /* name of the iconset to be used */ -void win_clear_icon_set() +void plat_clear_icon_set() { int i; @@ -42,12 +42,12 @@ void win_clear_icon_set() } } -void win_system_icon_set(HINSTANCE hInst) +void plat_system_icon_set() { int i, x = win_get_system_metrics(SM_CXSMICON, dpi), y = win_get_system_metrics(SM_CYSMICON, dpi); for (i = 0; i < 256; i++) - hIcon[i] = LoadImage(hInst, MAKEINTRESOURCE(i), IMAGE_ICON, x, y, LR_DEFAULTCOLOR); + hIcon[i] = LoadImage(hinstance, MAKEINTRESOURCE(i), IMAGE_ICON, x, y, LR_DEFAULTCOLOR); } typedef struct @@ -103,17 +103,8 @@ const _ICON_DATA icon_files[] = {252, "storage_controllers.ico"} }; -void win_load_icon_set(HINSTANCE hInst) +void plat_get_icons_path(char* path_root) { - win_clear_icon_set(); - win_system_icon_set(hInst); - - if (strlen(icon_set) == 0) - return; - - char path_root[2048] = {0}, temp[2048] = {0}; - wchar_t wtemp[2048] = {0}; - char roms_root[1024] = {0}; if (rom_path[0]) strcpy(roms_root, rom_path); @@ -122,6 +113,20 @@ void win_load_icon_set(HINSTANCE hInst) plat_append_filename(path_root, roms_root, "icons"); plat_path_slash(path_root); +} + +void plat_load_icon_set() +{ + plat_clear_icon_set(); + plat_system_icon_set(); + + if (strlen(icon_set) == 0) + return; + + char path_root[2048] = {0}, temp[2048] = {0}; + wchar_t wtemp[2048] = {0}; + + plat_get_icons_path(path_root); strcat(path_root, icon_set); plat_path_slash(path_root); diff --git a/src/win/win_lang.c b/src/win/win_lang.c index 5f79e8c61..f67c6144f 100644 --- a/src/win/win_lang.c +++ b/src/win/win_lang.c @@ -36,6 +36,8 @@ /* Language */ static LCID temp_language; +static char temp_icon_set[256] = {0}; + int enum_helper, c; HWND hwndProgSett; @@ -76,6 +78,86 @@ progsett_fill_languages(HWND hdlg) SendMessage(lang_combo, CB_SETCURSEL, enum_helper, 0); } +/* Load available iconsets */ +static void +progsett_fill_iconsets(HWND hdlg) +{ + HWND icon_combo = GetDlgItem(hdlg, IDC_COMBO_ICON); + + /* Add the default one */ + wchar_t buffer[512] = L"("; + wcscat(buffer, plat_get_string(IDS_2090)); + wcscat(buffer, L")"); + + SendMessage(icon_combo, CB_RESETCONTENT, 0, 0); + SendMessage(icon_combo, CB_ADDSTRING, 0, (LPARAM)buffer); + SendMessage(icon_combo, CB_SETITEMDATA, 0, (LPARAM)strdup("")); + + int combo_index = -1; + + /* Find for extra ones */ + HANDLE hFind; + WIN32_FIND_DATA data; + + char icon_path_root[512]; + plat_get_icons_path(icon_path_root); + + wchar_t search[512]; + pclog("icon_path_root: %s\n", icon_path_root); + mbstowcs(search, icon_path_root, strlen(icon_path_root) + 1); + wcscat(search, L"*.*"); + pclog("search: %ls\n", search); + + hFind = FindFirstFile((LPCWSTR)search, &data); + + if (hFind != INVALID_HANDLE_VALUE) { + do { + if (wcscmp(data.cFileName, L".") && wcscmp(data.cFileName, L"..") && + (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) + { + wchar_t temp[512] = {0}, dispname[512] = {0}; + mbstowcs(temp, icon_path_root, strlen(icon_path_root) + 1); + wcscat(temp, data.cFileName); + wcscat(temp, L"\\iconinfo.txt"); + + pclog("temp: %ls\n", temp); + + wcscpy(dispname, data.cFileName); + FILE *fp = _wfopen(temp, L"r"); + if (fp) + { + char line[512]; + if (fgets(line, 511, fp)) + { + pclog("found! %s\n", line); + mbstowcs(dispname, line, strlen(line) + 1); + } + + fclose(fp); + } + + char filename[512]; + wcstombs(filename, data.cFileName, 511); + + int index = SendMessage(icon_combo, CB_ADDSTRING, 0, (LPARAM)dispname); + SendMessage(icon_combo, CB_SETITEMDATA, index, (LPARAM)(strdup(filename))); + + if (!strcmp(filename, icon_set)) + combo_index = index; + } + } while (FindNextFile(hFind, &data)); + FindClose(hFind); + } + + if (combo_index == -1) + { + combo_index = 0; + strcpy(temp_icon_set, ""); + } + + SendMessage(icon_combo, CB_SETCURSEL, combo_index, 0); +} + /* This returns 1 if any variable has changed, 0 if not. */ static int progsett_settings_changed(void) @@ -84,6 +166,7 @@ progsett_settings_changed(void) /* Language */ i = i || has_language_changed(temp_language); + i = i || strcmp(temp_icon_set, icon_set); return i; } @@ -107,6 +190,10 @@ progsett_settings_save(void) /* Language */ set_language(temp_language); + /* Iconset */ + strcpy(icon_set, temp_icon_set); + plat_load_icon_set(hinstance); + /* Update title bar */ update_mouse_msg(); @@ -131,7 +218,10 @@ ProgSettDlgProcedure(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) hwndProgSett = hdlg; /* Language */ temp_language = lang_id; + strcpy(temp_icon_set, icon_set); + pclog("temp_icon_set: %s\n", temp_icon_set); progsett_fill_languages(hdlg); + progsett_fill_iconsets(hdlg); break; case WM_COMMAND: @@ -154,6 +244,16 @@ ProgSettDlgProcedure(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) } break; + case IDC_COMBO_ICON: + if (HIWORD(wParam) == CBN_SELCHANGE) { + pclog("dosth\n"); + HWND combo = GetDlgItem(hdlg, IDC_COMBO_ICON); + int index = SendMessage(combo, CB_GETCURSEL, 0, 0); + strcpy(temp_icon_set, (char*)SendMessage(combo, CB_GETITEMDATA, index, 0)); + pclog("temp_icon_set: %s\n", temp_icon_set); + } + break; + case IDC_BUTTON_DEFAULT: { HWND combo = GetDlgItem(hdlg, IDC_COMBO_LANG); int index = progsett_indexof(combo, DEFAULT_LANGUAGE); @@ -161,10 +261,35 @@ ProgSettDlgProcedure(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) temp_language = DEFAULT_LANGUAGE; break; } + + case IDC_BUTTON_DEFICON: { + pclog("dosth\n"); + SendMessage(GetDlgItem(hdlg, IDC_COMBO_ICON), CB_SETCURSEL, 0, 0); + strcpy(temp_icon_set, ""); + pclog("temp_icon_set: %s\n", temp_icon_set); + break; + } default: break; } break; + + case WM_DESTROY: { + int i; + LRESULT temp; + HWND combo = GetDlgItem(hdlg, IDC_COMBO_ICON); + for (i = 0; i < SendMessage(combo, CB_GETCOUNT, 0, 0); i++) + { + temp = SendMessage(combo, CB_GETITEMDATA, i, 0); + if (temp) + { + free((void*)temp); + SendMessage(combo, CB_SETITEMDATA, i, 0); + } + } + } + break; + } return(FALSE); diff --git a/src/win/win_stbar.c b/src/win/win_stbar.c index df82d15e5..d8e079e14 100644 --- a/src/win/win_stbar.c +++ b/src/win/win_stbar.c @@ -877,7 +877,7 @@ StatusBarPopupMenu(HWND hwnd, POINT pt, int id) /* API: Load status bar icons */ void StatusBarLoadIcon(HINSTANCE hInst) { - win_load_icon_set(hInst); + plat_load_icon_set(hInst); } /* Handle messages for the Status Bar window. */ diff --git a/src/win/win_ui.c b/src/win/win_ui.c index ca089eabd..84bde8e64 100644 --- a/src/win/win_ui.c +++ b/src/win/win_ui.c @@ -1064,7 +1064,7 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) break; case WM_DESTROY: - win_clear_icon_set(); + plat_clear_icon_set(); KillTimer(hwnd, TIMER_1SEC); PostQuitMessage(0); break;