Mouse rewrite
This commit is contained in:
@@ -158,6 +158,44 @@ bool GlobalCommand(Event event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Underline word on mouse cursor
|
||||||
|
if (event.ctrl) {
|
||||||
|
Vec2I mouse = MouseVec2I();
|
||||||
|
For(order) {
|
||||||
|
Window *window = &Windows[it];
|
||||||
|
if (!window->visible) continue;
|
||||||
|
bool mouse_in_document = CheckCollisionPointRec(mouse, window->document_rect);
|
||||||
|
if (mouse_in_document) {
|
||||||
|
View *view = GetView(window->active_view);
|
||||||
|
Buffer *buffer = GetBuffer(view->active_buffer);
|
||||||
|
Int p = ScreenSpaceToBufferPosErrorOutOfBounds(window, view, buffer, mouse);
|
||||||
|
if (p != -1) {
|
||||||
|
view->underline_pos[view->underline_count++] = p;
|
||||||
|
Assert(view->underline_count <= 2);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle wheel scrolling
|
||||||
|
if (event.wheel.x || event.wheel.y) {
|
||||||
|
Vec2I mouse = MouseVec2I();
|
||||||
|
|
||||||
|
For(order) {
|
||||||
|
Window *window = &Windows[it];
|
||||||
|
if (!window->visible) continue;
|
||||||
|
|
||||||
|
bool mouse_in_window = CheckCollisionPointRec(mouse, window->total_rect);
|
||||||
|
if (mouse_in_window) {
|
||||||
|
View *view = GetView(window->active_view);
|
||||||
|
view->scroll.y -= (Int)(event.wheel.y * 48);
|
||||||
|
view->scroll.x += (Int)(event.wheel.x * 48);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Handle selected window scrollbar
|
// Handle selected window scrollbar
|
||||||
// @note: the order here assumes that we won't run this code on the
|
// @note: the order here assumes that we won't run this code on the
|
||||||
// same event as the scroll was pressed
|
// same event as the scroll was pressed
|
||||||
@@ -175,9 +213,12 @@ bool GlobalCommand(Event event) {
|
|||||||
double v = p / size_y;
|
double v = p / size_y;
|
||||||
v = v + (window->mouse_scroller_offset);
|
v = v + (window->mouse_scroller_offset);
|
||||||
view->scroll.y = (Int)(v * (double)s.line_count * (double)FontLineSpacing);
|
view->scroll.y = (Int)(v * (double)s.line_count * (double)FontLineSpacing);
|
||||||
|
run_window_command = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DocumentSelected && MouseUp()) {
|
if (DocumentSelected != GetActiveWindow()) {
|
||||||
|
DocumentSelected = NULL;
|
||||||
|
} else if (DocumentSelected && MouseUp()) {
|
||||||
Assert(ScrollbarSelected == NULL);
|
Assert(ScrollbarSelected == NULL);
|
||||||
DocumentSelected = NULL;
|
DocumentSelected = NULL;
|
||||||
} else if (DocumentSelected) {
|
} else if (DocumentSelected) {
|
||||||
@@ -207,31 +248,10 @@ bool GlobalCommand(Event event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// underline
|
|
||||||
if (event.ctrl) {
|
|
||||||
Vec2I mouse = MouseVec2I();
|
|
||||||
For(order) {
|
|
||||||
Window *window = &Windows[it];
|
|
||||||
if (!window->visible) continue;
|
|
||||||
bool mouse_in_document = CheckCollisionPointRec(mouse, window->document_rect);
|
|
||||||
if (mouse_in_document) {
|
|
||||||
View *view = GetView(window->active_view);
|
|
||||||
Buffer *buffer = GetBuffer(view->active_buffer);
|
|
||||||
Int p = ScreenSpaceToBufferPosErrorOutOfBounds(window, view, buffer, mouse);
|
|
||||||
if (p != -1) {
|
|
||||||
view->underline_pos[view->underline_count++] = p;
|
|
||||||
Assert(view->underline_count <= 2);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.ctrl && Mouse(RIGHT)) {
|
|
||||||
GoBackToLastCrumb();
|
|
||||||
}
|
|
||||||
|
|
||||||
// @todo: maybe move some of this stuff to window command ???
|
// @todo: maybe move some of this stuff to window command ???
|
||||||
|
// for now let's leave it because we are relaying on global state
|
||||||
|
// - maybe just do the check if active window is matching the DocumentSelected window
|
||||||
|
// - if scrollbar selected then don't invoke window command
|
||||||
if (event.ctrl && Mouse(LEFT)) {
|
if (event.ctrl && Mouse(LEFT)) {
|
||||||
Vec2I mouse = MouseVec2I();
|
Vec2I mouse = MouseVec2I();
|
||||||
Window *window = GetActiveWindow();
|
Window *window = GetActiveWindow();
|
||||||
@@ -290,6 +310,8 @@ bool GlobalCommand(Event event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Figure out scrollbar click
|
// Figure out scrollbar click
|
||||||
|
// @todo: it generally works ok but it moves the scrollbar a bit on click
|
||||||
|
// when mouse is not even moving
|
||||||
For(order) {
|
For(order) {
|
||||||
Window *window = &Windows[it];
|
Window *window = &Windows[it];
|
||||||
if (!window->visible) continue;
|
if (!window->visible) continue;
|
||||||
@@ -308,27 +330,14 @@ bool GlobalCommand(Event event) {
|
|||||||
} else {
|
} else {
|
||||||
window->mouse_scroller_offset = (s.rect.min.y - p) / size_y;
|
window->mouse_scroller_offset = (s.rect.min.y - p) / size_y;
|
||||||
}
|
}
|
||||||
|
run_window_command = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle wheel scrolling
|
if (event.ctrl && Mouse(RIGHT)) {
|
||||||
if (event.wheel.x || event.wheel.y) {
|
GoBackToLastCrumb();
|
||||||
Vec2I mouse = MouseVec2I();
|
|
||||||
|
|
||||||
For(order) {
|
|
||||||
Window *window = &Windows[it];
|
|
||||||
if (!window->visible) continue;
|
|
||||||
|
|
||||||
bool mouse_in_window = CheckCollisionPointRec(mouse, window->total_rect);
|
|
||||||
if (mouse_in_window) {
|
|
||||||
View *view = GetView(window->active_view);
|
|
||||||
view->scroll.y -= (Int)(event.wheel.y * 48);
|
|
||||||
view->scroll.x += (Int)(event.wheel.x * 48);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Ctrl(SDLK_GRAVE)) {
|
if (Ctrl(SDLK_GRAVE)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user