diff options
Diffstat (limited to 'src/frontend/mame/ui/datmenu.cpp')
-rw-r--r-- | src/frontend/mame/ui/datmenu.cpp | 211 |
1 files changed, 35 insertions, 176 deletions
diff --git a/src/frontend/mame/ui/datmenu.cpp b/src/frontend/mame/ui/datmenu.cpp index 10c5e3c9717..df8ac0a7e67 100644 --- a/src/frontend/mame/ui/datmenu.cpp +++ b/src/frontend/mame/ui/datmenu.cpp @@ -24,6 +24,7 @@ #include "uiinput.h" #include <cmath> +#include <limits> #include <string_view> @@ -34,14 +35,14 @@ namespace ui { //------------------------------------------------- menu_dats_view::menu_dats_view(mame_ui_manager &mui, render_container &container, const ui_system_info *system) - : menu(mui, container) + : menu_textbox(mui, container) , m_system(!system ? &system_list::instance().systems()[driver_list::find(mui.machine().system().name)] : system) , m_swinfo(nullptr) , m_issoft(false) - , m_layout() , m_actual(0) { + set_process_flags(PROCESS_LR_ALWAYS | PROCESS_CUSTOM_NAV); for (device_image_interface& image : image_interface_enumerator(mui.machine().root_device())) { if (image.filename()) @@ -71,11 +72,10 @@ menu_dats_view::menu_dats_view(mame_ui_manager &mui, render_container &container //------------------------------------------------- menu_dats_view::menu_dats_view(mame_ui_manager &mui, render_container &container, const ui_software_info &swinfo) - : menu(mui, container) + : menu_textbox(mui, container) , m_system(nullptr) , m_swinfo(&swinfo) , m_issoft(true) - , m_layout() , m_actual(0) , m_list(swinfo.listname) , m_short(swinfo.shortname) @@ -83,6 +83,7 @@ menu_dats_view::menu_dats_view(mame_ui_manager &mui, render_container &container , m_parent(swinfo.parentname) { + set_process_flags(PROCESS_LR_ALWAYS | PROCESS_CUSTOM_NAV); if (!swinfo.infotext.empty()) m_items_list.emplace_back(_("Software List Info"), 0, ""); std::vector<std::string> lua_list; @@ -165,18 +166,17 @@ void menu_dats_view::add_info_text(text_layout &layout, std::string_view text, r // handle //------------------------------------------------- -void menu_dats_view::handle() +void menu_dats_view::handle(event const *ev) { - event const *const menu_event = process(PROCESS_LR_ALWAYS | PROCESS_CUSTOM_NAV); - if (menu_event) + if (ev) { - switch (menu_event->iptkey) + switch (ev->iptkey) { case IPT_UI_LEFT: if (m_actual > 0) { m_actual--; - reset(reset_options::SELECT_FIRST); + reset_layout(); } break; @@ -184,33 +184,12 @@ void menu_dats_view::handle() if ((m_actual + 1) < m_items_list.size()) { m_actual++; - reset(reset_options::SELECT_FIRST); + reset_layout(); } break; - case IPT_UI_UP: - --top_line; - break; - - case IPT_UI_DOWN: - ++top_line; - break; - - case IPT_UI_PAGE_UP: - top_line -= m_visible_lines - 3; - break; - - case IPT_UI_PAGE_DOWN: - top_line += m_visible_lines - 3; - break; - - case IPT_UI_HOME: - top_line = 0; - break; - - case IPT_UI_END: - top_line = m_layout->lines() - m_visible_lines; - break; + default: + handle_key(ev->iptkey); } } } @@ -221,150 +200,8 @@ void menu_dats_view::handle() void menu_dats_view::populate(float &customtop, float &custombottom) { - bool paused = machine().paused(); - if (!paused) - machine().pause(); - - m_layout = std::nullopt; - customtop = 2.0f * ui().get_line_height() + 4.0f * ui().box_tb_border(); custombottom = ui().get_line_height() + 3.0f * ui().box_tb_border(); - - if (!paused) - machine().resume(); -} - -//------------------------------------------------- -// draw - draw dats menu -//------------------------------------------------- - -void menu_dats_view::draw(uint32_t flags) -{ - float const aspect = machine().render().ui_aspect(&container()); - float const line_height = ui().get_line_height(); - float const ud_arrow_width = line_height * aspect; - float const gutter_width = 0.52f * line_height * aspect; - float const visible_width = 1.0f - (2.0f * ui().box_lr_border() * aspect); - float const visible_left = (1.0f - visible_width) * 0.5f; - float const extra_height = 2.0f * line_height; - float const visible_extra_menu_height = get_customtop() + get_custombottom() + extra_height; - - // determine effective positions taking into account the hilighting arrows - float const effective_width = visible_width - 2.0f * gutter_width; - float const effective_left = visible_left + gutter_width; - - draw_background(); - map_mouse(); - - // account for extra space at the top and bottom - float visible_main_menu_height = 1.0f - 2.0f * ui().box_tb_border() - visible_extra_menu_height; - m_visible_lines = int(std::trunc(visible_main_menu_height / line_height)); - visible_main_menu_height = float(m_visible_lines) * line_height; - - // compute top/left of inner menu area by centering, if the menu is at the bottom of the extra, adjust - float const visible_top = ((1.0f - (visible_main_menu_height + visible_extra_menu_height)) * 0.5f) + get_customtop(); - - // compute text box size - float const x1 = visible_left; - float const y1 = visible_top - ui().box_tb_border(); - float const x2 = x1 + visible_width; - float const y2 = visible_top + visible_main_menu_height + ui().box_tb_border() + extra_height; - float const line_x0 = x1 + 0.5f * UI_LINE_WIDTH; - float const line_x1 = x2 - 0.5f * UI_LINE_WIDTH; - float const separator = visible_top + float(m_visible_lines) * line_height; - - ui().draw_outlined_box(container(), x1, y1, x2, y2, ui().colors().background_color()); - - if (!m_layout || (m_layout->width() != effective_width)) - { - std::string buffer; - if (!m_items_list.empty()) - { - if (m_issoft) - get_data_sw(buffer); - else - get_data(buffer); - } - m_layout.emplace(ui().create_layout(container(), effective_width)); - add_info_text(*m_layout, buffer, ui().colors().text_color()); - } - int const visible_items = m_layout->lines(); - m_visible_lines = (std::min)(visible_items, m_visible_lines); - top_line = (std::max)(0, top_line); - if (top_line + m_visible_lines >= visible_items) - top_line = visible_items - m_visible_lines; - - clear_hover(); - if (top_line) - { - // if we're on the top line, display the up arrow - rgb_t fgcolor = ui().colors().text_color(); - if (mouse_in_rect(line_x0, visible_top, line_x1, visible_top + line_height)) - { - fgcolor = ui().colors().mouseover_color(); - highlight( - line_x0, visible_top, - line_x1, visible_top + line_height, - ui().colors().mouseover_bg_color()); - set_hover(HOVER_ARROW_UP); - } - draw_arrow( - 0.5f * (x1 + x2) - 0.5f * ud_arrow_width, visible_top + 0.25f * line_height, - 0.5f * (x1 + x2) + 0.5f * ud_arrow_width, visible_top + 0.75f * line_height, - fgcolor, ROT0); - } - if ((top_line + m_visible_lines) < visible_items) - { - // if we're on the bottom line, display the down arrow - float const line_y = visible_top + float(m_visible_lines - 1) * line_height; - rgb_t fgcolor = ui().colors().text_color(); - if (mouse_in_rect(line_x0, line_y, line_x1, line_y + line_height)) - { - fgcolor = ui().colors().mouseover_color(); - highlight( - line_x0, line_y, - line_x1, line_y + line_height, - ui().colors().mouseover_bg_color()); - set_hover(HOVER_ARROW_DOWN); - } - draw_arrow( - 0.5f * (x1 + x2) - 0.5f * ud_arrow_width, line_y + 0.25f * line_height, - 0.5f * (x1 + x2) + 0.5f * ud_arrow_width, line_y + 0.75f * line_height, - fgcolor, ROT0 ^ ORIENTATION_FLIP_Y); - } - - // return the number of visible lines, minus 1 for top arrow and 1 for bottom arrow - m_visible_items = m_visible_lines - (top_line ? 1 : 0) - (top_line + m_visible_lines != visible_items); - m_layout->emit( - container(), - top_line ? (top_line + 1) : 0, m_visible_items, - effective_left, visible_top + (top_line ? line_height : 0.0f)); - - // add visual separator before the "return to prevous menu" item - container().add_line( - x1, separator + (0.5f * line_height), - x2, separator + (0.5f * line_height), - UI_LINE_WIDTH, ui().colors().text_color(), PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); - - menu_item const &pitem = item(0); - std::string_view const itemtext = pitem.text; - float const line_y0 = separator + line_height; - float const line_y1 = line_y0 + line_height; - - if (mouse_in_rect(line_x0, line_y0, line_x1, line_y1) && is_selectable(pitem)) - set_hover(0); - - highlight(line_x0, line_y0, line_x1, line_y1, ui().colors().selected_bg_color()); - ui().draw_text_full( - container(), itemtext, - effective_left, line_y0, effective_width, - text_layout::text_justify::CENTER, text_layout::word_wrapping::TRUNCATE, - mame_ui_manager::NORMAL, - ui().colors().selected_color(), ui().colors().selected_bg_color(), - nullptr, nullptr); - - // if there is something special to add, do it by calling the virtual method - custom_render(get_selection_ref(), get_customtop(), get_custombottom(), x1, y1, x2, y2); } //------------------------------------------------- @@ -512,7 +349,7 @@ void menu_dats_view::custom_render(void *selectedref, float top, float bottom, f } //------------------------------------------------- -// load data from DATs +// custom mouse click handling //------------------------------------------------- bool menu_dats_view::custom_mouse_down() @@ -533,6 +370,28 @@ bool menu_dats_view::custom_mouse_down() } //------------------------------------------------- +// populate selected DAT text +//------------------------------------------------- + +void menu_dats_view::populate_text(std::optional<text_layout> &layout, float &width, int &lines) +{ + if (!layout || (layout->width() != width)) + { + std::string buffer; + if (!m_items_list.empty()) + { + if (m_issoft) + get_data_sw(buffer); + else + get_data(buffer); + } + layout.emplace(ui().create_layout(container(), width)); + add_info_text(*layout, buffer, ui().colors().text_color()); + lines = std::numeric_limits<int>::max(); + } +} + +//------------------------------------------------- // load data from DATs //------------------------------------------------- |