Move globals to text_editor.h

This commit is contained in:
Krzosa Karol
2024-07-23 09:09:18 +02:00
parent 5f18779f1d
commit 7249bbf92b
3 changed files with 21 additions and 26 deletions

View File

@@ -1,35 +1,21 @@
#define BASIC_IMPL #define BASIC_IMPL
#include "../basic/basic.h" #include "../basic/basic.h"
#include "../profiler/profiler.cpp"
#include "new_basic.cpp" #include "new_basic.cpp"
#include "string16.cpp" #include "string16.cpp"
#include <math.h> #include <math.h>
#include "math_int.cpp" #include "math_int.cpp"
#include "math.cpp" #include "math.cpp"
#include "raylib.h"
#include "../profiler/profiler.cpp"
#include "text_editor.h" #include "text_editor.h"
#include "buffer_helpers.cpp" #include "buffer_helpers.cpp"
#include "buffer.cpp" #include "buffer.cpp"
#include "buffer_multi_cursor.cpp" #include "buffer_multi_cursor.cpp"
#include "buffer_history.cpp" #include "buffer_history.cpp"
#include "buffer_test_load.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 "commands.cpp"
#include "colors.cpp" #include "colors.cpp"
#include "raylib_utils.cpp"
#include "windows.cpp" #include "windows.cpp"
#include "view_commands_clipboard.cpp" #include "view_commands_clipboard.cpp"
#include "view_commands.cpp" #include "view_commands.cpp"
@@ -78,8 +64,8 @@ int main(void) {
FontSize = 16; FontSize = 16;
FontSpacing = 1; FontSpacing = 1;
FontLineSpacing = FontSize; FontLineSpacing = FontSize;
Font = LoadFontEx("c:\\Windows\\Fonts\\consola.ttf", (int)FontSize, NULL, 500); MainFont = LoadFontEx("c:\\Windows\\Fonts\\consola.ttf", (int)FontSize, NULL, 500);
FontCharSpacing = GetCharSpacing(Font, FontSize, FontSpacing); FontCharSpacing = GetCharSpacing(MainFont, FontSize, FontSpacing);
// Create null // Create null
{ {
@@ -143,7 +129,7 @@ int main(void) {
ProfileScope(game_loop); ProfileScope(game_loop);
Rect2I screen_rect = GetScreenRect(); 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].total_rect = CutLeft(&screen_rect, (Int)((double)GetSize(screen_rect).x * 0.33));
Windows[1].document_rect = Windows[1].total_rect; Windows[1].document_rect = Windows[1].total_rect;

View File

@@ -83,6 +83,15 @@ Array<View> Views = {};
Array<Window> Windows = {}; Array<Window> Windows = {};
WindowID ActiveWindow = {}; WindowID ActiveWindow = {};
float MenuFontSize = 19.f;
Font MenuFont;
Font MainFont;
Int FontSize;
Int FontSpacing;
Int FontLineSpacing;
Int FontCharSpacing;
inline Window *GetWindow(WindowID id) { inline Window *GetWindow(WindowID id) {
For(Windows) if (it.id.id == id.id) return &it; For(Windows) if (it.id.id == id.id) return &it;
return &Windows[0]; return &Windows[0];

View File

@@ -56,18 +56,18 @@ void DrawVisibleText(Window &window) {
float text_offset_x = 0; 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) { 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 codepoint = line_string[col_index];
int index = GetGlyphIndex(Font, codepoint); int index = GetGlyphIndex(MainFont, codepoint);
if (codepoint == '\n' || codepoint == '\r') { 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); // 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 == ' ') { } 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); // 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') { } 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); if (MainFont.glyphs[index].advanceX == 0) text_offset_x += ((float)MainFont.recs[index].width + FontSpacing);
else text_offset_x += ((float)Font.glyphs[index].advanceX + FontSpacing); else text_offset_x += ((float)MainFont.glyphs[index].advanceX + FontSpacing);
} }
} }
} }
@@ -201,12 +201,12 @@ void DrawWindow(Window &window) {
pos += r.min; pos += r.min;
String s = Format(scratch, "%lld", (long long)line); String s = Format(scratch, "%lld", (long long)line);
String16 string = ToString16(scratch, s); 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); Vec2 p = ToVec2(pos);
float rectx = (float)GetSize(r).x; float rectx = (float)GetSize(r).x;
p.x += (rectx - x) / 2.f; p.x += (rectx - x) / 2.f;
if (x > rectx) p.x = 0; 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(); EndScissorMode();