summaryrefslogtreecommitdiffstatshomepage
path: root/src/frontend/mame/ui/utils.h
blob: 5e6c2f6acfd99b4a1eea84afffee57ab7d84aea5 (plain) (blame)
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
// license:BSD-3-Clause
// copyright-holders:Maurizio Petrarota
/***************************************************************************

    ui/utils.h

    Internal UI user interface.

***************************************************************************/

#pragma once

#ifndef __UI_UTILS_H__
#define __UI_UTILS_H__

#include "unicode.h"

#define MAX_CHAR_INFO            256
#define MAX_CUST_FILTER          8

// GLOBAL ENUMERATORS
enum : UINT16
{
	FILTER_FIRST = 0,
	FILTER_ALL = FILTER_FIRST,
	FILTER_AVAILABLE,
	FILTER_UNAVAILABLE,
	FILTER_WORKING,
	FILTER_NOT_WORKING,
	FILTER_MECHANICAL,
	FILTER_NOT_MECHANICAL,
	FILTER_CATEGORY,
	FILTER_FAVORITE,
	FILTER_BIOS,
	FILTER_PARENT,
	FILTER_CLONES,
	FILTER_MANUFACTURER,
	FILTER_YEAR,
	FILTER_SAVE,
	FILTER_NOSAVE,
	FILTER_CHD,
	FILTER_NOCHD,
	FILTER_VERTICAL,
	FILTER_HORIZONTAL,
	FILTER_CUSTOM,
	FILTER_LAST = FILTER_CUSTOM
};

enum
{
	FIRST_VIEW = 0,
	SNAPSHOT_VIEW = FIRST_VIEW,
	CABINETS_VIEW,
	CPANELS_VIEW,
	PCBS_VIEW,
	FLYERS_VIEW,
	TITLES_VIEW,
	ENDS_VIEW,
	ARTPREV_VIEW,
	BOSSES_VIEW,
	LOGOS_VIEW,
	VERSUS_VIEW,
	GAMEOVER_VIEW,
	HOWTO_VIEW,
	SCORES_VIEW,
	SELECT_VIEW,
	MARQUEES_VIEW,
	LAST_VIEW = MARQUEES_VIEW
};

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 : UINT16
{
	UI_SW_FIRST = 0,
	UI_SW_ALL = UI_SW_FIRST,
	UI_SW_AVAILABLE,
	UI_SW_UNAVAILABLE,
	UI_SW_PARENTS,
	UI_SW_CLONES,
	UI_SW_YEARS,
	UI_SW_PUBLISHERS,
	UI_SW_SUPPORTED,
	UI_SW_PARTIAL_SUPPORTED,
	UI_SW_UNSUPPORTED,
	UI_SW_REGION,
	UI_SW_TYPE,
	UI_SW_LIST,
	UI_SW_CUSTOM,
	UI_SW_LAST = UI_SW_CUSTOM
};

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_DATS,
	HOVER_RPANEL_ARROW,
	HOVER_LPANEL_ARROW,
	HOVER_FILTER_FIRST,
	HOVER_FILTER_LAST = (HOVER_FILTER_FIRST) + 1 + FILTER_LAST,
	HOVER_SW_FILTER_FIRST,
	HOVER_SW_FILTER_LAST = (HOVER_SW_FILTER_FIRST) + 1 + UI_SW_LAST,
	HOVER_RP_FIRST,
	HOVER_RP_LAST = (HOVER_RP_FIRST) + 1 + RP_LAST
};

// GLOBAL STRUCTURES
struct ui_software_info
{
	ui_software_info() {}
	ui_software_info(std::string sname, std::string lname, std::string pname, std::string y, std::string pub,
		UINT8 s, std::string pa, const game_driver *d, std::string li, std::string i, std::string is, UINT8 em,
		std::string plong, std::string u, std::string de, bool av)
	{
		shortname = sname; longname = lname; parentname = pname; year = y; publisher = pub;
		supported = s; part = pa; driver = d; listname = li; interface = i; instance = is; startempty = em;
		parentlongname = plong; usage = u; devicetype = de; available = av;
	}
	std::string shortname;
	std::string longname;
	std::string parentname;
	std::string year;
	std::string publisher;
	UINT8 supported = 0;
	std::string part;
	const game_driver *driver = nullptr;
	std::string listname;
	std::string interface;
	std::string instance;
	UINT8 startempty = 0;
	std::string parentlongname;
	std::string usage;
	std::string devicetype;
	bool available = false;

	bool operator==(const ui_software_info& r)
	{
		if (shortname == r.shortname && longname == r.longname && parentname == r.parentname
			&& year == r.year && publisher == r.publisher && supported == r.supported
			&& part == r.part && driver == r.driver && listname == r.listname
			&& interface == r.interface && instance == r.instance && startempty == r.startempty
			&& parentlongname == r.parentlongname && usage == r.usage && devicetype == r.devicetype)
			return true;

		return false;
	}
};

// Manufacturers
struct c_mnfct
{
	static void set(const char *str);
	static std::string getname(const char *str);
	static std::vector<std::string> ui;
	static std::unordered_map<std::string, int> uimap;
	static UINT16 actual;
};

// Years
struct c_year
{
	static void set(const char *str);
	static std::vector<std::string> ui;
	static UINT16 actual;
};

// GLOBAL CLASS
struct ui_globals
{
	static UINT8        curimage_view, curdats_view, curdats_total, cur_sw_dats_view, cur_sw_dats_total, rpanel;
	static bool         switch_image, redraw_icon, default_image, reset;
	static int          visible_main_lines, visible_sw_lines;
	static UINT16       panels_status;
	static bool         has_icons;
};

#define main_struct(name) \
struct name##_filters \
{ \
	static UINT16 actual; \
	static const char *text[]; \
	static size_t length; \
};

main_struct(main);
main_struct(sw);

// Custom filter
struct custfltr
{
	static UINT16  main;
	static UINT16  numother;
	static UINT16  other[MAX_CUST_FILTER];
	static UINT16  mnfct[MAX_CUST_FILTER];
	static UINT16  screen[MAX_CUST_FILTER];
	static UINT16  year[MAX_CUST_FILTER];
};

// Software custom filter
struct sw_custfltr
{
	static UINT16  main;
	static UINT16  numother;
	static UINT16  other[MAX_CUST_FILTER];
	static UINT16  mnfct[MAX_CUST_FILTER];
	static UINT16  year[MAX_CUST_FILTER];
	static UINT16  region[MAX_CUST_FILTER];
	static UINT16  type[MAX_CUST_FILTER];
	static UINT16  list[MAX_CUST_FILTER];
};

// GLOBAL FUNCTIONS
int fuzzy_substring(std::string needle, std::string haystack);
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);


//-------------------------------------------------
//  input_character - inputs a typed character
//  into a buffer
//-------------------------------------------------

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();

	if ((unichar == 8) || (unichar == 0x7f))
	{
		// backspace
		if (0 < buflen)
		{
			auto buffer_oldend = buffer.c_str() + buflen;
			auto buffer_newend = utf8_previous_char(buffer_oldend);
			buffer.resize(buffer_newend - buffer.c_str());
			result = 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)
		{
			buffer += utf8_char;
			result = true;
		}
	}
	return result;
}


//-------------------------------------------------
//  input_character - inputs a typed character
//  into a buffer
//-------------------------------------------------

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);
}


#endif /* __UI_UTILS_H__ */