9 | 9 |
|
10 | 10 |
size: ->
|
11 | 11 |
vec2 math.random! * 200 + 100, math.random! * 200 + 100
|
|
12 |
|
|
13 |
hit =
|
|
14 |
radius: (pos, r) ->
|
|
15 |
hit.radius2 pos, r*r
|
|
16 |
|
|
17 |
radius2: (pos, r2) ->
|
|
18 |
contains = (INPUT.mouse - pos)\len2! < r2
|
|
19 |
INPUT\mouse_event! or 'hover' if contains
|
|
20 |
|
|
21 |
line: (frm, to, r2=10) ->
|
|
22 |
delta = to - frm
|
|
23 |
mouse = INPUT.mouse - frm
|
|
24 |
dot = (mouse\dot delta) / delta\len2!
|
|
25 |
dot = math.min 1, math.max 0, dot
|
|
26 |
p = frm + delta * dot
|
|
27 |
|
|
28 |
hit.radius2 p, r2
|
|
29 |
|
|
30 |
rect: (min, max) ->
|
|
31 |
rect = bound2 min, max
|
|
32 |
contains = rect\contains INPUT.mouse
|
|
33 |
INPUT\mouse_event! or 'hover' if contains
|
12 | 34 |
|
13 | 35 |
draw =
|
14 | 36 |
cross: (pos) ->
|
|
20 | 42 |
lg.line mx, my, Mx, My
|
21 | 43 |
lg.line mx, My, Mx, my
|
22 | 44 |
|
23 | |
contains = (INPUT.mouse - pos)\len2! < hs\len2!
|
24 | |
INPUT\mouse_event! if contains
|
|
45 |
hit.radius2 pos, hs\len2!
|
25 | 46 |
|
26 | 47 |
line: (frm, to) ->
|
27 | 48 |
lg.setColor 1, 1, 1
|
28 | 49 |
lg.line frm.x, frm.y, to.x, to.y
|
29 | 50 |
|
30 | |
-- @TODO: hit checking
|
|
51 |
hit.line frm, to
|
|
52 |
|
|
53 |
arrow: (frm, to) ->
|
|
54 |
dir = (to - frm)\normalize!
|
|
55 |
up = dir\perpendicular!
|
|
56 |
draw.line to - dir * 15 + up * 7, to
|
|
57 |
draw.line to - dir * 15 - up * 7, to
|
|
58 |
|
|
59 |
draw.line frm, to
|
31 | 60 |
|
32 | 61 |
rect: (min, max) ->
|
33 | 62 |
x, y = min\unpack!
|
|
35 | 64 |
lg.setColor 1, 1, 1
|
36 | 65 |
lg.rectangle 'line', x, y, w, h
|
37 | 66 |
|
38 | |
rect = bound2 min, max
|
39 | |
contains = rect\contains INPUT.mouse
|
40 | |
INPUT\mouse_event! if contains
|
|
67 |
hit.rect min, max
|
41 | 68 |
|
42 | 69 |
circle: (center, r) ->
|
43 | 70 |
x, y = center\unpack!
|
44 | 71 |
lg.setColor 1, 1, 1
|
45 | 72 |
lg.circle 'line', x, y, r
|
46 | 73 |
|
47 | |
contains = (INPUT.mouse - center)\len! < r
|
48 | |
INPUT\mouse_event! if contains
|
|
74 |
hit.radius2 center, r*r
|
49 | 75 |
|
50 | 76 |
half_handle = vec2 15, 15
|
51 | 77 |
input =
|
|
108 | 134 |
delta = last and pos - last
|
109 | 135 |
return delta and delta\len2! > 0 and delta
|
110 | 136 |
|
111 | |
rectangle: do
|
|
137 |
line: (frm, to) =>
|
|
138 |
input.point @frm, frm
|
|
139 |
input.point @to, to
|
|
140 |
|
|
141 |
frm, to = @frm!, @to!
|
|
142 |
@set :frm, :to
|
|
143 |
draw.line frm, to
|
|
144 |
|
|
145 |
arrow: (frm, to) =>
|
|
146 |
input.point @frm, frm
|
|
147 |
input.point @to, to
|
|
148 |
|
|
149 |
frm, to = @frm!, @to!
|
|
150 |
@set :frm, :to
|
|
151 |
draw.line frm, to
|
|
152 |
|
|
153 |
rect: do
|
112 | 154 |
meta = size: => @max - @min
|
113 | 155 |
meta.__index = meta
|
114 | 156 |
|
|
145 | 187 |
|
146 | 188 |
selection: (pattern) =>
|
147 | 189 |
-- @TOOD: fix
|
148 | |
@init {o for o in *SESSION.objects when match and o.name\match init}
|
149 | |
|
150 | |
lg.push 'all'
|
151 | |
lg.setLineWidth 5
|
152 | |
for obj in *OBJS
|
153 | |
selected = @selection[obj]
|
|
190 |
@init {o,o for o in *SESSION.objects when match and o.name\match init}
|
|
191 |
|
|
192 |
selection = @!
|
|
193 |
index = {o,i for i,o in ipairs selection}
|
|
194 |
|
|
195 |
to_remove = {}
|
|
196 |
for obj in *SESSION.objects
|
|
197 |
selected = index[obj]
|
154 | 198 |
if selected
|
155 | |
obj\draw 'line', orng
|
156 | |
|
157 | |
if obj\hit!
|
158 | |
@selection[obj] = if selected then nil else obj
|
159 | |
|
160 | |
lg.pop!
|
161 | |
|
162 | |
[o for o in pairs @selection]
|
|
199 |
draw.cross obj.pos
|
|
200 |
-- obj\draw 'line', orng
|
|
201 |
|
|
202 |
if obj\hit! == 'down'
|
|
203 |
if selected
|
|
204 |
table.insert to_remove, selected
|
|
205 |
else
|
|
206 |
table.insert selection, obj
|
|
207 |
|
|
208 |
table.sort to_remove
|
|
209 |
for i=#to_remove,1,-1
|
|
210 |
table.remove selection, to_remove[i]
|
|
211 |
|
|
212 |
op =
|
|
213 |
move: (obj, to) ->
|
|
214 |
draw.arrow obj.pos, to
|
|
215 |
obj\draw!
|
163 | 216 |
|
164 | 217 |
{
|
|
218 |
:hit
|
165 | 219 |
:random
|
166 | 220 |
:draw
|
167 | 221 |
:input
|
|
222 |
:op
|
168 | 223 |
}
|