Skip to content

Commit efb7516

Browse files
committed
rg_gui: Removed old rg_gui_draw_keyboard, extracted the new rg_gui_draw_virtual_keyboard to replace it
1 parent dc9d274 commit efb7516

3 files changed

Lines changed: 25 additions & 33 deletions

File tree

components/retro-go/rg_gui.c

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,7 @@ char *rg_gui_file_picker(const char *title, const char *path, bool (*validator)(
10461046
return filepath;
10471047
}
10481048

1049-
void rg_gui_draw_virtual_keyboard(const char *title, const char *message, const char *input_buffer,
1049+
void rg_gui_draw_input_screen(const char *title, const char *message, const char *input_buffer,
10501050
const rg_keyboard_layout_t *current_layout, int cursor_pos, bool partial_redraw)
10511051
{
10521052
const int key_width = 28;
@@ -1088,8 +1088,25 @@ void rg_gui_draw_virtual_keyboard(const char *title, const char *message, const
10881088
snprintf(text_buffer, sizeof(text_buffer), "%s%s", input_buffer, show_cursor ? "_" : " ");
10891089
rg_gui_draw_text(keyboard_x + 5, input_box_y + 5, keyboard_width - 10, text_buffer, C_BLACK, C_WHITE, 0);
10901090

1091-
// Draw keyboard container with same border style as dialog
1092-
rg_gui_draw_rect(keyboard_x - 2, keyboard_y - 2, keyboard_width + 4, keyboard_height + 4, 2, gui.style.box_border, C_NONE);
1091+
// Draw keyboard pad
1092+
rg_gui_draw_virtual_keyboard(keyboard_x, keyboard_y, current_layout, cursor_pos, true);
1093+
}
1094+
1095+
void rg_gui_draw_virtual_keyboard(int x_pos, int y_pos, const rg_keyboard_layout_t *current_layout, int cursor_pos, bool partial_redraw)
1096+
{
1097+
const int key_width = 28;
1098+
const int key_height = 20;
1099+
const int keyboard_width = current_layout->columns * key_width;
1100+
const int keyboard_height = current_layout->rows * key_height;
1101+
const int keyboard_x = get_horizontal_position(x_pos, keyboard_width);
1102+
const int keyboard_y = get_vertical_position(y_pos, keyboard_height);
1103+
1104+
if (!partial_redraw)
1105+
{
1106+
// Draw keyboard container with same border style as dialog
1107+
rg_gui_draw_rect(keyboard_x - 2, keyboard_y - 2, keyboard_width + 4, keyboard_height + 4, 2,
1108+
gui.style.box_border, gui.style.box_background);
1109+
}
10931110

10941111
// Draw keyboard keys
10951112
for (int row = 0; row < current_layout->rows; row++)
@@ -1270,7 +1287,7 @@ char *rg_gui_input_str(const char *title, const char *message, const char *defau
12701287

12711288
if (redraw)
12721289
{
1273-
rg_gui_draw_virtual_keyboard(title, message, input_buffer, current_layout, cursor_pos, redraws++ > 0);
1290+
rg_gui_draw_input_screen(title, message, input_buffer, current_layout, cursor_pos, redraws++ > 0);
12741291
redraw = false;
12751292
}
12761293

@@ -1287,31 +1304,6 @@ char *rg_gui_input_str(const char *title, const char *message, const char *defau
12871304
return input_length > 0 ? strdup(input_buffer) : NULL;
12881305
}
12891306

1290-
void rg_gui_draw_keyboard(const rg_keyboard_layout_t *map, size_t cursor)
1291-
{
1292-
RG_ASSERT_ARG(map);
1293-
1294-
int width = map->columns * 16 + 16;
1295-
int height = map->rows * 16 + 16;
1296-
1297-
int x_pos = (gui.screen_width - width) / 2;
1298-
int y_pos = (gui.screen_height - height);
1299-
1300-
char buf[2] = {0};
1301-
1302-
rg_gui_draw_rect(x_pos, y_pos, width, height, 2, gui.style.box_border, gui.style.box_background);
1303-
1304-
for (size_t i = 0; i < map->columns * map->rows; ++i)
1305-
{
1306-
int x = x_pos + 8 + (i % map->columns) * 16;
1307-
int y = y_pos + 8 + (i / map->columns) * 16;
1308-
if (!map->layout[i])
1309-
continue;
1310-
buf[0] = map->layout[i];
1311-
rg_gui_draw_text(x + 1, y + 1, 14, buf, C_BLACK, i == cursor ? C_CYAN : C_IVORY, RG_TEXT_ALIGN_CENTER);
1312-
}
1313-
}
1314-
13151307
static rg_gui_event_t volume_update_cb(rg_gui_option_t *option, rg_gui_event_t event)
13161308
{
13171309
int level = rg_audio_get_volume();

components/retro-go/rg_gui.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ void rg_gui_draw_dialog(const char *header, const rg_gui_option_t *options, int
122122
void rg_gui_draw_image(int x_pos, int y_pos, int width, int height, bool resample, const rg_image_t *img);
123123
void rg_gui_draw_hourglass(void); // This should be moved to system or display...
124124
void rg_gui_draw_status_bars(void);
125-
void rg_gui_draw_keyboard(const rg_keyboard_layout_t *map, size_t cursor);
126-
void rg_gui_draw_virtual_keyboard(const char *title, const char *message, const char *input_buffer,
127-
const rg_keyboard_layout_t *layout_ptr, int cursor_pos, bool partial_redraw);
125+
void rg_gui_draw_virtual_keyboard(int x_pos, int y_pos, const rg_keyboard_layout_t *map, int cursor_pos, bool partial_redraw);
126+
void rg_gui_draw_input_screen(const char *title, const char *message, const char *input_buffer,
127+
const rg_keyboard_layout_t *layout_ptr, int cursor_pos, bool partial_redraw);
128128
void rg_gui_draw_message(const char *format, ...);
129129

130130
intptr_t rg_gui_dialog(const char *title, const rg_gui_option_t *options, int selected_index);

components/retro-go/rg_input.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ int rg_input_read_keyboard(const rg_keyboard_layout_t *map)
478478
cursor = RG_MIN(RG_MAX(cursor, 0), count - 1);
479479

480480
if (cursor != prev_cursor)
481-
rg_gui_draw_keyboard(map, cursor);
481+
rg_gui_draw_virtual_keyboard(RG_GUI_CENTER, RG_GUI_BOTTOM, map, cursor, false);
482482

483483
rg_input_wait_for_key(RG_KEY_ALL, false, 500);
484484
rg_input_wait_for_key(RG_KEY_ANY, true, 500);

0 commit comments

Comments
 (0)