about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-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