resizer.anubis
3.33 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
The Anubis/Paradize Project.
The resizer widget.
Copyright (c) Alain Prouté 2004-2005.
Authors: Alain Prouté
read widget.anubis
read tools.anubis
This file defines the 'resizer' widget. This widget appears as a small square with 4
arrows pointing to top-left, top-right bottom-left and bottom-right. When left clicked,
it captures the mouse, and while the mouse is captured it adds the coordinates of mouse
movements to two variables given at its creation. Of course, these variables may be
monitored by other widgets (like windows or scrollbars for example), and this may
produce various effects, like 'resizing'.
public define Widget
create_resizer
(
WidgetParameters parameters,
Var(Int32) x_v, // variable controled by the resizer
Var(Int32) y_v, // idem
Var(Int32) w_v // width of resizer (pixels)
).
--- That's all for the public part ! --------------------------------------------------
define (KeyboardState ks, WidgetMouseCapturedEvent e) -> WidgetAnswer
captured_handler
(
Var(Int32) x_v, // controled variables
Var(Int32) y_v,
Var(Int32) mx_v, // last known position of mouse
Var(Int32) my_v
) =
(KeyboardState ks, WidgetMouseCapturedEvent e) |->
with xe = x(e), ye = y(e),
x_v <- *x_v + (xe - *mx_v);
mx_v <- xe;
y_v <- *y_v + (ye - *my_v);
my_v <- ye;
handled([]).
public define Widget
create_resizer
(
WidgetParameters parms,
Var(Int32) x_v, // variable controled by the resizer
Var(Int32) y_v, // idem
Var(Int32) w_v // width of resizer (pixels)
) =
create_widget(
/* set childs positions */
(WidgetPositionToolBox ptb) |-> unique,
/* get size */
(One u) |-> (*w_v,*w_v),
/* redraw */
(WidgetDrawToolBox dtb) |->
draw_relief_area(dtb,1,rect(0,0,*w_v,*w_v),
*main_color_v(parms),
*light_color_v(parms),
*dark_color_v(parms)),
/* Duplicate */
(One u) |-> create_resizer(parms,x_v,y_v,w_v),
/* Change size */
(Int32 w, Int32 h) |-> alert,
/* event handling */
(WidgetEventToolBox etb, WidgetNormalEvent e) |->
if e is
{
mouse_gone then not_handled([]),
mouse_move(ks,x,y) then not_handled([]),
mouse_click(ks,mc,x,y) then
if mc is
{
left_down then
forget(capture_mouse(etb,captured_handler(x_v,y_v,
var((Int32)x),var((Int32)y))));
handled([]),
left_up then not_handled([]),
middle_down then not_handled([]),
middle_up then not_handled([]),
right_down then not_handled([]),
right_up then not_handled([]),
}
},
/* monitoring */
[ ]
).