From 985f58ec76eeb9860f84e018ce3caf817ca56071 Mon Sep 17 00:00:00 2001 From: Dimitris Panokostas Date: Sat, 25 Nov 2023 19:19:30 +0100 Subject: [PATCH] Make GUI colors and Font configurable - Added struct to hold values - Extracted default values to struct - Added try/catch block when opening font in ShowMessage, in case the font isn't found --- src/include/options.h | 11 +++++++++++ src/osdep/amiberry.cpp | 3 ++- src/osdep/gui/ShowMessage.cpp | 22 +++++++++++++++++----- src/osdep/gui/gui_handling.h | 5 +++++ src/osdep/gui/main_window.cpp | 16 ++++++++-------- 5 files changed, 43 insertions(+), 14 deletions(-) diff --git a/src/include/options.h b/src/include/options.h index f142917c1..9056c3a86 100644 --- a/src/include/options.h +++ b/src/include/options.h @@ -14,6 +14,7 @@ #include "uae/types.h" #include "traps.h" +#include "guisan/color.hpp" #define UAEMAJOR 5 #define UAEMINOR 6 @@ -1190,6 +1191,16 @@ struct amiberry_hotkey hotkey_modifiers modifiers; }; +struct amiberry_gui_theme +{ + gcn::Color base_color = gcn::Color(170, 170, 170); + gcn::Color selector_inactive = gcn::Color(170, 170, 170); + gcn::Color selector_active = gcn::Color(103, 136, 187); + gcn::Color textbox_background = gcn::Color(220, 220, 220); + std::string font_name = "AmigaTopaz.ttf"; + int font_size = 15; +}; + struct amiberry_options { bool quickstart_start = true; diff --git a/src/osdep/amiberry.cpp b/src/osdep/amiberry.cpp index a8b62c285..837dfb627 100644 --- a/src/osdep/amiberry.cpp +++ b/src/osdep/amiberry.cpp @@ -103,6 +103,7 @@ int relativepaths = 0; int saveimageoriginalpath = 0; struct amiberry_options amiberry_options = {}; +struct amiberry_gui_theme gui_theme = {}; amiberry_hotkey enter_gui_key; SDL_GameControllerButton enter_gui_button; amiberry_hotkey quit_key; @@ -3205,7 +3206,7 @@ static int parse_amiberry_settings_line(const char *path, char *linea) ret |= cfgfile_string(option, value, "inputrecordings_dir", input_dir, sizeof input_dir); ret |= cfgfile_string(option, value, "screenshot_dir", screenshot_dir, sizeof screenshot_dir); ret |= cfgfile_string(option, value, "nvram_dir", nvram_dir, sizeof nvram_dir); - // NOTE: amiberry_config is a "read only", ie. it's not written in + // NOTE: amiberry_config is a "read only", i.e. it's not written in // save_amiberry_settings(). It's purpose is to provide -o amiberry_config=path // command line option. ret |= cfgfile_string(option, value, "amiberry_config", amiberry_conf_file, sizeof amiberry_conf_file); diff --git a/src/osdep/gui/ShowMessage.cpp b/src/osdep/gui/ShowMessage.cpp index 80d0413cc..be4c16f3d 100644 --- a/src/osdep/gui/ShowMessage.cpp +++ b/src/osdep/gui/ShowMessage.cpp @@ -1,5 +1,7 @@ #include #include +#include +#include #include #include @@ -167,20 +169,30 @@ static void InitShowMessage(const std::string& message) { gui_top = new gcn::Container(); gui_top->setDimension(gcn::Rectangle(0, 0, GUI_WIDTH, GUI_HEIGHT)); - gui_baseCol = gcn::Color(170, 170, 170); + gui_baseCol = gui_theme.base_color; gui_top->setBaseColor(gui_baseCol); uae_gui->setTop(gui_top); } if (gui_font == nullptr) { TTF_Init(); -#ifdef USE_OPENGL - gui_font = new gcn::ImageFont(prefix_with_data_path("rpgfont.png"), " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,!?-+/():;%&`'*#=[]\""); + try + { +#ifdef USE_OPENGL + gui_font = new gcn::ImageFont(prefix_with_data_path("rpgfont.png"), " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,!?-+/():;%&`'*#=[]\""); #else - gui_font = new gcn::SDLTrueTypeFont(prefix_with_data_path("AmigaTopaz.ttf"), 15); - gui_font->setAntiAlias(false); + gui_font = new gcn::SDLTrueTypeFont(prefix_with_data_path(gui_theme.font_name), gui_theme.font_size); + gui_font->setAntiAlias(false); #endif + } + catch (exception& ex) + { + cout << ex.what() << '\n'; + write_log("An error occurred while trying to open the GUI font! Exception: %s\n", ex.what()); + abort(); + } + gcn::Widget::setGlobalFont(gui_font); } diff --git a/src/osdep/gui/gui_handling.h b/src/osdep/gui/gui_handling.h index d25db3d63..867306f54 100644 --- a/src/osdep/gui/gui_handling.h +++ b/src/osdep/gui/gui_handling.h @@ -146,9 +146,14 @@ extern bool gui_running; extern ConfigCategory categories[]; extern gcn::Gui* uae_gui; extern gcn::Container* gui_top; + +// GUI Colors +extern amiberry_gui_theme gui_theme; extern gcn::Color gui_baseCol; extern gcn::Color colTextboxBackground; +extern gcn::Color colSelectorInactive; extern gcn::Color colSelectorActive; + extern gcn::SDLInput* gui_input; extern SDL_Surface* gui_screen; extern SDL_Joystick* gui_joystick; diff --git a/src/osdep/gui/main_window.cpp b/src/osdep/gui/main_window.cpp index b7fdd9c16..ad456e4ff 100644 --- a/src/osdep/gui/main_window.cpp +++ b/src/osdep/gui/main_window.cpp @@ -174,10 +174,12 @@ gcn::Container* gui_top; gcn::Container* selectors; gcn::ScrollArea* selectorsScrollArea; +// GUI Colors gcn::Color gui_baseCol; gcn::Color colTextboxBackground; gcn::Color colSelectorInactive; gcn::Color colSelectorActive; + gcn::FocusHandler* focusHdl; gcn::Widget* activeWidget; @@ -1238,10 +1240,10 @@ void gui_widgets_init() //------------------------------------------------- // Define base colors //------------------------------------------------- - gui_baseCol = gcn::Color(170, 170, 170); - colSelectorInactive = gcn::Color(170, 170, 170); - colSelectorActive = gcn::Color(103, 136, 187); - colTextboxBackground = gcn::Color(220, 220, 220); + gui_baseCol = gui_theme.base_color; + colSelectorInactive = gui_theme.selector_inactive; + colSelectorActive = gui_theme.selector_active; + colTextboxBackground = gui_theme.textbox_background; //------------------------------------------------- // Create container for main page @@ -1263,7 +1265,8 @@ void gui_widgets_init() #ifdef USE_OPENGL gui_font = new gcn::ImageFont(prefix_with_data_path("rpgfont.png"), " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,!?-+/():;%&`'*#=[]\""); #else - gui_font = new gcn::SDLTrueTypeFont(prefix_with_data_path("AmigaTopaz.ttf"), 15); + gui_font = new gcn::SDLTrueTypeFont(prefix_with_data_path(gui_theme.font_name), gui_theme.font_size); + gui_font->setAntiAlias(false); #endif } catch (exception& ex) @@ -1274,9 +1277,6 @@ void gui_widgets_init() } gcn::Widget::setGlobalFont(gui_font); -#ifndef USE_OPENGL - gui_font->setAntiAlias(false); -#endif //-------------------------------------------------- // Create main buttons