Skip to content

Commit

Permalink
Make GUI colors and Font configurable
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
midwan committed Nov 25, 2023
1 parent 77b9997 commit 985f58e
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 14 deletions.
11 changes: 11 additions & 0 deletions src/include/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "uae/types.h"

#include "traps.h"
#include "guisan/color.hpp"

#define UAEMAJOR 5
#define UAEMINOR 6
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/osdep/amiberry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
22 changes: 17 additions & 5 deletions src/osdep/gui/ShowMessage.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>

#include <guisan.hpp>
#include <SDL_ttf.h>
Expand Down Expand Up @@ -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);
}

Expand Down
5 changes: 5 additions & 0 deletions src/osdep/gui/gui_handling.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 8 additions & 8 deletions src/osdep/gui/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -1274,9 +1277,6 @@ void gui_widgets_init()
}

gcn::Widget::setGlobalFont(gui_font);
#ifndef USE_OPENGL
gui_font->setAntiAlias(false);
#endif

//--------------------------------------------------
// Create main buttons
Expand Down

0 comments on commit 985f58e

Please sign in to comment.