Optimize cursor rendering
This commit is contained in:
@@ -28,7 +28,7 @@ void _BeginProfileScope(const char *name, int len) {
|
||||
get_time_in_micros() // timestamp in microseconds -- start of your timing block
|
||||
);
|
||||
}
|
||||
#define BeginProfileScope(name) _BeginProfileScope(name, sizeof(name) - 1)
|
||||
#define BeginProfileScope(name) _BeginProfileScope(#name, sizeof(#name) - 1)
|
||||
|
||||
void EndProfileScope() {
|
||||
spall_buffer_end(&spall_ctx, &spall_buffer,
|
||||
|
||||
@@ -91,34 +91,24 @@ void DrawCaret(Window &window, XY xy, float size, Color color) {
|
||||
DrawRectangleRec(ToRectangle(rect), color);
|
||||
}
|
||||
|
||||
void DrawLineHighlight(Window &window, XY fxy, Color color) {
|
||||
ProfileFunction();
|
||||
View &view = *GetActiveView(&window);
|
||||
Vec2I w = XYToWorldPos(view, XYLine(fxy.line));
|
||||
w -= view.scroll;
|
||||
w += window.document_rect.min;
|
||||
Rect2I rect = {
|
||||
{ 0, w.y},
|
||||
{GetRenderWidth(), w.y + FontLineSpacing}
|
||||
};
|
||||
DrawRectangleRec(ToRectangle(rect), color);
|
||||
}
|
||||
|
||||
void DrawSelection(Window &window, Caret &it) {
|
||||
ProfileFunction();
|
||||
void DrawWindow(Window &window) {
|
||||
View &view = *GetActiveView(&window);
|
||||
Buffer *buffer = GetBuffer(view.active_buffer);
|
||||
Int front = GetFront(it);
|
||||
Int back = GetBack(it);
|
||||
if (front != back) {
|
||||
DrawRectangleRec(ToRectangle(window.total_rect), ColorBackground);
|
||||
bool is_active = IsActive(&window) || window.id.id == GetLastActiveWindow().id;
|
||||
|
||||
BeginScissorMode((int)window.document_rect.min.x, (int)window.document_rect.min.y, (int)window.document_rect.max.x - (int)window.document_rect.min.x, (int)window.document_rect.max.y - (int)window.document_rect.min.y);
|
||||
BeginProfileScope(draw_caret_selection);
|
||||
Rect2I visible = GetVisibleCells(window);
|
||||
For(view.carets) {
|
||||
XY min = PosToXY(*buffer, it.range.min);
|
||||
XY max = PosToXY(*buffer, it.range.max);
|
||||
if (visible.min.y > max.line) return;
|
||||
if (visible.max.y < min.line) return;
|
||||
if (visible.min.y > max.line) continue;
|
||||
if (visible.max.y < min.line) continue;
|
||||
|
||||
XY bxy = PosToXY(*buffer, back);
|
||||
Color color = ColorSelection;
|
||||
if (GetSize(it.range)) {
|
||||
//
|
||||
// Draw selection
|
||||
for (Int line = visible.min.y; line <= visible.max.y && line >= 0 && line < buffer->line_starts.len; line += 1) {
|
||||
String16 line_string = GetLineString(*buffer, line);
|
||||
|
||||
@@ -127,14 +117,13 @@ void DrawSelection(Window &window, Caret &it) {
|
||||
bool b = min.line != max.line && (line == min.line && col >= min.col);
|
||||
bool c = min.line != max.line && (line == max.line && col < max.col);
|
||||
bool d = min.line == max.line && line == max.line && col >= min.col && col < max.col;
|
||||
if (!(a || b || c || d)) continue;
|
||||
|
||||
if (a || b || c || d) {
|
||||
Vec2I pos = {col * FontCharSpacing, line * FontLineSpacing};
|
||||
pos -= view.scroll;
|
||||
pos += window.document_rect.min;
|
||||
Rectangle rectangle = {(float)pos.x, (float)pos.y, (float)FontCharSpacing, (float)FontLineSpacing};
|
||||
|
||||
DrawRectangleRec(rectangle, color);
|
||||
DrawRectangleRec(rectangle, ColorSelection);
|
||||
|
||||
if (line_string[col] == ' ' || line_string[col] == '\t') {
|
||||
DrawCircle((int)pos.x + (int)FontCharSpacing / 2, (int)pos.y + (int)FontLineSpacing / 2, (float)FontSize / 10.f, ColorWhitespaceDuringSelection);
|
||||
@@ -145,33 +134,26 @@ void DrawSelection(Window &window, Caret &it) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DrawWindow(Window &window) {
|
||||
View &view = *GetActiveView(&window);
|
||||
Buffer *buffer = GetBuffer(view.active_buffer);
|
||||
DrawRectangleRec(ToRectangle(window.total_rect), ColorBackground);
|
||||
bool is_active = IsActive(&window) || window.id.id == GetLastActiveWindow().id;
|
||||
|
||||
BeginScissorMode((int)window.document_rect.min.x, (int)window.document_rect.min.y, (int)window.document_rect.max.x - (int)window.document_rect.min.x, (int)window.document_rect.max.y - (int)window.document_rect.min.y);
|
||||
BeginProfileScope("draw_caret_selection");
|
||||
For(view.carets) {
|
||||
} else {
|
||||
//
|
||||
// Draw highlight
|
||||
Int front = GetFront(it);
|
||||
XY fxy = PosToXY(*buffer, front);
|
||||
if (GetSize(it.range)) {
|
||||
DrawSelection(window, it);
|
||||
} else {
|
||||
DrawLineHighlight(window, fxy, ColorLineHighlight);
|
||||
Vec2I w = XYToWorldPos(view, XYLine(fxy.line));
|
||||
w -= view.scroll;
|
||||
w += window.document_rect.min;
|
||||
Rect2I rect = {
|
||||
{ 0, w.y},
|
||||
{GetRenderWidth(), w.y + FontLineSpacing}
|
||||
};
|
||||
DrawRectangleRec(ToRectangle(rect), ColorLineHighlight);
|
||||
}
|
||||
}
|
||||
EndProfileScope();
|
||||
|
||||
DrawVisibleText(window);
|
||||
|
||||
BeginProfileScope("draw_carets");
|
||||
Rect2I visible = GetVisibleCells(window);
|
||||
BeginProfileScope(draw_carets);
|
||||
For(view.carets) {
|
||||
Int front = GetFront(it);
|
||||
XY fxy = PosToXY(*buffer, front);
|
||||
|
||||
Reference in New Issue
Block a user