Adding bars to the window
This commit is contained in:
@@ -29,6 +29,7 @@ struct Window {
|
||||
Font font;
|
||||
float font_size;
|
||||
float font_spacing;
|
||||
Rect2 start_rect;
|
||||
Rect2 rect;
|
||||
|
||||
Range selection_anchor_point;
|
||||
@@ -251,7 +252,7 @@ Array<LayoutColumn> CalculateVisibleColumns(Arena *arena, Window &window) {
|
||||
for (int64_t line = visible_line_range.min; line < visible_line_range.max && line >= 0 && line < window.layout.rows.len; line += 1) {
|
||||
LayoutRow &row = window.layout.rows[line];
|
||||
For(row.columns) {
|
||||
if (CheckCollisionRecs(ToRectangle(it.rect - window.scroll), ToRectangle(window.rect))) {
|
||||
if (CheckCollisionRecs(ToRectangle(it.rect + window.rect.min - window.scroll), ToRectangle(window.rect))) {
|
||||
r.add(it);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,10 +79,10 @@ int main() {
|
||||
|
||||
Array<Window> windows = {};
|
||||
{
|
||||
Window window = {};
|
||||
window.rect = GetScreenRect();
|
||||
window.font = font;
|
||||
window.font_size = font_size;
|
||||
Window window = {};
|
||||
window.start_rect = GetScreenRect();
|
||||
window.font = font;
|
||||
window.font_size = font_size;
|
||||
window.font_spacing;
|
||||
InitArena(&window.layout_arena);
|
||||
InitBuffer(GetSystemAllocator(), &window.buffer);
|
||||
@@ -417,9 +417,16 @@ int main() {
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
ForItem(window, windows) {
|
||||
Rectangle rectangle_in_render_units = ToRectangle(window.rect);
|
||||
DrawRectangleRec(rectangle_in_render_units, WHITE);
|
||||
Array<LayoutColumn> visible_columns = CalculateVisibleColumns(&FrameArena, window);
|
||||
// Draw and layout window overlay
|
||||
{
|
||||
window.rect = window.start_rect;
|
||||
Rect2 horizontal_bar_rect = CutBottom(&window.rect, 10);
|
||||
Rect2 vertical_bar_rect = CutRight(&window.rect, 10);
|
||||
Rect2 line_numbers = CutLeft(&window.rect, 50);
|
||||
|
||||
Rectangle rectangle_in_render_units = ToRectangle(window.rect);
|
||||
DrawRectangleRec(rectangle_in_render_units, WHITE);
|
||||
}
|
||||
|
||||
// Mouse selection
|
||||
{
|
||||
@@ -434,7 +441,7 @@ int main() {
|
||||
}
|
||||
|
||||
if ((mouse_in_window && IsMouseButtonDown(MOUSE_BUTTON_LEFT)) || window.mouse_selecting) {
|
||||
Vec2 mouse_lookup = Vector2Add(mouse, window.scroll);
|
||||
Vec2 mouse_lookup = mouse - window.rect.min + window.scroll;
|
||||
LayoutRow *row = GetLayoutRow(window, mouse_lookup.y);
|
||||
if (row == NULL) {
|
||||
if (mouse.y < 0) {
|
||||
@@ -455,8 +462,6 @@ int main() {
|
||||
}
|
||||
Assert(col);
|
||||
|
||||
Rect2 col_rect = col->rect - window.scroll;
|
||||
Rectangle col_rectangle = ToRectangle(col_rect);
|
||||
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
|
||||
if (!IsKeyDown(KEY_LEFT_CONTROL)) {
|
||||
window.cursors.clear();
|
||||
@@ -542,9 +547,7 @@ int main() {
|
||||
LayoutRow &row = window.layout.rows[line];
|
||||
|
||||
ForItem(col, row.columns) {
|
||||
Vec2 p0 = Vector2Subtract(col.rect.min, window.scroll);
|
||||
Vec2 p1 = Vector2Subtract(col.rect.max, window.scroll);
|
||||
Rect2 rect = {p0, p1};
|
||||
Rect2 rect = {col.rect.min + window.rect.min - window.scroll, col.rect.max + window.rect.min - window.scroll};
|
||||
|
||||
if (!CheckCollisionRecs(ToRectangle(rect), ToRectangle(window.rect))) {
|
||||
continue; // Clip everything that is outside the window and screen
|
||||
@@ -560,6 +563,8 @@ int main() {
|
||||
}
|
||||
}
|
||||
|
||||
Array<LayoutColumn> visible_columns = CalculateVisibleColumns(&FrameArena, window);
|
||||
|
||||
// Draw cursor stuff
|
||||
ForItem(cursor, window.cursors) {
|
||||
auto front = GetRowCol(window, GetFront(cursor));
|
||||
@@ -567,21 +572,19 @@ int main() {
|
||||
|
||||
For(visible_columns) {
|
||||
if (it.pos >= cursor.range.min && it.pos < cursor.range.max) {
|
||||
Rect2 rect = it.rect - window.scroll;
|
||||
Rect2 rect = it.rect + window.rect.min - window.scroll;
|
||||
DrawRectangleRec(ToRectangle(rect), {0, 50, 150, 50});
|
||||
}
|
||||
}
|
||||
|
||||
if (front.b) {
|
||||
Rect2 rect = front.b->rect;
|
||||
rect -= window.scroll;
|
||||
rect = CutLeft(&rect, 4);
|
||||
Rect2 rect = front.b->rect + window.rect.min - window.scroll;
|
||||
rect = CutLeft(&rect, 4);
|
||||
DrawRectangleRec(ToRectangle(rect), RED);
|
||||
}
|
||||
if (back.b) {
|
||||
Rect2 rect = back.b->rect;
|
||||
rect -= window.scroll;
|
||||
rect = CutLeft(&rect, 2);
|
||||
Rect2 rect = back.b->rect + window.rect.min - window.scroll;
|
||||
rect = CutLeft(&rect, 2);
|
||||
DrawRectangleRec(ToRectangle(rect), GREEN);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user