diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2022-05-16 22:28:34 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2022-05-16 22:28:34 -0700 |
commit | 3a9f02c9f26f9f773ff003a7792aabbb4064f062 (patch) | |
tree | 1586d25e170a0f6b0514975993812b44b13a7605 | |
parent | 2ea683f4f28f4e983a949a9ef57e1a52f54f76ca (diff) | |
download | text.love-3a9f02c9f26f9f773ff003a7792aabbb4064f062.tar.gz |
move
-rw-r--r-- | main.lua | 45 |
1 files changed, 21 insertions, 24 deletions
diff --git a/main.lua b/main.lua index 26f0b81..da0b3cd 100644 --- a/main.lua +++ b/main.lua @@ -196,7 +196,27 @@ end function love.mousepressed(x,y, button) propagate_to_button_handlers(x,y, button) - propagate_to_drawings(x,y, button) + + for i,drawing in ipairs(lines) do + if drawing.mode == 'drawing' then + local x, y = love.mouse.getX(), love.mouse.getY() + 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=current_mode, points={{x=coord(x-16), y=coord(y-drawing.y)}}} + elseif current_mode == 'line' or current_mode == 'manhattan' then + local j = insert_point(drawing.points, coord(x-16), coord(y-drawing.y)) + drawing.pending = {mode=current_mode, p1=j} + elseif current_mode == 'polygon' then + local j = insert_point(drawing.points, coord(x-16), coord(y-drawing.y)) + drawing.pending = {mode=current_mode, vertices={j}} + elseif current_mode == 'circle' then + local j = insert_point(drawing.points, coord(x-16), coord(y-drawing.y)) + drawing.pending = {mode=current_mode, center=j} + end + lines.current = drawing + end + end + end end function love.mousereleased(x,y, button) @@ -261,29 +281,6 @@ function love.mousereleased(x,y, button) end end -function propagate_to_drawings(x,y, button) - for i,drawing in ipairs(lines) do - if drawing.mode == 'drawing' then - local x, y = love.mouse.getX(), love.mouse.getY() - 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=current_mode, points={{x=coord(x-16), y=coord(y-drawing.y)}}} - elseif current_mode == 'line' or current_mode == 'manhattan' then - local j = insert_point(drawing.points, coord(x-16), coord(y-drawing.y)) - drawing.pending = {mode=current_mode, p1=j} - elseif current_mode == 'polygon' then - local j = insert_point(drawing.points, coord(x-16), coord(y-drawing.y)) - drawing.pending = {mode=current_mode, vertices={j}} - elseif current_mode == 'circle' then - local j = insert_point(drawing.points, coord(x-16), coord(y-drawing.y)) - drawing.pending = {mode=current_mode, center=j} - end - lines.current = drawing - end - end - end -end - function insert_point(points, x,y) for i,point in ipairs(points) do if near(point, x,y) then |