/
IUP.pm
567 lines (421 loc) · 11.2 KB
/
IUP.pm
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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
use NativeCall;
sub libname($lib) {
given $*VM{'config'}{'load_ext'} {
when '.so' { return "$lib.so" } # Linux
when '.bundle' { return "$lib.dylib" } # Mac OS
default { return $lib }
}
};
sub LOCAL_LIB() { return libname("IUP"); }
#
# Callback Return Values
#
constant IUP_IGNORE = -1;
constant IUP_DEFAULT = -2;
constant IUP_CLOSE = -3;
constant IUP_CONTINUE = -4;
#
# IupPopup and IupShowXY Parameter Values
#
constant IUP_CENTER = 0xFFFF; # 65535
constant IUP_LEFT = 0xFFFE; # 65534
constant IUP_RIGHT = 0xFFFD; # 65533
constant IUP_MOUSEPOS = 0xFFFC; # 65532
constant IUP_CURRENT = 0xFFFB; # 65531
constant IUP_CENTERPARENT = 0xFFFA; # 65530
constant IUP_TOP = IUP_LEFT;
constant IUP_BOTTOM = IUP_RIGHT;
#
# Color Space
#
constant IUP_RGB = 1;
constant IUP_RGBA = 2;
class IUP::Pixmap {
method load(@data) {
my $image = CArray[int8].new();
my $i = 0;
for @data -> $c {
if 0 > $c.Int > 255 {
say "Error loading Pixmap...";
exit();
}
$image[$i++] = $c.Int;
}
return $image;
}
}
class IUP::Callback is repr('CPointer') {}
class IUP::Handle is repr('CPointer') {
sub p6IupNewChildrenList(int32)
returns OpaquePointer is native(LOCAL_LIB) { ... };
sub p6IupAddChildToList(OpaquePointer, IUP::Handle, int32, int32)
is native(LOCAL_LIB) { ... };
sub p6IupFree(OpaquePointer)
is native(LOCAL_LIB) { ... };
### Callbacks
sub p6IupSetCallback_void(IUP::Handle, Str, &cb(--> int32))
returns IUP::Callback is native(LOCAL_LIB) { ... };
sub p6IupSetCallback_handle(IUP::Handle, Str, &cb(IUP::Handle --> int32))
returns IUP::Callback is native(LOCAL_LIB) { ... };
###
sub IupDestroy(IUP::Handle)
is native(LOCAL_LIB) { ... };
sub IupAppend(IUP::Handle $ih, IUP::Handle $child)
returns IUP::Handle is native(LOCAL_LIB) { ... };
sub IupInsert(IUP::Handle $ih, IUP::Handle $ref_child, IUP::Handle $child)
returns IUP::Handle is native(LOCAL_LIB) { ... };
sub IupGetChild(IUP::Handle, int32)
returns IUP::Handle is native(LOCAL_LIB) { ... };
sub IupGetNextChild(IUP::Handle $ih, IUP::Handle $child)
returns IUP::Handle is native(LOCAL_LIB) { ... };
sub IupGetParent(IUP::Handle)
returns IUP::Handle is native(LOCAL_LIB) { ... };
sub IupGetDialog(IUP::Handle)
returns int32 is native(LOCAL_LIB) { ... };
###
sub IupPopup(IUP::Handle, int32, int32)
returns int32 is native(LOCAL_LIB) { ... };
sub IupShow(IUP::Handle)
returns int32 is native(LOCAL_LIB) { ... };
sub IupShowXY(IUP::Handle, int32, int32)
returns int32 is native(LOCAL_LIB) { ... };
sub IupHide(IUP::Handle)
returns int32 is native(LOCAL_LIB) { ... };
sub IupMap(IUP::Handle)
returns int32 is native(LOCAL_LIB) { ... };
###
sub IupSetAttribute(IUP::Handle, Str, Str)
is native(LOCAL_LIB) { ... };
sub IupStoreAttribute(IUP::Handle, Str, Str)
is native(LOCAL_LIB) { ... };
sub IupSetAttributes(IUP::Handle, Str)
returns IUP::Handle is native(LOCAL_LIB) { ... };
sub IupGetAttribute(IUP::Handle, Str)
returns Str is native(LOCAL_LIB) { ... };
sub IupGetAttributes(IUP::Handle)
returns Str is native(LOCAL_LIB) { ... };
sub IupGetInt(IUP::Handle, Str)
returns int32 is native(LOCAL_LIB) { ... };
###
sub IupSetCallback(IUP::Handle, Str, IUP::Callback)
returns IUP::Callback is native(LOCAL_LIB) { ... };
###
sub IupSetHandle(Str, IUP::Handle)
returns IUP::Handle is native(LOCAL_LIB) { ... };
###
sub IupSetAttributeHandle(IUP::Handle $ih, Str $name, IUP::Handle $ih_named)
is native(LOCAL_LIB) { ... };
###
sub IupFill()
returns IUP::Handle is native(LOCAL_LIB) { ... };
sub p6IupVbox(IUP::Handle)
returns IUP::Handle is native(LOCAL_LIB) { ... };
sub IupVboxv(OpaquePointer)
returns IUP::Handle is native(LOCAL_LIB) { ... };
sub p6IupHbox(IUP::Handle)
returns IUP::Handle is native(LOCAL_LIB) { ... };
sub IupHboxv(OpaquePointer)
returns IUP::Handle is native(LOCAL_LIB) { ... };
###
sub IupFrame(IUP::Handle $child)
returns IUP::Handle is native(LOCAL_LIB) { ... };
###
sub IupImage(int32, int32, CArray[int8])
returns IUP::Handle is native(LOCAL_LIB) { ... };
sub IupImageRGB(int32, int32, CArray[int8])
returns IUP::Handle is native(LOCAL_LIB) { ... };
sub IupImageRGBA(int32, int32, CArray[int8])
returns IUP::Handle is native(LOCAL_LIB) { ... };
###
sub p6IupItem(Str, Str)
returns IUP::Handle is native(LOCAL_LIB) { ... };
sub IupSubmenu(Str, IUP::Handle)
returns IUP::Handle is native(LOCAL_LIB) { ... };
sub IupSeparator()
returns IUP::Handle is native(LOCAL_LIB) { ... };
sub p6IupMenu(IUP::Handle)
returns IUP::Handle is native(LOCAL_LIB) { ... };
sub IupMenuv(OpaquePointer)
returns IUP::Handle is native(LOCAL_LIB) { ... };
###
sub p6IupButton(Str $title, Str $action)
returns IUP::Handle is native(LOCAL_LIB) { ... };
sub IupCanvas(Str $action)
returns IUP::Handle is native(LOCAL_LIB) { ... };
sub IupDialog(IUP::Handle)
returns IUP::Handle is native(LOCAL_LIB) { ... };
sub IupLabel(Str)
returns IUP::Handle is native(LOCAL_LIB) { ... };
sub p6IupText(Str $action)
returns IUP::Handle is native(LOCAL_LIB) { ... };
###
sub IupMessage(Str $title, Str $message)
is native(LOCAL_LIB) { ... };
### METHODS ###
method destroy() {
IupDestroy(self);
}
method append(IUP::Handle $child) {
return IupAppend(self, $child);
}
method insert(IUP::Handle $ref_child, IUP::Handle $child) {
return IupInsert(self, $ref_child, $child);
}
method get_child($position) {
return IupGetChild(self, $position);
}
method get_next_child(IUP::Handle $child) {
return IupGetNextChild(self, $child);
}
method get_parent() {
return IupGetParent(self);
}
method get_dialog() {
return IupGetDialog(self);
}
###
method popup(Int $x, Int $y) {
return IupPopup(self, $x, $y);
}
multi method show() {
return IupShow(self);
}
multi method show(Int $x, Int $y) {
return IupShowXY(self, $x, $y);
}
method hide() {
return IupHide(self);
}
method map() {
return IupMap(self);
}
###
# http://www.tecgraf.puc-rio.br/iup/en/func/iupsetattribute.html
method set_attribute(Str $name, Str $value) {
#IupSetAttribute(self, $name, $value);
IupStoreAttribute(self, $name, $value);
}
# numeric keys
multi method set_attributes(*@attributes) {
my Str @tmp = ();
for @attributes.values -> $pair {
my ($name, $value) = $pair.kv;
push(@tmp, join("=", $name, "\"$value\""));
}
my $string = join(", ", @tmp).Str;
return IupSetAttributes(self, $string);
}
multi method set_attributes(*%attributes) {
my Str @tmp = ();
for %attributes.kv -> Str $name, $value {
push(@tmp, join("=", $name, "\"$value\""));
}
return IupSetAttributes(self, join(", ", @tmp).Str);
}
method get_attribute(Str $name) returns Str {
return IupGetAttribute(self, $name);
}
method get_attributes() returns Str {
return IupGetAttributes(self);
}
method get_int(Str $name) returns Int {
return IupGetInt(self, $name);
}
###
method set_callback(Str $name, $function) {
my @params = $function.signature.params;
given @params.elems {
when 0 { return p6IupSetCallback_void(self, $name.fmt("%s").Str, $function); }
when 1 { return p6IupSetCallback_handle(self, $name.fmt("%s").Str, $function); }
default { say "Error... no callback"; }
}
}
method set_callbacks(*%callbacks) {
for %callbacks.kv -> $name, $function {
self.set_callback($name, $function);
}
return self;
}
###
method set_handle(Str $name) {
return IupSetHandle($name, self);
}
###
method set_attribute_handle(Str $name, IUP::Handle $ih_named) {
IupSetAttributeHandle(self, $name, $ih_named);
}
###
method fill() {
return IupFill();
}
method vboxv(*@child) {
my $n = @child.elems;
if $n > 1 {
my $list = p6IupNewChildrenList($n);
my $pos = 0;
for @child -> $c {
p6IupAddChildToList($list, $c, $pos, $n);
$pos++;
}
my $result = IupVboxv($list);
p6IupFree($list);
return $result;
}
if $n == 1 {
return p6IupVbox(@child[0]);
}
}
method vbox(*@child) {
return self.vboxv(@child);
}
method hboxv(*@child) {
my $n = @child.elems;
if $n > 1 {
my $list = p6IupNewChildrenList($n);
my $pos = 0;
for @child -> $c {
p6IupAddChildToList($list, $c, $pos, $n);
$pos++;
}
my $result = IupHboxv($list);
p6IupFree($list);
return $result;
}
if $n == 1 {
return p6IupHbox(@child[0]);
}
}
method hbox(*@child) {
return self.hboxv(@child);
}
###
method frame($child) {
return IupFrame($child);
}
###
method image(
Int $width where $width > 0,
Int $height where $height > 0,
$pixels,
Int $color_space where 0..IUP_RGBA = 0) {
given $color_space {
when IUP_RGB { return IupImageRGB($width, $height, $pixels); }
when IUP_RGBA { return IupImageRGBA($width, $height, $pixels); }
default { return IupImage($width, $height, $pixels); }
}
}
###
method item(Str $title, Str $action) {
return p6IupItem($title, $action);
}
method submenu(Str $title, $child) {
return IupSubmenu($title, $child);
}
method separator() {
return IupSeparator();
}
method menuv(*@child) {
my $n = @child.elems;
if $n > 1 {
my $list = p6IupNewChildrenList($n);
my $pos = 0;
for @child -> $c {
p6IupAddChildToList($list, $c, $pos, $n);
$pos++;
}
my $result = IupMenuv($list);
p6IupFree($list);
return $result;
}
if $n == 1 {
return p6IupMenu(@child[0]);
}
}
method menu(*@child) {
return self.menuv(@child);
}
###
method button(Str $title, Str $action) {
return p6IupButton($title, $action);
}
method canvas(Str $action) {
return IupCanvas($action);
}
method dialog($child) {
return IupDialog($child);
}
method label(Str $str) {
return IupLabel($str);
}
method text(Str $action) {
return p6IupText($action);
}
###
method message(Str $title, Str $message) {
IupMessage($title, $message);
}
}
class IUP is IUP::Handle {
sub p6IupOpen(int32, CArray[Str])
returns int32 is native(LOCAL_LIB) { ... };
sub IupClose()
is native(LOCAL_LIB) { ... };
sub IupImageLibOpen()
is native(LOCAL_LIB) { ... };
sub IupMainLoop()
returns int32 is native(LOCAL_LIB) { ... };
#sub IupLoopStep()
#returns int32 is native(LOCAL_LIB) { ... };
#sub IupLoopStepWait()
#returns int32 is native(LOCAL_LIB) { ... };
#sub IupMainLoopLevel()
#returns int32 is native(LOCAL_LIB) { ... };
#sub IupFlush()
#is native(LOCAL_LIB) { ... };
#sub IupExitLoop()
#is native(LOCAL_LIB) { ... };
###
sub IupSetLanguage(Str)
is native(LOCAL_LIB) { ... };
sub IupGetLanguage()
returns Str is native(LOCAL_LIB) { ... };
### METHODS ###
method open(@argv) {
my $argc = @argv.elems;
my $arglist := CArray[Str].new();
my $i = 0;
for @argv -> $a {
$arglist[$i] = $a;
$i++;
}
return p6IupOpen($argc, $arglist);
}
method close() {
IupClose();
}
method image_lib_open() {
IupImageLibOpen();
}
method main_loop() {
return IupMainLoop();
}
#method loop_step(Bool $wait = False) {
#return $wait ?? IupLoopStepWait() !! IupLoopStep();
#}
#method main_loop_level() {
#return IupMainLoopLevel();
#}
#method flush() {
#IupFlush();
#}
#method exit_loop() {
#IupExitLoop();
#}
###
method set_language($language) {
IupSetLanguage($language);
}
method get_language() returns Str {
return IupGetLanguage();
}
}