about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-07-12 17:27:00 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-07-12 17:27:00 -0700
commit1ede1c3c6d3fc2ec8070da4c726b3fbe1bf9d374 (patch)
treec8fc163a3156f8084a302fe94751340f1b266622
parentf7d4deef0ce51ad0527eb0b8b1a244adf3fb50f6 (diff)
downloadview.love-1ede1c3c6d3fc2ec8070da4c726b3fbe1bf9d374.tar.gz
add state arg to a few functions
  - Drawing.current_drawing
  - Drawing.select_shape_at_mouse
  - Drawing.select_point_at_mouse
  - Drawing.select_drawing_at_mouse
-rw-r--r--drawing.lua50
-rw-r--r--edit.lua2
2 files changed, 26 insertions, 26 deletions
diff --git a/drawing.lua b/drawing.lua
index 6f9d99c..d0e0123 100644
--- a/drawing.lua
+++ b/drawing.lua
@@ -377,7 +377,7 @@ function Drawing.keychord_pressed(State, chord)
     State.current_drawing_mode = 'freehand'
   elseif App.mouse_down(1) and chord == 'l' then
     State.current_drawing_mode = 'line'
-    local _,drawing = Drawing.current_drawing()
+    local _,drawing = Drawing.current_drawing(State)
     if drawing.pending.mode == 'freehand' then
       drawing.pending.p1 = Drawing.insert_point(drawing.points, drawing.pending.points[1].x, drawing.pending.points[1].y)
     elseif drawing.pending.mode == 'polygon' or drawing.pending.mode == 'rectangle' or drawing.pending.mode == 'square' then
@@ -390,7 +390,7 @@ function Drawing.keychord_pressed(State, chord)
     State.current_drawing_mode = 'line'
   elseif App.mouse_down(1) and chord == 'm' then
     State.current_drawing_mode = 'manhattan'
-    local drawing = Drawing.select_drawing_at_mouse()
+    local drawing = Drawing.select_drawing_at_mouse(State)
     if drawing.pending.mode == 'freehand' then
       drawing.pending.p1 = Drawing.insert_point(drawing.points, drawing.pending.points[1].x, drawing.pending.points[1].y)
     elseif drawing.pending.mode == 'line' then
@@ -407,7 +407,7 @@ function Drawing.keychord_pressed(State, chord)
     State.current_drawing_mode = 'polygon'
   elseif App.mouse_down(1) and chord == 'g' then
     State.current_drawing_mode = 'polygon'
-    local _,drawing = Drawing.current_drawing()
+    local _,drawing = Drawing.current_drawing(State)
     if drawing.pending.mode == 'freehand' then
       drawing.pending.vertices = {Drawing.insert_point(drawing.points, drawing.pending.points[1].x, drawing.pending.points[1].y)}
     elseif drawing.pending.mode == 'line' or drawing.pending.mode == 'manhattan' then
@@ -424,7 +424,7 @@ function Drawing.keychord_pressed(State, chord)
     State.current_drawing_mode = 'rectangle'
   elseif App.mouse_down(1) and chord == 'r' then
     State.current_drawing_mode = 'rectangle'
-    local _,drawing = Drawing.current_drawing()
+    local _,drawing = Drawing.current_drawing(State)
     if drawing.pending.mode == 'freehand' then
       drawing.pending.vertices = {Drawing.insert_point(drawing.points, drawing.pending.points[1].x, drawing.pending.points[1].y)}
     elseif drawing.pending.mode == 'line' or drawing.pending.mode == 'manhattan' then
@@ -441,7 +441,7 @@ function Drawing.keychord_pressed(State, chord)
     State.current_drawing_mode = 'square'
   elseif App.mouse_down(1) and chord == 's' then
     State.current_drawing_mode = 'square'
-    local _,drawing = Drawing.current_drawing()
+    local _,drawing = Drawing.current_drawing(State)
     if drawing.pending.mode == 'freehand' then
       drawing.pending.vertices = {Drawing.insert_point(drawing.points, drawing.pending.points[1].x, drawing.pending.points[1].y)}
     elseif drawing.pending.mode == 'line' or drawing.pending.mode == 'manhattan' then
@@ -459,12 +459,12 @@ function Drawing.keychord_pressed(State, chord)
     end
     drawing.pending.mode = 'square'
   elseif App.mouse_down(1) and chord == 'p' and State.current_drawing_mode == 'polygon' then
-    local _,drawing = Drawing.current_drawing()
+    local _,drawing = Drawing.current_drawing(State)
     local mx,my = Drawing.coord(App.mouse_x()-State.margin_left), Drawing.coord(App.mouse_y()-drawing.y)
     local j = Drawing.insert_point(drawing.points, mx,my)
     table.insert(drawing.pending.vertices, j)
   elseif App.mouse_down(1) and chord == 'p' and (State.current_drawing_mode == 'rectangle' or State.current_drawing_mode == 'square') then
-    local _,drawing = Drawing.current_drawing()
+    local _,drawing = Drawing.current_drawing(State)
     local mx,my = Drawing.coord(App.mouse_x()-State.margin_left), Drawing.coord(App.mouse_y()-drawing.y)
     local j = Drawing.insert_point(drawing.points, mx,my)
     while #drawing.pending.vertices >= 2 do
@@ -474,7 +474,7 @@ function Drawing.keychord_pressed(State, chord)
   elseif chord == 'C-o' and not App.mouse_down(1) then
     State.current_drawing_mode = 'circle'
   elseif App.mouse_down(1) and chord == 'a' and State.current_drawing_mode == 'circle' then
-    local _,drawing = Drawing.current_drawing()
+    local _,drawing = Drawing.current_drawing(State)
     drawing.pending.mode = 'arc'
     local mx,my = Drawing.coord(App.mouse_x()-State.margin_left), Drawing.coord(App.mouse_y()-drawing.y)
     local center = drawing.points[drawing.pending.center]
@@ -482,7 +482,7 @@ function Drawing.keychord_pressed(State, chord)
     drawing.pending.start_angle = geom.angle(center.x,center.y, mx,my)
   elseif App.mouse_down(1) and chord == 'o' then
     State.current_drawing_mode = 'circle'
-    local _,drawing = Drawing.current_drawing()
+    local _,drawing = Drawing.current_drawing(State)
     if drawing.pending.mode == 'freehand' then
       drawing.pending.center = Drawing.insert_point(drawing.points, drawing.pending.points[1].x, drawing.pending.points[1].y)
     elseif drawing.pending.mode == 'line' or drawing.pending.mode == 'manhattan' then
@@ -492,7 +492,7 @@ function Drawing.keychord_pressed(State, chord)
     end
     drawing.pending.mode = 'circle'
   elseif chord == 'C-u' and not App.mouse_down(1) then
-    local drawing_index,drawing,i,p = Drawing.select_point_at_mouse()
+    local drawing_index,drawing,i,p = Drawing.select_point_at_mouse(State)
     if drawing then
       if State.previous_drawing_mode == nil then
         State.previous_drawing_mode = State.current_drawing_mode
@@ -503,7 +503,7 @@ function Drawing.keychord_pressed(State, chord)
       State.lines.current_drawing = drawing
     end
   elseif chord == 'C-n' and not App.mouse_down(1) then
-    local drawing_index,drawing,point_index,p = Drawing.select_point_at_mouse()
+    local drawing_index,drawing,point_index,p = Drawing.select_point_at_mouse(State)
     if drawing then
       if State.previous_drawing_mode == nil then
         -- don't clobber
@@ -516,7 +516,7 @@ function Drawing.keychord_pressed(State, chord)
       State.lines.current_drawing = drawing
     end
   elseif chord == 'C-d' and not App.mouse_down(1) then
-    local _,drawing,i,p = Drawing.select_point_at_mouse()
+    local _,drawing,i,p = Drawing.select_point_at_mouse(State)
     if drawing then
       for _,shape in ipairs(drawing.shapes) do
         if Drawing.contains_point(shape, i) then
@@ -534,17 +534,17 @@ function Drawing.keychord_pressed(State, chord)
       end
       drawing.points[i].deleted = true
     end
-    local drawing,_,shape = Drawing.select_shape_at_mouse()
+    local drawing,_,shape = Drawing.select_shape_at_mouse(State)
     if drawing then
       shape.mode = 'deleted'
     end
   elseif chord == 'C-h' and not App.mouse_down(1) then
-    local drawing = Drawing.select_drawing_at_mouse()
+    local drawing = Drawing.select_drawing_at_mouse(State)
     if drawing then
       drawing.show_help = true
     end
   elseif chord == 'escape' and App.mouse_down(1) then
-    local _,drawing = Drawing.current_drawing()
+    local _,drawing = Drawing.current_drawing(State)
     drawing.pending = {}
   end
 end
@@ -597,9 +597,9 @@ function Drawing.complete_square(firstx,firsty, secondx,secondy, x,y)
   return thirdx,thirdy, fourthx,fourthy
 end
 
-function Drawing.current_drawing()
+function Drawing.current_drawing(State)
   local x, y = App.mouse_x(), App.mouse_y()
-  for drawing_index,drawing in ipairs(Editor_state.lines) do
+  for drawing_index,drawing in ipairs(State.lines) do
     if drawing.mode == 'drawing' then
       if Drawing.in_drawing(drawing, x,y) then
         return drawing_index,drawing
@@ -609,12 +609,12 @@ function Drawing.current_drawing()
   return nil
 end
 
-function Drawing.select_shape_at_mouse()
-  for _,drawing in ipairs(Editor_state.lines) do
+function Drawing.select_shape_at_mouse(State)
+  for _,drawing in ipairs(State.lines) do
     if drawing.mode == 'drawing' then
       local x, y = App.mouse_x(), App.mouse_y()
       if Drawing.in_drawing(drawing, x,y) 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)
         for i,shape in ipairs(drawing.shapes) do
           assert(shape)
           if geom.on_shape(mx,my, drawing, shape) then
@@ -626,12 +626,12 @@ function Drawing.select_shape_at_mouse()
   end
 end
 
-function Drawing.select_point_at_mouse()
-  for drawing_index,drawing in ipairs(Editor_state.lines) do
+function Drawing.select_point_at_mouse(State)
+  for drawing_index,drawing in ipairs(State.lines) do
     if drawing.mode == 'drawing' then
       local x, y = App.mouse_x(), App.mouse_y()
       if Drawing.in_drawing(drawing, x,y) 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)
         for i,point in ipairs(drawing.points) do
           assert(point)
           if Drawing.near(point, mx,my) then
@@ -643,8 +643,8 @@ function Drawing.select_point_at_mouse()
   end
 end
 
-function Drawing.select_drawing_at_mouse()
-  for _,drawing in ipairs(Editor_state.lines) do
+function Drawing.select_drawing_at_mouse(State)
+  for _,drawing in ipairs(State.lines) do
     if drawing.mode == 'drawing' then
       local x, y = App.mouse_x(), App.mouse_y()
       if Drawing.in_drawing(drawing, x,y) then
diff --git a/edit.lua b/edit.lua
index 303ecbe..2616487 100644
--- a/edit.lua
+++ b/edit.lua
@@ -399,7 +399,7 @@ function edit.keychord_pressed(State, chord, key)
   -- dispatch to drawing or text
   elseif App.mouse_down(1) or chord:sub(1,2) == 'C-' then
     -- DON'T reset line.y here
-    local drawing_index, drawing = Drawing.current_drawing()
+    local drawing_index, drawing = Drawing.current_drawing(State)
     if drawing_index then
       local before = snapshot(State, drawing_index)
       Drawing.keychord_pressed(State, chord)
9c891c22379f029c42abc38e408c'>4c37b3e9 ^
d1c9392a ^

5fe060d5 ^



d1c9392a ^
5fe060d5 ^
9c1056f5 ^
5fe060d5 ^

4c37b3e9 ^
5fe060d5 ^
4c37b3e9 ^
52daf072 ^

d1c9392a ^


9c1056f5 ^
d1c9392a ^






52daf072 ^

d1c9392a ^

52daf072 ^
cdfff1a1 ^

9c1056f5 ^
cdfff1a1 ^
52daf072 ^




















































































































































































































25ad969f ^



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360