From dec8e9006193908c9fb8fd32de2a9c15cdb05aaf Mon Sep 17 00:00:00 2001 From: Gwenhael Le Moine Date: Thu, 5 Sep 2024 13:06:39 +0200 Subject: [PATCH] add a channel to colors and add TRANSPARENT --- src/ui.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/ui_inner.h | 5 +++-- src/ui_sdl2.c | 6 +++--- 3 files changed, 64 insertions(+), 5 deletions(-) diff --git a/src/ui.c b/src/ui.c index a1297b6..231a581 100644 --- a/src/ui.c +++ b/src/ui.c @@ -147,6 +147,7 @@ color_t colors_sx[ NB_COLORS ] = { .r = 255, .g = 255, .b = 255, + .a = 255, .mono_rgb = 255, .gray_rgb = 255, }, @@ -155,6 +156,7 @@ color_t colors_sx[ NB_COLORS ] = { .r = 255, .g = 166, .b = 0, + .a = 255, .mono_rgb = 255, .gray_rgb = 230, }, @@ -163,6 +165,7 @@ color_t colors_sx[ NB_COLORS ] = { .r = 0, .g = 210, .b = 255, + .a = 255, .mono_rgb = 255, .gray_rgb = 169, }, @@ -171,6 +174,7 @@ color_t colors_sx[ NB_COLORS ] = { .r = 109, .g = 93, .b = 93, + .a = 255, .mono_rgb = 0, .gray_rgb = 91, }, @@ -179,6 +183,7 @@ color_t colors_sx[ NB_COLORS ] = { .r = 90, .g = 77, .b = 77, + .a = 255, .mono_rgb = 0, .gray_rgb = 81, }, @@ -187,6 +192,7 @@ color_t colors_sx[ NB_COLORS ] = { .r = 76, .g = 65, .b = 65, + .a = 255, .mono_rgb = 0, .gray_rgb = 69, }, @@ -195,6 +201,7 @@ color_t colors_sx[ NB_COLORS ] = { .r = 202, .g = 221, .b = 92, + .a = 255, .mono_rgb = 255, .gray_rgb = 205, }, @@ -203,6 +210,7 @@ color_t colors_sx[ NB_COLORS ] = { .r = 0, .g = 0, .b = 128, + .a = 255, .mono_rgb = 0, .gray_rgb = 20, }, @@ -211,6 +219,7 @@ color_t colors_sx[ NB_COLORS ] = { .r = 109, .g = 78, .b = 78, + .a = 255, .mono_rgb = 0, .gray_rgb = 88, }, @@ -219,6 +228,7 @@ color_t colors_sx[ NB_COLORS ] = { .r = 90, .g = 64, .b = 64, + .a = 255, .mono_rgb = 0, .gray_rgb = 73, }, @@ -227,6 +237,7 @@ color_t colors_sx[ NB_COLORS ] = { .r = 76, .g = 54, .b = 54, + .a = 255, .mono_rgb = 0, .gray_rgb = 60, }, @@ -235,6 +246,7 @@ color_t colors_sx[ NB_COLORS ] = { .r = 155, .g = 118, .b = 84, + .a = 255, .mono_rgb = 0, .gray_rgb = 124, }, @@ -243,6 +255,7 @@ color_t colors_sx[ NB_COLORS ] = { .r = 124, .g = 94, .b = 67, + .a = 255, .mono_rgb = 0, .gray_rgb = 99, }, @@ -251,6 +264,7 @@ color_t colors_sx[ NB_COLORS ] = { .r = 100, .g = 75, .b = 53, + .a = 255, .mono_rgb = 0, .gray_rgb = 79, }, @@ -259,6 +273,7 @@ color_t colors_sx[ NB_COLORS ] = { .r = 204, .g = 169, .b = 107, + .a = 255, .mono_rgb = 255, .gray_rgb = 172, }, @@ -267,6 +282,7 @@ color_t colors_sx[ NB_COLORS ] = { .r = 64, .g = 64, .b = 64, + .a = 255, .mono_rgb = 0, .gray_rgb = 65, }, @@ -275,6 +291,7 @@ color_t colors_sx[ NB_COLORS ] = { .r = 202, .g = 184, .b = 144, + .a = 255, .mono_rgb = 255, .gray_rgb = 185, }, @@ -283,6 +300,7 @@ color_t colors_sx[ NB_COLORS ] = { .r = 0, .g = 0, .b = 0, + .a = 255, .mono_rgb = 255, .gray_rgb = 0, }, @@ -291,6 +309,7 @@ color_t colors_sx[ NB_COLORS ] = { .r = 60, .g = 42, .b = 42, + .a = 255, .mono_rgb = 0, .gray_rgb = 48, }, @@ -299,6 +318,16 @@ color_t colors_sx[ NB_COLORS ] = { .r = 0, .g = 0, .b = 0, + .a = 255, + .mono_rgb = 0, + .gray_rgb = 0, + }, + { + .name = "transparent", + .r = 0, + .g = 0, + .b = 0, + .a = 0, .mono_rgb = 0, .gray_rgb = 0, }, @@ -310,6 +339,7 @@ color_t colors_gx[ NB_COLORS ] = { .r = 255, .g = 255, .b = 255, + .a = 255, .mono_rgb = 255, .gray_rgb = 255, }, @@ -318,6 +348,7 @@ color_t colors_gx[ NB_COLORS ] = { .r = 255, .g = 186, .b = 255, + .a = 255, .mono_rgb = 255, .gray_rgb = 220, }, @@ -326,6 +357,7 @@ color_t colors_gx[ NB_COLORS ] = { .r = 0, .g = 255, .b = 204, + .a = 255, .mono_rgb = 255, .gray_rgb = 169, }, @@ -334,6 +366,7 @@ color_t colors_gx[ NB_COLORS ] = { .r = 104, .g = 104, .b = 104, + .a = 255, .mono_rgb = 0, .gray_rgb = 104, }, @@ -342,6 +375,7 @@ color_t colors_gx[ NB_COLORS ] = { .r = 88, .g = 88, .b = 88, + .a = 255, .mono_rgb = 0, .gray_rgb = 88, }, @@ -350,6 +384,7 @@ color_t colors_gx[ NB_COLORS ] = { .r = 74, .g = 74, .b = 74, + .a = 255, .mono_rgb = 0, .gray_rgb = 74, }, @@ -358,6 +393,7 @@ color_t colors_gx[ NB_COLORS ] = { .r = 202, .g = 221, .b = 92, + .a = 255, .mono_rgb = 255, .gray_rgb = 205, }, @@ -366,6 +402,7 @@ color_t colors_gx[ NB_COLORS ] = { .r = 0, .g = 0, .b = 128, + .a = 255, .mono_rgb = 0, .gray_rgb = 20, }, @@ -374,6 +411,7 @@ color_t colors_gx[ NB_COLORS ] = { .r = 88, .g = 88, .b = 88, + .a = 255, .mono_rgb = 0, .gray_rgb = 88, }, @@ -382,6 +420,7 @@ color_t colors_gx[ NB_COLORS ] = { .r = 74, .g = 74, .b = 74, + .a = 255, .mono_rgb = 0, .gray_rgb = 74, }, @@ -390,6 +429,7 @@ color_t colors_gx[ NB_COLORS ] = { .r = 64, .g = 64, .b = 64, + .a = 255, .mono_rgb = 0, .gray_rgb = 64, }, @@ -398,6 +438,7 @@ color_t colors_gx[ NB_COLORS ] = { .r = 128, .g = 128, .b = 138, + .a = 255, .mono_rgb = 0, .gray_rgb = 128, }, @@ -406,6 +447,7 @@ color_t colors_gx[ NB_COLORS ] = { .r = 104, .g = 104, .b = 110, + .a = 255, .mono_rgb = 0, .gray_rgb = 104, }, @@ -414,6 +456,7 @@ color_t colors_gx[ NB_COLORS ] = { .r = 84, .g = 84, .b = 90, + .a = 255, .mono_rgb = 0, .gray_rgb = 84, }, @@ -422,6 +465,7 @@ color_t colors_gx[ NB_COLORS ] = { .r = 176, .g = 176, .b = 184, + .a = 255, .mono_rgb = 255, .gray_rgb = 176, }, @@ -430,6 +474,7 @@ color_t colors_gx[ NB_COLORS ] = { .r = 104, .g = 104, .b = 110, + .a = 255, .mono_rgb = 0, .gray_rgb = 104, }, @@ -438,6 +483,7 @@ color_t colors_gx[ NB_COLORS ] = { .r = 240, .g = 240, .b = 240, + .a = 255, .mono_rgb = 255, .gray_rgb = 240, }, @@ -446,6 +492,7 @@ color_t colors_gx[ NB_COLORS ] = { .r = 0, .g = 0, .b = 0, + .a = 255, .mono_rgb = 255, .gray_rgb = 0, }, @@ -454,6 +501,7 @@ color_t colors_gx[ NB_COLORS ] = { .r = 104, .g = 104, .b = 110, + .a = 255, .mono_rgb = 0, .gray_rgb = 104, }, @@ -462,6 +510,16 @@ color_t colors_gx[ NB_COLORS ] = { .r = 0, .g = 0, .b = 0, + .a = 255, + .mono_rgb = 0, + .gray_rgb = 0, + }, + { + .name = "transparent", + .r = 0, + .g = 0, + .b = 0, + .a = 0, .mono_rgb = 0, .gray_rgb = 0, }, diff --git a/src/ui_inner.h b/src/ui_inner.h index eaf2dda..7dc5a24 100644 --- a/src/ui_inner.h +++ b/src/ui_inner.h @@ -24,9 +24,10 @@ #define FRAME 17 #define UNDERLAY 18 #define BLACK 19 +#define TRANSPARENT 20 #define FIRST_COLOR WHITE -#define LAST_COLOR BLACK +#define LAST_COLOR TRANSPARENT #define NB_COLORS ( LAST_COLOR + 1 ) /***********/ @@ -39,7 +40,7 @@ typedef struct letter_t { typedef struct color_t { const char* name; - int r, g, b; + int r, g, b, a; int mono_rgb; int gray_rgb; } color_t; diff --git a/src/ui_sdl2.c b/src/ui_sdl2.c index e299a22..ac2f533 100644 --- a/src/ui_sdl2.c +++ b/src/ui_sdl2.c @@ -110,13 +110,13 @@ static SDL_Texture* bitmap_to_texture( unsigned int w, unsigned int h, unsigned static void __draw_pixel( int x, int y, int color ) { - SDL_SetRenderDrawColor( renderer, colors[ color ].r, colors[ color ].g, colors[ color ].b, 255 ); + SDL_SetRenderDrawColor( renderer, colors[ color ].r, colors[ color ].g, colors[ color ].b, colors[ color ].a ); SDL_RenderDrawPoint( renderer, x, y ); } static void __draw_line( int x1, int y1, int x2, int y2, int color ) { - SDL_SetRenderDrawColor( renderer, colors[ color ].r, colors[ color ].g, colors[ color ].b, 255 ); + SDL_SetRenderDrawColor( renderer, colors[ color ].r, colors[ color ].g, colors[ color ].b, colors[ color ].a ); SDL_RenderDrawLine( renderer, x1, y1, x2, y2 ); } @@ -128,7 +128,7 @@ static void __draw_rect( int x, int y, int w, int h, int color ) rect.w = w; rect.h = h; - SDL_SetRenderDrawColor( renderer, colors[ color ].r, colors[ color ].g, colors[ color ].b, 255 ); + SDL_SetRenderDrawColor( renderer, colors[ color ].r, colors[ color ].g, colors[ color ].b, colors[ color ].a ); SDL_RenderFillRect( renderer, &rect ); }