ui corner anti aliasing

This commit is contained in:
jacob 2025-12-28 19:28:40 -06:00
parent f8ab74eafe
commit 7b4edbdfbb
6 changed files with 43 additions and 34 deletions

View File

@ -102,7 +102,8 @@ void V_BeginCommandsWidget(V_CommandsWidget *widget)
{ {
ZeroStruct(&widget->build); ZeroStruct(&widget->build);
widget->build.cp = UI_PushCP(UI_NilKey); 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) 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(); V_WidgetTheme theme = V_GetWidgetTheme();
Vec2 cursor_pos = UI_CursorPos(); Vec2 cursor_pos = UI_CursorPos();
UI_Push(Tag, HashF("commands widget"));
UI_Key titlebar_key = UI_KeyF("title bar"); UI_Key titlebar_key = UI_KeyF("title bar");
Vec4 window_background_color = theme.window_background_color; 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 window_border_color = theme.window_border_color;
Vec4 titlebar_color = Zi; Vec4 titlebar_color = Zi;
Vec4 titlebar_border_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(BackgroundColor, window_background_color);
UI_Push(BorderColor, window_border_color); UI_Push(BorderColor, window_border_color);
UI_Push(Border, theme.window_border); UI_Push(Border, theme.window_border);
// UI_Push(Rounding, UI_RPIX(15));
UI_Push(Rounding, UI_RPIX(15)); UI_Push(Rounding, UI_RPIX(15));
UI_Push(Width, UI_PIX(theme.window_width, 0)); UI_Push(Width, UI_PIX(theme.window_width, 0));
UI_Push(Height, UI_SHRINK(0, 0)); UI_Push(Height, UI_SHRINK(0, 0));
UI_Push(ChildLayoutAxis, Axis_Y); UI_Push(ChildLayoutAxis, Axis_Y);
UI_Push(FloatingPos, widget->pos); UI_Push(FloatingPos, widget->pos);
UI_SetNext(Flags, UI_BoxFlag_Floating); UI_SetNext(Flags, UI_BoxFlag_Floating);
UI_PushCP(UI_BuildBoxEx(UI_KeyF("titlebar"))); UI_PushCP(UI_BuildBoxEx(widget->key));
{ {
// Title bar // Title bar
UI_PushCP(UI_NilKey); UI_PushCP(UI_NilKey);
@ -621,7 +620,7 @@ void V_TickForever(WaveLaneCtx *lane)
for (Button btn = 0; btn < countof(frame->held_buttons); ++btn) 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) if (!has_mouse_focus)
{ {
@ -646,7 +645,7 @@ void V_TickForever(WaveLaneCtx *lane)
b32 ignore = 0; b32 ignore = 0;
if (down) 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) if (!has_mouse_focus)
{ {

View File

@ -133,6 +133,7 @@ Struct(V_CommandsWidget)
{ {
// Persistent state // Persistent state
Vec2 pos; Vec2 pos;
UI_Key key;
// Per-build state // Per-build state
struct struct

View File

@ -25,7 +25,7 @@ ComputeShader2D(V_BackdropCS, 8, 8)
f32 half_bounds_size = params.world_size * 0.5; 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_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)); 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.y > (bounds_screen_p0.y - half_thickness) &&
screen_pos.x < (bounds_screen_p1.x + half_thickness) && screen_pos.x < (bounds_screen_p1.x + half_thickness) &&
screen_pos.y < (bounds_screen_p1.y + half_thickness); screen_pos.y < (bounds_screen_p1.y + half_thickness);

View File

@ -695,7 +695,7 @@ UI_Frame *UI_BeginFrame(UI_FrameFlag frame_flags, Vec4 swapchain_color)
case ControllerEventKind_ButtonDown: 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) 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; hovered_box->report.is_m2_held = 1;
} }
else if (cev.button == Button_M3)
{
hovered_box->report.is_m3_held = 1;
}
active_box = hovered_box; active_box = hovered_box;
} }
} }
@ -716,7 +720,7 @@ UI_Frame *UI_BeginFrame(UI_FrameFlag frame_flags, Vec4 swapchain_color)
case ControllerEventKind_ButtonUp: 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) 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; active_box->report.is_m2_held = 0;
} }
else if (cev.button == Button_M3)
{
active_box->report.is_m3_held = 0;
}
active_box = 0; active_box = 0;
} }
} }

View File

@ -176,6 +176,7 @@ Struct(UI_Report)
{ {
b32 is_m1_held; b32 is_m1_held;
b32 is_m2_held; b32 is_m2_held;
b32 is_m3_held;
b32 is_hovered; b32 is_hovered;
b32 is_hot; b32 is_hot;

View File

@ -82,35 +82,35 @@ PixelShader(UI_DRectPS, UI_DRectPSOutput, UI_DRectPSInput input)
} }
} }
// Background color Vec4 final_color = 0;
Vec4 background_color = 0;
{ {
if (rect_dist <= 0) // Background color
if (G_IsRefNil(rect.tex))
{ {
if (border_dist <= 0) final_color = input.background_lin;
{
background_color = border_color;
}
else if (!G_IsRefNil(rect.tex))
{
Texture2D<Vec4> tex = G_Dereference<Vec4>(rect.tex);
background_color = tex.Sample(sampler, input.tex_uv);
}
else
{
background_color = input.background_lin;
}
} }
} else
{
Texture2D<Vec4> tex = G_Dereference<Vec4>(rect.tex);
final_color = tex.Sample(sampler, input.tex_uv);
}
final_color *= rect_dist <= 0;
// Final color // Border color
Vec4 final_color = background_color; {
final_color *= input.tint_lin; 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 // Tint
if (UI_ShaderConst_DebugDraw) final_color *= input.tint_lin;
{
final_color = rect.debug_lin; // Debug color
if (UI_ShaderConst_DebugDraw)
{
final_color = rect.debug_lin;
}
} }
UI_DRectPSOutput output; UI_DRectPSOutput output;