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