rendfont.cpp: Convert another function to std::string_view

* cmddata.h: Remove long-disused UI button color tables
This commit is contained in:
AJR 2020-12-12 19:28:57 -05:00
parent 4d7ef27490
commit 95c6429988
6 changed files with 128 additions and 269 deletions

View File

@ -372,35 +372,30 @@ private:
} // anonymous namespace
void convert_command_glyph(std::string &str)
std::string convert_command_glyph(std::string_view str)
{
(void)str.c_str(); // force NUL-termination - we depend on it later
std::size_t const len(str.length());
std::vector<char> buf(2 * (len + 1));
std::vector<char> buf(2 * (str.length() + 1));
std::size_t j(0);
for (std::size_t i = 0; len > i; )
while (!str.empty())
{
// decode UTF-8
char32_t uchar;
int const codelen(uchar_from_utf8(&uchar, &str[i], len - i));
int const codelen(uchar_from_utf8(&uchar, &str[0], str.length()));
if (0 >= codelen)
break;
i += codelen;
str.remove_prefix(codelen);
// check for three metacharacters
fix_command_t const *fixcmd(nullptr);
switch (uchar)
{
case COMMAND_CONVERT_TEXT:
for (fix_strings_t *fixtext = convert_text; fixtext->glyph_code; ++fixtext)
for (fix_strings_t const *fixtext = convert_text; fixtext->glyph_code; ++fixtext)
{
if (!fixtext->glyph_str_len)
fixtext->glyph_str_len = std::strlen(fixtext->glyph_str);
if (!std::strncmp(fixtext->glyph_str, &str[i], fixtext->glyph_str_len))
if (str.substr(0, fixtext->glyph_str.length()) == fixtext->glyph_str)
{
uchar = fixtext->glyph_code + COMMAND_UNICODE;
i += strlen(fixtext->glyph_str);
str.remove_prefix(fixtext->glyph_str.length());
break;
}
}
@ -416,20 +411,20 @@ void convert_command_glyph(std::string &str)
}
// this substitutes a single character
if (fixcmd)
if (fixcmd && !str.empty())
{
if (str[i] == uchar)
if (str[0] == uchar)
{
++i;
str.remove_prefix(1);
}
else
{
while (fixcmd->glyph_code && (fixcmd->glyph_char != str[i]))
while (fixcmd->glyph_code && !str.empty() && fixcmd->glyph_char != str[0])
++fixcmd;
if (fixcmd->glyph_code)
if (fixcmd->glyph_code && !str.empty())
{
uchar = COMMAND_UNICODE + fixcmd->glyph_code;
++i;
str.remove_prefix(1);
}
}
}
@ -440,7 +435,7 @@ void convert_command_glyph(std::string &str)
break;
j += outlen;
}
str.assign(&buf[0], j);
return std::string(&buf[0], j);
}

View File

@ -110,6 +110,6 @@ private:
static const u64 CACHED_BDF_HASH_SIZE = 1024;
};
void convert_command_glyph(std::string &s);
std::string convert_command_glyph(std::string_view str);
#endif /* MAME_EMU_RENDFONT_H */

View File

@ -10,32 +10,6 @@
#pragma once
#define BUTTON_COLOR_RED rgb_t(255,64,64)
#define BUTTON_COLOR_YELLOW rgb_t(255,238,0)
#define BUTTON_COLOR_GREEN rgb_t(0,255,64)
#define BUTTON_COLOR_BLUE rgb_t(0,170,255)
#define BUTTON_COLOR_PURPLE rgb_t(170,0,255)
#define BUTTON_COLOR_PINK rgb_t(255,0,170)
#define BUTTON_COLOR_AQUA rgb_t(0,255,204)
#define BUTTON_COLOR_SILVER rgb_t(255,0,255)
#define BUTTON_COLOR_NAVY rgb_t(255,160,0)
#define BUTTON_COLOR_LIME rgb_t(190,190,190)
enum
{
B_COLOR_RED,
B_COLOR_YELLOW,
B_COLOR_GREEN,
B_COLOR_BLUE,
B_COLOR_PURPLE,
B_COLOR_PINK,
B_COLOR_AQUA,
B_COLOR_SILVER,
B_COLOR_NAVY,
B_COLOR_LIME,
MAX_COLORTABLE
};
// command.dat symbols assigned to Unicode PUA U+E000
#define COMMAND_UNICODE (0xe000)
#define MAX_GLYPH_FONT (150)
@ -49,102 +23,6 @@ enum
// Define Simple Game Command ShortCut
#define COMMAND_CONVERT_TEXT '@'
// Defined Game Command Font Color Array
static rgb_t const color_table[] =
{
0, // dummy
BUTTON_COLOR_RED, // BTN_A
BUTTON_COLOR_YELLOW, // BTN_B
BUTTON_COLOR_GREEN, // BTN_C
BUTTON_COLOR_BLUE, // BTN_D
BUTTON_COLOR_PINK, // BTN_E
BUTTON_COLOR_PURPLE, // BTN_F
BUTTON_COLOR_AQUA, // BTN_G
BUTTON_COLOR_SILVER, // BTN_H
BUTTON_COLOR_NAVY, // BTN_I
BUTTON_COLOR_LIME, // BTN_J
BUTTON_COLOR_RED, // BTN_K
BUTTON_COLOR_YELLOW, // BTN_L
BUTTON_COLOR_GREEN, // BTN_M
BUTTON_COLOR_BLUE, // BTN_N
BUTTON_COLOR_PINK, // BTN_O
BUTTON_COLOR_PURPLE, // BTN_P
BUTTON_COLOR_AQUA, // BTN_Q
BUTTON_COLOR_SILVER, // BTN_R
BUTTON_COLOR_NAVY, // BTN_S
BUTTON_COLOR_LIME, // BTN_T
BUTTON_COLOR_RED, // BTN_U
BUTTON_COLOR_YELLOW, // BTN_V
BUTTON_COLOR_GREEN, // BTN_W
BUTTON_COLOR_BLUE, // BTN_X
BUTTON_COLOR_PINK, // BTN_Y
BUTTON_COLOR_PURPLE, // BTN_Z
BUTTON_COLOR_RED, // BTN_1
BUTTON_COLOR_YELLOW, // BTN_2
BUTTON_COLOR_GREEN, // BTN_3
BUTTON_COLOR_BLUE, // BTN_4
BUTTON_COLOR_PINK, // BTN_5
BUTTON_COLOR_PURPLE, // BTN_6
BUTTON_COLOR_AQUA, // BTN_7
BUTTON_COLOR_SILVER, // BTN_8
BUTTON_COLOR_NAVY, // BTN_9
BUTTON_COLOR_LIME, // BTN_10
BUTTON_COLOR_BLUE, // BTN_DEC
BUTTON_COLOR_RED, // BTN_INC
0, // BTN_+
0, // DIR_...
0, // DIR_1
0, // DIR_2
0, // DIR_3
0, // DIR_4
BUTTON_COLOR_RED, // Joystick Ball
0, // DIR_6
0, // DIR_7
0, // DIR_8
0, // DIR_9
0, // DIR_N
BUTTON_COLOR_RED, // BTN_START
BUTTON_COLOR_YELLOW, // BTN_SELECT
BUTTON_COLOR_PINK, // BTN_PUNCH
BUTTON_COLOR_PURPLE, // BTN_KICK
BUTTON_COLOR_BLUE, // BTN_GUARD
0,
BUTTON_COLOR_YELLOW, // Light Punch
BUTTON_COLOR_NAVY, // Middle Punch
BUTTON_COLOR_RED, // Strong Punch
BUTTON_COLOR_LIME, // Light Kick
BUTTON_COLOR_AQUA, // Middle Kick
BUTTON_COLOR_BLUE, // Strong Kick
BUTTON_COLOR_PURPLE, // 3 Kick
BUTTON_COLOR_PINK, // 3 Punch
BUTTON_COLOR_PURPLE, // 2 Kick
BUTTON_COLOR_PINK, // 2 Punch
BUTTON_COLOR_RED, // CUSTOM_1
BUTTON_COLOR_YELLOW, // CUSTOM_2
BUTTON_COLOR_GREEN, // CUSTOM_3
BUTTON_COLOR_BLUE, // CUSTOM_4
BUTTON_COLOR_PINK, // CUSTOM_5
BUTTON_COLOR_PURPLE, // CUSTOM_6
BUTTON_COLOR_AQUA, // CUSTOM_7
BUTTON_COLOR_SILVER, // CUSTOM_8
BUTTON_COLOR_RED, // (Cursor Up)
BUTTON_COLOR_YELLOW, // (Cursor Down)
BUTTON_COLOR_GREEN, // (Cursor Left)
BUTTON_COLOR_BLUE, // (Cursor Right)
0, // Non Player Lever
BUTTON_COLOR_LIME, // Gray Color Lever
BUTTON_COLOR_RED, // 1 Player Lever
BUTTON_COLOR_YELLOW, // 2 Player Lever
BUTTON_COLOR_GREEN, // 3 Player Lever
BUTTON_COLOR_BLUE, // 4 Player Lever
BUTTON_COLOR_PINK, // 5 Player Lever
BUTTON_COLOR_PURPLE, // 6 Player Lever
BUTTON_COLOR_AQUA, // 7 Player Lever
BUTTON_COLOR_SILVER // 8 Player Lever
};
#define COLOR_BUTTONS ARRAY_LENGTH(color_table)
struct fix_command_t
{
char glyph_char;
@ -154,9 +32,8 @@ struct fix_command_t
struct fix_strings_t
{
char const *glyph_str;
int const glyph_code;
unsigned glyph_str_len;
std::string_view glyph_str;
int glyph_code;
};
static fix_command_t const default_text[] =
@ -286,117 +163,117 @@ static fix_command_t const expand_text[] =
{ 0, 0 } // end of array
};
static fix_strings_t convert_text[] =
static const fix_strings_t convert_text[] =
{
// Alphabetic Buttons: A~Z
{ "A-button", 1, 0 }, // BTN_A
{ "B-button", 2, 0 }, // BTN_B
{ "C-button", 3, 0 }, // BTN_C
{ "D-button", 4, 0 }, // BTN_D
{ "E-button", 5, 0 }, // BTN_E
{ "F-button", 6, 0 }, // BTN_F
{ "G-button", 7, 0 }, // BTN_G
{ "H-button", 8, 0 }, // BTN_H
{ "I-button", 9, 0 }, // BTN_I
{ "J-button", 10, 0 }, // BTN_J
{ "K-button", 11, 0 }, // BTN_K
{ "L-button", 12, 0 }, // BTN_L
{ "M-button", 13, 0 }, // BTN_M
{ "N-button", 14, 0 }, // BTN_N
{ "O-button", 15, 0 }, // BTN_O
{ "P-button", 16, 0 }, // BTN_P
{ "Q-button", 17, 0 }, // BTN_Q
{ "R-button", 18, 0 }, // BTN_R
{ "S-button", 19, 0 }, // BTN_S
{ "T-button", 20, 0 }, // BTN_T
{ "U-button", 21, 0 }, // BTN_U
{ "V-button", 22, 0 }, // BTN_V
{ "W-button", 23, 0 }, // BTN_W
{ "X-button", 24, 0 }, // BTN_X
{ "Y-button", 25, 0 }, // BTN_Y
{ "Z-button", 26, 0 }, // BTN_Z
{ "A-button", 1 }, // BTN_A
{ "B-button", 2 }, // BTN_B
{ "C-button", 3 }, // BTN_C
{ "D-button", 4 }, // BTN_D
{ "E-button", 5 }, // BTN_E
{ "F-button", 6 }, // BTN_F
{ "G-button", 7 }, // BTN_G
{ "H-button", 8 }, // BTN_H
{ "I-button", 9 }, // BTN_I
{ "J-button", 10 }, // BTN_J
{ "K-button", 11 }, // BTN_K
{ "L-button", 12 }, // BTN_L
{ "M-button", 13 }, // BTN_M
{ "N-button", 14 }, // BTN_N
{ "O-button", 15 }, // BTN_O
{ "P-button", 16 }, // BTN_P
{ "Q-button", 17 }, // BTN_Q
{ "R-button", 18 }, // BTN_R
{ "S-button", 19 }, // BTN_S
{ "T-button", 20 }, // BTN_T
{ "U-button", 21 }, // BTN_U
{ "V-button", 22 }, // BTN_V
{ "W-button", 23 }, // BTN_W
{ "X-button", 24 }, // BTN_X
{ "Y-button", 25 }, // BTN_Y
{ "Z-button", 26 }, // BTN_Z
// Special Moves and Buttons
{ "decrease", 37, 0 }, // BTN_DEC
{ "increase", 38, 0 }, // BTN_INC
{ "BALL", 45, 0 }, // Joystick Ball
{ "start", 51, 0 }, // BTN_START
{ "select", 52, 0 }, // BTN_SELECT
{ "punch", 53, 0 }, // BTN_PUNCH
{ "kick", 54, 0 }, // BTN_KICK
{ "guard", 55, 0 }, // BTN_GUARD
{ "L-punch", 57, 0 }, // Light Punch
{ "M-punch", 58, 0 }, // Middle Punch
{ "S-punch", 59, 0 }, // Strong Punch
{ "L-kick", 60, 0 }, // Light Kick
{ "M-kick", 61, 0 }, // Middle Kick
{ "S-kick", 62, 0 }, // Strong Kick
{ "3-kick", 63, 0 }, // 3 Kick
{ "3-punch", 64, 0 }, // 3 Punch
{ "2-kick", 65, 0 }, // 2 Kick
{ "2-punch", 66, 0 }, // 2 Pick
{ "decrease", 37 }, // BTN_DEC
{ "increase", 38 }, // BTN_INC
{ "BALL", 45 }, // Joystick Ball
{ "start", 51 }, // BTN_START
{ "select", 52 }, // BTN_SELECT
{ "punch", 53 }, // BTN_PUNCH
{ "kick", 54 }, // BTN_KICK
{ "guard", 55 }, // BTN_GUARD
{ "L-punch", 57 }, // Light Punch
{ "M-punch", 58 }, // Middle Punch
{ "S-punch", 59 }, // Strong Punch
{ "L-kick", 60 }, // Light Kick
{ "M-kick", 61 }, // Middle Kick
{ "S-kick", 62 }, // Strong Kick
{ "3-kick", 63 }, // 3 Kick
{ "3-punch", 64 }, // 3 Punch
{ "2-kick", 65 }, // 2 Kick
{ "2-punch", 66 }, // 2 Pick
// Custom Buttons and Cursor Buttons
{ "custom1", 67, 0 }, // CUSTOM_1
{ "custom2", 68, 0 }, // CUSTOM_2
{ "custom3", 69, 0 }, // CUSTOM_3
{ "custom4", 70, 0 }, // CUSTOM_4
{ "custom5", 71, 0 }, // CUSTOM_5
{ "custom6", 72, 0 }, // CUSTOM_6
{ "custom7", 73, 0 }, // CUSTOM_7
{ "custom8", 74, 0 }, // CUSTOM_8
{ "up", 75, 0 }, // (Cursor Up)
{ "down", 76, 0 }, // (Cursor Down)
{ "left", 77, 0 }, // (Cursor Left)
{ "right", 78, 0 }, // (Cursor Right)
{ "custom1", 67 }, // CUSTOM_1
{ "custom2", 68 }, // CUSTOM_2
{ "custom3", 69 }, // CUSTOM_3
{ "custom4", 70 }, // CUSTOM_4
{ "custom5", 71 }, // CUSTOM_5
{ "custom6", 72 }, // CUSTOM_6
{ "custom7", 73 }, // CUSTOM_7
{ "custom8", 74 }, // CUSTOM_8
{ "up", 75 }, // (Cursor Up)
{ "down", 76 }, // (Cursor Down)
{ "left", 77 }, // (Cursor Left)
{ "right", 78 }, // (Cursor Right)
// Player Lever
{ "lever", 79, 0 }, // Non Player Lever
{ "nplayer", 80, 0 }, // Gray Color Lever
{ "1player", 81, 0 }, // 1 Player Lever
{ "2player", 82, 0 }, // 2 Player Lever
{ "3player", 83, 0 }, // 3 Player Lever
{ "4player", 84, 0 }, // 4 Player Lever
{ "5player", 85, 0 }, // 5 Player Lever
{ "6player", 86, 0 }, // 6 Player Lever
{ "7player", 87, 0 }, // 7 Player Lever
{ "8player", 88, 0 }, // 8 Player Lever
{ "lever", 79 }, // Non Player Lever
{ "nplayer", 80 }, // Gray Color Lever
{ "1player", 81 }, // 1 Player Lever
{ "2player", 82 }, // 2 Player Lever
{ "3player", 83 }, // 3 Player Lever
{ "4player", 84 }, // 4 Player Lever
{ "5player", 85 }, // 5 Player Lever
{ "6player", 86 }, // 6 Player Lever
{ "7player", 87 }, // 7 Player Lever
{ "8player", 88 }, // 8 Player Lever
// Composition of Arrow Directions
{ "-->", 90, 0 }, // Arrow
{ "==>", 91, 0 }, // Continue Arrow
{ "hcb", 100, 0 }, // Half Circle Back
{ "huf", 101, 0 }, // Half Circle Front Up
{ "hcf", 102, 0 }, // Half Circle Front
{ "hub", 103, 0 }, // Half Circle Back Up
{ "qfd", 104, 0 }, // 1/4 Cir For 2 Down
{ "qdb", 105, 0 }, // 1/4 Cir Down 2 Back
{ "qbu", 106, 0 }, // 1/4 Cir Back 2 Up
{ "quf", 107, 0 }, // 1/4 Cir Up 2 For
{ "qbd", 108, 0 }, // 1/4 Cir Back 2 Down
{ "qdf", 109, 0 }, // 1/4 Cir Down 2 For
{ "qfu", 110, 0 }, // 1/4 Cir For 2 Up
{ "qub", 111, 0 }, // 1/4 Cir Up 2 Back
{ "fdf", 112, 0 }, // Full Clock Forward
{ "fub", 113, 0 }, // Full Clock Back
{ "fuf", 114, 0 }, // Full Count Forward
{ "fdb", 115, 0 }, // Full Count Back
{ "xff", 116, 0 }, // 2x Forward
{ "xbb", 117, 0 }, // 2x Back
{ "dsf", 118, 0 }, // Dragon Screw Forward
{ "dsb", 119, 0 }, // Dragon Screw Back
{ "-->", 90 }, // Arrow
{ "==>", 91 }, // Continue Arrow
{ "hcb", 100 }, // Half Circle Back
{ "huf", 101 }, // Half Circle Front Up
{ "hcf", 102 }, // Half Circle Front
{ "hub", 103 }, // Half Circle Back Up
{ "qfd", 104 }, // 1/4 Cir For 2 Down
{ "qdb", 105 }, // 1/4 Cir Down 2 Back
{ "qbu", 106 }, // 1/4 Cir Back 2 Up
{ "quf", 107 }, // 1/4 Cir Up 2 For
{ "qbd", 108 }, // 1/4 Cir Back 2 Down
{ "qdf", 109 }, // 1/4 Cir Down 2 For
{ "qfu", 110 }, // 1/4 Cir For 2 Up
{ "qub", 111 }, // 1/4 Cir Up 2 Back
{ "fdf", 112 }, // Full Clock Forward
{ "fub", 113 }, // Full Clock Back
{ "fuf", 114 }, // Full Count Forward
{ "fdb", 115 }, // Full Count Back
{ "xff", 116 }, // 2x Forward
{ "xbb", 117 }, // 2x Back
{ "dsf", 118 }, // Dragon Screw Forward
{ "dsb", 119 }, // Dragon Screw Back
// Big letter Text
{ "AIR", 121, 0 }, // AIR
{ "DIR", 122, 0 }, // DIR
{ "MAX", 123, 0 }, // MAX
{ "TAP", 124, 0 }, // TAP
{ "AIR", 121 }, // AIR
{ "DIR", 122 }, // DIR
{ "MAX", 123 }, // MAX
{ "TAP", 124 }, // TAP
// Condition of Positions
{ "jump", 125, 0 }, // Jump
{ "hold", 126, 0 }, // Hold
{ "air", 127, 0 }, // Air
{ "sit", 128, 0 }, // Squatting
{ "close", 129, 0 }, // Close
{ "away", 130, 0 }, // Away
{ "charge", 131, 0 }, // Charge
{ "tap", 132, 0 }, // Serious Tap
{ "button", 133, 0 }, // Any Button
{ nullptr, 0, 0 } // end of array
{ "jump", 125 }, // Jump
{ "hold", 126 }, // Hold
{ "air", 127 }, // Air
{ "sit", 128 }, // Squatting
{ "close", 129 }, // Close
{ "away", 130 }, // Away
{ "charge", 131 }, // Charge
{ "tap", 132 }, // Serious Tap
{ "button", 133 }, // Any Button
{ "", 0 } // end of array
};
#endif // MAME_EMU_UI_CMDDATA_H

View File

@ -201,8 +201,7 @@ void menu_game_options::populate(float &customtop, float &custombottom)
// add subitem if the filter wants it
if (active_filter.wants_adjuster())
{
std::string name("^!");
convert_command_glyph(name);
std::string name(convert_command_glyph("^!"));
item_append(name, active_filter.adjust_text(), active_filter.arrow_flags(), (void *)(FILTER_ADJUST));
}

View File

@ -972,8 +972,7 @@ float menu_select_launch::draw_left_panel(
}
// calculate horizontal offset for unadorned names
std::string tmp("_# ");
convert_command_glyph(tmp);
std::string tmp(convert_command_glyph("_# "));
float const text_sign = ui().get_string_width(tmp, text_size);
// get the maximum width of a filter name
@ -1005,10 +1004,7 @@ float menu_select_launch::draw_left_panel(
else
{
if (current == filter)
{
str = std::string("_> ");
convert_command_glyph(str);
}
str = convert_command_glyph("_> ");
str.append(Filter::display_name(filter));
}

View File

@ -133,10 +133,7 @@ public:
{
std::string result;
if (Type == n)
{
result = "_> ";
convert_command_glyph(result);
}
result = convert_command_glyph("_> ");
result.append(Base::display_name(n));
return result;
}
@ -259,18 +256,14 @@ public:
{
std::string result;
if (Type == n)
{
result = "_> ";
convert_command_glyph(result);
}
result = convert_command_glyph("_> ");
else
{
for (unsigned i = 0; (MAX > i) && m_filters[i]; ++i)
{
if (m_filters[i]->get_type() == n)
{
result = util::string_format("@custom%u ", i + 1);
convert_command_glyph(result);
result = convert_command_glyph(util::string_format("@custom%u ", i + 1));
break;
}
}
@ -509,8 +502,7 @@ void composite_filter_impl_base<Impl, Base, Type>::menu_configure::populate(floa
set_selected_index(item_count() - 2);
if (m_parent.m_filters[i]->wants_adjuster())
{
std::string name("^!");
convert_command_glyph(name);
std::string name(convert_command_glyph("^!"));
item_append(name, m_parent.m_filters[i]->adjust_text(), m_parent.m_filters[i]->arrow_flags(), (void *)(ADJUST_FIRST + i));
}
item_append(menu_item_type::SEPARATOR);