summaryrefslogtreecommitdiffstatshomepage
path: root/src/frontend/mame/ui/menu.cpp
diff options
context:
space:
mode:
author AJR <ajrhacker@users.noreply.github.com>2020-12-08 21:19:17 -0500
committer AJR <ajrhacker@users.noreply.github.com>2020-12-08 21:24:46 -0500
commitc22cb17f326b4939d8ff4219410909e32e70ab86 (patch)
tree8db68c201fa9673eeb6acab37a5d221c7a338ea6 /src/frontend/mame/ui/menu.cpp
parent6172111b187c1dd66329adb2b9bba2a82a0ce116 (diff)
C++17 string handling updates (without charconv so as not to break GCC 7)
- render.cpp, rendlay.cpp, ui/ui.cpp, ui/menu.cpp: Change argument types for text processing functions from const char * to std::string_view - ui/menu.cpp: Add overloads of item_append omitting the frequently empty subtext argument - cheat.cpp: Remove some c_str() calls that became unnecessary a while ago
Diffstat (limited to 'src/frontend/mame/ui/menu.cpp')
-rw-r--r--src/frontend/mame/ui/menu.cpp70
1 files changed, 24 insertions, 46 deletions
diff --git a/src/frontend/mame/ui/menu.cpp b/src/frontend/mame/ui/menu.cpp
index b0a84d3a95c..c52b61449e7 100644
--- a/src/frontend/mame/ui/menu.cpp
+++ b/src/frontend/mame/ui/menu.cpp
@@ -293,21 +293,21 @@ void menu::reset(reset_options options)
// add an item to return
if (!m_parent)
{
- item_append(_("Return to Machine"), "", 0, nullptr);
+ item_append(_("Return to Machine"), 0, nullptr);
}
else if (m_parent->is_special_main_menu())
{
if (machine().options().ui() == emu_options::UI_SIMPLE)
- item_append(_("Exit"), "", 0, nullptr);
+ item_append(_("Exit"), 0, nullptr);
else
- item_append(_("Exit"), "", FLAG_LEFT_ARROW | FLAG_RIGHT_ARROW, nullptr);
+ item_append(_("Exit"), FLAG_LEFT_ARROW | FLAG_RIGHT_ARROW, nullptr);
}
else
{
if (machine().options().ui() != emu_options::UI_SIMPLE && stack_has_special_main_menu())
- item_append(_("Return to Previous Menu"), "", FLAG_LEFT_ARROW | FLAG_RIGHT_ARROW, nullptr);
+ item_append(_("Return to Previous Menu"), FLAG_LEFT_ARROW | FLAG_RIGHT_ARROW, nullptr);
else
- item_append(_("Return to Previous Menu"), "", 0, nullptr);
+ item_append(_("Return to Previous Menu"), 0, nullptr);
}
}
@@ -339,30 +339,10 @@ void menu::set_special_main_menu(bool special)
// end of the menu
//-------------------------------------------------
-void menu::item_append(menu_item item)
-{
- item_append(item.text, item.subtext, item.flags, item.ref, item.type);
-}
-
-//-------------------------------------------------
-// item_append - append a new item to the
-// end of the menu
-//-------------------------------------------------
-
void menu::item_append(menu_item_type type, uint32_t flags)
{
if (type == menu_item_type::SEPARATOR)
- item_append(MENU_SEPARATOR_ITEM, "", flags, nullptr, menu_item_type::SEPARATOR);
-}
-
-//-------------------------------------------------
-// item_append - append a new item to the
-// end of the menu
-//-------------------------------------------------
-
-void menu::item_append(const std::string &text, const std::string &subtext, uint32_t flags, void *ref, menu_item_type type)
-{
- item_append(std::string(text), std::string(subtext), flags, ref, type);
+ item_append(MENU_SEPARATOR_ITEM, flags, nullptr, menu_item_type::SEPARATOR);
}
//-------------------------------------------------
@@ -510,7 +490,7 @@ void menu::draw(uint32_t flags)
// first draw the FPS counter
if (ui().show_fps_counter())
{
- ui().draw_text_full(container(), machine().video().speed_text().c_str(), 0.0f, 0.0f, 1.0f,
+ ui().draw_text_full(container(), machine().video().speed_text(), 0.0f, 0.0f, 1.0f,
ui::text_layout::RIGHT, ui::text_layout::WORD, mame_ui_manager::OPAQUE_, rgb_t::white(), rgb_t::black(), nullptr, nullptr);
}
@@ -533,11 +513,11 @@ 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.c_str()) + gutter_width;
+ float total_width = gutter_width + ui().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.c_str());
+ total_width += 2.0f * gutter_width + ui().get_string_width(pitem.subtext);
// track the maximum
if (total_width > visible_width)
@@ -612,7 +592,7 @@ void menu::draw(uint32_t flags)
{
auto const itemnum = top_line + linenum;
menu_item const &pitem = m_items[itemnum];
- char const *const itemtext = pitem.text.c_str();
+ std::string_view const itemtext = pitem.text;
rgb_t fgcolor = ui().colors().text_color();
rgb_t bgcolor = ui().colors().text_bg_color();
rgb_t fgcolor2 = ui().colors().subitem_color();
@@ -689,7 +669,6 @@ void menu::draw(uint32_t flags)
{
// otherwise, draw the item on the left and the subitem text on the right
bool const subitem_invert(pitem.flags & FLAG_INVERT);
- char const *subitem_text(pitem.subtext.c_str());
float item_width, subitem_width;
// draw the left-side text
@@ -698,7 +677,7 @@ void menu::draw(uint32_t flags)
if (pitem.flags & FLAG_COLOR_BOX)
{
- rgb_t color = rgb_t((uint32_t)strtoul(subitem_text, nullptr, 16));
+ 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");
@@ -708,6 +687,8 @@ void menu::draw(uint32_t flags)
}
else
{
+ std::string_view subitem_text(pitem.subtext);
+
// give 2 spaces worth of padding
item_width += 2.0f * gutter_width;
@@ -720,13 +701,13 @@ void menu::draw(uint32_t flags)
}
// customize subitem text color
- if (!core_stricmp(subitem_text, _("On")))
+ if (!core_strnicmp(&subitem_text[0], _("On"), subitem_text.length()))
fgcolor2 = rgb_t(0x00,0xff,0x00);
- if (!core_stricmp(subitem_text, _("Off")))
+ if (!core_strnicmp(&subitem_text[0], _("Off"), subitem_text.length()))
fgcolor2 = rgb_t(0xff,0x00,0x00);
- if (!core_stricmp(subitem_text, _("Auto")))
+ if (!core_strnicmp(&subitem_text[0], _("Auto"), subitem_text.length()))
fgcolor2 = rgb_t(0xff,0xff,0x00);
// draw the subitem right-justified
@@ -769,7 +750,7 @@ void menu::draw(uint32_t flags)
float target_width, target_height;
// compute the multi-line target width/height
- ui().draw_text_full(container(), pitem.subtext.c_str(), 0, 0, visible_width * 0.75f,
+ ui().draw_text_full(container(), pitem.subtext, 0, 0, visible_width * 0.75f,
ui::text_layout::RIGHT, ui::text_layout::WORD, mame_ui_manager::NONE, rgb_t::white(), rgb_t::black(), &target_width, &target_height);
// determine the target location
@@ -785,7 +766,7 @@ void menu::draw(uint32_t flags)
target_y + target_height + ui().box_tb_border(),
subitem_invert ? ui().colors().selected_bg_color() : ui().colors().background_color());
- ui().draw_text_full(container(), pitem.subtext.c_str(), target_x, target_y, target_width,
+ ui().draw_text_full(container(), pitem.subtext, target_x, target_y, target_width,
ui::text_layout::RIGHT, ui::text_layout::WORD, mame_ui_manager::NORMAL, ui().colors().selected_color(), ui().colors().selected_bg_color(), nullptr, nullptr);
}
@@ -805,8 +786,8 @@ void menu::custom_render(void *selectedref, float top, float bottom, float x, fl
void menu::draw_text_box()
{
- const char *text = m_items[0].text.c_str();
- const char *backtext = m_items[1].text.c_str();
+ std::string_view const text = m_items[0].text;
+ std::string_view const backtext = m_items[1].text;
float const aspect = machine().render().ui_aspect(&container());
float line_height = ui().get_line_height();
float lr_arrow_width = 0.4f * line_height * aspect;
@@ -1286,7 +1267,7 @@ void menu::draw_arrow(float x0, float y0, float x1, float y1, rgb_t fgcolor, uin
// or footer text
//-------------------------------------------------
-void menu::extra_text_draw_box(float origx1, float origx2, float origy, float yspan, const char *text, int direction)
+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());
@@ -1343,14 +1324,11 @@ void menu::extra_text_position(float origx1, float origx2, float origy, float ys
// and footer text
//-------------------------------------------------
-void menu::extra_text_render(float top, float bottom, float origx1, float origy1, float origx2, float origy2, const char *header, const char *footer)
+void menu::extra_text_render(float top, float bottom, float origx1, float origy1, float origx2, float origy2, std::string_view header, std::string_view footer)
{
- header = (header && *header) ? header : nullptr;
- footer = (footer && *footer) ? footer : nullptr;
-
- if (header != nullptr)
+ if (!header.empty())
extra_text_draw_box(origx1, origx2, origy1, top, header, -1);
- if (footer != nullptr)
+ if (!footer.empty())
extra_text_draw_box(origx1, origx2, origy2, bottom, footer, +1);
}