From 978d2d603aef13ae3bd93ed96a24f6c96957b5ea Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Sun, 28 Jul 2024 14:49:46 +0200 Subject: [PATCH] Add xwheel --- src/text_editor/commands.cpp | 7 ++++--- src/text_editor/lua_api.cpp | 2 +- src/text_editor/text_editor.cpp | 2 +- src/text_editor/todo.txt | 15 ++++++++++++++- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/text_editor/commands.cpp b/src/text_editor/commands.cpp index 0f5c696..a8411aa 100644 --- a/src/text_editor/commands.cpp +++ b/src/text_editor/commands.cpp @@ -26,7 +26,7 @@ struct Event { }; uint8_t mouse; uint8_t mouse_double_click; - float wheel; + Vec2 wheel; const char *text; }; @@ -269,7 +269,7 @@ bool GlobalCommand(Event event) { } } - if (event.wheel) { + if (event.wheel.x || event.wheel.y) { Scratch scratch; Array order = GetWindowZOrder(scratch); Vec2I mouse = MouseVec2I(); @@ -281,7 +281,8 @@ bool GlobalCommand(Event event) { 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 * 48); + view->scroll.y -= (Int)(event.wheel.y * 48); + view->scroll.x += (Int)(event.wheel.x * 48); break; } } diff --git a/src/text_editor/lua_api.cpp b/src/text_editor/lua_api.cpp index d461867..611de41 100644 --- a/src/text_editor/lua_api.cpp +++ b/src/text_editor/lua_api.cpp @@ -42,7 +42,7 @@ int LuaOpen(lua_State *L) { return 0; } - if (FieldString(L, "kind") == "open_textfile") { + if (FieldString(L, "kind") == "text") { String file_path = FieldString(L, "file_path"); String line_string = FieldString(L, "line"); Int line = strtoll(line_string.data, NULL, 10); diff --git a/src/text_editor/text_editor.cpp b/src/text_editor/text_editor.cpp index 0bc498e..066074a 100644 --- a/src/text_editor/text_editor.cpp +++ b/src/text_editor/text_editor.cpp @@ -95,7 +95,7 @@ void ProcessSDLEvent(SDL_Event *input_event) { SDL_MouseWheelEvent &b = input_event->wheel; event.xmouse = (int16_t)b.mouse_x; event.ymouse = (int16_t)b.mouse_y; - event.wheel = b.y; + event.wheel = {b.x, b.y}; } break; default: return; } diff --git a/src/text_editor/todo.txt b/src/text_editor/todo.txt index 6e2a437..1bb4f3c 100644 --- a/src/text_editor/todo.txt +++ b/src/text_editor/todo.txt @@ -1,6 +1,5 @@ - Save file (utf16->utf8) - make sure we only save file buffers -- Move open fully to config so that user can easily modify the plumbing - resize windows - color the line number with line highlight - page up and down should also scroll and leave you in exactly same scroll @@ -19,3 +18,17 @@ - Search all buffers - Search and replace - Search result buffer + + + + + +- Move open fully to config so that user can easily modify the plumbing +function Open(s) + o = ApplyRules(s) + if o.kind == "text" then + open_buffer(o.file_path, o.line, o.col) + elseif o.kind == "url" then + open_web(o.url) + end +end