round glyph advance & bounds during run generation

This commit is contained in:
jacob 2025-12-29 03:37:56 -06:00
parent f7df2f78b8
commit 4d25eadd40
5 changed files with 44 additions and 16 deletions

View File

@ -1183,6 +1183,15 @@ Vec2 DimsFromRng2(Rng2 r)
return result;
}
Vec2 CenterFromRng2(Rng2 r)
{
Vec2 result = Zi;
Vec2 dims = DimsFromRng2(r);
result.x = r.p0.x + dims.x * 0.5;
result.y = r.p0.y + dims.y * 0.5;
return result;
}
Rng2 UnionRng2(Rng2 a, Rng2 b)
{
Rng2 result = Zi;
@ -1227,6 +1236,15 @@ Vec2I32 DimsFromRng2I32(Rng2I32 r)
return result;
}
Vec2I32 CenterFromRng2I32(Rng2I32 r)
{
Vec2I32 result = Zi;
Vec2I32 dims = DimsFromRng2I32(r);
result.x = r.p0.x + dims.x * 0.5;
result.y = r.p0.y + dims.y * 0.5;
return result;
}
Rng2I32 UnionRng2I32(Rng2I32 a, Rng2I32 b)
{
Rng2I32 result = Zi;

View File

@ -392,6 +392,7 @@ u32 U32FromVec4(Vec4 v);
//- Rng2
Vec2 DimsFromRng2(Rng2 r);
Vec2 CenterFromRng2(Rng2 r);
Rng2 UnionRng2(Rng2 a, Rng2 b);
Rng2 AddRng2Vec2(Rng2 r, Vec2 v);
Rng2 MulRng2Vec2(Rng2 a, Vec2 v);
@ -399,6 +400,7 @@ Rng2 DivRng2Vec2(Rng2 a, Vec2 v);
//- Rng2I32
Vec2I32 DimsFromRng2I32(Rng2I32 r);
Vec2I32 CenterFromRng2I32(Rng2I32 r);
Rng2I32 UnionRng2I32(Rng2I32 a, Rng2I32 b);
Rng2I32 AddRng2I32Vec2I32(Rng2I32 r, Vec2I32 v);
Rng2I32 MulRng2I32Vec2I32(Rng2I32 a, Vec2I32 v);

View File

@ -184,6 +184,8 @@ GC_Run GC_RunFromString(Arena *arena, String str, GC_FontKey font, f32 font_size
Rng2 bounds = Zi;
bounds.p0 = MulVec2(glyph->bounds.p0, scale);
bounds.p1 = MulVec2(glyph->bounds.p1, scale);
bounds.p0 = RoundVec2(bounds.p0);
bounds.p1 = RoundVec2(bounds.p1);
rect->tex = glyph->atlas->tex_ref;
rect->tex_slice = glyph->tex_slice;

View File

@ -134,14 +134,13 @@ V_CommandsWidgetItemReport V_PushCommandsWidgetItem(V_CommandsWidget *widget, V_
void V_EndCommandsWidget(V_CommandsWidget *widget)
{
V_Frame *frame = V_CurrentFrame();
V_WidgetTheme theme = V_GetWidgetTheme();
Vec2 cursor_pos = UI_CursorPos();
UI_Key titlebar_key = UI_KeyF("title bar");
UI_Report titlebar_rep = UI_ReportFromKey(titlebar_key);
UI_Push(Scale, titlebar_rep.exists);
UI_Push(Tint, VEC4(1, 1, 1, titlebar_rep.exists));
Vec2 titlebar_half_dims = MulVec2(DimsFromRng2(titlebar_rep.screen_rect), 0.5);
Vec4 window_background_color = theme.window_background_color;
// Vec4 window_background_color = VEC4(0, 0, 0, 0);
@ -151,11 +150,18 @@ void V_EndCommandsWidget(V_CommandsWidget *widget)
Vec4 divider_color = theme.divider_color;
if (titlebar_rep.m1.held)
{
widget->pos = SubVec2(cursor_pos, titlebar_rep.last_down_mouse_offset);
widget->pos = AddVec2(SubVec2(cursor_pos, titlebar_rep.last_down_mouse_offset), titlebar_half_dims);
}
// window_border_color = BlendSrgb(window_border_color, Rgb(0.5, 0.5, 0.5), titlebar_rep.hot);
window_border_color = BlendSrgb(window_border_color, Rgb32(0x0078a6), titlebar_rep.hot);
UI_Push(Scale, titlebar_rep.exists);
UI_Push(Tint, VEC4(1, 1, 1, titlebar_rep.exists));
// Vec2 pos = LerpVec2(MulVec2(Vec2FromVec(frame->ui_dims), 0.5), widget->pos, titlebar_rep.exists);
Vec2 pos = SubVec2(widget->pos, titlebar_half_dims);
UI_Push(BackgroundColor, window_background_color);
UI_Push(BorderColor, window_border_color);
UI_Push(Border, theme.window_border);
@ -163,7 +169,7 @@ void V_EndCommandsWidget(V_CommandsWidget *widget)
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_Push(FloatingPos, pos);
UI_SetNext(Flags, UI_BoxFlag_Floating);
UI_PushCP(UI_BuildBoxEx(widget->key));
{

View File

@ -12,7 +12,7 @@
X(toggle_console, Toggle Developer Console, V_CmdDescFlag_None, V_HOTKEY( Button_GraveAccent ), ) \
X(toggle_fullscreen, Toggle Fullscreen Mode, V_CmdDescFlag_None, V_HOTKEY( Button_Enter, .alt = 1 ) ) \
X(toggle_window_topmost, Toggle Window Topmost, V_CmdDescFlag_None, V_HOTKEY( Button_F4 ), ) \
X(spawn, Spawn/Teleport Player, V_CmdDescFlag_None, V_HOTKEY( Button_T ), ) \
X(spawn, Spawn/Teleport Player to Cursor, V_CmdDescFlag_None, V_HOTKEY( Button_T ), ) \
// --------------------------------------------------------------------------------------------------------------------
////////////////////////////////////////////////////////////