about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-05-11 22:33:45 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-05-11 22:35:36 -0700
commitfbba31ff7a60205ab633a84ea44bf935427f6291 (patch)
tree1622479bbab5f68f9b91bd46e81d88657b05fc64
parentccf7ecc5020014e4e277e0f31edce1b1ad40629d (diff)
downloadtext.love-fbba31ff7a60205ab633a84ea44bf935427f6291.tar.gz
turn strokes into horizontal and vertical lines
-rw-r--r--main.lua16
1 files changed, 16 insertions, 0 deletions
diff --git a/main.lua b/main.lua
index 71ed3d1..6a8933e 100644
--- a/main.lua
+++ b/main.lua
@@ -176,6 +176,11 @@ function keychord_pressed(chord)
     if drawing then
       convert_line(drawing,i,shape)
     end
+  elseif chord == 'C-m' then
+    local drawing,i,shape = select_shape_at_mouse()
+    if drawing then
+      convert_horvert(drawing,i,shape)
+    end
   end
 end
 
@@ -202,5 +207,16 @@ function convert_line(drawing, i, shape)
   drawing.shapes[i] = {shape[1], shape[#shape]}
 end
 
+-- turn a stroke into either a horizontal or vertical line
+function convert_horvert(drawing, i, shape)
+  local x1,y1 = shape[1].x, shape[1].y
+  local x2,y2 = shape[#shape].x, shape[#shape].y
+  if math.abs(x1-x2) > math.abs(y1-y2) then
+    drawing.shapes[i] = {{x=x1, y=y1}, {x=x2, y=y1}}
+  else
+    drawing.shapes[i] = {{x=x1, y=y1}, {x=x1, y=y2}}
+  end
+end
+
 function love.keyreleased(key, scancode)
 end