diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2022-05-11 21:57:36 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2022-05-11 21:57:36 -0700 |
commit | e83f2191075d4202395ba57ff1785bba849dc72d (patch) | |
tree | 64529873efd191464d498de4767cf7959c01eba3 | |
parent | 4850e78568c89da414501259fc9472df87eec33b (diff) | |
download | text.love-e83f2191075d4202395ba57ff1785bba849dc72d.tar.gz |
bugfix: restrict strokes to the drawing they started in
-rw-r--r-- | main.lua | 19 |
1 files 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) |