From 91fe5cd98061af426505319e826d76d5b8ad4daa Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Wed, 11 May 2022 22:15:54 -0700 Subject: [PATCH] more lightweight; select just the stroke at the mouse --- main.lua | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/main.lua b/main.lua index 7a47c7a..accc980 100644 --- a/main.lua +++ b/main.lua @@ -4,7 +4,6 @@ require 'repl' local utf8 = require 'utf8' lines = {} -mode = '' width, height, flags = 0, 0, nil exec_payload = nil @@ -45,7 +44,7 @@ function love.draw() y = y+line.h for _,shape in ipairs(line.shapes) do - if shape.selected then + if on_freehand(love.mouse.getX(),love.mouse.getY(), shape) then love.graphics.setColor(1,0,0) else love.graphics.setColor(0,0,0) @@ -79,7 +78,7 @@ function love.draw() end function love.update(dt) - if love.mouse.isDown('1') and mode == 'draw' then + if love.mouse.isDown('1') then if lines.current then local drawing = lines.current if type(drawing) == 'table' then @@ -98,22 +97,14 @@ function love.mousepressed(x,y, button) end function propagate_to_drawings(x,y, button) - mode = 'grab' 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 - for _,shape in ipairs(drawing.shapes) do - if on_freehand(x,y, shape) then - shape.selected = true - return - end - end end end end - mode = 'draw' end function on_freehand(x,y, shape)