diff options
Diffstat (limited to 'src/frontend/mame/ui/ui.cpp')
-rw-r--r-- | src/frontend/mame/ui/ui.cpp | 209 |
1 files changed, 156 insertions, 53 deletions
diff --git a/src/frontend/mame/ui/ui.cpp b/src/frontend/mame/ui/ui.cpp index 62b84281b02..a0b55307dc6 100644 --- a/src/frontend/mame/ui/ui.cpp +++ b/src/frontend/mame/ui/ui.cpp @@ -30,6 +30,7 @@ #include "ui/state.h" #include "ui/viewgfx.h" #include "imagedev/cassette.h" +#include "config.h" #include "../osd/modules/lib/osdobj_common.h" @@ -93,6 +94,25 @@ 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 ***************************************************************************/ @@ -165,8 +185,7 @@ mame_ui_manager::mame_ui_manager(running_machine &machine) , m_popup_text_end(0) , m_mouse_bitmap(32, 32) , m_mouse_arrow_texture(nullptr) - , m_mouse_show(false) - , m_target_font_height(0) {} + , m_mouse_show(false) {} mame_ui_manager::~mame_ui_manager() { @@ -179,12 +198,10 @@ void mame_ui_manager::init() ui::menu::init(machine(), options()); ui_gfx_init(machine()); - m_ui_colors.refresh(options()); - - // update font row info from setting - update_target_font_height(); + get_font_rows(&machine()); + decode_ui_color(0, &machine()); - // more initialization + // more initialisation using namespace std::placeholders; set_handler(ui_callback_type::GENERAL, std::bind(&mame_ui_manager::handler_messagebox, this, _1)); m_non_char_keys_down = std::make_unique<uint8_t[]>((ARRAY_LENGTH(non_char_keys) + 7) / 8); @@ -192,6 +209,8 @@ void mame_ui_manager::init() // request a callback upon exiting machine().add_notifier(MACHINE_NOTIFY_EXIT, machine_notify_delegate(&mame_ui_manager::exit, this)); + // register callbacks + machine().configuration().config_register("sliders", config_load_delegate(&mame_ui_manager::config_load, this), config_save_delegate(&mame_ui_manager::config_save, this)); // create mouse bitmap uint32_t *dst = &m_mouse_bitmap.pix32(0); @@ -202,16 +221,6 @@ void mame_ui_manager::init() //------------------------------------------------- -// update_target_font_height -//------------------------------------------------- - -void mame_ui_manager::update_target_font_height() -{ - m_target_font_height = 1.0f / options().font_rows(); -} - - -//------------------------------------------------- // exit - clean up ourselves on exit //------------------------------------------------- @@ -302,7 +311,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 = colors().background_color(); + messagebox_backcolor = UI_BACKGROUND_COLOR; messagebox_text.clear(); // pick the next state @@ -369,7 +378,7 @@ void mame_ui_manager::set_startup_text(const char *text, bool force) // copy in the new text messagebox_text.assign(text); - messagebox_backcolor = colors().background_color(); + messagebox_backcolor = UI_BACKGROUND_COLOR; // don't update more than 4 times/second if (force || (curtime - lastupdatetime) > osd_ticks_per_second() / 4) @@ -416,7 +425,8 @@ void mame_ui_manager::update_and_render(render_container &container) m_popup_text_end = 0; // display the internal mouse cursor - if (m_mouse_show || (is_menu_active() && machine().options().ui_mouse())) + if (machine().options().ui_mouse() && (m_mouse_show || is_menu_active())) //MESSUI - (NEWUI) system pointer always on; MAME pointer always off +// if (m_mouse_show || (is_menu_active() && machine().options().ui_mouse())) { int32_t mouse_target_x, mouse_target_y; bool mouse_button; @@ -428,7 +438,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, colors().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, UI_TEXT_COLOR, m_mouse_arrow_texture, PRIMFLAG_ANTIALIAS(1) | PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); } } } @@ -472,7 +482,7 @@ float mame_ui_manager::get_line_height() one_to_one_line_height = (float)raw_font_pixel_height / (float)target_pixel_height; // determine the scale factor - scale_factor = target_font_height() / one_to_one_line_height; + scale_factor = UI_TARGET_FONT_HEIGHT / one_to_one_line_height; // if our font is small-ish, do integral scaling if (raw_font_pixel_height < 24) @@ -530,7 +540,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, colors().border_color(), backcolor); + draw_outlined_box(container, x0, y0, x1, y1, UI_BORDER_COLOR, backcolor); } @@ -556,7 +566,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, colors().text_color(), colors().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, UI_TEXT_COLOR, UI_TEXT_BG_COLOR, nullptr, nullptr); } @@ -598,7 +608,7 @@ void mame_ui_manager::draw_text_full(render_container &container, const char *or void mame_ui_manager::draw_text_box(render_container &container, const char *text, ui::text_layout::text_justify justify, float xpos, float ypos, rgb_t backcolor) { // cap the maximum width - float maximum_width = 1.0f - box_lr_border() * 2; + float maximum_width = 1.0f - UI_BOX_LR_BORDER * 2; // create a layout ui::text_layout layout = create_layout(container, maximum_width, justify); @@ -622,15 +632,15 @@ void mame_ui_manager::draw_text_box(render_container &container, ui::text_layout auto actual_left = layout.actual_left(); auto actual_width = layout.actual_width(); auto actual_height = layout.actual_height(); - auto x = std::min(std::max(xpos - actual_width / 2, box_lr_border()), 1.0f - actual_width - box_lr_border()); - auto y = std::min(std::max(ypos - actual_height / 2, box_tb_border()), 1.0f - actual_height - box_tb_border()); + auto x = std::min(std::max(xpos - actual_width / 2, UI_BOX_LR_BORDER), 1.0f - actual_width - UI_BOX_LR_BORDER); + auto y = std::min(std::max(ypos - actual_height / 2, UI_BOX_TB_BORDER), 1.0f - actual_height - UI_BOX_TB_BORDER); // add a box around that draw_outlined_box(container, - x - box_lr_border(), - y - box_tb_border(), - x + actual_width + box_lr_border(), - y + actual_height + box_tb_border(), backcolor); + x - UI_BOX_LR_BORDER, + y - UI_BOX_TB_BORDER, + x + actual_width + UI_BOX_LR_BORDER, + y + actual_height + UI_BOX_TB_BORDER, backcolor); // emit the text layout.emit(container, x - actual_left, y); @@ -644,7 +654,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, colors().background_color()); + draw_text_box(container, text, ui::text_layout::text_justify::LEFT, 0.5f, 0.5f, UI_BACKGROUND_COLOR); } @@ -1022,8 +1032,8 @@ void mame_ui_manager::image_handler_ingame() if (!layout.empty()) { float x = 0.2f; - float y = 0.5f * get_line_height() + 2.0f * box_tb_border(); - draw_text_box(machine().render().ui_container(), layout, x, y, colors().background_color()); + 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); } } } @@ -1512,6 +1522,7 @@ std::vector<ui::menu_item> mame_ui_manager::slider_init(running_machine &machine } } #endif + config_apply(); std::vector<ui::menu_item> items; for (auto &slider : m_sliders) @@ -2073,11 +2084,45 @@ void mame_ui_manager::draw_textured_box(render_container &container, float x0, f container.add_line(x0, y1, x0, y0, UI_LINE_WIDTH, linecolor, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); } +//------------------------------------------------- +// 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 +//------------------------------------------------- + +int get_font_rows(running_machine *machine) +{ + static int value; + + return ((machine != nullptr) ? value = mame_machine_manager::instance()->ui().options().font_rows() : value); +} + void mame_ui_manager::popup_time_string(int seconds, std::string message) { // extract the text messagebox_poptext = message; - messagebox_backcolor = colors().background_color(); + messagebox_backcolor = UI_BACKGROUND_COLOR; // set a timer m_popup_text_end = osd_ticks() + osd_ticks_per_second() * seconds; @@ -2197,22 +2242,80 @@ 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(); + +//------------------------------------------------- +// config_load - read data from the +// configuration file +//------------------------------------------------- + +void mame_ui_manager::config_load(config_type cfg_type, util::xml::data_node const *parentnode) +{ + // we only care about game files + if (cfg_type != config_type::GAME) + return; + + // might not have any data + if (parentnode == nullptr) + return; + + // iterate over slider nodes + for (util::xml::data_node const *slider_node = parentnode->get_child("slider"); slider_node; slider_node = slider_node->get_next_sibling("slider")) + { + const char *desc = slider_node->get_attribute_string("desc", ""); + int32_t saved_val = slider_node->get_attribute_int("value", 0); + + // create a dummy slider to store the saved value + m_sliders_saved.push_back(slider_alloc(0, desc, 0, saved_val, 0, 0, 0)); + } +} + + +//------------------------------------------------- +// config_appy - apply data from the conf. file +// This currently needs to be done on a separate +// step because sliders are not created yet when +// configuration file is loaded +//------------------------------------------------- + +void mame_ui_manager::config_apply(void) +{ + // iterate over sliders and restore saved values + for (auto &slider : m_sliders) + { + for (auto &slider_saved : m_sliders_saved) + { + if (!strcmp(slider->description.c_str(), slider_saved->description.c_str())) + { + std::string tempstring; + slider->update(machine(), slider->arg, slider->id, &tempstring, slider_saved->defval); + break; + } + } + } +} + + +//------------------------------------------------- +// config_save - save data to the configuration +// file +//------------------------------------------------- + +void mame_ui_manager::config_save(config_type cfg_type, util::xml::data_node *parentnode) +{ + // we only care about game files + if (cfg_type != config_type::GAME) + return; + + std::string tempstring; + util::xml::data_node *slider_node; + + // save UI sliders + for (auto &slider : m_sliders) + { + int32_t curval = slider->update(machine(), slider->arg, slider->id, &tempstring, SLIDER_NOCHANGE); + slider_node = parentnode->add_child("slider", nullptr); + slider_node->set_attribute("desc", slider->description.c_str()); + slider_node->set_attribute_int("value", curval); + } } + |