about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-07-12 16:21:56 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-07-12 16:21:56 -0700
commitd6795f9df0d98788804528a317ec5bb94f795922 (patch)
tree71526946a4af21191332318157698c1ff76a0098
parent780105cb13a9000f63e18201912de01e77480d25 (diff)
downloadview.love-d6795f9df0d98788804528a317ec5bb94f795922.tar.gz
add state arg to Drawing.mouse_released
-rw-r--r--drawing.lua40
-rw-r--r--edit.lua2
2 files changed, 21 insertions, 21 deletions
diff --git a/drawing.lua b/drawing.lua
index 998a473..ac879f8 100644
--- a/drawing.lua
+++ b/drawing.lua
@@ -276,16 +276,16 @@ function Drawing.relax_constraints(drawing, p)
   end
 end
 
-function Drawing.mouse_released(x,y, button)
-  if Editor_state.current_drawing_mode == 'move' then
-    Editor_state.current_drawing_mode = Editor_state.previous_drawing_mode
-    Editor_state.previous_drawing_mode = nil
-    if Editor_state.lines.current_drawing then
-      Editor_state.lines.current_drawing.pending = {}
-      Editor_state.lines.current_drawing = nil
-    end
-  elseif Editor_state.lines.current_drawing then
-    local drawing = Editor_state.lines.current_drawing
+function Drawing.mouse_released(State, x,y, button)
+  if State.current_drawing_mode == 'move' then
+    State.current_drawing_mode = State.previous_drawing_mode
+    State.previous_drawing_mode = nil
+    if State.lines.current_drawing then
+      State.lines.current_drawing.pending = {}
+      State.lines.current_drawing = nil
+    end
+  elseif State.lines.current_drawing then
+    local drawing = State.lines.current_drawing
     if drawing.pending then
       if drawing.pending.mode == nil then
         -- nothing pending
@@ -294,14 +294,14 @@ function Drawing.mouse_released(x,y, button)
         Drawing.smoothen(drawing.pending)
         table.insert(drawing.shapes, drawing.pending)
       elseif drawing.pending.mode == 'line' then
-        local mx,my = Drawing.coord(x-Editor_state.margin_left), Drawing.coord(y-drawing.y)
+        local mx,my = Drawing.coord(x-State.margin_left), Drawing.coord(y-drawing.y)
         if mx >= 0 and mx < 256 and my >= 0 and my < drawing.h then
           drawing.pending.p2 = Drawing.insert_point(drawing.points, mx,my)
           table.insert(drawing.shapes, drawing.pending)
         end
       elseif drawing.pending.mode == 'manhattan' then
         local p1 = drawing.points[drawing.pending.p1]
-        local mx,my = Drawing.coord(x-Editor_state.margin_left), Drawing.coord(y-drawing.y)
+        local mx,my = Drawing.coord(x-State.margin_left), Drawing.coord(y-drawing.y)
         if mx >= 0 and mx < 256 and my >= 0 and my < drawing.h then
           if math.abs(mx-p1.x) > math.abs(my-p1.y) then
             drawing.pending.p2 = Drawing.insert_point(drawing.points, mx, p1.y)
@@ -309,11 +309,11 @@ function Drawing.mouse_released(x,y, button)
             drawing.pending.p2 = Drawing.insert_point(drawing.points, p1.x, my)
           end
           local p2 = drawing.points[drawing.pending.p2]
-          App.mouse_move(Editor_state.margin_left+Drawing.pixels(p2.x), drawing.y+Drawing.pixels(p2.y))
+          App.mouse_move(State.margin_left+Drawing.pixels(p2.x), drawing.y+Drawing.pixels(p2.y))
           table.insert(drawing.shapes, drawing.pending)
         end
       elseif drawing.pending.mode == 'polygon' then
-        local mx,my = Drawing.coord(x-Editor_state.margin_left), Drawing.coord(y-drawing.y)
+        local mx,my = Drawing.coord(x-State.margin_left), Drawing.coord(y-drawing.y)
         if mx >= 0 and mx < 256 and my >= 0 and my < drawing.h then
           table.insert(drawing.pending.vertices, Drawing.insert_point(drawing.points, mx,my))
           table.insert(drawing.shapes, drawing.pending)
@@ -321,7 +321,7 @@ function Drawing.mouse_released(x,y, button)
       elseif drawing.pending.mode == 'rectangle' then
         assert(#drawing.pending.vertices <= 2)
         if #drawing.pending.vertices == 2 then
-          local mx,my = Drawing.coord(x-Editor_state.margin_left), Drawing.coord(y-drawing.y)
+          local mx,my = Drawing.coord(x-State.margin_left), Drawing.coord(y-drawing.y)
           if mx >= 0 and mx < 256 and my >= 0 and my < drawing.h then
             local first = drawing.points[drawing.pending.vertices[1]]
             local second = drawing.points[drawing.pending.vertices[2]]
@@ -336,7 +336,7 @@ function Drawing.mouse_released(x,y, button)
       elseif drawing.pending.mode == 'square' then
         assert(#drawing.pending.vertices <= 2)
         if #drawing.pending.vertices == 2 then
-          local mx,my = Drawing.coord(x-Editor_state.margin_left), Drawing.coord(y-drawing.y)
+          local mx,my = Drawing.coord(x-State.margin_left), Drawing.coord(y-drawing.y)
           if mx >= 0 and mx < 256 and my >= 0 and my < drawing.h then
             local first = drawing.points[drawing.pending.vertices[1]]
             local second = drawing.points[drawing.pending.vertices[2]]
@@ -347,14 +347,14 @@ function Drawing.mouse_released(x,y, button)
           end
         end
       elseif drawing.pending.mode == 'circle' then
-        local mx,my = Drawing.coord(x-Editor_state.margin_left), Drawing.coord(y-drawing.y)
+        local mx,my = Drawing.coord(x-State.margin_left), Drawing.coord(y-drawing.y)
         if mx >= 0 and mx < 256 and my >= 0 and my < drawing.h then
           local center = drawing.points[drawing.pending.center]
           drawing.pending.radius = geom.dist(center.x,center.y, mx,my)
           table.insert(drawing.shapes, drawing.pending)
         end
       elseif drawing.pending.mode == 'arc' then
-        local mx,my = Drawing.coord(x-Editor_state.margin_left), Drawing.coord(y-drawing.y)
+        local mx,my = Drawing.coord(x-State.margin_left), Drawing.coord(y-drawing.y)
         if mx >= 0 and mx < 256 and my >= 0 and my < drawing.h then
           local center = drawing.points[drawing.pending.center]
           drawing.pending.end_angle = geom.angle_with_hint(center.x,center.y, mx,my, drawing.pending.end_angle)
@@ -366,8 +366,8 @@ function Drawing.mouse_released(x,y, button)
         print(drawing.pending.mode)
         assert(false)
       end
-      Editor_state.lines.current_drawing.pending = {}
-      Editor_state.lines.current_drawing = nil
+      State.lines.current_drawing.pending = {}
+      State.lines.current_drawing = nil
     end
   end
 end
diff --git a/edit.lua b/edit.lua
index 718f8fb..7aa9057 100644
--- a/edit.lua
+++ b/edit.lua
@@ -239,7 +239,7 @@ function edit.mouse_released(State, x,y, mouse_button)
   if State.search_term then return end
 --?   print('release')
   if State.lines.current_drawing then
-    Drawing.mouse_released(x,y, mouse_button)
+    Drawing.mouse_released(State, x,y, mouse_button)
     schedule_save()
     if Drawing.before then
       record_undo_event({before=Drawing.before, after=snapshot(State.lines.current_drawing_index)})