Commit: f31a43e859a02b9598acb09ff3f59a4327c76a09
Parent: c099e818540b0a0fe2efee4db39b7e027eb1590a
Author: Randy Palamar
Date: Wed, 12 Jun 2024 19:35:00 -0600
add animation to the stack and set some defaults
Diffstat:
2 files changed, 42 insertions(+), 13 deletions(-)
diff --git a/colourpicker.c b/colourpicker.c
@@ -12,14 +12,18 @@ static const char *mode_labels[CPM_LAST][4] = {
static f32
move_towards_f32(f32 current, f32 target, f32 delta)
{
+ f32 result;
f32 remaining = target - current;
- if (target < current)
- delta *= -1;
-
if (ABS(remaining) < ABS(delta))
return target;
- return current + delta;
+
+ if (target < current)
+ result = current - delta;
+ else
+ result = current + delta;
+
+ return result;
}
static v2
@@ -355,13 +359,15 @@ do_colour_stack(ColourPickerCtx *ctx, Rect sa, f32 dt)
r.pos.x += sa.size.w * 0.15;
r.pos.y += sa.size.h * 0.06;
+ static f32 stack_scales[ARRAY_COUNT(ctx->colour_stack.items)] = { 1, 1, 1, 1, 1 };
+ f32 stack_scale_target = 1.2f;
+ f32 stack_scale_delta = (stack_scale_target - 1) * 8 * dt;
for (u32 i = 0; i < 5; i++) {
i32 cidx = (ctx->colour_stack.widx + i) % ARRAY_COUNT(ctx->colour_stack.items);
v4 colour = ctx->colour_stack.items[cidx];
- DrawRectangleRounded(r.rr, 1, 0, ColorFromNormalized(colour.rv));
- DrawRectangleRoundedLinesEx(r.rr, 1, 0, 3.0, Fade(BLACK, 0.8));
- if (CheckCollisionPointRec(mouse.rv, r.rr) &&
- IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
+
+ b32 stack_collides = CheckCollisionPointRec(mouse.rv, r.rr);
+ if (stack_collides && IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
if (ctx->mode == CPM_HSV) {
ctx->colour = rgb_to_hsv(colour);
ctx->flags |= CPF_REFILL_TEXTURE;
@@ -370,6 +376,21 @@ do_colour_stack(ColourPickerCtx *ctx, Rect sa, f32 dt)
}
}
+ stack_scales[cidx] = move_towards_f32(stack_scales[cidx],
+ stack_collides? stack_scale_target : 1,
+ stack_scale_delta);
+
+ f32 scale = stack_scales[cidx];
+ Rect draw_rect = {
+ .pos = {
+ .x = r.pos.x - (scale - 1) * r.size.w / 2,
+ .y = r.pos.y - (scale - 1) * r.size.h / 2,
+ },
+ .size = { .x = r.size.w * scale, .y = r.size.h * scale },
+ };
+ DrawRectangleRounded(draw_rect.rr, 1, 0, ColorFromNormalized(colour.rv));
+ DrawRectangleRoundedLinesEx(draw_rect.rr, 1, 0, 3.0, Fade(BLACK, 0.8));
+
r.pos.y += sa.size.h * 0.16;
}
@@ -393,11 +414,11 @@ do_colour_stack(ColourPickerCtx *ctx, Rect sa, f32 dt)
.y = center.y - 0.3 * r.size.h + y_shift,
};
v2 t_left = {
- .x = center.x - 0.3 * r.size.w,
+ .x = center.x - 0.3 * r.size.w - 0.75 * y_shift,
.y = center.y + 0.3 * r.size.h,
};
v2 t_right = {
- .x = center.x + 0.3 * r.size.w,
+ .x = center.x + 0.3 * r.size.w + 0.75 * y_shift,
.y = center.y + 0.3 * r.size.h,
};
diff --git a/main.c b/main.c
@@ -73,12 +73,20 @@ main(void)
{
ColourPickerCtx ctx = {0};
ctx.window_size = (uv2){.w = 720, .h = 960};
- ctx.bg = (Color){ .r = 0x26, .g = 0x1e, .b = 0x22, .a = 0xff };
- ctx.fg = (Color){ .r = 0xea, .g = 0xe1, .b = 0xb4, .a = 0xff };
- ctx.colour = (v4){ .r = 0.53, .g = 0.82, .b = 0.59, .a = 1.0 };
ctx.mode = CPM_HSV;
ctx.flags |= CPF_REFILL_TEXTURE;
+ ctx.colour = (v4){ .r = 0.53, .g = 0.82, .b = 0.59, .a = 1.0 };
+
+ ctx.bg = (Color){ .r = 0x26, .g = 0x1e, .b = 0x22, .a = 0xff };
+ ctx.fg = (Color){ .r = 0xea, .g = 0xe1, .b = 0xb4, .a = 0xff };
+
+ ctx.colour_stack.items[0] = (v4){ .r = 0.04, .g = 0.04, .b = 0.04, .a = 1.00 };
+ ctx.colour_stack.items[1] = (v4){ .r = 0.92, .g = 0.88, .b = 0.78, .a = 1.00 };
+ ctx.colour_stack.items[2] = (v4){ .r = 0.59, .g = 0.11, .b = 0.25, .a = 1.00 };
+ ctx.colour_stack.items[3] = (v4){ .r = 0.11, .g = 0.59, .b = 0.36, .a = 1.00 };
+ ctx.colour_stack.items[4] = (v4){ .r = 0.14, .g = 0.29, .b = 0.72, .a = 1.00 };
+
#ifndef _DEBUG
SetTraceLogLevel(LOG_ERROR);
#endif