about summary refs log tree commit diff stats
path: root/main.lua
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-05-16 22:28:34 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-05-16 22:28:34 -0700
commit3a9f02c9f26f9f773ff003a7792aabbb4064f062 (patch)
tree1586d25e170a0f6b0514975993812b44b13a7605 /main.lua
parent2ea683f4f28f4e983a949a9ef57e1a52f54f76ca (diff)
downloadtext.love-3a9f02c9f26f9f773ff003a7792aabbb4064f062.tar.gz
move
Diffstat (limited to 'main.lua')
-rw-r--r--main.lua45
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