Skip to content

Commit 5b6b668

Browse files
committed
rg_gui+rg_input: Moved the virtual keypad from rg_input to rg_gui
Eventually rg_input will need some way to read the keyboard transparently, but this isn't what it was.
1 parent f74b578 commit 5b6b668

File tree

6 files changed

+101
-107
lines changed

6 files changed

+101
-107
lines changed

components/retro-go/libs/netplay/rg_netplay.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ bool rg_netplay_quick_start(void)
417417
if (screen_msg != status_msg)
418418
{
419419
rg_display_clear(0);
420-
rg_gui_draw_dialog(status_msg, NULL, 0);
420+
rg_gui_draw_message(status_msg);
421421
screen_msg = status_msg;
422422
}
423423

components/retro-go/rg_gui.c

Lines changed: 88 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,45 +1142,95 @@ void rg_gui_draw_virtual_keyboard(int x_pos, int y_pos, const rg_keyboard_layout
11421142
}
11431143
}
11441144

1145+
static const rg_keyboard_layout_t keyboard_layouts[] = {
1146+
// Lowercase letters
1147+
{
1148+
.layout = "1234567890"
1149+
"qwertyuiop"
1150+
"asdfghjkl "
1151+
"zxcvbnm.,?",
1152+
.columns = 10,
1153+
.rows = 4,
1154+
.is_upper = false,
1155+
.is_symbols = false
1156+
},
1157+
// Uppercase letters
1158+
{
1159+
.layout = "1234567890"
1160+
"QWERTYUIOP"
1161+
"ASDFGHJKL "
1162+
"ZXCVBNM.,?",
1163+
.columns = 10,
1164+
.rows = 4,
1165+
.is_upper = true,
1166+
.is_symbols = false
1167+
},
1168+
// Symbols
1169+
{
1170+
.layout = "!@#$%^&*()"
1171+
"[]{}|\\:;\"'"
1172+
"<>?/+=_-~ "
1173+
"1234567890",
1174+
.columns = 10,
1175+
.rows = 4,
1176+
.is_upper = false,
1177+
.is_symbols = true
1178+
}
1179+
};
1180+
1181+
// TODO: Abstract all the redundant/similar code between rg_gui_input_str and rg_gui_input_char
1182+
1183+
int rg_gui_input_char(const rg_keyboard_layout_t *map)
1184+
{
1185+
if (!map)
1186+
map = &keyboard_layouts[0];
1187+
1188+
int cursor = -1;
1189+
int count = map->columns * map->rows;
1190+
1191+
rg_input_wait_for_key(RG_KEY_ALL, false, 1000);
1192+
1193+
while (1)
1194+
{
1195+
uint32_t joystick = rg_input_read_gamepad();
1196+
int prev_cursor = cursor;
1197+
1198+
if (joystick & RG_KEY_A)
1199+
return map->layout[cursor];
1200+
if (joystick & RG_KEY_B)
1201+
break;
1202+
1203+
if (joystick & RG_KEY_LEFT)
1204+
cursor--;
1205+
if (joystick & RG_KEY_RIGHT)
1206+
cursor++;
1207+
if (joystick & RG_KEY_UP)
1208+
cursor -= map->columns;
1209+
if (joystick & RG_KEY_DOWN)
1210+
cursor += map->columns;
1211+
1212+
if (cursor > count - 1)
1213+
cursor = prev_cursor;
1214+
else if (cursor < 0)
1215+
cursor = prev_cursor;
1216+
1217+
cursor = RG_MIN(RG_MAX(cursor, 0), count - 1);
1218+
1219+
if (cursor != prev_cursor)
1220+
rg_gui_draw_virtual_keyboard(RG_GUI_CENTER, RG_GUI_BOTTOM, map, cursor, false);
1221+
1222+
rg_input_wait_for_key(RG_KEY_ALL, false, 500);
1223+
rg_input_wait_for_key(RG_KEY_ANY, true, 500);
1224+
1225+
rg_system_tick(0);
1226+
}
1227+
1228+
return -1;
1229+
}
1230+
11451231
char *rg_gui_input_str(const char *title, const char *message, const char *default_value)
11461232
{
11471233
// Virtual keyboard implementation for Wi-Fi credential input
1148-
static const rg_keyboard_layout_t layouts[] = {
1149-
// Lowercase letters
1150-
{
1151-
.layout = "1234567890"
1152-
"qwertyuiop"
1153-
"asdfghjkl "
1154-
"zxcvbnm.,?",
1155-
.columns = 10,
1156-
.rows = 4,
1157-
.is_upper = false,
1158-
.is_symbols = false
1159-
},
1160-
// Uppercase letters
1161-
{
1162-
.layout = "1234567890"
1163-
"QWERTYUIOP"
1164-
"ASDFGHJKL "
1165-
"ZXCVBNM.,?",
1166-
.columns = 10,
1167-
.rows = 4,
1168-
.is_upper = true,
1169-
.is_symbols = false
1170-
},
1171-
// Symbols
1172-
{
1173-
.layout = "!@#$%^&*()"
1174-
"[]{}|\\:;\"'"
1175-
"<>?/+=_-~ "
1176-
"1234567890",
1177-
.columns = 10,
1178-
.rows = 4,
1179-
.is_upper = false,
1180-
.is_symbols = true
1181-
}
1182-
};
1183-
11841234
char input_buffer[128] = {0};
11851235
if (default_value)
11861236
strncpy(input_buffer, default_value, sizeof(input_buffer) - 1);
@@ -1190,7 +1240,7 @@ char *rg_gui_input_str(const char *title, const char *message, const char *defau
11901240
int input_length = strlen(input_buffer);
11911241
bool cancelled = false;
11921242

1193-
const rg_keyboard_layout_t *current_layout = &layouts[layout_idx];
1243+
const rg_keyboard_layout_t *current_layout = &keyboard_layouts[layout_idx];
11941244

11951245
// Follow the same pattern as rg_gui_dialog
11961246
rg_input_wait_for_key(RG_KEY_ALL, false, 1000);
@@ -1271,7 +1321,7 @@ char *rg_gui_input_str(const char *title, const char *message, const char *defau
12711321
{
12721322
layout_idx = 1; // Switch to uppercase
12731323
}
1274-
current_layout = &layouts[layout_idx];
1324+
current_layout = &keyboard_layouts[layout_idx];
12751325
cursor_pos = 0;
12761326
redraw = true;
12771327
redraws = 0;

components/retro-go/rg_gui.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,15 @@ typedef struct
6767
uint8_t data[]; // stream of rg_font_glyph_t (end of list indicated by an entry with 0x0000 codepoint)
6868
} rg_font_t;
6969

70+
typedef struct
71+
{
72+
const char *layout;
73+
size_t columns;
74+
size_t rows;
75+
bool is_upper;
76+
bool is_symbols;
77+
} rg_keyboard_layout_t;
78+
7079
typedef struct
7180
{
7281
intptr_t arg;
@@ -132,6 +141,7 @@ bool rg_gui_confirm(const char *title, const char *message, bool default_yes);
132141
void rg_gui_alert(const char *title, const char *message);
133142
char *rg_gui_file_picker(const char *title, const char *path, bool (*validator)(const char *path), bool none_option);
134143
char *rg_gui_input_str(const char *title, const char *message, const char *default_value);
144+
int rg_gui_input_char(const rg_keyboard_layout_t *map);
135145

136146
int rg_gui_savestate_menu(const char *title, const char *rom_path);
137147
void rg_gui_options_menu(void);

components/retro-go/rg_input.c

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -431,60 +431,3 @@ const char *rg_input_get_key_mapping(rg_key_t key)
431431
return "PHYSICAL";
432432
return NULL;
433433
}
434-
435-
const rg_keyboard_layout_t virtual_map1 = {
436-
.layout = "0123456789"
437-
"ABCDEFGHIJ"
438-
"KLMNOPQRST"
439-
"UVWXYZ ,. ",
440-
.columns = 10,
441-
.rows = 4,
442-
};
443-
444-
int rg_input_read_keyboard(const rg_keyboard_layout_t *map)
445-
{
446-
int cursor = -1;
447-
int count = map->columns * map->rows;
448-
449-
if (!map)
450-
map = &virtual_map1;
451-
452-
rg_input_wait_for_key(RG_KEY_ALL, false, 1000);
453-
454-
while (1)
455-
{
456-
uint32_t joystick = rg_input_read_gamepad();
457-
int prev_cursor = cursor;
458-
459-
if (joystick & RG_KEY_A)
460-
return map->layout[cursor];
461-
if (joystick & RG_KEY_B)
462-
break;
463-
464-
if (joystick & RG_KEY_LEFT)
465-
cursor--;
466-
if (joystick & RG_KEY_RIGHT)
467-
cursor++;
468-
if (joystick & RG_KEY_UP)
469-
cursor -= map->columns;
470-
if (joystick & RG_KEY_DOWN)
471-
cursor += map->columns;
472-
473-
if (cursor > count - 1)
474-
cursor = prev_cursor;
475-
else if (cursor < 0)
476-
cursor = prev_cursor;
477-
478-
cursor = RG_MIN(RG_MAX(cursor, 0), count - 1);
479-
480-
if (cursor != prev_cursor)
481-
rg_gui_draw_virtual_keyboard(RG_GUI_CENTER, RG_GUI_BOTTOM, map, cursor, false);
482-
483-
rg_input_wait_for_key(RG_KEY_ALL, false, 500);
484-
rg_input_wait_for_key(RG_KEY_ANY, true, 500);
485-
486-
rg_system_tick(0);
487-
}
488-
489-
return -1;
490-
}

components/retro-go/rg_input.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,23 +88,14 @@ typedef struct
8888
bool charging;
8989
} rg_battery_t;
9090

91-
typedef struct
92-
{
93-
const char *layout;
94-
size_t columns;
95-
size_t rows;
96-
bool is_upper;
97-
bool is_symbols;
98-
} rg_keyboard_layout_t;
99-
10091
void rg_input_init(void);
10192
void rg_input_deinit(void);
10293
bool rg_input_key_is_pressed(rg_key_t mask);
10394
bool rg_input_wait_for_key(rg_key_t mask, bool pressed, int timeout_ms);
10495
const char *rg_input_get_key_name(rg_key_t key);
10596
const char *rg_input_get_key_mapping(rg_key_t key);
10697
uint32_t rg_input_read_gamepad(void);
107-
int rg_input_read_keyboard(const rg_keyboard_layout_t *map);
98+
int rg_input_read_keyboard(void);
10899
rg_battery_t rg_input_read_battery(void);
109100
bool rg_input_read_gamepad_raw(uint32_t *out);
110101
bool rg_input_read_keyboard_raw(int *out);

retro-core/main/main_sms.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ void sms_main(void)
216216
{
217217
rg_gui_draw_text(RG_GUI_CENTER, RG_GUI_CENTER, 0, _("To start, try: 1 or * or #"), C_YELLOW, C_BLACK, RG_TEXT_BIGGER);
218218
rg_audio_set_mute(true);
219-
int key = rg_input_read_keyboard(&coleco_keyboard);
219+
int key = rg_gui_input_char(&coleco_keyboard);
220220
rg_audio_set_mute(false);
221221

222222
if (key >= '0' && key <= '9')

0 commit comments

Comments
 (0)