Commit: 5496a233e7321c94813340162657dd1fad91fe2a
Parent: 707b5858b91d2d539b0bb5f6edc71ccf68a91c1c
Author: Randy Palamar
Date: Tue, 23 Jul 2024 10:48:40 -0600
change ui colours to be defines
There isn't any reason for these to be changed at runtime.
Diffstat:
4 files changed, 31 insertions(+), 34 deletions(-)
diff --git a/beamformer.c b/beamformer.c
@@ -214,6 +214,13 @@ draw_settings_ui(BeamformerCtx *ctx, Arena arena, f32 dt, Rect r, v2 mouse)
{ "Dynamic Range:", " [dB]", &ctx->fsctx.db, 1, 1 },
};
+ static v4 colours[] = {
+ FG_COLOUR, FG_COLOUR, FG_COLOUR, FG_COLOUR,
+ FG_COLOUR, FG_COLOUR, FG_COLOUR, FG_COLOUR,
+ };
+ static_assert(ARRAY_COUNT(colours) == ARRAY_COUNT(listings),
+ "draw_settings_ui: colours array count must match listings array count");
+
struct { f32 min, max; } limits[] = {
{0},
{0, 100e6},
@@ -225,16 +232,10 @@ draw_settings_ui(BeamformerCtx *ctx, Arena arena, f32 dt, Rect r, v2 mouse)
{-120, 0},
};
- static b32 init = 1;
- static v4 colours[ARRAY_COUNT(listings)];
+
f32 scale = 6;
v4 scaled_dt = (v4){.x = scale * dt, .y = scale * dt, .z = scale * dt, .w = scale * dt};
- v4 delta = scaled_sub_v4(ctx->fg, ctx->hovered_colour, scaled_dt);
- if (init) {
- for (i32 i = 0; i < ARRAY_COUNT(colours); i++)
- colours[i] = ctx->fg;
- init = 0;
- }
+ v4 delta = scaled_sub_v4(FG_COLOUR, HOVERED_COLOUR, scaled_dt);
static char focus_buf[64];
static i32 focus_buf_curs = 0;
@@ -252,7 +253,7 @@ draw_settings_ui(BeamformerCtx *ctx, Arena arena, f32 dt, Rect r, v2 mouse)
for (i32 i = 0; i < ARRAY_COUNT(listings); i++) {
struct listing *l = listings + i;
DrawTextEx(ctx->font, l->prefix, pos.rl, ctx->font_size, ctx->font_spacing,
- colour_from_normalized(ctx->fg));
+ colour_from_normalized(FG_COLOUR));
if (i == focused_idx) snprintf((char *)txt.data, txt.len, "%s", focus_buf);
else snprintf((char *)txt.data, txt.len, "%0.02f", *l->data * l->data_scale);
@@ -276,21 +277,17 @@ draw_settings_ui(BeamformerCtx *ctx, Arena arena, f32 dt, Rect r, v2 mouse)
}
}
- Color tcol;
if (i == overlap_idx)
- colours[i] = move_towards_v4(colours[i], ctx->hovered_colour, delta);
+ colours[i] = move_towards_v4(colours[i], HOVERED_COLOUR, delta);
else
- colours[i] = move_towards_v4(colours[i], ctx->fg, delta);
-
- if (i == focused_idx) tcol = colour_from_normalized(ctx->focused_colour);
- else tcol = colour_from_normalized(colours[i]);
+ colours[i] = move_towards_v4(colours[i], FG_COLOUR, delta);
DrawTextEx(ctx->font, (char *)txt.data, rpos.rl, ctx->font_size,
- ctx->font_spacing, tcol);
+ ctx->font_spacing, colour_from_normalized(colours[i]));
rpos.x += txt_s.x;
DrawTextEx(ctx->font, l->suffix, rpos.rl, ctx->font_size, ctx->font_spacing,
- colour_from_normalized(ctx->fg));
+ colour_from_normalized(FG_COLOUR));
pos.y += txt_s.y + line_pad;
}
@@ -360,7 +357,7 @@ draw_debug_overlay(BeamformerCtx *ctx, Arena arena, f32 dt)
/* NOTE: Partial Tranfers */
{
DrawTextEx(ctx->font, (char *)partial_txt.data, pos.rl, fontsize, fontspace,
- colour_from_normalized(ctx->fg));
+ colour_from_normalized(FG_COLOUR));
pos.y += partial_fs.y;
}
@@ -458,7 +455,7 @@ do_beamformer(BeamformerCtx *ctx, Arena arena)
/* NOTE: Draw UI */
BeginDrawing();
- ClearBackground(colour_from_normalized(ctx->bg));
+ ClearBackground(colour_from_normalized(BG_COLOUR));
Texture *output = &ctx->fsctx.output.texture;
@@ -528,10 +525,10 @@ do_beamformer(BeamformerCtx *ctx, Arena arena)
static v4 txt_colour = (v4){.a = 1.0};
f32 scale = 6;
v4 scaled_dt = (v4){.x = scale * dt, .y = scale * dt, .z = scale * dt, .w = scale * dt};
- v4 delta = scaled_sub_v4(ctx->fg, ctx->hovered_colour, scaled_dt);
+ v4 delta = scaled_sub_v4(FG_COLOUR, HOVERED_COLOUR, scaled_dt);
if (CheckCollisionPointRec(mouse.rl, tick_rect.rl)) {
- txt_colour = move_towards_v4(txt_colour, ctx->hovered_colour, delta);
+ txt_colour = move_towards_v4(txt_colour, HOVERED_COLOUR, delta);
f32 size_delta = GetMouseWheelMove() * 0.5e-3;
/* TODO: smooth scroll this? */
bp->output_min_xz.x -= size_delta;
@@ -541,14 +538,14 @@ do_beamformer(BeamformerCtx *ctx, Arena arena)
ctx->params->upload = 1;
}
} else {
- txt_colour = move_towards_v4(txt_colour, ctx->fg, delta);
+ txt_colour = move_towards_v4(txt_colour, FG_COLOUR, delta);
}
f32 x_mm = bp->output_min_xz.x * 1e3;
f32 x_mm_inc = x_inc * output_dim.x * 1e3 / vr.size.w;
for (u32 i = 0 ; i < line_count.x; i++) {
- DrawLineEx(start_pos.rl, end_pos.rl, 3, colour_from_normalized(ctx->fg));
+ DrawLineEx(start_pos.rl, end_pos.rl, 3, colour_from_normalized(FG_COLOUR));
snprintf((char *)txt.data, txt.len, "%+0.01f mm", x_mm);
DrawTextPro(ctx->font, (char *)txt.data, txt_pos.rl, (Vector2){0},
90, ctx->font_size, ctx->font_spacing,
@@ -579,10 +576,10 @@ do_beamformer(BeamformerCtx *ctx, Arena arena)
static v4 txt_colour = (v4){.a = 1.0};
f32 scale = 6;
v4 scaled_dt = (v4){.x = scale * dt, .y = scale * dt, .z = scale * dt, .w = scale * dt};
- v4 delta = scaled_sub_v4(ctx->fg, ctx->hovered_colour, scaled_dt);
+ v4 delta = scaled_sub_v4(FG_COLOUR, HOVERED_COLOUR, scaled_dt);
if (CheckCollisionPointRec(mouse.rl, tick_rect.rl)) {
- txt_colour = move_towards_v4(txt_colour, ctx->hovered_colour, delta);
+ txt_colour = move_towards_v4(txt_colour, HOVERED_COLOUR, delta);
f32 size_delta = GetMouseWheelMove() * 0.5e-3;
/* TODO: smooth scroll this? */
bp->output_max_xz.y += size_delta;
@@ -591,14 +588,14 @@ do_beamformer(BeamformerCtx *ctx, Arena arena)
ctx->params->upload = 1;
}
} else {
- txt_colour = move_towards_v4(txt_colour, ctx->fg, delta);
+ txt_colour = move_towards_v4(txt_colour, FG_COLOUR, delta);
}
f32 y_mm = bp->output_min_xz.y * 1e3;
f32 y_mm_inc = y_inc * output_dim.y * 1e3 / vr.size.h;
for (u32 i = 0 ; i < line_count.y; i++) {
- DrawLineEx(start_pos.rl, end_pos.rl, 3, colour_from_normalized(ctx->fg));
+ DrawLineEx(start_pos.rl, end_pos.rl, 3, colour_from_normalized(FG_COLOUR));
snprintf((char *)txt.data, txt.len, "%0.01f mm", y_mm);
DrawTextEx(ctx->font, (char *)txt.data, txt_pos.rl,
ctx->font_size, ctx->font_spacing,
diff --git a/beamformer.h b/beamformer.h
@@ -10,6 +10,11 @@
#include "util.h"
+#define BG_COLOUR (v4){.r = 0.15, .g = 0.12, .b = 0.13, .a = 1.0}
+#define FG_COLOUR (v4){.r = 0.92, .g = 0.88, .b = 0.78, .a = 1.0}
+#define FOCUSED_COLOUR (v4){.r = 0.86, .g = 0.28, .b = 0.21, .a = 1.0}
+#define HOVERED_COLOUR (v4){.r = 0.11, .g = 0.50, .b = 0.59, .a = 1.0}
+
typedef union {
struct { f32 x, y; };
struct { f32 w, h; };
@@ -100,8 +105,6 @@ typedef struct {
u32 flags;
/* UI Theming */
- v4 bg, fg;
- v4 focused_colour, hovered_colour;
Font font;
u32 font_size;
u32 font_spacing;
diff --git a/main.c b/main.c
@@ -150,11 +150,6 @@ main(void)
SetConfigFlags(FLAG_VSYNC_HINT|FLAG_WINDOW_RESIZABLE);
InitWindow(ctx.window_size.w, ctx.window_size.h, "OGL Beamformer");
- ctx.bg = (v4){.r = 0.15, .g = 0.12, .b = 0.13, .a = 1.0};
- ctx.fg = (v4){.r = 0.92, .g = 0.88, .b = 0.78, .a = 1.0};
- ctx.focused_colour = (v4){.r = 0.86, .g = 0.28, .b = 0.21, .a = 1.0};
- ctx.hovered_colour = (v4){.r = 0.11, .g = 0.50, .b = 0.59, .a = 1.0};
-
ctx.font_size = 32;
ctx.font_spacing = 0;
ctx.font = GetFontDefault();
diff --git a/util.h b/util.h
@@ -13,6 +13,8 @@
#define DEBUG_EXPORT static
#endif
+#define static_assert _Static_assert
+
#define ARRAY_COUNT(a) (sizeof(a) / sizeof(*a))
#define ABS(x) ((x) < 0 ? (-x) : (x))
#define CLAMP(x, a, b) ((x) = (x) < (a) ? (a) : (x) > (b) ? (b) : (x))