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.
This commit is contained in:
Kartik K. Agaram 2023-04-17 23:28:42 -07:00
parent bcb16bbd8d
commit d55ecf822b
5 changed files with 18 additions and 16 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

12
0038-to_node Normal file
View File

@ -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