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
|
-
|
|
|
|
|
|
!
-
|
|
|
|
!
-
-
!
-
-
|
|
!
!
-
|
|
|
|
-
|
|
|
|
|
|
-
|
|
|
|
|
|
|
!
|
|
|
|
!
-
|
|
|
!
-
|
|
!
| #module "box"
#define MAX_BOX 256
#define RECT_X 0
#define RECT_Y 1
#define RECT_SX 2
#define RECT_SY 3
#deffunc box_init
dim box_rect, MAX_BOX, 4
dim box_count,1
dim box_drag,3
box_count = 0
box_drag = 0,0,-1
return
#deffunc box_add int x, int y, int sx, int sy
if box_count < MAX_BOX {
box_rect(box_count,0) = x
box_rect(box_count,1) = y
box_rect(box_count,2) = sx
box_rect(box_count,3) = sy
box_count++
return box_count - 1
}
return -1
#defcfunc box_getcount
return box_count
#deffunc box_get int n, var x, var y, var sx, var sy
if 0 <= n {
x = box_rect(n,0)
y = box_rect(n,1)
sx= box_rect(n,2)
sy= box_rect(n,3)
}
return
#deffunc box_del int n
if n < 0 {
} else : if n < box_count {
}
return
#defcfunc box_inrect int x, int y
r = -1
repeat box_count
nn = box_count - 1 - cnt
if box_rect(nn,0) <= x && x <= box_rect(nn,0)+box_rect(nn,2) {
if box_rect(nn,1) <= y && y <= box_rect(nn,1)+box_rect(nn,3) {
r = nn
break
}
}
loop
return r
#deffunc box_setzorder int n, int z
if 0 <= n && n < box_count && 0 <= z && z < box_count && n != z {
_x = box_rect(n,0)
_y = box_rect(n,1)
_sx= box_rect(n,2)
_sy= box_rect(n,3)
if n < z {
repeat z - n, n
box_rect(cnt,0) = box_rect(cnt + 1,0)
box_rect(cnt,1) = box_rect(cnt + 1,1)
box_rect(cnt,2) = box_rect(cnt + 1,2)
box_rect(cnt,3) = box_rect(cnt + 1,3)
loop
} else {
repeat n - z, z
nn = n - cnt
box_rect(nn,0) = box_rect(nn - 1,0)
box_rect(nn,1) = box_rect(nn - 1,1)
box_rect(nn,2) = box_rect(nn - 1,2)
box_rect(nn,3) = box_rect(nn - 1,3)
loop
}
box_rect(z,0) = _x
box_rect(z,1) = _y
box_rect(z,2) = _sx
box_rect(z,3) = _sy
}
return
#deffunc box_drag_start int mx, int my
nn = box_inrect(mx, my)
if 0 <= nn && nn < box_count {
box_drag.0 = mx - box_rect(nn,0)
box_drag.1 = my - box_rect(nn,1)
box_drag.2 = nn
}
return
#deffunc box_dragging int mx, int my
if 0 <= box_drag.2 && box_drag.2 < box_count {
box_rect(box_drag.2,0) = mx - box_drag.0
box_rect(box_drag.2,1) = my - box_drag.1
}
return
#deffunc box_drag_end
box_drag.2 = -1
return
#global
|