Restructure and reload font

This commit is contained in:
Krzosa Karol
2024-07-27 11:35:14 +02:00
parent a43fe1789b
commit 03eece4e41
6 changed files with 544 additions and 691 deletions

View File

@@ -360,3 +360,29 @@ 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);
if (MainFont.texture_id) {
glDeleteTextures(1, &MainFont.texture_id);
Dealloc(&MainFont.glyphs);
MainFont = {};
}
Scratch scratch;
Atlas atlas = CreateAtlas(scratch, {1024, 1024});
MainFont = CreateFont(&atlas, size, FontPath);
{
glCreateTextures(GL_TEXTURE_2D, 1, &atlas.texture_id);
glTextureParameteri(atlas.texture_id, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTextureParameteri(atlas.texture_id, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTextureParameteri(atlas.texture_id, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTextureParameteri(atlas.texture_id, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTextureStorage2D(atlas.texture_id, 1, GL_R8, (GLsizei)atlas.size.x, (GLsizei)atlas.size.y);
glTextureSubImage2D(atlas.texture_id, 0, 0, 0, (GLsizei)atlas.size.x, (GLsizei)atlas.size.y, GL_RED, GL_UNSIGNED_BYTE, atlas.bitmap);
}
MainFont.texture_id = atlas.texture_id;
FontCharSpacing = GetCharSpacing(&MainFont);
FontLineSpacing = GetLineSpacing(&MainFont);
}

View File

@@ -1,3 +1,49 @@
bool AppIsRunning = true;
bool WaitForEvents = true;
enum {
MOUSE_NONE,
MOUSE_MOVE,
MOUSE_LEFT,
MOUSE_RIGHT,
MOUSE_MIDDLE,
MOUSE_LEFT_UP,
MOUSE_RIGHT_UP,
MOUSE_MIDDLE_UP,
};
struct Event {
SDL_Keycode key;
int16_t xmouse;
int16_t ymouse;
struct {
uint8_t shift : 1;
uint8_t ctrl : 1;
uint8_t alt : 1;
uint8_t super : 1;
};
uint8_t mouse;
uint8_t mouse_double_click;
float wheel;
const char *text;
};
#define Press(KEY) (event.key == KEY)
#define Ctrl(KEY) (event.key == KEY && event.ctrl)
#define Shift(KEY) (event.key == KEY && event.shift)
#define Alt(KEY) (event.key == KEY && event.alt)
#define CtrlShift(KEY) (event.key == KEY && event.ctrl && event.shift)
#define CtrlAlt(KEY) (event.key == KEY && event.ctrl && event.alt)
#define AltShift(KEY) (event.key == KEY && event.shift && event.alt)
#define MouseVec2() \
Vec2 { (float)event.xmouse, (float)event.ymouse }
#define MouseVec2I() \
Vec2I { (Int) event.xmouse, (Int)event.ymouse }
#define Mouse(x) (event.mouse == MOUSE_##x)
#define MousePress() (Mouse(LEFT) || Mouse(RIGHT) || Mouse(MIDDLE))
Int MoveOnWhitespaceBoundaryForward(Buffer &buffer, Int pos) {
pos = Clamp(pos, (Int)0, buffer.len);
bool standing_on_whitespace = IsWhitespace(buffer.str[pos]);
@@ -181,27 +227,110 @@ Array<Range> FindAllInBuffer(Allocator allocator, Buffer *buffer, String16 needl
return result;
}
// void HandleGlobalCommands() {
// if (CtrlPress(KEY_P)) {
bool GlobalCommand(Event event) {
ProfileFunction();
bool run_window_command = true;
if (Mouse(MOVE)) {
Vec2I mouse = MouseVec2I();
Window *window = GetActiveWindow();
bool mouse_in_document = CheckCollisionPointRec(mouse, window->document_rect);
bool mouse_in_scrollbar = CheckCollisionPointRec(mouse, window->scrollbar_rect);
bool mouse_in_total = CheckCollisionPointRec(mouse, window->total_rect);
// }
static SDL_Cursor *SDL_MouseCursor;
if (SDL_MouseCursor) SDL_DestroyCursor(SDL_MouseCursor);
// if (CtrlPress(KEY_F)) {
// Window *search_window = GetWindow(SearchWindowID);
// if (search_window->visible) {
// SetActiveWindow(GetLastActiveWindow());
// } else {
// SetActiveWindow(search_window->id);
// }
// }
if (window->mouse_selecting || mouse_in_document) {
SDL_MouseCursor = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_TEXT);
SDL_SetCursor(SDL_MouseCursor);
} else if (mouse_in_scrollbar || window->mouse_selecting_scrollbar) {
SDL_MouseCursor = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_DEFAULT);
SDL_SetCursor(SDL_MouseCursor);
} else {
SDL_MouseCursor = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_POINTER);
SDL_SetCursor(SDL_MouseCursor);
}
}
// if (CtrlPress(KEY_MINUS)) {
// Int font_size = Clamp(FontSize - 1, (Int)4, (Int)100);
// ReloadFont(font_size);
// }
// if (CtrlPress(KEY_EQUAL)) {
// Int font_size = Clamp(FontSize + 1, (Int)4, (Int)100);
// ReloadFont(font_size);
// }
if (MousePress()) {
Scratch scratch;
Array<Int> order = GetWindowZOrder(scratch);
Vec2I mouse = MouseVec2I();
// }
For(order) {
Window *window = &Windows[it];
if (!window->visible) continue;
bool mouse_in_window = CheckCollisionPointRec(mouse, window->total_rect);
if (mouse_in_window) {
Window *active_window = GetWindow(ActiveWindow);
if (active_window->z <= window->z) {
SetActiveWindow(window->id);
}
}
}
}
if (event.wheel) {
Scratch scratch;
Array<Int> order = GetWindowZOrder(scratch);
Vec2I mouse = MouseVec2I();
For(order) {
Window *window = &Windows[it];
if (!window->visible) continue;
bool mouse_in_window = CheckCollisionPointRec(mouse, window->total_rect);
if (mouse_in_window) {
View *view = GetView(window->active_view);
view->scroll.y -= (Int)(event.wheel * 48);
break;
}
}
}
if (Press(SDLK_F5)) {
AppIsRunning = false;
run_window_command = false;
}
if (Ctrl(SDLK_P)) {
Window *command_window = GetWindow(CommandWindowID);
if (command_window->visible) {
SetActiveWindow(GetLastActiveWindow());
} else {
SetActiveWindow(command_window->id);
}
run_window_command = false;
}
if (Ctrl(SDLK_P)) {
Window *search_window = GetWindow(SearchWindowID);
if (search_window->visible) {
SetActiveWindow(GetLastActiveWindow());
} else {
SetActiveWindow(search_window->id);
}
run_window_command = false;
}
if (Ctrl(SDLK_1)) {
SetActiveWindow({0});
run_window_command = false;
}
if (Ctrl(SDLK_2)) {
SetActiveWindow({1});
run_window_command = false;
}
if (Ctrl(SDLK_3)) {
SetActiveWindow({2});
run_window_command = false;
}
if (Ctrl(SDLK_MINUS)) {
ReloadFont((int32_t)MainFont.size - 1);
} else if (Ctrl(SDLK_EQUALS)) {
ReloadFont((int32_t)MainFont.size + 1);
}
return run_window_command;
}

View File

@@ -181,14 +181,6 @@ void Command_EvalLuaLine(View *view) {
Command_EvalLua(view, string);
}
// void PrintDebugCarets(View *view, const char *msg) {
// Buffer *null_buffer = GetBuffer(NullBufferID);
// Appendf(null_buffer, "%s id: %d sel_anchor(%d, %d)\n", msg, view->caret_change_id, view->selection_anchor.min, view->selection_anchor.max);
// For(view->carets) {
// Appendf(null_buffer, " min: %lld max: %lld front: %d\n", (long long)it.range.min, (long long)it.range.max, it.ifront);
// }
// }
// Merge carets that overlap, this needs to be handled before any edits to
// make sure overlapping edits won't happen.
//
@@ -257,4 +249,357 @@ void ReplaceInfobarData() {
String16 string = ToString16(scratch, s);
ReplaceText(buffer, replace_range, string);
Command_SelectRangeOneCursor(view, {});
}
void WindowCommand(Event event, Window *window, View *view) {
ProfileFunction();
Buffer *buffer = GetBuffer(view->active_buffer);
if (Ctrl(SDLK_F2)) {
LoadBigLine(buffer);
} else if (Press(SDLK_F2)) {
LoadBigText(buffer);
}
if (Press(SDLK_ESCAPE)) {
if (window->deactivate_on_escape) {
SetActiveWindow(GetLastActiveWindow());
} else {
view->carets.len = 1;
}
}
if (CtrlAlt(SDLK_DOWN)) {
Command_DuplicateLine(view, DIR_DOWN);
} else if (AltShift(SDLK_DOWN)) {
Command_CreateCursorVertical(view, DIR_DOWN);
} else if (CtrlShift(SDLK_DOWN)) {
For(view->carets) it = ChangeFront(it, MovePos(*buffer, GetFront(it), DIR_DOWN, true));
} else if (Ctrl(SDLK_DOWN)) {
For(view->carets) it = MakeCaret(MovePos(*buffer, it.range.max, DIR_DOWN, true));
} else if (Shift(SDLK_DOWN)) {
For(view->carets) it = ChangeFront(it, MovePos(*buffer, GetFront(it), DIR_DOWN, false));
} else if (Press(SDLK_DOWN)) {
For(view->carets) {
if (GetSize(it.range) == 0) {
it = MakeCaret(MovePos(*buffer, it.range.max, DIR_DOWN, false));
} else {
it = MakeCaret(it.range.max);
}
}
}
if (CtrlAlt(SDLK_UP)) {
Command_DuplicateLine(view, DIR_UP);
} else if (AltShift(SDLK_UP)) {
Command_CreateCursorVertical(view, DIR_UP);
} else if (CtrlShift(SDLK_UP)) {
For(view->carets) it = ChangeFront(it, MovePos(*buffer, GetFront(it), DIR_UP, CTRL_PRESSED));
} else if (Ctrl(SDLK_UP)) {
For(view->carets) it = MakeCaret(MovePos(*buffer, it.range.min, DIR_UP, CTRL_PRESSED));
} else if (Shift(SDLK_UP)) {
For(view->carets) it = ChangeFront(it, MovePos(*buffer, GetFront(it), DIR_UP));
} else if (Press(SDLK_UP)) {
For(view->carets) {
if (GetSize(it.range) == 0) {
it = MakeCaret(MovePos(*buffer, it.range.min, DIR_UP));
} else {
it = MakeCaret(it.range.min);
}
}
}
if (CtrlShift(SDLK_LEFT)) {
For(view->carets) it = ChangeFront(it, MovePos(*buffer, GetFront(it), DIR_LEFT, true));
} else if (Ctrl(SDLK_LEFT)) {
For(view->carets) {
if (GetSize(it.range) != 0 && GetFront(it) != it.range.min) {
it = MakeCaret(it.range.min);
} else {
it = MakeCaret(MovePos(*buffer, it.range.min, DIR_LEFT, true));
}
}
} else if (Shift(SDLK_LEFT)) {
For(view->carets) it = ChangeFront(it, MovePos(*buffer, GetFront(it), DIR_LEFT, false));
} else if (Press(SDLK_LEFT)) {
For(view->carets) {
if (GetSize(it.range) == 0) {
it = MakeCaret(MovePos(*buffer, it.range.min, DIR_LEFT, false));
} else {
it = MakeCaret(it.range.min);
}
}
}
if (CtrlShift(SDLK_RIGHT)) {
For(view->carets) it = ChangeFront(it, MovePos(*buffer, GetFront(it), DIR_RIGHT, true));
} else if (Ctrl(SDLK_RIGHT)) {
For(view->carets) {
if (GetSize(it.range) != 0 && GetFront(it) != it.range.max) {
it = MakeCaret(it.range.max);
} else {
it = MakeCaret(MovePos(*buffer, it.range.max, DIR_RIGHT, true));
}
}
} else if (Shift(SDLK_RIGHT)) {
For(view->carets) it = ChangeFront(it, MovePos(*buffer, GetFront(it), DIR_RIGHT, false));
} else if (Press(SDLK_RIGHT)) {
For(view->carets) {
if (GetSize(it.range) == 0) {
it = MakeCaret(MovePos(*buffer, it.range.max, DIR_RIGHT, false));
} else {
it = MakeCaret(it.range.max);
}
}
}
if (CtrlShift(SDLK_Z)) {
RedoEdit(buffer, &view->carets);
} else if (Ctrl(SDLK_Z)) {
UndoEdit(buffer, &view->carets);
}
if (Ctrl(SDLK_C)) {
Command_Copy(view);
} else if (Ctrl(SDLK_V)) {
Command_Paste(view);
} else if (Ctrl(SDLK_X)) {
Command_Copy(view);
Command_Replace(view, L"");
}
if (Ctrl(SDLK_A)) {
Command_SelectEntireBuffer(view);
view->update_scroll = false;
}
if (Shift(SDLK_PAGEUP)) {
Command_MoveCursorsByPageSize(window, DIR_UP, SHIFT_PRESSED);
} else if (Press(SDLK_PAGEUP)) {
Command_MoveCursorsByPageSize(window, DIR_UP);
}
if (Shift(SDLK_PAGEDOWN)) {
Command_MoveCursorsByPageSize(window, DIR_DOWN, SHIFT_PRESSED);
} else if (Press(SDLK_PAGEDOWN)) {
Command_MoveCursorsByPageSize(window, DIR_DOWN);
}
if (Shift(SDLK_HOME)) {
Command_MoveCursorsToSide(window, DIR_LEFT, SHIFT_PRESSED);
} else if (Press(SDLK_HOME)) {
Command_MoveCursorsToSide(window, DIR_LEFT);
}
if (Shift(SDLK_END)) {
Command_MoveCursorsToSide(window, DIR_RIGHT, SHIFT_PRESSED);
} else if (Press(SDLK_END)) {
Command_MoveCursorsToSide(window, DIR_RIGHT);
}
bool search = false;
if (Press(SDLK_TAB)) {
Command_Replace(view, L" ");
search = true;
}
if (Ctrl(SDLK_BACKSPACE)) {
Command_Delete(view, DIR_LEFT, CTRL_PRESSED);
search = true;
} else if (Press(SDLK_BACKSPACE)) {
Command_Delete(view, DIR_LEFT);
search = true;
}
if (Ctrl(SDLK_DELETE)) {
Command_Delete(view, DIR_RIGHT, CTRL_PRESSED);
search = true;
} else if (Press(SDLK_DELETE)) {
Command_Delete(view, DIR_RIGHT);
search = true;
}
if (event.text) {
Scratch scratch;
String string = event.text;
String16 string16 = ToString16(scratch, string);
Window *window = GetActiveWindow();
View *view = GetActiveView(window);
Command_Replace(view, string16);
search = true;
}
if (Ctrl(SDLK_D)) {
String16 string = GetString(*buffer, view->carets[0].range);
Caret caret = FindInBuffer(buffer, string, view->carets[0], true);
Insert(&view->carets, caret, 0);
MergeCarets(view);
}
if (Ctrl(SDLK_F3)) {
Buffer *search_buffer = GetBuffer("*search*");
String16 search_string = GetString(*search_buffer);
Caret caret = FindInBuffer(buffer, search_string, view->carets[0], true);
Insert(&view->carets, caret, 0);
MergeCarets(view);
} else if (Press(SDLK_F3)) {
Buffer *search_buffer = GetBuffer("*search*");
String16 search_string = GetString(*search_buffer);
Caret caret = FindInBuffer(buffer, search_string, view->carets[0], true);
view->carets.len = 1;
view->carets[0] = caret;
}
if (window->id.id == SearchWindowID.id) {
Window *seek_window = GetWindow(GetLastActiveWindow());
View *seek_view = GetView(seek_window->active_view);
Buffer *seek_buffer = GetBuffer(seek_view->active_buffer);
String16 needle = GetString(*buffer);
if (search) {
seek_view->carets[0] = FindInBuffer(seek_buffer, needle, seek_view->carets[0]);
seek_view->carets.len = 1;
}
if (Alt(SDLK_RETURN)) {
Command_SelectAll(seek_view, needle);
// SetActiveWindow(seek_window->id);
} else if (Ctrl(SDLK_RETURN)) {
Caret caret = FindInBuffer(seek_buffer, needle, seek_view->carets[0], true);
Insert(&seek_view->carets, caret, 0);
MergeCarets(seek_view);
} else if (Press(SDLK_RETURN)) {
Caret caret = FindInBuffer(seek_buffer, needle, seek_view->carets[0], true);
seek_view->carets.len = 1;
seek_view->carets[0] = caret;
}
}
if (window->fuzzy_search && search) {
Scratch scratch;
String16 first_line_string = GetLineStringWithoutNL(*buffer, 0);
Array<FuzzyPair> ratings = FuzzySearchLines(scratch, buffer, 1, buffer->line_starts.len, first_line_string);
Buffer *temp_buffer = CreateTempBuffer(scratch, buffer->cap);
ReplaceText(temp_buffer, GetEndAsRange(*temp_buffer), first_line_string);
ReplaceText(temp_buffer, GetEndAsRange(*temp_buffer), L"\n");
For(ratings) {
String16 s = GetLineStringWithoutNL(*buffer, it.index);
if (s.len == 0) continue;
ReplaceText(temp_buffer, GetEndAsRange(*temp_buffer), s);
ReplaceText(temp_buffer, GetEndAsRange(*temp_buffer), L"\n");
}
Caret caret = view->carets[0];
Command_SelectEntireBuffer(view);
Command_Replace(view, GetString(*temp_buffer));
view->carets[0] = caret;
}
if (Ctrl(SDLK_Q) || Mouse(MIDDLE)) {
// @todo: Consider applying this to all cursors
if (GetSize(view->carets[0].range) == 0) {
Command_EvalLuaLine(view);
} else {
String16 string = GetString(*buffer, view->carets[0].range);
Command_EvalLua(view, string);
}
}
if (window->execute_line) {
if (Press(SDLK_RETURN)) {
Command_EvalLuaLine(view);
}
} else if (window->id.id == SearchWindowID.id) {
} else {
if (Ctrl(SDLK_RETURN)) {
Command_MoveCursorsToSide(window, DIR_RIGHT);
Command_Replace(view, L"\n");
} else if (Press(SDLK_RETURN)) {
Command_Replace(view, L"\n");
}
}
if (!Mouse(NONE)) {
ProfileScope(mouse);
Vec2 mouse_vec2 = MouseVec2();
Vec2I mouse = MouseVec2I();
bool mouse_in_document = CheckCollisionPointRec(mouse, window->document_rect);
bool mouse_in_scrollbar = CheckCollisionPointRec(mouse, window->scrollbar_rect);
bool scrollbar_action = mouse_in_scrollbar || window->mouse_selecting_scrollbar;
bool document_action = mouse_in_document || window->mouse_selecting;
if (!scrollbar_action && document_action) {
Vec2I mworld = mouse - window->document_rect.min + view->scroll;
Vec2I pos = mworld / Vec2I{FontCharSpacing, FontLineSpacing};
XY xy = {(Int)(pos.x), (Int)(pos.y)};
Int p = XYToPosWithoutNL(*buffer, xy);
if (mouse_in_document && Mouse(LEFT) && event.mouse_double_click) {
Caret *c = &view->carets[0];
if (InBounds({c->range.min - 1, c->range.max + 1}, p)) {
c->range = EncloseWord(*buffer, p);
view->selection_anchor = c->range;
}
} else if (mouse_in_document && Mouse(LEFT) && event.ctrl) {
Insert(&view->carets, MakeCaret(p, p), 0);
view->selection_anchor = view->carets[0].range;
} else if (mouse_in_document && Mouse(LEFT)) {
view->carets.len = 0;
Insert(&view->carets, MakeCaret(p, p), 0);
view->selection_anchor = view->carets[0].range;
}
if (mouse_in_document && Mouse(LEFT)) {
window->mouse_selecting = true;
}
if (window->mouse_selecting) {
if (Mouse(LEFT_UP)) {
window->mouse_selecting = false;
}
MergeCarets(view, &view->selection_anchor);
Caret &caret = view->carets[0];
if (view->selection_anchor.min > p) {
caret = MakeCaret(p, view->selection_anchor.max);
} else if (view->selection_anchor.max < p) {
caret = MakeCaret(p, view->selection_anchor.min);
} else {
caret = MakeCaret(view->selection_anchor.max, view->selection_anchor.min);
}
MergeCarets(view, &view->selection_anchor);
}
} else if (!(mouse_in_document || window->mouse_selecting) && mouse_in_scrollbar || window->mouse_selecting_scrollbar) {
Scroller s = ComputeScrollerRect(*window);
double size_y = (double)GetSize(window->scrollbar_rect).y;
double p = mouse_vec2.y - window->scrollbar_rect.min.y;
if (Mouse(LEFT)) {
window->mouse_selecting_scrollbar = true;
} else if (Mouse(LEFT_UP)) {
window->mouse_selecting_scrollbar = false;
}
if (Mouse(LEFT)) {
if (mouse_vec2.y < s.rect.min.y || mouse_vec2.y > s.rect.max.y) {
view->scroll.y = (Int)(p / size_y * (double)s.line_count * (double)FontLineSpacing);
window->mouse_scroller_offset = -(double)GetSize(s.rect).y / 2.0 / size_y;
} else {
window->mouse_scroller_offset = (s.rect.min.y - p) / size_y;
}
}
if (window->mouse_selecting_scrollbar) {
double v = p / size_y;
v = v + (window->mouse_scroller_offset);
view->scroll.y = (Int)(v * (double)s.line_count * (double)FontLineSpacing);
}
}
if (window->mouse_selecting || window->mouse_selecting_scrollbar) {
WaitForEvents = false;
}
}
}

View File

@@ -36,506 +36,7 @@
#include "lua.hpp"
#include "lua_api.cpp"
bool AppIsRunning = true;
bool WaitForEvents = true;
SDL_Cursor *SDL_MouseCursor = NULL;
enum {
MOUSE_NONE,
MOUSE_MOVE,
MOUSE_LEFT,
MOUSE_RIGHT,
MOUSE_MIDDLE,
MOUSE_LEFT_UP,
MOUSE_RIGHT_UP,
MOUSE_MIDDLE_UP,
};
struct Event {
SDL_Keycode key;
int16_t xmouse;
int16_t ymouse;
struct {
uint8_t shift : 1;
uint8_t ctrl : 1;
uint8_t alt : 1;
uint8_t super : 1;
};
uint8_t mouse;
uint8_t mouse_double_click;
float wheel;
const char *text;
};
#define Press(KEY) (event.key == KEY)
#define Ctrl(KEY) (event.key == KEY && event.ctrl)
#define Shift(KEY) (event.key == KEY && event.shift)
#define Alt(KEY) (event.key == KEY && event.alt)
#define CtrlShift(KEY) (event.key == KEY && event.ctrl && event.shift)
#define CtrlAlt(KEY) (event.key == KEY && event.ctrl && event.alt)
#define AltShift(KEY) (event.key == KEY && event.shift && event.alt)
#define MouseVec2() \
Vec2 { (float)event.xmouse, (float)event.ymouse }
#define MouseVec2I() \
Vec2I { (Int) event.xmouse, (Int)event.ymouse }
#define Mouse(x) (event.mouse == MOUSE_##x)
#define MousePress() (Mouse(LEFT) || Mouse(RIGHT) || Mouse(MIDDLE))
bool GlobalCommand(Event event) {
bool run_window_command = true;
if (Mouse(MOVE)) {
Vec2I mouse = MouseVec2I();
Window *window = GetActiveWindow();
bool mouse_in_document = CheckCollisionPointRec(mouse, window->document_rect);
bool mouse_in_scrollbar = CheckCollisionPointRec(mouse, window->scrollbar_rect);
bool mouse_in_total = CheckCollisionPointRec(mouse, window->total_rect);
if (SDL_MouseCursor) SDL_DestroyCursor(SDL_MouseCursor);
if (window->mouse_selecting || mouse_in_document) {
SDL_MouseCursor = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_TEXT);
SDL_SetCursor(SDL_MouseCursor);
} else if (mouse_in_scrollbar || window->mouse_selecting_scrollbar) {
SDL_MouseCursor = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_DEFAULT);
SDL_SetCursor(SDL_MouseCursor);
} else {
SDL_MouseCursor = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_POINTER);
SDL_SetCursor(SDL_MouseCursor);
}
}
if (MousePress()) {
Scratch scratch;
Array<Int> order = GetWindowZOrder(scratch);
Vec2I mouse = MouseVec2I();
For(order) {
Window *window = &Windows[it];
if (!window->visible) continue;
bool mouse_in_window = CheckCollisionPointRec(mouse, window->total_rect);
if (mouse_in_window) {
Window *active_window = GetWindow(ActiveWindow);
if (active_window->z <= window->z) {
SetActiveWindow(window->id);
}
}
}
}
if (event.wheel) {
Scratch scratch;
Array<Int> order = GetWindowZOrder(scratch);
Vec2I mouse = MouseVec2I();
For(order) {
Window *window = &Windows[it];
if (!window->visible) continue;
bool mouse_in_window = CheckCollisionPointRec(mouse, window->total_rect);
if (mouse_in_window) {
View *view = GetView(window->active_view);
view->scroll.y -= (Int)(event.wheel * 48);
break;
}
}
}
if (Press(SDLK_F5)) {
AppIsRunning = false;
run_window_command = false;
}
if (Ctrl(SDLK_P)) {
Window *command_window = GetWindow(CommandWindowID);
if (command_window->visible) {
SetActiveWindow(GetLastActiveWindow());
} else {
SetActiveWindow(command_window->id);
}
run_window_command = false;
}
if (Ctrl(SDLK_P)) {
Window *search_window = GetWindow(SearchWindowID);
if (search_window->visible) {
SetActiveWindow(GetLastActiveWindow());
} else {
SetActiveWindow(search_window->id);
}
run_window_command = false;
}
if (Ctrl(SDLK_1)) {
SetActiveWindow({0});
run_window_command = false;
}
if (Ctrl(SDLK_2)) {
SetActiveWindow({1});
run_window_command = false;
}
if (Ctrl(SDLK_3)) {
SetActiveWindow({2});
run_window_command = false;
}
return run_window_command;
}
void WindowCommand(Event event, Window *window, View *view) {
Buffer *buffer = GetBuffer(view->active_buffer);
if (Ctrl(SDLK_F2)) {
LoadBigLine(buffer);
} else if (Press(SDLK_F2)) {
LoadBigText(buffer);
}
if (Press(SDLK_ESCAPE)) {
if (window->deactivate_on_escape) {
SetActiveWindow(GetLastActiveWindow());
} else {
view->carets.len = 1;
}
}
if (CtrlAlt(SDLK_DOWN)) {
Command_DuplicateLine(view, DIR_DOWN);
} else if (AltShift(SDLK_DOWN)) {
Command_CreateCursorVertical(view, DIR_DOWN);
} else if (CtrlShift(SDLK_DOWN)) {
For(view->carets) it = ChangeFront(it, MovePos(*buffer, GetFront(it), DIR_DOWN, true));
} else if (Ctrl(SDLK_DOWN)) {
For(view->carets) it = MakeCaret(MovePos(*buffer, it.range.max, DIR_DOWN, true));
} else if (Shift(SDLK_DOWN)) {
For(view->carets) it = ChangeFront(it, MovePos(*buffer, GetFront(it), DIR_DOWN, false));
} else if (Press(SDLK_DOWN)) {
For(view->carets) {
if (GetSize(it.range) == 0) {
it = MakeCaret(MovePos(*buffer, it.range.max, DIR_DOWN, false));
} else {
it = MakeCaret(it.range.max);
}
}
}
if (CtrlAlt(SDLK_UP)) {
Command_DuplicateLine(view, DIR_UP);
} else if (AltShift(SDLK_UP)) {
Command_CreateCursorVertical(view, DIR_UP);
} else if (CtrlShift(SDLK_UP)) {
For(view->carets) it = ChangeFront(it, MovePos(*buffer, GetFront(it), DIR_UP, CTRL_PRESSED));
} else if (Ctrl(SDLK_UP)) {
For(view->carets) it = MakeCaret(MovePos(*buffer, it.range.min, DIR_UP, CTRL_PRESSED));
} else if (Shift(SDLK_UP)) {
For(view->carets) it = ChangeFront(it, MovePos(*buffer, GetFront(it), DIR_UP));
} else if (Press(SDLK_UP)) {
For(view->carets) {
if (GetSize(it.range) == 0) {
it = MakeCaret(MovePos(*buffer, it.range.min, DIR_UP));
} else {
it = MakeCaret(it.range.min);
}
}
}
if (CtrlShift(SDLK_LEFT)) {
For(view->carets) it = ChangeFront(it, MovePos(*buffer, GetFront(it), DIR_LEFT, true));
} else if (Ctrl(SDLK_LEFT)) {
For(view->carets) {
if (GetSize(it.range) != 0 && GetFront(it) != it.range.min) {
it = MakeCaret(it.range.min);
} else {
it = MakeCaret(MovePos(*buffer, it.range.min, DIR_LEFT, true));
}
}
} else if (Shift(SDLK_LEFT)) {
For(view->carets) it = ChangeFront(it, MovePos(*buffer, GetFront(it), DIR_LEFT, false));
} else if (Press(SDLK_LEFT)) {
For(view->carets) {
if (GetSize(it.range) == 0) {
it = MakeCaret(MovePos(*buffer, it.range.min, DIR_LEFT, false));
} else {
it = MakeCaret(it.range.min);
}
}
}
if (CtrlShift(SDLK_RIGHT)) {
For(view->carets) it = ChangeFront(it, MovePos(*buffer, GetFront(it), DIR_RIGHT, true));
} else if (Ctrl(SDLK_RIGHT)) {
For(view->carets) {
if (GetSize(it.range) != 0 && GetFront(it) != it.range.max) {
it = MakeCaret(it.range.max);
} else {
it = MakeCaret(MovePos(*buffer, it.range.max, DIR_RIGHT, true));
}
}
} else if (Shift(SDLK_RIGHT)) {
For(view->carets) it = ChangeFront(it, MovePos(*buffer, GetFront(it), DIR_RIGHT, false));
} else if (Press(SDLK_RIGHT)) {
For(view->carets) {
if (GetSize(it.range) == 0) {
it = MakeCaret(MovePos(*buffer, it.range.max, DIR_RIGHT, false));
} else {
it = MakeCaret(it.range.max);
}
}
}
if (CtrlShift(SDLK_Z)) {
RedoEdit(buffer, &view->carets);
} else if (Ctrl(SDLK_Z)) {
UndoEdit(buffer, &view->carets);
}
if (Ctrl(SDLK_C)) {
Command_Copy(view);
} else if (Ctrl(SDLK_V)) {
Command_Paste(view);
} else if (Ctrl(SDLK_X)) {
Command_Copy(view);
Command_Replace(view, L"");
}
if (Ctrl(SDLK_A)) {
Command_SelectEntireBuffer(view);
view->update_scroll = false;
}
if (Shift(SDLK_PAGEUP)) {
Command_MoveCursorsByPageSize(window, DIR_UP, SHIFT_PRESSED);
} else if (Press(SDLK_PAGEUP)) {
Command_MoveCursorsByPageSize(window, DIR_UP);
}
if (Shift(SDLK_PAGEDOWN)) {
Command_MoveCursorsByPageSize(window, DIR_DOWN, SHIFT_PRESSED);
} else if (Press(SDLK_PAGEDOWN)) {
Command_MoveCursorsByPageSize(window, DIR_DOWN);
}
if (Shift(SDLK_HOME)) {
Command_MoveCursorsToSide(window, DIR_LEFT, SHIFT_PRESSED);
} else if (Press(SDLK_HOME)) {
Command_MoveCursorsToSide(window, DIR_LEFT);
}
if (Shift(SDLK_END)) {
Command_MoveCursorsToSide(window, DIR_RIGHT, SHIFT_PRESSED);
} else if (Press(SDLK_END)) {
Command_MoveCursorsToSide(window, DIR_RIGHT);
}
bool search = false;
if (Press(SDLK_TAB)) {
Command_Replace(view, L" ");
search = true;
}
if (Ctrl(SDLK_BACKSPACE)) {
Command_Delete(view, DIR_LEFT, CTRL_PRESSED);
search = true;
} else if (Press(SDLK_BACKSPACE)) {
Command_Delete(view, DIR_LEFT);
search = true;
}
if (Ctrl(SDLK_DELETE)) {
Command_Delete(view, DIR_RIGHT, CTRL_PRESSED);
search = true;
} else if (Press(SDLK_DELETE)) {
Command_Delete(view, DIR_RIGHT);
search = true;
}
if (event.text) {
Scratch scratch;
String string = event.text;
String16 string16 = ToString16(scratch, string);
Window *window = GetActiveWindow();
View *view = GetActiveView(window);
Command_Replace(view, string16);
search = true;
}
if (Ctrl(SDLK_D)) {
String16 string = GetString(*buffer, view->carets[0].range);
Caret caret = FindInBuffer(buffer, string, view->carets[0], true);
Insert(&view->carets, caret, 0);
MergeCarets(view);
}
if (Ctrl(SDLK_F3)) {
Buffer *search_buffer = GetBuffer("*search*");
String16 search_string = GetString(*search_buffer);
Caret caret = FindInBuffer(buffer, search_string, view->carets[0], true);
Insert(&view->carets, caret, 0);
MergeCarets(view);
} else if (Press(SDLK_F3)) {
Buffer *search_buffer = GetBuffer("*search*");
String16 search_string = GetString(*search_buffer);
Caret caret = FindInBuffer(buffer, search_string, view->carets[0], true);
view->carets.len = 1;
view->carets[0] = caret;
}
if (window->id.id == SearchWindowID.id) {
Window *seek_window = GetWindow(GetLastActiveWindow());
View *seek_view = GetView(seek_window->active_view);
Buffer *seek_buffer = GetBuffer(seek_view->active_buffer);
String16 needle = GetString(*buffer);
if (search) {
seek_view->carets[0] = FindInBuffer(seek_buffer, needle, seek_view->carets[0]);
seek_view->carets.len = 1;
}
if (Alt(SDLK_RETURN)) {
Command_SelectAll(seek_view, needle);
// SetActiveWindow(seek_window->id);
} else if (Ctrl(SDLK_RETURN)) {
Caret caret = FindInBuffer(seek_buffer, needle, seek_view->carets[0], true);
Insert(&seek_view->carets, caret, 0);
MergeCarets(seek_view);
} else if (Press(SDLK_RETURN)) {
Caret caret = FindInBuffer(seek_buffer, needle, seek_view->carets[0], true);
seek_view->carets.len = 1;
seek_view->carets[0] = caret;
}
}
if (window->fuzzy_search && search) {
Scratch scratch;
String16 first_line_string = GetLineStringWithoutNL(*buffer, 0);
Array<FuzzyPair> ratings = FuzzySearchLines(scratch, buffer, 1, buffer->line_starts.len, first_line_string);
Buffer *temp_buffer = CreateTempBuffer(scratch, buffer->cap);
ReplaceText(temp_buffer, GetEndAsRange(*temp_buffer), first_line_string);
ReplaceText(temp_buffer, GetEndAsRange(*temp_buffer), L"\n");
For(ratings) {
String16 s = GetLineStringWithoutNL(*buffer, it.index);
if (s.len == 0) continue;
ReplaceText(temp_buffer, GetEndAsRange(*temp_buffer), s);
ReplaceText(temp_buffer, GetEndAsRange(*temp_buffer), L"\n");
}
Caret caret = view->carets[0];
Command_SelectEntireBuffer(view);
Command_Replace(view, GetString(*temp_buffer));
view->carets[0] = caret;
}
if (Ctrl(SDLK_Q) /* || IsMouseButtonPressed(MOUSE_BUTTON_MIDDLE)*/) {
// @todo: Consider applying this to all cursors
if (GetSize(view->carets[0].range) == 0) {
Command_EvalLuaLine(view);
} else {
String16 string = GetString(*buffer, view->carets[0].range);
Command_EvalLua(view, string);
}
}
if (window->execute_line) {
if (Press(SDLK_RETURN)) {
Command_EvalLuaLine(view);
}
} else if (window->id.id == SearchWindowID.id) {
} else {
if (Ctrl(SDLK_RETURN)) {
Command_MoveCursorsToSide(window, DIR_RIGHT);
Command_Replace(view, L"\n");
} else if (Press(SDLK_RETURN)) {
Command_Replace(view, L"\n");
}
}
if (!Mouse(NONE)) {
ProfileScope(mouse);
Vec2 mouse_vec2 = MouseVec2();
Vec2I mouse = MouseVec2I();
bool mouse_in_document = CheckCollisionPointRec(mouse, window->document_rect);
bool mouse_in_scrollbar = CheckCollisionPointRec(mouse, window->scrollbar_rect);
bool scrollbar_action = mouse_in_scrollbar || window->mouse_selecting_scrollbar;
bool document_action = mouse_in_document || window->mouse_selecting;
if (!scrollbar_action && document_action) {
Vec2I mworld = mouse - window->document_rect.min + view->scroll;
Vec2I pos = mworld / Vec2I{FontCharSpacing, FontLineSpacing};
XY xy = {(Int)(pos.x), (Int)(pos.y)};
Int p = XYToPosWithoutNL(*buffer, xy);
if (mouse_in_document && Mouse(LEFT) && event.mouse_double_click) {
Caret *c = &view->carets[0];
if (InBounds({c->range.min - 1, c->range.max + 1}, p)) {
c->range = EncloseWord(*buffer, p);
view->selection_anchor = c->range;
}
} else if (mouse_in_document && Mouse(LEFT) && event.ctrl) {
Insert(&view->carets, MakeCaret(p, p), 0);
view->selection_anchor = view->carets[0].range;
} else if (mouse_in_document && Mouse(LEFT)) {
view->carets.len = 0;
Insert(&view->carets, MakeCaret(p, p), 0);
view->selection_anchor = view->carets[0].range;
}
if (mouse_in_document && Mouse(LEFT)) {
window->mouse_selecting = true;
}
if (window->mouse_selecting) {
if (Mouse(LEFT_UP)) {
window->mouse_selecting = false;
}
MergeCarets(view, &view->selection_anchor);
Caret &caret = view->carets[0];
if (view->selection_anchor.min > p) {
caret = MakeCaret(p, view->selection_anchor.max);
} else if (view->selection_anchor.max < p) {
caret = MakeCaret(p, view->selection_anchor.min);
} else {
caret = MakeCaret(view->selection_anchor.max, view->selection_anchor.min);
}
MergeCarets(view, &view->selection_anchor);
}
} else if (!(mouse_in_document || window->mouse_selecting) && mouse_in_scrollbar || window->mouse_selecting_scrollbar) {
Scroller s = ComputeScrollerRect(*window);
double size_y = (double)GetSize(window->scrollbar_rect).y;
double p = mouse_vec2.y - window->scrollbar_rect.min.y;
if (Mouse(LEFT)) {
window->mouse_selecting_scrollbar = true;
} else if (Mouse(LEFT_UP)) {
window->mouse_selecting_scrollbar = false;
}
if (Mouse(LEFT)) {
if (mouse_vec2.y < s.rect.min.y || mouse_vec2.y > s.rect.max.y) {
view->scroll.y = (Int)(p / size_y * (double)s.line_count * (double)FontLineSpacing);
window->mouse_scroller_offset = -(double)GetSize(s.rect).y / 2.0 / size_y;
} else {
window->mouse_scroller_offset = (s.rect.min.y - p) / size_y;
}
}
if (window->mouse_selecting_scrollbar) {
double v = p / size_y;
v = v + (window->mouse_scroller_offset);
view->scroll.y = (Int)(v * (double)s.line_count * (double)FontLineSpacing);
}
}
if (window->mouse_selecting || window->mouse_selecting_scrollbar) {
WaitForEvents = false;
}
}
}
void Command(Event event) {
void HandleEvent(Event event) {
bool run_window_command = GlobalCommand(event);
if (run_window_command) {
Window *window = GetActiveWindow();
@@ -546,6 +47,7 @@ void Command(Event event) {
}
void ProcessSDLEvent(SDL_Event *input_event) {
ProfileFunction();
Event event = {};
SDL_Keymod mod = SDL_GetModState();
event.shift = (mod & SDL_KMOD_SHIFT) != 0;
@@ -559,20 +61,10 @@ void ProcessSDLEvent(SDL_Event *input_event) {
SDL_KeyboardEvent &key = input_event->key;
event.key = key.key;
} break;
case SDL_EVENT_KEY_UP: {
return;
} break;
case SDL_EVENT_TEXT_INPUT: {
SDL_TextInputEvent &b = input_event->text;
event.text = b.text;
} break;
case SDL_EVENT_MOUSE_MOTION: {
// SDL_MouseMotionEvent &b = input_event->motion;
// event.xmouse = (int16_t)b.x;
// event.ymouse = (int16_t)b.y;
// event.mouse = MOUSE_MOVE;
return;
} break;
case SDL_EVENT_MOUSE_BUTTON_DOWN: {
SDL_MouseButtonEvent &b = input_event->button;
event.xmouse = (int16_t)b.x;
@@ -609,7 +101,7 @@ void ProcessSDLEvent(SDL_Event *input_event) {
default: return;
}
Command(event);
HandleEvent(event);
}
#if _WIN32
@@ -619,7 +111,6 @@ int main()
#endif
{
BeginProfiler();
BeginProfileScope("main");
InitScratch();
InitArena(&Perm);
@@ -651,6 +142,14 @@ int main()
SDL_GL_SetSwapInterval(1); // Enable vsync
SDL_ShowWindow(window);
// Set icon
{
uint32_t data = 0xddddddff;
SDL_Surface *surface = SDL_CreateSurfaceFrom(1, 1, SDL_PIXELFORMAT_RGBA8888, &data, sizeof(uint32_t));
SDL_SetWindowIcon(window, surface);
SDL_DestroySurface(surface);
}
if (!gladLoadGLLoader((GLADloadproc)SDL_GL_GetProcAddress)) {
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Couldn't load opengl!", SDL_GetError(), NULL);
return 1;
@@ -659,26 +158,9 @@ int main()
SDL_StartTextInput(window);
SDL_GL_SetSwapInterval(1); // vsync
InitRender();
ReloadFont(16);
InitLua();
{
Scratch scratch;
Atlas atlas = CreateAtlas(scratch, {1024, 1024});
MainFont = CreateFont(&atlas, 16, "C:\\Windows\\Fonts\\consola.ttf");
{
glCreateTextures(GL_TEXTURE_2D, 1, &atlas.texture_id);
glTextureParameteri(atlas.texture_id, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTextureParameteri(atlas.texture_id, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTextureParameteri(atlas.texture_id, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTextureParameteri(atlas.texture_id, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTextureStorage2D(atlas.texture_id, 1, GL_R8, (GLsizei)atlas.size.x, (GLsizei)atlas.size.y);
glTextureSubImage2D(atlas.texture_id, 0, 0, 0, (GLsizei)atlas.size.x, (GLsizei)atlas.size.y, GL_RED, GL_UNSIGNED_BYTE, atlas.bitmap);
}
MainFont.texture_id = atlas.texture_id;
FontCharSpacing = GetCharSpacing(&MainFont);
FontLineSpacing = GetLineSpacing(&MainFont);
}
InitWindows();
while (AppIsRunning) {
FrameID += 1;
@@ -719,7 +201,7 @@ int main()
event.xmouse = (int16_t)xmouse;
event.ymouse = (int16_t)ymouse;
event.mouse = MOUSE_MOVE;
Command(event);
HandleEvent(event);
}
ReplaceInfobarData();

View File

@@ -56,133 +56,7 @@ int main(void) {
InitLua();
Allocator sys_allocator = GetSystemAllocator();
// Create null
{
Buffer *buffer = CreateBuffer(sys_allocator, "*scratch*");
}
{
Window *w = CreateWindow();
Buffer *b = CreateBuffer(sys_allocator, "*load_text_a*");
View *v = CreateView(b->id);
LoadTextA(b);
AddView(w, v->id);
}
SetActiveWindow({1});
{
Window *w = CreateWindow();
Buffer *b = CreateBuffer(sys_allocator, "*load_unicode*");
View *v = CreateView(b->id);
LoadUnicode(b);
AddView(w, v->id);
}
{
Window *w = CreateWindow();
Buffer *b = GetBuffer({0});
View *v = CreateView(b->id);
AddView(w, v->id);
}
{
Window *w = CreateWindow();
w->draw_scrollbar = false;
w->draw_line_numbers = false;
w->dont_save_in_active_window_history = true;
w->deactivate_on_escape = true;
Buffer *b = CreateBuffer(sys_allocator, "*infobar*");
b->no_history = true;
View *v = CreateView(b->id);
AddView(w, v->id);
InfoBarWindowID = w->id;
}
{
Window *w = CreateWindow();
w->draw_scrollbar = false;
w->draw_line_numbers = false;
w->visible = false;
w->fuzzy_search = true;
w->execute_line = true;
w->invisible_when_inactive = true;
w->dont_save_in_active_window_history = true;
w->deactivate_on_escape = true;
Buffer *b = CreateBuffer(sys_allocator, "*commands*");
View *v = CreateView(b->id);
AddView(w, v->id);
CommandWindowID = w->id;
Command_EvalLua(v, L"open \"./\"");
}
{
Window *w = CreateWindow();
w->draw_scrollbar = false;
w->draw_line_numbers = false;
w->visible = false;
w->dont_save_in_active_window_history = true;
w->invisible_when_inactive = true;
w->deactivate_on_escape = true;
Buffer *b = CreateBuffer(sys_allocator, "*search*");
View *v = CreateView(b->id);
AddView(w, v->id);
SearchWindowID = w->id;
}
while (!WindowShouldClose()) {
ProfileScope(game_loop);
FrameID += 1;
Rect2I screen_rect = GetScreenRect();
Rect2I infobar_rect = CutBottom(&screen_rect, (Int)FontLineSpacing);
float line_numbers_size = MeasureTextEx(MainFont, "1234567891", (float)FontSize, (float)FontSpacing).x;
{
int i = 5;
if (Windows[i].visible) {
Rect2I rect = CutBottom(&screen_rect, FontLineSpacing);
Windows[i].total_rect = rect;
Windows[i].document_rect = Windows[i].total_rect;
}
}
{
int i = 0;
Windows[i].total_rect = CutLeft(&screen_rect, (Int)((double)GetSize(screen_rect).x * 0.33));
Windows[i].document_rect = Windows[i].total_rect;
if (Windows[i].draw_scrollbar) Windows[i].scrollbar_rect = CutRight(&Windows[i].document_rect, 10);
if (Windows[i].draw_line_numbers) Windows[i].line_numbers_rect = CutLeft(&Windows[i].document_rect, (Int)line_numbers_size);
}
{
int i = 1;
Windows[i].total_rect = CutLeft(&screen_rect, (Int)((double)GetSize(screen_rect).x * 0.5));
Windows[i].document_rect = Windows[i].total_rect;
if (Windows[i].draw_scrollbar) Windows[i].scrollbar_rect = CutRight(&Windows[i].document_rect, 10);
if (Windows[i].draw_line_numbers) Windows[i].line_numbers_rect = CutLeft(&Windows[i].document_rect, (Int)line_numbers_size);
}
{
int i = 2;
Windows[i].total_rect = CutLeft(&screen_rect, (Int)((double)GetSize(screen_rect).x * 1.0));
Windows[i].document_rect = Windows[i].total_rect;
if (Windows[i].draw_scrollbar) Windows[i].scrollbar_rect = CutRight(&Windows[i].document_rect, 10);
if (Windows[i].draw_line_numbers) Windows[i].line_numbers_rect = CutLeft(&Windows[i].document_rect, (Int)line_numbers_size);
}
{
int i = 3;
Windows[i].total_rect = infobar_rect;
Windows[i].document_rect = Windows[i].total_rect;
}
{
int i = 4;
Rect2 screen_rect = GetScreenRectF();
Vec2 size = GetSize(screen_rect);
CutTop(&screen_rect, size.y * 0.05f);
CutLeft(&screen_rect, size.x * 0.2f);
CutRight(&screen_rect, size.x * 0.2f);
Rect2 r = CutTop(&screen_rect, FontLineSpacing * 30.f);
Windows[i].z = 1;
Windows[i].total_rect = ToRect2I(r);
Windows[i].document_rect = Windows[i].total_rect;
}
BeginDrawing();
ClearBackground(ColorBackground);

View File

@@ -125,14 +125,11 @@ void DrawWindow(Window &window) {
DrawRect(rect, ColorSelection);
if (line_string[col] == ' ' || line_string[col] == '\t') {
DrawCircle({pos.x + (float)FontCharSpacing / 2.f, pos.y + (float)FontLineSpacing / 2.f}, MainFont.size / 10.f, ColorWhitespaceDuringSelection);
// DrawCircle((int)pos.x + (int)FontCharSpacing / 2, (int)pos.y + (int)FontLineSpacing / 2, (float)MainFont.size / 10.f, ColorWhitespaceDuringSelection);
DrawCircle({pos.x + (float)FontCharSpacing / 2.f, (float)pos.y + MainFont.descent}, MainFont.size / 8.f, ColorWhitespaceDuringSelection);
} else if (line_string[col] == '\n') {
DrawCircle({pos.x + (float)FontCharSpacing / 2.f, pos.y + (float)FontLineSpacing / 2.f}, MainFont.size / 4.f, ColorWhitespaceDuringSelection);
// DrawEllipse((int)pos.x + (int)FontCharSpacing / 2, (int)pos.y + (int)FontLineSpacing / 2, (float)MainFont.size / 4.f, (float)MainFont.size / 15.f, ColorWhitespaceDuringSelection);
DrawCircle({pos.x + (float)FontCharSpacing / 2.f, pos.y + (float)FontLineSpacing / 2.f}, MainFont.size / 8.f, ColorWhitespaceDuringSelection);
} else if (line_string[col] == '\r') {
DrawCircle({pos.x + (float)FontCharSpacing / 2.f, pos.y + (float)FontLineSpacing / 2.f}, MainFont.size / 4.f, ColorWhitespaceDuringSelection);
// DrawEllipse((int)pos.x + (int)FontCharSpacing / 2, (int)pos.y + (int)FontLineSpacing / 2, (float)MainFont.size / 10.f, (float)MainFont.size / 4.f, ColorWhitespaceDuringSelection);
DrawCircle({pos.x + (float)FontCharSpacing / 2.f, pos.y + (float)FontLineSpacing / 2.f}, MainFont.size / 8.f, ColorWhitespaceDuringSelection);
}
}
}