From 7249bbf92b0318279ff19a5577f806e638dbff2b Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Tue, 23 Jul 2024 09:09:18 +0200 Subject: [PATCH] Move globals to text_editor.h --- src/text_editor/text_editor.cpp | 26 ++++++-------------------- src/text_editor/text_editor.h | 9 +++++++++ src/text_editor/view_draw.cpp | 12 ++++++------ 3 files changed, 21 insertions(+), 26 deletions(-) diff --git a/src/text_editor/text_editor.cpp b/src/text_editor/text_editor.cpp index d63f1d9..0f6d64a 100644 --- a/src/text_editor/text_editor.cpp +++ b/src/text_editor/text_editor.cpp @@ -1,35 +1,21 @@ #define BASIC_IMPL #include "../basic/basic.h" +#include "../profiler/profiler.cpp" #include "new_basic.cpp" #include "string16.cpp" #include #include "math_int.cpp" #include "math.cpp" - -#include "../profiler/profiler.cpp" - +#include "raylib.h" #include "text_editor.h" #include "buffer_helpers.cpp" #include "buffer.cpp" #include "buffer_multi_cursor.cpp" #include "buffer_history.cpp" #include "buffer_test_load.cpp" - -#include "raylib.h" -#include "raylib_utils.cpp" - -float MenuFontSize = 19.f; -Font MenuFont; - -Font Font; -Int FontSize; -Int FontSpacing; -Int FontLineSpacing; -Int FontCharSpacing; - #include "commands.cpp" #include "colors.cpp" - +#include "raylib_utils.cpp" #include "windows.cpp" #include "view_commands_clipboard.cpp" #include "view_commands.cpp" @@ -78,8 +64,8 @@ int main(void) { FontSize = 16; FontSpacing = 1; FontLineSpacing = FontSize; - Font = LoadFontEx("c:\\Windows\\Fonts\\consola.ttf", (int)FontSize, NULL, 500); - FontCharSpacing = GetCharSpacing(Font, FontSize, FontSpacing); + MainFont = LoadFontEx("c:\\Windows\\Fonts\\consola.ttf", (int)FontSize, NULL, 500); + FontCharSpacing = GetCharSpacing(MainFont, FontSize, FontSpacing); // Create null { @@ -143,7 +129,7 @@ int main(void) { ProfileScope(game_loop); Rect2I screen_rect = GetScreenRect(); - float line_numbers_size = MeasureTextEx(Font, "12345", (float)FontSize, (float)FontSpacing).x; + float line_numbers_size = MeasureTextEx(MainFont, "12345", (float)FontSize, (float)FontSpacing).x; { Windows[1].total_rect = CutLeft(&screen_rect, (Int)((double)GetSize(screen_rect).x * 0.33)); Windows[1].document_rect = Windows[1].total_rect; diff --git a/src/text_editor/text_editor.h b/src/text_editor/text_editor.h index d9a441f..b9d32d6 100644 --- a/src/text_editor/text_editor.h +++ b/src/text_editor/text_editor.h @@ -83,6 +83,15 @@ Array Views = {}; Array Windows = {}; WindowID ActiveWindow = {}; +float MenuFontSize = 19.f; +Font MenuFont; + +Font MainFont; +Int FontSize; +Int FontSpacing; +Int FontLineSpacing; +Int FontCharSpacing; + inline Window *GetWindow(WindowID id) { For(Windows) if (it.id.id == id.id) return ⁢ return &Windows[0]; diff --git a/src/text_editor/view_draw.cpp b/src/text_editor/view_draw.cpp index b41ca58..4686007 100644 --- a/src/text_editor/view_draw.cpp +++ b/src/text_editor/view_draw.cpp @@ -56,18 +56,18 @@ void DrawVisibleText(Window &window) { float text_offset_x = 0; for (Int col_index = visible.min.x; col_index < visible.max.x && col_index >= 0 && col_index < line_string.len; col_index += 1) { int codepoint = line_string[col_index]; - int index = GetGlyphIndex(Font, codepoint); + int index = GetGlyphIndex(MainFont, codepoint); if (codepoint == '\n' || codepoint == '\r') { // DrawCircle((int)pos.x + (int)text_offset_x + (int)FontCharSpacing / 2, (int)pos.y + (int)FontLineSpacing / 2, (float)FontSize / 10.f, tint); } else if (codepoint == ' ') { // DrawCircle((int)pos.x + (int)text_offset_x + (int)FontCharSpacing / 2, (int)pos.y + (int)FontLineSpacing / 2, (float)FontSize / 10.f, space_color); } else if (codepoint != '\t') { - DrawTextCodepoint(Font, codepoint, {(float)pos.x + text_offset_x, (float)pos.y}, (float)FontSize, tint); + DrawTextCodepoint(MainFont, codepoint, {(float)pos.x + text_offset_x, (float)pos.y}, (float)FontSize, tint); } - if (Font.glyphs[index].advanceX == 0) text_offset_x += ((float)Font.recs[index].width + FontSpacing); - else text_offset_x += ((float)Font.glyphs[index].advanceX + FontSpacing); + if (MainFont.glyphs[index].advanceX == 0) text_offset_x += ((float)MainFont.recs[index].width + FontSpacing); + else text_offset_x += ((float)MainFont.glyphs[index].advanceX + FontSpacing); } } } @@ -201,12 +201,12 @@ void DrawWindow(Window &window) { pos += r.min; String s = Format(scratch, "%lld", (long long)line); String16 string = ToString16(scratch, s); - float x = MeasureTextEx(Font, s.data, (float)FontSize, (float)FontSpacing).x; + float x = MeasureTextEx(MainFont, s.data, (float)FontSize, (float)FontSpacing).x; Vec2 p = ToVec2(pos); float rectx = (float)GetSize(r).x; p.x += (rectx - x) / 2.f; if (x > rectx) p.x = 0; - DrawString(Font, string, p, (float)FontSize, (float)FontSpacing, ColorTextLineNumbers); + DrawString(MainFont, string, p, (float)FontSize, (float)FontSpacing, ColorTextLineNumbers); } EndScissorMode();