summaryrefslogtreecommitdiffstatshomepage
path: root/src/frontend/mame/ui/utils.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/frontend/mame/ui/utils.h')
-rw-r--r--src/frontend/mame/ui/utils.h126
1 files changed, 78 insertions, 48 deletions
diff --git a/src/frontend/mame/ui/utils.h b/src/frontend/mame/ui/utils.h
index 098588086f2..04cb25a840c 100644
--- a/src/frontend/mame/ui/utils.h
+++ b/src/frontend/mame/ui/utils.h
@@ -15,12 +15,17 @@
#include "softlist.h"
#include "unicode.h"
+// FIXME: allow OSD module headers to be included in a less ugly way
+#include "../osd/modules/lib/osdlib.h"
+
#include <algorithm>
#include <functional>
#include <limits>
#include <memory>
#include <string>
+#include <string_view>
#include <unordered_map>
+#include <utility>
#include <vector>
@@ -181,6 +186,7 @@ public:
CLONES,
MANUFACTURER,
YEAR,
+ SOURCE_FILE,
SAVE,
NOSAVE,
CHD,
@@ -271,10 +277,13 @@ class machine_filter_data
public:
std::vector<std::string> const &manufacturers() const { return m_manufacturers; }
std::vector<std::string> const &years() const { return m_years; }
+ std::vector<std::string> const &source_files() const { return m_source_files; }
// adding entries
void add_manufacturer(std::string const &manufacturer);
void add_year(std::string const &year);
+ void add_source_file(std::string_view path);
+
void finalise();
// use heuristics to extract meaningful parts from machine metadata
@@ -301,6 +310,7 @@ private:
std::vector<std::string> m_manufacturers;
std::vector<std::string> m_years;
+ std::vector<std::string> m_source_files;
machine_filter::type m_current_filter = machine_filter::ALL;
filter_map m_filters;
@@ -352,60 +362,29 @@ private:
enum
{
- RP_FIRST = 0,
- RP_IMAGES = RP_FIRST,
- RP_INFOS,
- RP_LAST = RP_INFOS
-};
-
-enum
-{
SHOW_PANELS = 0,
HIDE_LEFT_PANEL,
HIDE_RIGHT_PANEL,
HIDE_BOTH
};
-enum
-{
- HOVER_DAT_UP = -1000,
- HOVER_DAT_DOWN,
- HOVER_UI_LEFT,
- HOVER_UI_RIGHT,
- HOVER_ARROW_UP,
- HOVER_ARROW_DOWN,
- HOVER_B_FAV,
- HOVER_B_EXPORT,
- HOVER_B_AUDIT,
- HOVER_B_DATS,
- HOVER_BACKTRACK,
- HOVER_RPANEL_ARROW,
- HOVER_LPANEL_ARROW,
- HOVER_FILTER_FIRST,
- HOVER_FILTER_LAST = HOVER_FILTER_FIRST + std::max<int>(ui::machine_filter::COUNT, ui::software_filter::COUNT),
- HOVER_RP_FIRST,
- HOVER_RP_LAST = HOVER_RP_FIRST + 1 + RP_LAST,
- HOVER_INFO_TEXT
-};
-
// FIXME: this stuff shouldn't all be globals
// GLOBAL CLASS
struct ui_globals
{
- static uint8_t curdats_view, curdats_total, cur_sw_dats_view, cur_sw_dats_total, rpanel;
- static bool default_image, reset;
- static int visible_main_lines, visible_sw_lines;
- static uint16_t panels_status;
+ static uint8_t curdats_view, curdats_total, cur_sw_dats_view, cur_sw_dats_total;
+ static bool reset;
};
// GLOBAL FUNCTIONS
char* chartrimcarriage(char str[]);
-const char* strensure(const char* s);
int getprecisionchr(const char* s);
std::vector<std::string> tokenize(const std::string &text, char sep);
+namespace ui {
+
//-------------------------------------------------
// input_character - inputs a typed character
// into a buffer
@@ -414,31 +393,30 @@ std::vector<std::string> tokenize(const std::string &text, char sep);
template <typename F>
bool input_character(std::string &buffer, std::string::size_type size, char32_t unichar, F &&filter)
{
- bool result = false;
- auto buflen = buffer.size();
-
+ auto const buflen(buffer.length());
if ((unichar == 8) || (unichar == 0x7f))
{
// backspace
if (0 < buflen)
{
- auto buffer_oldend = buffer.c_str() + buflen;
- auto buffer_newend = utf8_previous_char(buffer_oldend);
+ auto const buffer_oldend(buffer.c_str() + buflen);
+ auto const buffer_newend(utf8_previous_char(buffer_oldend));
buffer.resize(buffer_newend - buffer.c_str());
- result = true;
+ return true;
}
}
else if ((unichar >= ' ') && filter(unichar))
{
// append this character - check against the size first
- std::string utf8_char = utf8_from_uchar(unichar);
- if ((buffer.size() + utf8_char.size()) <= size)
+ char utf8char[UTF8_CHAR_MAX];
+ auto const utf8len(utf8_from_uchar(utf8char, std::size(utf8char), unichar));
+ if ((0 < utf8len) && (size >= utf8len) && ((size - utf8len) >= buflen))
{
- buffer += utf8_char;
- result = true;
+ buffer.append(utf8char, utf8len);
+ return true;
}
}
- return result;
+ return false;
}
@@ -450,9 +428,61 @@ bool input_character(std::string &buffer, std::string::size_type size, char32_t
template <typename F>
bool input_character(std::string &buffer, char32_t unichar, F &&filter)
{
- auto size = std::numeric_limits<std::string::size_type>::max();
- return input_character(buffer, size, unichar, filter);
+ auto const size(std::numeric_limits<std::string::size_type>::max());
+ return input_character(buffer, size, unichar, std::forward<F>(filter));
+}
+
+
+//-------------------------------------------------
+// paste_text - paste text from clipboard into a
+// buffer, ignoring invalid characters
+//-------------------------------------------------
+
+template <typename F>
+bool paste_text(std::string &buffer, std::string::size_type size, F &&filter)
+{
+ std::string const clip(osd_get_clipboard_text());
+ std::string_view text(clip);
+ bool updated(false);
+ int codelength;
+ char32_t unichar;
+ while ((codelength = uchar_from_utf8(&unichar, text)) != 0)
+ {
+ text.remove_prefix((0 < codelength) ? codelength : 1);
+ if ((0 < codelength) && filter(unichar))
+ {
+ char utf8char[UTF8_CHAR_MAX];
+ auto const utf8len(utf8_from_uchar(utf8char, std::size(utf8char), unichar));
+ if (0 < utf8len)
+ {
+ if ((size < utf8len) || ((size - utf8len) < buffer.length()))
+ {
+ return updated;
+ }
+ else
+ {
+ buffer.append(utf8char, utf8len);
+ updated = true;
+ }
+ }
+ }
+ }
+ return updated;
}
+//-------------------------------------------------
+// paste_text - paste text from clipboard into a
+// buffer, ignoring invalid characters
+//-------------------------------------------------
+
+template <typename F>
+bool paste_text(std::string &buffer, F &&filter)
+{
+ auto const size(std::numeric_limits<std::string::size_type>::max());
+ return paste_text(buffer, size, std::forward<F>(filter));
+}
+
+} // namespace ui
+
#endif // MAME_FRONTEND_UI_UTILS_H