From d55960ced007758a6df45d5010c7b4f28339e7a6 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 14 May 2022 15:09:22 -0700 Subject: bugfix: keep the click to create a new drawing from creating a new shape in the drawing Easiest way to do this is to keep the screen areas for button and drawing disjoint. --- main.lua | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/main.lua b/main.lua index aa1053b..d6e45c4 100644 --- a/main.lua +++ b/main.lua @@ -82,9 +82,9 @@ function love.draw() line.y = y y = y+pixels(line.h) love.graphics.setColor(0.75,0.75,0.75) - love.graphics.rectangle('line', 12,line.y, drawingw,pixels(line.h)) + love.graphics.rectangle('line', 16,line.y, drawingw,pixels(line.h)) - local mx,my = coord(love.mouse.getX()-12), coord(love.mouse.getY()-line.y) + local mx,my = coord(love.mouse.getX()-16), coord(love.mouse.getY()-line.y) for _,shape in ipairs(line.shapes) do if on_shape(mx,my, shape) then @@ -92,9 +92,9 @@ function love.draw() else love.graphics.setColor(0,0,0) end - draw_shape(12,line.y, shape) + draw_shape(16,line.y, shape) end - draw_pending_shape(12,line.y, line.pending) + draw_pending_shape(16,line.y, line.pending) else love.graphics.draw(text, 25,y, 0, 1.5) end @@ -114,9 +114,9 @@ function love.update(dt) 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 + pixels(drawing.h) and x >= 12 and x < 12+drawingw then + if y >= drawing.y and y < drawing.y + pixels(drawing.h) and x >= 16 and x < 16+drawingw then if drawing.pending.mode == 'freehand' then - table.insert(drawing.pending.points, {x=coord(love.mouse.getX()-12), y=coord(love.mouse.getY()-drawing.y)}) + table.insert(drawing.pending.points, {x=coord(love.mouse.getX()-16), y=coord(love.mouse.getY()-drawing.y)}) end end end @@ -135,7 +135,7 @@ function love.mousereleased(x,y, button) if lines.current.pending.mode == 'freehand' then -- the last point added during update is good enough elseif lines.current.pending.mode == 'line' then - lines.current.pending.x2 = coord(x-12) + lines.current.pending.x2 = coord(x-16) lines.current.pending.y2 = coord(y-lines.current.y) end table.insert(lines.current.shapes, lines.current.pending) @@ -149,11 +149,11 @@ 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 + pixels(drawing.h) and x >= 12 and x < 12+drawingw then + if y >= drawing.y and y < drawing.y + pixels(drawing.h) and x >= 16 and x < 16+drawingw then if current_mode == 'freehand' then - drawing.pending = {mode='freehand', points={x=coord(x-12), y=coord(y-drawing.y)}} + drawing.pending = {mode='freehand', points={x=coord(x-16), y=coord(y-drawing.y)}} elseif current_mode == 'line' then - drawing.pending = {mode='line', x1=coord(x-12), y1=coord(y-drawing.y)} + drawing.pending = {mode='line', x1=coord(x-16), y1=coord(y-drawing.y)} end lines.current = drawing end @@ -284,7 +284,7 @@ function in_drawing() local x, y = love.mouse.getX(), love.mouse.getY() for _,drawing in ipairs(lines) do if type(drawing) == 'table' then - if y >= drawing.y and y < drawing.y + pixels(drawing.h) and x >= 12 and x < 12+drawingw then + if y >= drawing.y and y < drawing.y + pixels(drawing.h) and x >= 16 and x < 16+drawingw then return true end end @@ -296,7 +296,7 @@ function current_drawing() local x, y = love.mouse.getX(), love.mouse.getY() for _,drawing in ipairs(lines) do if type(drawing) == 'table' then - if y >= drawing.y and y < drawing.y + pixels(drawing.h) and x >= 12 and x < 12+drawingw then + if y >= drawing.y and y < drawing.y + pixels(drawing.h) and x >= 16 and x < 16+drawingw then return drawing end end @@ -308,8 +308,8 @@ function select_shape_at_mouse() for _,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 + pixels(drawing.h) and x >= 12 and x < 12+drawingw then - local mx,my = coord(love.mouse.getX()-12), coord(love.mouse.getY()-drawing.y) + if y >= drawing.y and y < drawing.y + pixels(drawing.h) and x >= 16 and x < 16+drawingw then + local mx,my = coord(love.mouse.getX()-16), coord(love.mouse.getY()-drawing.y) for i,shape in ipairs(drawing.shapes) do if on_shape(mx,my, shape) then return drawing,i,shape -- cgit 1.4.1-2-gfad0 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96