From 10f90e30e26ae7d2f3d7b66cafeaa5bea4d3b8a2 Mon Sep 17 00:00:00 2001 From: Zachary Levy Date: Mon, 29 Jun 2026 19:04:57 +0000 Subject: [PATCH] Added bound helper (#40) Co-authored-by: Zachary Levy Reviewed-on: https://git.bfpower.io/BFPOWER/levlib/pulls/40 --- draw/draw.odin | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/draw/draw.odin b/draw/draw.odin index 01e9652..ff15180 100644 --- a/draw/draw.odin +++ b/draw/draw.odin @@ -857,6 +857,15 @@ needs_transform :: #force_inline proc(origin: Vec2, rotation: f32) -> bool { // ----- Anchors ------------ // --------------------------------------------------------------------------------------------------------------------- +// Translate `local` — a point relative to `bounds`'s top-left — into `bounds`'s own coordinate +// space by offsetting it by the rectangle's origin. Unlike the anchor helpers above (which +// return size-relative offsets and ignore `bounds.x`/`bounds.y`), this uses the rectangle's +// position. Handy for drawing inside a sub-region whose rect you were handed — e.g. the +// `bounds` passed to a `Custom_Draw` callback: `local_to_bounds(bounds, {cx, cy})`. +bound :: #force_inline proc(bounds: Rectangle, local: Vec2) -> Vec2 { + return {bounds.x + local.x, bounds.y + local.y} +} + // Return Vec2 pixel offsets for use as the `origin` parameter of draw calls. // Composable with normal vector +/- arithmetic. //