Small refactor
This commit is contained in:
@@ -37,7 +37,7 @@ void Command_MoveCursorsByPageSize(Window *window, int direction, bool shift = f
|
|||||||
View &view = *GetActiveView(window);
|
View &view = *GetActiveView(window);
|
||||||
Buffer *buffer = GetBuffer(view.active_buffer);
|
Buffer *buffer = GetBuffer(view.active_buffer);
|
||||||
|
|
||||||
Rect2I visible_cells_rect = GetVisibleCells(*window);
|
Rect2I visible_cells_rect = GetVisibleCells(window);
|
||||||
Int y = GetSize(visible_cells_rect).y - 2;
|
Int y = GetSize(visible_cells_rect).y - 2;
|
||||||
if (direction == DIR_UP) y = -y;
|
if (direction == DIR_UP) y = -y;
|
||||||
|
|
||||||
@@ -572,7 +572,7 @@ void WindowCommand(Event event, Window *window, View *view) {
|
|||||||
MergeCarets(view, &view->selection_anchor);
|
MergeCarets(view, &view->selection_anchor);
|
||||||
}
|
}
|
||||||
} else if (!(mouse_in_document || window->mouse_selecting) && mouse_in_scrollbar || window->mouse_selecting_scrollbar) {
|
} else if (!(mouse_in_document || 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_vec2.y - window->scrollbar_rect.min.y;
|
double p = mouse_vec2.y - window->scrollbar_rect.min.y;
|
||||||
|
|
||||||
|
|||||||
@@ -174,10 +174,6 @@ int main()
|
|||||||
Array<Int> order = GetWindowZOrder(scratch);
|
Array<Int> order = GetWindowZOrder(scratch);
|
||||||
For(order) {
|
For(order) {
|
||||||
Window *window = &Windows[it];
|
Window *window = &Windows[it];
|
||||||
if (window->invisible_when_inactive) {
|
|
||||||
if (IsActive(window)) window->visible = true;
|
|
||||||
else window->visible = false;
|
|
||||||
}
|
|
||||||
if (!window->visible) continue;
|
if (!window->visible) continue;
|
||||||
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];
|
||||||
@@ -206,9 +202,16 @@ int main()
|
|||||||
|
|
||||||
ReplaceInfobarData();
|
ReplaceInfobarData();
|
||||||
|
|
||||||
For(order) {
|
For(IterateInReverse(&order)) {
|
||||||
Window *window = &Windows[it];
|
Window *window = &Windows[it];
|
||||||
|
{
|
||||||
|
if (window->invisible_when_inactive) {
|
||||||
|
if (IsActive(window)) window->visible = true;
|
||||||
|
else window->visible = false;
|
||||||
|
}
|
||||||
if (!window->visible) continue;
|
if (!window->visible) continue;
|
||||||
|
}
|
||||||
|
|
||||||
View *view = GetActiveView(window);
|
View *view = GetActiveView(window);
|
||||||
Buffer *buffer = GetBuffer(view->active_buffer);
|
Buffer *buffer = GetBuffer(view->active_buffer);
|
||||||
|
|
||||||
@@ -218,7 +221,7 @@ int main()
|
|||||||
Int front = GetFront(c);
|
Int front = GetFront(c);
|
||||||
XY xy = PosToXY(*buffer, front);
|
XY xy = PosToXY(*buffer, front);
|
||||||
|
|
||||||
Rect2I visible = GetVisibleCells(*window);
|
Rect2I visible = GetVisibleCells(window);
|
||||||
Vec2I visible_cells = GetSize(visible);
|
Vec2I visible_cells = GetSize(visible);
|
||||||
Vec2I visible_size = visible_cells * Vec2I{FontCharSpacing, FontLineSpacing};
|
Vec2I visible_size = visible_cells * Vec2I{FontCharSpacing, FontLineSpacing};
|
||||||
Vec2I rect_size = GetSize(window->document_rect);
|
Vec2I rect_size = GetSize(window->document_rect);
|
||||||
@@ -255,12 +258,7 @@ int main()
|
|||||||
// calculating this value incrementally but do we even need X scrollbar or x clipping?
|
// calculating this value incrementally but do we even need X scrollbar or x clipping?
|
||||||
view->scroll.x = ClampBottom(view->scroll.x, (Int)0);
|
view->scroll.x = ClampBottom(view->scroll.x, (Int)0);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
For(IterateInReverse(&order)) {
|
|
||||||
Window &window = Windows[it];
|
|
||||||
if (!window.visible) continue;
|
|
||||||
// HandleWindowBindings(&window);
|
|
||||||
DrawWindow(window);
|
DrawWindow(window);
|
||||||
}
|
}
|
||||||
EndFrameRender(ColorBackground);
|
EndFrameRender(ColorBackground);
|
||||||
|
|||||||
@@ -90,9 +90,9 @@ String WorkingDir;
|
|||||||
Arena Perm;
|
Arena Perm;
|
||||||
|
|
||||||
String16 EvalString(Allocator allocator, String16 string16);
|
String16 EvalString(Allocator allocator, String16 string16);
|
||||||
Rect2I GetVisibleCells(Window &window);
|
Rect2I GetVisibleCells(Window *window);
|
||||||
void AfterEdit(View *view, Array<Edit> edits);
|
void AfterEdit(View *view, Array<Edit> edits);
|
||||||
Scroller ComputeScrollerRect(Window &window);
|
Scroller ComputeScrollerRect(Window *window);
|
||||||
void Command_EvalLua(View *view, String16 string);
|
void Command_EvalLua(View *view, String16 string);
|
||||||
void MergeCarets(View *view, Range *mouse_selection_anchor = NULL);
|
void MergeCarets(View *view, Range *mouse_selection_anchor = NULL);
|
||||||
inline BufferID AllocBufferID();
|
inline BufferID AllocBufferID();
|
||||||
@@ -9,7 +9,4 @@
|
|||||||
- word completion
|
- word completion
|
||||||
- Colored strings
|
- Colored strings
|
||||||
|
|
||||||
- move off raylib
|
|
||||||
- Adjust text position a little bit down?
|
|
||||||
- proper double click that works on laptop
|
|
||||||
- font cache and on demand unicode loads
|
- font cache and on demand unicode loads
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
Array<Int> GetWindowZOrder(Allocator allocator) {
|
Array<Int> GetWindowZOrder(Allocator allocator) {
|
||||||
Array<Int> order = {allocator};
|
Array<Int> order = {allocator};
|
||||||
For(Windows) if (it.z == 2) Add(&order, GetIndex(Windows, it));
|
For(Windows) if (it.z == 2) Add(&order, GetIndex(Windows, it));
|
||||||
@@ -87,11 +86,11 @@ void LayoutWindows() {
|
|||||||
float line_numbers_size = GetStringSize(&MainFont, L"1234567891").x;
|
float line_numbers_size = GetStringSize(&MainFont, L"1234567891").x;
|
||||||
{
|
{
|
||||||
int i = 5;
|
int i = 5;
|
||||||
if (Windows[i].visible) {
|
Rect2I sr = screen_rect;
|
||||||
Rect2I rect = CutBottom(&screen_rect, FontLineSpacing);
|
Rect2I rect = CutBottom(&sr, FontLineSpacing);
|
||||||
Windows[i].total_rect = rect;
|
Windows[i].total_rect = rect;
|
||||||
Windows[i].document_rect = Windows[i].total_rect;
|
Windows[i].document_rect = Windows[i].total_rect;
|
||||||
}
|
Windows[i].z = 1;
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|||||||
@@ -3,27 +3,27 @@ Vec2I GetCellSize() {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Rect2I GetVisibleCells(Window &window) {
|
Rect2I GetVisibleCells(Window *window) {
|
||||||
ProfileFunction();
|
ProfileFunction();
|
||||||
View &view = *GetActiveView(&window);
|
View *view = GetActiveView(window);
|
||||||
Vec2I size = GetSize(window.document_rect);
|
Vec2I size = GetSize(window->document_rect);
|
||||||
|
|
||||||
Int _cx = size.x / FontCharSpacing;
|
Int _cx = size.x / FontCharSpacing;
|
||||||
Int _cy = size.y / FontLineSpacing;
|
Int _cy = size.y / FontLineSpacing;
|
||||||
Int cx = _cx + 1;
|
Int cx = _cx + 1;
|
||||||
Int cy = _cy + 2;
|
Int cy = _cy + 2;
|
||||||
|
|
||||||
Vec2I pos = {SafeDivide(view.scroll.x, FontCharSpacing), SafeDivide(view.scroll.y, FontLineSpacing)};
|
Vec2I pos = {SafeDivide(view->scroll.x, FontCharSpacing), SafeDivide(view->scroll.y, FontLineSpacing)};
|
||||||
Int x = pos.x;
|
Int x = pos.x;
|
||||||
Int y = pos.y;
|
Int y = pos.y;
|
||||||
Rect2I result = {x, y, x + cx, y + cy};
|
Rect2I result = {x, y, x + cx, y + cy};
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Scroller ComputeScrollerRect(Window &window) {
|
Scroller ComputeScrollerRect(Window *window) {
|
||||||
View &view = *GetActiveView(&window);
|
View *view = GetActiveView(window);
|
||||||
Buffer *buffer = GetBuffer(view.active_buffer);
|
Buffer *buffer = GetBuffer(view->active_buffer);
|
||||||
Vec2I size = GetSize(window.scrollbar_rect);
|
Vec2I size = GetSize(window->scrollbar_rect);
|
||||||
Rect2I vis = GetVisibleCells(window);
|
Rect2I vis = GetVisibleCells(window);
|
||||||
Int line_count = buffer->line_starts.len + GetSize(vis).y - 1;
|
Int line_count = buffer->line_starts.len + GetSize(vis).y - 1;
|
||||||
|
|
||||||
@@ -31,17 +31,17 @@ Scroller ComputeScrollerRect(Window &window) {
|
|||||||
double end = (double)vis.max.y / (double)line_count;
|
double end = (double)vis.max.y / (double)line_count;
|
||||||
|
|
||||||
Rect2 rect = {
|
Rect2 rect = {
|
||||||
{(float)window.scrollbar_rect.min.x, (float)window.scrollbar_rect.min.y + (float)((double)size.y * begin)},
|
{(float)window->scrollbar_rect.min.x, (float)window->scrollbar_rect.min.y + (float)((double)size.y * begin)},
|
||||||
{(float)window.scrollbar_rect.max.x, (float)window.scrollbar_rect.min.y + (float)((double)size.y * end)},
|
{(float)window->scrollbar_rect.max.x, (float)window->scrollbar_rect.min.y + (float)((double)size.y * end)},
|
||||||
};
|
};
|
||||||
Scroller result = {rect, begin, end, line_count};
|
Scroller result = {rect, begin, end, line_count};
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawVisibleText(Window &window) {
|
void DrawVisibleText(Window *window) {
|
||||||
ProfileFunction();
|
ProfileFunction();
|
||||||
Color tint = ColorText;
|
Color tint = ColorText;
|
||||||
View *view = GetActiveView(&window);
|
View *view = GetActiveView(window);
|
||||||
Buffer *buffer = GetBuffer(view->active_buffer);
|
Buffer *buffer = GetBuffer(view->active_buffer);
|
||||||
|
|
||||||
Rect2I visible = GetVisibleCells(window);
|
Rect2I visible = GetVisibleCells(window);
|
||||||
@@ -50,7 +50,7 @@ void DrawVisibleText(Window &window) {
|
|||||||
|
|
||||||
Vec2I pos = {visible.min.x * (Int)FontCharSpacing, line_index * (Int)FontLineSpacing};
|
Vec2I pos = {visible.min.x * (Int)FontCharSpacing, line_index * (Int)FontLineSpacing};
|
||||||
pos -= view->scroll;
|
pos -= view->scroll;
|
||||||
pos += window.document_rect.min;
|
pos += window->document_rect.min;
|
||||||
|
|
||||||
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) {
|
||||||
@@ -70,36 +70,36 @@ void DrawVisibleText(Window &window) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Vec2I XYToWorldPos(const View &view, XY xy) {
|
Vec2I XYToWorldPos(View *view, XY xy) {
|
||||||
Vec2I result = {xy.col * (Int)FontCharSpacing, xy.line * (Int)FontLineSpacing};
|
Vec2I result = {xy.col * (Int)FontCharSpacing, xy.line * (Int)FontLineSpacing};
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Rect2I XYToRect(const View &view, XY xy) {
|
Rect2I XYToRect(View *view, XY xy) {
|
||||||
Rect2I result = Rect2IFromSize(XYToWorldPos(view, xy), GetCellSize());
|
Rect2I result = Rect2IFromSize(XYToWorldPos(view, xy), GetCellSize());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawCaret(Window &window, XY xy, float size, Color color) {
|
void DrawCaret(Window *window, XY xy, float size, Color color) {
|
||||||
View &view = *GetActiveView(&window);
|
View *view = GetActiveView(window);
|
||||||
Rect2I _rect = XYToRect(view, xy);
|
Rect2I _rect = XYToRect(view, xy);
|
||||||
Rect2I rect = CutLeft(&_rect, (Int)(size * (float)FontCharSpacing));
|
Rect2I rect = CutLeft(&_rect, (Int)(size * (float)FontCharSpacing));
|
||||||
rect -= view.scroll;
|
rect -= view->scroll;
|
||||||
rect += window.document_rect.min;
|
rect += window->document_rect.min;
|
||||||
DrawRect(ToRect2(rect), color);
|
DrawRect(ToRect2(rect), color);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawWindow(Window &window) {
|
void DrawWindow(Window *window) {
|
||||||
View &view = *GetActiveView(&window);
|
View *view = GetActiveView(window);
|
||||||
Buffer *buffer = GetBuffer(view.active_buffer);
|
Buffer *buffer = GetBuffer(view->active_buffer);
|
||||||
SetScissor(GetScreenRectF());
|
SetScissor(GetScreenRectF());
|
||||||
DrawRect(window.total_rect, ColorBackground);
|
DrawRect(window->total_rect, ColorBackground);
|
||||||
bool is_active = IsActive(&window) || window.id.id == GetLastActiveWindow().id;
|
bool is_active = IsActive(window) || window->id.id == GetLastActiveWindow().id;
|
||||||
|
|
||||||
SetScissor(window.document_rect);
|
SetScissor(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) {
|
||||||
XY min = PosToXY(*buffer, it.range.min);
|
XY min = PosToXY(*buffer, it.range.min);
|
||||||
XY max = PosToXY(*buffer, it.range.max);
|
XY max = PosToXY(*buffer, it.range.max);
|
||||||
if (visible.min.y > max.line) continue;
|
if (visible.min.y > max.line) continue;
|
||||||
@@ -119,8 +119,8 @@ void DrawWindow(Window &window) {
|
|||||||
if (!(a || b || c || d)) continue;
|
if (!(a || b || c || d)) continue;
|
||||||
|
|
||||||
Vec2I pos = {col * FontCharSpacing, line * FontLineSpacing};
|
Vec2I pos = {col * FontCharSpacing, line * FontLineSpacing};
|
||||||
pos -= view.scroll;
|
pos -= view->scroll;
|
||||||
pos += window.document_rect.min;
|
pos += window->document_rect.min;
|
||||||
Rect2 rect = Rect2FromSize({(float)pos.x, (float)pos.y}, {(float)FontCharSpacing, (float)FontLineSpacing});
|
Rect2 rect = Rect2FromSize({(float)pos.x, (float)pos.y}, {(float)FontCharSpacing, (float)FontLineSpacing});
|
||||||
DrawRect(rect, ColorSelection);
|
DrawRect(rect, ColorSelection);
|
||||||
|
|
||||||
@@ -139,8 +139,8 @@ void DrawWindow(Window &window) {
|
|||||||
Int front = GetFront(it);
|
Int front = GetFront(it);
|
||||||
XY fxy = PosToXY(*buffer, front);
|
XY fxy = PosToXY(*buffer, front);
|
||||||
Vec2I w = XYToWorldPos(view, XYLine(fxy.line));
|
Vec2I w = XYToWorldPos(view, XYLine(fxy.line));
|
||||||
w -= view.scroll;
|
w -= view->scroll;
|
||||||
w += window.document_rect.min;
|
w += window->document_rect.min;
|
||||||
Rect2 rect = {
|
Rect2 rect = {
|
||||||
{ 0.f, (float)w.y},
|
{ 0.f, (float)w.y},
|
||||||
{WindowSize.x, (float)w.y + (float)FontLineSpacing}
|
{WindowSize.x, (float)w.y + (float)FontLineSpacing}
|
||||||
@@ -152,49 +152,49 @@ void DrawWindow(Window &window) {
|
|||||||
DrawVisibleText(window);
|
DrawVisibleText(window);
|
||||||
|
|
||||||
BeginProfileScope(draw_carets);
|
BeginProfileScope(draw_carets);
|
||||||
For(view.carets) {
|
For(view->carets) {
|
||||||
Int front = GetFront(it);
|
Int front = GetFront(it);
|
||||||
XY fxy = PosToXY(*buffer, front);
|
XY fxy = PosToXY(*buffer, front);
|
||||||
if (fxy.col >= visible.min.x && fxy.col < visible.max.x && fxy.line >= visible.min.y && fxy.line <= visible.max.y) {
|
if (fxy.col >= visible.min.x && fxy.col < visible.max.x && fxy.line >= visible.min.y && fxy.line <= visible.max.y) {
|
||||||
bool main_caret = &it == &view.carets.data[0];
|
bool main_caret = &it == &view->carets.data[0];
|
||||||
DrawCaret(window, fxy, 0.3f, main_caret ? ColorMainCaret : ColorSubCaret);
|
DrawCaret(window, fxy, 0.3f, main_caret ? ColorMainCaret : ColorSubCaret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
EndProfileScope();
|
EndProfileScope();
|
||||||
|
|
||||||
// Draw line numbers
|
// Draw line numbers
|
||||||
if (window.draw_line_numbers) {
|
if (window->draw_line_numbers) {
|
||||||
SetScissor(window.line_numbers_rect);
|
SetScissor(window->line_numbers_rect);
|
||||||
DrawRect(window.line_numbers_rect, ColorBackground);
|
DrawRect(window->line_numbers_rect, ColorBackground);
|
||||||
|
|
||||||
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) {
|
||||||
Scratch scratch;
|
Scratch scratch;
|
||||||
Vec2I pos = {0, line * FontLineSpacing};
|
Vec2I pos = {0, line * FontLineSpacing};
|
||||||
pos.y -= view.scroll.y;
|
pos.y -= view->scroll.y;
|
||||||
pos += window.line_numbers_rect.min;
|
pos += window->line_numbers_rect.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 = GetStringSize(&MainFont, string).x;
|
float x = GetStringSize(&MainFont, string).x;
|
||||||
Vec2 p = ToVec2(pos);
|
Vec2 p = ToVec2(pos);
|
||||||
float rectx = (float)GetSize(window.line_numbers_rect).x;
|
float rectx = (float)GetSize(window->line_numbers_rect).x;
|
||||||
p.x += (rectx - x) / 2.f;
|
p.x += (rectx - x) / 2.f;
|
||||||
if (x > rectx) p.x = (float)window.line_numbers_rect.min.x;
|
if (x > rectx) p.x = (float)window->line_numbers_rect.min.x;
|
||||||
DrawString(&MainFont, string, p, ColorTextLineNumbers);
|
DrawString(&MainFont, string, p, ColorTextLineNumbers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw scrollbar
|
// Draw scrollbar
|
||||||
if (window.draw_scrollbar) {
|
if (window->draw_scrollbar) {
|
||||||
SetScissor(window.scrollbar_rect);
|
SetScissor(window->scrollbar_rect);
|
||||||
// Vec2 mouse = GetMousePosition();
|
// Vec2 mouse = GetMousePosition();
|
||||||
// bool mouse_in_scrollbar = CheckCollisionPointRec(mouse, ToRectangle(window.scrollbar_rect));
|
// bool mouse_in_scrollbar = CheckCollisionPointRec(mouse, ToRectangle(window->scrollbar_rect));
|
||||||
|
|
||||||
DrawRect(window.scrollbar_rect, ColorScrollbarBackground);
|
DrawRect(window->scrollbar_rect, ColorScrollbarBackground);
|
||||||
Scroller scroller = ComputeScrollerRect(window);
|
Scroller scroller = ComputeScrollerRect(window);
|
||||||
Rect2 rect = Shrink(scroller.rect, 2);
|
Rect2 rect = Shrink(scroller.rect, 2);
|
||||||
Color color = ColorScrollbarScroller;
|
Color color = ColorScrollbarScroller;
|
||||||
// if (!window.mouse_selecting && (window.mouse_selecting_scrollbar || mouse_in_scrollbar)) {
|
// if (!window->mouse_selecting && (window->mouse_selecting_scrollbar || mouse_in_scrollbar)) {
|
||||||
// if (is_active) color = ColorScrollbarScrollerSelected;
|
// if (is_active) color = ColorScrollbarScrollerSelected;
|
||||||
// }
|
// }
|
||||||
DrawRect(rect, color);
|
DrawRect(rect, color);
|
||||||
@@ -202,6 +202,6 @@ void DrawWindow(Window &window) {
|
|||||||
|
|
||||||
if (!is_active) {
|
if (!is_active) {
|
||||||
SetScissor(GetScreenRectF());
|
SetScissor(GetScreenRectF());
|
||||||
DrawRect(window.total_rect, {0, 0, 0, 30});
|
DrawRect(window->total_rect, {0, 0, 0, 30});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user