delegate update events to drawings
This commit is contained in:
parent
10bc32e2f0
commit
c1ba40ac70
25
drawing.lua
25
drawing.lua
|
@ -69,6 +69,31 @@ function Drawing.mouse_pressed(drawing, x,y, button)
|
||||||
Lines.current = drawing
|
Lines.current = drawing
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- a couple of operations on drawings need to constantly check the state of the mouse
|
||||||
|
function Drawing.update()
|
||||||
|
if Lines.current == nil then return end
|
||||||
|
local drawing = Lines.current
|
||||||
|
assert(drawing.mode == 'drawing')
|
||||||
|
local x, y = love.mouse.getX(), love.mouse.getY()
|
||||||
|
if love.mouse.isDown('1') then
|
||||||
|
if Drawing.in_drawing(drawing, x,y) then
|
||||||
|
if drawing.pending.mode == 'freehand' then
|
||||||
|
table.insert(drawing.pending.points, {x=Drawing.coord(love.mouse.getX()-16), y=Drawing.coord(love.mouse.getY()-drawing.y)})
|
||||||
|
elseif drawing.pending.mode == 'move' then
|
||||||
|
local mx,my = Drawing.coord(x-16), Drawing.coord(y-drawing.y)
|
||||||
|
drawing.pending.target_point.x = mx
|
||||||
|
drawing.pending.target_point.y = my
|
||||||
|
end
|
||||||
|
end
|
||||||
|
elseif Current_drawing_mode == 'move' then
|
||||||
|
if Drawing.in_drawing(drawing, x, y) then
|
||||||
|
local mx,my = Drawing.coord(x-16), Drawing.coord(y-drawing.y)
|
||||||
|
drawing.pending.target_point.x = mx
|
||||||
|
drawing.pending.target_point.y = my
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function Drawing.mouse_released(x,y, button)
|
function Drawing.mouse_released(x,y, button)
|
||||||
if Current_drawing_mode == 'move' then
|
if Current_drawing_mode == 'move' then
|
||||||
Current_drawing_mode = Previous_drawing_mode
|
Current_drawing_mode = Previous_drawing_mode
|
||||||
|
|
22
main.lua
22
main.lua
|
@ -126,27 +126,7 @@ function love.draw()
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.update(dt)
|
function love.update(dt)
|
||||||
if Lines.current == nil then return end
|
Drawing.update(dt)
|
||||||
local drawing = Lines.current
|
|
||||||
assert(drawing.mode == 'drawing')
|
|
||||||
local x, y = love.mouse.getX(), love.mouse.getY()
|
|
||||||
if love.mouse.isDown('1') then
|
|
||||||
if Drawing.in_drawing(drawing, x,y) then
|
|
||||||
if drawing.pending.mode == 'freehand' then
|
|
||||||
table.insert(drawing.pending.points, {x=Drawing.coord(love.mouse.getX()-16), y=Drawing.coord(love.mouse.getY()-drawing.y)})
|
|
||||||
elseif drawing.pending.mode == 'move' then
|
|
||||||
local mx,my = Drawing.coord(x-16), Drawing.coord(y-drawing.y)
|
|
||||||
drawing.pending.target_point.x = mx
|
|
||||||
drawing.pending.target_point.y = my
|
|
||||||
end
|
|
||||||
end
|
|
||||||
elseif Current_drawing_mode == 'move' then
|
|
||||||
if Drawing.in_drawing(drawing, x, y) then
|
|
||||||
local mx,my = Drawing.coord(x-16), Drawing.coord(y-drawing.y)
|
|
||||||
drawing.pending.target_point.x = mx
|
|
||||||
drawing.pending.target_point.y = my
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.mousepressed(x,y, button)
|
function love.mousepressed(x,y, button)
|
||||||
|
|
Loading…
Reference in New Issue