Skip to content

Commit

Permalink
rg_gui: Small optimization in rg_gui_draw_text
Browse files Browse the repository at this point in the history
If a glyph row has no pixel, there is no need to draw it because the buffer has already been filled with the bg color.
  • Loading branch information
ducalex committed Nov 20, 2024
1 parent 201baba commit d049045
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
20 changes: 14 additions & 6 deletions components/retro-go/rg_gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,11 @@ static uint16_t *get_draw_buffer(int width, int height, rg_color_t fill_color)
if (!gui.draw_buffer)
RG_PANIC("Failed to allocate draw buffer!");

for (size_t i = 0; i < pixels; ++i)
gui.draw_buffer[i] = fill_color;
if (fill_color != C_NONE)
{
for (size_t i = 0; i < pixels; ++i)
gui.draw_buffer[i] = fill_color;
}

return gui.draw_buffer;
}
Expand Down Expand Up @@ -185,6 +188,8 @@ rg_color_t rg_gui_get_theme_color(const char *section, const char *key, rg_color
return default_value;
if (strcmp(strval, "transparent") == 0)
return C_TRANSPARENT;
if (strcmp(strval, "none") == 0)
return C_NONE;
int intval = (int)strtol(strval, NULL, 0);
// It is better to specify colors as RGB565 to avoid data loss, but we also accept RGB888 for convenience
if (strlen(strval) == 8 && strval[0] == '0' && strval[1] == 'x')
Expand Down Expand Up @@ -438,9 +443,13 @@ rg_rect_t rg_gui_draw_text(int x_pos, int y_pos, int width, const char *text, //
{
for (int y = 0; y < font_height; y++)
{
uint16_t *output = &draw_buffer[(draw_width * (y + padding)) + x_offset];
for (int x = 0; x < width; x++)
output[x] = (bitmap[y] & (1 << x)) ? color_fg : color_bg;
uint32_t row = bitmap[y];
if (row != 0) // get_draw_buffer fills the bg color, nothing to do if row empty
{
uint16_t *output = &draw_buffer[(draw_width * (y + padding)) + x_offset];
for (int x = 0; x < width; x++)
output[x] = ((row >> x) & 1) ? color_fg : color_bg;
}
}
}

Expand Down Expand Up @@ -527,7 +536,6 @@ void rg_gui_draw_icons(void)

if (battery.present)
{

#ifdef RG_SCREEN_HAS_ROUND_CORNERS
right += 42; // This is to shift the battery icon a bit on the left
#else
Expand Down
8 changes: 4 additions & 4 deletions components/retro-go/rg_gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ void rg_gui_debug_menu(const rg_gui_option_t *extra_options);
/* -- µGUI COLORS -- */
/* -- Source: http://www.rapidtables.com/web/color/RGB_Color.htm -- */
/* -------------------------------------------------------------------------------- */
enum colors565
enum colors565 // rg_color_t
{
C_MAROON = 0x8000,
C_DARK_RED = 0x8800,
Expand Down Expand Up @@ -275,7 +275,7 @@ enum colors565
C_GAINSBORO = 0xDEDB,
C_WHITE_SMOKE = 0xF7BE,
C_WHITE = 0xFFFF,
// C_TRANSPARENT = -1,
C_TRANSPARENT = C_MAGENTA,
C_NONE = -1,

C_TRANSPARENT = C_MAGENTA, // -1,
C_NONE = -2,
};
12 changes: 6 additions & 6 deletions launcher/main/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ typedef enum {
} preview_mode_t;

typedef struct {
uint16_t background;
uint16_t foreground;
rg_color_t background;
rg_color_t foreground;
struct {
uint16_t standard_bg;
uint16_t standard_fg;
uint16_t selected_bg;
uint16_t selected_fg;
rg_color_t standard_bg;
rg_color_t standard_fg;
rg_color_t selected_bg;
rg_color_t selected_fg;
} list;
} theme_t;

Expand Down

0 comments on commit d049045

Please sign in to comment.