Fixing scissoring

This commit is contained in:
Krzosa Karol
2024-07-26 21:47:23 +02:00
parent 7803bc87a6
commit 9d02d5ab78
8 changed files with 572 additions and 616 deletions

View File

@@ -80,6 +80,15 @@ Rect2 operator+=(Rect2 &r, float value) { r = r + value; return r; }
Rect2 operator*=(Rect2 &r, float value) { r = r * value; return r; } Rect2 operator*=(Rect2 &r, float value) { r = r * value; return r; }
Rect2 operator/=(Rect2 &r, float value) { r = r / value; return r; } Rect2 operator/=(Rect2 &r, float value) { r = r / value; return r; }
bool operator==(Rect2 a, Rect2 b) {
bool result = a.min.x == b.min.x && a.min.y == b.min.y && a.max.x == b.max.x && a.max.y == b.max.y;
return result;
}
bool operator!=(Rect2 a, Rect2 b) {
bool result = !(a == b);
return result;
}
Vec2 operator-(Vec2 a, Vec2 b) { return {a.x - b.x, a.y - b.y}; } Vec2 operator-(Vec2 a, Vec2 b) { return {a.x - b.x, a.y - b.y}; }
Vec2 operator+(Vec2 a, Vec2 b) { return {a.x + b.x, a.y + b.y}; } Vec2 operator+(Vec2 a, Vec2 b) { return {a.x + b.x, a.y + b.y}; }
Vec2 operator*(Vec2 a, Vec2 b) { return {a.x * b.x, a.y * b.y}; } Vec2 operator*(Vec2 a, Vec2 b) { return {a.x * b.x, a.y * b.y}; }

View File

@@ -14,7 +14,8 @@ struct Vertex2D {
struct VertexNode2D { struct VertexNode2D {
VertexNode2D *next; VertexNode2D *next;
int count; int count;
Vertex2D vertices[1024 * 64]; Vertex2D vertices[1024 * 16];
Rect2 scissor;
}; };
struct VertexList2D { struct VertexList2D {
@@ -29,17 +30,27 @@ unsigned VBO, VAO;
Shader Shader2D; Shader Shader2D;
Arena RenderArena; Arena RenderArena;
Vec2 WindowSize; Vec2 WindowSize;
Rect2 CurrentScissor;
Font MainFont; Font MainFont;
Int FontLineSpacing; Int FontLineSpacing;
Int FontCharSpacing; Int FontCharSpacing;
void BeginFrameRender(Vec2 window_size) { Rect2 GetScreenRectF() {
Rect2 result = {0, 0, WindowSize.x, WindowSize.y};
return result;
}
Rect2I GetScreenRectI() {
Rect2I result = {0, 0, (Int)WindowSize.x, (Int)WindowSize.y};
return result;
}
void BeginFrameRender() {
Clear(&RenderArena); Clear(&RenderArena);
TotalVertexCount = 0; TotalVertexCount = 0;
Vertices.first = NULL; Vertices.first = NULL;
Vertices.last = NULL; Vertices.last = NULL;
WindowSize = window_size; CurrentScissor = GetScreenRectF();
} }
void EndFrameRender(Color color) { void EndFrameRender(Color color) {
@@ -50,8 +61,9 @@ void EndFrameRender(Color color) {
glDisable(GL_CULL_FACE); glDisable(GL_CULL_FACE);
glViewport(0, 0, (GLsizei)WindowSize.x, (GLsizei)WindowSize.y); glViewport(0, 0, (GLsizei)WindowSize.x, (GLsizei)WindowSize.y);
glScissor(0, 0, (GLsizei)WindowSize.x, (GLsizei)WindowSize.y);
glClearColor(color.r, color.g, color.b, color.a); glClearColor(color.r, color.g, color.b, color.a);
glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
// Default draw using the font texture // Default draw using the font texture
glBindProgramPipeline(Shader2D.pipeline); glBindProgramPipeline(Shader2D.pipeline);
@@ -59,6 +71,12 @@ void EndFrameRender(Color color) {
float yinverse = 1.f / (WindowSize.y / 2.f); float yinverse = 1.f / (WindowSize.y / 2.f);
glProgramUniform2f(Shader2D.vshader, 0, xinverse, yinverse); glProgramUniform2f(Shader2D.vshader, 0, xinverse, yinverse);
for (VertexNode2D *it = Vertices.first; it; it = it->next) { for (VertexNode2D *it = Vertices.first; it; it = it->next) {
Rect2 rect = it->scissor;
GLint x = (GLint)rect.min.x;
GLint y = (GLint)rect.min.y;
GLsizei w = (GLsizei)(rect.max.x - rect.min.x);
GLsizei h = (GLsizei)(rect.max.y - rect.min.y);
glScissor(x, (GLint)WindowSize.y - h, w, h);
glNamedBufferSubData(VBO, 0, it->count * sizeof(Vertex2D), it->vertices); glNamedBufferSubData(VBO, 0, it->count * sizeof(Vertex2D), it->vertices);
glBindVertexArray(VAO); glBindVertexArray(VAO);
GLint s_texture = 0; // texture unit that sampler2D will use in GLSL code GLint s_texture = 0; // texture unit that sampler2D will use in GLSL code
@@ -183,11 +201,39 @@ Shader CreateShader(char *glsl_vshader, char *glsl_fshader) {
} while (0) } while (0)
#define SLL_QUEUE_ADD(f, l, n) SLL_QUEUE_ADD_MOD(f, l, n, next) #define SLL_QUEUE_ADD(f, l, n) SLL_QUEUE_ADD_MOD(f, l, n, next)
VertexNode2D *AllocVertexNode2D(Allocator allocator, VertexList2D *list) {
VertexNode2D *node = AllocType(allocator, VertexNode2D);
SLL_QUEUE_ADD(list->first, list->last, node);
return node;
}
void SetScissor(Rect2 rect) {
CurrentScissor = rect;
VertexNode2D *node = Vertices.last;
if (!node) {
node = AllocVertexNode2D(RenderArena, &Vertices);
node->scissor = rect;
return;
}
if (node->scissor != rect && node->count == 0) {
node->scissor = rect;
return;
}
if (node->scissor != rect) {
node = AllocVertexNode2D(RenderArena, &Vertices);
node->scissor = rect;
return;
}
}
Vertex2D *AllocVertex2D(Allocator allocator, VertexList2D *list, int count) { Vertex2D *AllocVertex2D(Allocator allocator, VertexList2D *list, int count) {
VertexNode2D *node = list->last; VertexNode2D *node = list->last;
if (node == 0 || node->count + count > Lengthof(node->vertices)) { if (node == 0 || node->count + count > Lengthof(node->vertices)) {
node = AllocType(allocator, VertexNode2D); node = AllocVertexNode2D(allocator, list);
SLL_QUEUE_ADD(list->first, list->last, node); node->scissor = CurrentScissor;
} }
TotalVertexCount += count; TotalVertexCount += count;
@@ -249,7 +295,7 @@ void DrawRect(Rect2 rect, Color color) {
} }
Vec2 DrawString(Font *font, String16 string, Vec2 pos, Color color, bool draw = true) { Vec2 DrawString(Font *font, String16 string, Vec2 pos, Color color, bool draw = true) {
pos.y += font->ascent; pos.y += font->ascent - font->descent;
Vec2 original_pos = pos; Vec2 original_pos = pos;
For(string) { For(string) {
Glyph *g = GetGlyph(font, it); Glyph *g = GetGlyph(font, it);
@@ -277,25 +323,3 @@ Int GetLineSpacing(Font *font) {
Int result = (Int)(font->ascent - font->descent + font->line_gap); Int result = (Int)(font->ascent - font->descent + font->line_gap);
return result; return result;
} }
void BeginScissor(Rect2 rect) {
glScissor((GLint)rect.min.x, (GLint)rect.min.y, (GLsizei)(rect.max.x - rect.min.x), (GLsizei)(rect.max.y - rect.min.y));
}
void BeginScissor(Rect2I rect) {
glScissor((GLint)rect.min.x, (GLint)rect.min.y, (GLsizei)(rect.max.x - rect.min.x), (GLsizei)(rect.max.y - rect.min.y));
}
void EndScissor() {
glScissor(0, 0, (GLsizei)WindowSize.x, (GLsizei)WindowSize.y);
}
Rect2 GetScreenRectF() {
Rect2 result = {0, 0, WindowSize.x, WindowSize.y};
return result;
}
Rect2I GetScreenRectI() {
Rect2I result = {0, 0, (Int)WindowSize.x, (Int)WindowSize.y};
return result;
}

View File

@@ -1,69 +1,3 @@
inline bool Press(int key) {
bool result = IsKeyPressed(key) || IsKeyPressedRepeat(key);
return result;
}
inline bool Shift() {
bool result = IsKeyDown(KEY_LEFT_SHIFT) || IsKeyDown(KEY_RIGHT_SHIFT);
return result;
}
inline bool Ctrl() {
bool result = IsKeyDown(KEY_LEFT_CONTROL) || IsKeyDown(KEY_RIGHT_CONTROL);
return result;
}
inline bool Alt() {
bool result = IsKeyDown(KEY_LEFT_ALT) || IsKeyDown(KEY_RIGHT_ALT);
return result;
}
inline bool AltPress(int key) {
bool result = Press(key) && Alt();
return result;
}
inline bool CtrlPress(int key) {
bool result = Press(key) && Ctrl();
return result;
}
inline bool ShiftPress(int key) {
bool result = Press(key) && Shift();
return result;
}
inline bool CtrlShiftPress(int key) {
bool result = Press(key) && Shift() && Ctrl();
return result;
}
inline bool CtrlAltPress(int key) {
bool result = Press(key) && Ctrl() && Alt();
return result;
}
inline bool AltShiftPress(int key) {
bool result = Press(key) && Shift() && Alt();
return result;
}
bool IsDoubleClick() {
static double last_click_time;
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
double time = GetTime();
double diff = time - last_click_time;
last_click_time = time;
// @todo: don't do this manually, use windows
if (diff >= 0.05 && diff <= 0.3) {
last_click_time = 0;
return true;
}
} else if (IsMouseButtonDown(MOUSE_BUTTON_LEFT)) {
last_click_time = 0;
}
return false;
}
Int MoveOnWhitespaceBoundaryForward(Buffer &buffer, Int pos) { Int MoveOnWhitespaceBoundaryForward(Buffer &buffer, Int pos) {
pos = Clamp(pos, (Int)0, buffer.len); pos = Clamp(pos, (Int)0, buffer.len);
@@ -209,19 +143,6 @@ Range EncloseWord(Buffer &buffer, Int pos) {
return result; return result;
} }
void ReloadFont(Int font_size) {
if (MainFont.glyphs) {
UnloadFont(MainFont);
MainFont = {};
}
FontSize = font_size;
FontSpacing = 1;
FontLineSpacing = FontSize;
MainFont = LoadFontEx("c:\\Windows\\Fonts\\consola.ttf", (int)FontSize, NULL, 500);
FontCharSpacing = GetCharSpacing(MainFont, FontSize, FontSpacing);
}
Caret FindInBuffer(Buffer *buffer, String16 needle, Caret caret, bool find_next = false) { Caret FindInBuffer(Buffer *buffer, String16 needle, Caret caret, bool find_next = false) {
Int pos = caret.range.min; Int pos = caret.range.min;
String16 medium = GetString(*buffer, {pos, INT64_MAX}); String16 medium = GetString(*buffer, {pos, INT64_MAX});
@@ -261,39 +182,39 @@ Array<Range> FindAllInBuffer(Allocator allocator, Buffer *buffer, String16 needl
return result; return result;
} }
void HandleGlobalCommands() { // void HandleGlobalCommands() {
if (CtrlPress(KEY_P)) { // if (CtrlPress(KEY_P)) {
Window *command_window = GetWindow(CommandWindowID); // Window *command_window = GetWindow(CommandWindowID);
if (command_window->visible) { // if (command_window->visible) {
SetActiveWindow(GetLastActiveWindow()); // SetActiveWindow(GetLastActiveWindow());
} else { // } else {
SetActiveWindow(command_window->id); // SetActiveWindow(command_window->id);
} // }
} // }
if (CtrlPress(KEY_F)) { // if (CtrlPress(KEY_F)) {
Window *search_window = GetWindow(SearchWindowID); // Window *search_window = GetWindow(SearchWindowID);
if (search_window->visible) { // if (search_window->visible) {
SetActiveWindow(GetLastActiveWindow()); // SetActiveWindow(GetLastActiveWindow());
} else { // } else {
SetActiveWindow(search_window->id); // SetActiveWindow(search_window->id);
} // }
} // }
if (CtrlPress(KEY_MINUS)) { // if (CtrlPress(KEY_MINUS)) {
Int font_size = Clamp(FontSize - 1, (Int)4, (Int)100); // Int font_size = Clamp(FontSize - 1, (Int)4, (Int)100);
ReloadFont(font_size); // ReloadFont(font_size);
} // }
if (CtrlPress(KEY_EQUAL)) { // if (CtrlPress(KEY_EQUAL)) {
Int font_size = Clamp(FontSize + 1, (Int)4, (Int)100); // Int font_size = Clamp(FontSize + 1, (Int)4, (Int)100);
ReloadFont(font_size); // ReloadFont(font_size);
} // }
if (CtrlPress(KEY_ONE)) { // if (CtrlPress(KEY_ONE)) {
SetActiveWindow({0}); // SetActiveWindow({0});
} else if (CtrlPress(KEY_TWO)) { // } else if (CtrlPress(KEY_TWO)) {
SetActiveWindow({1}); // SetActiveWindow({1});
} else if (CtrlPress(KEY_THREE)) { // } else if (CtrlPress(KEY_THREE)) {
SetActiveWindow({2}); // SetActiveWindow({2});
} // }
} // }

View File

@@ -231,342 +231,342 @@ void MergeCarets(View *view, Range *mouse_selection_anchor) {
void HandleActiveWindowBindings(Window *window, bool *update_scroll) { void HandleActiveWindowBindings(Window *window, bool *update_scroll) {
View &view = *GetActiveView(window); View &view = *GetActiveView(window);
Buffer *buffer = GetBuffer(view.active_buffer); Buffer *buffer = GetBuffer(view.active_buffer);
if (CtrlPress(KEY_F2)) { // if (CtrlPress(KEY_F2)) {
LoadBigLine(buffer); // LoadBigLine(buffer);
} else if (Press(KEY_F2)) { // } else if (Press(KEY_F2)) {
LoadBigText(buffer); // LoadBigText(buffer);
} // }
if (Press(KEY_ESCAPE)) { // if (Press(KEY_ESCAPE)) {
if (window->deactivate_on_escape) { // if (window->deactivate_on_escape) {
SetActiveWindow(GetLastActiveWindow()); // SetActiveWindow(GetLastActiveWindow());
} else { // } else {
view.carets.len = 1; // view.carets.len = 1;
} // }
} // }
if (CtrlAltPress(KEY_DOWN)) { // if (CtrlAltPress(KEY_DOWN)) {
Command_DuplicateLine(&view, DIR_DOWN); // Command_DuplicateLine(&view, DIR_DOWN);
} else if (AltShiftPress(KEY_DOWN)) { // } else if (AltShiftPress(KEY_DOWN)) {
Command_CreateCursorVertical(&view, DIR_DOWN); // Command_CreateCursorVertical(&view, DIR_DOWN);
} else if (CtrlShiftPress(KEY_DOWN)) { // } else if (CtrlShiftPress(KEY_DOWN)) {
For(view.carets) it = ChangeFront(it, MovePos(*buffer, GetFront(it), DIR_DOWN, true)); // For(view.carets) it = ChangeFront(it, MovePos(*buffer, GetFront(it), DIR_DOWN, true));
} else if (CtrlPress(KEY_DOWN)) { // } else if (CtrlPress(KEY_DOWN)) {
For(view.carets) it = MakeCaret(MovePos(*buffer, it.range.max, DIR_DOWN, true)); // For(view.carets) it = MakeCaret(MovePos(*buffer, it.range.max, DIR_DOWN, true));
} else if (ShiftPress(KEY_DOWN)) { // } else if (ShiftPress(KEY_DOWN)) {
For(view.carets) it = ChangeFront(it, MovePos(*buffer, GetFront(it), DIR_DOWN, false)); // For(view.carets) it = ChangeFront(it, MovePos(*buffer, GetFront(it), DIR_DOWN, false));
} else if (Press(KEY_DOWN)) { // } else if (Press(KEY_DOWN)) {
For(view.carets) { // For(view.carets) {
if (GetSize(it.range) == 0) { // if (GetSize(it.range) == 0) {
it = MakeCaret(MovePos(*buffer, it.range.max, DIR_DOWN, false)); // it = MakeCaret(MovePos(*buffer, it.range.max, DIR_DOWN, false));
} else { // } else {
it = MakeCaret(it.range.max); // it = MakeCaret(it.range.max);
} // }
} // }
} // }
if (CtrlAltPress(KEY_UP)) { // if (CtrlAltPress(KEY_UP)) {
Command_DuplicateLine(&view, DIR_UP); // Command_DuplicateLine(&view, DIR_UP);
} else if (AltShiftPress(KEY_UP)) { // } else if (AltShiftPress(KEY_UP)) {
Command_CreateCursorVertical(&view, DIR_UP); // Command_CreateCursorVertical(&view, DIR_UP);
} else if (CtrlShiftPress(KEY_UP)) { // } else if (CtrlShiftPress(KEY_UP)) {
For(view.carets) it = ChangeFront(it, MovePos(*buffer, GetFront(it), DIR_UP, CTRL_PRESSED)); // For(view.carets) it = ChangeFront(it, MovePos(*buffer, GetFront(it), DIR_UP, CTRL_PRESSED));
} else if (CtrlPress(KEY_UP)) { // } else if (CtrlPress(KEY_UP)) {
For(view.carets) it = MakeCaret(MovePos(*buffer, it.range.min, DIR_UP, CTRL_PRESSED)); // For(view.carets) it = MakeCaret(MovePos(*buffer, it.range.min, DIR_UP, CTRL_PRESSED));
} else if (ShiftPress(KEY_UP)) { // } else if (ShiftPress(KEY_UP)) {
For(view.carets) it = ChangeFront(it, MovePos(*buffer, GetFront(it), DIR_UP)); // For(view.carets) it = ChangeFront(it, MovePos(*buffer, GetFront(it), DIR_UP));
} else if (Press(KEY_UP)) { // } else if (Press(KEY_UP)) {
For(view.carets) { // For(view.carets) {
if (GetSize(it.range) == 0) { // if (GetSize(it.range) == 0) {
it = MakeCaret(MovePos(*buffer, it.range.min, DIR_UP)); // it = MakeCaret(MovePos(*buffer, it.range.min, DIR_UP));
} else { // } else {
it = MakeCaret(it.range.min); // it = MakeCaret(it.range.min);
} // }
} // }
} // }
if (CtrlShiftPress(KEY_LEFT)) { // if (CtrlShiftPress(KEY_LEFT)) {
For(view.carets) it = ChangeFront(it, MovePos(*buffer, GetFront(it), DIR_LEFT, true)); // For(view.carets) it = ChangeFront(it, MovePos(*buffer, GetFront(it), DIR_LEFT, true));
} else if (CtrlPress(KEY_LEFT)) { // } else if (CtrlPress(KEY_LEFT)) {
For(view.carets) { // For(view.carets) {
if (GetSize(it.range) != 0 && GetFront(it) != it.range.min) { // if (GetSize(it.range) != 0 && GetFront(it) != it.range.min) {
it = MakeCaret(it.range.min); // it = MakeCaret(it.range.min);
} else { // } else {
it = MakeCaret(MovePos(*buffer, it.range.min, DIR_LEFT, true)); // it = MakeCaret(MovePos(*buffer, it.range.min, DIR_LEFT, true));
} // }
} // }
} else if (ShiftPress(KEY_LEFT)) { // } else if (ShiftPress(KEY_LEFT)) {
For(view.carets) it = ChangeFront(it, MovePos(*buffer, GetFront(it), DIR_LEFT, false)); // For(view.carets) it = ChangeFront(it, MovePos(*buffer, GetFront(it), DIR_LEFT, false));
} else if (Press(KEY_LEFT)) { // } else if (Press(KEY_LEFT)) {
For(view.carets) { // For(view.carets) {
if (GetSize(it.range) == 0) { // if (GetSize(it.range) == 0) {
it = MakeCaret(MovePos(*buffer, it.range.min, DIR_LEFT, false)); // it = MakeCaret(MovePos(*buffer, it.range.min, DIR_LEFT, false));
} else { // } else {
it = MakeCaret(it.range.min); // it = MakeCaret(it.range.min);
} // }
} // }
} // }
if (CtrlShiftPress(KEY_RIGHT)) { // if (CtrlShiftPress(KEY_RIGHT)) {
For(view.carets) it = ChangeFront(it, MovePos(*buffer, GetFront(it), DIR_RIGHT, true)); // For(view.carets) it = ChangeFront(it, MovePos(*buffer, GetFront(it), DIR_RIGHT, true));
} else if (CtrlPress(KEY_RIGHT)) { // } else if (CtrlPress(KEY_RIGHT)) {
For(view.carets) { // For(view.carets) {
if (GetSize(it.range) != 0 && GetFront(it) != it.range.max) { // if (GetSize(it.range) != 0 && GetFront(it) != it.range.max) {
it = MakeCaret(it.range.max); // it = MakeCaret(it.range.max);
} else { // } else {
it = MakeCaret(MovePos(*buffer, it.range.max, DIR_RIGHT, true)); // it = MakeCaret(MovePos(*buffer, it.range.max, DIR_RIGHT, true));
} // }
} // }
} else if (ShiftPress(KEY_RIGHT)) { // } else if (ShiftPress(KEY_RIGHT)) {
For(view.carets) it = ChangeFront(it, MovePos(*buffer, GetFront(it), DIR_RIGHT, false)); // For(view.carets) it = ChangeFront(it, MovePos(*buffer, GetFront(it), DIR_RIGHT, false));
} else if (Press(KEY_RIGHT)) { // } else if (Press(KEY_RIGHT)) {
For(view.carets) { // For(view.carets) {
if (GetSize(it.range) == 0) { // if (GetSize(it.range) == 0) {
it = MakeCaret(MovePos(*buffer, it.range.max, DIR_RIGHT, false)); // it = MakeCaret(MovePos(*buffer, it.range.max, DIR_RIGHT, false));
} else { // } else {
it = MakeCaret(it.range.max); // it = MakeCaret(it.range.max);
} // }
} // }
} // }
if (CtrlShiftPress(KEY_Z)) { // if (CtrlShiftPress(KEY_Z)) {
RedoEdit(buffer, &view.carets); // RedoEdit(buffer, &view.carets);
} else if (CtrlPress(KEY_Z)) { // } else if (CtrlPress(KEY_Z)) {
UndoEdit(buffer, &view.carets); // UndoEdit(buffer, &view.carets);
} // }
if (CtrlPress(KEY_C)) { // if (CtrlPress(KEY_C)) {
Command_Copy(&view); // Command_Copy(&view);
} else if (CtrlPress(KEY_V)) { // } else if (CtrlPress(KEY_V)) {
Command_Paste(&view); // Command_Paste(&view);
} else if (CtrlPress(KEY_X)) { // } else if (CtrlPress(KEY_X)) {
Command_Copy(&view); // Command_Copy(&view);
Command_Replace(&view, L""); // Command_Replace(&view, L"");
} // }
if (CtrlPress(KEY_A)) { // if (CtrlPress(KEY_A)) {
Command_SelectEntireBuffer(&view); // Command_SelectEntireBuffer(&view);
*update_scroll = false; // *update_scroll = false;
} // }
if (ShiftPress(KEY_PAGE_UP)) { // if (ShiftPress(KEY_PAGE_UP)) {
Command_MoveCursorsByPageSize(window, DIR_UP, SHIFT_PRESSED); // Command_MoveCursorsByPageSize(window, DIR_UP, SHIFT_PRESSED);
} else if (Press(KEY_PAGE_UP)) { // } else if (Press(KEY_PAGE_UP)) {
Command_MoveCursorsByPageSize(window, DIR_UP); // Command_MoveCursorsByPageSize(window, DIR_UP);
} // }
if (ShiftPress(KEY_PAGE_DOWN)) { // if (ShiftPress(KEY_PAGE_DOWN)) {
Command_MoveCursorsByPageSize(window, DIR_DOWN, SHIFT_PRESSED); // Command_MoveCursorsByPageSize(window, DIR_DOWN, SHIFT_PRESSED);
} else if (Press(KEY_PAGE_DOWN)) { // } else if (Press(KEY_PAGE_DOWN)) {
Command_MoveCursorsByPageSize(window, DIR_DOWN); // Command_MoveCursorsByPageSize(window, DIR_DOWN);
} // }
if (ShiftPress(KEY_HOME)) { // if (ShiftPress(KEY_HOME)) {
Command_MoveCursorsToSide(window, DIR_LEFT, SHIFT_PRESSED); // Command_MoveCursorsToSide(window, DIR_LEFT, SHIFT_PRESSED);
} else if (Press(KEY_HOME)) { // } else if (Press(KEY_HOME)) {
Command_MoveCursorsToSide(window, DIR_LEFT); // Command_MoveCursorsToSide(window, DIR_LEFT);
} // }
if (ShiftPress(KEY_END)) { // if (ShiftPress(KEY_END)) {
Command_MoveCursorsToSide(window, DIR_RIGHT, SHIFT_PRESSED); // Command_MoveCursorsToSide(window, DIR_RIGHT, SHIFT_PRESSED);
} else if (Press(KEY_END)) { // } else if (Press(KEY_END)) {
Command_MoveCursorsToSide(window, DIR_RIGHT); // Command_MoveCursorsToSide(window, DIR_RIGHT);
} // }
bool search = false; // bool search = false;
if (Press(KEY_TAB)) { // if (Press(KEY_TAB)) {
Command_Replace(&view, L" "); // Command_Replace(&view, L" ");
search = true; // search = true;
} // }
if (CtrlPress(KEY_BACKSPACE)) { // if (CtrlPress(KEY_BACKSPACE)) {
Command_Delete(&view, DIR_LEFT, CTRL_PRESSED); // Command_Delete(&view, DIR_LEFT, CTRL_PRESSED);
search = true; // search = true;
} else if (Press(KEY_BACKSPACE)) { // } else if (Press(KEY_BACKSPACE)) {
Command_Delete(&view, DIR_LEFT); // Command_Delete(&view, DIR_LEFT);
search = true; // search = true;
} // }
if (CtrlPress(KEY_DELETE)) { // if (CtrlPress(KEY_DELETE)) {
Command_Delete(&view, DIR_RIGHT, CTRL_PRESSED); // Command_Delete(&view, DIR_RIGHT, CTRL_PRESSED);
search = true; // search = true;
} else if (Press(KEY_DELETE)) { // } else if (Press(KEY_DELETE)) {
Command_Delete(&view, DIR_RIGHT); // Command_Delete(&view, DIR_RIGHT);
search = true; // search = true;
} // }
for (int c = GetCharPressed(); c; c = GetCharPressed()) { // for (int c = GetCharPressed(); c; c = GetCharPressed()) {
// we interpret 2 byte sequences as 1 byte when rendering but we still // // we interpret 2 byte sequences as 1 byte when rendering but we still
// want to read them properly. // // want to read them properly.
String16 string = L"?"; // String16 string = L"?";
UTF16Result result = UTF32ToUTF16((uint32_t)c); // UTF16Result result = UTF32ToUTF16((uint32_t)c);
if (!result.error) string = {(wchar_t *)result.out_str, result.len}; // if (!result.error) string = {(wchar_t *)result.out_str, result.len};
Command_Replace(&view, string); // Command_Replace(&view, string);
search = true; // search = true;
} // }
if (CtrlPress(KEY_D)) { // if (CtrlPress(KEY_D)) {
String16 string = GetString(*buffer, view.carets[0].range); // String16 string = GetString(*buffer, view.carets[0].range);
Caret caret = FindInBuffer(buffer, string, view.carets[0], true); // Caret caret = FindInBuffer(buffer, string, view.carets[0], true);
Insert(&view.carets, caret, 0); // Insert(&view.carets, caret, 0);
MergeCarets(&view); // MergeCarets(&view);
} // }
if (Press(KEY_F3)) { // if (Press(KEY_F3)) {
Buffer *search_buffer = GetBuffer("*search*"); // Buffer *search_buffer = GetBuffer("*search*");
String16 search_string = GetString(*search_buffer); // String16 search_string = GetString(*search_buffer);
Caret caret = FindInBuffer(buffer, search_string, view.carets[0], true); // Caret caret = FindInBuffer(buffer, search_string, view.carets[0], true);
if (Ctrl()) { // if (Ctrl()) {
Insert(&view.carets, caret, 0); // Insert(&view.carets, caret, 0);
MergeCarets(&view); // MergeCarets(&view);
} else { // } else {
view.carets.len = 1; // view.carets.len = 1;
view.carets[0] = caret; // view.carets[0] = caret;
} // }
} // }
if (window->id.id == SearchWindowID.id) { // if (window->id.id == SearchWindowID.id) {
Window *seek_window = GetWindow(GetLastActiveWindow()); // Window *seek_window = GetWindow(GetLastActiveWindow());
View *seek_view = GetView(seek_window->active_view); // View *seek_view = GetView(seek_window->active_view);
Buffer *seek_buffer = GetBuffer(seek_view->active_buffer); // Buffer *seek_buffer = GetBuffer(seek_view->active_buffer);
String16 needle = GetString(*buffer); // String16 needle = GetString(*buffer);
if (search) { // if (search) {
seek_view->carets[0] = FindInBuffer(seek_buffer, needle, seek_view->carets[0]); // seek_view->carets[0] = FindInBuffer(seek_buffer, needle, seek_view->carets[0]);
seek_view->carets.len = 1; // seek_view->carets.len = 1;
} // }
if (AltPress(KEY_ENTER)) { // if (AltPress(KEY_ENTER)) {
Command_SelectAll(seek_view, needle); // Command_SelectAll(seek_view, needle);
// SetActiveWindow(seek_window->id); // // SetActiveWindow(seek_window->id);
} else if (Press(KEY_ENTER)) { // } else if (Press(KEY_ENTER)) {
Caret caret = FindInBuffer(seek_buffer, needle, seek_view->carets[0], true); // Caret caret = FindInBuffer(seek_buffer, needle, seek_view->carets[0], true);
if (Ctrl()) { // if (Ctrl()) {
Insert(&seek_view->carets, caret, 0); // Insert(&seek_view->carets, caret, 0);
MergeCarets(seek_view); // MergeCarets(seek_view);
} else { // } else {
seek_view->carets.len = 1; // seek_view->carets.len = 1;
seek_view->carets[0] = caret; // seek_view->carets[0] = caret;
} // }
} // }
} // }
if (window->fuzzy_search && search) { // if (window->fuzzy_search && search) {
Scratch scratch; // Scratch scratch;
String16 first_line_string = GetLineStringWithoutNL(*buffer, 0); // String16 first_line_string = GetLineStringWithoutNL(*buffer, 0);
Array<FuzzyPair> ratings = FuzzySearchLines(scratch, buffer, 1, buffer->line_starts.len, first_line_string); // Array<FuzzyPair> ratings = FuzzySearchLines(scratch, buffer, 1, buffer->line_starts.len, first_line_string);
Buffer *temp_buffer = CreateTempBuffer(scratch, buffer->cap); // Buffer *temp_buffer = CreateTempBuffer(scratch, buffer->cap);
ReplaceText(temp_buffer, GetEndAsRange(*temp_buffer), first_line_string); // ReplaceText(temp_buffer, GetEndAsRange(*temp_buffer), first_line_string);
ReplaceText(temp_buffer, GetEndAsRange(*temp_buffer), L"\n"); // ReplaceText(temp_buffer, GetEndAsRange(*temp_buffer), L"\n");
For(ratings) { // For(ratings) {
String16 s = GetLineStringWithoutNL(*buffer, it.index); // String16 s = GetLineStringWithoutNL(*buffer, it.index);
if (s.len == 0) continue; // if (s.len == 0) continue;
ReplaceText(temp_buffer, GetEndAsRange(*temp_buffer), s); // ReplaceText(temp_buffer, GetEndAsRange(*temp_buffer), s);
ReplaceText(temp_buffer, GetEndAsRange(*temp_buffer), L"\n"); // ReplaceText(temp_buffer, GetEndAsRange(*temp_buffer), L"\n");
} // }
Caret caret = view.carets[0]; // Caret caret = view.carets[0];
Command_SelectEntireBuffer(&view); // Command_SelectEntireBuffer(&view);
Command_Replace(&view, GetString(*temp_buffer)); // Command_Replace(&view, GetString(*temp_buffer));
view.carets[0] = caret; // view.carets[0] = caret;
} // }
if (CtrlPress(KEY_Q) || IsMouseButtonPressed(MOUSE_BUTTON_MIDDLE)) { // if (CtrlPress(KEY_Q) || IsMouseButtonPressed(MOUSE_BUTTON_MIDDLE)) {
// @todo: Consider applying this to all cursors // // @todo: Consider applying this to all cursors
if (GetSize(view.carets[0].range) == 0) { // if (GetSize(view.carets[0].range) == 0) {
Command_EvalLuaLine(&view); // Command_EvalLuaLine(&view);
} else { // } else {
String16 string = GetString(*buffer, view.carets[0].range); // String16 string = GetString(*buffer, view.carets[0].range);
Command_EvalLua(&view, string); // Command_EvalLua(&view, string);
} // }
} // }
if (window->execute_line) { // if (window->execute_line) {
if (Press(KEY_ENTER)) { // if (Press(KEY_ENTER)) {
Command_EvalLuaLine(&view); // Command_EvalLuaLine(&view);
} // }
} else if (window->id.id == SearchWindowID.id) { // } else if (window->id.id == SearchWindowID.id) {
} else { // } else {
if (CtrlPress(KEY_ENTER)) { // if (CtrlPress(KEY_ENTER)) {
Command_MoveCursorsToSide(window, DIR_RIGHT); // Command_MoveCursorsToSide(window, DIR_RIGHT);
Command_Replace(&view, L"\n"); // Command_Replace(&view, L"\n");
} else if (Press(KEY_ENTER)) { // } else if (Press(KEY_ENTER)) {
Command_Replace(&view, L"\n"); // Command_Replace(&view, L"\n");
} // }
} // }
{ // {
ProfileScope(mouse); // ProfileScope(mouse);
Vec2 _mouse = GetMousePosition(); // Vec2 _mouse = GetMousePosition();
bool mouse_in_view = CheckCollisionPointRec(_mouse, ToRectangle(window->document_rect)); // bool mouse_in_view = CheckCollisionPointRec(_mouse, ToRectangle(window->document_rect));
bool mouse_in_scrollbar = CheckCollisionPointRec(_mouse, ToRectangle(window->scrollbar_rect)); // bool mouse_in_scrollbar = CheckCollisionPointRec(_mouse, ToRectangle(window->scrollbar_rect));
Vec2I mouse = ToVec2I(_mouse); // Vec2I mouse = ToVec2I(_mouse);
if (!(mouse_in_scrollbar || window->mouse_selecting_scrollbar) && (mouse_in_view || window->mouse_selecting)) { // if (!(mouse_in_scrollbar || window->mouse_selecting_scrollbar) && (mouse_in_view || window->mouse_selecting)) {
Vec2I mworld = mouse - window->document_rect.min + view.scroll; // Vec2I mworld = mouse - window->document_rect.min + view.scroll;
Vec2I pos = mworld / Vec2I{FontCharSpacing, FontLineSpacing}; // Vec2I pos = mworld / Vec2I{FontCharSpacing, FontLineSpacing};
XY xy = {(Int)(pos.x), (Int)(pos.y)}; // XY xy = {(Int)(pos.x), (Int)(pos.y)};
Int p = XYToPosWithoutNL(*buffer, xy); // Int p = XYToPosWithoutNL(*buffer, xy);
if (mouse_in_view && IsMouseButtonDown(MOUSE_BUTTON_LEFT)) { // if (mouse_in_view && IsMouseButtonDown(MOUSE_BUTTON_LEFT)) {
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) { // if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
if (IsDoubleClick()) { // if (IsDoubleClick()) {
Caret *c = &view.carets[0]; // Caret *c = &view.carets[0];
if (InBounds({c->range.min - 1, c->range.max + 1}, p)) { // if (InBounds({c->range.min - 1, c->range.max + 1}, p)) {
c->range = EncloseWord(*buffer, p); // c->range = EncloseWord(*buffer, p);
view.selection_anchor = c->range; // view.selection_anchor = c->range;
} // }
} else { // } else {
if (!IsKeyDown(KEY_LEFT_CONTROL)) { // if (!IsKeyDown(KEY_LEFT_CONTROL)) {
view.carets.len = 0; // view.carets.len = 0;
} // }
Insert(&view.carets, MakeCaret(p, p), 0); // Insert(&view.carets, MakeCaret(p, p), 0);
view.selection_anchor = view.carets[0].range; // view.selection_anchor = view.carets[0].range;
} // }
} else if (IsMouseButtonDown(MOUSE_BUTTON_LEFT)) { // } else if (IsMouseButtonDown(MOUSE_BUTTON_LEFT)) {
window->mouse_selecting = true; // window->mouse_selecting = true;
} // }
} // }
if (window->mouse_selecting) { // if (window->mouse_selecting) {
if (!IsMouseButtonDown(MOUSE_BUTTON_LEFT)) window->mouse_selecting = false; // if (!IsMouseButtonDown(MOUSE_BUTTON_LEFT)) window->mouse_selecting = false;
MergeCarets(&view, &view.selection_anchor); // MergeCarets(&view, &view.selection_anchor);
Caret &caret = view.carets[0]; // Caret &caret = view.carets[0];
if (view.selection_anchor.min > p) { // if (view.selection_anchor.min > p) {
caret = MakeCaret(p, view.selection_anchor.max); // caret = MakeCaret(p, view.selection_anchor.max);
} else if (view.selection_anchor.max < p) { // } else if (view.selection_anchor.max < p) {
caret = MakeCaret(p, view.selection_anchor.min); // caret = MakeCaret(p, view.selection_anchor.min);
} else { // } else {
caret = MakeCaret(view.selection_anchor.max, view.selection_anchor.min); // caret = MakeCaret(view.selection_anchor.max, view.selection_anchor.min);
} // }
MergeCarets(&view, &view.selection_anchor); // MergeCarets(&view, &view.selection_anchor);
} // }
} else if (!(mouse_in_view || window->mouse_selecting) && mouse_in_scrollbar || window->mouse_selecting_scrollbar) { // } else if (!(mouse_in_view || window->mouse_selecting) && mouse_in_scrollbar || window->mouse_selecting_scrollbar) {
Scroller s = ComputeScrollerRect(*window); // Scroller s = ComputeScrollerRect(*window);
double size_y = (double)GetSize(window->scrollbar_rect).y; // double size_y = (double)GetSize(window->scrollbar_rect).y;
double p = _mouse.y - window->scrollbar_rect.min.y; // double p = _mouse.y - window->scrollbar_rect.min.y;
if (IsMouseButtonDown(MOUSE_BUTTON_LEFT)) { // if (IsMouseButtonDown(MOUSE_BUTTON_LEFT)) {
window->mouse_selecting_scrollbar = true; // window->mouse_selecting_scrollbar = true;
} else if (!IsMouseButtonDown(MOUSE_BUTTON_LEFT)) { // } else if (!IsMouseButtonDown(MOUSE_BUTTON_LEFT)) {
window->mouse_selecting_scrollbar = false; // window->mouse_selecting_scrollbar = false;
} // }
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) { // if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
if (_mouse.y < s.rect.min.y || _mouse.y > s.rect.max.y) { // if (_mouse.y < s.rect.min.y || _mouse.y > s.rect.max.y) {
view.scroll.y = (Int)(p / size_y * (double)s.line_count * (double)FontLineSpacing); // 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; // window->mouse_scroller_offset = -(double)GetSize(s.rect).y / 2.0 / size_y;
} else { // } else {
window->mouse_scroller_offset = (s.rect.min.y - p) / size_y; // window->mouse_scroller_offset = (s.rect.min.y - p) / size_y;
} // }
} // }
if (window->mouse_selecting_scrollbar) { // if (window->mouse_selecting_scrollbar) {
double v = p / size_y; // double v = p / size_y;
v = v + (window->mouse_scroller_offset); // v = v + (window->mouse_scroller_offset);
view.scroll.y = (Int)(v * (double)s.line_count * (double)FontLineSpacing); // view.scroll.y = (Int)(v * (double)s.line_count * (double)FontLineSpacing);
} // }
} // }
} // }
MergeCarets(&view); MergeCarets(&view);
} }
@@ -638,24 +638,24 @@ void ChangeActiveWindowAndScroll(Array<Int> &order) {
View *view = GetActiveView(window); View *view = GetActiveView(window);
view->main_caret_on_begin_frame = view->carets[0]; view->main_caret_on_begin_frame = view->carets[0];
Vec2 mouse = GetMousePosition(); // Vec2 mouse = GetMousePosition();
bool mouse_in_window = CheckCollisionPointRec(mouse, ToRectangle(window->total_rect)); // bool mouse_in_window = CheckCollisionPointRec(mouse, ToRectangle(window->total_rect));
if (mouse_in_window) { // if (mouse_in_window) {
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) { // if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
Window *active_window = GetWindow(ActiveWindow); // Window *active_window = GetWindow(ActiveWindow);
if (active_window->z <= window->z) { // if (active_window->z <= window->z) {
SetActiveWindow(window->id); // SetActiveWindow(window->id);
} // }
} // }
if (LastFrameIDWhenScrolled != FrameID) { // if (LastFrameIDWhenScrolled != FrameID) {
if (IsKeyDown(KEY_F1)) { // if (IsKeyDown(KEY_F1)) {
view->scroll.x -= (Int)(GetMouseWheelMove() * 48); // view->scroll.x -= (Int)(GetMouseWheelMove() * 48);
} else { // } else {
view->scroll.y -= (Int)(GetMouseWheelMove() * 48); // view->scroll.y -= (Int)(GetMouseWheelMove() * 48);
} // }
LastFrameIDWhenScrolled = FrameID; // LastFrameIDWhenScrolled = FrameID;
} // }
} // }
} }
} }

View File

@@ -26,6 +26,8 @@
#include "management.cpp" #include "management.cpp"
#include "window.cpp" #include "window.cpp"
#include "commands.cpp"
#include "commands_window.cpp"
#include "colors.cpp" #include "colors.cpp"
#include "window_draw.cpp" #include "window_draw.cpp"
@@ -139,135 +141,14 @@ int main()
FontLineSpacing = GetLineSpacing(&MainFont); FontLineSpacing = GetLineSpacing(&MainFont);
} }
Allocator sys_allocator = GetSystemAllocator(); InitWindows();
{
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 (AppIsRunning) { while (AppIsRunning) {
FrameID += 1; FrameID += 1;
int window_x, window_y; int window_x, window_y;
SDL_GetWindowSize(window, &window_x, &window_y); SDL_GetWindowSize(window, &window_x, &window_y);
Vec2 window_size = {(float)window_x, (float)window_y}; WindowSize = {(float)window_x, (float)window_y};
BeginFrameRender(window_size); BeginFrameRender();
LayoutWindows();
Rect2I screen_rect = GetScreenRectI();
Rect2I infobar_rect = CutBottom(&screen_rect, (Int)FontLineSpacing);
float line_numbers_size = GetStringSize(&MainFont, L"1234567891").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;
}
SDL_Event event; SDL_Event event;
if (WaitForEvents) { if (WaitForEvents) {
@@ -280,6 +161,7 @@ int main()
Scratch scratch; Scratch scratch;
Array<Int> order = GetWindowZOrder(scratch); Array<Int> order = GetWindowZOrder(scratch);
For(IterateInReverse(&order)) { For(IterateInReverse(&order)) {
Window &window = Windows[it]; Window &window = Windows[it];
if (window.visible) { if (window.visible) {
@@ -287,7 +169,6 @@ int main()
DrawWindow(window); DrawWindow(window);
} }
} }
// { // {
// Scratch scratch; // Scratch scratch;
// uint64_t ms = SDL_GetTicks(); // uint64_t ms = SDL_GetTicks();

View File

@@ -4,6 +4,7 @@
- We can actually combine this with command window and lua, it's just going to be a buffer of - We can actually combine this with command window and lua, it's just going to be a buffer of
- open "asd/asd/asd/asd" - open "asd/asd/asd/asd"
- Ctrl + F - Ctrl + F
- Rework window views to contain a history of past views
- word completion - word completion
- Colored strings - Colored strings

View File

@@ -22,3 +22,130 @@ Array<Int> GetWindowZOrder(Allocator allocator) {
For(Windows) if (it.z == 0) Add(&order, GetIndex(Windows, it)); For(Windows) if (it.z == 0) Add(&order, GetIndex(Windows, it));
return order; return order;
} }
void InitWindows() {
Allocator sys_allocator = GetSystemAllocator();
{
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);
}
{
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;
}
SetActiveWindow({1});
}
void LayoutWindows() {
Rect2I screen_rect = GetScreenRectI();
Rect2I infobar_rect = CutBottom(&screen_rect, (Int)FontLineSpacing);
float line_numbers_size = GetStringSize(&MainFont, L"1234567891").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;
}
}

View File

@@ -57,17 +57,12 @@ void DrawVisibleText(Window &window) {
int codepoint = line_string[col_index]; int codepoint = line_string[col_index];
Glyph *g = GetGlyph(&MainFont, codepoint); Glyph *g = GetGlyph(&MainFont, codepoint);
Vec2 p = ToVec2(pos); Vec2 p = ToVec2(pos);
p.y += MainFont.ascent; p.y += MainFont.ascent - MainFont.descent;
p.x += text_offset_x; p.x += text_offset_x;
Rect2 rect = Rect2FromSize(p + g->offset, g->size); Rect2 rect = Rect2FromSize(p + g->offset, g->size);
if (codepoint == '\n' || codepoint == '\r') { if (codepoint != '\n' && codepoint != '\r' && codepoint != ' ') {
// 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') {
PushQuad2D(RenderArena, &Vertices, rect, g->atlas_bounding_box, tint); PushQuad2D(RenderArena, &Vertices, rect, g->atlas_bounding_box, tint);
// DrawTextCodepoint(MainFont, codepoint, {(float)pos.x + text_offset_x, (float)pos.y}, (float)FontSize, tint);
} }
if (g->xadvance == 0) text_offset_x += g->size.x; if (g->xadvance == 0) text_offset_x += g->size.x;
@@ -101,7 +96,7 @@ void DrawWindow(Window &window) {
DrawRect(ToRect2(window.total_rect), ColorBackground); DrawRect(ToRect2(window.total_rect), ColorBackground);
bool is_active = IsActive(&window) || window.id.id == GetLastActiveWindow().id; bool is_active = IsActive(&window) || window.id.id == GetLastActiveWindow().id;
BeginScissor(window.document_rect); SetScissor(ToRect2(window.document_rect));
BeginProfileScope(draw_caret_selection); BeginProfileScope(draw_caret_selection);
Rect2I visible = GetVisibleCells(window); Rect2I visible = GetVisibleCells(window);
For(view.carets) { For(view.carets) {
@@ -167,28 +162,12 @@ void DrawWindow(Window &window) {
} }
} }
EndProfileScope(); EndProfileScope();
EndScissor();
// Draw scrollbar
if (window.draw_scrollbar) {
// Vec2 mouse = GetMousePosition();
// bool mouse_in_scrollbar = CheckCollisionPointRec(mouse, ToRectangle(window.scrollbar_rect));
DrawRect(ToRect2(window.scrollbar_rect), ColorScrollbarBackground);
Scroller scroller = ComputeScrollerRect(window);
Rect2 rect = Shrink(scroller.rect, 2);
Color color = ColorScrollbarScroller;
// if (!window.mouse_selecting && (window.mouse_selecting_scrollbar || mouse_in_scrollbar)) {
// if (is_active) color = ColorScrollbarScrollerSelected;
// }
DrawRect(rect, color);
}
// Draw line numbers // Draw line numbers
if (window.draw_line_numbers) { if (window.draw_line_numbers) {
Rect2I r = window.line_numbers_rect; Rect2I r = window.line_numbers_rect;
DrawRect(ToRect2(r), ColorBackground); DrawRect(ToRect2(r), ColorBackground);
BeginScissor(r); SetScissor(ToRect2(r));
Rect2I vlines = GetVisibleCells(window); Rect2I vlines = GetVisibleCells(window);
for (Int line = vlines.min.y; line <= vlines.max.y; line += 1) { for (Int line = vlines.min.y; line <= vlines.max.y; line += 1) {
@@ -205,8 +184,22 @@ void DrawWindow(Window &window) {
if (x > rectx) p.x = (float)r.min.x; if (x > rectx) p.x = (float)r.min.x;
DrawString(&MainFont, string, p, ColorTextLineNumbers); DrawString(&MainFont, string, p, ColorTextLineNumbers);
} }
}
EndScissor(); SetScissor(GetScreenRectF());
// Draw scrollbar
if (window.draw_scrollbar) {
// Vec2 mouse = GetMousePosition();
// bool mouse_in_scrollbar = CheckCollisionPointRec(mouse, ToRectangle(window.scrollbar_rect));
DrawRect(ToRect2(window.scrollbar_rect), ColorScrollbarBackground);
Scroller scroller = ComputeScrollerRect(window);
Rect2 rect = Shrink(scroller.rect, 2);
Color color = ColorScrollbarScroller;
// if (!window.mouse_selecting && (window.mouse_selecting_scrollbar || mouse_in_scrollbar)) {
// if (is_active) color = ColorScrollbarScrollerSelected;
// }
DrawRect(rect, color);
} }
if (!is_active) { if (!is_active) {