From d55ecf822bee712618ed8d81bc4ceac6d7ed0023 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Mon, 17 Apr 2023 23:28:42 -0700 Subject: [PATCH] start implementing the mouse handler Until now the hover actions were happening in surface coordinates sx/sy but the mouse press action (done so far) was happening in viewport coordinates vx/vy. Now it's consistent. Surface coordinates make more sense since most data in memory uses them. --- 0006-on.mouse_press | 7 ++++--- 0007-to_text | 11 ----------- 0036-on_move_bar | 2 +- 0037-on_resize | 2 +- 0038-to_node | 12 ++++++++++++ 5 files changed, 18 insertions(+), 16 deletions(-) delete mode 100644 0007-to_text create mode 100644 0038-to_node diff --git a/0006-on.mouse_press b/0006-on.mouse_press index 52a00c6..35b80de 100644 --- a/0006-on.mouse_press +++ b/0006-on.mouse_press @@ -3,11 +3,12 @@ on.mouse_press = function(x,y, mouse_button) Cursor_node.show_cursor = nil Cursor_node = nil end - local node = to_text(x,y) + local sx, sy = sx(x), sy(y) + local node = to_node(sx,sy) if node then Cursor_node = node edit.mouse_press(node.editor, x,y, mouse_button) else - Pan = {x=Viewport.x+x/Viewport.zoom,y=Viewport.y+y/Viewport.zoom} + Pan = {x=sx,y=sy} end -end +end \ No newline at end of file diff --git a/0007-to_text b/0007-to_text deleted file mode 100644 index 3eb81e5..0000000 --- a/0007-to_text +++ /dev/null @@ -1,11 +0,0 @@ -to_text = function(x,y) - for _,node in ipairs(Surface) do - if node.type == 'text' then - if x >= vx(node.x) and node.w and x < vx(node.x + node.w) then - if y >= vy(node.y) and node.h and y < vy(node.y + node.h) then - return node - end - end - end - end -end \ No newline at end of file diff --git a/0036-on_move_bar b/0036-on_move_bar index 1efec2b..246642f 100644 --- a/0036-on_move_bar +++ b/0036-on_move_bar @@ -2,7 +2,7 @@ on_move_bar = function(sx,sy) for _,node in ipairs(Nodes) do if sx >= node.x-10 and sx < node.x-10+node.w/2 then if sy >= node.y - 40 and sy < node.y-20 then - return true + return node end end end diff --git a/0037-on_resize b/0037-on_resize index b2d989c..9094268 100644 --- a/0037-on_resize +++ b/0037-on_resize @@ -3,7 +3,7 @@ on_resize = function(sx,sy) if sx >= node.x+node.w+20 and sx < node.x+node.w+24 then local buffer_height = math.max(node.h, 3*node.editor.line_height) if sy >= node.y and sy < node.y+buffer_height then - return true + return node end end end diff --git a/0038-to_node b/0038-to_node new file mode 100644 index 0000000..02d951a --- /dev/null +++ b/0038-to_node @@ -0,0 +1,12 @@ +to_node = function(sx,sy) + for _,node in ipairs(Surface) do + if node.type == 'text' then + if sx >= node.x and sx < node.x + node.w then + local buffer_height = math.max(node.h, 3*node.editor.line_height) + if sy >= node.y and sy < node.y + buffer_height then + return node + end + end + end + end +end \ No newline at end of file