From 7b4edbdfbbead87f5ec875a3819262e4c0752ad1 Mon Sep 17 00:00:00 2001 From: jacob Date: Sun, 28 Dec 2025 19:28:40 -0600 Subject: [PATCH] ui corner anti aliasing --- src/pp/pp_vis/pp_vis_core.c | 13 +++++---- src/pp/pp_vis/pp_vis_core.h | 1 + src/pp/pp_vis/pp_vis_shaders.g | 2 +- src/ui/ui_core.c | 12 +++++++-- src/ui/ui_core.h | 1 + src/ui/ui_shaders.g | 48 +++++++++++++++++----------------- 6 files changed, 43 insertions(+), 34 deletions(-) diff --git a/src/pp/pp_vis/pp_vis_core.c b/src/pp/pp_vis/pp_vis_core.c index 0447b973..0e7a1167 100644 --- a/src/pp/pp_vis/pp_vis_core.c +++ b/src/pp/pp_vis/pp_vis_core.c @@ -102,7 +102,8 @@ void V_BeginCommandsWidget(V_CommandsWidget *widget) { ZeroStruct(&widget->build); widget->build.cp = UI_PushCP(UI_NilKey); - UI_Push(Tag, HashF("commands widget")); + widget->key = UI_KeyF("commands widget"); + UI_Push(Tag, widget->key.hash); } V_CommandsWidgetItemReport V_PushCommandsWidgetItem(V_CommandsWidget *widget, V_CommandsWidgetItemDesc desc) @@ -131,11 +132,10 @@ void V_EndCommandsWidget(V_CommandsWidget *widget) V_WidgetTheme theme = V_GetWidgetTheme(); Vec2 cursor_pos = UI_CursorPos(); - UI_Push(Tag, HashF("commands widget")); - UI_Key titlebar_key = UI_KeyF("title bar"); Vec4 window_background_color = theme.window_background_color; + // Vec4 window_background_color = VEC4(0, 0, 0, 0); Vec4 window_border_color = theme.window_border_color; Vec4 titlebar_color = Zi; Vec4 titlebar_border_color = Zi; @@ -153,14 +153,13 @@ void V_EndCommandsWidget(V_CommandsWidget *widget) UI_Push(BackgroundColor, window_background_color); UI_Push(BorderColor, window_border_color); UI_Push(Border, theme.window_border); - // UI_Push(Rounding, UI_RPIX(15)); UI_Push(Rounding, UI_RPIX(15)); UI_Push(Width, UI_PIX(theme.window_width, 0)); UI_Push(Height, UI_SHRINK(0, 0)); UI_Push(ChildLayoutAxis, Axis_Y); UI_Push(FloatingPos, widget->pos); UI_SetNext(Flags, UI_BoxFlag_Floating); - UI_PushCP(UI_BuildBoxEx(UI_KeyF("titlebar"))); + UI_PushCP(UI_BuildBoxEx(widget->key)); { // Title bar UI_PushCP(UI_NilKey); @@ -621,7 +620,7 @@ void V_TickForever(WaveLaneCtx *lane) for (Button btn = 0; btn < countof(frame->held_buttons); ++btn) { - if (btn == Button_M1 || btn == Button_M2) + if (btn == Button_M1 || btn == Button_M2 || btn == Button_M3) { if (!has_mouse_focus) { @@ -646,7 +645,7 @@ void V_TickForever(WaveLaneCtx *lane) b32 ignore = 0; if (down) { - if (cev.button == Button_M1 || cev.button == Button_M2) + if (cev.button == Button_M1 || cev.button == Button_M2 || cev.button == Button_M3) { if (!has_mouse_focus) { diff --git a/src/pp/pp_vis/pp_vis_core.h b/src/pp/pp_vis/pp_vis_core.h index 0ab5fe4f..ba41f362 100644 --- a/src/pp/pp_vis/pp_vis_core.h +++ b/src/pp/pp_vis/pp_vis_core.h @@ -133,6 +133,7 @@ Struct(V_CommandsWidget) { // Persistent state Vec2 pos; + UI_Key key; // Per-build state struct diff --git a/src/pp/pp_vis/pp_vis_shaders.g b/src/pp/pp_vis/pp_vis_shaders.g index fa1389ee..8603b0c0 100644 --- a/src/pp/pp_vis/pp_vis_shaders.g +++ b/src/pp/pp_vis/pp_vis_shaders.g @@ -25,7 +25,7 @@ ComputeShader2D(V_BackdropCS, 8, 8) f32 half_bounds_size = params.world_size * 0.5; Vec2 bounds_screen_p0 = mul(params.world_to_draw_xf, Vec3(-half_bounds_size, -half_bounds_size, 1)); Vec2 bounds_screen_p1 = mul(params.world_to_draw_xf, Vec3(half_bounds_size, half_bounds_size, 1)); - b32 is_in_bounds = screen_pos.x > (bounds_screen_p0.x - half_thickness) && + bool is_in_bounds = screen_pos.x > (bounds_screen_p0.x - half_thickness) && screen_pos.y > (bounds_screen_p0.y - half_thickness) && screen_pos.x < (bounds_screen_p1.x + half_thickness) && screen_pos.y < (bounds_screen_p1.y + half_thickness); diff --git a/src/ui/ui_core.c b/src/ui/ui_core.c index c7da7a4e..edb8b696 100644 --- a/src/ui/ui_core.c +++ b/src/ui/ui_core.c @@ -695,7 +695,7 @@ UI_Frame *UI_BeginFrame(UI_FrameFlag frame_flags, Vec4 swapchain_color) case ControllerEventKind_ButtonDown: { - if (cev.button == Button_M1 || cev.button == Button_M2) + if (cev.button == Button_M1 || cev.button == Button_M2 || cev.button == Button_M3) { if (hovered_box) { @@ -709,6 +709,10 @@ UI_Frame *UI_BeginFrame(UI_FrameFlag frame_flags, Vec4 swapchain_color) { hovered_box->report.is_m2_held = 1; } + else if (cev.button == Button_M3) + { + hovered_box->report.is_m3_held = 1; + } active_box = hovered_box; } } @@ -716,7 +720,7 @@ UI_Frame *UI_BeginFrame(UI_FrameFlag frame_flags, Vec4 swapchain_color) case ControllerEventKind_ButtonUp: { - if (cev.button == Button_M1 || cev.button == Button_M2) + if (cev.button == Button_M1 || cev.button == Button_M2 || cev.button == Button_M3) { if (active_box) { @@ -733,6 +737,10 @@ UI_Frame *UI_BeginFrame(UI_FrameFlag frame_flags, Vec4 swapchain_color) { active_box->report.is_m2_held = 0; } + else if (cev.button == Button_M3) + { + active_box->report.is_m3_held = 0; + } active_box = 0; } } diff --git a/src/ui/ui_core.h b/src/ui/ui_core.h index 8a951ebc..98be896e 100644 --- a/src/ui/ui_core.h +++ b/src/ui/ui_core.h @@ -176,6 +176,7 @@ Struct(UI_Report) { b32 is_m1_held; b32 is_m2_held; + b32 is_m3_held; b32 is_hovered; b32 is_hot; diff --git a/src/ui/ui_shaders.g b/src/ui/ui_shaders.g index 7da9376f..05dd9663 100644 --- a/src/ui/ui_shaders.g +++ b/src/ui/ui_shaders.g @@ -82,35 +82,35 @@ PixelShader(UI_DRectPS, UI_DRectPSOutput, UI_DRectPSInput input) } } - // Background color - Vec4 background_color = 0; + Vec4 final_color = 0; { - if (rect_dist <= 0) + // Background color + if (G_IsRefNil(rect.tex)) { - if (border_dist <= 0) - { - background_color = border_color; - } - else if (!G_IsRefNil(rect.tex)) - { - Texture2D tex = G_Dereference(rect.tex); - background_color = tex.Sample(sampler, input.tex_uv); - } - else - { - background_color = input.background_lin; - } + final_color = input.background_lin; } - } + else + { + Texture2D tex = G_Dereference(rect.tex); + final_color = tex.Sample(sampler, input.tex_uv); + } + final_color *= rect_dist <= 0; - // Final color - Vec4 final_color = background_color; - final_color *= input.tint_lin; + // Border color + { + f32 half_border_dist_fwidth = fwidth(border_dist) * 0.5; + f32 border_alpha = smoothstep(half_border_dist_fwidth, -half_border_dist_fwidth, border_dist); + final_color = lerp(final_color, border_color, border_alpha); + } - // Debug color - if (UI_ShaderConst_DebugDraw) - { - final_color = rect.debug_lin; + // Tint + final_color *= input.tint_lin; + + // Debug color + if (UI_ShaderConst_DebugDraw) + { + final_color = rect.debug_lin; + } } UI_DRectPSOutput output;