From a16e39bb629a5115168b3c18ae93efdcac4f0125 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laci=20b=C3=A1?= Date: Sun, 14 Nov 2021 19:50:05 +0100 Subject: [PATCH] Initial commit for changeable icon set --- src/include/86box/win.h | 7 +- src/win/CMakeLists.txt | 2 +- src/win/Makefile.mingw | 2 +- src/win/win_icon.c | 149 ++++++++++++++++++++++++++++++++++++++++ src/win/win_settings.c | 8 +-- src/win/win_stbar.c | 42 +---------- src/win/win_ui.c | 13 +--- 7 files changed, 160 insertions(+), 63 deletions(-) create mode 100644 src/win/win_icon.c diff --git a/src/include/86box/win.h b/src/include/86box/win.h index 33e55f1d4..f4d592756 100644 --- a/src/include/86box/win.h +++ b/src/include/86box/win.h @@ -107,6 +107,7 @@ extern HWND hwndMain, hwndRender; extern HANDLE ghMutex; extern HICON hIcon[256]; +extern int dpi; extern RECT oldclip; extern int sbar_height, user_resize; extern int acp_utf8; @@ -122,8 +123,6 @@ extern uint8_t filterindex; extern void ResizeWindowByClientArea(HWND hwnd, int width, int height); extern void InitCrashDump(void); -extern HICON LoadIconEx(PCTSTR pszIconName); - /* Emulator start/stop support functions. */ extern void do_start(void); extern void do_stop(void); @@ -150,6 +149,10 @@ 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/win/CMakeLists.txt b/src/win/CMakeLists.txt index 727644f7b..d94485929 100644 --- a/src/win/CMakeLists.txt +++ b/src/win/CMakeLists.txt @@ -18,7 +18,7 @@ enable_language(RC) add_library(plat OBJECT win.c win_dynld.c win_cdrom.c win_thread.c win_keyboard.c win_crashdump.c win_midi.c win_mouse.c) -add_library(ui OBJECT win_ui.c win_stbar.c win_sdl.c win_dialog.c win_about.c +add_library(ui OBJECT win_ui.c win_icon.c win_stbar.c win_sdl.c win_dialog.c win_about.c win_settings.c win_devconf.c win_snd_gain.c win_specify_dim.c win_new_floppy.c win_jsconf.c win_media_menu.c win_lang.c 86Box.rc) diff --git a/src/win/Makefile.mingw b/src/win/Makefile.mingw index 8414f538f..ceb31a75a 100644 --- a/src/win/Makefile.mingw +++ b/src/win/Makefile.mingw @@ -423,7 +423,7 @@ ifeq ($(WX), y) LIBS += $(WX_LIBS) UIOBJ := wx_main.o wx_ui.o wx_stbar.o wx_render.o else - UIOBJ := win_ui.o win_stbar.o \ + UIOBJ := win_ui.o win_icon.o win_stbar.o \ win_sdl.o \ win_dialog.o win_about.o \ win_settings.o win_devconf.o win_snd_gain.o win_specify_dim.o win_lang.o \ diff --git a/src/win/win_icon.c b/src/win/win_icon.c new file mode 100644 index 000000000..14ac454e6 --- /dev/null +++ b/src/win/win_icon.c @@ -0,0 +1,149 @@ +/* + * 86Box A hypervisor and IBM PC system emulator that specializes in + * running old operating systems and software designed for IBM + * PC systems and compatibles from 1981 through fairly recent + * system designs based on the PCI bus. + * + * This file is part of the 86Box distribution. + * + * Implement the application's icon changing system. + * + * + * Authors: Laci bá' + * + * Copyright 2021 Laci bá'. + */ + +#include +#include +#include +#include +#include +#include +#include +#include <86box/86box.h> +#include <86box/config.h> +#include <86box/plat.h> +#include <86box/ui.h> +#include <86box/win.h> + +HICON hIcon[256]; /* icon data loaded from resources */ +char icon_set[256] = "winbox"; /* name of the iconset to be used */ + +void win_clear_icon_set() +{ + int i; + + for (i = 0; i < 256; i++) + if (hIcon[i] != 0) + { + DestroyIcon(hIcon[i]); + hIcon[i] = 0; + } +} + +void win_system_icon_set(HINSTANCE hInst) +{ + 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); +} + +typedef struct +{ + int id; + char* filename; +} _ICON_DATA; + +const _ICON_DATA icon_files[] = + { + {16, "floppy_525.ico"}, + {17, "floppy_525_active.ico"}, + {24, "floppy_35.ico"}, + {25, "floppy_35_active.ico"}, + {32, "cdrom.ico"}, + {33, "cdrom_active.ico"}, + {48, "zip.ico"}, + {49, "zip_active.ico"}, + {56, "mo.ico"}, + {57, "mo_active.ico"}, + {64, "cassette.ico"}, + {65, "cassette_active.ico"}, + {80, "hard_disk.ico"}, + {81, "hard_disk_active.ico"}, + {96, "network.ico"}, + {97, "network_active.ico"}, + {104, "cartridge.ico"}, + {144, "floppy_525_empty.ico"}, + {145, "floppy_525_empty_active.ico"}, + {152, "floppy_35_empty.ico"}, + {153, "floppy_35_empty_active.ico"}, + {160, "cdrom_empty.ico"}, + {161, "cdrom_empty_active.ico"}, + {176, "zip_empty.ico"}, + {177, "zip_empty_active.ico"}, + {184, "mo_empty.ico"}, + {185, "mo_empty_active.ico"}, + {192, "cassette_empty.ico"}, + {193, "cassette_empty_active.ico"}, + {232, "cartridge_empty.ico"}, + {240, "machine.ico"}, + {241, "display.ico"}, + {242, "input_devices.ico"}, + {243, "sound.ico"}, + {244, "ports.ico"}, + {245, "other_peripherals.ico"}, + {246, "floppy_and_cdrom_drives.ico"}, + {247, "other_removable_devices.ico"}, + {248, "floppy_disabled.ico"}, + {249, "cdrom_disabled.ico"}, + {250, "zip_disabled.ico"}, + {251, "mo_disabled.ico"}, + {252, "storage_controllers.ico"} + }; + +void win_load_icon_set(HINSTANCE hInst) +{ + 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); + else + plat_append_filename(roms_root, exe_path, "roms"); + + plat_append_filename(path_root, roms_root, "icons"); + plat_path_slash(path_root); + strcat(path_root, icon_set); + plat_path_slash(path_root); + + int i, count = sizeof(icon_files) / sizeof(_ICON_DATA), + x = win_get_system_metrics(SM_CXSMICON, dpi), y = win_get_system_metrics(SM_CYSMICON, dpi); + for (i = 0; i < count; i++) + { + plat_append_filename(temp, path_root, icon_files[i].filename); + mbstowcs(wtemp, temp, strlen(temp) + 1); + + HICON ictemp; + ictemp = LoadImageW(NULL, (LPWSTR)wtemp, IMAGE_ICON, x, y, LR_LOADFROMFILE | LR_DEFAULTCOLOR); + if (ictemp) + { + HICON* helper = &hIcon[icon_files[i].id]; + if (*helper) + DestroyIcon(*helper); + *helper = ictemp; + } + } + + uint32_t curr_lang = lang_id; + lang_id = 0; + set_language(curr_lang); +} \ No newline at end of file diff --git a/src/win/win_settings.c b/src/win/win_settings.c index d7fdb3816..4d253d8f7 100644 --- a/src/win/win_settings.c +++ b/src/win/win_settings.c @@ -76,7 +76,6 @@ static int first_cat = 0; -static int dpi = 96; /* Machine category */ static int temp_machine_type, temp_machine, temp_cpu, temp_wait_states, temp_fpu, temp_sync; @@ -265,13 +264,8 @@ image_list_init(HWND hdlg, int id, const uint8_t *icon_ids) if (icon_ids[i] == 0) break; -#if defined(__amd64__) || defined(__aarch64__) - hiconItem = LoadIcon(hinstance, (LPCWSTR) ((uint64_t) icon_ids[i])); -#else - hiconItem = LoadIcon(hinstance, (LPCWSTR) ((uint32_t) icon_ids[i])); -#endif + hiconItem = hIcon[icon_ids[i]]; ImageList_AddIcon(hSmall, hiconItem); - DestroyIcon(hiconItem); i++; } diff --git a/src/win/win_stbar.c b/src/win/win_stbar.c index b89bcafed..df82d15e5 100644 --- a/src/win/win_stbar.c +++ b/src/win/win_stbar.c @@ -71,7 +71,6 @@ static uint8_t *sb_part_icons; static int sb_parts = 0; static int sb_ready = 0; static uint8_t sb_map[256]; -static int dpi = 96; static int icon_width = 24; static wchar_t sb_text[512] = L"\0"; static wchar_t sb_bugtext[512] = L"\0"; @@ -878,46 +877,7 @@ StatusBarPopupMenu(HWND hwnd, POINT pt, int id) /* API: Load status bar icons */ void StatusBarLoadIcon(HINSTANCE hInst) { - int i; - int x = win_get_system_metrics(SM_CXSMICON, dpi); - - for (i=0; i<256; i++) { - if (hIcon[i] != 0) - DestroyIcon(hIcon[i]); - } - - for (i = 16; i < 18; i++) - hIcon[i] = LoadImage(hInst, MAKEINTRESOURCE(i), IMAGE_ICON, x, x, LR_DEFAULTCOLOR); - for (i = 24; i < 26; i++) - hIcon[i] = LoadImage(hInst, MAKEINTRESOURCE(i), IMAGE_ICON, x, x, LR_DEFAULTCOLOR); - for (i = 32; i < 34; i++) - hIcon[i] = LoadImage(hInst, MAKEINTRESOURCE(i), IMAGE_ICON, x, x, LR_DEFAULTCOLOR); - for (i = 48; i < 50; i++) - hIcon[i] = LoadImage(hInst, MAKEINTRESOURCE(i), IMAGE_ICON, x, x, LR_DEFAULTCOLOR); - for (i = 56; i < 58; i++) - hIcon[i] = LoadImage(hInst, MAKEINTRESOURCE(i), IMAGE_ICON, x, x, LR_DEFAULTCOLOR); - for (i = 64; i < 66; i++) - hIcon[i] = LoadImage(hInst, MAKEINTRESOURCE(i), IMAGE_ICON, x, x, LR_DEFAULTCOLOR); - for (i = 80; i < 82; i++) - hIcon[i] = LoadImage(hInst, MAKEINTRESOURCE(i), IMAGE_ICON, x, x, LR_DEFAULTCOLOR); - for (i = 96; i < 98; i++) - hIcon[i] = LoadImage(hInst, MAKEINTRESOURCE(i), IMAGE_ICON, x, x, LR_DEFAULTCOLOR); - hIcon[104] = LoadImage(hInst, MAKEINTRESOURCE(104), IMAGE_ICON, x, x, LR_DEFAULTCOLOR); - for (i = 144; i < 146; i++) - hIcon[i] = LoadImage(hInst, MAKEINTRESOURCE(i), IMAGE_ICON, x, x, LR_DEFAULTCOLOR); - for (i = 152; i < 154; i++) - hIcon[i] = LoadImage(hInst, MAKEINTRESOURCE(i), IMAGE_ICON, x, x, LR_DEFAULTCOLOR); - for (i = 160; i < 162; i++) - hIcon[i] = LoadImage(hInst, MAKEINTRESOURCE(i), IMAGE_ICON, x, x, LR_DEFAULTCOLOR); - for (i = 176; i < 178; i++) - hIcon[i] = LoadImage(hInst, MAKEINTRESOURCE(i), IMAGE_ICON, x, x, LR_DEFAULTCOLOR); - for (i = 184; i < 186; i++) - hIcon[i] = LoadImage(hInst, MAKEINTRESOURCE(i), IMAGE_ICON, x, x, LR_DEFAULTCOLOR); - for (i = 192; i < 194; i++) - hIcon[i] = LoadImage(hInst, MAKEINTRESOURCE(i), IMAGE_ICON, x, x, LR_DEFAULTCOLOR); - hIcon[232] = LoadImage(hInst, MAKEINTRESOURCE(232), IMAGE_ICON, x, x, LR_DEFAULTCOLOR); - for (i = 243; i < 244; i++) - hIcon[i] = LoadImage(hInst, MAKEINTRESOURCE(i), IMAGE_ICON, x, x, LR_DEFAULTCOLOR); + win_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 57ef417a2..ca089eabd 100644 --- a/src/win/win_ui.c +++ b/src/win/win_ui.c @@ -59,7 +59,6 @@ HWND hwndMain, /* application main window */ hwndRender; /* machine render window */ HMENU menuMain; /* application main menu */ -HICON hIcon[256]; /* icon data loaded from resources */ RECT oldclip; /* mouse rect */ int sbar_height = 23; /* statusbar height */ int minimized = 0; @@ -78,7 +77,7 @@ extern WCHAR wopenfilestring[512]; static wchar_t wTitle[512]; static int manager_wm = 0; static int save_window_pos = 0, pause_state = 0; -static int dpi = 96; +int dpi = 96; static int padded_frame = 0; static int vis = -1; @@ -153,15 +152,6 @@ show_cursor(int val) vis = val; } - -HICON -LoadIconEx(PCTSTR pszIconName) -{ - return((HICON)LoadImage(hinstance, pszIconName, IMAGE_ICON, - 16, 16, LR_SHARED)); -} - - static void video_toggle_option(HMENU h, int *val, int id) { @@ -1074,6 +1064,7 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) break; case WM_DESTROY: + win_clear_icon_set(); KillTimer(hwnd, TIMER_1SEC); PostQuitMessage(0); break;