generic_editor.anubis
5.53 KB
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
read tools/basis.anubis
read widgets3/widget.anubis
read widgets3/tools.anubis
read widgets3/host_window.anubis
read widgets3/menu_manager.anubis
read widgets3/menus.anubis
define RGB black = rgb(0,0,0).
define RGB red = rgb(255,0,0).
define RGB yellow = rgb(255,255,210).
define RGB white = rgb(255,255,255).
type ENode:
enode (WidgetRectangle area_1,
List(WidgetRectangle) area_others,
Bool is_place_holder,
Var(Bool) h_v,
WidgetDrawToolBox -> One redraw,
List(Var(ENode)) childs).
*** Copying a enode.
For 'cut/copy/paste' operations we need to make a copy of an enode.
define ENode
copy
(
ENode e
) =
if e is enode(a1,ao,iph,h_v,rd,cs) then
enode(a1,ao,iph,var(*h_v),rd,
map((Var(ENode) e_v) |-> var(copy(*e_v)) ,cs)).
*** Making a place holder.
define ENode
make_place_holder
(
ENode model
) =
if model is enode(area_1,_,_,_,_,_) then
if area_1 is rect(x,y,u,v) then
with r = (WidgetRectangle)rect(x,y,x+10,y+10),
enode(r,
[],
true,
var(false),
(WidgetDrawToolBox dtb) |-> draw(dtb)(r,red),
[]).
*** Drawing the highlighting.
define One
draw_highlighting
(
WidgetDrawToolBox dtb,
List(WidgetRectangle) l
) =
if l is
{
[ ] then unique,
[h . t] then draw(dtb)(h,yellow);
draw_highlighting(dtb,t)
}.
*** Drawing the editor and its content.
define WidgetDrawToolBox -> One
redraw_editor
(
Var(Int32) ed_width_v,
Var(Int32) ed_height_v,
Var(ENode) content_v
) =
(WidgetDrawToolBox dtb) |->
draw(dtb)(rect(0,0,*ed_width_v,*ed_height_v),white);
if *content_v is enode(_,_,_,_,rd,_) then rd(dtb).
*** Drawing a node.
define One
draw_node
(
ENode e
) =
if e is enode(WidgetRectangle area_1,
List(WidgetRectangle) area_others,
Bool is_place_holder,
Var(Bool) h_v,
((WidgetDrawToolBox) -> One) redraw,
List(Var(ENode)) childs) then alert.
*** Getting the location of node which is highlighted (if any).
define Maybe(Var(ENode))
get_highlighted
(
Var(ENode) e
).
define Maybe(Var(ENode))
get_highlighted
(
List(Var(ENode)) l
) =
if l is
{
[ ] then failure,
[h . t] then if get_highlighted(h) is
{
failure then get_highlighted(t)
success(v) then success(v)
}
}.
define Maybe(Var(ENode))
get_highlighted
(
Var(ENode) e
) =
if *e is enode(a1,ao,iph,h_v,rd,cs) then
if *h_v
then success(e)
else get_highlighted(cs).
*** Getting the location of the smallest node containing the mouse pointer (if any).
define Maybe(Var(ENode))
get_smallest_node
(
Var(ENode) e,
Int32 mx,
Int32 my
).
define Maybe(Var(ENode))
get_smallest_node
(
List(Var(ENode)) l,
Int32 mx,
Int32 my
) =
if l is
{
[ ] then failure,
[h . t] then if get_smallest_node(h,mx,my) is
{
failure then get_smallest_node(t,mx,my),
success(v) then success(v)
}
}.
define Maybe(Var(ENode))
get_smallest_node
(
Var(ENode) e,
Int32 mx,
Int32 my
) =
if *e is enode(a1,ao,iph,h_v,rd,cs) then
if mapor((WidgetRectangle r) |-> belongs(mx,my,r),[a1 . ao])
then if get_smallest_node(cs,mx,my) is
{
failure then success(e)
success(c) then success(c)
}
else failure.
*** Performing a 'Cut', a 'Copy' or a 'Paste'.
define WidgetEventToolBox -> List(WidgetRectangle)
do_cut
(
Var(MenuCommand) menu_cv,
Rectangle editor_area,
Var(ENode) where,
Var(ENode) paste_v
) =
(WidgetEventToolBox mmetb) |->
paste_v <- *where;
where <- make_place_holder(*where);
menu_cv <- clear;
[receive_rectangle(mmetb)(editor_area)].
define WidgetEventToolBox -> List(WidgetRectangle)
do_copy
(
Var(MenuCommand) menu_cv,
Rectangle editor_area,
Var(ENode) where,
Var(ENode) paste_v
) =
(WidgetEventToolBox mmetb) |->
paste_v <- copy(*where);
menu_cv <- clear;
[receive_rectangle(mmetb)(editor_area)].
define WidgetEventToolBox -> List(WidgetRectangle)
do_paste
(
Var(MenuCommand) menu_cv,
Rectangle editor_area,
Var(ENode) where,
Var(ENode) paste_v
) =
(WidgetEventToolBox mmetb) |->
where <- copy(*paste_v);
menu_cv <- clear;
[receive_rectangle(mmetb)(editor_area)].
*** The event handler of the editor.
define WidgetAnswer
handle_mouse_move
(
Var(ENode) content_v
) =
with mb_already_highlighted = get_highlighted(content_v),