Improve mouse selection, add multicursor for mouse selection
This commit is contained in:
@@ -79,9 +79,6 @@ int main() {
|
||||
}
|
||||
|
||||
InitEventRecording();
|
||||
// @todo: multiple ui elements, add focus
|
||||
// @todo: immediate mode interface for all this
|
||||
Vec2 camera_offset_world_to_render_units = {};
|
||||
while (!WindowShouldClose()) {
|
||||
For(windows) {
|
||||
Assert(it.cursors.len);
|
||||
@@ -93,13 +90,6 @@ int main() {
|
||||
{
|
||||
Window *focused_window = &windows[0];
|
||||
|
||||
if (IsKeyDown(KEY_F1)) {
|
||||
camera_offset_world_to_render_units = Vector2Subtract(camera_offset_world_to_render_units, GetMouseDelta());
|
||||
}
|
||||
if (IsKeyDown(KEY_F2)) {
|
||||
SetTraceLogLevel(LOG_DEBUG);
|
||||
}
|
||||
|
||||
float mouse_wheel = GetMouseWheelMove() * 48;
|
||||
focused_window->scroll.y -= mouse_wheel;
|
||||
focused_window->scroll.y = ClampBottom(focused_window->scroll.y, 0.f);
|
||||
@@ -369,54 +359,60 @@ int main() {
|
||||
ForItem(window, windows) {
|
||||
Rectangle rectangle_in_render_units = ToRectangle(window.rect);
|
||||
DrawRectangleRec(rectangle_in_render_units, WHITE);
|
||||
|
||||
Array<LayoutColumn> visible_columns = CalculateVisibleColumns(&FrameArena, window);
|
||||
|
||||
// Mouse selection
|
||||
// @todo: multicursor
|
||||
SetMouseCursor(MOUSE_CURSOR_DEFAULT);
|
||||
if (IsMouseButtonDown(MOUSE_BUTTON_LEFT)) {
|
||||
Vec2 mouse = GetMousePosition();
|
||||
Vec2 mouse_lookup = Vector2Add(mouse, window.scroll);
|
||||
|
||||
LayoutRow *row = GetLayoutRow(window, mouse_lookup.y);
|
||||
if (row == NULL) {
|
||||
if (mouse.y < 0) {
|
||||
row = window.layout.rows.first();
|
||||
} else {
|
||||
row = window.layout.rows.last();
|
||||
}
|
||||
}
|
||||
Assert(row);
|
||||
|
||||
LayoutColumn *col = GetLayoutColumn(row, mouse_lookup.x);
|
||||
if (col == NULL) {
|
||||
if (mouse.x < 0) {
|
||||
col = row->columns.first();
|
||||
} else {
|
||||
col = row->columns.last();
|
||||
}
|
||||
}
|
||||
Assert(col);
|
||||
|
||||
Rect2 col_rect = col->rect - window.scroll;
|
||||
Rectangle col_rectangle = ToRectangle(col_rect);
|
||||
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
|
||||
window.cursors.clear();
|
||||
window.cursors.add({col->pos, col->pos});
|
||||
window.mouse_selecting = true;
|
||||
}
|
||||
|
||||
if (!window.mouse_selecting) {
|
||||
{
|
||||
Vec2 mouse = GetMousePosition();
|
||||
bool mouse_in_window = CheckCollisionPointRec(mouse, ToRectangle(window.rect));
|
||||
if (!window.mouse_selecting && mouse_in_window) {
|
||||
SetMouseCursor(MOUSE_CURSOR_IBEAM);
|
||||
}
|
||||
|
||||
if (window.mouse_selecting) {
|
||||
SetMouseCursor(MOUSE_CURSOR_RESIZE_ALL);
|
||||
if (!IsMouseButtonDown(MOUSE_BUTTON_LEFT)) {
|
||||
window.mouse_selecting = false;
|
||||
if (!window.mouse_selecting && !mouse_in_window) {
|
||||
SetMouseCursor(MOUSE_CURSOR_DEFAULT);
|
||||
}
|
||||
|
||||
if ((mouse_in_window && IsMouseButtonDown(MOUSE_BUTTON_LEFT)) || window.mouse_selecting) {
|
||||
Vec2 mouse_lookup = Vector2Add(mouse, window.scroll);
|
||||
LayoutRow *row = GetLayoutRow(window, mouse_lookup.y);
|
||||
if (row == NULL) {
|
||||
if (mouse.y < 0) {
|
||||
row = window.layout.rows.first();
|
||||
} else {
|
||||
row = window.layout.rows.last();
|
||||
}
|
||||
}
|
||||
Assert(row);
|
||||
|
||||
LayoutColumn *col = GetLayoutColumn(row, mouse_lookup.x);
|
||||
if (col == NULL) {
|
||||
if (mouse.x < 0) {
|
||||
col = row->columns.first();
|
||||
} else {
|
||||
col = row->columns.last();
|
||||
}
|
||||
}
|
||||
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();
|
||||
}
|
||||
window.cursors.add({col->pos, col->pos});
|
||||
window.mouse_selecting = true;
|
||||
}
|
||||
|
||||
if (window.mouse_selecting) {
|
||||
SetMouseCursor(MOUSE_CURSOR_RESIZE_ALL);
|
||||
if (!IsMouseButtonDown(MOUSE_BUTTON_LEFT)) {
|
||||
window.mouse_selecting = false;
|
||||
}
|
||||
Cursor *cursor = window.cursors.last();
|
||||
cursor[0] = ChangeFront(*cursor, col->pos);
|
||||
}
|
||||
Cursor *cursor = window.cursors.last();
|
||||
cursor[0] = ChangeFront(*cursor, col->pos);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
|
||||
// @todo: multiple ui elements, add focus
|
||||
// @todo: immediate mode interface for all this
|
||||
|
||||
Buffer buffer;
|
||||
Rect window_rect;
|
||||
bool window_open = true;
|
||||
@@ -14,7 +17,7 @@ if (window_open) {
|
||||
|
||||
Node *node = TextField(&buffer);
|
||||
if (node->text_changed) {
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user