move draw helpers to vis core
This commit is contained in:
parent
d0130c4810
commit
5f6c1f629e
@ -154,18 +154,32 @@ S_Shape S_MulXformShape(Xform xf, S_Shape shape)
|
|||||||
Vec2 S_SupportPointFromShape(S_Shape shape, Vec2 dir)
|
Vec2 S_SupportPointFromShape(S_Shape shape, Vec2 dir)
|
||||||
{
|
{
|
||||||
Vec2 result = Zi;
|
Vec2 result = Zi;
|
||||||
|
Vec2 dir_norm = NormVec2(dir);
|
||||||
f32 max_dot = -Inf;
|
f32 max_dot = -Inf;
|
||||||
for (i32 i = 0; i < shape.points_count; ++i)
|
for (i32 i = 0; i < shape.points_count; ++i)
|
||||||
{
|
{
|
||||||
Vec2 p = shape.points[i];
|
Vec2 p = shape.points[i];
|
||||||
f32 dot = DotVec2(p, dir);
|
f32 dot = DotVec2(p, dir_norm);
|
||||||
if (dot > max_dot)
|
if (dot > max_dot)
|
||||||
{
|
{
|
||||||
max_dot = dot;
|
max_dot = dot;
|
||||||
result = p;
|
result = p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result = AddVec2(result, MulVec2(dir, shape.radius));
|
result = AddVec2(result, MulVec2(dir_norm, shape.radius));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
Rng2 S_BoundingBoxFromShape(S_Shape shape)
|
||||||
|
{
|
||||||
|
Vec2 left = S_SupportPointFromShape(shape, VEC2(-1, 0));
|
||||||
|
Vec2 top = S_SupportPointFromShape(shape, VEC2(0, -1));
|
||||||
|
Vec2 right = S_SupportPointFromShape(shape, VEC2(1, 0));
|
||||||
|
Vec2 bottom = S_SupportPointFromShape(shape, VEC2(0, 1));
|
||||||
|
|
||||||
|
Rng2 result = Zi;
|
||||||
|
result.p0 = VEC2(left.x, top.y);
|
||||||
|
result.p1 = VEC2(right.x, bottom.y);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -448,11 +462,6 @@ void S_TickForever(WaveLaneCtx *lane)
|
|||||||
|
|
||||||
for (S_Ent *ent = S_FirstEnt(&iter, world); ent->active; ent = S_NextEnt(&iter))
|
for (S_Ent *ent = S_FirstEnt(&iter, world); ent->active; ent = S_NextEnt(&iter))
|
||||||
{
|
{
|
||||||
if (!IsVec2Zero(ent->move))
|
|
||||||
{
|
|
||||||
DEBUGBREAKABLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
Xform xf = ent->xf;
|
Xform xf = ent->xf;
|
||||||
if (!IsVec2Zero(ent->look))
|
if (!IsVec2Zero(ent->look))
|
||||||
{
|
{
|
||||||
|
|||||||
@ -260,12 +260,13 @@ Rng2I32 S_UpdateTilesInPlaceFromPlacement(u8 *tiles, S_TilePlacement placement);
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//~ Shape helpers
|
//~ Shape helpers
|
||||||
|
|
||||||
#define S_ShapeFromDesc(...) S_ShapeFromDescEx((S_ShapeDesc) { __VA_ARGS__ })
|
|
||||||
S_Shape S_ShapeFromDescEx(S_ShapeDesc desc);
|
S_Shape S_ShapeFromDescEx(S_ShapeDesc desc);
|
||||||
|
#define S_ShapeFromDesc(...) S_ShapeFromDescEx((S_ShapeDesc) { __VA_ARGS__ })
|
||||||
|
|
||||||
S_Shape S_MulXformShape(Xform xf, S_Shape shape);
|
S_Shape S_MulXformShape(Xform xf, S_Shape shape);
|
||||||
|
|
||||||
Vec2 S_SupportPointFromShape(S_Shape shape, Vec2 dir);
|
Vec2 S_SupportPointFromShape(S_Shape shape, Vec2 dir);
|
||||||
|
Rng2 S_BoundingBoxFromShape(S_Shape shape);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//~ Lookup helpers
|
//~ Lookup helpers
|
||||||
|
|||||||
@ -27,7 +27,6 @@
|
|||||||
//- Api
|
//- Api
|
||||||
|
|
||||||
@IncludeC pp_vis_shaders.cgh
|
@IncludeC pp_vis_shaders.cgh
|
||||||
@IncludeC pp_vis_draw.h
|
|
||||||
@IncludeC pp_vis_core.h
|
@IncludeC pp_vis_core.h
|
||||||
|
|
||||||
@IncludeG pp_vis_shaders.cgh
|
@IncludeG pp_vis_shaders.cgh
|
||||||
@ -38,7 +37,6 @@
|
|||||||
//////////////////////////////
|
//////////////////////////////
|
||||||
//- Impl
|
//- Impl
|
||||||
|
|
||||||
@IncludeC pp_vis_draw.c
|
|
||||||
@IncludeC pp_vis_core.c
|
@IncludeC pp_vis_core.c
|
||||||
|
|
||||||
@IncludeG pp_vis_shaders.g
|
@IncludeG pp_vis_shaders.g
|
||||||
|
|||||||
@ -16,7 +16,7 @@ void V_Shutdown(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//~ Helpers
|
//~ Misc helpers
|
||||||
|
|
||||||
V_Frame *V_CurrentFrame(void)
|
V_Frame *V_CurrentFrame(void)
|
||||||
{
|
{
|
||||||
@ -72,6 +72,148 @@ String V_StringFromHotkey(Arena *arena, V_Hotkey hotkey)
|
|||||||
return StringFromList(arena, parts, Lit(" + "));
|
return StringFromList(arena, parts, Lit(" + "));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
//~ Draw helpers
|
||||||
|
|
||||||
|
void V_DrawPoly(Vec2Array points, Vec4 srgb, V_DrawFlag flags)
|
||||||
|
{
|
||||||
|
V_Frame *frame = V_CurrentFrame();
|
||||||
|
Arena *verts_arena = frame->dverts_arena;
|
||||||
|
Arena *idxs_arena = frame->dvert_idxs_arena;
|
||||||
|
Vec4 lin = LinearFromSrgb(srgb);
|
||||||
|
if (flags & V_DrawFlag_Line)
|
||||||
|
{
|
||||||
|
i32 verts_count = points.count;
|
||||||
|
if (verts_count >= 2)
|
||||||
|
{
|
||||||
|
TempArena scratch = BeginScratchNoConflict();
|
||||||
|
{
|
||||||
|
f32 half_thickness = 1;
|
||||||
|
i32 lines_count = verts_count == 2 ? 1 : verts_count;
|
||||||
|
i32 line_verts_count = lines_count * 4;
|
||||||
|
i32 idx_count = lines_count * 6;
|
||||||
|
i32 idx_offset = ArenaCount(verts_arena, V_DVert);
|
||||||
|
|
||||||
|
// Push dverts
|
||||||
|
V_DVert *dverts = PushStructsNoZero(verts_arena, V_DVert, line_verts_count);
|
||||||
|
for (i32 line_idx = 0; line_idx < lines_count; ++line_idx)
|
||||||
|
{
|
||||||
|
i32 a_idx = line_idx;
|
||||||
|
i32 b_idx = line_idx + 1;
|
||||||
|
if (b_idx >= lines_count)
|
||||||
|
{
|
||||||
|
b_idx = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vec2 a = points.points[a_idx];
|
||||||
|
Vec2 b = points.points[b_idx];
|
||||||
|
|
||||||
|
Vec2 a_to_b = SubVec2(b, a);
|
||||||
|
Vec2 perp = Vec2WithLen(PerpVec2(a_to_b), half_thickness);
|
||||||
|
|
||||||
|
Vec2 p0 = AddVec2(a, perp);
|
||||||
|
Vec2 p1 = SubVec2(a, perp);
|
||||||
|
Vec2 p2 = SubVec2(b, perp);
|
||||||
|
Vec2 p3 = AddVec2(b, perp);
|
||||||
|
|
||||||
|
i32 offset = line_idx * 4;
|
||||||
|
dverts[offset + 0] = (V_DVert) { .pos = p0, .color_lin = lin };
|
||||||
|
dverts[offset + 1] = (V_DVert) { .pos = p1, .color_lin = lin };
|
||||||
|
dverts[offset + 2] = (V_DVert) { .pos = p2, .color_lin = lin };
|
||||||
|
dverts[offset + 3] = (V_DVert) { .pos = p3, .color_lin = lin };
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate indices
|
||||||
|
i32 *indices = PushStructsNoZero(idxs_arena, i32, idx_count);
|
||||||
|
for (i32 line_idx = 0; line_idx < lines_count; ++line_idx)
|
||||||
|
{
|
||||||
|
i32 indices_offset = line_idx * 6;
|
||||||
|
i32 vert_idx_offset = idx_offset + (line_idx * 4);
|
||||||
|
indices[indices_offset + 0] = vert_idx_offset + 0;
|
||||||
|
indices[indices_offset + 1] = vert_idx_offset + 1;
|
||||||
|
indices[indices_offset + 2] = vert_idx_offset + 2;
|
||||||
|
indices[indices_offset + 3] = vert_idx_offset + 0;
|
||||||
|
indices[indices_offset + 4] = vert_idx_offset + 2;
|
||||||
|
indices[indices_offset + 5] = vert_idx_offset + 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
EndScratch(scratch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
i32 verts_count = points.count;
|
||||||
|
if (verts_count >= 3)
|
||||||
|
{
|
||||||
|
i32 idx_offset = ArenaCount(verts_arena, V_DVert);
|
||||||
|
i32 tris_count = verts_count - 2;
|
||||||
|
i32 idx_count = tris_count * 3;
|
||||||
|
|
||||||
|
// Push dverts
|
||||||
|
V_DVert *dverts = PushStructsNoZero(verts_arena, V_DVert, verts_count);
|
||||||
|
for (i32 point_idx = 0; point_idx < (i32)points.count; ++point_idx)
|
||||||
|
{
|
||||||
|
V_DVert *dvert = &dverts[point_idx];
|
||||||
|
dvert->pos = points.points[point_idx];
|
||||||
|
dvert->color_lin = lin;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate indices in a fan pattern
|
||||||
|
i32 *indices = PushStructsNoZero(idxs_arena, i32, idx_count);
|
||||||
|
for (i32 i = 0; i < tris_count; ++i)
|
||||||
|
{
|
||||||
|
i32 tri_offset = i * 3;
|
||||||
|
indices[tri_offset + 0] = idx_offset;
|
||||||
|
indices[tri_offset + 1] = idx_offset + i + 1;
|
||||||
|
indices[tri_offset + 2] = idx_offset + i + 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void V_DrawShape(S_Shape shape, Vec4 srgb, i32 detail, V_DrawFlag flags)
|
||||||
|
{
|
||||||
|
if (shape.radius == 0)
|
||||||
|
{
|
||||||
|
Vec2Array draw_points = Zi;
|
||||||
|
draw_points.points = shape.points;
|
||||||
|
draw_points.count = shape.points_count;
|
||||||
|
V_DrawPoly(draw_points, srgb, flags);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TempArena scratch = BeginScratchNoConflict();
|
||||||
|
{
|
||||||
|
Vec2Array draw_points = Zi;
|
||||||
|
draw_points.points = PushStructsNoZero(scratch.arena, Vec2, detail);
|
||||||
|
draw_points.count = detail;
|
||||||
|
for (i32 i = 0; i < detail; ++i)
|
||||||
|
{
|
||||||
|
f32 rad = ((f32)i / (f32)detail) * Tau;
|
||||||
|
Vec2 dir = Vec2FromAngle(rad);
|
||||||
|
Vec2 sp = S_SupportPointFromShape(shape, dir);
|
||||||
|
draw_points.points[i] = sp;
|
||||||
|
}
|
||||||
|
V_DrawPoly(draw_points, srgb, flags);
|
||||||
|
}
|
||||||
|
EndScratch(scratch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void V_DrawRect(Rng2 rect, Vec4 srgb, V_DrawFlag flags)
|
||||||
|
{
|
||||||
|
Vec2 points[4] = {
|
||||||
|
VEC2(rect.p0.x, rect.p0.y),
|
||||||
|
VEC2(rect.p1.x, rect.p0.y),
|
||||||
|
VEC2(rect.p1.x, rect.p1.y),
|
||||||
|
VEC2(rect.p0.x, rect.p1.y),
|
||||||
|
};
|
||||||
|
Vec2Array points_arr = Zi;
|
||||||
|
points_arr.points = points;
|
||||||
|
points_arr.count = countof(points);
|
||||||
|
V_DrawPoly(points_arr, srgb, flags);
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//~ Theme
|
//~ Theme
|
||||||
|
|
||||||
@ -90,6 +232,7 @@ V_WidgetTheme V_GetWidgetTheme(void)
|
|||||||
theme.h4 = 1.0;
|
theme.h4 = 1.0;
|
||||||
theme.h5 = 0.875;
|
theme.h5 = 0.875;
|
||||||
theme.h6 = 0.75;
|
theme.h6 = 0.75;
|
||||||
|
theme.micro = 0.50;
|
||||||
|
|
||||||
// theme.rounding = 0;
|
// theme.rounding = 0;
|
||||||
// theme.rounding = 1;
|
// theme.rounding = 1;
|
||||||
@ -668,11 +811,10 @@ void V_TickForever(WaveLaneCtx *lane)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////
|
//////////////////////////////
|
||||||
//- Build editor UI
|
|
||||||
|
|
||||||
// TODO: Remove this (testing)
|
|
||||||
|
|
||||||
//- Init test layout
|
//- Init test layout
|
||||||
|
|
||||||
|
// TODO: Remove this
|
||||||
|
|
||||||
if (!V.root_panel)
|
if (!V.root_panel)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
@ -690,7 +832,7 @@ void V_TickForever(WaveLaneCtx *lane)
|
|||||||
panel->parent = V.root_panel;
|
panel->parent = V.root_panel;
|
||||||
panel->key = UI_RandKey(); // TODO: Don't use random keys
|
panel->key = UI_RandKey(); // TODO: Don't use random keys
|
||||||
panel->axis = !panel->parent->axis;
|
panel->axis = !panel->parent->axis;
|
||||||
panel->pref_ratio = 0.25;
|
panel->pref_ratio = 0.15;
|
||||||
DllQueuePush(panel->parent->first, panel->parent->last, panel);
|
DllQueuePush(panel->parent->first, panel->parent->last, panel);
|
||||||
++panel->parent->count;
|
++panel->parent->count;
|
||||||
++V.panels_count;
|
++V.panels_count;
|
||||||
@ -725,7 +867,7 @@ void V_TickForever(WaveLaneCtx *lane)
|
|||||||
++panel->parent->count;
|
++panel->parent->count;
|
||||||
++V.panels_count;
|
++V.panels_count;
|
||||||
|
|
||||||
panel->pref_ratio = 0.75;
|
panel->pref_ratio = 0.85;
|
||||||
panel->is_viewport_panel = 1;
|
panel->is_viewport_panel = 1;
|
||||||
|
|
||||||
// {
|
// {
|
||||||
@ -770,6 +912,9 @@ void V_TickForever(WaveLaneCtx *lane)
|
|||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//////////////////////////////
|
||||||
|
//- Build panels
|
||||||
|
|
||||||
if (frame->is_editing)
|
if (frame->is_editing)
|
||||||
{
|
{
|
||||||
Struct(PanelDfsNode) { PanelDfsNode *next; b32 visited; V_Panel *panel; UI_Checkpoint cp; };
|
Struct(PanelDfsNode) { PanelDfsNode *next; b32 visited; V_Panel *panel; UI_Checkpoint cp; };
|
||||||
@ -882,7 +1027,7 @@ void V_TickForever(WaveLaneCtx *lane)
|
|||||||
//////////////////////////////
|
//////////////////////////////
|
||||||
//- Build tab row
|
//- Build tab row
|
||||||
|
|
||||||
f32 tab_spacing = 5;
|
f32 tab_spacing = UI_FNT(0.25, 0).v;
|
||||||
V_Window *active_window = 0;
|
V_Window *active_window = 0;
|
||||||
V_Window *close_window = 0;
|
V_Window *close_window = 0;
|
||||||
{
|
{
|
||||||
@ -1037,24 +1182,27 @@ void V_TickForever(WaveLaneCtx *lane)
|
|||||||
UI_SetNext(BackgroundColor, bg_color);
|
UI_SetNext(BackgroundColor, bg_color);
|
||||||
UI_SetNext(BorderColor, border_color);
|
UI_SetNext(BorderColor, border_color);
|
||||||
UI_SetNext(BorderSize, 1);
|
UI_SetNext(BorderSize, 1);
|
||||||
UI_SetNext(Width, UI_SHRINK(0, 0));
|
UI_SetNext(Width, UI_SHRINK(0, 1));
|
||||||
UI_SetNext(Height, UI_SHRINK(0, 0));
|
UI_SetNext(Height, UI_SHRINK(0, 0));
|
||||||
UI_SetNext(ChildAlignment, UI_Region_Left);
|
UI_SetNext(ChildAlignment, UI_Region_Left);
|
||||||
UI_SetNext(Misc, window == active_window);
|
UI_SetNext(Misc, window == active_window);
|
||||||
UI_SetNext(Flags, UI_BoxFlag_CaptureMouse);
|
UI_SetNext(Flags, UI_BoxFlag_CaptureMouse);
|
||||||
UI_SetNext(Text, tab_name);
|
|
||||||
UI_PushCP(UI_BuildRowEx(tab->key));
|
UI_PushCP(UI_BuildRowEx(tab->key));
|
||||||
{
|
{
|
||||||
|
UI_BuildSpacer(UI_PIX(tab_spacing, 0), Axis_X);
|
||||||
|
|
||||||
// Build tab title
|
// Build tab title
|
||||||
{
|
{
|
||||||
UI_SetNext(ChildAlignment, UI_Region_Center);
|
UI_SetNext(ChildAlignment, UI_Region_Center);
|
||||||
UI_SetNext(Flags, UI_BoxFlag_DrawText);
|
UI_SetNext(Flags, UI_BoxFlag_DrawText);
|
||||||
UI_SetNext(Text, tab_name);
|
UI_SetNext(Text, tab_name);
|
||||||
UI_SetNext(Width, UI_SHRINK(6, 0));
|
UI_SetNext(Width, UI_SHRINK(0, 0));
|
||||||
UI_SetNext(Height, UI_SHRINK(2, 0));
|
UI_SetNext(Height, UI_SHRINK(2, 0));
|
||||||
UI_BuildRow();
|
UI_BuildRow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UI_BuildSpacer(UI_PIX(tab_spacing, 0), Axis_X);
|
||||||
|
|
||||||
// Build tab close button
|
// Build tab close button
|
||||||
{
|
{
|
||||||
UI_Key close_key = UI_KeyF("close");
|
UI_Key close_key = UI_KeyF("close");
|
||||||
@ -1069,11 +1217,21 @@ void V_TickForever(WaveLaneCtx *lane)
|
|||||||
UI_SetNext(BorderColor, close_border_color);
|
UI_SetNext(BorderColor, close_border_color);
|
||||||
UI_SetNext(BorderSize, 2);
|
UI_SetNext(BorderSize, 2);
|
||||||
UI_SetNext(ChildAlignment, UI_Region_Center);
|
UI_SetNext(ChildAlignment, UI_Region_Center);
|
||||||
UI_SetNext(Flags, UI_BoxFlag_DrawText | UI_BoxFlag_CaptureMouse);
|
UI_SetNext(Flags, UI_BoxFlag_CaptureMouse);
|
||||||
UI_SetNext(Text, Lit("x"));
|
UI_SetNext(Width, UI_SHRINK(0, 0));
|
||||||
UI_SetNext(Width, UI_SHRINK(6, 0));
|
UI_SetNext(Height, UI_GROW(1, 0));
|
||||||
UI_SetNext(Height, UI_SHRINK(2, 0));
|
UI_PushCP(UI_BuildRowEx(close_key));
|
||||||
UI_BuildRowEx(close_key);
|
{
|
||||||
|
UI_BuildSpacer(UI_PIX(tab_spacing * 2, 0), Axis_X);
|
||||||
|
|
||||||
|
UI_SetNext(Width, UI_SHRINK(0, 1));
|
||||||
|
UI_SetNext(Height, UI_SHRINK(0, 1));
|
||||||
|
UI_SetNext(FontSize, UI_Top(FontSize) * theme.micro);
|
||||||
|
UI_BuildIcon(theme.icon_font, UI_Icon_Cross);
|
||||||
|
|
||||||
|
UI_BuildSpacer(UI_PIX(tab_spacing * 2, 0), Axis_X);
|
||||||
|
}
|
||||||
|
UI_PopCP(UI_TopCP());
|
||||||
|
|
||||||
if (close_rep.m1.presses)
|
if (close_rep.m1.presses)
|
||||||
{
|
{
|
||||||
@ -1135,13 +1293,16 @@ void V_TickForever(WaveLaneCtx *lane)
|
|||||||
UI_SetNext(BorderColor, border_color);
|
UI_SetNext(BorderColor, border_color);
|
||||||
UI_SetNext(BorderSize, 2);
|
UI_SetNext(BorderSize, 2);
|
||||||
UI_SetNext(Width, UI_SHRINK(10, 0));
|
UI_SetNext(Width, UI_SHRINK(10, 0));
|
||||||
UI_SetNext(Height, UI_SHRINK(2, 0));
|
UI_SetNext(Height, UI_GROW(1, 0));
|
||||||
UI_SetNext(ChildAlignment, UI_Region_Center);
|
UI_SetNext(ChildAlignment, UI_Region_Center);
|
||||||
// UI_SetNext(FontSize, theme.font_size * 1.5);
|
// UI_SetNext(FontSize, theme.font_size * 1.5);
|
||||||
UI_SetNext(Flags, UI_BoxFlag_DrawText | UI_BoxFlag_CaptureMouse);
|
UI_SetNext(Flags, UI_BoxFlag_CaptureMouse);
|
||||||
UI_SetNext(Text, Lit("+"));
|
|
||||||
UI_PushCP(UI_BuildRowEx(key));
|
UI_PushCP(UI_BuildRowEx(key));
|
||||||
{
|
{
|
||||||
|
UI_SetNext(Width, UI_SHRINK(0, 1));
|
||||||
|
UI_SetNext(Height, UI_SHRINK(0, 1));
|
||||||
|
UI_SetNext(FontSize, UI_Top(FontSize) * theme.micro);
|
||||||
|
UI_BuildIcon(theme.icon_font, UI_Icon_Plus);
|
||||||
}
|
}
|
||||||
UI_PopCP(UI_TopCP());
|
UI_PopCP(UI_TopCP());
|
||||||
}
|
}
|
||||||
@ -1589,7 +1750,7 @@ void V_TickForever(WaveLaneCtx *lane)
|
|||||||
UI_SetNext(Height, UI_SHRINK(0, 1));
|
UI_SetNext(Height, UI_SHRINK(0, 1));
|
||||||
UI_SetNext(Flags, UI_BoxFlag_CaptureMouse);
|
UI_SetNext(Flags, UI_BoxFlag_CaptureMouse);
|
||||||
UI_SetNext(FontSize, UI_Top(FontSize) * theme.h6);
|
UI_SetNext(FontSize, UI_Top(FontSize) * theme.h6);
|
||||||
UI_BuildIconEx(reset_key, UI_Icon_Loop2, theme.icon_font);
|
UI_BuildIconEx(reset_key, theme.icon_font, UI_Icon_Loop2);
|
||||||
}
|
}
|
||||||
|
|
||||||
UI_BuildSpacer(UI_PIX(spacing, 1), Axis_X);
|
UI_BuildSpacer(UI_PIX(spacing, 1), Axis_X);
|
||||||
@ -2199,6 +2360,7 @@ void V_TickForever(WaveLaneCtx *lane)
|
|||||||
{
|
{
|
||||||
Xform ent_to_world_xf = ent->xf;
|
Xform ent_to_world_xf = ent->xf;
|
||||||
Xform ent_to_draw_xf = MulXform(frame->world_to_draw_xf, ent_to_world_xf);
|
Xform ent_to_draw_xf = MulXform(frame->world_to_draw_xf, ent_to_world_xf);
|
||||||
|
S_Shape draw_shape = S_MulXformShape(ent_to_draw_xf, ent->local_shape);
|
||||||
|
|
||||||
b32 is_visible = 1;
|
b32 is_visible = 1;
|
||||||
if (is_visible)
|
if (is_visible)
|
||||||
@ -2207,9 +2369,9 @@ void V_TickForever(WaveLaneCtx *lane)
|
|||||||
{
|
{
|
||||||
Vec4 color = Color_Purple;
|
Vec4 color = Color_Purple;
|
||||||
i32 detail = 32;
|
i32 detail = 32;
|
||||||
S_Shape shape = S_MulXformShape(ent_to_draw_xf, ent->local_shape);
|
V_DrawShape(draw_shape, color, detail, V_DrawFlag_Line);
|
||||||
V_DrawShape(frame->dverts_arena, frame->dvert_idxs_arena, shape, LinearFromSrgb(color), detail, V_DrawFlag_Line);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw weapon
|
// Draw weapon
|
||||||
if (ent->has_weapon)
|
if (ent->has_weapon)
|
||||||
{
|
{
|
||||||
@ -2226,7 +2388,14 @@ void V_TickForever(WaveLaneCtx *lane)
|
|||||||
Xform local_xf = XformFromTrs(TRS(.t = { 0, 0 }, .r = Tau / 4));
|
Xform local_xf = XformFromTrs(TRS(.t = { 0, 0 }, .r = Tau / 4));
|
||||||
Xform xf = MulXform(ent_to_draw_xf, local_xf);
|
Xform xf = MulXform(ent_to_draw_xf, local_xf);
|
||||||
S_Shape shape = S_MulXformShape(xf, local_shape);
|
S_Shape shape = S_MulXformShape(xf, local_shape);
|
||||||
V_DrawShape(frame->dverts_arena, frame->dvert_idxs_arena, shape, LinearFromSrgb(color), 10, V_DrawFlag_Line);
|
V_DrawShape(shape, color, 10, V_DrawFlag_Line);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw aabb
|
||||||
|
{
|
||||||
|
Vec4 color = Color_Orange;
|
||||||
|
Rng2 bb = S_BoundingBoxFromShape(draw_shape);
|
||||||
|
V_DrawRect(bb, color, V_DrawFlag_Line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,6 +30,7 @@ Struct(V_WidgetTheme)
|
|||||||
f32 h4;
|
f32 h4;
|
||||||
f32 h5;
|
f32 h5;
|
||||||
f32 h6;
|
f32 h6;
|
||||||
|
f32 micro;
|
||||||
|
|
||||||
f32 rounding;
|
f32 rounding;
|
||||||
|
|
||||||
@ -180,6 +181,15 @@ Struct(V_Window)
|
|||||||
b32 is_tile_window;
|
b32 is_tile_window;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
//~ Draw types
|
||||||
|
|
||||||
|
Enum(V_DrawFlag)
|
||||||
|
{
|
||||||
|
V_DrawFlag_None = 0,
|
||||||
|
V_DrawFlag_Line = (1 << 0),
|
||||||
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//~ State types
|
//~ State types
|
||||||
|
|
||||||
@ -295,7 +305,7 @@ void V_Bootstrap(void);
|
|||||||
void V_Shutdown(void);
|
void V_Shutdown(void);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//~ Helpers
|
//~ Misc helpers
|
||||||
|
|
||||||
V_Frame *V_CurrentFrame(void);
|
V_Frame *V_CurrentFrame(void);
|
||||||
V_Frame *V_LastFrame(void);
|
V_Frame *V_LastFrame(void);
|
||||||
@ -303,6 +313,13 @@ V_Cmd *V_PushVisCmd(String name);
|
|||||||
S_Cmd *V_PushSimCmd(S_CmdKind kind);
|
S_Cmd *V_PushSimCmd(S_CmdKind kind);
|
||||||
String V_StringFromHotkey(Arena *arena, V_Hotkey hotkey);
|
String V_StringFromHotkey(Arena *arena, V_Hotkey hotkey);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
//~ Draw helpers
|
||||||
|
|
||||||
|
void V_DrawPoly(Vec2Array points, Vec4 srgb, V_DrawFlag flags);
|
||||||
|
void V_DrawShape(S_Shape shape, Vec4 srgb, i32 detail, V_DrawFlag flags);
|
||||||
|
void V_DrawRect(Rng2 rect, Vec4 srgb, V_DrawFlag flags);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//~ Theme
|
//~ Theme
|
||||||
|
|
||||||
|
|||||||
@ -1,123 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//~ Shape helpers
|
|
||||||
|
|
||||||
void V_DrawPoly(Arena *verts_arena, Arena *idxs_arena, Vec2Array points, Vec4 color_lin, V_DrawFlag flags)
|
|
||||||
{
|
|
||||||
if (flags & V_DrawFlag_Line)
|
|
||||||
{
|
|
||||||
i32 verts_count = points.count;
|
|
||||||
if (verts_count >= 2)
|
|
||||||
{
|
|
||||||
TempArena scratch = BeginScratchNoConflict();
|
|
||||||
{
|
|
||||||
f32 half_thickness = 1;
|
|
||||||
i32 lines_count = verts_count == 2 ? 1 : verts_count;
|
|
||||||
i32 line_verts_count = lines_count * 4;
|
|
||||||
i32 idx_count = lines_count * 6;
|
|
||||||
i32 idx_offset = ArenaCount(verts_arena, V_DVert);
|
|
||||||
|
|
||||||
// Push dverts
|
|
||||||
V_DVert *dverts = PushStructsNoZero(verts_arena, V_DVert, line_verts_count);
|
|
||||||
for (i32 line_idx = 0; line_idx < lines_count; ++line_idx)
|
|
||||||
{
|
|
||||||
i32 a_idx = line_idx;
|
|
||||||
i32 b_idx = line_idx + 1;
|
|
||||||
if (b_idx >= lines_count)
|
|
||||||
{
|
|
||||||
b_idx = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
Vec2 a = points.points[a_idx];
|
|
||||||
Vec2 b = points.points[b_idx];
|
|
||||||
|
|
||||||
Vec2 a_to_b = SubVec2(b, a);
|
|
||||||
Vec2 perp = Vec2WithLen(PerpVec2(a_to_b), half_thickness);
|
|
||||||
|
|
||||||
Vec2 p0 = AddVec2(a, perp);
|
|
||||||
Vec2 p1 = SubVec2(a, perp);
|
|
||||||
Vec2 p2 = SubVec2(b, perp);
|
|
||||||
Vec2 p3 = AddVec2(b, perp);
|
|
||||||
|
|
||||||
i32 offset = line_idx * 4;
|
|
||||||
dverts[offset + 0] = (V_DVert) { .pos = p0, .color_lin = color_lin };
|
|
||||||
dverts[offset + 1] = (V_DVert) { .pos = p1, .color_lin = color_lin };
|
|
||||||
dverts[offset + 2] = (V_DVert) { .pos = p2, .color_lin = color_lin };
|
|
||||||
dverts[offset + 3] = (V_DVert) { .pos = p3, .color_lin = color_lin };
|
|
||||||
}
|
|
||||||
|
|
||||||
// Generate indices
|
|
||||||
i32 *indices = PushStructsNoZero(idxs_arena, i32, idx_count);
|
|
||||||
for (i32 line_idx = 0; line_idx < lines_count; ++line_idx)
|
|
||||||
{
|
|
||||||
i32 indices_offset = line_idx * 6;
|
|
||||||
i32 vert_idx_offset = idx_offset + (line_idx * 4);
|
|
||||||
indices[indices_offset + 0] = vert_idx_offset + 0;
|
|
||||||
indices[indices_offset + 1] = vert_idx_offset + 1;
|
|
||||||
indices[indices_offset + 2] = vert_idx_offset + 2;
|
|
||||||
indices[indices_offset + 3] = vert_idx_offset + 0;
|
|
||||||
indices[indices_offset + 4] = vert_idx_offset + 2;
|
|
||||||
indices[indices_offset + 5] = vert_idx_offset + 3;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
EndScratch(scratch);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
i32 verts_count = points.count;
|
|
||||||
if (verts_count >= 3)
|
|
||||||
{
|
|
||||||
i32 idx_offset = ArenaCount(verts_arena, V_DVert);
|
|
||||||
i32 tris_count = verts_count - 2;
|
|
||||||
i32 idx_count = tris_count * 3;
|
|
||||||
|
|
||||||
// Push dverts
|
|
||||||
V_DVert *dverts = PushStructsNoZero(verts_arena, V_DVert, verts_count);
|
|
||||||
for (i32 point_idx = 0; point_idx < (i32)points.count; ++point_idx)
|
|
||||||
{
|
|
||||||
V_DVert *dvert = &dverts[point_idx];
|
|
||||||
dvert->pos = points.points[point_idx];
|
|
||||||
dvert->color_lin = color_lin;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Generate indices in a fan pattern
|
|
||||||
i32 *indices = PushStructsNoZero(idxs_arena, i32, idx_count);
|
|
||||||
for (i32 i = 0; i < tris_count; ++i)
|
|
||||||
{
|
|
||||||
i32 tri_offset = i * 3;
|
|
||||||
indices[tri_offset + 0] = idx_offset;
|
|
||||||
indices[tri_offset + 1] = idx_offset + i + 1;
|
|
||||||
indices[tri_offset + 2] = idx_offset + i + 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void V_DrawShape(Arena *verts_arena, Arena *idxs_arena, S_Shape shape, Vec4 color_lin, i32 detail, V_DrawFlag flags)
|
|
||||||
{
|
|
||||||
if (shape.radius == 0)
|
|
||||||
{
|
|
||||||
Vec2Array draw_points = Zi;
|
|
||||||
draw_points.points = shape.points;
|
|
||||||
draw_points.count = shape.points_count;
|
|
||||||
V_DrawPoly(verts_arena, idxs_arena, draw_points, color_lin, flags);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
TempArena scratch = BeginScratchNoConflict();
|
|
||||||
{
|
|
||||||
Vec2Array draw_points = Zi;
|
|
||||||
draw_points.points = PushStructsNoZero(scratch.arena, Vec2, detail);
|
|
||||||
draw_points.count = detail;
|
|
||||||
for (i32 i = 0; i < detail; ++i)
|
|
||||||
{
|
|
||||||
f32 rad = ((f32)i / (f32)detail) * Tau;
|
|
||||||
Vec2 dir = Vec2FromAngle(rad);
|
|
||||||
Vec2 sp = S_SupportPointFromShape(shape, dir);
|
|
||||||
draw_points.points[i] = sp;
|
|
||||||
}
|
|
||||||
V_DrawPoly(verts_arena, idxs_arena, draw_points, color_lin, flags);
|
|
||||||
}
|
|
||||||
EndScratch(scratch);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,14 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//~ Flag types
|
|
||||||
|
|
||||||
Enum(V_DrawFlag)
|
|
||||||
{
|
|
||||||
V_DrawFlag_None = 0,
|
|
||||||
V_DrawFlag_Line = (1 << 0),
|
|
||||||
};
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
//~ Shape helpers
|
|
||||||
|
|
||||||
void V_DrawPoly(Arena *verts_arena, Arena *idxs_arena, Vec2Array points, Vec4 color_lin, V_DrawFlag flags);
|
|
||||||
void V_DrawShape(Arena *verts_arena, Arena *idxs_arena, S_Shape shape, Vec4 color_lin, i32 detail, V_DrawFlag flags);
|
|
||||||
@ -1164,7 +1164,6 @@ void UI_EndFrame(UI_Frame *frame)
|
|||||||
}
|
}
|
||||||
else if (sem_dims.kind == UI_SizeKind_Shrink && AnyBit(box->desc.flags, UI_BoxFlag_DrawText))
|
else if (sem_dims.kind == UI_SizeKind_Shrink && AnyBit(box->desc.flags, UI_BoxFlag_DrawText))
|
||||||
{
|
{
|
||||||
// TODO: Distinguish between baseline alignment & visual alignment
|
|
||||||
f32 text_size = 0;
|
f32 text_size = 0;
|
||||||
if (axis == Axis_X)
|
if (axis == Axis_X)
|
||||||
{
|
{
|
||||||
@ -1258,8 +1257,8 @@ void UI_EndFrame(UI_Frame *frame)
|
|||||||
for (Axis axis = 0; axis < Axis_COUNTXY; ++axis)
|
for (Axis axis = 0; axis < Axis_COUNTXY; ++axis)
|
||||||
{
|
{
|
||||||
f32 box_size = box->solved_dims.v[axis];
|
f32 box_size = box->solved_dims.v[axis];
|
||||||
// Accumulate non-floating sizes
|
|
||||||
{
|
{
|
||||||
|
// Accumulate non-floating sizes
|
||||||
f32 unconstrained_size_accum = 0;
|
f32 unconstrained_size_accum = 0;
|
||||||
f32 flex_accum = 0;
|
f32 flex_accum = 0;
|
||||||
f32 violation = 0;
|
f32 violation = 0;
|
||||||
@ -1269,8 +1268,6 @@ void UI_EndFrame(UI_Frame *frame)
|
|||||||
b32 is_floating = AnyBit(child->desc.flags, UI_BoxFlag_Floating);
|
b32 is_floating = AnyBit(child->desc.flags, UI_BoxFlag_Floating);
|
||||||
if (!is_floating)
|
if (!is_floating)
|
||||||
{
|
{
|
||||||
child->solved_dims.v[axis] = RoundF32(child->solved_dims.v[axis]);
|
|
||||||
|
|
||||||
f32 size = child->solved_dims.v[axis];
|
f32 size = child->solved_dims.v[axis];
|
||||||
f32 strictness = child->desc.pref_semantic_dims[axis].strictness;
|
f32 strictness = child->desc.pref_semantic_dims[axis].strictness;
|
||||||
f32 flex = size * (1.0 - strictness);
|
f32 flex = size * (1.0 - strictness);
|
||||||
@ -1286,6 +1283,7 @@ void UI_EndFrame(UI_Frame *frame)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
unconstrained_size_accum = FloorF32(unconstrained_size_accum);
|
||||||
violation = unconstrained_size_accum - box_size;
|
violation = unconstrained_size_accum - box_size;
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
@ -1333,6 +1331,7 @@ void UI_EndFrame(UI_Frame *frame)
|
|||||||
UI_Box *box = boxes_pre[pre_index];
|
UI_Box *box = boxes_pre[pre_index];
|
||||||
UI_Box *parent = box->parent;
|
UI_Box *parent = box->parent;
|
||||||
|
|
||||||
|
// TODO: Distinguish between baseline alignment & visual alignment
|
||||||
UI_RegionPair child_alignment = UI_PairFromRegion(box->desc.child_alignment);
|
UI_RegionPair child_alignment = UI_PairFromRegion(box->desc.child_alignment);
|
||||||
UI_RegionPair alignment_in_parent = UI_PairFromRegion(parent ? parent->desc.child_alignment : UI_Region_TopLeft);
|
UI_RegionPair alignment_in_parent = UI_PairFromRegion(parent ? parent->desc.child_alignment : UI_Region_TopLeft);
|
||||||
|
|
||||||
@ -1341,7 +1340,6 @@ void UI_EndFrame(UI_Frame *frame)
|
|||||||
|
|
||||||
b32 is_floating = AnyBit(box->desc.flags, UI_BoxFlag_Floating);
|
b32 is_floating = AnyBit(box->desc.flags, UI_BoxFlag_Floating);
|
||||||
|
|
||||||
|
|
||||||
// Apply scale
|
// Apply scale
|
||||||
for (Axis axis = 0; axis < Axis_COUNTXY; ++axis)
|
for (Axis axis = 0; axis < Axis_COUNTXY; ++axis)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -63,7 +63,7 @@ UI_Key UI_BuildLabelF_(String fmt, ...)
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//~ Icon helpers
|
//~ Icon helpers
|
||||||
|
|
||||||
UI_Key UI_BuildIconEx(UI_Key key, UI_Icon icon, GC_FontKey font)
|
UI_Key UI_BuildIconEx(UI_Key key, GC_FontKey font, UI_Icon icon)
|
||||||
{
|
{
|
||||||
UI_SetNext(Font, font);
|
UI_SetNext(Font, font);
|
||||||
UI_SetNext(Icon, icon);
|
UI_SetNext(Icon, icon);
|
||||||
|
|||||||
@ -14,8 +14,8 @@ UI_Key UI_BuildLabelF_(String fmt, ...);
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//~ Icon helpers
|
//~ Icon helpers
|
||||||
|
|
||||||
UI_Key UI_BuildIconEx(UI_Key key, UI_Icon icon, GC_FontKey font);
|
UI_Key UI_BuildIconEx(UI_Key key, GC_FontKey font, UI_Icon icon);
|
||||||
#define UI_BuildIcon(icon, font) UI_BuildIconEx(UI_NilKey, (icon), (font))
|
#define UI_BuildIcon(font, icon) UI_BuildIconEx(UI_NilKey, (font), (icon))
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//~ Spacing helpers
|
//~ Spacing helpers
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user