mirror of
https://github.com/Ed94/raddebugger.git
synced 2026-08-04 21:08:40 +00:00
extend font provider backend with ability to independently toggle hinting & full anti-aliasing; fix up ui text measurement/placement; introduce per-window settings for adjusting font rendering parameters
This commit is contained in:
+14
-153
@@ -87,7 +87,7 @@ d_string_from_fancy_string_list(Arena *arena, D_FancyStringList *list)
|
||||
}
|
||||
|
||||
internal D_FancyRunList
|
||||
d_fancy_run_list_from_fancy_string_list(Arena *arena, F32 tab_size_px, F_RunFlags flags, D_FancyStringList *strs)
|
||||
d_fancy_run_list_from_fancy_string_list(Arena *arena, F32 tab_size_px, F_RasterFlags flags, D_FancyStringList *strs)
|
||||
{
|
||||
ProfBeginFunction();
|
||||
D_FancyRunList run_list = {0};
|
||||
@@ -104,11 +104,6 @@ d_fancy_run_list_from_fancy_string_list(Arena *arena, F32 tab_size_px, F_RunFlag
|
||||
run_list.dim.x += dst_n->v.run.dim.x;
|
||||
run_list.dim.y = Max(run_list.dim.y, dst_n->v.run.dim.y);
|
||||
base_align_px += dst_n->v.run.dim.x;
|
||||
if(n->next != 0)
|
||||
{
|
||||
run_list.dim.x -= dst_n->v.run.end_pad;
|
||||
base_align_px -= dst_n->v.run.end_pad;
|
||||
}
|
||||
}
|
||||
ProfEnd();
|
||||
return run_list;
|
||||
@@ -465,7 +460,7 @@ d_truncated_fancy_run_list(Vec2F32 p, D_FancyRunList *list, F32 max_x, F_Run tra
|
||||
ProfBeginFunction();
|
||||
|
||||
//- rjf: total advance > max? -> enable trailer
|
||||
B32 trailer_enabled = (list->dim.x >= max_x && trailer_run.dim.x < max_x);
|
||||
B32 trailer_enabled = (list->dim.x > max_x && trailer_run.dim.x < max_x);
|
||||
|
||||
//- rjf: draw runs
|
||||
F32 advance = 0;
|
||||
@@ -483,18 +478,17 @@ d_truncated_fancy_run_list(Vec2F32 p, D_FancyRunList *list, F32 max_x, F_Run tra
|
||||
F_Piece *piece_first = fr->run.pieces.v;
|
||||
F_Piece *piece_opl = piece_first + fr->run.pieces.count;
|
||||
F32 pre_advance = advance;
|
||||
F32 last_piece_end_pad = 0;
|
||||
last_color = fr->color;
|
||||
for(F_Piece *piece = piece_first;
|
||||
piece < piece_opl;
|
||||
piece += 1)
|
||||
{
|
||||
if(trailer_enabled && advance + piece->advance >= (max_x - trailer_run.dim.x))
|
||||
if(trailer_enabled && advance + piece->advance > (max_x - trailer_run.dim.x))
|
||||
{
|
||||
trailer_found = 1;
|
||||
break;
|
||||
}
|
||||
if(!trailer_enabled && advance + piece->advance >= max_x)
|
||||
if(!trailer_enabled && advance + piece->advance > max_x)
|
||||
{
|
||||
goto end_draw;
|
||||
}
|
||||
@@ -508,18 +502,17 @@ d_truncated_fancy_run_list(Vec2F32 p, D_FancyRunList *list, F32 max_x, F_Run tra
|
||||
if(!r_handle_match(texture, r_handle_zero()))
|
||||
{
|
||||
d_img(dst, src, texture, fr->color, 0, 0, 0);
|
||||
//d_rect(dst, v4f32(1, 0, 0, 1), 0, 1.f, 0.f);
|
||||
//d_rect(dst, v4f32(0, 1, 0, 0.5f), 0, 1.f, 0.f);
|
||||
}
|
||||
advance += piece->advance;
|
||||
last_piece_end_pad = ((F32)piece->offset.x+(F32)dim_2s16(piece->subrect).x) - piece->advance;
|
||||
pixel_range.min = Min(pre_advance, pixel_range.min);
|
||||
pixel_range.max = Max(advance, pixel_range.max);
|
||||
}
|
||||
if(fr->underline_thickness > 0)
|
||||
{
|
||||
d_rect(r2f32p(p.x + pixel_range.min + 1.f,
|
||||
d_rect(r2f32p(p.x + pixel_range.min,
|
||||
p.y+fr->run.descent+fr->run.descent/8,
|
||||
p.x + pixel_range.max + last_piece_end_pad/2,
|
||||
p.x + pixel_range.max,
|
||||
p.y+fr->run.descent+fr->run.descent/8+fr->underline_thickness),
|
||||
fr->color, 0, 0, 0.8f);
|
||||
}
|
||||
@@ -591,9 +584,8 @@ d_truncated_fancy_run_fuzzy_matches(Vec2F32 p, D_FancyRunList *list, F32 max_x,
|
||||
F_Piece *piece = &run->pieces.v[piece_idx];
|
||||
if(contains_1u64(byte_range, byte_off))
|
||||
{
|
||||
F32 pre_advance = advance+piece->offset.x;
|
||||
F32 post_advance = advance+piece->advance;
|
||||
last_piece_end_pad = ((F32)piece->offset.x+(F32)dim_2s16(piece->subrect).x) - piece->advance;
|
||||
F32 pre_advance = advance + piece->offset.x;
|
||||
F32 post_advance = advance + piece->advance;
|
||||
pixel_range.min = Min(pre_advance, pixel_range.min);
|
||||
pixel_range.max = Max(post_advance, pixel_range.max);
|
||||
}
|
||||
@@ -603,8 +595,10 @@ d_truncated_fancy_run_fuzzy_matches(Vec2F32 p, D_FancyRunList *list, F32 max_x,
|
||||
}
|
||||
if(pixel_range.min < pixel_range.max)
|
||||
{
|
||||
Rng2F32 rect = r2f32p(p.x + pixel_range.min, p.y - descent - ascent,
|
||||
p.x + pixel_range.max + last_piece_end_pad/2, p.y - descent - ascent + list->dim.y);
|
||||
Rng2F32 rect = r2f32p(p.x + pixel_range.min - ascent/4.f,
|
||||
p.y - descent - ascent - ascent/8.f,
|
||||
p.x + pixel_range.max + ascent/4.f,
|
||||
p.y - descent - ascent + ascent/8.f + list->dim.y);
|
||||
rect.x0 = Min(rect.x0, p.x+max_x);
|
||||
rect.x1 = Min(rect.x1, p.x+max_x);
|
||||
d_rect(rect, color, (descent+ascent)/4.f, 0, 1.f);
|
||||
@@ -638,143 +632,10 @@ d_text_run(Vec2F32 p, Vec4F32 color, F_Run run)
|
||||
}
|
||||
|
||||
internal void
|
||||
d_truncated_text_run(Vec2F32 p, Vec4F32 color, F32 max_x, F_Run text_run, F_Run trailer_run)
|
||||
{
|
||||
B32 truncated = 0;
|
||||
B32 set_truncation = 0;
|
||||
F32 truncation_p = p.x;
|
||||
F32 max_x_minus_ellipses = max_x - trailer_run.dim.x;
|
||||
F32 available_space = max_x - p.x;
|
||||
|
||||
// rjf: find last piece before truncation
|
||||
B32 truncation_needed = 0;
|
||||
F_Piece *last_piece_before_truncation = 0;
|
||||
F32 truncation_offset = 0;
|
||||
if(available_space > text_run.dim.x || available_space > trailer_run.dim.x)
|
||||
{
|
||||
F32 advance = 0;
|
||||
F_Piece *text_run_first = text_run.pieces.v;
|
||||
F_Piece *text_run_opl = text_run_first + text_run.pieces.count;
|
||||
for(F_Piece *piece = text_run_first;
|
||||
piece < text_run_opl;
|
||||
piece += 1)
|
||||
{
|
||||
Rng2F32 src = r2f32p((F32)piece->subrect.x0, (F32)piece->subrect.y0, (F32)piece->subrect.x1, (F32)piece->subrect.y1);
|
||||
Vec2F32 size = dim_2f32(src);
|
||||
Rng2F32 dst = r2f32p(p.x + piece->offset.x + advance,
|
||||
p.y + piece->offset.y,
|
||||
p.x + piece->offset.x + advance + size.x,
|
||||
p.y + piece->offset.y + size.y);
|
||||
advance += piece->advance;
|
||||
if(last_piece_before_truncation == 0 && p.x + advance > max_x_minus_ellipses)
|
||||
{
|
||||
truncation_offset = advance - piece->advance;
|
||||
last_piece_before_truncation = piece;
|
||||
}
|
||||
if(p.x + advance > max_x)
|
||||
{
|
||||
truncation_needed = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// rjf: draw pieces
|
||||
if(available_space > text_run.dim.x || available_space > trailer_run.dim.x)
|
||||
{
|
||||
F32 advance = 0;
|
||||
F_Piece *text_run_first = text_run.pieces.v;
|
||||
F_Piece *text_run_opl = text_run_first + text_run.pieces.count;
|
||||
for(F_Piece *piece = text_run_first;
|
||||
piece < text_run_opl;
|
||||
piece += 1)
|
||||
{
|
||||
if(truncation_needed && piece == last_piece_before_truncation)
|
||||
{
|
||||
break;
|
||||
}
|
||||
R_Handle texture = piece->texture;
|
||||
Rng2F32 src = r2f32p((F32)piece->subrect.x0, (F32)piece->subrect.y0, (F32)piece->subrect.x1, (F32)piece->subrect.y1);
|
||||
Vec2F32 size = dim_2f32(src);
|
||||
Rng2F32 dst = r2f32p(p.x + piece->offset.x + advance,
|
||||
p.y + piece->offset.y,
|
||||
p.x + piece->offset.x + advance + size.x,
|
||||
p.y + piece->offset.y + size.y);
|
||||
if(size.x != 0 && size.y != 0 && !r_handle_match(texture, r_handle_zero()))
|
||||
{
|
||||
d_img(dst, src, texture, color, 0, 0, 0);
|
||||
}
|
||||
advance += piece->advance;
|
||||
}
|
||||
}
|
||||
|
||||
// rjf: draw truncation ellipses
|
||||
if(truncation_needed && last_piece_before_truncation != 0)
|
||||
{
|
||||
Vec2F32 ellipses_p = {p.x + truncation_offset, p.y};
|
||||
Vec4F32 ellipses_color = color;
|
||||
F32 advance = 0;
|
||||
F_Piece *trailer_run_first = trailer_run.pieces.v;
|
||||
F_Piece *trailer_run_opl = trailer_run_first + trailer_run.pieces.count;
|
||||
for(F_Piece *piece = trailer_run_first;
|
||||
piece < trailer_run_opl;
|
||||
piece += 1)
|
||||
{
|
||||
R_Handle texture = piece->texture;
|
||||
Rng2F32 src = r2f32p((F32)piece->subrect.x0, (F32)piece->subrect.y0, (F32)piece->subrect.x1, (F32)piece->subrect.y1);
|
||||
Vec2F32 size = dim_2f32(src);
|
||||
Rng2F32 dst = r2f32p(ellipses_p.x + piece->offset.x + advance,
|
||||
ellipses_p.y + piece->offset.y,
|
||||
ellipses_p.x + piece->offset.x + advance + size.x,
|
||||
ellipses_p.y + piece->offset.y + size.y);
|
||||
if(size.x != 0 && size.y != 0 && !r_handle_match(texture, r_handle_zero()))
|
||||
{
|
||||
d_img(dst, src, texture, ellipses_color, 0, 0, 0);
|
||||
}
|
||||
ellipses_color.w *= 0.5f;
|
||||
advance += piece->advance;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal void
|
||||
d_text(F_Tag font, F32 size, F32 base_align_px, F32 tab_size_px, F_RunFlags flags, Vec2F32 p, Vec4F32 color, String8 string)
|
||||
d_text(F_Tag font, F32 size, F32 base_align_px, F32 tab_size_px, F_RasterFlags flags, Vec2F32 p, Vec4F32 color, String8 string)
|
||||
{
|
||||
Temp scratch = scratch_begin(0, 0);
|
||||
F_Run run = f_push_run_from_string(scratch.arena, font, size, base_align_px, tab_size_px, flags, string);
|
||||
d_text_run(p, color, run);
|
||||
scratch_end(scratch);
|
||||
}
|
||||
|
||||
internal void
|
||||
d_textf(F_Tag font, F32 size, F32 base_align_px, F32 tab_size_px, F_RunFlags flags, Vec2F32 p, Vec4F32 color, char *fmt, ...)
|
||||
{
|
||||
Temp scratch = scratch_begin(0, 0);
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
String8 string = push_str8fv(scratch.arena, fmt, args);
|
||||
va_end(args);
|
||||
d_text(font, size, base_align_px, tab_size_px, flags, p, color, string);
|
||||
scratch_end(scratch);
|
||||
}
|
||||
|
||||
internal void
|
||||
d_truncated_text(F_Tag font, F32 size, F32 base_align_px, F32 tab_size_px, F_RunFlags flags, Vec2F32 p, Vec4F32 color, F32 max_x, String8 string)
|
||||
{
|
||||
Temp scratch = scratch_begin(0, 0);
|
||||
F_Run run = f_push_run_from_string(scratch.arena, font, size, base_align_px, tab_size_px, flags, string);
|
||||
F_Run ellipses_run = f_push_run_from_string(scratch.arena, font, size, base_align_px, tab_size_px, 0, str8_lit("..."));
|
||||
d_truncated_text_run(p, color, max_x, run, ellipses_run);
|
||||
scratch_end(scratch);
|
||||
}
|
||||
|
||||
internal void
|
||||
d_truncated_textf(F_Tag font, F32 size, F32 base_align_px, F32 tab_size_px, F_RunFlags flags, Vec2F32 p, Vec4F32 color, F32 max_x, char *fmt, ...)
|
||||
{
|
||||
Temp scratch = scratch_begin(0, 0);
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
String8 string = push_str8f(scratch.arena, fmt, args);
|
||||
d_truncated_text(font, size, base_align_px, tab_size_px, flags, p, color, max_x, string);
|
||||
va_end(args);
|
||||
scratch_end(scratch);
|
||||
}
|
||||
|
||||
+2
-6
@@ -111,7 +111,7 @@ internal U64 d_hash_from_string(String8 string);
|
||||
internal void d_fancy_string_list_push(Arena *arena, D_FancyStringList *list, D_FancyString *str);
|
||||
internal void d_fancy_string_list_concat_in_place(D_FancyStringList *dst, D_FancyStringList *to_push);
|
||||
internal String8 d_string_from_fancy_string_list(Arena *arena, D_FancyStringList *list);
|
||||
internal D_FancyRunList d_fancy_run_list_from_fancy_string_list(Arena *arena, F32 tab_size_px, F_RunFlags flags, D_FancyStringList *strs);
|
||||
internal D_FancyRunList d_fancy_run_list_from_fancy_string_list(Arena *arena, F32 tab_size_px, F_RasterFlags flags, D_FancyStringList *strs);
|
||||
internal D_FancyRunList d_fancy_run_list_copy(Arena *arena, D_FancyRunList *src);
|
||||
|
||||
////////////////////////////////
|
||||
@@ -186,10 +186,6 @@ internal void d_sub_bucket(D_Bucket *bucket);
|
||||
internal void d_truncated_fancy_run_list(Vec2F32 p, D_FancyRunList *list, F32 max_x, F_Run trailer_run);
|
||||
internal void d_truncated_fancy_run_fuzzy_matches(Vec2F32 p, D_FancyRunList *list, F32 max_x, FuzzyMatchRangeList *ranges, Vec4F32 color);
|
||||
internal void d_text_run(Vec2F32 p, Vec4F32 color, F_Run run);
|
||||
internal void d_truncated_text_run(Vec2F32 p, Vec4F32 color, F32 max_x, F_Run text_run, F_Run trailer_run);
|
||||
internal void d_text(F_Tag font, F32 size, F32 base_align_px, F32 tab_size_px, F_RunFlags flags, Vec2F32 p, Vec4F32 color, String8 string);
|
||||
internal void d_textf(F_Tag font, F32 size, F32 base_align_px, F32 tab_size_px, F_RunFlags flags, Vec2F32 p, Vec4F32 color, char *fmt, ...);
|
||||
internal void d_truncated_text(F_Tag font, F32 size, F32 base_align_px, F32 tab_size_px, F_RunFlags flags, Vec2F32 p, Vec4F32 color, F32 max_x, String8 string);
|
||||
internal void d_truncated_textf(F_Tag font, F32 size, F32 base_align_px, F32 tab_size_px, F_RunFlags flags, Vec2F32 p, Vec4F32 color, F32 max_x, char *fmt, ...);
|
||||
internal void d_text(F_Tag font, F32 size, F32 base_align_px, F32 tab_size_px, F_RasterFlags flags, Vec2F32 p, Vec4F32 color, String8 string);
|
||||
|
||||
#endif // DRAW_H
|
||||
|
||||
Reference in New Issue
Block a user