From 33e0b227a0491437bb8da3a955f9f1df87ced1b4 Mon Sep 17 00:00:00 2001 From: Ed_ Date: Mon, 13 Jan 2025 00:39:14 -0500 Subject: [PATCH] Added get_font_entry, resolve_px_scalar_size, snap_normalized_position_to_view --- vefontcache/vefontcache.odin | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/vefontcache/vefontcache.odin b/vefontcache/vefontcache.odin index d9a66c3..2cfd37d 100644 --- a/vefontcache/vefontcache.odin +++ b/vefontcache/vefontcache.odin @@ -1196,6 +1196,10 @@ get_font_vertical_metrics :: #force_inline proc ( ctx : Context, font : Font_ID, //#region("miscellaneous") +get_font_entry :: #force_inline proc "contextless" ( ctx : ^Context, font : Font_ID ) -> Entry { + return ctx.entries[font] +} + get_cursor_pos :: #force_inline proc "contextless" ( ctx : Context ) -> Vec2 { return ctx.cursor_pos } // Will normalize the value of the position and scale based on the provided view. @@ -1237,6 +1241,25 @@ resolve_zoom_size_scale :: #force_inline proc "contextless" ( return } +resolve_px_scalar_size :: #force_inline proc "contextless" ( parser_info : Parser_Font_Info, px_size, px_scalar : f32, norm_scale : Vec2 +) -> (target_px_size, target_font_scale : f32, target_scale : Vec2 ) +{ + target_px_size = px_size * px_scalar + target_scale = norm_scale * (1 / px_scalar) + target_font_scale = parser_scale( parser_info, target_px_size ) + return +} + +snap_normalized_position_to_view :: #force_inline proc "contextless" ( position, view : Vec2 ) -> (position_snapped : Vec2) +{ + should_snap := cast(f32) i32(view.x > 0 && view.y > 0) + view_quotient := 1 / Vec2 { max(view.x, 1), max(view.y, 1) } + + position_snapped = ceil(position * view) * view_quotient * should_snap + position_snapped = max(position, position_snapped) + return +} + set_alpha_scalar :: #force_inline proc( ctx : ^Context, scalar : f32 ) { assert(ctx != nil); ctx.alpha_sharpen = scalar } set_px_scalar :: #force_inline proc( ctx : ^Context, scalar : f32 ) { assert(ctx != nil); ctx.px_scalar = scalar } set_zoom_px_interval :: #force_inline proc( ctx : ^Context, interval : i32 ) { assert(ctx != nil); ctx.zoom_px_interval = f32(interval) }