Skip to content

Commit e845c74

Browse files
committed
rg_gui: rg_gui_draw_dialog now returns a rect
This will be needed to preserve size between calls to it
1 parent 4569d36 commit e845c74

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

components/retro-go/rg_gui.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ static size_t get_dialog_items_count(const rg_gui_option_t *options)
661661
return opt - options;
662662
}
663663

664-
void rg_gui_draw_dialog(const char *title, const rg_gui_option_t *options, size_t options_count, int sel)
664+
rg_rect_t rg_gui_draw_dialog(const char *title, const rg_gui_option_t *options, size_t options_count, int sel) // const rg_rect_t *rect,
665665
{
666666
RG_ASSERT_ARG(options || options_count == 0);
667667

@@ -674,6 +674,7 @@ void rg_gui_draw_dialog(const char *title, const rg_gui_option_t *options, size_
674674
const int row_padding_x = 8;
675675
const int max_inner_width = max_box_width - sep_width - (row_padding_x + box_padding) * 2;
676676

677+
int box_x, box_y;
677678
int box_width = box_padding * 2;
678679
int box_height = box_padding * 2 + (title ? font_height + 6 : 0);
679680
int inner_width = TEXT_RECT(title, 0).width;
@@ -717,9 +718,8 @@ void rg_gui_draw_dialog(const char *title, const rg_gui_option_t *options, size_
717718
col2_width = inner_width - col1_width - sep_width;
718719
box_width += inner_width + row_padding_x * 2;
719720
box_height = RG_MIN(box_height, max_box_height);
720-
721-
const int box_x = (gui.screen_width - box_width) / 2;
722-
const int box_y = (gui.screen_height - box_height) / 2;
721+
box_x = (gui.screen_width - box_width) / 2;
722+
box_y = (gui.screen_height - box_height) / 2;
723723

724724
int x = box_x + box_padding;
725725
int y = box_y + box_padding;
@@ -804,9 +804,14 @@ void rg_gui_draw_dialog(const char *title, const rg_gui_option_t *options, size_
804804
rg_gui_draw_rect(box_x, y, box_width, (box_y + box_height) - y, 0, 0, gui.style.box_background);
805805
}
806806

807+
// Draw box border
807808
rg_gui_draw_rect(box_x, box_y, box_width, box_height, box_padding, gui.style.box_background, C_NONE);
808809
rg_gui_draw_rect(box_x - 1, box_y - 1, box_width + 2, box_height + 2, 1, gui.style.box_border, C_NONE);
809810

811+
// Draw box shadow
812+
// rg_gui_draw_rect(box_x + box_width + 4, box_y + box_height, box_width, 4, 0, C_NONE, gui.style.shadow); // Bottom
813+
// rg_gui_draw_rect(box_x + box_width, box_y + 4, 4, box_height, 0, C_NONE, gui.style.shadow); // left
814+
810815
// Basic scroll indicators are overlayed at the end...
811816
if (list_top_i > 0)
812817
{
@@ -816,7 +821,6 @@ void rg_gui_draw_dialog(const char *title, const rg_gui_option_t *options, size_
816821
rg_gui_draw_rect(x + 1, y - 2, 4, 2, 0, 0, gui.style.scrollbar);
817822
rg_gui_draw_rect(x + 2, y - 4, 2, 2, 0, 0, gui.style.scrollbar);
818823
}
819-
820824
if (list_end_i + 1 < options_count)
821825
{
822826
int x = box_x + box_width - 10;
@@ -825,9 +829,11 @@ void rg_gui_draw_dialog(const char *title, const rg_gui_option_t *options, size_
825829
rg_gui_draw_rect(x + 1, y - 2, 4, 2, 0, 0, gui.style.scrollbar);
826830
rg_gui_draw_rect(x + 2, y - 0, 2, 2, 0, 0, gui.style.scrollbar);
827831
}
832+
833+
return (rg_rect_t){box_x, box_y, box_width, box_height};
828834
}
829835

830-
void rg_gui_draw_message(const char *format, ...)
836+
rg_rect_t rg_gui_draw_message(const char *format, ...) // const rg_rect_t *rect,
831837
{
832838
RG_ASSERT_ARG(format);
833839

@@ -841,7 +847,7 @@ void rg_gui_draw_message(const char *format, ...)
841847
RG_DIALOG_END,
842848
};
843849
// FIXME: Should rg_display_force_redraw() be called? Before? After? Both?
844-
rg_gui_draw_dialog(NULL, options, 1, 0);
850+
return rg_gui_draw_dialog(NULL, options, 1, 0);
845851
}
846852

847853
intptr_t rg_gui_dialog(const char *title, const rg_gui_option_t *options_const, int selected_index)
@@ -2153,7 +2159,7 @@ void rg_gui_debug_menu(void)
21532159
snprintf(heap_free, 20, "%d+%d", stats.freeMemoryInt, stats.freeMemoryExt);
21542160
snprintf(block_free, 20, "%d+%d", stats.freeBlockInt, stats.freeBlockExt);
21552161
snprintf(app_name, 32, "%s", rg_system_get_app()->name);
2156-
snprintf(uptime, 20, "%ds", (int)(rg_system_timer() / 1000000));
2162+
snprintf(uptime, 20, "%ds", stats.uptime);
21572163
snprintf(overclock, 20, "%d (%dMhz)", rg_system_get_overclock(), rg_system_get_cpu_speed());
21582164

21592165
rg_battery_t battery;

components/retro-go/rg_gui.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,17 +117,17 @@ void rg_gui_copy_buffer(int left, int top, int width, int height, int stride, co
117117

118118
rg_rect_t rg_gui_draw_text(int x_pos, int y_pos, int width, const char *text, // const rg_font_t *font,
119119
rg_color_t color_fg, rg_color_t color_bg, uint32_t flags);
120+
rg_rect_t rg_gui_draw_dialog(const char *title, const rg_gui_option_t *options, size_t options_count, int sel);
121+
rg_rect_t rg_gui_draw_message(const char *format, ...);
120122
void rg_gui_draw_rect(int x_pos, int y_pos, int width, int height, int border_size,
121123
rg_color_t border_color, rg_color_t fill_color);
122-
void rg_gui_draw_icons(void);
123-
void rg_gui_draw_dialog(const char *title, const rg_gui_option_t *options, size_t options_count, int sel);
124124
void rg_gui_draw_image(int x_pos, int y_pos, int width, int height, bool resample, const rg_image_t *img);
125+
void rg_gui_draw_icons(void);
125126
void rg_gui_draw_hourglass(void); // This should be moved to system or display...
126127
void rg_gui_draw_status_bars(void);
127128
void rg_gui_draw_virtual_keyboard(int x_pos, int y_pos, const rg_keyboard_layout_t *map, int cursor_pos, bool partial_redraw);
128129
void rg_gui_draw_input_screen(const char *title, const char *message, const char *input_buffer,
129130
const rg_keyboard_layout_t *layout_ptr, int cursor_pos, bool partial_redraw);
130-
void rg_gui_draw_message(const char *format, ...);
131131

132132
intptr_t rg_gui_dialog(const char *title, const rg_gui_option_t *options, int selected_index);
133133
bool rg_gui_confirm(const char *title, const char *message, bool default_yes);

0 commit comments

Comments
 (0)