about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-05-11 22:29:21 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-05-11 22:29:21 -0700
commitccf7ecc5020014e4e277e0f31edce1b1ad40629d (patch)
tree8e4d245ccbe0f1f9357d2f3f55795afe789b814c
parent61292c439bf5549d195abaa9c32dc627a108bb6c (diff)
downloadtext.love-ccf7ecc5020014e4e277e0f31edce1b1ad40629d.tar.gz
refactor
-rw-r--r--main.lua23
1 files changed, 15 insertions, 8 deletions
diff --git a/main.lua b/main.lua
index afd4b32..71ed3d1 100644
--- a/main.lua
+++ b/main.lua
@@ -172,14 +172,21 @@ function keychord_pressed(chord)
   elseif chord == 'C-d' then
     parse_into_exec_payload(lines[#lines])
   elseif chord == 'C-l' then
-    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
-          for j,shape in ipairs(drawing.shapes) do
-            if on_freehand(love.mouse.getX(),love.mouse.getY(), shape) then
-              convert_line(drawing,j,shape)
-            end
+    local drawing,i,shape = select_shape_at_mouse()
+    if drawing then
+      convert_line(drawing,i,shape)
+    end
+  end
+end
+
+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 + drawing.h and x >= 12 and x < 12+drawing.w then
+        for i,shape in ipairs(drawing.shapes) do
+          if on_freehand(love.mouse.getX(),love.mouse.getY(), shape) then
+            return drawing,i,shape
           end
         end
       end