summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author AJR <ajrhacker@users.noreply.github.com>2017-05-10 14:15:04 -0400
committer AJR <ajrhacker@users.noreply.github.com>2017-05-10 14:20:32 -0400
commitdccefed038b63d718deb0d6046d8a72b3d1151f5 (patch)
treee13b2a0f0595a6ff8b50b81e37a8c41ad96237d0
parent2b94a4a300951fd79711ac83fc4f169a25e8d539 (diff)
Fix bug that permanently disabled some UI search strings when they were cleared
(nw) This adopts std::string::clear() and empty() consistently, rather than storing and checking for NUL as with C-style buffers. This fixes issue #2295 and probably other unreported bugs afflicting UI search text input.
-rw-r--r--src/frontend/mame/ui/custui.cpp13
-rw-r--r--src/frontend/mame/ui/dirmenu.cpp4
-rw-r--r--src/frontend/mame/ui/dirmenu.h2
-rw-r--r--src/frontend/mame/ui/selector.cpp6
-rw-r--r--src/frontend/mame/ui/selector.h2
-rw-r--r--src/frontend/mame/ui/selgame.cpp14
-rw-r--r--src/frontend/mame/ui/selgame.h2
-rw-r--r--src/frontend/mame/ui/selsoft.cpp10
-rw-r--r--src/frontend/mame/ui/selsoft.h2
-rw-r--r--src/frontend/mame/ui/simpleselgame.cpp8
-rw-r--r--src/frontend/mame/ui/simpleselgame.h2
11 files changed, 33 insertions, 32 deletions
diff --git a/src/frontend/mame/ui/custui.cpp b/src/frontend/mame/ui/custui.cpp
index 17a5c22539b..21b2f196440 100644
--- a/src/frontend/mame/ui/custui.cpp
+++ b/src/frontend/mame/ui/custui.cpp
@@ -688,13 +688,14 @@ void menu_colors_ui::restore_colors()
// ctor
//-------------------------------------------------
-menu_rgb_ui::menu_rgb_ui(mame_ui_manager &mui, render_container &container, rgb_t *_color, std::string _title) : menu(mui, container)
+menu_rgb_ui::menu_rgb_ui(mame_ui_manager &mui, render_container &container, rgb_t *_color, std::string _title)
+ : menu(mui, container),
+ m_color(_color),
+ m_search(),
+ m_key_active(false),
+ m_lock_ref(0),
+ m_title(_title)
{
- m_color = _color;
- m_key_active = false;
- m_lock_ref = 0;
- m_title = _title;
- m_search[0] = '\0';
}
//-------------------------------------------------
diff --git a/src/frontend/mame/ui/dirmenu.cpp b/src/frontend/mame/ui/dirmenu.cpp
index 1ef39925bfd..baea5973efb 100644
--- a/src/frontend/mame/ui/dirmenu.cpp
+++ b/src/frontend/mame/ui/dirmenu.cpp
@@ -278,7 +278,7 @@ menu_add_change_folder::menu_add_change_folder(mame_ui_manager &mui, render_cont
{
m_ref = ref;
m_change = (s_folders[ref].action == CHANGE);
- m_search[0] = '\0';
+ m_search.clear();
// configure the starting path
osd_get_full_path(m_current_path, ".");
@@ -338,7 +338,7 @@ void menu_add_change_folder::handle()
}
// reset the char buffer also in this case
- m_search[0] = '\0';
+ m_search.clear();
reset(reset_options::SELECT_FIRST);
}
else if (menu_event->iptkey == IPT_SPECIAL)
diff --git a/src/frontend/mame/ui/dirmenu.h b/src/frontend/mame/ui/dirmenu.h
index 5d092273b1c..d887dd58231 100644
--- a/src/frontend/mame/ui/dirmenu.h
+++ b/src/frontend/mame/ui/dirmenu.h
@@ -100,7 +100,7 @@ public:
protected:
virtual void custom_render(void *selectedref, float top, float bottom, float x, float y, float x2, float y2) override;
- virtual bool menu_has_search_active() override { return (m_search[0] != 0); }
+ virtual bool menu_has_search_active() override { return !m_search.empty(); }
private:
virtual void populate(float &customtop, float &custombottom) override;
diff --git a/src/frontend/mame/ui/selector.cpp b/src/frontend/mame/ui/selector.cpp
index 83af27c4b72..8d5dd900e13 100644
--- a/src/frontend/mame/ui/selector.cpp
+++ b/src/frontend/mame/ui/selector.cpp
@@ -23,25 +23,25 @@ namespace ui {
menu_selector::menu_selector(mame_ui_manager &mui, render_container &container, std::vector<std::string> const &s_sel, uint16_t &s_actual, int category, int _hover)
: menu(mui, container)
+ , m_search()
, m_selector(s_actual)
, m_category(category)
, m_hover(_hover)
, m_first_pass(true)
, m_str_items(s_sel)
{
- m_search[0] = '\0';
m_searchlist[0] = nullptr;
}
menu_selector::menu_selector(mame_ui_manager &mui, render_container &container, std::vector<std::string> &&s_sel, uint16_t &s_actual, int category, int _hover)
: menu(mui, container)
+ , m_search()
, m_selector(s_actual)
, m_category(category)
, m_hover(_hover)
, m_first_pass(true)
, m_str_items(std::move(s_sel))
{
- m_search[0] = '\0';
m_searchlist[0] = nullptr;
}
@@ -104,7 +104,7 @@ void menu_selector::handle()
}
// escape pressed with non-empty text clears the text
- else if (menu_event->iptkey == IPT_UI_CANCEL && m_search[0] != 0)
+ else if (menu_event->iptkey == IPT_UI_CANCEL && !m_search.empty())
{
m_search.clear();
reset(reset_options::SELECT_FIRST);
diff --git a/src/frontend/mame/ui/selector.h b/src/frontend/mame/ui/selector.h
index e111d69551c..7a74a9d2c76 100644
--- a/src/frontend/mame/ui/selector.h
+++ b/src/frontend/mame/ui/selector.h
@@ -37,7 +37,7 @@ public:
protected:
virtual void custom_render(void *selectedref, float top, float bottom, float x, float y, float x2, float y2) override;
- virtual bool menu_has_search_active() override { return (m_search[0] != 0); }
+ virtual bool menu_has_search_active() override { return !m_search.empty(); }
private:
enum { VISIBLE_GAMES_IN_SEARCH = 200 };
diff --git a/src/frontend/mame/ui/selgame.cpp b/src/frontend/mame/ui/selgame.cpp
index e2628f63a9b..6d298f4d150 100644
--- a/src/frontend/mame/ui/selgame.cpp
+++ b/src/frontend/mame/ui/selgame.cpp
@@ -335,10 +335,10 @@ void menu_select_game::handle()
// handle UI_RIGHT_PANEL
ui_globals::rpanel = RP_INFOS;
}
- else if (menu_event->iptkey == IPT_UI_CANCEL && m_search[0] != 0)
+ else if (menu_event->iptkey == IPT_UI_CANCEL && !m_search.empty())
{
// escape pressed with non-empty text clears the text
- m_search[0] = '\0';
+ m_search.clear();
reset(reset_options::SELECT_FIRST);
}
else if (menu_event->iptkey == IPT_UI_DATS)
@@ -465,7 +465,7 @@ void menu_select_game::handle()
// handle filters selection from key shortcuts
if (check_filter)
{
- m_search[0] = '\0';
+ m_search.clear();
if (l_hover == FILTER_CATEGORY)
{
main_filters::actual = l_hover;
@@ -503,12 +503,12 @@ void menu_select_game::populate(float &customtop, float &custombottom)
if (!isfavorite())
{
// if search is not empty, find approximate matches
- if (m_search[0] != 0)
+ if (!m_search.empty())
populate_search();
else
{
// reset search string
- m_search[0] = '\0';
+ m_search.clear();
m_displaylist.clear();
// if filter is set on category, build category list
@@ -554,7 +554,7 @@ void menu_select_game::populate(float &customtop, float &custombottom)
else
{
// populate favorites list
- m_search[0] = '\0';
+ m_search.clear();
int curitem = 0;
// iterate over entries
@@ -1332,7 +1332,7 @@ void menu_select_game::general_info(const game_driver *driver, std::string &buff
void menu_select_game::inkey_export()
{
std::vector<game_driver const *> list;
- if (m_search[0] != 0)
+ if (!m_search.empty())
{
for (int curitem = 0; m_searchlist[curitem]; ++curitem)
list.push_back(m_searchlist[curitem]);
diff --git a/src/frontend/mame/ui/selgame.h b/src/frontend/mame/ui/selgame.h
index 7c745ab1d8d..fd9dc1ba1ca 100644
--- a/src/frontend/mame/ui/selgame.h
+++ b/src/frontend/mame/ui/selgame.h
@@ -27,7 +27,7 @@ public:
static void force_game_select(mame_ui_manager &mui, render_container &container);
protected:
- virtual bool menu_has_search_active() override { return (m_search[0] != 0); }
+ virtual bool menu_has_search_active() override { return !m_search.empty(); }
private:
enum
diff --git a/src/frontend/mame/ui/selsoft.cpp b/src/frontend/mame/ui/selsoft.cpp
index b5eeb36b204..bd19399ee1b 100644
--- a/src/frontend/mame/ui/selsoft.cpp
+++ b/src/frontend/mame/ui/selsoft.cpp
@@ -262,10 +262,10 @@ void menu_select_software::handle()
// handle UI_RIGHT_PANEL
ui_globals::rpanel = RP_INFOS;
}
- else if (menu_event->iptkey == IPT_UI_CANCEL && m_search[0] != 0)
+ else if (menu_event->iptkey == IPT_UI_CANCEL && !m_search.empty())
{
// escape pressed with non-empty text clears the text
- m_search[0] = '\0';
+ m_search.clear();
reset(reset_options::SELECT_FIRST);
}
else if (menu_event->iptkey == IPT_UI_FAVORITES)
@@ -383,7 +383,7 @@ void menu_select_software::handle()
// handle filters selection from key shortcuts
if (check_filter)
{
- m_search[0] = '\0';
+ m_search.clear();
switch (l_sw_hover)
{
case UI_SW_REGION:
@@ -432,7 +432,7 @@ void menu_select_software::populate(float &customtop, float &custombottom)
}
// no active search
- if (m_search[0] == 0)
+ if (m_search.empty())
{
// if the device can be loaded empty, add an item
if (m_has_empty_start)
@@ -1495,7 +1495,7 @@ void menu_select_software::get_selection(ui_software_info const *&software, game
void menu_select_software::make_topbox_text(std::string &line0, std::string &line1, std::string &line2) const
{
// determine the text for the header
- int vis_item = (m_search[0] != 0) ? visible_items : (m_has_empty_start ? visible_items - 1 : visible_items);
+ int vis_item = !m_search.empty() ? visible_items : (m_has_empty_start ? visible_items - 1 : visible_items);
line0 = string_format(_("%1$s %2$s ( %3$d / %4$d software packages )"), emulator_info::get_appname(), bare_build_version, vis_item, m_swinfo.size() - 1);
line1 = string_format(_("Driver: \"%1$s\" software list "), m_driver->description);
diff --git a/src/frontend/mame/ui/selsoft.h b/src/frontend/mame/ui/selsoft.h
index 48a452b5c68..3f014460791 100644
--- a/src/frontend/mame/ui/selsoft.h
+++ b/src/frontend/mame/ui/selsoft.h
@@ -27,7 +27,7 @@ public:
virtual ~menu_select_software() override;
protected:
- virtual bool menu_has_search_active() override { return (m_search[0] != 0); }
+ virtual bool menu_has_search_active() override { return !m_search.empty(); }
private:
enum { VISIBLE_GAMES_IN_SEARCH = 200 };
diff --git a/src/frontend/mame/ui/simpleselgame.cpp b/src/frontend/mame/ui/simpleselgame.cpp
index bfa8b91b205..76578d132dc 100644
--- a/src/frontend/mame/ui/simpleselgame.cpp
+++ b/src/frontend/mame/ui/simpleselgame.cpp
@@ -185,9 +185,9 @@ void simple_menu_select_game::inkey_select(const event *menu_event)
void simple_menu_select_game::inkey_cancel()
{
// escape pressed with non-empty text clears the text
- if (m_search[0] != 0)
+ if (!m_search.empty())
{
- m_search[0] = '\0';
+ m_search.clear();
reset(reset_options::SELECT_FIRST);
}
}
@@ -238,7 +238,7 @@ void simple_menu_select_game::populate(float &customtop, float &custombottom)
// otherwise, rebuild the match list
assert(m_drivlist != nullptr);
- if (m_search[0] != 0 || m_matchlist[0] == -1 || m_rerandomize)
+ if (!m_search.empty() || m_matchlist[0] == -1 || m_rerandomize)
m_drivlist->find_approximate_matches(m_search.c_str(), matchcount, m_matchlist);
m_rerandomize = false;
@@ -281,7 +281,7 @@ void simple_menu_select_game::custom_render(void *selectedref, float top, float
int line;
// display the current typeahead
- if (m_search[0] != 0)
+ if (!m_search.empty())
tempbuf[0] = string_format(_("Type name or select: %1$s_"), m_search);
else
tempbuf[0] = _("Type name or select: (random)");
diff --git a/src/frontend/mame/ui/simpleselgame.h b/src/frontend/mame/ui/simpleselgame.h
index a520165c340..b4dad4916c2 100644
--- a/src/frontend/mame/ui/simpleselgame.h
+++ b/src/frontend/mame/ui/simpleselgame.h
@@ -28,7 +28,7 @@ public:
protected:
virtual void custom_render(void *selectedref, float top, float bottom, float x, float y, float x2, float y2) override;
- virtual bool menu_has_search_active() override { return (m_search[0] != 0); }
+ virtual bool menu_has_search_active() override { return !m_search.empty(); }
private:
enum { VISIBLE_GAMES_IN_LIST = 15 };