diff --git a/src/base/base_math.h b/src/base/base_math.h index a005361c..e1332ad7 100644 --- a/src/base/base_math.h +++ b/src/base/base_math.h @@ -13,8 +13,8 @@ Enum(Axis) Axis_Y = 1, Axis_Z = 2, - Axis_CountXY = 2, - Axis_CountXYZ = 3, + Axis_CountXY = 2, + Axis_CountXYZ = 3 }; //////////////////////////////////////////////////////////// diff --git a/src/font/font.c b/src/font/font.c index ea0dcd8f..4c25130f 100644 --- a/src/font/font.c +++ b/src/font/font.c @@ -250,11 +250,11 @@ F_Run F_RunFromString(Arena *arena, F_Font *font, String str) for (CodepointIter it = InitCodepointIter(str); NextCodepoint(&it);) { u32 codepoint = it.codepoint; - if (codepoint < 0 || font->glyphs_count <= codepoint) + if (font->glyphs_count <= codepoint) { codepoint = '?'; } - if (0 <= codepoint && codepoint < font->glyphs_count) + if (codepoint < font->glyphs_count) { u16 index = font->lookup[codepoint]; F_Glyph glyph = font->glyphs[index]; diff --git a/src/gpu/gpu_dx12/gpu_dx12.c b/src/gpu/gpu_dx12/gpu_dx12.c index 86dd29f3..0fe7c20b 100644 --- a/src/gpu/gpu_dx12/gpu_dx12.c +++ b/src/gpu/gpu_dx12/gpu_dx12.c @@ -874,7 +874,7 @@ GPU_Resource *GPU_AcquireResource(GPU_ResourceDesc desc) { switch (desc.kind) { - case GPU_ResourceKind_Sampler: break; + default: break; /* Buffer */ case GPU_ResourceKind_Buffer: @@ -1249,6 +1249,7 @@ i64 GPU_EndCommandList(GPU_CommandList *gpu_cl) switch (cmd->kind) { + default: break; case GPU_D12_CommandKind_TransitionToSrv: { diff --git a/src/gpu/gpu_dx12/gpu_dx12.h b/src/gpu/gpu_dx12/gpu_dx12.h index 8a3bc183..f8d1bc52 100644 --- a/src/gpu/gpu_dx12/gpu_dx12.h +++ b/src/gpu/gpu_dx12/gpu_dx12.h @@ -1,9 +1,11 @@ //////////////////////////////////////////////////////////// //~ DirectX12 libs -#include -#include -#include +#pragma warning(push, 0) +# include +# include +# include +#pragma warning(pop) #pragma comment(lib, "d3d12") #pragma comment(lib, "dxgi") diff --git a/src/meta/meta.c b/src/meta/meta.c index be7f56d9..b0bdaff8 100644 --- a/src/meta/meta.c +++ b/src/meta/meta.c @@ -916,7 +916,7 @@ JobDef(Build, _, __) PushStringToList(arena, &cp.compiler_only_flags_msvc, Lit("-Z7")); /* Enable warnings */ - PushStringToList(arena, &cp.warnings_msvc, Lit("-W4")); + PushStringToList(arena, &cp.warnings_msvc, Lit("-Wall")); PushStringToList(arena, &cp.warnings_msvc, Lit("-WX")); // PushStringToList(arena, &cp.warnings_msvc, Lit("-we4013")); /* function undefined; assuming extern returning int */ @@ -931,6 +931,12 @@ JobDef(Build, _, __) PushStringToList(arena, &cp.warnings_msvc, Lit("-wd4702")); /* unreachable code */ PushStringToList(arena, &cp.warnings_msvc, Lit("-wd4127")); /* conditional expression is constant */ PushStringToList(arena, &cp.warnings_msvc, Lit("-wd4305")); /* 'initializing': truncation from 'double' to 'f32' */ + PushStringToList(arena, &cp.warnings_msvc, Lit("-wd4820")); /* bytes padding added after data member */ + PushStringToList(arena, &cp.warnings_msvc, Lit("-wd4464")); /* relative include path contains '..' */ + PushStringToList(arena, &cp.warnings_msvc, Lit("-wd4061")); /* enumerator is not explicitly handled by a case label */ + PushStringToList(arena, &cp.warnings_msvc, Lit("-wd4242")); /* conversion from X to Y, possible loss of data */ + PushStringToList(arena, &cp.warnings_msvc, Lit("-wd4388")); /* signed/unsigned mismatch */ + PushStringToList(arena, &cp.warnings_msvc, Lit("-wd5045")); /* Compiler will insert Spectre mitigation for memory load if /Qspectre switch specified */ } //- Clang diff --git a/src/platform/platform.h b/src/platform/platform.h index eadf2531..639877f6 100644 --- a/src/platform/platform.h +++ b/src/platform/platform.h @@ -348,8 +348,8 @@ String P_GetClipboardText(Arena *arena); //////////////////////////////////////////////////////////// //~ @hookdecl Timer hooks -Fence *P_GetTimerFence(); -i64 P_GetCurrentTimerPeriodNs(); +Fence *P_GetTimerFence(void); +i64 P_GetCurrentTimerPeriodNs(void); //////////////////////////////////////////////////////////// //~ @hookdecl Sleep hooks diff --git a/src/platform/platform_win32/platform_win32.c b/src/platform/platform_win32/platform_win32.c index 229ec71e..9c7c1848 100644 --- a/src/platform/platform_win32/platform_win32.c +++ b/src/platform/platform_win32/platform_win32.c @@ -980,13 +980,13 @@ String P_GetClipboardText(Arena *arena) //////////////////////////////////////////////////////////// //~ @hookdef Timer hooks -Fence *P_GetTimerFence() +Fence *P_GetTimerFence(void) { P_W32_SharedState *g = &P_W32_shared_state; return &g->timer_fence; } -i64 P_GetCurrentTimerPeriodNs() +i64 P_GetCurrentTimerPeriodNs(void) { P_W32_SharedState *g = &P_W32_shared_state; return Atomic64Fetch(&g->average_timer_period_ns.v); diff --git a/src/pp/pp.c b/src/pp/pp.c index f68000fa..76976c04 100644 --- a/src/pp/pp.c +++ b/src/pp/pp.c @@ -105,7 +105,7 @@ void PP_PushGameUiStyle(void) UI_Push(Font, ResourceKeyFromStore(&PP_Resources, Lit("font/fixedsys.ttf"))); UI_Push(FontSize, 16); - UI_Push(Rounding, 0); + UI_Push(Rounding, UI_RPIX(0)); UI_Push(Border, 1); // UI_Push(BackgroundColor, Rgba32F(0.3, 0.5, 0.3, 0.3)); @@ -1953,9 +1953,9 @@ void PP_UpdateUser(void) UI_SetNext(BackgroundColor, Rgba32F(0.075, 0.075, 0.075, 0.99)); UI_SetNext(BorderColor, Rgba32F(0.2, 0.2, 0.2, 1)); UI_SetNext(Border, 2); - UI_SetNext(Rounding, 0.1); + UI_SetNext(Rounding, UI_RPIX(10)); UI_SetNext(Parent, pp_root_box); - UI_SetNext(Flags, UI_BoxFlag_Floating | UI_BoxFlag_ClampFloatingX | UI_BoxFlag_ClampFloatingY); + UI_SetNext(Flags, UI_BoxFlag_Floating); UI_SetNext(FloatingPos, g->lister_pos); UI_SetNext(Width, UI_PIX(size.x, 0)); UI_SetNext(Height, UI_PIX(size.y, 0)); @@ -1964,30 +1964,33 @@ void PP_UpdateUser(void) UI_PushCheckpoint(); { - UI_SetNext(Parent, lister_box); - UI_SetNext(LayoutAxis, Axis_X); - UI_SetNext(Width, UI_FILL(1, 0)); - UI_SetNext(Height, UI_FNT(1, 0)); - // UI_SetNext(BackgroundColor, 0); - // UI_SetNext(Border, 0); - UI_Box *title_bar = UI_BuildBox(Zstr); + UI_Push(Parent, lister_box); + // UI_BuildSpacer(UI_PIX(10, 0)); { - UI_Push(Parent, title_bar); - UI_Push(Width, UI_FILL(1, 0)); - UI_Push(Padding, 0); - UI_Push(BackgroundColor, 0); - UI_Push(Border, 0); + UI_SetNext(LayoutAxis, Axis_X); + UI_SetNext(Width, UI_FILL(1, 0)); + UI_SetNext(Height, UI_FNT(1, 0)); + // UI_SetNext(BackgroundColor, 0); + // UI_SetNext(Border, 0); + UI_Box *title_bar = UI_BuildBox(Zstr); { - UI_Box *left_box = UI_BuildBox(Zstr); - } - { - UI_SetNext(Text, Lit("Title")); - UI_SetNext(Flags, UI_BoxFlag_DrawText); - UI_SetNext(Width, UI_FIT(1)); - UI_Box *title_box = UI_BuildBox(Zstr); - } - { - UI_Box *right_box = UI_BuildBox(Zstr); + UI_Push(Parent, title_bar); + UI_Push(Width, UI_FILL(1, 0)); + UI_Push(Padding, 0); + UI_Push(BackgroundColor, 0); + UI_Push(Border, 0); + { + UI_Box *left_box = UI_BuildBox(Zstr); + } + { + UI_SetNext(Text, Lit("Title")); + UI_SetNext(Flags, UI_BoxFlag_DrawText); + UI_SetNext(Width, UI_FIT(1)); + UI_Box *title_box = UI_BuildBox(Zstr); + } + { + UI_Box *right_box = UI_BuildBox(Zstr); + } } } } diff --git a/src/pp/pp_widgets.c b/src/pp/pp_widgets.c index 9222e4e3..3d18193e 100644 --- a/src/pp/pp_widgets.c +++ b/src/pp/pp_widgets.c @@ -122,7 +122,7 @@ UI_Box *PP_BuildDebugConsole(b32 minimized) UI_SetNext(Width, UI_FILL(1, 0)); UI_SetNext(Height, UI_FIT(1)); UI_SetNext(BorderColor, Rgba32F(0.25, 0.25, 0.25, 1)); - UI_SetNext(Rounding, 0); + UI_SetNext(Rounding, UI_RPIX(0)); UI_SetNext(Border, 1); UI_Box *log_box = UI_BuildBox(Zstr); UI_Push(Parent, log_box); diff --git a/src/ui/ui_core.c b/src/ui/ui_core.c index 624540ac..bd0358bf 100644 --- a/src/ui/ui_core.c +++ b/src/ui/ui_core.c @@ -110,6 +110,7 @@ UI_StyleNode *UI_PushStyleNode(UI_Style desc) { UI_SharedState *g = &UI_shared_state; UI_StyleNode *n = g->style_tops[desc.kind]; + b32 cancel = 0; if (!n->style.forced) { { @@ -705,18 +706,14 @@ i64 UI_EndBuild(GPU_Resource *render_target, Xform ui_to_screen_xf) /* Solve floating violations */ for (UI_Box *child = box->first; child; child = child->next) { - if (child->flags & UI_BoxFlag_Floating) + if ((child->flags & UI_BoxFlag_Floating) && !(child->flags & UI_BoxFlag_NoFloatingClamp)) { - if (((child->flags & UI_BoxFlag_ClampFloatingX) && axis == Axis_X) || - ((child->flags & UI_BoxFlag_ClampFloatingY) && axis == Axis_Y)) + f32 size = child->solved_dims[axis]; + if (size > box_size) { - f32 size = child->solved_dims[axis]; - if (size > box_size) - { - f32 strictness = child->pref_size[axis].strictness; - f32 flex = size * (1.0 - strictness); - child->solved_dims[axis] = MaxF32(size - flex, box_size); - } + f32 strictness = child->pref_size[axis].strictness; + f32 flex = size * (1.0 - strictness); + child->solved_dims[axis] = MaxF32(size - flex, box_size); } } } @@ -728,38 +725,91 @@ i64 UI_EndBuild(GPU_Resource *render_target, Xform ui_to_screen_xf) { UI_Box *box = boxes_pre[pre_index]; UI_Box *parent = box->parent; - Vec2 dims = VEC2(box->solved_dims[0], box->solved_dims[1]); - Vec2 pos = ZI; - if (box->flags & UI_BoxFlag_Floating) + + /* Position */ { - /* Calculate floating box pos */ - Vec2 offset = box->floating_pos; - pos = AddVec2(parent->p0, offset); - if (box->flags & UI_BoxFlag_ClampFloatingX) + Vec2 dims = VEC2(box->solved_dims[0], box->solved_dims[1]); + Vec2 final_pos = ZI; + + /* Floating box position */ + if (box->flags & UI_BoxFlag_Floating) { - f32 overshoot = MaxF32(0, (pos.x + dims.x) - parent->p1.x); - pos.x = MaxF32(parent->p0.x, pos.x - overshoot); + Vec2 offset = box->floating_pos; + final_pos = AddVec2(parent->p0, offset); + if (!(box->flags & UI_BoxFlag_NoFloatingClamp)) + { + { + f32 overshoot = MaxF32(0, (final_pos.x + dims.x) - parent->p1.x); + final_pos.x = MaxF32(parent->p0.x, final_pos.x - overshoot); + } + { + f32 overshoot = MaxF32((final_pos.y + dims.y) - parent->p1.y, 0); + final_pos.y = MaxF32(parent->p0.y, final_pos.y - overshoot); + } + } } - if (box->flags & UI_BoxFlag_ClampFloatingY) - { - f32 overshoot = MaxF32((pos.y + dims.y) - parent->p1.y, 0); - pos.y = MaxF32(parent->p0.y, pos.y - overshoot); - } - } - else - { - /* Calculate non-floating box pos */ - if (parent) + /* Non-floating box position */ + else if (parent) { b32 is_layout_x = parent->layout_axis == Axis_X; f32 layout_cursor = parent->layout_cursor; Vec2 offset = VEC2(layout_cursor * is_layout_x, layout_cursor * !is_layout_x); parent->layout_cursor += dims.x * is_layout_x + dims.y * !is_layout_x; - pos = AddVec2(parent->p0, offset); + final_pos = AddVec2(parent->p0, offset); } + + /* Submit position */ + box->p0 = final_pos; + box->p1 = AddVec2(final_pos, dims); + } + + /* Rounding */ + { + UI_Round rounding = box->rounding; + Vec2 half_dims = MulVec2(SubVec2(box->p1, box->p0), 0.5); + f32 min_half_dims = MinF32(half_dims.x, half_dims.y); + f32 final_rounding_tl = 0; + f32 final_rounding_tr = 0; + f32 final_rounding_br = 0; + f32 final_rounding_bl = 0; + + switch(rounding.kind) + { + default: break; + case UI_RoundKind_Pixel: + { + final_rounding_tl = rounding.v; + final_rounding_tr = final_rounding_tl; + final_rounding_br = final_rounding_tl; + final_rounding_bl = final_rounding_tl; + } break; + case UI_RoundKind_Fill: + { + final_rounding_tl = rounding.v * min_half_dims; + final_rounding_tr = final_rounding_tl; + final_rounding_br = final_rounding_tl; + final_rounding_bl = final_rounding_tl; + } break; + } + + if (parent && !((box->flags & UI_BoxFlag_Floating) && (box->flags & UI_BoxFlag_NoFloatingClamp))) + { + Vec2 vtl = SubVec2(VEC2(parent->p0.x, parent->p0.y), VEC2(box->p0.x, box->p0.y)); + Vec2 vtr = SubVec2(VEC2(parent->p1.x, parent->p0.y), VEC2(box->p1.x, box->p0.y)); + Vec2 vbr = SubVec2(VEC2(parent->p1.x, parent->p1.y), VEC2(box->p1.x, box->p1.y)); + Vec2 vbl = SubVec2(VEC2(parent->p0.x, parent->p1.y), VEC2(box->p0.x, box->p1.y)); + final_rounding_tl = MaxF32(final_rounding_tl, parent->rounding_tl - Vec2Len(vtl)); + final_rounding_tr = MaxF32(final_rounding_tr, parent->rounding_tr - Vec2Len(vtr)); + final_rounding_br = MaxF32(final_rounding_br, parent->rounding_br - Vec2Len(vbr)); + final_rounding_bl = MaxF32(final_rounding_bl, parent->rounding_bl - Vec2Len(vbl)); + } + + /* Submit rounding */ + box->rounding_tl = final_rounding_tl; + box->rounding_tr = final_rounding_tr; + box->rounding_br = final_rounding_br; + box->rounding_bl = final_rounding_bl; } - box->p0 = pos; - box->p1 = AddVec2(pos, dims); } ////////////////////////////// @@ -797,7 +847,41 @@ i64 UI_EndBuild(GPU_Resource *render_target, Xform ui_to_screen_xf) rect->border_srgb = box->border_color; rect->tint_srgb = box->tint; rect->border = box->border; - rect->rounding = box->rounding; + + + + /* Rounding */ + rect->tl_rounding = box->rounding_tl; + rect->tr_rounding = box->rounding_tr; + rect->br_rounding = box->rounding_br; + rect->bl_rounding = box->rounding_bl; + // { + // UI_Rounding rounding = box->rounding; + // f32 final_rounding = 0; + // { + // Vec2 half_dims = MulVec2(SubVec2(box->p1, box->p0), 0.5); + // f32 min_half_dims = MinF32(half_dims.x, half_dims.y); + // switch(rounding.kind) + // { + // default: break; + // case UI_RoundKind_Pixel: + // { + // final_rounding = rounding.v; + // } break; + // case UI_RoundKind_Fit: + // { + // final_rounding = rounding.v * min_half_dims; + // } break; + // } + // final_rounding = MinF32(final_rounding, min_half_dims); + // } + // rect->tl_rounding = final_rounding; + // rect->tr_rounding = final_rounding; + // rect->br_rounding = final_rounding; + // rect->bl_rounding = final_rounding; + // } + + /* Texture */ if (box->background_texture != 0) { rect->tex = GPU_Texture2DRidFromResource(box->background_texture); diff --git a/src/ui/ui_core.h b/src/ui/ui_core.h index ac948372..0fbd5f04 100644 --- a/src/ui/ui_core.h +++ b/src/ui/ui_core.h @@ -14,9 +14,9 @@ Struct(UI_Key) Enum(UI_SizeKind) { - UI_SizeKind_Fit, - UI_SizeKind_Fill, - UI_SizeKind_Pixel, + UI_SizeKind_Fit, /* Size to contents */ + UI_SizeKind_Fill, /* Size as percent of parent size */ + UI_SizeKind_Pixel, /* Exact size */ }; Struct(UI_Size) @@ -26,6 +26,21 @@ Struct(UI_Size) f32 strictness; }; +//////////////////////////////////////////////////////////// +//~ Rounding types + +Enum(UI_RoundKind) +{ + UI_RoundKind_Pixel, /* Exact radius */ + UI_RoundKind_Fill, /* Radius as percent of size */ +}; + +Struct(UI_Round) +{ + UI_RoundKind kind; + f32 v; +}; + //////////////////////////////////////////////////////////// //~ Box flag types @@ -35,8 +50,7 @@ Enum(UI_BoxFlag) UI_BoxFlag_DrawText = (1 << 0), UI_BoxFlag_NoTextTruncation = (1 << 1), UI_BoxFlag_Floating = (1 << 2), - UI_BoxFlag_ClampFloatingX = (1 << 3), - UI_BoxFlag_ClampFloatingY = (1 << 4), + UI_BoxFlag_NoFloatingClamp = (1 << 3), }; //////////////////////////////////////////////////////////// @@ -58,7 +72,7 @@ Enum(UI_BoxFlag) x(FontSize, u32) \ x(Text, String) \ x(Padding, f32) \ - x(Rounding, f32) \ + x(Rounding, UI_Round) \ x(FloatingPos, Vec2) \ /* ------------------------------------------- */ @@ -152,18 +166,18 @@ Struct(UI_Box) Vec2 background_texture_uv1; UI_Size pref_size[Axis_CountXY]; + UI_Round rounding; u32 background_color; u32 border_color; u32 text_color; u32 tint; f32 border; - f32 padding; - f32 rounding; Vec2 floating_pos; String text; Axis layout_axis; ResourceKey font_resource; f32 font_size; + f32 padding; //- Pre-layout data u64 pre_index; @@ -178,6 +192,10 @@ Struct(UI_Box) //- Post-layout data Vec2 p0; Vec2 p1; + f32 rounding_tl; + f32 rounding_tr; + f32 rounding_br; + f32 rounding_bl; }; Struct(UI_BoxBin) @@ -253,18 +271,18 @@ void UI_PopCheckpoint(void); //////////////////////////////////////////////////////////// //~ Style helpers -UI_StyleNode *UI_PushStyleNode(UI_Style desc); -UI_Style UI_PopStyleNode(UI_StyleKind kind); -UI_StyleNode *UI_PeekTopStyleNode(UI_StyleKind kind); -UI_Style UI_StyleFromTopNode(UI_StyleKind kind, b32 use); +UI_StyleNode *UI_PushStyleNode(UI_Style desc); +UI_Style UI_PopStyleNode(UI_StyleKind kind); +UI_StyleNode *UI_PeekTopStyleNode(UI_StyleKind kind); +UI_Style UI_StyleFromTopNode(UI_StyleKind kind, b32 use); -#define UI_SetNext(name, v) UI_PushStyleNode((UI_Style) { .kind = UI_StyleKind_##name, .name = v, .pop_when_used = 1 }) -#define UI_Push(name, v) UI_PushStyleNode((UI_Style) { .kind = UI_StyleKind_##name, .name = v }) -#define UI_ForceNext(name, v) UI_PushStyleNode((UI_Style) { .kind = UI_StyleKind_##name, .name = v, .pop_when_used = 1, .forced = 1 }) -#define UI_ForcePush(name, v) UI_PushStyleNode((UI_Style) { .kind = UI_StyleKind_##name, .name = v, .forced = 1 }) -#define UI_Pop(name, v) UI_PopStyleNode(UI_StyleKind_##name).name -#define UI_UseTop(name) UI_StyleFromTopNode(UI_StyleKind_##name, 1).name -#define UI_PeekTop(name) UI_StyleFromTopNode(UI_StyleKind_##name, 0).name +#define UI_SetNext(name, ...) UI_PushStyleNode((UI_Style) { .kind = UI_StyleKind_##name, .name = __VA_ARGS__, .pop_when_used = 1 }) +#define UI_Push(name, ...) UI_PushStyleNode((UI_Style) { .kind = UI_StyleKind_##name, .name = __VA_ARGS__ }) +#define UI_ForceNext(name, ...) UI_PushStyleNode((UI_Style) { .kind = UI_StyleKind_##name, .name = __VA_ARGS__, .pop_when_used = 1, .forced = 1 }) +#define UI_ForcePush(name, ...) UI_PushStyleNode((UI_Style) { .kind = UI_StyleKind_##name, .name = __VA_ARGS__, .forced = 1 }) +#define UI_Pop(name) UI_PopStyleNode(UI_StyleKind_##name).name +#define UI_UseTop(name) UI_StyleFromTopNode(UI_StyleKind_##name, 1).name +#define UI_PeekTop(name) UI_StyleFromTopNode(UI_StyleKind_##name, 0).name //////////////////////////////////////////////////////////// //~ Size helpers @@ -276,6 +294,14 @@ UI_Style UI_StyleFromTopNode(UI_StyleKind kind, b32 use); #define UI_FILL(_v, _s) UI_SIZE(UI_SizeKind_Fill, (_v), (_s)) #define UI_FNT(_v, _s) UI_SIZE(UI_SizeKind_Pixel, (f32)UI_PeekTop(FontSize) * (_v), (_s)) +//////////////////////////////////////////////////////////// +//~ Rounding helpers + +#define UI_ROUND(_kind, _v) (UI_Round) { .kind = (_kind), .v = (_v)} + +#define UI_RPIX(_v) UI_ROUND(UI_RoundKind_Pixel, (_v)) +#define UI_RFILL(_v) UI_ROUND(UI_RoundKind_Fill, (_v)) + //////////////////////////////////////////////////////////// //~ Box diff --git a/src/ui/ui_draw.gpu b/src/ui/ui_draw.gpu index afce9199..9d484017 100644 --- a/src/ui/ui_draw.gpu +++ b/src/ui/ui_draw.gpu @@ -71,50 +71,34 @@ UI_RectPS_Output PSDef(UI_RectPS, UI_RectPS_Input input) result = input.background_lin; } - Vec2 size = Vec2(p1.x - p0.x, p1.y - p0.y); - Vec2 half_size = size * 0.5; - /* Calculate distance to edge (negative means out of bounds) */ - f32 edge_dist; + f32 edge_dist = min(min(p.x - p0.x, p1.x - p.x), min(p.y - p0.y, p1.y - p.y)); { - /* TODO: Read per-corner rounding here */ - f32 radius = min(half_size.x, half_size.y) * rect.rounding; - Vec2 tl = Vec2(p0.x + radius, p0.y + radius); - Vec2 tr = Vec2(p1.x - radius, p0.y + radius); - Vec2 br = Vec2(p1.x - radius, p1.y - radius); - Vec2 bl = Vec2(p0.x + radius, p1.y - radius); - - if (p.x < tl.x && p.y < tl.y) - { - edge_dist = radius - length(tl - p); - } - else if (p.x > tr.x && p.y < tr.y) - { - edge_dist = radius - length(tr - p); - } - else if (p.x > br.x && p.y > br.y) - { - edge_dist = radius - length(br - p); - } - else if (p.x < bl.x && p.y > bl.y) - { - edge_dist = radius - length(bl - p); - } - else - { - edge_dist = min(min(p.x - p0.x, p1.x - p.x), min(p.y - p0.y, p1.y - p.y)); - } + f32 tl_radius = rect.tl_rounding; + f32 tr_radius = rect.tr_rounding; + f32 br_radius = rect.br_rounding; + f32 bl_radius = rect.bl_rounding; + Vec2 tl = Vec2(p0.x + tl_radius, p0.y + tl_radius); + Vec2 tr = Vec2(p1.x - tr_radius, p0.y + tr_radius); + Vec2 br = Vec2(p1.x - br_radius, p1.y - br_radius); + Vec2 bl = Vec2(p0.x + bl_radius, p1.y - bl_radius); + if (p.x < tl.x && p.y < tl.y) edge_dist = min(edge_dist, tl_radius - length(tl - p)); + if (p.x > tr.x && p.y < tr.y) edge_dist = min(edge_dist, tr_radius - length(tr - p)); + if (p.x > br.x && p.y > br.y) edge_dist = min(edge_dist, br_radius - length(br - p)); + if (p.x < bl.x && p.y > bl.y) edge_dist = min(edge_dist, bl_radius - length(bl - p)); } /* Border */ + if (edge_dist < rect.border) + { + result = input.border_lin; + } + + /* Out of bounds */ if (edge_dist < 0) { result = 0; } - else if (edge_dist < rect.border) - { - result = input.border_lin; - } /* Tint */ result *= input.tint_lin; diff --git a/src/ui/ui_draw.h b/src/ui/ui_draw.h index 32eed4f7..4267fe06 100644 --- a/src/ui/ui_draw.h +++ b/src/ui/ui_draw.h @@ -34,7 +34,11 @@ Struct(UI_RectInstance) Vec2 tex_uv0; Vec2 tex_uv1; Texture2DRid tex; - f32 rounding; + + f32 tl_rounding; + f32 tr_rounding; + f32 br_rounding; + f32 bl_rounding; }; //////////////////////////////////////////////////////////// diff --git a/src/window/window_win32/window_win32.c b/src/window/window_win32/window_win32.c index 74bedec5..03673226 100644 --- a/src/window/window_win32/window_win32.c +++ b/src/window/window_win32/window_win32.c @@ -521,6 +521,8 @@ void WND_EndFrame(WND_Frame frame) WND_Cmd cmd = n->cmd; switch(cmd.kind) { + default: break; + //- Minimize case WND_CmdKind_SetMinimized: {