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:
parent
bcb16bbd8d
commit
d55ecf822b
|
@ -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
|
11
0007-to_text
11
0007-to_text
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue