Improve font rendering
This commit is contained in:
@@ -299,8 +299,19 @@ void DrawRect(Rect2I rect, Color color) {
|
||||
PushQuad2D(RenderArena, &Vertices, ToRect2(rect), MainFont.white_texture_bounding_box, color);
|
||||
}
|
||||
|
||||
Int GetCharSpacing(Font *font, int codepoint = '_') {
|
||||
Glyph *g = GetGlyph(font, codepoint);
|
||||
if (g->xadvance) return (Int)g->xadvance;
|
||||
return (Int)g->size.x;
|
||||
}
|
||||
|
||||
Int GetLineSpacing(Font *font) {
|
||||
Int result = (Int)(font->ascent - font->descent + font->line_gap);
|
||||
return result;
|
||||
}
|
||||
|
||||
Vec2 DrawString(Font *font, String16 string, Vec2 pos, Color color, bool draw = true) {
|
||||
pos.y += font->ascent - font->descent;
|
||||
pos.y += GetLineSpacing(font) + font->descent;
|
||||
Vec2 original_pos = pos;
|
||||
For(string) {
|
||||
Glyph *g = GetGlyph(font, it);
|
||||
@@ -346,17 +357,6 @@ void DrawCircle(Vec2 pos, float radius, Color color) {
|
||||
}
|
||||
}
|
||||
|
||||
Int GetCharSpacing(Font *font, int codepoint = '_') {
|
||||
Glyph *g = GetGlyph(font, codepoint);
|
||||
if (g->xadvance) return (Int)g->xadvance;
|
||||
return (Int)g->size.x;
|
||||
}
|
||||
|
||||
Int GetLineSpacing(Font *font) {
|
||||
Int result = (Int)(font->ascent - font->descent + font->line_gap);
|
||||
return result;
|
||||
}
|
||||
|
||||
String FontPath = "C:\\Windows\\Fonts\\consola.ttf";
|
||||
void ReloadFont(int32_t size) {
|
||||
size = ClampBottom(2, size);
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
- bugs:
|
||||
- scrolling when clicking on scroller is busted
|
||||
|
||||
- Windows
|
||||
- Mark windows as absolute or non-automatic layout and then just loop through windows
|
||||
- layouting, resize windows
|
||||
|
||||
@@ -57,7 +57,8 @@ void DrawVisibleText(Window *window) {
|
||||
int codepoint = line_string[col_index];
|
||||
Glyph *g = GetGlyph(&MainFont, codepoint);
|
||||
Vec2 p = ToVec2(pos);
|
||||
p.y += MainFont.ascent - MainFont.descent;
|
||||
// p.y += MainFont.ascent - MainFont.descent;
|
||||
p.y += FontLineSpacing + MainFont.descent;
|
||||
p.x += text_offset_x;
|
||||
Rect2 rect = Rect2FromSize(p + g->offset, g->size);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user