better experience of moving a node around

After noodling about it for a few days, this seems like an improvement:
* When I "pick up" a node it's above the surface and doesn't disturb
  other nodes until I "put it down".

* There's a shadow around the node as I move it around, showing what is
  likely to be disturbed when I put it down.

* If I put down really close to where I picked up, it's considered an
  undo and no collisions are resolved.

* There's a hint around the original location to help me put it back
  there.
This commit is contained in:
Kartik K. Agaram 2023-12-21 08:10:05 -08:00
parent f3777901dd
commit c95a7e7184
7 changed files with 30 additions and 7 deletions

View File

@ -26,9 +26,9 @@ on.mouse_press = function(x,y, mouse_button)
if node then
-- move node
prepare_to_move(node)
Move = {xoff=App.mouse_x()-vx(node.x), yoff=App.mouse_y()-vy(node.y), node=node}
Move = {xoff=App.mouse_x()-vx(node.x), yoff=App.mouse_y()-vy(node.y), node=node, oldx=node.x, oldy=node.y}
return
end
-- pan surface
Pan = {x=Viewport.x+x/Viewport.zoom, y=Viewport.y+y/Viewport.zoom}
end
end

View File

@ -7,6 +7,12 @@ on.mouse_release = function(x,y, mouse_button)
Pan = nil
A()
elseif Move then
-- resolve collisions unless I'm trying to put it back carefully where I started.
if dist(vx(Move.node.x), vy(Move.node.y), vx(Move.oldx), vy(Move.oldy)) > 10 then
Move.node.pos.x = Move.node.x+Move.node.hs.x
Move.node.pos.y = Move.node.y+Move.node.hs.y
move_others(Move.node)
end
Move = nil
A()
elseif Cursor_node then

View File

@ -23,9 +23,8 @@ on.update = function(dt)
-- quantize the x axis to discrete columns
Move.node.x = round(Move.node.x/100)*100
A1(Move.node.key)
Move.node.pos.x = Move.node.x+Move.node.hs.x
Move.node.pos.y = Move.node.y+Move.node.hs.y
move_others(Move.node)
Move.node.pos.x = Move.node.x+Move.node.w/2
Move.node.pos.y = Move.node.y+Move.node.h/2+30
return
end
end

View File

@ -5,6 +5,14 @@ on.draw = function()
love.graphics.draw(Canvas, q, 0,0)
return
end
-- some hacky stuff outside of LuaML
if Move then
-- a hint for original location of node, to help put it back
App.color{r=0.8, g=0.8, b=0.8}
love.graphics.rectangle('fill', vx(Move.oldx), vy(Move.oldy), scale(Move.node.w), scale(Move.node.h))
-- a hint about the amount of padding we're going to clear when we set the node down
draw_move_node_shadow()
end
for _,obj in ipairs(Surface) do
love.graphics.setColor(obj.r or 0, obj.g or 0, obj.b or 0)
if obj.type == 'rectangle' then

View File

@ -8,11 +8,11 @@ prepare_to_move = function(target)
if def.hs == nil then def.hs = {} end
def.hs.x = def.w/2
def.hs.y = def.h/2 + 30
def.pos.x = def.x + def.hs.x
def.pos.y = def.y + def.hs.y
if def == target then
def.hs.x = def.hs.x + 50
def.hs.y = def.hs.y + math.max(30, math.min(def.h/3, 200))
end
def.pos.x = def.x + def.hs.x
def.pos.y = def.y + def.hs.y
end
end

3
0133-dist Normal file
View File

@ -0,0 +1,3 @@
dist = function(x1,y1, x2,y2)
return ((x2-x1)^2+(y2-y1)^2)^0.5
end

View File

@ -0,0 +1,7 @@
draw_move_node_shadow = function()
love.graphics.rectangle('fill',
vx(Move.node.pos.x-Move.node.hs.x),
vy(Move.node.pos.y-Move.node.hs.y),
scale(Move.node.hs.x*2),
scale(Move.node.hs.y*2))
end