From 70b752eccbc4936dd84e3a492feac889c3012c09 Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Fri, 30 Jan 2026 21:44:46 +0100 Subject: [PATCH] Fix line number clipping, rendering issue --- src/basic/math_int.cpp | 8 ++++++++ src/render/opengl.cpp | 13 ++----------- src/text_editor/draw.cpp | 2 +- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/basic/math_int.cpp b/src/basic/math_int.cpp index dcb95d7..6298b1b 100644 --- a/src/basic/math_int.cpp +++ b/src/basic/math_int.cpp @@ -90,6 +90,14 @@ Vec2I GetMid(Rect2I r) { return result; } +Rect2 Round(Rect2 r) { + r.min.x = roundf(r.min.x); + r.max.x = roundf(r.max.x); + r.min.y = roundf(r.min.y); + r.max.y = roundf(r.max.y); + return r; +} + Rect2I CutLeft(Rect2I *r, Int value) { Int minx = r->min.x; r->min.x = Min(r->min.x + value, r->max.x); diff --git a/src/render/opengl.cpp b/src/render/opengl.cpp index e6f1bf3..902fb62 100644 --- a/src/render/opengl.cpp +++ b/src/render/opengl.cpp @@ -288,7 +288,7 @@ void PushVertex2D(Allocator allocator, VertexList2D *list, Vertex2D *vertices, i for (int i = 0; i < count; i += 1) result[i] = vertices[i]; } -void PushQuad2D(Allocator arena, VertexList2D *list, Rect2 rect, Rect2 tex, Color color, float rotation = 0.f, Vec2 rotation_point = {}) { +void PushQuad2D(Allocator arena, VertexList2D *list, Rect2 rect, Rect2 tex, Color color) { Vertex2D *v = AllocVertex2D(arena, list, 6); v[0] = { {rect.min.x, rect.max.y}, { tex.min.x, tex.max.y}, color }; v[1] = { {rect.max.x, rect.max.y}, { tex.max.x, tex.max.y}, color }; @@ -296,15 +296,6 @@ void PushQuad2D(Allocator arena, VertexList2D *list, Rect2 rect, Rect2 tex, Colo v[3] = { {rect.min.x, rect.min.y}, { tex.min.x, tex.min.y}, color }; v[4] = { {rect.max.x, rect.max.y}, { tex.max.x, tex.max.y}, color }; v[5] = { {rect.max.x, rect.min.y}, { tex.max.x, tex.min.y}, color }; - if (rotation != 0.f) { - float s = sinf(rotation); - float c = cosf(rotation); - for (int i = 0; i < 6; i += 1) { - v[i].pos -= rotation_point; - v[i].pos = {v[i].pos.x * c + v[i].pos.y * (-s), v[i].pos.x * s + v[i].pos.y * c}; - v[i].pos += rotation_point; - } - } } void DrawRect(Rect2 rect, Color color) { @@ -336,7 +327,7 @@ Vec2 DrawString(Font *font, String16 string, Vec2 pos, Color color, bool draw = Glyph *g = GetGlyph(font, it); Rect2 rect = Rect2FromSize(pos + g->offset, g->size); if (draw && it != '\n' && it != ' ' && it != '\t') { - PushQuad2D(RenderArena, &Vertices, rect, g->atlas_bounding_box, color); + PushQuad2D(RenderArena, &Vertices, Round(rect), g->atlas_bounding_box, color); } pos.x += g->xadvance; } diff --git a/src/text_editor/draw.cpp b/src/text_editor/draw.cpp index 3bb419c..b73cf7e 100644 --- a/src/text_editor/draw.cpp +++ b/src/text_editor/draw.cpp @@ -65,7 +65,7 @@ void DrawVisibleText(Window *window, Color tint) { Rect2 rect = Rect2FromSize(p + g->offset, g->size); if (codepoint != '\n' && codepoint != '\r' && codepoint != ' ' && codepoint != '\t') { - PushQuad2D(RenderArena, &Vertices, rect, g->atlas_bounding_box, tint); + PushQuad2D(RenderArena, &Vertices, Round(rect), g->atlas_bounding_box, tint); } text_offset_x += window->font->char_spacing;