resizer.anubis
4.37 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
The Anubis Project.
A Widget System (4th version).
The 'resizer' widget.
Copyright (c) Alain Proute' 2005.
Authors: Alain Proute'
The resizer is just a small rectangle with may capture the mouse. When the mouse is
captured, moving the mouse updates the given two variables accordingly,
i.e. displacements of the mouse are added to the variables.
read tools/basis.anubis
read widget.anubis
public define Widget
resizer
(
Int32 width, // width of resizer
Int32 height, // height of resizer
Var(Int32) x_v,
Var(Int32) y_v,
One -> Int32 x_min, // gives the minimal legal value for 'x_v'
One -> Int32 y_min, // gives the minimal legal value for 'y_v'
One -> Int32 x_max, // gives the maximal legal value for 'x_v'
One -> Int32 y_max, // gives the maximal legal value for 'y_v'
RGB color
).
For example, if you left click the resizer and move the mouse down right by (10,20)
pixels, the value of 'x_v' is incremented by 10, and the value of 'y_v' is incremented
by 20.
--- That's all for the public part ! --------------------------------------------------
read tools.anubis
define WidgetDrawToolBox -> One
draw_method
(
Int32 width,
Int32 height,
RGB color
) =
(WidgetDrawToolBox dtb) |->
draw_relief_area(dtb,2,rect(0,0,width,height),color,lighten(color),darken(color)).
define (WidgetEventToolBox,WidgetEvent) -> WidgetAnswer
event_handler
(
Var(Int32) x_v,
Var(Int32) y_v,
One -> Int32 x_min,
One -> Int32 y_min,
One -> Int32 x_max,
One -> Int32 y_max,
Var(Int32) initial_mx_v, // position of mouse on resizer when the mouse is captured
Var(Int32) initial_my_v,
Var(One) capture_ticket
) =
(WidgetEventToolBox etb, WidgetEvent e) |->
if e is
{
mouse_move(ks,x,y) then ignored,
mouse_click(ks,mc,x,y) then
if mc is left_down
then
(
initial_mx_v <- x;
initial_my_v <- y;
want_to_capture_mouse(capture_ticket,compress,area(etb)([]))
)
else ignored,
mouse_wheel(ks,delta,mx,my) then ignored,
mouse_gone then ignored,
captured_mouse_move(f) then
if f(capture_ticket,etb) is
{
failure then ignored,
success(p) then if p is (mx,my) then
x_v <- max(x_min(unique),min(x_max(unique),*x_v + (mx - *initial_mx_v)));
y_v <- max(y_min(unique),min(y_max(unique),*y_v + (my - *initial_my_v)));
resized
},
captured_mouse_liberated(f) then ignored,
key_down(f) then ignored,
keyboard_recaptured(f) then ignored,
changed(l) then ignored,
could_drop(_,_,_,_) then ignored,
want_to_drop(_,_,_) then ignored
}.
public define Widget
resizer
(
Int32 width, // width of resizer
Int32 height, // height of resizer
Var(Int32) x_v,
Var(Int32) y_v,
One -> Int32 x_min, // gives the minimal legal value for 'x_v'
One -> Int32 y_min, // gives the minimal legal value for 'y_v'
One -> Int32 x_max, // gives the maximal legal value for 'x_v'
One -> Int32 y_max, // gives the maximal legal value for 'y_v'
RGB color
) =
with initial_mx_v = var((Int32)0),
initial_my_v = var((Int32)0),
capture_ticket = var((One)unique),
create_widget
(
(One u) |-> (width,height),
draw_method(width,height,color),
event_handler(x_v,y_v,
x_min,y_min,x_max,y_max,
initial_mx_v,initial_my_v,
capture_ticket),
(One u) |-> []
).