about summary refs log tree commit diff stats
path: root/drawing.lua
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-07-13 08:14:01 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-07-13 08:14:01 -0700
commit457136a986ad39b38c448ccbb94db32a35cd8dd3 (patch)
treee9ce0f1b1830a4c36aa0a14174e5216fe43b0c4d /drawing.lua
parent9f962b7cacda1cf693d402f47ff45c474d883b51 (diff)
downloadtext.love-457136a986ad39b38c448ccbb94db32a35cd8dd3.tar.gz
chunking by simple local variable
Diffstat (limited to 'drawing.lua')
-rw-r--r--drawing.lua10
1 files changed, 6 insertions, 4 deletions
diff --git a/drawing.lua b/drawing.lua
index 065be70..2c83b4e 100644
--- a/drawing.lua
+++ b/drawing.lua
@@ -213,16 +213,18 @@ function Drawing.in_drawing(drawing, x,y, left,right)
 end
 
 function Drawing.mouse_pressed(State, drawing, x,y, button)
+  local cx = Drawing.coord(x-State.left, State.width)
+  local cy = Drawing.coord(y-drawing.y, State.width)
   if State.current_drawing_mode == 'freehand' then
-    drawing.pending = {mode=State.current_drawing_mode, points={{x=Drawing.coord(x-State.left, State.width), y=Drawing.coord(y-drawing.y, State.width)}}}
+    drawing.pending = {mode=State.current_drawing_mode, points={{x=cx, y=cy}}}
   elseif State.current_drawing_mode == 'line' or State.current_drawing_mode == 'manhattan' then
-    local j = Drawing.find_or_insert_point(drawing.points, Drawing.coord(x-State.left, State.width), Drawing.coord(y-drawing.y, State.width), State.width)
+    local j = Drawing.find_or_insert_point(drawing.points, cx, cy, State.width)
     drawing.pending = {mode=State.current_drawing_mode, p1=j}
   elseif State.current_drawing_mode == 'polygon' or State.current_drawing_mode == 'rectangle' or State.current_drawing_mode == 'square' then
-    local j = Drawing.find_or_insert_point(drawing.points, Drawing.coord(x-State.left, State.width), Drawing.coord(y-drawing.y, State.width), State.width)
+    local j = Drawing.find_or_insert_point(drawing.points, cx, cy, State.width)
     drawing.pending = {mode=State.current_drawing_mode, vertices={j}}
   elseif State.current_drawing_mode == 'circle' then
-    local j = Drawing.find_or_insert_point(drawing.points, Drawing.coord(x-State.left, State.width), Drawing.coord(y-drawing.y, State.width), State.width)
+    local j = Drawing.find_or_insert_point(drawing.points, cx, cy, State.width)
     drawing.pending = {mode=State.current_drawing_mode, center=j}
   elseif State.current_drawing_mode == 'move' then
     -- all the action is in mouse_released
ref='#n195'>195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227