From e83f2191075d4202395ba57ff1785bba849dc72d Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Wed, 11 May 2022 21:57:36 -0700 Subject: [PATCH] bugfix: restrict strokes to the drawing they started in --- main.lua | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/main.lua b/main.lua index 6cb7a2e..a0295a1 100644 --- a/main.lua +++ b/main.lua @@ -75,12 +75,11 @@ end function love.update(dt) if love.mouse.isDown('1') then - for i, line in ipairs(lines) do - if type(line) == 'table' then - local drawing = line + if lines.current then + local drawing = lines.current + if type(drawing) == 'table' then local x, y = love.mouse.getX(), love.mouse.getY() if y >= drawing.y and y < drawing.y + drawing.h and x >= 12 and x < 12+drawing.w then - lines.current = drawing table.insert(drawing.pending, {x=love.mouse.getX(), y=love.mouse.getY()}) end end @@ -90,6 +89,18 @@ end function love.mousepressed(x,y, button) propagate_to_button_handers(x,y, button) + propagate_to_drawings(x,y, button) +end + +function propagate_to_drawings(x,y, button) + for i,drawing in ipairs(lines) do + if type(drawing) == 'table' then + local x, y = love.mouse.getX(), love.mouse.getY() + if y >= drawing.y and y < drawing.y + drawing.h and x >= 12 and x < 12+drawing.w then + lines.current = drawing + end + end + end end function love.mousereleased(x,y, button)