summaryrefslogtreecommitdiffstatshomepage
path: root/src/frontend/mame/ui/selmenu.cpp
diff options
context:
space:
mode:
author Vas Crabb <vas@vastheman.com>2019-11-22 17:53:31 +1100
committer Vas Crabb <vas@vastheman.com>2019-11-22 17:53:31 +1100
commit09746dfedde2d2731de309a5729cb939cb1c93ba (patch)
tree1c377fbbbf9a335cfbe2e003bc399c6f02e6e742 /src/frontend/mame/ui/selmenu.cpp
parentaefe95ecd99b5be78a2c3cb3e1dca035315d8386 (diff)
UI updates:
* Re-wrote localisation loader: sanitise input, check for buffer overruns, fix endianness handling, keep data in a single allocated block, do a single hash lookup when fetching a string, print diagnostic output when things go wrong * Sort UI language menu so it's not in whatever random order the filesystem yields * Fixed most menu code to adjust L/R border for UI aspect ratio and pass container to render manager when getting UI aspect ratio * Converted a couple more things to use smart pointers
Diffstat (limited to 'src/frontend/mame/ui/selmenu.cpp')
-rw-r--r--src/frontend/mame/ui/selmenu.cpp71
1 files changed, 40 insertions, 31 deletions
diff --git a/src/frontend/mame/ui/selmenu.cpp b/src/frontend/mame/ui/selmenu.cpp
index f150a06dc8e..bb3e5dc8c00 100644
--- a/src/frontend/mame/ui/selmenu.cpp
+++ b/src/frontend/mame/ui/selmenu.cpp
@@ -711,7 +711,7 @@ void menu_select_launch::custom_render(void *selectedref, float top, float botto
// is favorite? draw the star
if (isstar)
- draw_star(origx1 + ui().box_lr_border(), origy2 + (2.0f * ui().box_tb_border()));
+ draw_star(origx1 + ui().box_lr_border() * machine().render().ui_aspect(&container()), origy2 + (2.0f * ui().box_tb_border()));
}
@@ -816,7 +816,7 @@ 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)
{
auto line_height = ui().get_line_height();
- auto lr_arrow_width = 0.4f * line_height * machine().render().ui_aspect();
+ auto lr_arrow_width = 0.4f * line_height * machine().render().ui_aspect(&container());
auto gutter_width = lr_arrow_width * 1.3f;
// set left-right arrows dimension
@@ -927,10 +927,12 @@ float menu_select_launch::draw_left_panel(
// outline the box and inset by the border width
float const origy1(y1);
float const origy2(y2);
- x2 = x1 + left_width + 2.0f * ui().box_lr_border();;
+ 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;
ui().draw_outlined_box(container(), x1, y1, x2, y2, ui().colors().background_color());
- x1 += ui().box_lr_border();
- x2 -= ui().box_lr_border();
+ x1 += lr_border;
+ x2 -= lr_border;
y1 += ui().box_tb_border();
y2 -= ui().box_tb_border();
@@ -987,12 +989,12 @@ float menu_select_launch::draw_left_panel(
y1 += line_height_max;
}
- x1 = x2 + ui().box_lr_border();
- x2 = x1 + 2.0f * ui().box_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 * machine().render().ui_aspect();
+ float const lr_arrow_width = 0.4f * space * aspect;
// set left-right arrows dimension
float const ar_x0 = 0.5f * (x2 + x1) - 0.5f * lr_arrow_width;
@@ -1010,7 +1012,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 + ui().box_lr_border();
+ return x2 + lr_border;
}
@@ -1118,7 +1120,7 @@ bool menu_select_launch::scale_icon(bitmap_argb32 &&src, texture_and_bitmap &dst
{
// calculate available space for the icon in pixels
float const height(ui().get_line_height());
- float const width(height * container().manager().ui_aspect());
+ 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());
@@ -1204,8 +1206,10 @@ void menu_select_launch::draw_toolbar(float x1, float y1, float x2, float y2)
ui().draw_outlined_box(container(), x1, y1, x2, y2, rgb_t(0xEF, 0x12, 0x47, 0x7B));
// take off the borders
- x1 += ui().box_lr_border();
- x2 -= ui().box_lr_border();
+ 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();
@@ -1214,7 +1218,7 @@ void menu_select_launch::draw_toolbar(float x1, float y1, float x2, float y2)
auto const num_valid(std::count_if(std::begin(t_bitmap), std::end(t_bitmap), [](bitmap_argb32 const &e) { return e.valid(); }));
- float const space_x = (y2 - y1) * container().manager().ui_aspect(&container());
+ float const space_x = (y2 - y1) * aspect;
float const total = (float(num_valid) * space_x) + (float(num_valid - 1) * 0.001f);
x1 += (x2 - x1) * 0.5f - total * 0.5f;
x2 = x1 + space_x;
@@ -1247,7 +1251,7 @@ void menu_select_launch::draw_toolbar(float x1, float y1, float x2, float y2)
void menu_select_launch::draw_star(float x0, float y0)
{
float y1 = y0 + ui().get_line_height();
- float x1 = x0 + ui().get_line_height() * container().manager().ui_aspect();
+ float x1 = x0 + ui().get_line_height() * container().manager().ui_aspect(&container());
container().add_quad(x0, y0, x1, y1, rgb_t::white(), m_cache->star_texture(), PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_PACKABLE);
}
@@ -1814,12 +1818,14 @@ void menu_select_launch::handle_events(uint32_t flags, event &ev)
void menu_select_launch::draw(uint32_t 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 * machine().render().ui_aspect();
+ 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 * ui().box_lr_border() : 0.3f;
- float visible_width = 1.0f - 4.0f * ui().box_lr_border();
+ 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;
@@ -1854,18 +1860,18 @@ void menu_select_launch::draw(uint32_t flags)
visible_top += get_customtop();
// compute left box size
- float x1 = visible_left - ui().box_lr_border();
+ float x1 = visible_left - lr_border;
float y1 = visible_top - ui().box_tb_border();
- float x2 = x1 + 2.0f * ui().box_lr_border();
+ float x2 = x1 + 2.0f * lr_border;
float y2 = visible_top + visible_main_menu_height + ui().box_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 * ui().box_lr_border();
+ visible_width -= right_panel_size + visible_left - 2.0f * lr_border;
// compute and add main box
- x1 = visible_left - ui().box_lr_border();
- x2 = visible_left + visible_width + ui().box_lr_border();
+ 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());
@@ -2053,8 +2059,8 @@ void menu_select_launch::draw(uint32_t flags)
draw_right_panel(x1, y1, x2, y2);
- x1 = primary_left - ui().box_lr_border();
- x2 = primary_left + primary_width + ui().box_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);
@@ -2080,10 +2086,11 @@ 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()));
+ float const x2(hide ? origx2 : (origx1 + 2.0f * ui().box_lr_border() * aspect));
float const space(x2 - origx1);
- float const lr_arrow_width(0.4f * space * machine().render().ui_aspect());
+ float const lr_arrow_width(0.4f * space * aspect);
// set left-right arrows dimension
float const ar_x0(0.5f * (x2 + origx1) - 0.5f * lr_arrow_width);
@@ -2342,7 +2349,7 @@ 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() * 1.3f;
+ float const gutter_width = 0.4f * line_height * machine().render().ui_aspect(&container()) * 1.3f;
std::string snaptext, searchstr;
get_title_search(snaptext, searchstr);
@@ -2555,8 +2562,9 @@ void menu_select_launch::exit(running_machine &machine)
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 * machine().render().ui_aspect();
+ float const lr_arrow_width = 0.4f * space * aspect;
// set left-right arrows dimension
float const ar_x0 = 0.5f * (x2 + x1) - (0.5f * lr_arrow_width);
@@ -2575,7 +2583,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();
+ return x2 + ui().box_lr_border() * aspect;
}
@@ -2669,8 +2677,9 @@ void menu_select_launch::infos_render(float origx1, float origy1, float origx2,
}
origy1 += ui().box_tb_border();
- float gutter_width = 0.4f * line_height * machine().render().ui_aspect() * 1.3f;
- float ud_arrow_width = line_height * machine().render().ui_aspect();
+ 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;
char const *const snaptext(m_info_view ? m_items_list[m_info_view - 1].c_str() : _(first));