summaryrefslogtreecommitdiffstats
path: root/src/frontend/mame/ui/ui.cpp
diff options
context:
space:
mode:
author npwoods <npwoods@mess.org>2019-06-28 17:30:09 -0400
committer R. Belmont <rb6502@users.noreply.github.com>2019-06-28 17:30:09 -0400
commit697ff7bd7149d635a838543b65409dd42d739087 (patch)
tree23d49d81fd2b87ed565fac5c758b73b678fa7ad2 /src/frontend/mame/ui/ui.cpp
parentcec557538d0d55b11780e83ac60e0fef68b37e0d (diff)
Changed the various usages of UI_*COLOR to be calls to src/frontend/mame/ui/moptions.h (#5282)
* Changed the various usages of UI_*COLOR to be calls to src/frontend/mame/ui/moptions.h The various UI_*COLOR macros were implemented as calls to decode_ui_color, which cached the values for the various options in a static array, which was obviously a gross hack. This refactoring is strategic because I am trying to confine awareness of mame_ui_manager to code in src/frontend/mame/ui, and the implementation of decode_ui_color() relied on the ability to access mame_ui_manager as a singleton from outside this code. * Created a ui_colors object, so that queries for UI RGB values would not always require parsing strings * Converted a few more options().zyx_color() to colors().zyx_color() * A few more misses from earlier
Diffstat (limited to 'src/frontend/mame/ui/ui.cpp')
-rw-r--r--src/frontend/mame/ui/ui.cpp80
1 files changed, 29 insertions, 51 deletions
diff --git a/src/frontend/mame/ui/ui.cpp b/src/frontend/mame/ui/ui.cpp
index 812d5c23502..0062df95ac1 100644
--- a/src/frontend/mame/ui/ui.cpp
+++ b/src/frontend/mame/ui/ui.cpp
@@ -92,25 +92,6 @@ static input_item_id const non_char_keys[] =
ITEM_ID_CANCEL
};
-static char const *const s_color_list[] = {
- OPTION_UI_BORDER_COLOR,
- OPTION_UI_BACKGROUND_COLOR,
- OPTION_UI_GFXVIEWER_BG_COLOR,
- OPTION_UI_UNAVAILABLE_COLOR,
- OPTION_UI_TEXT_COLOR,
- OPTION_UI_TEXT_BG_COLOR,
- OPTION_UI_SUBITEM_COLOR,
- OPTION_UI_CLONE_COLOR,
- OPTION_UI_SELECTED_COLOR,
- OPTION_UI_SELECTED_BG_COLOR,
- OPTION_UI_MOUSEOVER_COLOR,
- OPTION_UI_MOUSEOVER_BG_COLOR,
- OPTION_UI_MOUSEDOWN_COLOR,
- OPTION_UI_MOUSEDOWN_BG_COLOR,
- OPTION_UI_DIPSW_COLOR,
- OPTION_UI_SLIDER_COLOR
-};
-
/***************************************************************************
GLOBAL VARIABLES
***************************************************************************/
@@ -197,7 +178,7 @@ void mame_ui_manager::init()
ui_gfx_init(machine());
get_font_rows(&machine());
- decode_ui_color(0, &machine());
+ m_ui_colors.refresh(options());
// more initialization
using namespace std::placeholders;
@@ -306,7 +287,7 @@ void mame_ui_manager::display_startup_screens(bool first_time)
for (int state = 0; state < maxstate && !machine().scheduled_event_pending() && !ui::menu::stack_has_special_main_menu(machine()); state++)
{
// default to standard colors
- messagebox_backcolor = UI_BACKGROUND_COLOR;
+ messagebox_backcolor = colors().background_color();
messagebox_text.clear();
// pick the next state
@@ -373,7 +354,7 @@ void mame_ui_manager::set_startup_text(const char *text, bool force)
// copy in the new text
messagebox_text.assign(text);
- messagebox_backcolor = UI_BACKGROUND_COLOR;
+ messagebox_backcolor = colors().background_color();
// don't update more than 4 times/second
if (force || (curtime - lastupdatetime) > osd_ticks_per_second() / 4)
@@ -432,7 +413,7 @@ void mame_ui_manager::update_and_render(render_container &container)
if (mouse_target->map_point_container(mouse_target_x, mouse_target_y, container, mouse_x, mouse_y))
{
const float cursor_size = 0.6 * get_line_height();
- container.add_quad(mouse_x, mouse_y, mouse_x + cursor_size * container.manager().ui_aspect(&container), mouse_y + cursor_size, UI_TEXT_COLOR, m_mouse_arrow_texture, PRIMFLAG_ANTIALIAS(1) | PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA));
+ container.add_quad(mouse_x, mouse_y, mouse_x + cursor_size * container.manager().ui_aspect(&container), mouse_y + cursor_size, colors().text_color(), m_mouse_arrow_texture, PRIMFLAG_ANTIALIAS(1) | PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA));
}
}
}
@@ -534,7 +515,7 @@ float mame_ui_manager::get_string_width(const char *s, float text_size)
void mame_ui_manager::draw_outlined_box(render_container &container, float x0, float y0, float x1, float y1, rgb_t backcolor)
{
- draw_outlined_box(container, x0, y0, x1, y1, UI_BORDER_COLOR, backcolor);
+ draw_outlined_box(container, x0, y0, x1, y1, colors().border_color(), backcolor);
}
@@ -560,7 +541,7 @@ void mame_ui_manager::draw_outlined_box(render_container &container, float x0, f
void mame_ui_manager::draw_text(render_container &container, const char *buf, float x, float y)
{
- draw_text_full(container, buf, x, y, 1.0f - x, ui::text_layout::LEFT, ui::text_layout::WORD, mame_ui_manager::NORMAL, UI_TEXT_COLOR, UI_TEXT_BG_COLOR, nullptr, nullptr);
+ draw_text_full(container, buf, x, y, 1.0f - x, ui::text_layout::LEFT, ui::text_layout::WORD, mame_ui_manager::NORMAL, colors().text_color(), colors().text_bg_color(), nullptr, nullptr);
}
@@ -648,7 +629,7 @@ void mame_ui_manager::draw_text_box(render_container &container, ui::text_layout
void mame_ui_manager::draw_message_window(render_container &container, const char *text)
{
- draw_text_box(container, text, ui::text_layout::text_justify::LEFT, 0.5f, 0.5f, UI_BACKGROUND_COLOR);
+ draw_text_box(container, text, ui::text_layout::text_justify::LEFT, 0.5f, 0.5f, colors().background_color());
}
@@ -1027,7 +1008,7 @@ void mame_ui_manager::image_handler_ingame()
{
float x = 0.2f;
float y = 0.5f * get_line_height() + 2.0f * UI_BOX_TB_BORDER;
- draw_text_box(machine().render().ui_container(), layout, x, y, UI_BACKGROUND_COLOR);
+ draw_text_box(machine().render().ui_container(), layout, x, y, colors().background_color());
}
}
}
@@ -2078,29 +2059,6 @@ void mame_ui_manager::draw_textured_box(render_container &container, float x0, f
}
//-------------------------------------------------
-// decode UI color options
-//-------------------------------------------------
-
-rgb_t decode_ui_color(int id, running_machine *machine)
-{
- static rgb_t color[ARRAY_LENGTH(s_color_list)];
-
- if (machine != nullptr) {
- ui_options option;
- for (int x = 0; x < ARRAY_LENGTH(s_color_list); ++x) {
- const char *o_default = option.value(s_color_list[x]);
- const char *s_option = mame_machine_manager::instance()->ui().options().value(s_color_list[x]);
- int len = strlen(s_option);
- if (len != 8)
- color[x] = rgb_t((uint32_t)strtoul(o_default, nullptr, 16));
- else
- color[x] = rgb_t((uint32_t)strtoul(s_option, nullptr, 16));
- }
- }
- return color[id];
-}
-
-//-------------------------------------------------
// get font rows from options
//-------------------------------------------------
@@ -2115,7 +2073,7 @@ void mame_ui_manager::popup_time_string(int seconds, std::string message)
{
// extract the text
messagebox_poptext = message;
- messagebox_backcolor = UI_BACKGROUND_COLOR;
+ messagebox_backcolor = colors().background_color();
// set a timer
m_popup_text_end = osd_ticks() + osd_ticks_per_second() * seconds;
@@ -2234,3 +2192,23 @@ void mame_ui_manager::menu_reset()
{
ui::menu::stack_reset(machine());
}
+
+void ui_colors::refresh(const ui_options &options)
+{
+ m_border_color = options.border_color();
+ m_background_color = options.background_color();
+ m_gfxviewer_bg_color = options.gfxviewer_bg_color();
+ m_unavailable_color = options.unavailable_color();
+ m_text_color = options.text_color();
+ m_text_bg_color = options.text_bg_color();
+ m_subitem_color = options.subitem_color();
+ m_clone_color = options.clone_color();
+ m_selected_color = options.selected_color();
+ m_selected_bg_color = options.selected_bg_color();
+ m_mouseover_color = options.mouseover_color();
+ m_mouseover_bg_color = options.mouseover_bg_color();
+ m_mousedown_color = options.mousedown_color();
+ m_mousedown_bg_color = options.mousedown_bg_color();
+ m_dipsw_color = options.dipsw_color();
+ m_slider_color = options.slider_color();
+}