diff options
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 |
commit | 09746dfedde2d2731de309a5729cb939cb1c93ba (patch) | |
tree | 1c377fbbbf9a335cfbe2e003bc399c6f02e6e742 /src/frontend/mame/ui/datmenu.cpp | |
parent | aefe95ecd99b5be78a2c3cb3e1dca035315d8386 (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/datmenu.cpp')
-rw-r--r-- | src/frontend/mame/ui/datmenu.cpp | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/src/frontend/mame/ui/datmenu.cpp b/src/frontend/mame/ui/datmenu.cpp index 7df7d2fe4b9..bd39e72a6cd 100644 --- a/src/frontend/mame/ui/datmenu.cpp +++ b/src/frontend/mame/ui/datmenu.cpp @@ -149,10 +149,11 @@ void menu_dats_view::populate(float &customtop, float &custombottom) void menu_dats_view::draw(uint32_t flags) { + float const aspect = machine().render().ui_aspect(&container()); float const line_height = ui().get_line_height(); - float const ud_arrow_width = line_height * machine().render().ui_aspect(); - float const gutter_width = 0.52f * line_height * machine().render().ui_aspect(); - float const visible_width = 1.0f - (2.0f * ui().box_lr_border()); + float const ud_arrow_width = line_height * aspect; + float const gutter_width = 0.52f * line_height * aspect; + float const visible_width = 1.0f - (2.0f * ui().box_lr_border() * aspect); float const visible_left = (1.0f - visible_width) * 0.5f; float const extra_height = 2.0f * line_height; float const visible_extra_menu_height = get_customtop() + get_custombottom() + extra_height; @@ -191,7 +192,7 @@ void menu_dats_view::draw(uint32_t flags) int const n_loop = (std::min)(visible_items, m_visible_lines); for (int linenum = 0; linenum < n_loop; linenum++) { - float const line_y = visible_top + (float)linenum * line_height; + float const line_y = visible_top + float(linenum) * line_height; int const itemnum = top_line + linenum; menu_item const &pitem = item(itemnum); char const *const itemtext = pitem.text.c_str(); @@ -295,9 +296,10 @@ void menu_dats_view::custom_render(void *selectedref, float top, float bottom, f float width; std::string driver = (m_issoft == true) ? m_swinfo->longname : m_driver->type.fullname(); + float const lr_border = ui().box_lr_border() * machine().render().ui_aspect(&container()); ui().draw_text_full(container(), driver.c_str(), 0.0f, 0.0f, 1.0f, ui::text_layout::CENTER, ui::text_layout::TRUNCATE, mame_ui_manager::NONE, rgb_t::white(), rgb_t::black(), &width, nullptr); - width += 2 * ui().box_lr_border(); + width += 2 * lr_border; maxwidth = std::max(maxwidth, width); // compute our bounds @@ -310,8 +312,8 @@ void menu_dats_view::custom_render(void *selectedref, float top, float bottom, f ui().draw_outlined_box(container(), x1, y1, x2, y2, UI_GREEN_COLOR); // take off the borders - x1 += ui().box_lr_border(); - x2 -= ui().box_lr_border(); + x1 += lr_border; + x2 -= lr_border; y1 += ui().box_tb_border(); ui().draw_text_full(container(), driver.c_str(), x1, y1, x2 - x1, ui::text_layout::CENTER, ui::text_layout::NEVER, @@ -328,8 +330,8 @@ void menu_dats_view::custom_render(void *selectedref, float top, float bottom, f float space = (1.0f - maxwidth) / (m_items_list.size() * 2); // compute our bounds - x1 -= ui().box_lr_border(); - x2 += ui().box_lr_border(); + x1 -= lr_border; + x2 += lr_border; y1 = y2 + ui().box_tb_border(); y2 += ui().get_line_height() + 2.0f * ui().box_tb_border(); @@ -361,7 +363,7 @@ void menu_dats_view::custom_render(void *selectedref, float top, float bottom, f std::string revision; revision.assign(_("Revision: ")).append(m_items_list[m_actual].revision); ui().draw_text_full(container(), revision.c_str(), 0.0f, 0.0f, 1.0f, ui::text_layout::CENTER, ui::text_layout::TRUNCATE, mame_ui_manager::NONE, rgb_t::white(), rgb_t::black(), &width, nullptr); - width += 2 * ui().box_lr_border(); + width += 2 * lr_border; maxwidth = std::max(origx2 - origx1, width); // compute our bounds @@ -374,8 +376,8 @@ void menu_dats_view::custom_render(void *selectedref, float top, float bottom, f ui().draw_outlined_box(container(), x1, y1, x2, y2, UI_GREEN_COLOR); // take off the borders - x1 += ui().box_lr_border(); - x2 -= ui().box_lr_border(); + x1 += lr_border; + x2 -= lr_border; y1 += ui().box_tb_border(); // draw the text within it @@ -393,9 +395,10 @@ void menu_dats_view::get_data() std::string buffer; mame_machine_manager::instance()->lua()->call_plugin("data", m_items_list[m_actual].option, buffer); + float const aspect = machine().render().ui_aspect(&container()); float const line_height = ui().get_line_height(); - float const gutter_width = 0.52f * line_height * machine().render().ui_aspect(); - float const visible_width = 1.0f - (2.0f * ui().box_lr_border()); + float const gutter_width = 0.52f * line_height * aspect; + float const visible_width = 1.0f - (2.0f * ui().box_lr_border() * aspect); float const effective_width = visible_width - 2.0f * gutter_width; auto lines = ui().wrap_text(container(), buffer.c_str(), 0.0f, 0.0f, effective_width, xstart, xend); @@ -417,7 +420,7 @@ void menu_dats_view::get_data_sw() else mame_machine_manager::instance()->lua()->call_plugin("data", m_items_list[m_actual].option - 1, buffer); - auto lines = ui().wrap_text(container(), buffer.c_str(), 0.0f, 0.0f, 1.0f - (4.0f * ui().box_lr_border()), xstart, xend); + auto lines = ui().wrap_text(container(), buffer.c_str(), 0.0f, 0.0f, 1.0f - (4.0f * ui().box_lr_border() * machine().render().ui_aspect(&container())), xstart, xend); for (int x = 0; x < lines; ++x) { std::string tempbuf(buffer.substr(xstart[x], xend[x] - xstart[x])); |