colourpicker

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

Commit: c0caa2043cc57cbd163bab98e69b663bcea8d7e1
Parent: 35e693e05eb7f81a07305bd528127cebeb11efc6
Author: Randy Palamar
Date:   Wed, 31 Jul 2024 20:13:12 -0600

make it possible to embed colourpicker in other applications

Diffstat:
Mcolourpicker.c | 26++++++++++++++------------
Mmain.c | 5+++--
Mutil.c | 7++++---
3 files changed, 21 insertions(+), 17 deletions(-)

diff --git a/colourpicker.c b/colourpicker.c @@ -1012,26 +1012,23 @@ do_picker_mode(ColourPickerCtx *ctx, v2 relative_origin) } DEBUG_EXPORT void -do_colour_picker(ColourPickerCtx *ctx) +do_colour_picker(ColourPickerCtx *ctx, f32 dt, Vector2 window_pos, Vector2 mouse_pos) { - ClearBackground(ctx->bg); - -#ifdef _DEBUG - DrawFPS(20, 20); -#endif - - ctx->dt = GetFrameTime(); - ctx->mouse_pos.rv = GetMousePosition(); + ctx->dt = dt; + ctx->mouse_pos.rv = mouse_pos; + ctx->window_pos.rv = window_pos; uv2 ws = ctx->window_size; + DrawRectangle(ctx->window_pos.x, ctx->window_pos.y, ws.w, ws.h, ctx->bg); + v2 pad = {.x = 0.05 * ws.w, .y = 0.05 * ws.h}; Rect upper = { - .pos = {.x = pad.x, .y = pad.y}, - .size = {.w = ws.w - 2 * pad.x, .h = ws.h * 0.6}, + .pos = {.x = ctx->window_pos.x + pad.x, .y = ctx->window_pos.y + pad.y}, + .size = {.w = ws.w - 2 * pad.x, .h = ws.h * 0.6}, }; Rect lower = { - .pos = {.x = pad.x, .y = pad.y + ws.h * 0.6}, + .pos = {.x = upper.pos.x, .y = upper.pos.y + ws.h * 0.6}, .size = {.w = ws.w - 2 * pad.x, .h = ws.h * 0.4 - 1 * pad.y}, }; @@ -1219,4 +1216,9 @@ do_colour_picker(ColourPickerCtx *ctx) btn_r.pos.y += 0.54 * mb.size.h; } } + +#ifdef _DEBUG + DrawFPS(20, 20); +#endif + } diff --git a/main.c b/main.c @@ -16,7 +16,7 @@ typedef struct timespec Filetime; static const char *libname = "./libcolourpicker.so"; static void *libhandle; -typedef void (do_colour_picker_fn)(ColourPickerCtx *); +typedef void (do_colour_picker_fn)(ColourPickerCtx *, f32 dt, Vector2 window_pos, Vector2 mouse); static do_colour_picker_fn *do_colour_picker; static Filetime @@ -160,7 +160,8 @@ main(i32 argc, char *argv[]) do_debug(); BeginDrawing(); - do_colour_picker(&ctx); + ClearBackground(ctx.bg); + do_colour_picker(&ctx, GetFrameTime(), (Vector2){0}, GetMousePosition()); EndDrawing(); } diff --git a/util.c b/util.c @@ -143,9 +143,12 @@ typedef struct { v4 colour, previous_colour; ColourStackState colour_stack; + uv2 window_size; + v2 window_pos; + v2 mouse_pos; + Font font; i32 font_size; - uv2 window_size; Color bg, fg; InputState is; @@ -159,8 +162,6 @@ typedef struct { f32 selection_hover_t[2]; v4 hover_colour; - v2 mouse_pos; - f32 dt; RenderTexture slider_texture;