colourpicker

Simple Colour Picker written in C
git clone anongit@rnpnr.xyz:colourpicker.git
Log | Files | Refs | Feed | Submodules | README | LICENSE

Commit: 4538824e7f82b74c034871c95789037be6b20193
Parent: 07a3b88bd7910e9ed110c532909224c51e407e50
Author: Randy Palamar
Date:   Sun,  9 Jun 2024 16:52:04 -0600

only display hex value in RGB

Having a hex value in HSV is not really useful.

Diffstat:
Mcolourpicker.c | 14++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/colourpicker.c b/colourpicker.c @@ -296,6 +296,8 @@ do_status_bar(ColourPickerCtx *ctx, Rect r, f32 dt) u32 r, g, b, a; sscanf(new, "%02x%02x%02x%02x", &r, &g, &b, &a); ctx->colour.rv = ColorNormalize((Color){ .r = r, .g = g, .b = b, .a = a }); + if (ctx->mode == CPM_HSV) + ctx->colour = rgb_to_hsv(ctx->colour); } static f32 scale_hex = 1.0; @@ -303,8 +305,12 @@ do_status_bar(ColourPickerCtx *ctx, Rect r, f32 dt) f32 scale_delta = (scale_target - 1.0) * 8 * dt; scale_hex = move_towards_f32(scale_hex, hex_collides? scale_target : 1.0, scale_delta); - Color hc = ColorFromNormalized(ctx->colour.rv); - const char *hex = TextFormat("%02x%02x%02x%02x", hc.r, hc.g, hc.b, hc.a); + Color hc; + if (ctx->mode == CPM_HSV) + hc = ColorFromNormalized(hsv_to_rgb(ctx->colour).rv); + else + hc = ColorFromNormalized(ctx->colour.rv); + const char *hex = TextFormat("%02x%02x%02x%02x", hc.r, hc.g, hc.b, hc.a); v2 fpos = left_align_text_in_rect(label_r, label, ctx->font, ctx->font_size); DrawTextEx(ctx->font, label, fpos.rv, ctx->font_size, 0, ctx->fg); @@ -343,8 +349,8 @@ do_colour_picker(ColourPickerCtx *ctx) { v4 vcolour = ctx->mode == CPM_HSV ? hsv_to_rgb(ctx->colour) : ctx->colour; Color colour = ColorFromNormalized(vcolour.rv); - v2 cc = { .x = (f32)ws.w / 2, .y = (f32)ws.h / 4 }; - DrawCircleSector(cc.rv, 0.6 * cc.x, 0, 360, 69, RED); + v2 cc = { .x = (f32)ws.w / 2, .y = (f32)ws.h / 4 }; + DrawRing(cc.rv, 0.58 * cc.x, 0.6 * cc.x, 0, 360, 69, Fade(BLACK, 0.5)); DrawCircleSector(cc.rv, 0.58 * cc.x, 0, 360, 69, colour); }