diff options
author | Vas Crabb <vas@vastheman.com> | 2023-01-04 16:21:15 +1100 |
---|---|---|
committer | Vas Crabb <vas@vastheman.com> | 2023-01-04 16:21:15 +1100 |
commit | fcee73320b0ddf778202eed51b06330f5c98f9f3 (patch) | |
tree | 995de44a6fd78974ba0b40d05d68ebebe859f9a8 /src/frontend/mame/ui | |
parent | b7fab7f35e45cccfebbfbb1edb7a3d79be64ae42 (diff) |
ui: Give menus an opportunity to recompute metrics on window resize.
Also reworked calculation of menu geometry in general, and limited width
of left panel on system/software selection menus.
Fixes images in the right panel and icons on the system/software
selection menus not being scaled correctly when the window is resized
(MT08539 is an example of this).
Fixes bad font size selection at low resolutions when using bitmap fonts
like uismall.bdf (GitHub #7105).
Fixes collapse/expand arrows on left/right panels of system/softwre
selection menus getting bigger if the window is made narrower.
Diffstat (limited to 'src/frontend/mame/ui')
32 files changed, 708 insertions, 605 deletions
diff --git a/src/frontend/mame/ui/about.cpp b/src/frontend/mame/ui/about.cpp index 05ba893ae00..715815399f9 100644 --- a/src/frontend/mame/ui/about.cpp +++ b/src/frontend/mame/ui/about.cpp @@ -72,9 +72,9 @@ void menu_about::custom_render(void *selectedref, float top, float bottom, float // draw the title draw_text_box( std::begin(m_header), std::end(m_header), - origx1, origx2, origy1 - top, origy1 - ui().box_tb_border(), + origx1, origx2, origy1 - top, origy1 - tb_border(), text_layout::text_justify::CENTER, text_layout::word_wrapping::TRUNCATE, false, - ui().colors().text_color(), UI_GREEN_COLOR, 1.0f); + ui().colors().text_color(), UI_GREEN_COLOR); } @@ -87,7 +87,7 @@ void menu_about::populate_text(std::optional<text_layout> &layout, float &width, if (!layout || (layout->width() != width)) { rgb_t const color = ui().colors().text_color(); - layout.emplace(ui().create_layout(container(), width)); + layout.emplace(create_layout(width)); for (char const *const *line = copying_text; *line; ++line) { layout->add_text(*line, color); @@ -106,7 +106,7 @@ void menu_about::populate_text(std::optional<text_layout> &layout, float &width, void menu_about::populate(float &customtop, float &custombottom) { // make space for the title and revision - customtop = (ui().get_line_height() * m_header.size()) + (ui().box_tb_border() * 3.0f); + customtop = (line_height() * m_header.size()) + (tb_border() * 3.0f); } diff --git a/src/frontend/mame/ui/analogipt.cpp b/src/frontend/mame/ui/analogipt.cpp index d8c22431ddd..4e3b15aecc8 100644 --- a/src/frontend/mame/ui/analogipt.cpp +++ b/src/frontend/mame/ui/analogipt.cpp @@ -71,15 +71,13 @@ void menu_analog::custom_render(void *selectedref, float top, float bottom, floa // work out how much space to use for field names float const aspect(machine().render().ui_aspect(&container())); float const extrawidth(0.4f + (((ui().box_lr_border() * 2.0f) + ui().get_line_height()) * aspect)); - float const nameavail(1.0f - (ui().box_lr_border() * 2.0f * aspect) - extrawidth); + float const nameavail(1.0f - (lr_border() * 2.0f) - extrawidth); float namewidth(0.0f); for (field_data &data : m_field_data) - namewidth = (std::min)((std::max)(ui().get_string_width(data.field.get().name()), namewidth), nameavail); + namewidth = (std::min)((std::max)(get_string_width(data.field.get().name()), namewidth), nameavail); // make a box or two rgb_t const fgcolor(ui().colors().text_color()); - float const lineheight(ui().get_line_height()); - float const border(ui().box_tb_border()); float const boxleft((1.0f - namewidth - extrawidth) / 2.0f); float const boxright(boxleft + namewidth + extrawidth); float boxtop; @@ -92,19 +90,19 @@ void menu_analog::custom_render(void *selectedref, float top, float bottom, floa m_prompt = util::string_format(_("Press %s to show menu"), ui().get_general_input_setting(IPT_UI_ON_SCREEN_DISPLAY)); draw_text_box( &m_prompt, &m_prompt + 1, - boxleft, boxright, y - top, y - top + lineheight + (border * 2.0f), + boxleft, boxright, y - top, y - top + line_height() + (tb_border() * 2.0f), text_layout::text_justify::CENTER, text_layout::word_wrapping::TRUNCATE, false, - fgcolor, ui().colors().background_color(), 1.0f); - boxtop = y - top + lineheight + (border * 3.0f); - firstliney = y - top + lineheight + (border * 4.0f); - visible_fields = std::min<int>(m_field_data.size(), int((y2 + bottom - border - firstliney) / lineheight)); - boxbottom = firstliney + (lineheight * visible_fields) + border; + fgcolor, ui().colors().background_color()); + boxtop = y - top + line_height() + (tb_border() * 3.0f); + firstliney = y - top + line_height() + (tb_border() * 4.0f); + visible_fields = std::min<int>(m_field_data.size(), int((y2 + bottom - tb_border() - firstliney) / line_height())); + boxbottom = firstliney + (line_height() * visible_fields) + tb_border(); } else { - boxtop = y2 + border; + boxtop = y2 + tb_border(); boxbottom = y2 + bottom; - firstliney = y2 + (border * 2.0f); + firstliney = y2 + (tb_border() * 2.0f); visible_fields = m_visible_fields; } ui().draw_outlined_box(container(), boxleft, boxtop, boxright, boxbottom, ui().colors().background_color()); @@ -133,24 +131,24 @@ void menu_analog::custom_render(void *selectedref, float top, float bottom, floa m_top_field = m_field_data.size() - visible_fields; // show live fields - namewidth += lineheight * aspect; - float const nameleft(boxleft + (ui().box_lr_border() * aspect)); + namewidth += line_height() * aspect; + float const nameleft(boxleft + lr_border()); float const indleft(nameleft + namewidth); float const indright(indleft + 0.4f); for (unsigned line = 0; visible_fields > line; ++line) { // draw arrows if scrolling is possible and menu is hidden - float const liney(firstliney + (lineheight * line)); + float const liney(firstliney + (line_height() * line)); if (m_hide_menu) { bool const uparrow(!line && m_top_field); bool const downarrow(((visible_fields - 1) == line) && ((m_field_data.size() - 1) > (line + m_top_field))); if (uparrow || downarrow) { - float const arrowwidth = lineheight * aspect; + float const arrowwidth = line_height() * aspect; draw_arrow( - 0.5f * (nameleft + indright - arrowwidth), liney + (0.25f * lineheight), - 0.5f * (nameleft + indright + arrowwidth), liney + (0.75f * lineheight), + 0.5f * (nameleft + indright - arrowwidth), liney + (0.25f * line_height()), + 0.5f * (nameleft + indright + arrowwidth), liney + (0.75f * line_height()), fgcolor, line ? (ROT0 ^ ORIENTATION_FLIP_Y) : ROT0); continue; } @@ -160,12 +158,11 @@ void menu_analog::custom_render(void *selectedref, float top, float bottom, floa field_data &data(m_field_data[line + m_top_field]); bool const selected(&data.field.get() == selfield); rgb_t const fieldcolor(selected ? ui().colors().selected_color() : fgcolor); - ui().draw_text_full( - container(), + draw_text_normal( data.field.get().name(), nameleft, liney, namewidth, text_layout::text_justify::LEFT, text_layout::word_wrapping::NEVER, - mame_ui_manager::NORMAL, fieldcolor, ui().colors().text_bg_color()); + fieldcolor); ioport_value cur(0U); data.field.get().live().analog->read(cur); @@ -174,8 +171,8 @@ void menu_analog::custom_render(void *selectedref, float top, float bottom, floa if (data.field.get().analog_reverse()) fill = 1.0f - fill; - float const indtop(liney + (lineheight * 0.2f)); - float const indbottom(liney + (lineheight * 0.8f)); + float const indtop(liney + (line_height() * 0.2f)); + float const indbottom(liney + (line_height() * 0.8f)); if (data.origin > fill) container().add_rect(indleft + (fill * 0.4f), indtop, indleft + (data.origin * 0.4f), indbottom, fgcolor, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); else @@ -404,7 +401,7 @@ void menu_analog::populate(float &customtop, float &custombottom) item_append(menu_item_type::SEPARATOR); // space for live display - custombottom = (ui().get_line_height() * m_visible_fields) + (ui().box_tb_border() * 3.0f); + custombottom = (line_height() * m_visible_fields) + (tb_border() * 3.0f); } @@ -456,8 +453,8 @@ void menu_analog::find_fields() } // restrict live display to 40% height plus borders - if ((ui().get_line_height() * m_field_data.size()) > 0.4f) - m_visible_fields = unsigned(0.4f / ui().get_line_height()); + if ((line_height() * m_field_data.size()) > 0.4f) + m_visible_fields = unsigned(0.4f / line_height()); else m_visible_fields = m_field_data.size(); } diff --git a/src/frontend/mame/ui/auditmenu.cpp b/src/frontend/mame/ui/auditmenu.cpp index ae585d6e2ed..b8656d3163c 100644 --- a/src/frontend/mame/ui/auditmenu.cpp +++ b/src/frontend/mame/ui/auditmenu.cpp @@ -83,9 +83,9 @@ void menu_audit::custom_render(void *selectedref, float top, float bottom, float { draw_text_box( &m_prompt, &m_prompt + 1, - x, x2, y2 + ui().box_tb_border(), y2 + bottom, + x, x2, y2 + tb_border(), y2 + bottom, text_layout::text_justify::CENTER, text_layout::word_wrapping::NEVER, false, - ui().colors().text_color(), UI_GREEN_COLOR, 1.0f); + ui().colors().text_color(), UI_GREEN_COLOR); } break; @@ -139,7 +139,7 @@ void menu_audit::populate(float &customtop, float &custombottom) item_append(util::string_format(_("Audit media for %1$u systems marked unavailable"), m_unavailable), 0, ITEMREF_START_FAST); item_append(util::string_format(_("Audit media for all %1$u systems"), m_availablesorted.size()), 0, ITEMREF_START_FULL); item_append(menu_item_type::SEPARATOR, 0); - custombottom = (ui().get_line_height() * 1.0f) + (ui().box_tb_border() * 3.0f); + custombottom = (line_height() * 1.0f) + (tb_border() * 3.0f); } void menu_audit::handle(event const *ev) diff --git a/src/frontend/mame/ui/confswitch.cpp b/src/frontend/mame/ui/confswitch.cpp index 5440b5545ec..f267d7fa725 100644 --- a/src/frontend/mame/ui/confswitch.cpp +++ b/src/frontend/mame/ui/confswitch.cpp @@ -328,9 +328,8 @@ void menu_settings_dip_switches::custom_render(void *selectedref, float top, flo // calculate optimal width float const aspect(machine().render().ui_aspect(&container())); - float const lineheight(ui().get_line_height()); - float const maxwidth(1.0f - (ui().box_lr_border() * 2.0f * aspect)); - m_single_width = (lineheight * SINGLE_TOGGLE_SWITCH_FIELD_WIDTH * aspect); + float const maxwidth(1.0f - (lr_border() * 2.0f)); + m_single_width = (line_height() * SINGLE_TOGGLE_SWITCH_FIELD_WIDTH * aspect); float width(0.0f); unsigned maxswitches(0U); for (switch_group_descriptor const &group : switch_groups()) @@ -338,30 +337,30 @@ void menu_settings_dip_switches::custom_render(void *selectedref, float top, flo if (group.mask) { maxswitches = (std::max)(group.switch_count(), maxswitches); - float const namewidth(ui().get_string_width(group.name)); + float const namewidth(get_string_width(group.name)); float const switchwidth(m_single_width * maxswitches); - width = (std::min)((std::max)(namewidth + switchwidth + (lineheight * aspect), width), maxwidth); + width = (std::min)((std::max)(namewidth + switchwidth + (line_height() * aspect), width), maxwidth); } } // draw extra menu area - float const boxwidth((std::max)(width + (ui().box_lr_border() * 2.0f * aspect), x2 - x1)); + float const boxwidth((std::max)(width + (lr_border() * 2.0f), x2 - x1)); float const boxleft((1.0f - boxwidth) * 0.5f); - ui().draw_outlined_box(container(), boxleft, y2 + ui().box_tb_border(), boxleft + boxwidth, y2 + bottom, ui().colors().background_color()); + ui().draw_outlined_box(container(), boxleft, y2 + tb_border(), boxleft + boxwidth, y2 + bottom, ui().colors().background_color()); // calculate centred layout float const nameleft((1.0f - width) * 0.5f); float const switchleft(nameleft + width - (m_single_width * maxswitches)); - float const namewidth(width - (m_single_width * maxswitches) - (lineheight * aspect)); + float const namewidth(width - (m_single_width * maxswitches) - (line_height() * aspect)); // iterate over switch groups ioport_field *const field((uintptr_t(selectedref) != 1U) ? reinterpret_cast<ioport_field *>(selectedref) : nullptr); - float const nubheight(lineheight * SINGLE_TOGGLE_SWITCH_HEIGHT); - m_nub_width = lineheight * SINGLE_TOGGLE_SWITCH_WIDTH * aspect; - float const ygap(lineheight * ((DIP_SWITCH_HEIGHT * 0.5f) - SINGLE_TOGGLE_SWITCH_HEIGHT) * 0.5f); + float const nubheight(line_height() * SINGLE_TOGGLE_SWITCH_HEIGHT); + m_nub_width = line_height() * SINGLE_TOGGLE_SWITCH_WIDTH * aspect; + float const ygap(line_height() * ((DIP_SWITCH_HEIGHT * 0.5f) - SINGLE_TOGGLE_SWITCH_HEIGHT) * 0.5f); float const xgap((m_single_width + (UI_LINE_WIDTH * 0.5f) - m_nub_width) * 0.5f); m_first_nub = switchleft + xgap; - m_clickable_height = (lineheight * DIP_SWITCH_HEIGHT) - (ygap * 2.0f); + m_clickable_height = (line_height() * DIP_SWITCH_HEIGHT) - (ygap * 2.0f); unsigned line(0U); for (unsigned n = 0; switch_groups().size() > n; ++n) { @@ -378,16 +377,15 @@ void menu_settings_dip_switches::custom_render(void *selectedref, float top, flo } // draw the name - float const liney(y2 + (ui().box_tb_border() * 2.0f) + (lineheight * (DIP_SWITCH_HEIGHT + DIP_SWITCH_SPACING) * line)); - ui().draw_text_full( - container(), + float const liney(y2 + (tb_border() * 2.0f) + (line_height() * (DIP_SWITCH_HEIGHT + DIP_SWITCH_SPACING) * line)); + draw_text_normal( group.name, - nameleft, liney + (lineheight * (DIP_SWITCH_HEIGHT - 1.0f) / 2.0f), namewidth, + nameleft, liney + (line_height() * (DIP_SWITCH_HEIGHT - 1.0f) / 2.0f), namewidth, text_layout::text_justify::RIGHT, text_layout::word_wrapping::NEVER, - mame_ui_manager::NORMAL, ui().colors().text_color(), PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); + ui().colors().text_color()); // draw the group outline - float const switchbottom(liney + (DIP_SWITCH_HEIGHT * lineheight)); + float const switchbottom(liney + (DIP_SWITCH_HEIGHT * line_height())); unsigned const cnt(group.switch_count()); ui().draw_outlined_box( container(), @@ -481,14 +479,13 @@ void menu_settings_dip_switches::populate(float &customtop, float &custombottom) if (active_switch_groups()) { m_switch_group_y.resize(switch_groups().size()); - float const lineheight(ui().get_line_height()); - float const groupheight(DIP_SWITCH_HEIGHT * lineheight); - float const groupspacing(DIP_SWITCH_SPACING * lineheight); + float const groupheight(DIP_SWITCH_HEIGHT * line_height()); + float const groupspacing(DIP_SWITCH_SPACING * line_height()); if ((active_switch_groups() * (groupheight + groupspacing)) > 0.7f) m_visible_switch_groups = unsigned(0.7f / (groupheight + groupspacing)); else m_visible_switch_groups = active_switch_groups(); - custombottom = (m_visible_switch_groups * groupheight) + ((m_visible_switch_groups - 1) * groupspacing) + (ui().box_tb_border() * 3.0f); + custombottom = (m_visible_switch_groups * groupheight) + ((m_visible_switch_groups - 1) * groupspacing) + (tb_border() * 3.0f); } else { diff --git a/src/frontend/mame/ui/custui.cpp b/src/frontend/mame/ui/custui.cpp index febb6a89472..c4d9e12ea70 100644 --- a/src/frontend/mame/ui/custui.cpp +++ b/src/frontend/mame/ui/custui.cpp @@ -516,7 +516,7 @@ void menu_font_ui::populate(float &customtop, float &custombottom) item_append(menu_item_type::SEPARATOR); - custombottom = ui().get_line_height() + 3.0f * ui().box_tb_border(); + custombottom = line_height() + 3.0f * tb_border(); } //------------------------------------------------- @@ -530,9 +530,9 @@ void menu_font_ui::custom_render(void *selectedref, float top, float bottom, flo char const *const bottomtext[] = { _("Sample text - Lorem ipsum dolor sit amet, consectetur adipiscing elit.") }; draw_text_box( std::begin(bottomtext), std::end(bottomtext), - origx1, origx2, origy2 + ui().box_tb_border(), origy2 + bottom, + origx1, origx2, origy2 + tb_border(), origy2 + bottom, text_layout::text_justify::LEFT, text_layout::word_wrapping::NEVER, false, - ui().colors().text_color(), UI_GREEN_COLOR, m_info_size); + ui().colors().text_color(), UI_GREEN_COLOR, ui().get_line_height(m_info_size)); } } @@ -627,7 +627,7 @@ void menu_colors_ui::populate(float &customtop, float &custombottom) item_append(_("Restore default colors"), 0, (void *)(uintptr_t)MUI_RESTORE); - custombottom = ui().get_line_height() + 3.0f * ui().box_tb_border(); + custombottom = line_height() + 3.0f * tb_border(); } //------------------------------------------------- @@ -640,22 +640,15 @@ void menu_colors_ui::custom_render(void *selectedref, float top, float bottom, f std::string const bottomtext[] = { util::string_format(_("Double-click or press %1$s to change color"), ui().get_general_input_setting(IPT_UI_SELECT)) }; draw_text_box( std::begin(bottomtext), std::end(bottomtext), - origx1, origx2, origy2 + ui().box_tb_border(), origy2 + bottom, + origx1, origx2, origy2 + tb_border(), origy2 + bottom, text_layout::text_justify::CENTER, text_layout::word_wrapping::TRUNCATE, false, - ui().colors().text_color(), ui().colors().background_color(), 1.0f); + ui().colors().text_color(), ui().colors().background_color()); // compute maxwidth char const *const topbuf = _("Menu Preview"); - const float lr_border = ui().box_lr_border() * machine().render().ui_aspect(&container()); - float width; - ui().draw_text_full( - container(), - topbuf, - 0.0f, 0.0f, 1.0f, - text_layout::text_justify::CENTER, text_layout::word_wrapping::NEVER, - mame_ui_manager::NONE, rgb_t::white(), rgb_t::black(), &width, nullptr); - float maxwidth = width + 2.0f * lr_border; + float width = get_string_width(topbuf); + float maxwidth = width + 2.0f * lr_border(); std::string sampletxt[5]; @@ -667,53 +660,45 @@ void menu_colors_ui::custom_render(void *selectedref, float top, float bottom, f for (auto & elem: sampletxt) { - ui().draw_text_full( - container(), - elem, - 0.0f, 0.0f, 1.0f, - text_layout::text_justify::CENTER, text_layout::word_wrapping::NEVER, - mame_ui_manager::NONE, rgb_t::white(), rgb_t::black(), &width, nullptr); - width += 2 * lr_border; - maxwidth = std::max(maxwidth, width); + width = get_string_width(elem); + maxwidth = std::max(maxwidth, width + 2.0f * lr_border()); } // compute our bounds for header - float x1 = origx2 + 2.0f * lr_border; + float x1 = origx2 + 2.0f * lr_border(); float x2 = x1 + maxwidth; float y1 = origy1; - float y2 = y1 + bottom - ui().box_tb_border(); + float y2 = y1 + bottom - tb_border(); // draw a box ui().draw_outlined_box(container(), x1, y1, x2, y2, UI_GREEN_COLOR); // take off the borders - x1 += lr_border; - x2 -= lr_border; - y1 += ui().box_tb_border(); - y2 -= ui().box_tb_border(); + x1 += lr_border(); + x2 -= lr_border(); + y1 += tb_border(); + y2 -= tb_border(); // draw the text within it - ui().draw_text_full( - container(), + draw_text_normal( topbuf, x1, y1, x2 - x1, text_layout::text_justify::CENTER, text_layout::word_wrapping::NEVER, - mame_ui_manager::NORMAL, ui().colors().text_color(), ui().colors().text_bg_color(), nullptr, nullptr); + ui().colors().text_color()); // compute our bounds for menu preview - float line_height = ui().get_line_height(); - x1 -= lr_border; - x2 += lr_border; - y1 = y2 + 2.0f * ui().box_tb_border(); - y2 = y1 + 5.0f * line_height + 2.0f * ui().box_tb_border(); + x1 -= lr_border(); + x2 += lr_border(); + y1 = y2 + 2.0f * tb_border(); + y2 = y1 + 5.0f * line_height() + 2.0f * tb_border(); // draw a box ui().draw_outlined_box(container(), x1, y1, x2, y2, m_color_table[MUI_BACKGROUND_COLOR].color); // take off the borders - x1 += lr_border; - x2 -= lr_border; - y1 += ui().box_tb_border(); + x1 += lr_border(); + x2 -= lr_border(); + y1 += tb_border(); // draw normal text ui().draw_text_full( @@ -721,8 +706,10 @@ void menu_colors_ui::custom_render(void *selectedref, float top, float bottom, f sampletxt[0], x1, y1, x2 - x1, text_layout::text_justify::CENTER, text_layout::word_wrapping::NEVER, - mame_ui_manager::NORMAL, m_color_table[MUI_TEXT_COLOR].color, m_color_table[MUI_TEXT_BG_COLOR].color, nullptr, nullptr); - y1 += line_height; + mame_ui_manager::NORMAL, m_color_table[MUI_TEXT_COLOR].color, m_color_table[MUI_TEXT_BG_COLOR].color, + nullptr, nullptr, + line_height()); + y1 += line_height(); // draw subitem text ui().draw_text_full( @@ -730,28 +717,34 @@ void menu_colors_ui::custom_render(void *selectedref, float top, float bottom, f sampletxt[1], x1, y1, x2 - x1, text_layout::text_justify::CENTER, text_layout::word_wrapping::NEVER, - mame_ui_manager::NORMAL, m_color_table[MUI_SUBITEM_COLOR].color, m_color_table[MUI_TEXT_BG_COLOR].color, nullptr, nullptr); - y1 += line_height; + mame_ui_manager::NORMAL, m_color_table[MUI_SUBITEM_COLOR].color, m_color_table[MUI_TEXT_BG_COLOR].color, + nullptr, nullptr, + line_height()); + y1 += line_height(); // draw selected text - highlight(x1, y1, x2, y1 + line_height, m_color_table[MUI_SELECTED_BG_COLOR].color); + highlight(x1, y1, x2, y1 + line_height(), m_color_table[MUI_SELECTED_BG_COLOR].color); ui().draw_text_full( container(), sampletxt[2], x1, y1, x2 - x1, text_layout::text_justify::CENTER, text_layout::word_wrapping::NEVER, - mame_ui_manager::NORMAL, m_color_table[MUI_SELECTED_COLOR].color, m_color_table[MUI_SELECTED_BG_COLOR].color, nullptr, nullptr); - y1 += line_height; + mame_ui_manager::NORMAL, m_color_table[MUI_SELECTED_COLOR].color, m_color_table[MUI_SELECTED_BG_COLOR].color, + nullptr, nullptr, + line_height()); + y1 += line_height(); // draw mouse over text - highlight(x1, y1, x2, y1 + line_height, m_color_table[MUI_MOUSEOVER_BG_COLOR].color); + highlight(x1, y1, x2, y1 + line_height(), m_color_table[MUI_MOUSEOVER_BG_COLOR].color); ui().draw_text_full( container(), sampletxt[3], x1, y1, x2 - x1, text_layout::text_justify::CENTER, text_layout::word_wrapping::NEVER, - mame_ui_manager::NORMAL, m_color_table[MUI_MOUSEOVER_COLOR].color, m_color_table[MUI_MOUSEOVER_BG_COLOR].color, nullptr, nullptr); - y1 += line_height; + mame_ui_manager::NORMAL, m_color_table[MUI_MOUSEOVER_COLOR].color, m_color_table[MUI_MOUSEOVER_BG_COLOR].color, + nullptr, nullptr, + line_height()); + y1 += line_height(); // draw clone text ui().draw_text_full( @@ -759,8 +752,9 @@ void menu_colors_ui::custom_render(void *selectedref, float top, float bottom, f sampletxt[4], x1, y1, x2 - x1, text_layout::text_justify::CENTER, text_layout::word_wrapping::NEVER, - mame_ui_manager::NORMAL, m_color_table[MUI_CLONE_COLOR].color, m_color_table[MUI_TEXT_BG_COLOR].color, nullptr, nullptr); - + mame_ui_manager::NORMAL, m_color_table[MUI_CLONE_COLOR].color, m_color_table[MUI_TEXT_BG_COLOR].color, + nullptr, nullptr, + line_height()); } //------------------------------------------------- @@ -916,7 +910,7 @@ void menu_rgb_ui::populate(float &customtop, float &custombottom) item_append(_("Choose from palette"), 0, (void *)(uintptr_t)PALETTE_CHOOSE); item_append(menu_item_type::SEPARATOR); - custombottom = ui().get_line_height() + 3.0f * ui().box_tb_border(); + custombottom = line_height() + 3.0f * tb_border(); } //------------------------------------------------- @@ -925,45 +919,39 @@ void menu_rgb_ui::populate(float &customtop, float &custombottom) void menu_rgb_ui::custom_render(void *selectedref, float top, float bottom, float origx1, float origy1, float origx2, float origy2) { - const float lr_border = ui().box_lr_border() * machine().render().ui_aspect(&container()); float maxwidth = origx2 - origx1; std::string sampletxt(_("Color preview:")); - float width; - ui().draw_text_full( - container(), - sampletxt, - 0.0f, 0.0f, 1.0f, - text_layout::text_justify::CENTER, text_layout::word_wrapping::NEVER, - mame_ui_manager::NONE, rgb_t::white(), rgb_t::black(), - &width); - width += 2 * lr_border; + float width = get_string_width(sampletxt); + width += 2 * lr_border(); maxwidth = std::max(origx2 - origx1, width); // compute our bounds float x1 = 0.5f - 0.5f * maxwidth; float x2 = x1 + maxwidth; - float y1 = origy2 + ui().box_tb_border(); + float y1 = origy2 + tb_border(); float y2 = origy2 + bottom; // draw a box - force black to ensure the text is legible ui().draw_outlined_box(container(), x1, y1, x2, y2, rgb_t::black()); // take off the borders - x1 += lr_border; - y1 += ui().box_tb_border(); + x1 += lr_border(); + y1 += tb_border(); // draw the text label - force white to ensure it's legible ui().draw_text_full( container(), sampletxt, - x1, y1, width - lr_border, + x1, y1, width - lr_border(), text_layout::text_justify::CENTER, text_layout::word_wrapping::NEVER, - mame_ui_manager::NORMAL, rgb_t::white(), rgb_t::black()); + mame_ui_manager::NORMAL, rgb_t::white(), rgb_t::black(), + nullptr, nullptr, + line_height()); - x1 += width + (lr_border * 2.0f); - x2 -= lr_border; - y2 -= ui().box_tb_border(); + x1 += width + (lr_border() * 2.0f); + x2 -= lr_border(); + y2 -= tb_border(); // add white under half the sample swatch to make alpha effects visible container().add_rect((x1 + x2) * 0.5f, y1, x2, y2, rgb_t::white(), PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); diff --git a/src/frontend/mame/ui/datmenu.cpp b/src/frontend/mame/ui/datmenu.cpp index c99a09c367f..2d65f2a8484 100644 --- a/src/frontend/mame/ui/datmenu.cpp +++ b/src/frontend/mame/ui/datmenu.cpp @@ -200,8 +200,8 @@ void menu_dats_view::handle(event const *ev) void menu_dats_view::populate(float &customtop, float &custombottom) { - customtop = 2.0f * ui().get_line_height() + 4.0f * ui().box_tb_border(); - custombottom = ui().get_line_height() + 3.0f * ui().box_tb_border(); + customtop = 2.0f * line_height() + 4.0f * tb_border(); + custombottom = line_height() + 3.0f * tb_border(); } //------------------------------------------------- @@ -214,63 +214,50 @@ void menu_dats_view::custom_render(void *selectedref, float top, float bottom, f float width; std::string_view const driver = m_issoft ? m_swinfo->longname : m_system->description; - float const lr_border = ui().box_lr_border() * machine().render().ui_aspect(&container()); - ui().draw_text_full( - container(), - driver, - 0.0f, 0.0f, 1.0f, - ui::text_layout::text_justify::CENTER, text_layout::word_wrapping::TRUNCATE, - mame_ui_manager::NONE, rgb_t::white(), rgb_t::black(), &width, nullptr); - width += 2 * lr_border; + width = get_string_width(driver); + width += 2 * lr_border(); maxwidth = std::max(maxwidth, width); // compute our bounds float x1 = 0.5f - 0.5f * maxwidth; float x2 = x1 + maxwidth; float y1 = origy1 - top; - float y2 = origy1 - 2.0f * ui().box_tb_border() - ui().get_line_height(); + float y2 = origy1 - 2.0f * tb_border() - line_height(); // draw a box ui().draw_outlined_box(container(), x1, y1, x2, y2, UI_GREEN_COLOR); // take off the borders - x1 += lr_border; - x2 -= lr_border; - y1 += ui().box_tb_border(); + x1 += lr_border(); + x2 -= lr_border(); + y1 += tb_border(); - ui().draw_text_full( - container(), + draw_text_normal( driver, x1, y1, x2 - x1, text_layout::text_justify::CENTER, ui::text_layout::word_wrapping::NEVER, - mame_ui_manager::NORMAL, ui().colors().text_color(), ui().colors().text_bg_color()); + ui().colors().text_color()); maxwidth = 0; for (auto const &elem : m_items_list) { - ui().draw_text_full( - container(), - elem.label, - 0.0f, 0.0f, 1.0f, - text_layout::text_justify::CENTER, text_layout::word_wrapping::NEVER, - mame_ui_manager::NONE, rgb_t::white(), rgb_t::black(), - &width, nullptr); + width = get_string_width(elem.label); maxwidth += width; } float space = (1.0f - maxwidth) / (m_items_list.size() * 2); // compute our bounds - x1 -= lr_border; - x2 += lr_border; - y1 = y2 + ui().box_tb_border(); - y2 += ui().get_line_height() + 2.0f * ui().box_tb_border(); + x1 -= lr_border(); + x2 += lr_border(); + y1 = y2 + tb_border(); + y2 += line_height() + 2.0f * tb_border(); // draw a box ui().draw_outlined_box(container(), x1, y1, x2, y2, ui().colors().background_color()); // take off the borders - y1 += ui().box_tb_border(); + y1 += tb_border(); // draw the text within it int x = 0; @@ -282,13 +269,7 @@ void menu_dats_view::custom_render(void *selectedref, float top, float bottom, f rgb_t const fcolor = (m_actual == x) ? rgb_t(0xff, 0xff, 0xff, 0x00) : ui().colors().text_color(); rgb_t const bcolor = (m_actual == x) ? rgb_t(0xff, 0xff, 0xff, 0xff) : ui().colors().text_bg_color(); - ui().draw_text_full( - container(), - elem.label, - x1, y1, 1.0f, - text_layout::text_justify::LEFT, text_layout::word_wrapping::NEVER, - mame_ui_manager::NONE, fcolor, bcolor, - &width, nullptr); + width = get_string_width(elem.label); if (bcolor != ui().colors().text_bg_color()) { @@ -305,7 +286,8 @@ void menu_dats_view::custom_render(void *selectedref, float top, float bottom, f x1, y1, 1.0f, text_layout::text_justify::LEFT, text_layout::word_wrapping::NEVER, mame_ui_manager::NORMAL, fcolor, bcolor, - &width, nullptr); + &width, nullptr, + line_height()); x1 += width + space; ++x; } @@ -314,37 +296,33 @@ void menu_dats_view::custom_render(void *selectedref, float top, float bottom, f if (!m_items_list.empty()) { std::string const revision(util::string_format(_("Revision: %1$s"), m_items_list[m_actual].revision)); - ui().draw_text_full( - container(), + width = get_text_width( revision, 0.0f, 0.0f, 1.0f, - text_layout::text_justify::CENTER, text_layout::word_wrapping::TRUNCATE, - mame_ui_manager::NONE, rgb_t::white(), rgb_t::black(), - &width, nullptr); - width += 2 * lr_border; + text_layout::text_justify::CENTER, text_layout::word_wrapping::TRUNCATE); + width += 2 * lr_border(); maxwidth = std::max(origx2 - origx1, width); // compute our bounds x1 = 0.5f - 0.5f * maxwidth; x2 = x1 + maxwidth; - y1 = origy2 + ui().box_tb_border(); + y1 = origy2 + tb_border(); y2 = origy2 + bottom; // draw a box ui().draw_outlined_box(container(), x1, y1, x2, y2, UI_GREEN_COLOR); // take off the borders - x1 += lr_border; - x2 -= lr_border; - y1 += ui().box_tb_border(); + x1 += lr_border(); + x2 -= lr_border(); + y1 += tb_border(); // draw the text within it - ui().draw_text_full( - container(), + draw_text_normal( revision, x1, y1, x2 - x1, text_layout::text_justify::CENTER, text_layout::word_wrapping::TRUNCATE, - mame_ui_manager::NORMAL, ui().colors().text_color(), ui().colors().text_bg_color()); + ui().colors().text_color()); } } @@ -385,7 +363,7 @@ void menu_dats_view::populate_text(std::optional<text_layout> &layout, float &wi else get_data(buffer); } - layout.emplace(ui().create_layout(container(), width)); + layout.emplace(create_layout(width)); add_info_text(*layout, buffer, ui().colors().text_color()); lines = std::numeric_limits<int>::max(); } diff --git a/src/frontend/mame/ui/devopt.cpp b/src/frontend/mame/ui/devopt.cpp index 1fc1e83564f..e03b8da9042 100644 --- a/src/frontend/mame/ui/devopt.cpp +++ b/src/frontend/mame/ui/devopt.cpp @@ -46,7 +46,7 @@ void menu_device_config::populate_text(std::optional<text_layout> &layout, float if (!layout || (layout->width() != width)) { rgb_t const color = ui().colors().text_color(); - layout.emplace(ui().create_layout(container(), width)); + layout.emplace(create_layout(width)); machine_config &mconfig(const_cast<machine_config &>(machine().config())); machine_config::token const tok(mconfig.begin_configuration(mconfig.root_device())); diff --git a/src/frontend/mame/ui/dirmenu.cpp b/src/frontend/mame/ui/dirmenu.cpp index 1e28c88cc37..252b53a5aae 100644 --- a/src/frontend/mame/ui/dirmenu.cpp +++ b/src/frontend/mame/ui/dirmenu.cpp @@ -333,8 +333,8 @@ void menu_add_change_folder::populate(float &customtop, float &custombottom) item_append(menu_item_type::SEPARATOR); // configure the custom rendering - customtop = 2.0f * ui().get_line_height() + 3.0f * ui().box_tb_border(); - custombottom = 1.0f * ui().get_line_height() + 3.0f * ui().box_tb_border(); + customtop = 2.0f * line_height() + 3.0f * tb_border(); + custombottom = 1.0f * line_height() + 3.0f * tb_border(); } //------------------------------------------------- @@ -351,17 +351,17 @@ void menu_add_change_folder::custom_render(void *selectedref, float top, float b m_current_path }; draw_text_box( std::begin(toptext), std::end(toptext), - origx1, origx2, origy1 - top, origy1 - ui().box_tb_border(), + origx1, origx2, origy1 - top, origy1 - tb_border(), text_layout::text_justify::CENTER, text_layout::word_wrapping::NEVER, false, - ui().colors().text_color(), UI_GREEN_COLOR, 1.0f); + ui().colors().text_color(), UI_GREEN_COLOR); // bottom text char const *const bottomtext[] = { _("Press TAB to set") }; draw_text_box( std::begin(bottomtext), std::end(bottomtext), - origx1, origx2, origy2 + ui().box_tb_border(), origy2 + bottom, + origx1, origx2, origy2 + tb_border(), origy2 + bottom, text_layout::text_justify::CENTER, text_layout::word_wrapping::TRUNCATE, false, - ui().colors().text_color(), ui().colors().background_color(), 1.0f); + ui().colors().text_color(), ui().colors().background_color()); } //------------------------------------------------- @@ -522,7 +522,7 @@ void menu_display_actual::populate(float &customtop, float &custombottom) item_append(menu_item_type::SEPARATOR); - customtop = (m_folders.size() + 1) * ui().get_line_height() + 6.0f * ui().box_tb_border(); + customtop = (m_folders.size() + 1) * line_height() + 6.0f * tb_border(); } //------------------------------------------------- @@ -531,17 +531,16 @@ void menu_display_actual::populate(float &customtop, float &custombottom) void menu_display_actual::custom_render(void *selectedref, float top, float bottom, float origx1, float origy1, float origx2, float origy2) { - float const lineheight(ui().get_line_height()); float const maxwidth(draw_text_box( std::begin(m_folders), std::end(m_folders), - origx1, origx2, origy1 - (3.0f * ui().box_tb_border()) - (m_folders.size() * lineheight), origy1 - ui().box_tb_border(), + origx1, origx2, origy1 - (3.0f * tb_border()) - (m_folders.size() * line_height()), origy1 - tb_border(), text_layout::text_justify::CENTER, text_layout::word_wrapping::TRUNCATE, false, - ui().colors().text_color(), ui().colors().background_color(), 1.0f)); + ui().colors().text_color(), ui().colors().background_color())); draw_text_box( std::begin(m_heading), std::end(m_heading), - 0.5f * (1.0f - maxwidth), 0.5f * (1.0f + maxwidth), origy1 - top, origy1 - top + lineheight + (2.0f * ui().box_tb_border()), + 0.5f * (1.0f - maxwidth), 0.5f * (1.0f + maxwidth), origy1 - top, origy1 - top + line_height() + (2.0f * tb_border()), text_layout::text_justify::CENTER, text_layout::word_wrapping::TRUNCATE, false, - ui().colors().text_color(), UI_GREEN_COLOR, 1.0f); + ui().colors().text_color(), UI_GREEN_COLOR); } } // anonymous namespace diff --git a/src/frontend/mame/ui/filecreate.cpp b/src/frontend/mame/ui/filecreate.cpp index 675ddc93ea6..21622d3d179 100644 --- a/src/frontend/mame/ui/filecreate.cpp +++ b/src/frontend/mame/ui/filecreate.cpp @@ -179,7 +179,7 @@ void menu_file_create::populate(float &customtop, float &custombottom) item_append(menu_item_type::SEPARATOR); item_append(_("Create"), 0, ITEMREF_CREATE); - customtop = ui().get_line_height() + 3.0f * ui().box_tb_border(); + customtop = line_height() + 3.0f * tb_border(); } diff --git a/src/frontend/mame/ui/filemngr.cpp b/src/frontend/mame/ui/filemngr.cpp index ec346940586..bbd38a9a411 100644 --- a/src/frontend/mame/ui/filemngr.cpp +++ b/src/frontend/mame/ui/filemngr.cpp @@ -153,7 +153,7 @@ void menu_file_manager::populate(float &customtop, float &custombottom) if (m_warnings.empty() || !missing_mandatory) item_append(m_warnings.empty() ? _("Reset System") : _("Start System"), 0, (void *)1); - custombottom = ui().get_line_height() + 3.0f * ui().box_tb_border(); + custombottom = line_height() + 3.0f * tb_border(); } diff --git a/src/frontend/mame/ui/filesel.cpp b/src/frontend/mame/ui/filesel.cpp index 664bd699c47..182e130dc61 100644 --- a/src/frontend/mame/ui/filesel.cpp +++ b/src/frontend/mame/ui/filesel.cpp @@ -79,7 +79,7 @@ menu_file_selector::~menu_file_selector() void menu_file_selector::custom_render(void *selectedref, float top, float bottom, float origx1, float origy1, float origx2, float origy2) { // lay out extra text - auto layout = ui().create_layout(container()); + auto layout = create_layout(); layout.add_text(m_current_directory); // position this extra text @@ -90,8 +90,8 @@ void menu_file_selector::custom_render(void *selectedref, float top, float botto ui().draw_outlined_box(container(), x1, y1, x2, y2, ui().colors().background_color()); // take off the borders - x1 += ui().box_lr_border() * machine().render().ui_aspect(&container()); - y1 += ui().box_tb_border(); + x1 += lr_border(); + y1 += tb_border(); size_t hit_start = 0, hit_span = 0; if (is_mouse_hit() @@ -428,7 +428,7 @@ void menu_file_selector::populate(float &customtop, float &custombottom) set_selection((void *)selected_entry); // set up custom render proc - customtop = ui().get_line_height() + 3.0f * ui().box_tb_border(); + customtop = line_height() + 3.0f * tb_border(); } diff --git a/src/frontend/mame/ui/info.cpp b/src/frontend/mame/ui/info.cpp index e2d1435b1ba..ce4999bb0fa 100644 --- a/src/frontend/mame/ui/info.cpp +++ b/src/frontend/mame/ui/info.cpp @@ -541,7 +541,7 @@ void menu_game_info::populate_text(std::optional<text_layout> &layout, float &wi if (!layout || (layout->width() != width)) { rgb_t const color = ui().colors().text_color(); - layout.emplace(ui().create_layout(container(), width)); + layout.emplace(create_layout(width)); layout->add_text(ui().machine_info().game_info_string(), color); lines = layout->lines(); } @@ -606,7 +606,7 @@ void menu_warn_info::populate_text(std::optional<text_layout> &layout, float &wi } rgb_t const color(ui().colors().text_color()); - layout.emplace(ui().create_layout(container(), width)); + layout.emplace(create_layout(width)); layout->add_text(std::move(buf).str(), color); lines = layout->lines(); } diff --git a/src/frontend/mame/ui/inputdevices.cpp b/src/frontend/mame/ui/inputdevices.cpp index d5c993bd075..5c1a7a8931a 100644 --- a/src/frontend/mame/ui/inputdevices.cpp +++ b/src/frontend/mame/ui/inputdevices.cpp @@ -47,16 +47,14 @@ protected: case ITEM_CLASS_RELATIVE: { // draw the outer box - ui().draw_outlined_box(container(), x, y2 + ui().box_tb_border(), x2, y2 + bottom, ui().colors().background_color()); + ui().draw_outlined_box(container(), x, y2 + tb_border(), x2, y2 + bottom, ui().colors().background_color()); // draw the indicator rgb_t const fgcolor(ui().colors().text_color()); - float const border = ui().box_lr_border() * machine().render().ui_aspect(&container()); - float const lineheight = ui().get_line_height(); - float const indleft = x + border; - float const indright = x2 - border; - float const indtop = y2 + (ui().box_tb_border() * 2.0F) + (lineheight * 0.2F); - float const indbottom = y2 + (ui().box_tb_border() * 2.0F) + (lineheight * 0.8F); + float const indleft = x + lr_border(); + float const indright = x2 - lr_border(); + float const indtop = y2 + (tb_border() * 2.0F) + (line_height() * 0.2F); + float const indbottom = y2 + (tb_border() * 2.0F) + (line_height() * 0.8F); float const indcentre = (x + x2) * 0.5F; s32 const value = (input.itemclass() == ITEM_CLASS_ABSOLUTE) ? input.read_as_absolute(ITEM_MODIFIER_NONE) : input.read_as_relative(ITEM_MODIFIER_NONE); if (0 < value) @@ -110,7 +108,7 @@ private: item_append(menu_item_type::SEPARATOR); if (haveanalog) - custombottom = ui().get_line_height() + (ui().box_tb_border() * 3.0F); + custombottom = line_height() + (tb_border() * 3.0F); } virtual void handle(event const *ev) override diff --git a/src/frontend/mame/ui/inputmap.cpp b/src/frontend/mame/ui/inputmap.cpp index 161ce0f03c6..2fbc8aeb95d 100644 --- a/src/frontend/mame/ui/inputmap.cpp +++ b/src/frontend/mame/ui/inputmap.cpp @@ -319,9 +319,9 @@ void menu_input::custom_render(void *selectedref, float top, float bottom, float char const *const text[] = { seqname.c_str() }; draw_text_box( std::begin(text), std::end(text), - x1, x2, y2 + ui().box_tb_border(), y2 + bottom, + x1, x2, y2 + tb_border(), y2 + bottom, text_layout::text_justify::CENTER, text_layout::word_wrapping::NEVER, false, - ui().colors().text_color(), ui().colors().background_color(), 1.0f); + ui().colors().text_color(), ui().colors().background_color()); } else { @@ -336,9 +336,9 @@ void menu_input::custom_render(void *selectedref, float top, float bottom, float char const *const text[] = { errormsg.c_str() }; draw_text_box( std::begin(text), std::end(text), - x1, x2, y2 + ui().box_tb_border(), y2 + bottom, + x1, x2, y2 + tb_border(), y2 + bottom, text_layout::text_justify::CENTER, text_layout::word_wrapping::NEVER, false, - ui().colors().text_color(), UI_RED_COLOR, 1.0f); + ui().colors().text_color(), UI_RED_COLOR); } else if (selectedref) { @@ -348,9 +348,9 @@ void menu_input::custom_render(void *selectedref, float top, float bottom, float char const *const text[] = { _("Pressed") }; draw_text_box( std::begin(text), std::end(text), - x1, x2, y2 + ui().box_tb_border(), y2 + bottom, + x1, x2, y2 + tb_border(), y2 + bottom, text_layout::text_justify::CENTER, text_layout::word_wrapping::NEVER, false, - ui().colors().text_color(), ui().colors().background_color(), 1.0f); + ui().colors().text_color(), ui().colors().background_color()); } else { @@ -359,9 +359,9 @@ void menu_input::custom_render(void *selectedref, float top, float bottom, float (!item.seq.empty() || item.defseq->empty()) ? clearprompt.c_str() : defaultprompt.c_str() }; draw_text_box( std::begin(text), std::end(text), - x1, x2, y2 + ui().box_tb_border(), y2 + bottom, + x1, x2, y2 + tb_border(), y2 + bottom, text_layout::text_justify::CENTER, text_layout::word_wrapping::NEVER, false, - ui().colors().text_color(), ui().colors().background_color(), 1.0f); + ui().colors().text_color(), ui().colors().background_color()); } } } @@ -610,7 +610,7 @@ void menu_input::populate_sorted(float &customtop, float &custombottom) defaultprompt = util::string_format(_("Press %1$s to restore default\n"), ui().get_general_input_setting(IPT_UI_CLEAR)); // leave space for showing the input sequence below the menu - custombottom = 2.0f * ui().get_line_height() + 3.0f * ui().box_tb_border(); + custombottom = 2.0f * line_height() + 3.0f * tb_border(); } } // namespace ui diff --git a/src/frontend/mame/ui/menu.cpp b/src/frontend/mame/ui/menu.cpp index 0ad1ad0b379..ba5767c794a 100644 --- a/src/frontend/mame/ui/menu.cpp +++ b/src/frontend/mame/ui/menu.cpp @@ -238,6 +238,14 @@ menu::menu(mame_ui_manager &mui, render_container &container) , m_heading() , m_items() , m_rebuilding(false) + , m_last_size(0, 0) + , m_last_aspect(0.0F) + , m_line_height(0.0F) + , m_gutter_width(0.0F) + , m_tb_border(0.0F) + , m_lr_border(0.0F) + , m_lr_arrow_width(0.0F) + , m_ud_arrow_width(0.0F) , m_process_flags(0) , m_selected(0) , m_hover(1) @@ -464,13 +472,7 @@ void menu::draw(uint32_t flags) bool const customonly = (flags & PROCESS_CUSTOM_ONLY); bool const noinput = (flags & PROCESS_NOINPUT); - float const aspect = machine().render().ui_aspect(&container()); - float const line_height = ui().get_line_height(); - float const lr_arrow_width = 0.4F * line_height * aspect; - float const ud_arrow_width = line_height * aspect; - float const gutter_width = 0.5F * line_height * aspect; - float const lr_border = ui().box_lr_border() * aspect; - float const max_width = 1.0F - ((lr_border + (aspect * UI_LINE_WIDTH)) * 2.0F); + float const max_width = 1.0F - ((lr_border() + (machine().render().ui_aspect(&container()) * UI_LINE_WIDTH)) * 2.0F); if (is_special_main_menu()) draw_background(); @@ -481,31 +483,31 @@ void menu::draw(uint32_t flags) for (auto const &pitem : m_items) { // compute width of left hand side - float total_width = gutter_width + ui().get_string_width(pitem.text()) + gutter_width; + float total_width = gutter_width() + get_string_width(pitem.text()) + gutter_width(); // add in width of right hand side if (!pitem.subtext().empty()) - total_width += 2.0F * gutter_width + ui().get_string_width(pitem.subtext()); + total_width += 2.0F * gutter_width() + get_string_width(pitem.subtext()); else if (pitem.flags() & FLAG_UI_HEADING) - total_width += 4.0F * ud_arrow_width; + total_width += 4.0F * ud_arrow_width(); // track the maximum visible_width = std::max(total_width, visible_width); // track the height as well - visible_main_menu_height += line_height; + visible_main_menu_height += line_height(); } // lay out the heading if present std::optional<text_layout> heading_layout; if (m_heading) { - heading_layout.emplace(ui().create_layout(container(), max_width - (gutter_width * 2.0F), text_layout::text_justify::CENTER)); + heading_layout.emplace(create_layout(max_width - (gutter_width() * 2.0F), text_layout::text_justify::CENTER)); heading_layout->add_text(*m_heading, ui().colors().text_color()); } // account for extra space at the top and bottom - float const top_extra_menu_height = m_customtop + (heading_layout ? (heading_layout->actual_height() + (ui().box_tb_border() * 3.0F)) : 0.0F); + float const top_extra_menu_height = m_customtop + (heading_layout ? (heading_layout->actual_height() + (tb_border() * 3.0F)) : 0.0F); float const visible_extra_menu_height = top_extra_menu_height + m_custombottom; // add a little bit of slop for rounding @@ -516,35 +518,35 @@ void menu::draw(uint32_t flags) visible_width = std::min(visible_width, max_width); // if the menu and extra menu won't fit, take away part of the regular menu, it will scroll - if (visible_main_menu_height + visible_extra_menu_height + 2.0F * ui().box_tb_border() > 1.0F) - visible_main_menu_height = 1.0F - 2.0F * ui().box_tb_border() - visible_extra_menu_height; + if (visible_main_menu_height + visible_extra_menu_height + 2.0F * tb_border() > 1.0F) + visible_main_menu_height = 1.0F - 2.0F * tb_border() - visible_extra_menu_height; - m_visible_lines = std::min(int(std::floor(visible_main_menu_height / line_height)), int(unsigned(m_items.size()))); - visible_main_menu_height = float(m_visible_lines) * line_height; + m_visible_lines = std::min(int(std::floor(visible_main_menu_height / line_height())), int(unsigned(m_items.size()))); + visible_main_menu_height = float(m_visible_lines) * line_height(); // compute top/left of inner menu area by centering float const visible_left = (1.0F - visible_width) * 0.5F; - float const visible_top = ((1.0F - visible_main_menu_height - visible_extra_menu_height) * 0.5F) + top_extra_menu_height; + float const visible_top = std::round((((1.0F - visible_main_menu_height - visible_extra_menu_height) * 0.5F) + top_extra_menu_height) * float(m_last_size.second)) / float(m_last_size.second); // first add us a box - float const x1 = visible_left - lr_border; - float const y1 = visible_top - ui().box_tb_border(); - float const x2 = visible_left + visible_width + lr_border; - float const y2 = visible_top + visible_main_menu_height + ui().box_tb_border(); + float const x1 = visible_left - lr_border(); + float const y1 = visible_top - tb_border(); + float const x2 = visible_left + visible_width + lr_border(); + float const y2 = visible_top + visible_main_menu_height + tb_border(); if (!customonly) { if (heading_layout) { float const heading_width = heading_layout->actual_width(); float const heading_left = (1.0F - heading_width) * 0.5F; - float const hx1 = std::min(x1, heading_left - gutter_width - lr_border); - float const hx2 = std::max(x2, heading_left + heading_width + gutter_width + lr_border); + float const hx1 = std::min(x1, heading_left - gutter_width() - lr_border()); + float const hx2 = std::max(x2, heading_left + heading_width + gutter_width() + lr_border()); ui().draw_outlined_box( container(), hx1, y1 - top_extra_menu_height, - hx2, y1 - m_customtop - ui().box_tb_border(), + hx2, y1 - m_customtop - tb_border(), UI_GREEN_COLOR); - heading_layout->emit(container(), (1.0F - heading_layout->width()) * 0.5F, y1 - top_extra_menu_height + ui().box_tb_border()); + heading_layout->emit(container(), (1.0F - heading_layout->width()) * 0.5F, y1 - top_extra_menu_height + tb_border()); } ui().draw_outlined_box( container(), @@ -570,8 +572,8 @@ void menu::draw(uint32_t flags) m_visible_items = m_visible_lines - (show_top_arrow ? 1 : 0) - (show_bottom_arrow ? 1 : 0); // 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; + float const effective_width = visible_width - 2.0F * gutter_width(); + float const effective_left = visible_left + gutter_width(); // locate mouse if (!customonly && !noinput) @@ -595,8 +597,8 @@ void menu::draw(uint32_t flags) rgb_t bgcolor = ui().colors().text_bg_color(); rgb_t fgcolor2 = ui().colors().subitem_color(); rgb_t fgcolor3 = ui().colors().clone_color(); - float const line_y0 = visible_top + (float)linenum * line_height; - float const line_y1 = line_y0 + line_height; + float const line_y0 = visible_top + (float)linenum * line_height(); + float const line_y1 = line_y0 + line_height(); // work out what we're dealing with bool const uparrow = !linenum && show_top_arrow; @@ -635,10 +637,10 @@ void menu::draw(uint32_t flags) { // if we're on the top line, display the up arrow draw_arrow( - 0.5F * (x1 + x2) - 0.5F * ud_arrow_width, - line_y0 + 0.25F * line_height, - 0.5F * (x1 + x2) + 0.5F * ud_arrow_width, - line_y0 + 0.75F * line_height, + 0.5F * (x1 + x2) - 0.5F * ud_arrow_width(), + line_y0 + 0.25F * line_height(), + 0.5F * (x1 + x2) + 0.5F * ud_arrow_width(), + line_y0 + 0.75F * line_height(), fgcolor, ROT0); } @@ -646,26 +648,26 @@ void menu::draw(uint32_t flags) { // if we're on the bottom line, display the down arrow draw_arrow( - 0.5F * (x1 + x2) - 0.5F * ud_arrow_width, - line_y0 + 0.25F * line_height, - 0.5F * (x1 + x2) + 0.5F * ud_arrow_width, - line_y0 + 0.75F * line_height, + 0.5F * (x1 + x2) - 0.5F * ud_arrow_width(), + line_y0 + 0.25F * line_height(), + 0.5F * (x1 + x2) + 0.5F * ud_arrow_width(), + line_y0 + 0.75F * line_height(), fgcolor, ROT0 ^ ORIENTATION_FLIP_Y); } else if (pitem.type() == menu_item_type::SEPARATOR) { // if we're just a divider, draw a line - container().add_line(visible_left, line_y0 + 0.5F * line_height, visible_left + visible_width, line_y0 + 0.5F * line_height, UI_LINE_WIDTH, ui().colors().border_color(), PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); + container().add_line(visible_left, line_y0 + 0.5F * line_height(), visible_left + visible_width, line_y0 + 0.5F * line_height(), UI_LINE_WIDTH, ui().colors().border_color(), PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); } else if (pitem.subtext().empty()) { // if we don't have a subitem, just draw the string centered if (pitem.flags() & FLAG_UI_HEADING) { - float heading_width = ui().get_string_width(itemtext); - container().add_line(visible_left, line_y0 + 0.5F * line_height, visible_left + ((visible_width - heading_width) / 2) - lr_border, line_y0 + 0.5F * line_height, UI_LINE_WIDTH, ui().colors().border_color(), PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); - container().add_line(visible_left + visible_width - ((visible_width - heading_width) / 2) + lr_border, line_y0 + 0.5F * line_height, visible_left + visible_width, line_y0 + 0.5F * line_height, UI_LINE_WIDTH, ui().colors().border_color(), PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); + float heading_width = get_string_width(itemtext); + container().add_line(visible_left, line_y0 + 0.5F * line_height(), visible_left + ((visible_width - heading_width) / 2) - lr_border(), line_y0 + 0.5F * line_height(), UI_LINE_WIDTH, ui().colors().border_color(), PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); + container().add_line(visible_left + visible_width - ((visible_width - heading_width) / 2) + lr_border(), line_y0 + 0.5F * line_height(), visible_left + visible_width, line_y0 + 0.5F * line_height(), UI_LINE_WIDTH, ui().colors().border_color(), PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); } ui().draw_text_full( container(), @@ -673,7 +675,8 @@ void menu::draw(uint32_t flags) effective_left, line_y0, effective_width, text_layout::text_justify::CENTER, text_layout::word_wrapping::TRUNCATE, mame_ui_manager::NORMAL, fgcolor, bgcolor, - nullptr, nullptr); + nullptr, nullptr, + line_height()); } else { @@ -688,14 +691,15 @@ void menu::draw(uint32_t flags) effective_left, line_y0, effective_width, text_layout::text_justify::LEFT, text_layout::word_wrapping::TRUNCATE, mame_ui_manager::NORMAL, fgcolor, bgcolor, - &item_width, nullptr); + &item_width, nullptr, + line_height()); if (pitem.flags() & FLAG_COLOR_BOX) { rgb_t color = rgb_t((uint32_t)strtoul(pitem.subtext().c_str(), nullptr, 16)); // give 2 spaces worth of padding - subitem_width = ui().get_string_width("FF00FF00"); + subitem_width = get_string_width("FF00FF00"); ui().draw_outlined_box( container(), @@ -708,10 +712,10 @@ void menu::draw(uint32_t flags) std::string_view subitem_text(pitem.subtext()); // give 2 spaces worth of padding - item_width += 2.0F * gutter_width; + item_width += 2.0F * gutter_width(); // if the subitem doesn't fit here, display dots - if (ui().get_string_width(subitem_text) > effective_width - item_width) + if (get_string_width(subitem_text) > effective_width - item_width) { subitem_text = "..."; if (is_selected(itemnum)) @@ -735,30 +739,31 @@ void menu::draw(uint32_t flags) effective_left + item_width, line_y0, effective_width - item_width, text_layout::text_justify::RIGHT, text_layout::word_wrapping::TRUNCATE, mame_ui_manager::NORMAL, subitem_invert ? fgcolor3 : fgcolor2, bgcolor, - &subitem_width, nullptr); + &subitem_width, nullptr, + line_height()); } // apply arrows if (is_selected(itemnum) && (pitem.flags() & FLAG_LEFT_ARROW)) { - float const l = effective_left + effective_width - subitem_width - gutter_width; - float const r = l + lr_arrow_width; + float const l = effective_left + effective_width - subitem_width - gutter_width(); + float const r = l + lr_arrow_width(); draw_arrow( - l, line_y0 + 0.1F * line_height, r, line_y0 + 0.9F * line_height, + l, line_y0 + 0.1F * line_height(), r, line_y0 + 0.9F * line_height(), fgcolor, ROT90 ^ ORIENTATION_FLIP_X); - if (mouse_in_rect(l, line_y0 + 0.1F * line_height, r, line_y0 + 0.9F * line_height)) + if (mouse_in_rect(l, line_y0 + 0.1F * line_height(), r, line_y0 + 0.9F * line_height())) m_hover = HOVER_UI_LEFT; } if (is_selected(itemnum) && (pitem.flags() & FLAG_RIGHT_ARROW)) { - float const r = effective_left + effective_width + gutter_width; - float const l = r - lr_arrow_width; + float const r = effective_left + effective_width + gutter_width(); + float const l = r - lr_arrow_width(); draw_arrow( - l, line_y0 + 0.1F * line_height, r, line_y0 + 0.9F * line_height, + l, line_y0 + 0.1F * line_height(), r, line_y0 + 0.9F * line_height(), fgcolor, ROT90); - if (mouse_in_rect(l, line_y0 + 0.1F * line_height, r, line_y0 + 0.9F * line_height)) + if (mouse_in_rect(l, line_y0 + 0.1F * line_height(), r, line_y0 + 0.9F * line_height())) m_hover = HOVER_UI_RIGHT; } } @@ -771,29 +776,25 @@ void menu::draw(uint32_t flags) menu_item const &pitem = selected_item(); bool const subitem_invert(pitem.flags() & FLAG_INVERT); auto const linenum = m_selected - top_line; - float const line_y = visible_top + (float)linenum * line_height; - float target_width, target_height; + float const line_y = visible_top + float(linenum) * line_height(); // compute the multi-line target width/height - ui().draw_text_full( - container(), + auto const [target_width, target_height] = get_text_dimensions( pitem.subtext(), 0, 0, visible_width * 0.75F, - text_layout::text_justify::RIGHT, text_layout::word_wrapping::WORD, - mame_ui_manager::NONE, rgb_t::white(), rgb_t::black(), - &target_width, &target_height); + text_layout::text_justify::RIGHT, text_layout::word_wrapping::WORD); // determine the target location - float const target_x = visible_left + visible_width - target_width - lr_border; - float target_y = line_y + line_height + ui().box_tb_border(); - if (target_y + target_height + ui().box_tb_border() > visible_main_menu_height) - target_y = line_y - target_height - ui().box_tb_border(); + float const target_x = visible_left + visible_width - target_width - lr_border(); + float target_y = line_y + line_height() + tb_border(); + if (target_y + target_height + tb_border() > visible_main_menu_height) + target_y = line_y - target_height - tb_border(); // add a box around that ui().draw_outlined_box( container(), - target_x - lr_border, target_y - ui().box_tb_border(), - target_x + target_width + lr_border, target_y + target_height + ui().box_tb_border(), + target_x - lr_border(), target_y - tb_border(), + target_x + target_width + lr_border(), target_y + target_height + tb_border(), subitem_invert ? ui().colors().selected_bg_color() : ui().colors().background_color()); ui().draw_text_full( @@ -809,6 +810,20 @@ void menu::draw(uint32_t flags) custom_render(get_selection_ref(), m_customtop, m_custombottom, x1, y1, x2, y2); } +void menu::recompute_metrics(uint32_t width, uint32_t height, float aspect) +{ + float const ui_line_height = ui().get_line_height(); + + // force whole pixels for line height, gutters and borders + m_line_height = std::floor(ui_line_height * float(height)) / float(height); + m_gutter_width = std::floor(0.5F * ui_line_height * aspect * float(width)) / float(width); + m_tb_border = std::floor(ui().box_tb_border() * float(height)) / float(height); + m_lr_border = std::floor(ui().box_lr_border() * aspect * float(width)) / float(width); + + m_lr_arrow_width = 0.4F * m_line_height * aspect; + m_ud_arrow_width = m_line_height * aspect; +} + void menu::custom_render(void *selectedref, float top, float bottom, float x, float y, float x2, float y2) { } @@ -1223,6 +1238,18 @@ void menu::validate_selection(int scandir) void menu::do_handle() { + // recompute metrics if necessary + render_manager &render(machine().render()); + render_target &target(render.ui_target()); + std::pair<uint32_t, uint32_t> const uisize(target.width(), target.height()); + float const aspect = render.ui_aspect(&container()); + if ((uisize != m_last_size) || (aspect != m_last_aspect)) + { + m_last_size = uisize; + m_last_aspect = aspect; + recompute_metrics(uisize.first, uisize.second, aspect); + } + if (m_items.empty()) { m_rebuilding = true; @@ -1267,6 +1294,16 @@ delegate<uint32_t (render_container &)> menu::get_ui_handler(mame_ui_manager &mu ***************************************************************************/ //------------------------------------------------- +// create_layout +//------------------------------------------------- + +text_layout menu::create_layout(float width, text_layout::text_justify justify, text_layout::word_wrapping wrap) +{ + return text_layout(*ui().get_font(), line_height() * m_last_aspect, line_height(), width, justify, wrap); +} + + +//------------------------------------------------- // highlight //------------------------------------------------- @@ -1294,7 +1331,7 @@ void menu::draw_arrow(float x0, float y0, float x1, float y1, rgb_t fgcolor, uin void menu::extra_text_draw_box(float origx1, float origx2, float origy, float yspan, std::string_view text, int direction) { // get the size of the text - auto layout = ui().create_layout(container()); + auto layout = create_layout(); layout.add_text(text); // position this extra text @@ -1305,8 +1342,8 @@ void menu::extra_text_draw_box(float origx1, float origx2, float origy, float ys ui().draw_outlined_box(container(), x1, y1, x2, y2, ui().colors().background_color()); // take off the borders - x1 += ui().box_lr_border() * machine().render().ui_aspect(&container()); - y1 += ui().box_tb_border(); + x1 += lr_border(); + y1 += tb_border(); // draw the text within it layout.emit(container(), x1, y1); @@ -1329,14 +1366,14 @@ void menu::draw_background() void menu::extra_text_position(float origx1, float origx2, float origy, float yspan, text_layout &layout, int direction, float &x1, float &y1, float &x2, float &y2) { - float width = layout.actual_width() + (2 * ui().box_lr_border() * machine().render().ui_aspect(&container())); + float width = layout.actual_width() + (2 * lr_border()); float maxwidth = std::max(width, origx2 - origx1); // compute our bounds x1 = 0.5F - (0.5F * maxwidth); x2 = x1 + maxwidth; y1 = origy + (yspan * direction); - y2 = origy + (ui().box_tb_border() * direction); + y2 = origy + (tb_border() * direction); if (y1 > y2) std::swap(y1, y2); diff --git a/src/frontend/mame/ui/menu.h b/src/frontend/mame/ui/menu.h index ca1f3b7384d..85a2f935d86 100644 --- a/src/frontend/mame/ui/menu.h +++ b/src/frontend/mame/ui/menu.h @@ -193,6 +193,63 @@ protected: float get_customtop() const { return m_customtop; } float get_custombottom() const { return m_custombottom; } + float line_height() const { return m_line_height; } + float gutter_width() const { return m_gutter_width; } + float tb_border() const { return m_tb_border; } + float lr_border() const { return m_lr_border; } + float lr_arrow_width() const { return m_lr_arrow_width; } + float ud_arrow_width() const { return m_ud_arrow_width; } + + float get_string_width(std::string_view s) { return ui().get_string_width(s, line_height()); } + text_layout create_layout(float width = 1.0, text_layout::text_justify justify = text_layout::text_justify::LEFT, text_layout::word_wrapping wrap = text_layout::word_wrapping::WORD); + + void draw_text_normal( + std::string_view text, + float x, float y, float width, + text_layout::text_justify justify, text_layout::word_wrapping wrap, + rgb_t color) + { + ui().draw_text_full( + container(), + text, + x, y, width, justify, wrap, + mame_ui_manager::NORMAL, color, ui().colors().text_bg_color(), + nullptr, nullptr, + line_height()); + } + + float get_text_width( + std::string_view text, + float x, float y, float width, + text_layout::text_justify justify, text_layout::word_wrapping wrap) + { + float result; + ui().draw_text_full( + container(), + text, + x, y, width, justify, wrap, + mame_ui_manager::NONE, rgb_t::white(), rgb_t::black(), + &result, nullptr, + line_height()); + return result; + } + + std::pair<float, float> get_text_dimensions( + std::string_view text, + float x, float y, float width, + text_layout::text_justify justify, text_layout::word_wrapping wrap) + { + std::pair<float, float> result; + ui().draw_text_full( + container(), + text, + x, y, width, justify, wrap, + mame_ui_manager::NONE, rgb_t::white(), rgb_t::black(), + &result.first, &result.second, + line_height()); + return result; + } + // highlight void highlight(float x0, float y0, float x1, float y1, rgb_t bgcolor); render_texture *hilight_main_texture() { return m_global_state.hilight_main_texture(); } @@ -214,16 +271,15 @@ protected: rgb_t fgcolor, rgb_t bgcolor, float text_size) { // size up the text - float const lrborder(ui().box_lr_border() * machine().render().ui_aspect(&container())); - float const origwidth(origx2 - origx1 - (2.0f * lrborder)); + float const origwidth(origx2 - origx1 - (2.0f * lr_border())); float maxwidth(origwidth); for (Iter it = begin; it != end; ++it) { std::string_view const &line(*it); if (!line.empty()) { - auto layout = ui().create_layout(container(), 1.0f, justify, wrap); - layout.add_text(std::string_view(*it), rgb_t::white(), rgb_t::black(), text_size); + text_layout layout(*ui().get_font(), text_size * m_last_aspect, text_size, 1.0, justify, wrap); + layout.add_text(std::string_view(*it), rgb_t::white(), rgb_t::black()); maxwidth = (std::max)(layout.actual_width(), maxwidth); } } @@ -234,13 +290,13 @@ protected: } // draw containing box - float const boxleft(0.5f - (maxwidth * 0.5f) - lrborder); - float boxright(0.5f + (maxwidth * 0.5f) + lrborder); + float const boxleft(0.5f - (maxwidth * 0.5f) - lr_border()); + float boxright(0.5f + (maxwidth * 0.5f) + lr_border()); ui().draw_outlined_box(container(), boxleft, y1, boxright, y2, bgcolor); // inset box and draw content float const textleft(0.5f - (maxwidth * 0.5f)); - y1 += ui().box_tb_border(); + y1 += tb_border(); for (Iter it = begin; it != end; ++it) { ui().draw_text_full( @@ -248,16 +304,27 @@ protected: textleft, y1, maxwidth, justify, wrap, mame_ui_manager::NORMAL, fgcolor, ui().colors().text_bg_color(), nullptr, nullptr, text_size); - y1 += ui().get_line_height(); + y1 += text_size; } // in case you want another box of similar width return maxwidth; } + template <typename Iter> + float draw_text_box( + Iter begin, Iter end, + float origx1, float origx2, float y1, float y2, + ui::text_layout::text_justify justify, ui::text_layout::word_wrapping wrap, bool scale, + rgb_t fgcolor, rgb_t bgcolor) + { + return draw_text_box(begin, end, origx1, origx2, y1, y2, justify, wrap, scale, fgcolor, bgcolor, line_height()); + } + void draw_background(); // draw additional menu content + virtual void recompute_metrics(uint32_t width, uint32_t height, float aspect); virtual void custom_render(void *selectedref, float top, float bottom, float x, float y, float x2, float y2); // map mouse to menu coordinates @@ -385,6 +452,15 @@ private: std::vector<menu_item> m_items; // array of items bool m_rebuilding; // ensure items are only added during rebuild + std::pair<uint32_t, uint32_t> m_last_size; // pixel size of UI container when metrics were computed + float m_last_aspect; // aspect ratio of UI container when metrics were computed + float m_line_height; + float m_gutter_width; + float m_tb_border; + float m_lr_border; + float m_lr_arrow_width; + float m_ud_arrow_width; + uint32_t m_process_flags; // event processing options int m_selected; // which item is selected int m_hover; // which item is being hovered over diff --git a/src/frontend/mame/ui/miscmenu.cpp b/src/frontend/mame/ui/miscmenu.cpp index d043157dbea..057df11e17d 100644 --- a/src/frontend/mame/ui/miscmenu.cpp +++ b/src/frontend/mame/ui/miscmenu.cpp @@ -231,7 +231,7 @@ void menu_bookkeeping::populate_text(std::optional<text_layout> &layout, float & if (!layout || (layout->width() != width)) { rgb_t const color = ui().colors().text_color(); - layout.emplace(ui().create_layout(container(), width)); + layout.emplace(create_layout(width)); // show total time first prevtime = machine().time(); diff --git a/src/frontend/mame/ui/optsmenu.cpp b/src/frontend/mame/ui/optsmenu.cpp index 225e2ef3af4..bc9757a44a4 100644 --- a/src/frontend/mame/ui/optsmenu.cpp +++ b/src/frontend/mame/ui/optsmenu.cpp @@ -86,7 +86,7 @@ void menu_simple_game_options::populate(float &customtop, float &custombottom) item_append(menu_item_type::SEPARATOR); item_append(_("Save Settings"), 0, (void *)(uintptr_t)SAVE_CONFIG); - custombottom = 2.0f * ui().get_line_height() + 3.0f * ui().box_tb_border(); + custombottom = 2.0f * line_height() + 3.0f * tb_border(); } //------------------------------------------------- diff --git a/src/frontend/mame/ui/selector.cpp b/src/frontend/mame/ui/selector.cpp index 93e3ce326d3..71643f4bf4e 100644 --- a/src/frontend/mame/ui/selector.cpp +++ b/src/frontend/mame/ui/selector.cpp @@ -124,7 +124,7 @@ void menu_selector::populate(float &customtop, float &custombottom) } item_append(menu_item_type::SEPARATOR); - custombottom = ui().get_line_height() + 3.0f * ui().box_tb_border(); + custombottom = line_height() + 3.0f * tb_border(); m_initial = -1; } @@ -138,9 +138,9 @@ void menu_selector::custom_render(void *selectedref, float top, float bottom, fl std::string const tempbuf[] = { util::string_format(_("menu-selector", "Double-click or press %1$s to select"), ui().get_general_input_setting(IPT_UI_SELECT)) }; draw_text_box( std::begin(tempbuf), std::end(tempbuf), - origx1, origx2, origy2 + ui().box_tb_border(), origy2 + bottom, + origx1, origx2, origy2 + tb_border(), origy2 + bottom, text_layout::text_justify::CENTER, text_layout::word_wrapping::NEVER, false, - ui().colors().text_color(), ui().colors().background_color(), 1.0f); + ui().colors().text_color(), ui().colors().background_color()); } //------------------------------------------------- diff --git a/src/frontend/mame/ui/selgame.cpp b/src/frontend/mame/ui/selgame.cpp index 15c3e3e22a6..9ca733bef99 100644 --- a/src/frontend/mame/ui/selgame.cpp +++ b/src/frontend/mame/ui/selgame.cpp @@ -126,6 +126,19 @@ menu_select_game::~menu_select_game() ui().save_ui_options(); } + +//------------------------------------------------- +// recompute metrics +//------------------------------------------------- + +void menu_select_game::recompute_metrics(uint32_t width, uint32_t height, float aspect) +{ + menu_select_launch::recompute_metrics(width, height, aspect); + + m_icons.clear(); +} + + //------------------------------------------------- // menu_activated //------------------------------------------------- @@ -461,8 +474,8 @@ void menu_select_game::populate(float &customtop, float &custombottom) } // configure the custom rendering - customtop = 3.0f * ui().get_line_height() + 5.0f * ui().box_tb_border(); - custombottom = 4.0f * ui().get_line_height() + 3.0f * ui().box_tb_border(); + customtop = 3.0f * line_height() + 5.0f * tb_border(); + custombottom = 4.0f * line_height() + 3.0f * tb_border(); // reselect prior game launched, if any if (old_item_selected != -1) @@ -939,6 +952,10 @@ render_texture *menu_select_game::get_icon_texture(int linenum, void *selectedre } +//------------------------------------------------- +// export displayed list +//------------------------------------------------- + void menu_select_game::inkey_export() { std::vector<game_driver const *> list; diff --git a/src/frontend/mame/ui/selgame.h b/src/frontend/mame/ui/selgame.h index 7c8467f8ff9..1f28052ff88 100644 --- a/src/frontend/mame/ui/selgame.h +++ b/src/frontend/mame/ui/selgame.h @@ -33,6 +33,8 @@ public: static void force_game_select(mame_ui_manager &mui, render_container &container); protected: + virtual void recompute_metrics(uint32_t width, uint32_t height, float aspect) override; + void menu_activated() override; void menu_deactivated() override; diff --git a/src/frontend/mame/ui/selmenu.cpp b/src/frontend/mame/ui/selmenu.cpp index ea8fb04b30b..ff11e43d32d 100644 --- a/src/frontend/mame/ui/selmenu.cpp +++ b/src/frontend/mame/ui/selmenu.cpp @@ -15,10 +15,6 @@ #include "ui/info.h" #include "ui/inifile.h" -// these hold static bitmap images -#include "ui/defimg.ipp" -#include "ui/toolbar.ipp" - #include "audit.h" #include "cheat.h" #include "mame.h" @@ -46,6 +42,11 @@ #include <utility> +// these hold static bitmap images +#include "ui/defimg.ipp" +#include "ui/toolbar.ipp" + + namespace ui { namespace { @@ -416,7 +417,7 @@ menu_select_launch::cache::cache(running_machine &machine) // create a texture for snapshot m_snapx_texture.reset(render.texture_alloc(render_texture::hq_scale)); - std::memcpy(&m_no_avail_bitmap.pix(0), no_avail_bmp, 256 * 256 * sizeof(uint32_t)); + std::memcpy(&m_no_avail_bitmap.pix(0), no_avail_bmp, 256 * 256 * sizeof(u32)); m_toolbar_bitmaps.resize(UI_TOOLBAR_BUTTONS); m_toolbar_textures.reserve(UI_TOOLBAR_BUTTONS); @@ -433,7 +434,7 @@ void menu_select_launch::cache::cache_toolbar(running_machine &machine, float wi // not bothering to transform for non-square pixels greatly simplifies this render_manager &render(machine.render()); render_target const &target(render.ui_target()); - int32_t const pix_size(std::ceil(std::max(width * target.width(), height * target.height()))); + s32 const pix_size(std::ceil(std::max(width * target.width(), height * target.height()))); if (m_toolbar_textures.empty() || (m_toolbar_bitmaps[0].width() != pix_size) || (m_toolbar_bitmaps[0].height() != pix_size)) { m_toolbar_textures.clear(); @@ -461,10 +462,10 @@ void menu_select_launch::cache::cache_toolbar(running_machine &machine, float wi svg.reset(); // correct colour format - for (int32_t y = 0; bitmap.height() > y; ++y) + for (s32 y = 0; bitmap.height() > y; ++y) { - uint32_t *dst(&bitmap.pix(y)); - for (int32_t x = 0; bitmap.width() > x; ++x, ++dst) + u32 *dst(&bitmap.pix(y)); + for (s32 x = 0; bitmap.width() > x; ++x, ++dst) { u8 const *const src(reinterpret_cast<u8 const *>(dst)); rgb_t const d(src[3], src[0], src[1], src[2]); @@ -611,6 +612,20 @@ void menu_select_launch::launch_system(mame_ui_manager &mui, game_driver const & //------------------------------------------------- +// recompute metrics +//------------------------------------------------- + +void menu_select_launch::recompute_metrics(uint32_t width, uint32_t height, float aspect) +{ + menu::recompute_metrics(width, height, aspect); + + // force right panel images to be redrawn + m_cache.set_snapx_driver(nullptr); + m_cache.set_snapx_software(nullptr); +} + + +//------------------------------------------------- // perform our special rendering //------------------------------------------------- @@ -620,15 +635,15 @@ void menu_select_launch::custom_render(void *selectedref, float top, float botto // determine the text for the header make_topbox_text(tempbuf[0], tempbuf[1], tempbuf[2]); - float const y1 = origy1 - 3.0f * ui().box_tb_border() - ui().get_line_height(); + float const y1 = origy1 - 3.0f * tb_border() - line_height(); draw_text_box( tempbuf, tempbuf + 3, origx1, origx2, origy1 - top, y1, text_layout::text_justify::CENTER, text_layout::word_wrapping::NEVER, true, - ui().colors().text_color(), ui().colors().background_color(), 1.0f); + ui().colors().text_color(), ui().colors().background_color()); // draw toolbar - draw_toolbar(origx1, y1, origx2, origy1 - ui().box_tb_border()); + draw_toolbar(origx1, y1, origx2, origy1 - tb_border()); // determine the text to render below ui_software_info const *swinfo; @@ -731,13 +746,13 @@ void menu_select_launch::custom_render(void *selectedref, float top, float botto // draw the footer draw_text_box( std::begin(tempbuf), std::end(tempbuf), - origx1, origx2, origy2 + ui().box_tb_border(), origy2 + bottom, + origx1, origx2, origy2 + tb_border(), origy2 + bottom, text_layout::text_justify::CENTER, text_layout::word_wrapping::NEVER, true, - ui().colors().text_color(), color, 1.0f); + ui().colors().text_color(), color); // is favorite? draw the star if (isstar) - draw_star(origx1 + ui().box_lr_border() * machine().render().ui_aspect(&container()), origy2 + (2.0f * ui().box_tb_border())); + draw_star(origx1 + lr_border(), origy2 + (2.0f * tb_border())); } @@ -854,21 +869,16 @@ void menu_select_launch::inkey_dats() void menu_select_launch::draw_common_arrow(float origx1, float origy1, float origx2, float origy2, int current, int dmin, int dmax, float title_size) { - float const aspect = machine().render().ui_aspect(&container()); - float const line_height = ui().get_line_height(); - float const lr_arrow_width = 0.4f * line_height * aspect; - float const gutter_width = 0.5f * line_height * aspect; - // set left-right arrows dimension - float const ar_x0 = 0.5f * (origx2 + origx1) + 0.5f * title_size + gutter_width - lr_arrow_width; - float const ar_y0 = origy1 + 0.1f * line_height; - float const ar_x1 = 0.5f * (origx2 + origx1) + 0.5f * title_size + gutter_width; - float const ar_y1 = origy1 + 0.9f * line_height; + float const ar_x0 = 0.5f * (origx2 + origx1) + 0.5f * title_size + gutter_width() - lr_arrow_width(); + float const ar_y0 = origy1 + 0.1f * line_height(); + float const ar_x1 = 0.5f * (origx2 + origx1) + 0.5f * title_size + gutter_width(); + float const ar_y1 = origy1 + 0.9f * line_height(); - float const al_x0 = 0.5f * (origx2 + origx1) - 0.5f * title_size - gutter_width; - float const al_y0 = origy1 + 0.1f * line_height; - float const al_x1 = 0.5f * (origx2 + origx1) - 0.5f * title_size - gutter_width + lr_arrow_width; - float const al_y1 = origy1 + 0.9f * line_height; + float const al_x0 = 0.5f * (origx2 + origx1) - 0.5f * title_size - gutter_width(); + float const al_y0 = origy1 + 0.1f * line_height(); + float const al_x1 = 0.5f * (origx2 + origx1) - 0.5f * title_size - gutter_width() + lr_arrow_width(); + float const al_y1 = origy1 + 0.9f * line_height(); rgb_t fgcolor_right, fgcolor_left; fgcolor_right = fgcolor_left = ui().colors().text_color(); @@ -908,21 +918,28 @@ void menu_select_launch::draw_common_arrow(float origx1, float origy1, float ori // draw info arrow //------------------------------------------------- -void menu_select_launch::draw_info_arrow(int ub, float origx1, float origx2, float oy1, float line_height, float text_size, float ud_arrow_width) +void menu_select_launch::draw_info_arrow(int ub, float origx1, float origx2, float oy1, float line_height, float ud_arrow_width) { rgb_t fgcolor = ui().colors().text_color(); - uint32_t orientation = (!ub) ? ROT0 : ROT0 ^ ORIENTATION_FLIP_Y; - if (mouse_in_rect(origx1, oy1, origx2, oy1 + (line_height * text_size))) + if (mouse_in_rect(origx1, oy1, origx2, oy1 + line_height)) { - ui().draw_textured_box(container(), origx1 + 0.01f, oy1, origx2 - 0.01f, oy1 + (line_height * text_size), ui().colors().mouseover_bg_color(), - rgb_t(43, 43, 43), hilight_main_texture(), PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_TEXWRAP(1)); - set_hover((!ub) ? HOVER_DAT_UP : HOVER_DAT_DOWN); + ui().draw_textured_box( + container(), + origx1 + 0.01f, oy1, origx2 - 0.01f, oy1 + line_height, + ui().colors().mouseover_bg_color(), rgb_t(43, 43, 43), + hilight_main_texture(), + PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_TEXWRAP(1)); + set_hover(!ub ? HOVER_DAT_UP : HOVER_DAT_DOWN); fgcolor = ui().colors().mouseover_color(); } - draw_arrow(0.5f * (origx1 + origx2) - 0.5f * (ud_arrow_width * text_size), oy1 + 0.25f * (line_height * text_size), - 0.5f * (origx1 + origx2) + 0.5f * (ud_arrow_width * text_size), oy1 + 0.75f * (line_height * text_size), fgcolor, orientation); + u32 const orientation = !ub ? ROT0 : (ROT0 ^ ORIENTATION_FLIP_Y); + draw_arrow( + 0.5f * (origx1 + origx2) - 0.5f * ud_arrow_width, oy1 + 0.25f * line_height, + 0.5f * (origx1 + origx2) + 0.5f * ud_arrow_width, oy1 + 0.75f * line_height, + fgcolor, + orientation); } bool menu_select_launch::draw_error_text() @@ -944,36 +961,34 @@ float menu_select_launch::draw_left_panel( return draw_collapsed_left_panel(x1, y1, x2, y2); // calculate line height - float const line_height(ui().get_line_height()); - float const text_size(ui().options().infos_size()); - float const sc(y2 - y1 - (2.0f * ui().box_tb_border())); - float line_height_max(line_height * text_size); + float const target_height(ui().get_line_height(ui().options().infos_size())); + float const sc(y2 - y1 - (2.0F * tb_border())); + float line_height_max(target_height); if ((Filter::COUNT * line_height_max) > sc) { float const lm(sc / Filter::COUNT); - line_height_max = line_height * (lm / line_height); + line_height_max = line_height() * (lm / line_height()); } // calculate horizontal offset for unadorned names std::string tmp(convert_command_glyph("_# ")); - float const text_sign = ui().get_string_width(tmp, text_size); + float const text_sign = ui().get_string_width(tmp, target_height); // get the maximum width of a filter name - float left_width(0.0f); + float left_width(0.0F); for (typename Filter::type x = Filter::FIRST; Filter::COUNT > x; ++x) - left_width = std::max(ui().get_string_width(Filter::display_name(x), text_size) + text_sign, left_width); + left_width = std::max(ui().get_string_width(Filter::display_name(x), target_height) + text_sign, left_width); + left_width = std::min(left_width, 0.25F); // outline the box and inset by the border width float const origy1(y1); float const origy2(y2); - float const aspect(machine().render().ui_aspect(&container())); - float const lr_border(ui().box_lr_border() * aspect); - x2 = x1 + left_width + 2.0f * lr_border; + x2 = x1 + left_width + 2.0F * lr_border(); ui().draw_outlined_box(container(), x1, y1, x2, y2, ui().colors().background_color()); - x1 += lr_border; - x2 -= lr_border; - y1 += ui().box_tb_border(); - y2 -= ui().box_tb_border(); + x1 += lr_border(); + x2 -= lr_border(); + y1 += tb_border(); + y2 -= tb_border(); // now draw the rows auto const active_filter(filters.find(current)); @@ -1015,28 +1030,29 @@ float menu_select_launch::draw_left_panel( } // finally draw the text itself and move to the next line - float const x1t = x1 + ((str == Filter::display_name(filter)) ? text_sign : 0.0f); + float const x1t = x1 + ((str == Filter::display_name(filter)) ? text_sign : 0.0F); ui().draw_text_full( container(), str, - x1t, y1, x2 - x1, - text_layout::text_justify::LEFT, text_layout::word_wrapping::NEVER, + x1t, y1, x2 - x1t, + text_layout::text_justify::LEFT, text_layout::word_wrapping::TRUNCATE, mame_ui_manager::NORMAL, fgcolor, bgcolor, - nullptr, nullptr, text_size); + nullptr, nullptr, + target_height); y1 += line_height_max; } - x1 = x2 + lr_border; - x2 = x1 + 2.0f * lr_border; + x1 = x2 + lr_border(); + x2 = x1 + 2.0F * lr_border(); y1 = origy1; y2 = origy2; float const space = x2 - x1; - float const lr_arrow_width = 0.4f * space * aspect; + float const lr_arrow_width = 0.4F * space; // set left-right arrows dimension - float const ar_x0 = 0.5f * (x2 + x1) - 0.5f * lr_arrow_width; - float const ar_y0 = 0.5f * (y2 + y1) + 0.1f * space; + float const ar_x0 = 0.5F * (x2 + x1 - lr_arrow_width); + float const ar_y0 = 0.5F * (y2 + y1) - tb_border(); float const ar_x1 = ar_x0 + lr_arrow_width; - float const ar_y1 = 0.5f * (y2 + y1) + 0.9f * space; + float const ar_y1 = ar_y0 + 2.0F * tb_border(); ui().draw_outlined_box(container(), x1, y1, x2, y2, rgb_t(0xef, 0x12, 0x47, 0x7b)); @@ -1048,7 +1064,7 @@ float menu_select_launch::draw_left_panel( } draw_arrow(ar_x0, ar_y0, ar_x1, ar_y1, fgcolor, ROT90 ^ ORIENTATION_FLIP_X); - return x2 + lr_border; + return x2 + lr_border(); } @@ -1147,11 +1163,11 @@ bool menu_select_launch::scale_icon(bitmap_argb32 &&src, texture_and_bitmap &dst if (src.valid()) { // calculate available space for the icon in pixels - float const height(ui().get_line_height()); + float const height(line_height()); float const width(height * container().manager().ui_aspect(&container())); render_target const &target(machine().render().ui_target()); - uint32_t const dst_height(target.height()); - uint32_t const dst_width(target.width()); + u32 const dst_height(target.height()); + u32 const dst_width(target.width()); bool const rotated((target.orientation() & ORIENTATION_SWAP_XY) != 0); int const max_height(int((rotated ? dst_width : dst_height) * height)); int const max_width(int((rotated ? dst_height : dst_width) * width)); @@ -1163,7 +1179,7 @@ bool menu_select_launch::scale_icon(bitmap_argb32 &&src, texture_and_bitmap &dst { float const pix_height(std::ceil(src.height() * ratio)); float const pix_width(std::ceil(src.width() * ratio)); - tmp.allocate(int32_t(pix_width), int32_t(pix_height)); + tmp.allocate(s32(pix_width), s32(pix_height)); render_resample_argb_bitmap_hq(tmp, src, render_color{ 1.0F, 1.0F, 1.0F, 1.0F }, true); } else @@ -1235,11 +1251,10 @@ void menu_select_launch::draw_toolbar(float x1, float y1, float x2, float y2) // take off the borders float const aspect(machine().render().ui_aspect(&container())); - float const lr_border(ui().box_lr_border() * aspect); - x1 += lr_border; - x2 -= lr_border; - y1 += ui().box_tb_border(); - y2 -= ui().box_tb_border(); + x1 += lr_border(); + x2 -= lr_border(); + y1 += tb_border(); + y2 -= tb_border(); // work out which buttons we're going to draw constexpr unsigned SYS_TOOLBAR_BITMAPS[] = { TOOLBAR_BITMAP_FAVORITE, TOOLBAR_BITMAP_SAVE, TOOLBAR_BITMAP_AUDIT, TOOLBAR_BITMAP_INFO }; @@ -1261,11 +1276,11 @@ void menu_select_launch::draw_toolbar(float x1, float y1, float x2, float y2) { set_hover(HOVER_BACKTRACK); color = rgb_t::white(); - float const ypos = y2 + ui().get_line_height() + 2.0f * ui().box_tb_border(); + float const ypos = y2 + line_height() + 2.0f * tb_border(); ui().draw_text_box( container(), have_parent ? _("Return to Previous Menu") : _("Exit"), - text_layout::text_justify::RIGHT, 1.0f - lr_border, ypos, + text_layout::text_justify::RIGHT, 1.0f - lr_border(), ypos, ui().colors().background_color()); } container().add_quad( @@ -1289,7 +1304,7 @@ void menu_select_launch::draw_toolbar(float x1, float y1, float x2, float y2) set_hover(HOVER_B_FAV + bitmap); color = rgb_t::white(); } - float ypos = y2 + ui().get_line_height() + 2.0f * ui().box_tb_border(); + float ypos = y2 + line_height() + 2.0f * tb_border(); ui().draw_text_box( container(), _(hover_msg[bitmap]), @@ -1313,8 +1328,8 @@ void menu_select_launch::draw_star(float x0, float y0) { if (TOOLBAR_BITMAP_FAVORITE < m_cache.toolbar_textures().size()) { - float const y1 = y0 + ui().get_line_height(); - float const x1 = x0 + ui().get_line_height() * container().manager().ui_aspect(&container()); + float const y1 = y0 + line_height(); + float const x1 = x0 + line_height() * container().manager().ui_aspect(&container()); container().add_quad( x0, y0, x1, y1, rgb_t::white(), @@ -1340,9 +1355,8 @@ void menu_select_launch::draw_icon(int linenum, void *selectedref, float x0, flo render_texture *const icon(get_icon_texture(linenum, selectedref)); if (icon) { - float const ud_arrow_width = ui().get_line_height() * container().manager().ui_aspect(&container()); - float const x1 = x0 + ud_arrow_width; - float const y1 = y0 + ui().get_line_height(); + float const x1 = x0 + ud_arrow_width(); + float const y1 = y0 + line_height(); container().add_quad(x0, y0, x1, y1, rgb_t::white(), icon, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); }; } @@ -1391,7 +1405,7 @@ void menu_select_launch::get_title_search(std::string &snaptext, std::string &se // handle keys for main menu //------------------------------------------------- -void menu_select_launch::handle_keys(uint32_t flags, int &iptkey) +void menu_select_launch::handle_keys(u32 flags, int &iptkey) { // bail if no items if (item_count() == 0) @@ -1639,12 +1653,12 @@ void menu_select_launch::handle_keys(uint32_t flags, int &iptkey) // handle input events for main menu //------------------------------------------------- -void menu_select_launch::handle_events(uint32_t flags, event &ev) +void menu_select_launch::handle_events(u32 flags, event &ev) { if (m_pressed) { bool const pressed = mouse_pressed(); - int32_t target_x, target_y; + s32 target_x, target_y; bool button; render_target *const mouse_target = machine().ui_input().find_mouse(&target_x, &target_y, &button); if (mouse_target && button && (hover() == HOVER_ARROW_DOWN || hover() == HOVER_ARROW_UP)) @@ -1885,17 +1899,12 @@ void menu_select_launch::handle_events(uint32_t flags, event &ev) // draw main menu //------------------------------------------------- -void menu_select_launch::draw(uint32_t flags) +void menu_select_launch::draw(u32 flags) { bool noinput = (flags & PROCESS_NOINPUT); - float const aspect = machine().render().ui_aspect(&container()); - float const lr_border = ui().box_lr_border() * aspect; - float line_height = ui().get_line_height(); - float const ud_arrow_width = line_height * aspect; - float const gutter_width = 0.52f * ud_arrow_width; - float const icon_offset = m_has_icons ? (1.5f * ud_arrow_width) : 0.0f; - float right_panel_size = (ui_globals::panels_status == HIDE_BOTH || ui_globals::panels_status == HIDE_RIGHT_PANEL) ? 2.0f * lr_border : 0.3f; - float visible_width = 1.0f - 4.0f * lr_border; + float const icon_offset = m_has_icons ? (1.5f * ud_arrow_width()) : 0.0f; + float right_panel_size = (ui_globals::panels_status == HIDE_BOTH || ui_globals::panels_status == HIDE_RIGHT_PANEL) ? 2.0f * lr_border() : 0.3f; + float visible_width = 1.0f - 4.0f * lr_border(); float primary_left = (1.0f - visible_width) * 0.5f; float primary_width = visible_width; @@ -1903,7 +1912,7 @@ void menu_select_launch::draw(uint32_t flags) clear_hover(); m_available_items = item_count() - m_skip_main_items; - float extra_height = m_skip_main_items * line_height; + float extra_height = m_skip_main_items * line_height(); float visible_extra_menu_height = get_customtop() + get_custombottom() + extra_height; // locate mouse @@ -1913,9 +1922,9 @@ void menu_select_launch::draw(uint32_t flags) 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; + float visible_main_menu_height = 1.0f - 2.0f * 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(); if (!m_is_swlist) ui_globals::visible_main_lines = m_visible_lines; @@ -1930,19 +1939,19 @@ void menu_select_launch::draw(uint32_t flags) visible_top += get_customtop(); // compute left box size - float x1 = visible_left - lr_border; - float y1 = visible_top - ui().box_tb_border(); - float x2 = x1 + 2.0f * lr_border; - float y2 = visible_top + visible_main_menu_height + ui().box_tb_border() + extra_height; + float x1 = visible_left - lr_border(); + float y1 = visible_top - tb_border(); + float x2 = x1 + 2.0f * lr_border(); + float y2 = visible_top + visible_main_menu_height + tb_border() + extra_height; // add left box visible_left = draw_left_panel(x1, y1, x2, y2); - visible_width -= right_panel_size + visible_left - 2.0f * lr_border; + visible_width -= right_panel_size + visible_left - 2.0f * lr_border(); // compute and add main box - x1 = visible_left - lr_border; - x2 = visible_left + visible_width + lr_border; - float line = visible_top + (float(m_visible_lines) * line_height); + x1 = visible_left - lr_border(); + x2 = visible_left + visible_width + lr_border(); + float line = visible_top + (float(m_visible_lines) * line_height()); ui().draw_outlined_box(container(), x1, y1, x2, y2, ui().colors().background_color()); // make sure the selection @@ -1974,16 +1983,17 @@ void menu_select_launch::draw(uint32_t flags) } // determine effective positions taking into account the hilighting arrows - float effective_width = visible_width - 2.0f * gutter_width; - float effective_left = visible_left + gutter_width; + float effective_width = visible_width - 2.0f * gutter_width(); + float effective_left = visible_left + gutter_width(); if ((m_focus == focused_menu::MAIN) && (selected_index() < m_available_items)) m_prev_selected = nullptr; int const n_loop = (std::min)(m_visible_lines, m_available_items); + float const pixelheight = machine().render().ui_target().height(); for (int linenum = 0; linenum < n_loop; linenum++) { - float line_y = visible_top + (float(linenum) * line_height); + float line_y = (std::round(visible_top * pixelheight) / pixelheight) + (float(linenum) * line_height()); int itemnum = top_line + linenum; const menu_item &pitem = item(itemnum); const std::string_view itemtext = pitem.text(); @@ -1993,7 +2003,7 @@ void menu_select_launch::draw(uint32_t flags) float line_x0 = x1 + 0.5f * UI_LINE_WIDTH; float line_y0 = line_y; float line_x1 = x2 - 0.5f * UI_LINE_WIDTH; - float line_y1 = line_y + line_height; + float line_y1 = line_y + line_height(); // set the hover if this is our item if (mouse_in_rect(line_x0, line_y0, line_x1, line_y1) && is_selectable(pitem)) @@ -2029,8 +2039,8 @@ void menu_select_launch::draw(uint32_t flags) if (linenum == 0 && top_line != 0) { // if we're on the top line, display the up arrow - 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); + 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); if (hover() == itemnum) set_hover(HOVER_ARROW_UP); @@ -2038,8 +2048,8 @@ void menu_select_launch::draw(uint32_t flags) else if (linenum == m_visible_lines - 1 && itemnum != m_available_items - 1) { // if we're on the bottom line, display the down arrow - 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); + 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); if (hover() == itemnum) set_hover(HOVER_ARROW_DOWN); @@ -2047,7 +2057,7 @@ void menu_select_launch::draw(uint32_t flags) else if (pitem.type() == menu_item_type::SEPARATOR) { // if we're just a divider, draw a line - container().add_line(visible_left, line_y + 0.5f * line_height, visible_left + visible_width, line_y + 0.5f * line_height, + container().add_line(visible_left, line_y + 0.5f * line_height(), visible_left + visible_width, line_y + 0.5f * line_height(), UI_LINE_WIDTH, ui().colors().text_color(), PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); } else if (pitem.subtext().empty()) @@ -2062,7 +2072,8 @@ void menu_select_launch::draw(uint32_t flags) effective_left + icon_offset, line_y, effective_width - icon_offset, text_layout::text_justify::LEFT, text_layout::word_wrapping::TRUNCATE, mame_ui_manager::NORMAL, item_invert ? fgcolor3 : fgcolor, bgcolor, - nullptr, nullptr); + nullptr, nullptr, + line_height()); } else { @@ -2071,14 +2082,8 @@ void menu_select_launch::draw(uint32_t flags) float item_width, subitem_width; // compute right space for subitem - ui().draw_text_full( - container(), - subitem_text, - effective_left + icon_offset, line_y, ui().get_string_width(pitem.subtext()), - text_layout::text_justify::RIGHT, text_layout::word_wrapping::NEVER, - mame_ui_manager::NONE, item_invert ? fgcolor3 : fgcolor, bgcolor, - &subitem_width, nullptr); - subitem_width += gutter_width; + subitem_width = get_string_width(subitem_text); + subitem_width += gutter_width(); // draw the item left-justified if (m_has_icons) @@ -2089,7 +2094,8 @@ void menu_select_launch::draw(uint32_t flags) effective_left + icon_offset, line_y, effective_width - icon_offset - subitem_width, text_layout::text_justify::LEFT, text_layout::word_wrapping::TRUNCATE, mame_ui_manager::NORMAL, item_invert ? fgcolor3 : fgcolor, bgcolor, - &item_width, nullptr); + &item_width, nullptr, + line_height()); // draw the subitem right-justified ui().draw_text_full( @@ -2098,7 +2104,8 @@ void menu_select_launch::draw(uint32_t flags) effective_left + icon_offset + item_width, line_y, effective_width - icon_offset - item_width, text_layout::text_justify::RIGHT, text_layout::word_wrapping::NEVER, mame_ui_manager::NORMAL, item_invert ? fgcolor3 : fgcolor, bgcolor, - nullptr, nullptr); + nullptr, nullptr, + line_height()); } } @@ -2109,7 +2116,7 @@ void menu_select_launch::draw(uint32_t flags) float line_x0 = x1 + 0.5f * UI_LINE_WIDTH; float line_y0 = line; float line_x1 = x2 - 0.5f * UI_LINE_WIDTH; - float line_y1 = line + line_height; + float line_y1 = line + line_height(); rgb_t fgcolor = ui().colors().text_color(); rgb_t bgcolor = ui().colors().text_bg_color(); @@ -2135,8 +2142,8 @@ void menu_select_launch::draw(uint32_t flags) if (pitem.type() == menu_item_type::SEPARATOR) { container().add_line( - visible_left, line + 0.5f * line_height, - visible_left + visible_width, line + 0.5f * line_height, + visible_left, line + 0.5f * line_height(), + visible_left + visible_width, line + 0.5f * line_height(), UI_LINE_WIDTH, ui().colors().text_color(), PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); } @@ -2148,9 +2155,10 @@ void menu_select_launch::draw(uint32_t flags) effective_left, line, effective_width, text_layout::text_justify::CENTER, text_layout::word_wrapping::TRUNCATE, mame_ui_manager::NORMAL, fgcolor, bgcolor, - nullptr, nullptr); + nullptr, nullptr, + line_height()); } - line += line_height; + line += line_height(); } x1 = x2; @@ -2158,8 +2166,8 @@ void menu_select_launch::draw(uint32_t flags) draw_right_panel(x1, y1, x2, y2); - x1 = primary_left - lr_border; - x2 = primary_left + primary_width + lr_border; + x1 = primary_left - lr_border(); + x2 = primary_left + primary_width + lr_border(); // 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); @@ -2185,19 +2193,18 @@ void menu_select_launch::draw(uint32_t flags) void menu_select_launch::draw_right_panel(float origx1, float origy1, float origx2, float origy2) { - float const aspect(machine().render().ui_aspect(&container())); bool const hide((ui_globals::panels_status == HIDE_RIGHT_PANEL) || (ui_globals::panels_status == HIDE_BOTH)); - float const x2(hide ? origx2 : (origx1 + 2.0f * ui().box_lr_border() * aspect)); + float const x2(hide ? origx2 : (origx1 + 2.0F * lr_border())); float const space(x2 - origx1); - float const lr_arrow_width(0.4f * space * aspect); + float const lr_arrow_width(0.4F * space); // set left-right arrows dimension - float const ar_x0(0.5f * (x2 + origx1) - 0.5f * lr_arrow_width); - float const ar_y0(0.5f * (origy2 + origy1) + 0.1f * space); + float const ar_x0(0.5F * (x2 + origx1 - lr_arrow_width)); + float const ar_y0(0.5F * (origy2 + origy1) - tb_border()); float const ar_x1(ar_x0 + lr_arrow_width); - float const ar_y1(0.5f * (origy2 + origy1) + 0.9f * space); + float const ar_y1(ar_y0 + 2.0F * tb_border()); - ui().draw_outlined_box(container(), origx1, origy1, origx2, origy2, rgb_t(0xEF, 0x12, 0x47, 0x7B)); + ui().draw_outlined_box(container(), origx1, origy1, origx2, origy2, rgb_t(0xef, 0x12, 0x47, 0x7b)); rgb_t fgcolor(ui().colors().text_color()); if (mouse_in_rect(origx1, origy1, x2, origy2)) @@ -2228,14 +2235,13 @@ void menu_select_launch::draw_right_panel(float origx1, float origy1, float orig float menu_select_launch::draw_right_box_title(float x1, float y1, float x2, float y2) { - auto line_height = ui().get_line_height(); float const midl = (x2 - x1) * 0.5f; // add outlined box for options ui().draw_outlined_box(container(), x1, y1, x2, y2, ui().colors().background_color()); // add separator line - container().add_line(x1 + midl, y1, x1 + midl, y1 + line_height, UI_LINE_WIDTH, ui().colors().border_color(), PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); + container().add_line(x1 + midl, y1, x1 + midl, y1 + line_height(), UI_LINE_WIDTH, ui().colors().border_color(), PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); std::string buffer[RP_LAST + 1] = { _(RIGHT_PANEL_NAMES[0].second), _(RIGHT_PANEL_NAMES[1].second) }; @@ -2243,7 +2249,7 @@ float menu_select_launch::draw_right_box_title(float x1, float y1, float x2, flo float text_size = 1.0f; for (auto & elem : buffer) { - auto textlen = ui().get_string_width(elem) + 0.01f; + auto textlen = get_string_width(elem) + 0.01f; float tmp_size = (textlen > midl) ? (midl / textlen) : 1.0f; text_size = std::min(text_size, tmp_size); } @@ -2253,7 +2259,7 @@ float menu_select_launch::draw_right_box_title(float x1, float y1, float x2, flo rgb_t bgcolor = ui().colors().text_bg_color(); rgb_t fgcolor = ui().colors().text_color(); - if (mouse_in_rect(x1, y1, x1 + midl, y1 + line_height)) + if (mouse_in_rect(x1, y1, x1 + midl, y1 + line_height())) { if (m_right_panel != cells) { @@ -2265,7 +2271,7 @@ float menu_select_launch::draw_right_box_title(float x1, float y1, float x2, flo if (m_right_panel != cells) { - container().add_line(x1, y1 + line_height, x1 + midl, y1 + line_height, UI_LINE_WIDTH, + container().add_line(x1, y1 + line_height(), x1 + midl, y1 + line_height(), UI_LINE_WIDTH, ui().colors().border_color(), PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); if (fgcolor != ui().colors().mouseover_color()) fgcolor = ui().colors().clone_color(); @@ -2277,12 +2283,12 @@ float menu_select_launch::draw_right_box_title(float x1, float y1, float x2, flo bgcolor = rgb_t(0xff, 0xff, 0xff); ui().draw_textured_box( container(), - x1 + UI_LINE_WIDTH, y1 + UI_LINE_WIDTH, x1 + midl - UI_LINE_WIDTH, y1 + line_height, + x1 + UI_LINE_WIDTH, y1 + UI_LINE_WIDTH, x1 + midl - UI_LINE_WIDTH, y1 + line_height(), bgcolor, rgb_t(43, 43, 43), hilight_main_texture(), PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_TEXWRAP(1)); } else if (bgcolor == ui().colors().mouseover_bg_color()) { - container().add_rect(x1 + UI_LINE_WIDTH, y1 + UI_LINE_WIDTH, x1 + midl - UI_LINE_WIDTH, y1 + line_height, + container().add_rect(x1 + UI_LINE_WIDTH, y1 + UI_LINE_WIDTH, x1 + midl - UI_LINE_WIDTH, y1 + line_height(), bgcolor, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_TEXWRAP(1)); } @@ -2291,11 +2297,12 @@ float menu_select_launch::draw_right_box_title(float x1, float y1, float x2, flo buffer[cells], x1 + UI_LINE_WIDTH, y1, midl - UI_LINE_WIDTH, text_layout::text_justify::CENTER, text_layout::word_wrapping::NEVER, - mame_ui_manager::NORMAL, fgcolor, bgcolor, nullptr, nullptr, text_size); + mame_ui_manager::NORMAL, fgcolor, bgcolor, nullptr, nullptr, + line_height() * text_size); x1 += midl; } - return (y1 + line_height + UI_LINE_WIDTH); + return (y1 + line_height() + UI_LINE_WIDTH); } @@ -2375,9 +2382,6 @@ void menu_select_launch::arts_render(float origx1, float origy1, float origx2, f std::string menu_select_launch::arts_render_common(float origx1, float origy1, float origx2, float origy2) { - float const line_height = ui().get_line_height(); - float const gutter_width = 0.4f * line_height * machine().render().ui_aspect(&container()) * 1.3f; - std::string snaptext, searchstr; get_title_search(snaptext, searchstr); @@ -2385,11 +2389,10 @@ std::string menu_select_launch::arts_render_common(float origx1, float origy1, f float title_size = 0.0f; for (int x = FIRST_VIEW; x < LAST_VIEW; x++) { - float text_length; - ui().draw_text_full(container(), - _("selmenu-artwork", std::get<1>(ARTS_INFO[m_image_view])), origx1, origy1, origx2 - origx1, - text_layout::text_justify::CENTER, text_layout::word_wrapping::TRUNCATE, mame_ui_manager::NONE, rgb_t::white(), rgb_t::black(), - &text_length, nullptr); + float const text_length = get_text_width( + _("selmenu-artwork", std::get<1>(ARTS_INFO[m_image_view])), + origx1, origy1, origx2 - origx1, + text_layout::text_justify::CENTER, text_layout::word_wrapping::TRUNCATE); title_size = (std::max)(text_length + 0.01f, title_size); } @@ -2398,26 +2401,27 @@ std::string menu_select_launch::arts_render_common(float origx1, float origy1, f float const middle = origx2 - origx1; // check size - float const sc = title_size + 2.0f * gutter_width; - float const tmp_size = (sc > middle) ? ((middle - 2.0f * gutter_width) / sc) : 1.0f; + float const sc = title_size + 2.0f * gutter_width(); + float const tmp_size = (sc > middle) ? ((middle - 2.0f * gutter_width()) / sc) : 1.0f; title_size *= tmp_size; if (bgcolor != ui().colors().text_bg_color()) { ui().draw_textured_box( container(), - origx1 + ((middle - title_size) * 0.5f), origy1 + ui().box_tb_border(), - origx1 + ((middle + title_size) * 0.5f), origy1 + ui().box_tb_border() + line_height, + origx1 + ((middle - title_size) * 0.5f), origy1 + tb_border(), + origx1 + ((middle + title_size) * 0.5f), origy1 + tb_border() + line_height(), bgcolor, rgb_t(43, 43, 43), hilight_main_texture(), PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_TEXWRAP(1)); } ui().draw_text_full(container(), - snaptext, origx1, origy1 + ui().box_tb_border(), origx2 - origx1, + snaptext, origx1, origy1 + tb_border(), origx2 - origx1, text_layout::text_justify::CENTER, text_layout::word_wrapping::TRUNCATE, mame_ui_manager::NORMAL, fgcolor, bgcolor, - nullptr, nullptr, tmp_size); + nullptr, nullptr, + line_height() * tmp_size); - draw_common_arrow(origx1, origy1 + ui().box_tb_border(), origx2, origy2, m_image_view, FIRST_VIEW, LAST_VIEW, title_size); + draw_common_arrow(origx1, origy1 + tb_border(), origx2, origy2, m_image_view, FIRST_VIEW, LAST_VIEW, title_size); return searchstr; } @@ -2430,7 +2434,6 @@ std::string menu_select_launch::arts_render_common(float origx1, float origy1, f void menu_select_launch::arts_render_images(bitmap_argb32 &&tmp_bitmap, float origx1, float origy1, float origx2, float origy2) { bool no_available = false; - float line_height = ui().get_line_height(); // if it fails, use the default image if (!tmp_bitmap.valid()) @@ -2449,7 +2452,7 @@ void menu_select_launch::arts_render_images(bitmap_argb32 &&tmp_bitmap, float or if (tmp_bitmap.valid()) { float panel_width = origx2 - origx1 - 0.02f; - float panel_height = origy2 - origy1 - 0.02f - (3.0f * ui().box_tb_border()) - (2.0f * line_height); + float panel_height = origy2 - origy1 - 0.02f - (3.0f * tb_border()) - (2.0f * line_height()); int screen_width = machine().render().ui_target().width(); int screen_height = machine().render().ui_target().height(); @@ -2524,11 +2527,10 @@ void menu_select_launch::draw_snapx(float origx1, float origy1, float origx2, fl // if the image is available, loaded and valid, display it if (snapx_valid()) { - float const line_height = ui().get_line_height(); float const x1 = origx1 + 0.01f; float const x2 = origx2 - 0.01f; - float const y1 = origy1 + (2.0f * ui().box_tb_border()) + line_height; - float const y2 = origy2 - ui().box_tb_border() - line_height; + float const y1 = origy1 + (2.0f * tb_border()) + line_height(); + float const y2 = origy2 - tb_border() - line_height(); // apply texture container().add_quad(x1, y1, x2, y2, rgb_t::white(), m_cache.snapx_texture(), PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); @@ -2678,7 +2680,7 @@ bool menu_select_launch::has_multiple_bios(game_driver const &driver, s_bios &bi for (romload::system_bios const &bios : romload::entries(driver.rom).get_system_bioses()) { std::string name(bios.get_description()); - uint32_t const bios_flags(bios.get_value()); + u32 const bios_flags(bios.get_value()); if (default_name && !std::strcmp(bios.get_name(), default_name)) { @@ -2700,15 +2702,14 @@ bool menu_select_launch::has_multiple_bios(game_driver const &driver, s_bios &bi float menu_select_launch::draw_collapsed_left_panel(float x1, float y1, float x2, float y2) { - float const aspect = machine().render().ui_aspect(&container()); float const space = x2 - x1; - float const lr_arrow_width = 0.4f * space * aspect; + float const lr_arrow_width = 0.4F * space; // set left-right arrows dimension - float const ar_x0 = 0.5f * (x2 + x1) - (0.5f * lr_arrow_width); - float const ar_y0 = 0.5f * (y2 + y1) + (0.1f * space); + float const ar_x0 = 0.5F * (x2 + x1 - lr_arrow_width); + float const ar_y0 = 0.5f * (y2 + y1) - tb_border(); float const ar_x1 = ar_x0 + lr_arrow_width; - float const ar_y1 = 0.5f * (y2 + y1) + (0.9f * space); + float const ar_y1 = ar_y0 + 2.0F * tb_border(); ui().draw_outlined_box(container(), x1, y1, x2, y2, rgb_t(0xef, 0x12, 0x47, 0x7b)); // FIXME: magic numbers in colour? @@ -2721,7 +2722,7 @@ float menu_select_launch::draw_collapsed_left_panel(float x1, float y1, float x2 draw_arrow(ar_x0, ar_y0, ar_x1, ar_y1, fgcolor, ROT90); - return x2 + ui().box_lr_border() * aspect; + return x2 + lr_border(); } @@ -2731,8 +2732,6 @@ float menu_select_launch::draw_collapsed_left_panel(float x1, float y1, float x2 void menu_select_launch::infos_render(float origx1, float origy1, float origx2, float origy2) { - float const line_height = ui().get_line_height(); - float text_size = ui().options().infos_size(); std::string_view first; ui_software_info const *software; ui_system_info const *system; @@ -2817,11 +2816,10 @@ void menu_select_launch::infos_render(float origx1, float origy1, float origx2, return; } - origy1 += ui().box_tb_border(); + origy1 += tb_border(); float const aspect(machine().render().ui_aspect(&container())); - float const gutter_width = 0.4f * line_height * aspect * 1.3f; - float const ud_arrow_width = line_height * aspect; - float oy1 = origy1 + line_height; + float const gutter_width = 0.4f * line_height() * aspect * 1.3f; + float oy1 = origy1 + line_height(); std::string_view const snaptext(m_info_view ? std::string_view(m_items_list[m_info_view - 1]) : first); @@ -2830,13 +2828,7 @@ void menu_select_launch::infos_render(float origx1, float origy1, float origx2, for (std::size_t x = 0; total > x; ++x) { std::string_view const name(x ? std::string_view(m_items_list[x - 1]) : first); - float txt_length(0.0f); - ui().draw_text_full( - container(), name, - origx1, origy1, origx2 - origx1, - text_layout::text_justify::CENTER, text_layout::word_wrapping::NEVER, - mame_ui_manager::NONE, ui().colors().text_color(), ui().colors().text_bg_color(), - &txt_length, nullptr); + float txt_length = get_string_width(name); txt_length += 0.01f; title_size = (std::max)(txt_length, title_size); } @@ -2861,7 +2853,7 @@ void menu_select_launch::infos_render(float origx1, float origy1, float origx2, ui().draw_textured_box( container(), origx1 + ((middle - title_size) * 0.5f), origy1, origx1 + ((middle + title_size) * 0.5f), - origy1 + line_height, bgcolor, rgb_t(255, 43, 43, 43), + origy1 + line_height(), bgcolor, rgb_t(255, 43, 43, 43), hilight_main_texture(), PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_TEXWRAP(1)); } @@ -2870,23 +2862,25 @@ void menu_select_launch::infos_render(float origx1, float origy1, float origx2, snaptext, origx1, origy1, origx2 - origx1, text_layout::text_justify::CENTER, text_layout::word_wrapping::NEVER, - mame_ui_manager::NORMAL, fgcolor, bgcolor, nullptr, nullptr, tmp_size); + mame_ui_manager::NORMAL, fgcolor, bgcolor, nullptr, nullptr, + line_height() * tmp_size); + float const info_line_height = ui().get_line_height(ui().options().infos_size()); sc = origx2 - origx1 - (2.0f * gutter_width); if (!m_info_layout || (m_info_layout->width() != sc)) { m_info_layout.emplace( - ui().create_layout( - container(), - sc, - text_layout::text_justify::LEFT, text_layout::word_wrapping::WORD)); - menu_dats_view::add_info_text(*m_info_layout, m_info_buffer, ui().colors().text_color(), text_size); + *ui().get_font(), + machine().render().ui_aspect(&container()) * info_line_height, info_line_height, + sc, + text_layout::text_justify::LEFT, text_layout::word_wrapping::WORD); + menu_dats_view::add_info_text(*m_info_layout, m_info_buffer, ui().colors().text_color()); m_total_lines = m_info_layout->lines(); } draw_common_arrow(origx1, origy1, origx2, origy2, m_info_view, 0, total - 1, title_size); - m_right_visible_lines = floor((origy2 - oy1) / (line_height * text_size)); + m_right_visible_lines = floor((origy2 - oy1) / info_line_height); if (m_total_lines < m_right_visible_lines) m_right_visible_lines = m_total_lines; if (m_topline_datsview < 0) @@ -2903,14 +2897,14 @@ void menu_select_launch::infos_render(float origx1, float origy1, float origx2, set_hover(HOVER_INFO_TEXT); if (up_arrow) - draw_info_arrow(0, origx1, origx2, oy1, line_height, text_size, ud_arrow_width); + draw_info_arrow(0, origx1, origx2, oy1, info_line_height, info_line_height * aspect); if (down_arrow) - draw_info_arrow(1, origx1, origx2, oy1 + (float(m_right_visible_lines - 1) * line_height * text_size), line_height, text_size, ud_arrow_width); + draw_info_arrow(1, origx1, origx2, oy1 + (float(m_right_visible_lines - 1) * info_line_height), info_line_height, info_line_height * aspect); m_info_layout->emit( container(), m_topline_datsview ? (m_topline_datsview + 1) : 0, r_visible_lines, - origx1 + gutter_width, oy1 + (m_topline_datsview ? (line_height * text_size) : 0.0f)); + origx1 + gutter_width, oy1 + (m_topline_datsview ? info_line_height : 0.0f)); } diff --git a/src/frontend/mame/ui/selmenu.h b/src/frontend/mame/ui/selmenu.h index cec6224e08c..86d579b26cd 100644 --- a/src/frontend/mame/ui/selmenu.h +++ b/src/frontend/mame/ui/selmenu.h @@ -126,6 +126,7 @@ protected: void launch_system(game_driver const &driver, ui_software_info const &swinfo) { launch_system(ui(), driver, &swinfo, nullptr, nullptr); } void launch_system(game_driver const &driver, ui_software_info const &swinfo, std::string const &part) { launch_system(ui(), driver, &swinfo, &part, nullptr); } + virtual void recompute_metrics(uint32_t width, uint32_t height, float aspect) override; virtual void custom_render(void *selectedref, float top, float bottom, float x, float y, float x2, float y2) override; // handlers @@ -134,7 +135,7 @@ protected: // draw arrow void draw_common_arrow(float origx1, float origy1, float origx2, float origy2, int current, int dmin, int dmax, float title); - void draw_info_arrow(int ub, float origx1, float origx2, float oy1, float line_height, float text_size, float ud_arrow_width); + void draw_info_arrow(int ub, float origx1, float origx2, float oy1, float line_height, float ud_arrow_width); bool draw_error_text(); @@ -284,11 +285,11 @@ private: void get_title_search(std::string &title, std::string &search); // event handling - virtual void handle_keys(uint32_t flags, int &iptkey) override; - virtual void handle_events(uint32_t flags, event &ev) override; + virtual void handle_keys(u32 flags, int &iptkey) override; + virtual void handle_events(u32 flags, event &ev) override; // draw game list - virtual void draw(uint32_t flags) override; + virtual void draw(u32 flags) override; // draw right panel void draw_right_panel(float origx1, float origy1, float origx2, float origy2); @@ -323,19 +324,19 @@ private: std::string m_info_buffer; std::optional<text_layout> m_info_layout; - cache &m_cache; - bool m_is_swlist; - focused_menu m_focus; - bool m_pressed; // mouse button held down - osd_ticks_t m_repeat; + cache &m_cache; + bool m_is_swlist; + focused_menu m_focus; + bool m_pressed; // mouse button held down + osd_ticks_t m_repeat; - int m_right_visible_lines; // right box lines + int m_right_visible_lines; // right box lines - uint8_t m_right_panel; - bool m_has_icons; - bool m_switch_image; - uint8_t m_image_view; - flags_cache m_flags; + u8 m_right_panel; + bool m_has_icons; + bool m_switch_image; + u8 m_image_view; + flags_cache m_flags; }; } // namespace ui diff --git a/src/frontend/mame/ui/selsoft.cpp b/src/frontend/mame/ui/selsoft.cpp index 427ef4c61a5..68fc26cd98e 100644 --- a/src/frontend/mame/ui/selsoft.cpp +++ b/src/frontend/mame/ui/selsoft.cpp @@ -607,8 +607,8 @@ void menu_select_software::populate(float &customtop, float &custombottom) // configure the custom rendering m_skip_main_items = 0; - customtop = 4.0f * ui().get_line_height() + 5.0f * ui().box_tb_border(); - custombottom = 4.0f * ui().get_line_height() + 4.0f * ui().box_tb_border(); + customtop = 4.0f * line_height() + 5.0f * tb_border(); + custombottom = 4.0f * line_height() + 4.0f * tb_border(); if (old_software != -1) { diff --git a/src/frontend/mame/ui/simpleselgame.cpp b/src/frontend/mame/ui/simpleselgame.cpp index 9db5ac2218d..be3e056c97f 100644 --- a/src/frontend/mame/ui/simpleselgame.cpp +++ b/src/frontend/mame/ui/simpleselgame.cpp @@ -284,8 +284,8 @@ void simple_menu_select_game::populate(float &customtop, float &custombottom) } // configure the custom rendering - customtop = ui().get_line_height() + 3.0f * ui().box_tb_border(); - custombottom = 4.0f * ui().get_line_height() + 3.0f * ui().box_tb_border(); + customtop = line_height() + 3.0f * tb_border(); + custombottom = 4.0f * line_height() + 3.0f * tb_border(); } @@ -307,7 +307,7 @@ void simple_menu_select_game::custom_render(void *selectedref, float top, float emulator_info::get_configname(), emulator_info::get_appname()), text_layout::text_justify::CENTER, - 0.5f, origy2 + ui().box_tb_border() + (0.5f * (bottom - ui().box_tb_border())), + 0.5f, origy2 + tb_border() + (0.5f * (bottom - tb_border())), UI_RED_COLOR); return; } @@ -324,9 +324,9 @@ void simple_menu_select_game::custom_render(void *selectedref, float top, float // draw the top box draw_text_box( tempbuf, tempbuf + 1, - origx1, origx2, origy1 - top, origy1 - ui().box_tb_border(), + origx1, origx2, origy1 - top, origy1 - tb_border(), text_layout::text_justify::CENTER, text_layout::word_wrapping::TRUNCATE, false, - ui().colors().text_color(), ui().colors().background_color(), 1.0f); + ui().colors().text_color(), ui().colors().background_color()); // determine the text to render below driver = ((uintptr_t)selectedref > 1) ? (const game_driver *)selectedref : nullptr; @@ -412,9 +412,9 @@ void simple_menu_select_game::custom_render(void *selectedref, float top, float // draw the bottom box draw_text_box( tempbuf, tempbuf + 4, - origx1, origx2, origy2 + ui().box_tb_border(), origy2 + bottom, + origx1, origx2, origy2 + tb_border(), origy2 + bottom, text_layout::text_justify::CENTER, text_layout::word_wrapping::TRUNCATE, true, - ui().colors().text_color(), driver ? m_cached_color : ui().colors().background_color(), 1.0f); + ui().colors().text_color(), driver ? m_cached_color : ui().colors().background_color()); } diff --git a/src/frontend/mame/ui/sliders.cpp b/src/frontend/mame/ui/sliders.cpp index f4b5017397a..e95789500ca 100644 --- a/src/frontend/mame/ui/sliders.cpp +++ b/src/frontend/mame/ui/sliders.cpp @@ -225,7 +225,7 @@ void menu_sliders::populate(float &customtop, float &custombottom) set_selection(ref); } - custombottom = 2.0f * ui().get_line_height() + 2.0f * ui().box_tb_border(); + custombottom = 2.0f * line_height() + 2.0f * tb_border(); } @@ -240,7 +240,6 @@ void menu_sliders::custom_render(void *selectedref, float top, float bottom, flo if (curslider != nullptr) { float bar_left, bar_area_top, bar_width, bar_area_height, bar_top, bar_bottom, default_x, current_x; - float line_height = ui().get_line_height(); float percentage, default_percentage; std::string tempstring; float text_height; @@ -257,29 +256,30 @@ void menu_sliders::custom_render(void *selectedref, float top, float bottom, flo tempstring.insert(0, " ").insert(0, curslider->description); // move us to the bottom of the screen, and expand to full width - const float lr_border = ui().box_lr_border() * machine().render().ui_aspect(&container()); - y2 = 1.0f - ui().box_tb_border(); + y2 = 1.0f - tb_border(); y1 = y2 - bottom; - x1 = lr_border; - x2 = 1.0f - lr_border; + x1 = lr_border(); + x2 = 1.0f - lr_border(); // draw extra menu area ui().draw_outlined_box(container(), x1, y1, x2, y2, ui().colors().background_color()); - y1 += ui().box_tb_border(); + y1 += tb_border(); // determine the text height ui().draw_text_full( container(), tempstring, - 0, 0, x2 - x1 - 2.0f * lr_border, + 0, 0, x2 - x1 - 2.0f * lr_border(), text_layout::text_justify::CENTER, text_layout::word_wrapping::TRUNCATE, - mame_ui_manager::NONE, rgb_t::white(), rgb_t::black(), nullptr, &text_height); + mame_ui_manager::NONE, rgb_t::white(), rgb_t::black(), + nullptr, &text_height, + line_height()); // draw the thermometer - bar_left = x1 + lr_border; + bar_left = x1 + lr_border(); bar_area_top = y1; - bar_width = x2 - x1 - 2.0f * lr_border; - bar_area_height = line_height; + bar_width = x2 - x1 - 2.0f * lr_border(); + bar_area_height = line_height(); // compute positions bar_top = bar_area_top + 0.125f * bar_area_height; @@ -299,12 +299,11 @@ void menu_sliders::custom_render(void *selectedref, float top, float bottom, flo container().add_line(default_x, bar_bottom, default_x, bar_area_top + bar_area_height, UI_LINE_WIDTH, ui().colors().border_color(), PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); // draw the actual text - ui().draw_text_full( - container(), + draw_text_normal( tempstring, - x1 + lr_border, y1 + line_height, x2 - x1 - 2.0f * lr_border, + x1 + lr_border(), y1 + line_height(), x2 - x1 - 2.0f * lr_border(), text_layout::text_justify::CENTER, text_layout::word_wrapping::WORD, - mame_ui_manager::NORMAL, ui().colors().text_color(), ui().colors().text_bg_color(), nullptr, &text_height); + ui().colors().text_color()); } } diff --git a/src/frontend/mame/ui/slotopt.cpp b/src/frontend/mame/ui/slotopt.cpp index 985b0fe5eb4..f1419122f98 100644 --- a/src/frontend/mame/ui/slotopt.cpp +++ b/src/frontend/mame/ui/slotopt.cpp @@ -204,7 +204,7 @@ void menu_slot_devices::populate(float &customtop, float &custombottom) item_append(_("Reset System"), 0, ITEMREF_RESET); // leave space for the name of the current option at the bottom - custombottom = ui().get_line_height() + 3.0f * ui().box_tb_border(); + custombottom = line_height() + 3.0f * tb_border(); } @@ -221,9 +221,9 @@ void menu_slot_devices::custom_render(void *selectedref, float top, float bottom char const *const text[] = { option ? option->devtype().fullname() : _("[empty slot]") }; draw_text_box( std::begin(text), std::end(text), - origx1, origx2, origy2 + ui().box_tb_border(), origy2 + bottom, + origx1, origx2, origy2 + tb_border(), origy2 + bottom, text_layout::text_justify::CENTER, text_layout::word_wrapping::TRUNCATE, false, - ui().colors().text_color(), ui().colors().background_color(), 1.0f); + ui().colors().text_color(), ui().colors().background_color()); } } diff --git a/src/frontend/mame/ui/state.cpp b/src/frontend/mame/ui/state.cpp index 633db99405e..3e3c460f203 100644 --- a/src/frontend/mame/ui/state.cpp +++ b/src/frontend/mame/ui/state.cpp @@ -225,7 +225,7 @@ void menu_load_save_state_base::populate(float &customtop, float &custombottom) item_append(_("Cancel"), 0, nullptr); // set up custom render proc - custombottom = (2.0f * ui().get_line_height()) + (3.0f * ui().box_tb_border()); + custombottom = (2.0f * line_height()) + (3.0f * tb_border()); // get ready to poll inputs m_switch_poller.reset(); @@ -446,9 +446,9 @@ void menu_load_save_state_base::custom_render(void *selectedref, float top, floa { draw_text_box( std::begin(text), std::next(std::begin(text), count), - origx1, origx2, origy2 + ui().box_tb_border(), origy2 + (count * ui().get_line_height()) + (3.0f * ui().box_tb_border()), + origx1, origx2, origy2 + tb_border(), origy2 + (count * line_height()) + (3.0f * tb_border()), text_layout::text_justify::CENTER, text_layout::word_wrapping::NEVER, false, - ui().colors().text_color(), ui().colors().background_color(), 1.0f); + ui().colors().text_color(), ui().colors().background_color()); } // draw the confirmation prompt if necessary diff --git a/src/frontend/mame/ui/submenu.cpp b/src/frontend/mame/ui/submenu.cpp index 450834a5458..3450504fc4c 100644 --- a/src/frontend/mame/ui/submenu.cpp +++ b/src/frontend/mame/ui/submenu.cpp @@ -446,7 +446,7 @@ void submenu::populate(float &customtop, float &custombottom) } item_append(menu_item_type::SEPARATOR); - custombottom = ui().get_line_height() + (3.0f * ui().box_tb_border()); + custombottom = ui().get_line_height() + (3.0f * tb_border()); } //------------------------------------------------- @@ -463,9 +463,9 @@ void submenu::custom_render(void *selectedref, float top, float bottom, float or char const *const bottomtext[] = { selected_sm_option.entry->description() }; draw_text_box( std::begin(bottomtext), std::end(bottomtext), - origx1, origx2, origy2 + ui().box_tb_border(), origy2 + bottom, + origx1, origx2, origy2 + tb_border(), origy2 + bottom, text_layout::text_justify::CENTER, text_layout::word_wrapping::TRUNCATE, false, - ui().colors().text_color(), ui().colors().background_color(), 1.0f); + ui().colors().text_color(), ui().colors().background_color()); } } } diff --git a/src/frontend/mame/ui/textbox.cpp b/src/frontend/mame/ui/textbox.cpp index a7fdca79f32..ac3f7337668 100644 --- a/src/frontend/mame/ui/textbox.cpp +++ b/src/frontend/mame/ui/textbox.cpp @@ -108,24 +108,20 @@ bool menu_textbox::custom_mouse_scroll(int lines) void menu_textbox::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.5f * line_height * aspect; - float const visible_width = 1.0f - (2.0f * ui().box_lr_border() * aspect); + float const visible_width = 1.0f - (2.0f * lr_border()); float const visible_left = (1.0f - visible_width) * 0.5f; - float const extra_height = 2.0f * line_height; + float const extra_height = 2.0f * line_height(); float const visible_extra_menu_height = get_customtop() + get_custombottom() + extra_height; // determine effective positions - float const maximum_width = visible_width - (2.0f * gutter_width); + float const maximum_width = visible_width - (2.0f * gutter_width()); draw_background(); map_mouse(); // account for extra space at the top and bottom and the separator/item for closing - float visible_main_menu_height = 1.0f - 2.0f * ui().box_tb_border() - visible_extra_menu_height; - m_window_lines = int(std::trunc(visible_main_menu_height / line_height)); + float visible_main_menu_height = 1.0f - 2.0f * tb_border() - visible_extra_menu_height; + m_window_lines = int(std::trunc(visible_main_menu_height / line_height())); // lay out the text if necessary if (!m_layout || (m_layout_width != maximum_width)) @@ -135,7 +131,7 @@ void menu_textbox::draw(uint32_t flags) m_layout_width = maximum_width; } m_window_lines = (std::min)(m_desired_lines, m_window_lines); - visible_main_menu_height = float(m_window_lines) * line_height; + visible_main_menu_height = float(m_window_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(); @@ -143,18 +139,18 @@ void menu_textbox::draw(uint32_t flags) // get width required to draw the sole menu item menu_item const &pitem = item(0); std::string_view const itemtext = pitem.text(); - float const itemwidth = gutter_width + ui().get_string_width(itemtext) + gutter_width; + float const itemwidth = gutter_width() + get_string_width(itemtext) + gutter_width(); float const draw_width = std::min(maximum_width, std::max(itemwidth, m_desired_width)); // compute text box size float const x1 = visible_left + ((maximum_width - draw_width) * 0.5f); - float const y1 = visible_top - ui().box_tb_border(); + float const y1 = visible_top - tb_border(); float const x2 = visible_left + visible_width - ((maximum_width - draw_width) * 0.5f); - float const y2 = visible_top + visible_main_menu_height + ui().box_tb_border() + extra_height; - float const effective_left = x1 + gutter_width; + float const y2 = visible_top + visible_main_menu_height + tb_border() + extra_height; + float const effective_left = x1 + gutter_width(); 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_window_lines) * line_height; + float const separator = visible_top + float(m_window_lines) * line_height(); ui().draw_outlined_box(container(), x1, y1, x2, y2, ui().colors().background_color()); @@ -169,37 +165,37 @@ void menu_textbox::draw(uint32_t flags) { // 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)) + 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, + line_x1, visible_top + line_height(), ui().colors().mouseover_bg_color()); set_hover(HOVER_ARROW_UP); } draw_arrow( - 0.5f * (x1 + x2 - ud_arrow_width), visible_top + (0.25f * line_height), - 0.5f * (x1 + x2 + ud_arrow_width), visible_top + (0.75f * line_height), + 0.5f * (x1 + x2 - ud_arrow_width()), visible_top + (0.25f * line_height()), + 0.5f * (x1 + x2 + ud_arrow_width()), visible_top + (0.75f * line_height()), fgcolor, ROT0); } if ((m_top_line + m_window_lines) < visible_items) { // if we're on the bottom line, display the down arrow - float const line_y = visible_top + float(m_window_lines - 1) * line_height; + float const line_y = visible_top + float(m_window_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)) + 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, + line_x1, line_y + line_height(), ui().colors().mouseover_bg_color()); set_hover(HOVER_ARROW_DOWN); } draw_arrow( - 0.5f * (x1 + x2 - ud_arrow_width), line_y + (0.25f * line_height), - 0.5f * (x1 + x2 + ud_arrow_width), line_y + (0.75f * line_height), + 0.5f * (x1 + x2 - ud_arrow_width()), line_y + (0.25f * line_height()), + 0.5f * (x1 + x2 + ud_arrow_width()), line_y + (0.75f * line_height()), fgcolor, ROT0 ^ ORIENTATION_FLIP_Y); } @@ -208,16 +204,16 @@ void menu_textbox::draw(uint32_t flags) m_layout->emit( container(), m_top_line ? (m_top_line + 1) : 0, text_lines, - effective_left, visible_top + (m_top_line ? line_height : 0.0f)); + effective_left, visible_top + (m_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), + x1, separator + (0.5f * line_height()), + x2, separator + (0.5f * line_height()), UI_LINE_WIDTH, ui().colors().text_color(), PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); - float const line_y0 = separator + line_height; - float const line_y1 = line_y0 + line_height; + 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); @@ -229,7 +225,8 @@ void menu_textbox::draw(uint32_t flags) 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); + nullptr, nullptr, + line_height()); // 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); diff --git a/src/frontend/mame/ui/ui.cpp b/src/frontend/mame/ui/ui.cpp index 878e175d22a..6789686cac7 100644 --- a/src/frontend/mame/ui/ui.cpp +++ b/src/frontend/mame/ui/ui.cpp @@ -720,40 +720,37 @@ render_font *mame_ui_manager::get_font() // of a line //------------------------------------------------- -float mame_ui_manager::get_line_height() +float mame_ui_manager::get_line_height(float scale) { - int32_t raw_font_pixel_height = get_font()->pixel_height(); - render_target &ui_target = machine().render().ui_target(); - int32_t target_pixel_height = ui_target.height(); - float one_to_one_line_height; - float scale_factor; + int32_t const raw_font_pixel_height = get_font()->pixel_height(); + float target_pixel_height = machine().render().ui_target().height(); // compute the font pixel height at the nominal size - one_to_one_line_height = (float)raw_font_pixel_height / (float)target_pixel_height; + float const one_to_one_line_height = float(raw_font_pixel_height) / target_pixel_height; // determine the scale factor - scale_factor = target_font_height() / one_to_one_line_height; + float scale_factor = target_font_height() * scale / one_to_one_line_height; // if our font is small-ish, do integral scaling if (raw_font_pixel_height < 24) { // do we want to scale smaller? only do so if we exceed the threshold - if (scale_factor <= 1.0f) + if (scale_factor <= 1.0F) { if (one_to_one_line_height < UI_MAX_FONT_HEIGHT || raw_font_pixel_height < 12) - scale_factor = 1.0f; + scale_factor = 1.0F; } - - // otherwise, just ensure an integral scale factor else + { + // otherwise, just ensure an integral scale factor scale_factor = floor(scale_factor); + } } - - // otherwise, just make sure we hit an even number of pixels else { - int32_t height = scale_factor * one_to_one_line_height * (float)target_pixel_height; - scale_factor = (float)height / (one_to_one_line_height * (float)target_pixel_height); + // otherwise, just make sure we hit an even number of pixels + int32_t height = scale_factor * one_to_one_line_height * target_pixel_height; + scale_factor = float(height) / (one_to_one_line_height * target_pixel_height); } return scale_factor * one_to_one_line_height; @@ -776,9 +773,14 @@ float mame_ui_manager::get_char_width(char32_t ch) // character string //------------------------------------------------- +float mame_ui_manager::get_string_width(std::string_view s) +{ + return get_string_width(s, get_line_height()); +} + float mame_ui_manager::get_string_width(std::string_view s, float text_size) { - return get_font()->utf8string_width(get_line_height() * text_size, machine().render().ui_aspect(), s); + return get_font()->utf8string_width(text_size, machine().render().ui_aspect(), s); } @@ -837,18 +839,37 @@ void mame_ui_manager::draw_text_full( float x, float y, float origwrapwidth, ui::text_layout::text_justify justify, ui::text_layout::word_wrapping wrap, draw_mode draw, rgb_t fgcolor, rgb_t bgcolor, + float *totalwidth, float *totalheight) +{ + draw_text_full( + container, + origs, + x, y, origwrapwidth, + justify, wrap, + draw, fgcolor, bgcolor, + totalwidth, totalheight, + get_line_height()); +} + +void mame_ui_manager::draw_text_full( + render_container &container, + std::string_view origs, + float x, float y, float origwrapwidth, + ui::text_layout::text_justify justify, ui::text_layout::word_wrapping wrap, + draw_mode draw, rgb_t fgcolor, rgb_t bgcolor, float *totalwidth, float *totalheight, float text_size) { // create the layout - auto layout = create_layout(container, origwrapwidth, justify, wrap); + ui::text_layout layout( + *get_font(), machine().render().ui_aspect(&container) * text_size, text_size, + origwrapwidth, justify, wrap); // append text to it layout.add_text( origs, fgcolor, - (draw == OPAQUE_) ? bgcolor : rgb_t::transparent(), - text_size); + (draw == OPAQUE_) ? bgcolor : rgb_t::transparent()); // and emit it (if we are asked to do so) if (draw != NONE) @@ -2039,8 +2060,8 @@ int32_t mame_ui_manager::slider_crossoffset(ioport_field &field, std::string *st ui::text_layout mame_ui_manager::create_layout(render_container &container, float width, ui::text_layout::text_justify justify, ui::text_layout::word_wrapping wrap) { // determine scale factors - float yscale = get_line_height(); - float xscale = yscale * machine().render().ui_aspect(&container); + float const yscale = get_line_height(); + float const xscale = yscale * machine().render().ui_aspect(&container); // create the layout return ui::text_layout(*get_font(), xscale, yscale, width, justify, wrap); diff --git a/src/frontend/mame/ui/ui.h b/src/frontend/mame/ui/ui.h index e773e669cd6..46a5ae4c383 100644 --- a/src/frontend/mame/ui/ui.h +++ b/src/frontend/mame/ui/ui.h @@ -153,13 +153,15 @@ public: virtual void set_startup_text(const char *text, bool force) override; void update_and_render(render_container &container); render_font *get_font(); - float get_line_height(); + float get_line_height(float scale = 1.0F); float get_char_width(char32_t ch); - float get_string_width(std::string_view s, float text_size = 1.0f); + float get_string_width(std::string_view s); + float get_string_width(std::string_view s, float text_size); void draw_outlined_box(render_container &container, float x0, float y0, float x1, float y1, rgb_t backcolor); void draw_outlined_box(render_container &container, float x0, float y0, float x1, float y1, rgb_t fgcolor, rgb_t bgcolor); void draw_text(render_container &container, std::string_view buf, float x, float y); - void draw_text_full(render_container &container, std::string_view origs, float x, float y, float origwrapwidth, ui::text_layout::text_justify justify, ui::text_layout::word_wrapping wrap, draw_mode draw, rgb_t fgcolor, rgb_t bgcolor, float *totalwidth = nullptr, float *totalheight = nullptr, float text_size = 1.0f); + void draw_text_full(render_container &container, std::string_view origs, float x, float y, float origwrapwidth, ui::text_layout::text_justify justify, ui::text_layout::word_wrapping wrap, draw_mode draw, rgb_t fgcolor, rgb_t bgcolor, float *totalwidth = nullptr, float *totalheight = nullptr); + void draw_text_full(render_container &container, std::string_view origs, float x, float y, float origwrapwidth, ui::text_layout::text_justify justify, ui::text_layout::word_wrapping wrap, draw_mode draw, rgb_t fgcolor, rgb_t bgcolor, float *totalwidth, float *totalheight, float text_size); void draw_text_box(render_container &container, std::string_view text, ui::text_layout::text_justify justify, float xpos, float ypos, rgb_t backcolor); void draw_text_box(render_container &container, ui::text_layout &layout, float xpos, float ypos, rgb_t backcolor); void draw_message_window(render_container &container, std::string_view text); |