use pixels for font size
This commit is contained in:
parent
7de757ec01
commit
52d7ddb1f4
@ -27,10 +27,11 @@ JobDef(F_Load, sig, _)
|
||||
|
||||
ResourceKey resource = sig->resource;
|
||||
String name = NameFromResource(resource);
|
||||
f32 point_size = sig->point_size;
|
||||
f32 font_size = sig->size;
|
||||
f32 em_size = font_size * (3.0 / 4.0);
|
||||
AC_Asset *asset = sig->asset;
|
||||
|
||||
LogInfoF("Loading font \"%F\" (point size %F)", FmtString(name), FmtFloat((f64)point_size));
|
||||
LogInfoF("Loading font \"%F\" (font size: %F, em size: %F)", FmtString(name), FmtFloat((f64)font_size), FmtFloat((f64)em_size));
|
||||
i64 start_ns = TimeNs();
|
||||
|
||||
Assert(StringEndsWith(name, Lit(".ttf")));
|
||||
@ -45,7 +46,7 @@ JobDef(F_Load, sig, _)
|
||||
"Font \"%F\" not found",
|
||||
FmtString(name)));
|
||||
}
|
||||
TTF_Decoded decoded = TTF_Decode(scratch.arena, resource_data, point_size, font_codes, countof(font_codes));
|
||||
TTF_Decoded decoded = TTF_Decode(scratch.arena, resource_data, em_size, font_codes, countof(font_codes));
|
||||
|
||||
/* Send texture to GPU */
|
||||
GPU_Resource *texture = 0;
|
||||
@ -129,7 +130,7 @@ JobDef(F_Load, sig, _)
|
||||
font->image_width = decoded.image_width;
|
||||
font->image_height = decoded.image_height;
|
||||
font->glyphs_count = decoded.glyphs_count;
|
||||
font->point_size = point_size;
|
||||
font->size = font_size;
|
||||
font->ascent = decoded.ascent;
|
||||
font->descent = decoded.descent;
|
||||
|
||||
@ -153,7 +154,7 @@ JobDef(F_Load, sig, _)
|
||||
font->lookup[codepoint] = decoded.cache_indices[i];
|
||||
}
|
||||
|
||||
LogSuccessF("Loaded font \"%F\" (point size %F) in %F seconds", FmtString(name), FmtFloat((f64)point_size), FmtFloat(SecondsFromNs(TimeNs() - start_ns)));
|
||||
LogSuccessF("Loaded font \"%F\" (font size: %F, em size: %F) in %F seconds", FmtString(name), FmtFloat((f64)font_size), FmtFloat((f64)em_size), FmtFloat(SecondsFromNs(TimeNs() - start_ns)));
|
||||
AC_MarkReady(asset, font);
|
||||
|
||||
EndScratch(scratch);
|
||||
@ -163,17 +164,17 @@ JobDef(F_Load, sig, _)
|
||||
//~ Font load operations
|
||||
|
||||
/* Returns the asset from the asset cache */
|
||||
AC_Asset *F_LoadAsset(ResourceKey resource, f32 point_size, b32 wait)
|
||||
AC_Asset *F_LoadAsset(ResourceKey resource, f32 size, b32 wait)
|
||||
{
|
||||
__prof;
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
String name = NameFromResource(resource);
|
||||
|
||||
/* Concatenate point_size to name for key */
|
||||
/* Concatenate size to name for key */
|
||||
String key = StringF(scratch.arena,
|
||||
"%F%F_font",
|
||||
FmtString(name),
|
||||
FmtFloatP((f64)point_size, 1));
|
||||
FmtFloatP((f64)size, 1));
|
||||
u64 hash = AC_HashFromKey(key);
|
||||
b32 is_first_touch;
|
||||
AC_Asset *asset = AC_TouchCache(key, hash, &is_first_touch);
|
||||
@ -187,7 +188,7 @@ AC_Asset *F_LoadAsset(ResourceKey resource, f32 point_size, b32 wait)
|
||||
job->sig = sig;
|
||||
sig->asset = asset;
|
||||
sig->resource = resource;
|
||||
sig->point_size = point_size;
|
||||
sig->size = size;
|
||||
CloseJob(job);
|
||||
}
|
||||
if (wait)
|
||||
|
||||
@ -21,7 +21,7 @@ Struct(F_Font)
|
||||
u16 *lookup;
|
||||
|
||||
/* Metrics */
|
||||
f32 point_size;
|
||||
f32 size;
|
||||
f32 ascent;
|
||||
f32 descent;
|
||||
};
|
||||
@ -49,14 +49,14 @@ Struct(F_Run)
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Font load job
|
||||
|
||||
JobDecl(F_Load, { AC_Asset *asset; f32 point_size; ResourceKey resource; });
|
||||
JobDecl(F_Load, { AC_Asset *asset; f32 size; ResourceKey resource; });
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Font load operations
|
||||
|
||||
AC_Asset *F_LoadAsset(ResourceKey resource, f32 point_size, b32 wait);
|
||||
F_Font *F_LoadFontAsync(ResourceKey resource, f32 point_size);
|
||||
F_Font *F_LoadFontWait(ResourceKey resource, f32 point_size);
|
||||
AC_Asset *F_LoadAsset(ResourceKey resource, f32 size, b32 wait);
|
||||
F_Font *F_LoadFontAsync(ResourceKey resource, f32 size);
|
||||
F_Font *F_LoadFontWait(ResourceKey resource, f32 size);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Run operations
|
||||
|
||||
25
src/pp/pp.c
25
src/pp/pp.c
@ -99,15 +99,14 @@ ExitFuncDef(PP_ShutdownUser)
|
||||
void PP_PushGameUiStyle(void)
|
||||
{
|
||||
// UI_Push(FontSize, 48);
|
||||
// UI_Push(FontSize, 24);
|
||||
// UI_Push(FontSize, 32);
|
||||
|
||||
// UI_Push(Font, ResourceKeyFromStore(&PP_Resources, Lit("font/roboto-med.ttf")));
|
||||
UI_Push(Font, ResourceKeyFromStore(&PP_Resources, Lit("font/fixedsys.ttf")));
|
||||
UI_Push(FontSize, 12);
|
||||
UI_Push(FontSize, 16);
|
||||
|
||||
UI_Push(Rounding, 0);
|
||||
|
||||
UI_Push(TextPadding, 4);
|
||||
UI_Push(Border, 1);
|
||||
// UI_Push(BackgroundColor, Rgba32F(0.3, 0.5, 0.3, 0.3));
|
||||
UI_Push(BackgroundColor, Rgba32F(0.3, 0.3, 0.3, 1));
|
||||
@ -1968,14 +1967,14 @@ void PP_UpdateUser(void)
|
||||
UI_SetNext(Parent, lister_box);
|
||||
UI_SetNext(LayoutAxis, Axis_X);
|
||||
UI_SetNext(Width, UI_FILL(1, 0));
|
||||
UI_SetNext(Height, UI_TXT(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, title_bar);
|
||||
UI_Push(Width, UI_FILL(1, 0));
|
||||
UI_Push(TextPadding, 0);
|
||||
UI_Push(Padding, 0);
|
||||
UI_Push(BackgroundColor, 0);
|
||||
UI_Push(Border, 0);
|
||||
{
|
||||
@ -2016,13 +2015,13 @@ void PP_UpdateUser(void)
|
||||
UI_Push(Parent, dbg_box);
|
||||
UI_Push(BackgroundColor, 0);
|
||||
UI_Push(BorderColor, 0);
|
||||
UI_Push(TextPadding, 2);
|
||||
UI_Push(Padding, 2);
|
||||
|
||||
UI_BuildLabelF("Blended world entities: %F/%F", FmtUint(g->ss_blended->num_ents_allocated), FmtUint(g->ss_blended->num_ents_reserved));
|
||||
UI_BuildLabelF("Blended world tick: %F", FmtUint(g->ss_blended->tick));
|
||||
|
||||
UI_BuildLabelF("Blended world time: %F", FmtFloat(SecondsFromNs(g->ss_blended->sim_time_ns)));
|
||||
UI_BuildSpacer(UI_TXT(1, 0));
|
||||
UI_BuildSpacer(UI_FNT(1, 0));
|
||||
|
||||
UI_BuildLabelF("Average local sim publish dt: %F", FmtFloat(SecondsFromNs(g->average_local_to_user_snapshot_publish_dt_ns)));
|
||||
UI_BuildLabelF("Local sim last known tick: %F", FmtUint(g->local_sim_last_known_tick));
|
||||
@ -2033,7 +2032,7 @@ void PP_UpdateUser(void)
|
||||
UI_BuildLabelF("Render time: %F", FmtFloat(SecondsFromNs(g->render_time_ns)));
|
||||
|
||||
UI_BuildLabelF("Local player: [%F]", FmtUid(local_player->key.uid));
|
||||
UI_BuildSpacer(UI_TXT(1, 0));
|
||||
UI_BuildSpacer(UI_FNT(1, 0));
|
||||
|
||||
Vec2 world_cursor = g->world_cursor;
|
||||
UI_BuildLabelF("Cursor world: %F, %F", FmtFloat(world_cursor.x), FmtFloat(world_cursor.y));
|
||||
@ -2046,7 +2045,7 @@ void PP_UpdateUser(void)
|
||||
|
||||
Vec2I32 tile_chunk_cursor = PP_TileChunkIndexFromWorldTileIndex(world_tile_cursor);
|
||||
UI_BuildLabelF("Cursor tile chunk: %F, %F", FmtSint(tile_chunk_cursor.x), FmtSint(tile_chunk_cursor.y));
|
||||
UI_BuildSpacer(UI_TXT(1, 0));
|
||||
UI_BuildSpacer(UI_FNT(1, 0));
|
||||
|
||||
UI_BuildLabelF("Network read: %F mbit/s", FmtFloat((f64)g->net_bytes_read.last_second * 8 / 1000 / 1000));
|
||||
|
||||
@ -2055,18 +2054,18 @@ void PP_UpdateUser(void)
|
||||
UI_BuildLabelF("Ping (real): %F ms", FmtFloat(SecondsFromNs(local_player->player_last_rtt_ns) * 1000));
|
||||
|
||||
UI_BuildLabelF("Ping (average): %F ms", FmtFloat(local_player->player_average_rtt_seconds * 1000));
|
||||
UI_BuildSpacer(UI_TXT(1, 0));
|
||||
UI_BuildSpacer(UI_FNT(1, 0));
|
||||
|
||||
UI_BuildLabelF("Memory committed: %F MiB", FmtFloat((f64)GetGstat(GSTAT_MEMORY_COMMITTED) / 1024 / 1024));
|
||||
|
||||
UI_BuildLabelF("Virtual memory reserved: %F TiB", FmtFloat((f64)GetGstat(GSTAT_MEMORY_RESERVED) / 1024 / 1024 / 1024 / 1024));
|
||||
|
||||
UI_BuildLabelF("Arenas allocated: %F", FmtUint(GetGstat(GSTAT_NUM_ARENAS)));
|
||||
UI_BuildSpacer(UI_TXT(1, 0));
|
||||
UI_BuildSpacer(UI_FNT(1, 0));
|
||||
|
||||
UI_BuildLabelF("GPU dedicated memory usage: %F MiB", FmtFloat((f64)gpu_stats.local_committed / 1024 / 1024));
|
||||
UI_BuildLabelF("GPU shared memory usage: %F MiB", FmtFloat((f64)gpu_stats.non_local_committed / 1024 / 1024));
|
||||
UI_BuildSpacer(UI_TXT(1, 0));
|
||||
UI_BuildSpacer(UI_FNT(1, 0));
|
||||
|
||||
UI_BuildLabelF("GPU resources: %F", FmtUint(gpu_stats.driver_resources_allocated));
|
||||
UI_BuildLabelF("GPU descriptors: %F", FmtUint(gpu_stats.driver_descriptors_allocated));
|
||||
@ -2074,7 +2073,7 @@ void PP_UpdateUser(void)
|
||||
//UI_BuildLabelF(\n"));
|
||||
|
||||
#if RtcIsEnabled
|
||||
UI_BuildSpacer(UI_TXT(1, 0));
|
||||
UI_BuildSpacer(UI_FNT(1, 0));
|
||||
UI_BuildLabelF("Debug steps: %F", FmtUint(GetGstat(GSTAT_DEBUG_STEPS)));
|
||||
//UI_BuildLabelF(\n"));
|
||||
#endif
|
||||
|
||||
@ -130,7 +130,7 @@ UI_Box *PP_BuildDebugConsole(b32 minimized)
|
||||
{
|
||||
UI_SetNext(BackgroundColor, 0);
|
||||
UI_SetNext(Border, 0);
|
||||
UI_SetNext(TextPadding, 6);
|
||||
UI_SetNext(Padding, 6);
|
||||
UI_SetNext(Text, text);
|
||||
UI_SetNext(Width, UI_FILL(1, 0));
|
||||
UI_SetNext(Height, UI_FIT(1));
|
||||
|
||||
@ -23,4 +23,4 @@ Struct(TTF_Decoded)
|
||||
|
||||
void TTF_Startup(void);
|
||||
|
||||
TTF_Decoded TTF_Decode(Arena *arena, String encoded, f32 point_size, u32 *cache_codes, u32 cache_codes_count);
|
||||
TTF_Decoded TTF_Decode(Arena *arena, String encoded, f32 em_size, u32 *cache_codes, u32 cache_codes_count);
|
||||
|
||||
@ -38,7 +38,7 @@ void TTF_Startup(void)
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ @hookdef Decode
|
||||
|
||||
TTF_Decoded TTF_Decode(Arena *arena, String encoded, f32 point_size, u32 *cache_codes, u32 cache_codes_count)
|
||||
TTF_Decoded TTF_Decode(Arena *arena, String encoded, f32 em_size, u32 *cache_codes, u32 cache_codes_count)
|
||||
{
|
||||
__prof;
|
||||
TTF_DW_SharedState *g = &TTF_DW_shared_state;
|
||||
@ -93,7 +93,7 @@ TTF_Decoded TTF_Decode(Arena *arena, String encoded, f32 point_size, u32 *cache_
|
||||
|
||||
u16 glyph_count = IDWriteFontFace_GetGlyphCount(font_face);
|
||||
|
||||
f32 pixel_per_em = point_size * (TTF_DW_Dpi / 72.0f);
|
||||
f32 pixel_per_em = em_size * (TTF_DW_Dpi / 72.0f);
|
||||
f32 pixel_per_design_unit = pixel_per_em / ((f32)metrics.designUnitsPerEm);
|
||||
|
||||
i32 raster_target_w = (i32)(8.0f * ((f32)metrics.capHeight) * pixel_per_design_unit);
|
||||
@ -107,7 +107,7 @@ TTF_Decoded TTF_Decode(Arena *arena, String encoded, f32 point_size, u32 *cache_
|
||||
|
||||
//- Setup render target
|
||||
IDWriteBitmapRenderTarget *render_target = 0;
|
||||
/* FIXME: errors when point_size too high */
|
||||
/* FIXME: errors when em_size too high */
|
||||
error = IDWriteGdiInterop_CreateBitmapRenderTarget(dwrite_gdi_interop, 0, (UINT32)raster_target_w, (UINT32)raster_target_h, &render_target);
|
||||
IDWriteBitmapRenderTarget_SetPixelsPerDip(render_target, 1.0);
|
||||
|
||||
|
||||
@ -254,7 +254,7 @@ UI_Box *UI_BuildBox(String seed)
|
||||
box->border = UI_UseTop(Border);
|
||||
box->font_resource = UI_UseTop(Font);
|
||||
box->font_size = UI_UseTop(FontSize);
|
||||
box->text_padding = UI_UseTop(TextPadding);
|
||||
box->padding = UI_UseTop(Padding);
|
||||
box->rounding = UI_UseTop(Rounding);
|
||||
box->text = UI_UseTop(Text);
|
||||
box->floating_pos = UI_UseTop(FloatingPos);
|
||||
@ -589,7 +589,7 @@ i64 UI_EndBuild(GPU_Resource *render_target, Xform ui_to_screen_xf)
|
||||
text_size = box->font->ascent + box->font->descent;
|
||||
}
|
||||
}
|
||||
box->solved_dims[axis] = text_size + box->text_padding * 2;
|
||||
box->solved_dims[axis] = text_size + box->padding * 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -814,7 +814,7 @@ i64 UI_EndBuild(GPU_Resource *render_target, Xform ui_to_screen_xf)
|
||||
|
||||
f32 ascent = box->font->ascent;
|
||||
f32 descent = box->font->descent;
|
||||
f32 padding = box->text_padding;
|
||||
f32 padding = box->padding;
|
||||
|
||||
Vec2 baseline = box->p0;
|
||||
baseline = AddVec2(baseline, VEC2(padding, padding + ascent));
|
||||
|
||||
@ -57,7 +57,7 @@ Enum(UI_BoxFlag)
|
||||
x(Font, ResourceKey) \
|
||||
x(FontSize, u32) \
|
||||
x(Text, String) \
|
||||
x(TextPadding, f32) \
|
||||
x(Padding, f32) \
|
||||
x(Rounding, f32) \
|
||||
x(FloatingPos, Vec2) \
|
||||
/* ------------------------------------------- */
|
||||
@ -157,7 +157,7 @@ Struct(UI_Box)
|
||||
u32 text_color;
|
||||
u32 tint;
|
||||
f32 border;
|
||||
f32 text_padding;
|
||||
f32 padding;
|
||||
f32 rounding;
|
||||
Vec2 floating_pos;
|
||||
String text;
|
||||
@ -274,7 +274,7 @@ UI_Style UI_StyleFromTopNode(UI_StyleKind kind, b32 use);
|
||||
#define UI_PIX(_v, _s) UI_SIZE(UI_SizeKind_Pixel, (_v), (_s))
|
||||
#define UI_FIT(_s) UI_SIZE(UI_SizeKind_Fit, 0, (_s))
|
||||
#define UI_FILL(_v, _s) UI_SIZE(UI_SizeKind_Fill, (_v), (_s))
|
||||
#define UI_TXT(_v, _s) UI_SIZE(UI_SizeKind_Pixel, (f32)UI_PeekTop(FontSize) * (4.0 / 3.0) * (_v), (_s))
|
||||
#define UI_FNT(_v, _s) UI_SIZE(UI_SizeKind_Pixel, (f32)UI_PeekTop(FontSize) * (_v), (_s))
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Box
|
||||
|
||||
Loading…
Reference in New Issue
Block a user