1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
// license:BSD-3-Clause
// copyright-holders:Dankan1890
/***************************************************************************
ui/utils.cpp
Internal UI user interface.
***************************************************************************/
#include "emu.h"
#include "ui/utils.h"
#include <algorithm>
extern const char UI_VERSION_TAG[];
const char UI_VERSION_TAG[] = "# UI INFO ";
// Years index
UINT16 c_year::actual = 0;
std::vector<std::string> c_year::ui;
// Manufacturers index
UINT16 c_mnfct::actual = 0;
std::vector<std::string> c_mnfct::ui;
// Main filters
UINT16 main_filters::actual = 0;
const char *main_filters::text[] = { "All", "Available", "Unavailable", "Working", "Not Working", "Mechanical", "Not Mechanical",
"Category", "Favorites", "BIOS", "Originals", "Clones", "Manufacturers", "Years", "Support Save",
"Not Support Save", "CHD", "No CHD", "Vertical", "Horizontal", "Custom" };
size_t main_filters::length = ARRAY_LENGTH(main_filters::text);
// Software filters
UINT16 sw_filters::actual = 0;
const char *sw_filters::text[] = { "All", "Available", "Unavailable", "Originals", "Clones", "Years", "Publishers", "Supported",
"Partial Supported", "Unsupported", "Region", "Device Type", "Software List", "Custom" };
size_t sw_filters::length = ARRAY_LENGTH(sw_filters::text);
// Globals
UINT8 ui_globals::rpanel = 0;
UINT8 ui_globals::curimage_view = 0;
UINT8 ui_globals::curdats_view = 0;
UINT8 ui_globals::cur_sw_dats_view = 0;
bool ui_globals::switch_image = false;
bool ui_globals::default_image = true;
bool ui_globals::reset = false;
bool ui_globals::redraw_icon = false;
int ui_globals::visible_main_lines = 0;
int ui_globals::visible_sw_lines = 0;
UINT16 ui_globals::panels_status = 0;
bool ui_globals::has_icons = false;
// Custom filter
UINT16 custfltr::main = 0;
UINT16 custfltr::numother = 0;
UINT16 custfltr::other[MAX_CUST_FILTER];
UINT16 custfltr::mnfct[MAX_CUST_FILTER];
UINT16 custfltr::year[MAX_CUST_FILTER];
UINT16 custfltr::screen[MAX_CUST_FILTER];
// Custom filter
UINT16 sw_custfltr::main = 0;
UINT16 sw_custfltr::numother = 0;
UINT16 sw_custfltr::other[MAX_CUST_FILTER];
UINT16 sw_custfltr::mnfct[MAX_CUST_FILTER];
UINT16 sw_custfltr::year[MAX_CUST_FILTER];
UINT16 sw_custfltr::region[MAX_CUST_FILTER];
UINT16 sw_custfltr::type[MAX_CUST_FILTER];
UINT16 sw_custfltr::list[MAX_CUST_FILTER];
char* chartrimcarriage(char str[])
{
char *pstr = strrchr(str, '\n');
if (pstr)
str[pstr - str] = '\0';
pstr = strrchr(str, '\r');
if (pstr)
str[pstr - str] = '\0';
return str;
}
const char* strensure(const char* s)
{
return s == nullptr ? "" : s;
}
//-------------------------------------------------
// search a substring with even partial matching
//-------------------------------------------------
int fuzzy_substring(std::string s_needle, std::string s_haystack)
{
if (s_needle.empty())
return s_haystack.size();
if (s_haystack.empty())
return s_needle.size();
strmakelower(s_needle);
strmakelower(s_haystack);
if (s_needle == s_haystack)
return 0;
if (s_haystack.find(s_needle) != std::string::npos)
return 0;
auto *row1 = global_alloc_array_clear<int>(s_haystack.size() + 2);
auto *row2 = global_alloc_array_clear<int>(s_haystack.size() + 2);
for (int i = 0; i < s_needle.size(); ++i)
{
row2[0] = i + 1;
for (int j = 0; j < s_haystack.size(); ++j)
{
int cost = (s_needle[i] == s_haystack[j]) ? 0 : 1;
row2[j + 1] = MIN(row1[j + 1] + 1, MIN(row2[j] + 1, row1[j] + cost));
}
int *tmp = row1;
row1 = row2;
row2 = tmp;
}
int *first, *smallest;
first = smallest = row1;
int *last = row1 + s_haystack.size();
while (++first != last)
if (*first < *smallest)
smallest = first;
int rv = *smallest;
global_free_array(row1);
global_free_array(row2);
return rv;
}
//-------------------------------------------------
// set manufacturers
//-------------------------------------------------
void c_mnfct::set(const char *str)
{
std::string name = getname(str);
if (std::find(ui.begin(), ui.end(), name) != ui.end())
return;
ui.push_back(name);
}
std::string c_mnfct::getname(const char *str)
{
std::string name(str);
size_t found = name.find("(");
if (found != std::string::npos)
return (name.substr(0, found - 1));
else
return name;
}
//-------------------------------------------------
// set years
//-------------------------------------------------
void c_year::set(const char *str)
{
std::string name(str);
if (std::find(ui.begin(), ui.end(), name) != ui.end())
return;
ui.push_back(name);
}
|