desktop_example.anubis
5.03 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
An example using 'desktop.anubis'.
read tools/basis.anubis
read host_window.anubis
read widget.anubis
read tools.anubis
read image.anubis
read box.anubis
read table.anubis
read text.anubis
read button.anubis
read desktop.anubis
read menu_manager.anubis
read menus.anubis
read window.anubis
read tartan_generator.anubis
define HostImage
default_image
=
print("making a tartan\n");
to_host_image(make_tartan_image(150,100),1).
define HostImage
load_image
(
String name
) =
with path = anubis_directory+"library/examples/graphism/image_samples/"+name+".jpg",
if read_image_from_JPEG_file(path) is
{
cannot_open_file then print("Cannot find file '"+name+"'.\n"); default_image,
decompress_error then print("Cannot decompress file '"+name+"'.\n"); default_image,
ok(jpeg_image) then to_host_image(jpeg_image,1)
}.
define Widget
my_support
(
String jpg_filename
) =
with path = anubis_directory+"library/examples/graphism/image_samples/"+jpg_filename,
if image(path) is
{
failure then print("Cannot find file: "+path+"\n"); image(default_image),
success(w) then w
}.
define Widget
command_button
(
WidgetParameters parms,
WidgetParameters grey_parms,
WidgetSupport supp,
String text
) =
create_button
(
100,25,
push_down(grey_parms),
(WidgetEventToolBox etb) |-> command(supp) <-
if *command(supp) is
{
hide then show,
show then hide,
expose then should_not_happen(show),
delete then should_not_happen(show)
},
(One u) |-> if *command(supp) is hide
then center_text(grey_parms,text)
else center_text(parms,text),
[]
).
define MenuItem
command_menu
(
String name,
WidgetParameters parms,
WidgetSupport supp,
) =
item((One u) |-> if *command(supp) is show then "* "+name else " "+name,
(WidgetEventToolBox etb) |-> command(supp) <-
if *command(supp) is
{
hide then show,
show then hide,
expose then should_not_happen(show),
delete then should_not_happen(show)
}).
define List(MenuItem)
numbers_list
(
Var(MenuCommand) menu_command_v,
WidgetParameters parms,
Word32 n
) =
if n =< 0 then [] else
with action = (WidgetEventToolBox etb) |-> print("You choosed "+n+"\n");
menu_command_v <- clear,
if n (mod 10) = 0
then [separator,
item(integer_to_string(n),action)
. numbers_list(menu_command_v,parms,n-1)]
else [item(integer_to_string(n),action)
. numbers_list(menu_command_v,parms,n-1)].
define WidgetSupport
window_image
(
Word32 x, Word32 y,
Word32 w, Word32 h,
String name
) =
support(x,y,create_box(relief_rgb(rgb(128,128,128)),10,
window(rgb(128,128,128),var(w),var(h),
my_support(name+".jpg"),resizable,both,(One _) |-> rgb(0,0,0))),var(show)).
define Widget
exit_widget
(
SystemFont font
) =
button
(
(One u) |-> push_down(100,20,center_text("Exit",font,rgb(255,0,0)),rgb(200,200,200)),
(One u) |-> blocking,
(WidgetEventToolBox etb) |-> close_host_window(etb),
[ ]
).
global define One
desktop_example
(
List(String) args
) =
with font_name = "helvetica_bold_r_12",
if load_system_font(font_name) is
{
failure then print("Cannot load system font '"+font_name+"'.\n"),
success(font) then
if screen_size is (sw,sh) then
with exit = exit_widget(font),
with suppexit = if size(exit) is (ew,eh) then
support(0, sh-eh, exit, var(show)),
with support2 = support(150, 300, my_support("cows.jpg"), var(show)),
with support2a = support(150, 300, my_support("fingers.jpg"), var(show)),
with support2b = support(150, 300, my_support("farm.jpg"), var(show)),
with support3 = support(10, 100, my_support("mountain.jpg"),var(show)),
with support3a = support(10, 100, my_support("torrent.jpg"), var(show)),
with support4 = support(200, 200, my_support("flowers.jpg"), var(show)),
forget(
open_host_window(
//transient,
managed(resizable),
create_desktop(var(sw),var(sh),
color(rgb(100,200,0)),
(One u) |-> u,
[
suppexit,
support4,support3a,support3,
support2b,support2a,support2
],
var((DesktopCommand)none)),
0,0,
"Desktop Example (window 1)"))
}.