ogl_beamforming

Ultrasound Beamforming Implemented with OpenGL
git clone anongit@rnpnr.xyz:ogl_beamforming.git
Log | Files | Refs | Feed | Submodules | LICENSE

Commit: 9792bfe783355418e55f9b520f5239394fd7bc72
Parent: c36035ca080200e6e8e2a1bd0b03160b05390d44
Author: Randy Palamar
Date:   Tue, 14 Jan 2025 20:23:44 -0700

ui: overlay mouse coordinates when hovering

closes: #12

Diffstat:
Mui.c | 23+++++++++++++++++++----
Mutil.c | 10++++++++++
2 files changed, 29 insertions(+), 4 deletions(-)

diff --git a/ui.c b/ui.c @@ -272,6 +272,10 @@ draw_display_overlay(BeamformerCtx *ctx, Arena a, v2 mouse, Rect display_rect) do_scale_bar(ui, &buf, var, mouse, SB_AXIAL, (Rect){.pos = start_pos, .size = vr.size}, bp->output_max_coordinate.z * 1e3, bp->output_min_coordinate.z * 1e3, s8(" mm")); + v2 pixels_to_mm = output_dim; + pixels_to_mm.x /= vr.size.x * 1e-3; + pixels_to_mm.y /= vr.size.y * 1e-3; + if (CheckCollisionPointRec(mouse.rl, vr.rl)) { is->hot_state = IS_DISPLAY; is->hot.store = &ctx->fsctx.threshold; @@ -280,6 +284,21 @@ draw_display_overlay(BeamformerCtx *ctx, Arena a, v2 mouse, Rect display_rect) is->hot.flags = V_GEN_MIPMAPS; is->hot.display_scale = 1; is->hot.scroll_scale = 1; + + v2 relative_mouse = sub_v2(mouse, vr.pos); + v2 mm = mul_v2(relative_mouse, pixels_to_mm); + mm.x += 1e3 * bp->output_min_coordinate.x; + mm.y += 1e3 * bp->output_min_coordinate.z; + + buf.widx = 0; + stream_append_v2(&buf, mm); + v2 txt_s = measure_text(ui->small_font, stream_to_s8(&buf)); + v2 txt_p = { + .x = vr.pos.x + vr.size.w - txt_s.w - 4, + .y = vr.pos.y + vr.size.h - txt_s.h - 4, + }; + draw_text(ui->small_font, stream_to_s8(&buf), txt_p, 0, + colour_from_normalized(RULER_COLOUR)); } /* TODO(rnp): store converted ruler points instead of screen points */ @@ -290,10 +309,6 @@ draw_display_overlay(BeamformerCtx *ctx, Arena a, v2 mouse, Rect display_rect) Color colour = colour_from_normalized(RULER_COLOUR); - v2 pixels_to_mm = output_dim; - pixels_to_mm.x /= vr.size.x * 1e-3; - pixels_to_mm.y /= vr.size.y * 1e-3; - end_p = clamp_v2_rect(end_p, vr); v2 pixel_delta = sub_v2(ui->ruler_start_p, end_p); v2 mm_delta = mul_v2(pixels_to_mm, pixel_delta); diff --git a/util.c b/util.c @@ -221,6 +221,16 @@ stream_append_f64_e(Stream *s, f64 f) } static void +stream_append_v2(Stream *s, v2 v) +{ + stream_append_byte(s, '{'); + stream_append_f64(s, v.x, 100); + stream_append_s8(s, s8(", ")); + stream_append_f64(s, v.y, 100); + stream_append_byte(s, '}'); +} + +static void stream_append_variable(Stream *s, Variable *var) { switch (var->type) {