Fixing bugs, bring back mouse selection
This commit is contained in:
@@ -468,13 +468,14 @@ int main() {
|
|||||||
for (int64_t line = line_min_y; line < line_max_y && line >= 0 && line < window.layout.rows.len; line += 1) {
|
for (int64_t line = line_min_y; line < line_max_y && 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), ToRectangle(window.rect))) {
|
if (CheckCollisionRecs(ToRectangle(it.rect - window.scroll), ToRectangle(window.rect))) {
|
||||||
visible_columns.add(it);
|
visible_columns.add(it);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the scroll based on first cursor
|
// Update the scroll based on first cursor
|
||||||
|
// @todo: needs a rewrite
|
||||||
if (!AreEqual(window.main_cursor_begin_frame, window.cursors[0])) {
|
if (!AreEqual(window.main_cursor_begin_frame, window.cursors[0])) {
|
||||||
Vec2 rect_size = GetSize(window.rect);
|
Vec2 rect_size = GetSize(window.rect);
|
||||||
float visible_cells_in_render_units = font_size * (float)visible_lines;
|
float visible_cells_in_render_units = font_size * (float)visible_lines;
|
||||||
@@ -485,9 +486,9 @@ int main() {
|
|||||||
Line line = FindLine(window.buffer, front);
|
Line line = FindLine(window.buffer, front);
|
||||||
|
|
||||||
// Scroll Y
|
// Scroll Y
|
||||||
if (line.number < line_min_y) {
|
if (line.number < (line_min_y + 1)) {
|
||||||
window.scroll.y = line.number * font_size;
|
window.scroll.y = line.number * font_size;
|
||||||
} else if (line.number >= line_max_y) {
|
} else if (line.number >= (line_max_y - 1)) {
|
||||||
int64_t diff = line.number - line_max_y;
|
int64_t diff = line.number - line_max_y;
|
||||||
window.scroll.y = (line_min_y + diff) * font_size + cut_off_in_render_units;
|
window.scroll.y = (line_min_y + diff) * font_size + cut_off_in_render_units;
|
||||||
}
|
}
|
||||||
@@ -514,6 +515,7 @@ int main() {
|
|||||||
|
|
||||||
// Mouse selection @todo
|
// Mouse selection @todo
|
||||||
{
|
{
|
||||||
|
SetMouseCursor(MOUSE_CURSOR_DEFAULT);
|
||||||
Vec2 mouse = GetMousePosition();
|
Vec2 mouse = GetMousePosition();
|
||||||
Vec2 mouse_lookup = Vector2Add(mouse, window.scroll);
|
Vec2 mouse_lookup = Vector2Add(mouse, window.scroll);
|
||||||
|
|
||||||
@@ -522,7 +524,16 @@ int main() {
|
|||||||
Rect2 col_rect = rowcol.b->rect - window.scroll;
|
Rect2 col_rect = rowcol.b->rect - window.scroll;
|
||||||
Rectangle col_rectangle = ToRectangle(col_rect);
|
Rectangle col_rectangle = ToRectangle(col_rect);
|
||||||
if (CheckCollisionPointRec(mouse, col_rectangle)) {
|
if (CheckCollisionPointRec(mouse, col_rectangle)) {
|
||||||
DrawRectangleRec(col_rectangle, {0, 0, 255, 40});
|
// DrawRectangleRec(col_rectangle, {0, 0, 255, 40});
|
||||||
|
SetMouseCursor(MOUSE_CURSOR_IBEAM);
|
||||||
|
|
||||||
|
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
|
||||||
|
window.cursors.clear();
|
||||||
|
window.cursors.add({rowcol.b->pos, rowcol.b->pos});
|
||||||
|
} else if (IsMouseButtonDown(MOUSE_BUTTON_LEFT)) {
|
||||||
|
Cursor *cursor = window.cursors.last();
|
||||||
|
cursor[0] = ChangeBack(*cursor, rowcol.b->pos);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -553,14 +564,15 @@ int main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw cursor stuff @todo: draw selection
|
// Draw cursor stuff
|
||||||
ForItem(cursor, window.cursors) {
|
ForItem(cursor, window.cursors) {
|
||||||
auto front = GetRowCol(window, GetFront(cursor));
|
auto front = GetRowCol(window, GetFront(cursor));
|
||||||
auto back = GetRowCol(window, GetBack(cursor));
|
auto back = GetRowCol(window, GetBack(cursor));
|
||||||
|
|
||||||
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) {
|
||||||
DrawRectangleRec(ToRectangle(it.rect), {0, 50, 150, 50});
|
Rect2 rect = it.rect - window.scroll;
|
||||||
|
DrawRectangleRec(ToRectangle(rect), {0, 50, 150, 50});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user