-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathawbwman.lua
2583 lines (2121 loc) · 64.3 KB
/
awbwman.lua
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
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--
-- AWB Window Manager,
-- More advanced windows from the (awbwnd.lua) base
-- tracking ordering, creation / destruction /etc.
--
local awbwnd_invsh = [[
uniform sampler2D map_diffuse;
uniform float obj_opacity;
varying vec2 texco;
void main(){
vec4 col = texture2D(map_diffuse, texco);
gl_FragColor = vec4(1.0 - col.r,
1.0 - col.g,
1.0 - col.b,
col.a * obj_opacity);
}
]];
local awb_wtable = {};
local awb_col = {};
local awb_cfg = {
focus_locked = false,
fullscreen = nil,
topbar_sz = 16,
spawnx = 20,
spawny = 20,
animspeed = 10,
bgopa = 0.8,
dispw = VRESW,
disph = VRESH,
displays = {},
meta = {},
hidden = {},
global_input= {},
amap = {},
spawn_method = "mouse",
-- the whole "cell allocation + nextspawn" strategy should
-- be entirely reworked, this is just crazy
rootcell_w = 80,
rootcell_h = 60,
icnroot_startx = 0,
icnroot_starty = 30,
icnroot_stepx = -80,
icnroot_stepy = 80,
icnroot_maxy = VRESH - 100,
icnroot_x = VRESW - 100,
icnroot_y = 30,
tabicn_base = 32,
global_vol = 1.0
};
local function awbwman_findind(val, tbl)
if (tbl == nil) then
tbl = awb_wtable;
end
for i,v in ipairs(tbl) do
if (v == val) then
return i;
end
end
end
local function awbwman_updateorder()
for i,v in ipairs(awb_wtable) do
if (v.anchor ~= nil) then
order_image(v.anchor, i * 10);
end
end
end
local function awbwman_pushback(wnd)
if (awb_cfg.focus == wnd) then
awb_cfg.focus = nil;
end
local ind = awbwman_findind(wnd);
if (ind ~= nil and ind > 1) then
table.remove(awb_wtable, ind);
table.insert(awb_wtable, ind - 1, wnd);
end
wnd:inactive();
end
function awbwman_meta(lbl, active)
if (lbl ~= nil) then
if (lbl == "alt") then
awb_cfg.meta.alt = active;
elseif (lbl ~= "shift") then
return "";
else
awb_cfg.meta.shift = active;
if (active == false) then
awbwman_tablist_toggle(false);
end
end
end
local rkey = "";
if (awb_cfg.meta.shift) then
rkey = rkey .. "SHIFT";
end
if (awb_cfg.meta.alt) then
rkey = rkey .. "ALT";
end
return rkey;
end
local function drop_popup()
if (awb_cfg.popup_active ~= nil) then
awb_cfg.popup_active:destroy(awb_cfg.animspeed);
awb_cfg.popup_active = nil;
end
end
--
-- Will receive mouse input events and cursor while be
-- disabled while this state is active
--
function awbwman_mousefocus(wnd)
blend_image( mouse_cursor(), 0.0, awb_cfg.animspeed );
awb_cfg.mouse_focus = wnd;
end
local function awbwman_focus(wnd, nodrop)
if (nodrop == nil or nodrop == false) then
drop_popup();
end
if (awb_cfg.focus) then
if (awb_cfg.focus == wnd or awb_cfg.focus_locked) then
return;
end
-- only inactivate a window that hasn't been destroyed
if (awb_cfg.focus.inactive) then
awb_cfg.focus:inactive();
else
awb_cfg.focus = nil;
end
end
wnd:active();
awb_cfg.focus = wnd;
local tbl = table.remove(awb_wtable, awbwman_findind(wnd));
table.insert(awb_wtable, tbl);
awbwman_updateorder();
end
function awbwman_ispopup(vid)
return awb_cfg.popup_active and awb_cfg.popup_active.ref == vid;
end
function awbwman_fullscreen(wnd)
awbwman_focus(wnd);
if (awb_cfg.shadowimg ~= nil) then
expire_image(awb_cfg.shadowimg, awb_cfg.animspeed);
blend_image(awb_cfg.shadowimg, 0.0, awb_cfg.animspeed);
awb_cfg.shadowimg = nil;
end
blend_image(mouse_cursor(), 0.0, awb_cfg.animspeed);
-- hide root window (will cascade and hide everything else)
blend_image(awb_cfg.root.anchor, 0.0, awb_cfg.animspeed);
for k, v in ipairs(awb_wtable) do
blend_image(v.anchor, 0.0, awb_cfg.animspeed);
end
awb_cfg.mouse_focus = wnd;
awb_cfg.fullscreen = {};
local cprops = {
width = wnd.w,
height = wnd.h
};
local iprops = wnd:canvas_iprops();
local ar = iprops.width / iprops.height;
local wr = iprops.width / VRESW;
local hr = iprops.height / VRESH;
local dw, dh;
if (hr > wr) then
dw = VRESH * ar;
dh = VRESH;
else
dw = VRESW;
dh = VRESW / ar;
end
awb_cfg.focus:resize(dw, dh, true);
local xp = 0.5 * (VRESW - dw);
local yp = 0.5 * (VRESH - dh);
-- setup intermediate representation
local vid = null_surface(dw, dh);
image_sharestorage(awb_cfg.focus.canvas.vid, vid);
blend_image(vid, 1.0, awb_cfg.animspeed);
move_image(vid, xp, yp);
show_image(vid);
order_image(vid, max_current_image_order());
wnd.in_fullscreen = true;
if (wnd.on_fullscreen) then
wnd:on_fullscreen(vid, true);
end
-- store values for restoring
awb_cfg.fullscreen.vid = vid;
awb_cfg.fullscreen.props = cprops;
awb_cfg.fullscreen.wnd = wnd;
-- force focus lock for mouse input etc.
awb_cfg.focus_locked = true;
end
function awbwman_dropfullscreen()
-- reattach canvas to window
blend_image(mouse_cursor(), 1.0, awb_cfg.animspeed);
for k, v in ipairs(awb_wtable) do
blend_image(v.anchor, 1.0, awb_cfg.animspeed);
end
blend_image(awb_cfg.root.anchor, 1.0, awb_cfg.animspeed);
local w = awb_cfg.fullscreen.props.width;
local h = awb_cfg.fullscreen.props.height;
awb_cfg.focus:resize(w, h, true);
awb_cfg.fullscreen.wnd.in_fullscreen = nil;
if (awb_cfg.fullscreen.wnd.on_fullscreen) then
awb_cfg.fullscreen.wnd:on_fullscreen(vid, false);
end
delete_image(awb_cfg.fullscreen.vid);
awb_cfg.mouse_focus = nil;
awb_cfg.focus_locked = false;
awb_cfg.fullscreen = nil;
end
function awbwman_shadow_nonfocus()
if (awb_cfg.focus_locked == false and awb_cfg.focus == nil or
awb_cfg.modal or (awb_cfg.focus and awb_cfg.focus.in_fullscreen)) then
return;
end
awb_cfg.focus_locked = not awb_cfg.focus_locked;
if (awb_cfg.focus_locked) then
local order = image_surface_properties(awb_cfg.focus.anchor).order;
awb_cfg.shadowimg = color_surface(VRESW, VRESH, 0, 0, 0);
order_image(awb_cfg.shadowimg, order - 1);
blend_image(awb_cfg.shadowimg, 0.5, awb_cfg.animspeed);
else
expire_image(awb_cfg.shadowimg, awb_cfg.animspeed);
blend_image(awb_cfg.shadowimg, 0.0, awb_cfg.animspeed);
awb_cfg.shadowimg = nil;
end
end
local function awbwman_dereg(tbl, wcont)
for i=1,#tbl do
if (tbl[i] == wcont) then
table.remove(tbl, i);
local tag = awbwman_cursortag();
if (tag and tag.source == wcont) then
tag:drop();
end
return true;
end
end
return false;
end
local function awbwman_close(wcont, nodest)
drop_popup();
awbwman_dereg(awb_wtable, wcont);
awbwman_dereg(awb_cfg.global_input, wcont);
if (awb_cfg.focus == wcont) then
awb_cfg.focus = nil;
if (awb_cfg.focus_locked) then
awbwman_shadow_nonfocus();
end
if (#awb_wtable > 0) then
awbwman_focus(awb_wtable[#awb_wtable]);
end
end
end
local function awbwman_regwnd(wcont)
drop_popup();
table.insert(awb_wtable, wcont);
awbwman_focus(wcont);
end
local function lineobj(src, x1, y1, x2, y2)
local dx = x2 - x1 + 1;
local dy = y2 - y1 + 1;
local len = math.sqrt(dx * dx + dy * dy);
resize_image(src, len, 2);
show_image(src);
-- quickfix to bug in origo_offset with -1 > n < 1 degrees
local deg = math.deg( math.atan2(dy, dx) );
if ( deg > -1.0 and deg < 1.0) then
deg = deg < 0.0 and -1.0 or 1.0;
end
rotate_image(src, math.deg( math.atan2(dy, dx) ) );
move_image(src, x1 + (dx * 0.5), y1 + (dy * 0.5));
image_origo_offset(src, -1 * (0.5 * len), -0.5);
return line;
end
local function awbwnd_fling(wnd, fx, fy, bar)
local len = math.sqrt(fx * fx + fy * fy);
local wlen = 0.5 * math.sqrt(VRESW * VRESW + VRESH * VRESH);
local fact = 1 / (len / wlen);
local time = (10 * fact > 20) and 20 or (10 * fact);
-- just some magnification + stop against screen edges
local dx = wnd.x + fx * 8;
local dy = wnd.y + fy * 8;
dx = dx >= 0 and dx or 0;
dy = dy >= awb_cfg.topbar_sz and dy or awb_cfg.topbar_sz;
dx = (dx + wnd.w > VRESW) and (VRESW - wnd.w) or dx;
dy = (dy + wnd.h > VRESH) and (VRESH - wnd.h) or dy;
wnd:move(dx, dy, 10 * fact);
end
local function awbman_mhandlers(wnd, bar)
--
-- for the drag and drop case, "fling" the window
-- if shiftstate is set
--
bar.drag = function(self, vid, x, y)
reset_image_transform(self.parent.anchor);
local mx, my = mouse_xy();
awbwman_focus(self.parent);
if (awb_cfg.meta.shift) then
if (self.line_beg ~= nil) then
lineobj(self.lineobj, self.line_beg[1], self.line_beg[2], mx, my);
order_image(self.lineobj, ORDER_MOUSE - 1);
else
self.line_beg = {mx, my};
self.lineobj = color_surface(1, 1, 225, 225, 225);
end
else
props = image_surface_resolve_properties(self.parent.anchor);
self.line_beg = nil;
wnd:move(props.x + x, props.y + y);
end
end
bar.dblclick = function(self, vid, x, y)
if (wnd.resizable == false) then
return;
end
awbwman_focus(self.parent);
--
-- Note; change this into a real "maximize / fullscreen window" thing
-- where the top-bar becomes self-hiding, the own window bar is hidden
-- and any submenus added gets moved to the top-bar
--
if (self.maximized) then
wnd:move(self.oldx, self.oldy);
wnd:resize(self.oldw, self.oldh);
self.maximized = false;
else
self.maximized = true;
self.oldx = wnd.x;
self.oldy = wnd.y;
self.oldw = wnd.w;
self.oldh = wnd.h;
wnd:move(0, 20);
wnd:resize(VRESW, VRESH - 20, true);
end
end
bar.drop = function(self, vid, x, y)
awbwman_focus(self.parent);
if (self.line_beg) then
local mx, my = mouse_xy();
local dx = mx - self.line_beg[1];
local dy = my - self.line_beg[2];
local ang = math.deg( math.atan2(dy, dx) );
awbwnd_fling(wnd, dx, dy, ang);
self.line_beg = nil;
delete_image(self.lineobj);
self.lineobj = nil;
else
wnd:move(wnd.x, wnd.y);
end
end
bar.click = function(self, vid, x, y)
awbwman_focus(self.parent);
end
bar.name = "awbwnd_default_tbarh";
mouse_addlistener(bar, {"drag", "drop", "click", "dblclick"});
table.insert(wnd.handlers, bar);
end
local function awbwman_addcaption(bar, caption)
if (bar.update_caption == nil) then
bar.update_caption = awbwman_addcaption;
else
image_sharestorage(caption, bar.capvid);
local props = image_surface_properties(caption);
delete_image(caption);
resize_image(bar.capvid, props.width, props.height);
resize_image(bar.bgvid, 3 + props.width * 1.1, bar.size);
return;
end
bar.update_caption = awbwman_addcaption;
-- bar.noresize_fill = false;
local props = image_surface_properties(caption);
local bgsurf = fill_surface(10, 10, 230, 230, 230);
local icn = bar:add_icon("caption", "fill", bgsurf);
delete_image(bgsurf);
if (props.height > (bar.size - 2)) then
resize_image(caption, 0, bar.size);
props = image_surface_properties(caption);
end
icn.maxsz = 3 + props.width * 1.1;
resize_image(icn.vid, icn.maxsz, bar.size);
link_image(caption, icn.vid);
show_image(caption);
image_inherit_order(caption, true);
order_image(caption, 1);
image_mask_set(caption, MASK_UNPICKABLE);
image_mask_set(icn.vid, MASK_UNPICKABLE);
move_image(caption, 2, 2 + 0.5 * (bar.size - props.height));
image_clip_on(caption, CLIP_SHALLOW);
bar.capvid = caption;
bar.bgvid = icn.vid;
end
function awbwman_gather_scatter()
if (awb_cfg.modal or (awb_cfg.focus and awb_cfg.focus.in_fullscreen)) then
return;
end
drop_popup();
if (awb_cfg.focus_locked) then
awbwman_shadow_nonfocus();
end
if (awb_cfg.scattered) then
for ind, val in ipairs(awb_wtable) do
if (not val.minimized and val.pos_memory) then
move_image(val.anchor, val.pos_memory[1],
val.pos_memory[2], awb_cfg.animspeed);
blend_image(val.anchor, 1.0, awb_cfg.animspeed);
end
end
awb_cfg.scattered = nil;
else
for ind, val in ipairs(awb_wtable) do
if (not val.minimized) then
val.pos_memory = {val.x, val.y};
if (val.w == nil) then
val.w = 64;
val.h = 32;
end
if ( ( val.x + val.w * 0.5) < 0.5 * VRESW) then
move_image(val.anchor, -val.w, val.y, awb_cfg.animspeed);
blend_image(val.anchor, 1.0, 9);
blend_image(val.anchor, 0.0, 1);
else
move_image(val.anchor, VRESW, val.y, awb_cfg.animspeed);
blend_image(val.anchor, 1.0, 9);
blend_image(val.anchor, 0.0, 1);
end
end
end
awb_cfg.scattered = true;
end
end
--
-- desired spawning behavior might change (i.e.
-- best fit, random, centered, at cursor, incremental pos, ...)
--
local function awbwman_next_spawnpos(wnd)
local oldx = awb_cfg.spawnx;
local oldy = awb_cfg.spawny;
if (awb_cfg.spawn_method == "mouse") then
local x, y = mouse_xy();
x = x - 16;
if (wnd.canvasw + x > VRESW) then
x = VRESW - wnd.canvasw;
end
if (wnd.canvash + y > VRESH) then
y = VRESH - wnd.canvash;
end
if (y < awb_cfg.topbar_sz) then
y = awb_cfg.topbar_sz;
end
return x, y;
else
awb_cfg.spawnx = awb_cfg.spawnx + awb_cfg.topbar_sz;
awb_cfg.spawny = awb_cfg.spawny + awb_cfg.topbar_sz;
if (awb_cfg.spawnx > VRESW * 0.75) then
awb_cfg.spawnx = 0;
end
if (awb_cfg.spawny > VRESH * 0.75) then
awb_cfg.spawny = 0;
end
end
return oldx, oldy;
end
local function next_iconspawn()
local oldx = awb_cfg.icnroot_x;
local oldy = awb_cfg.icnroot_y;
awb_cfg.icnroot_y = awb_cfg.icnroot_y + awb_cfg.icnroot_stepy;
if (awb_cfg.icnroot_y > awb_cfg.icnroot_maxy) then
awb_cfg.icnroot_x = awb_cfg.icnroot_x + awb_cfg.icnroot_stepx;
awb_cfg.icnroot_y = awb_cfg.icnroot_starty;
end
return oldx, oldy;
end
function awbwman_iconwnd(caption, selfun, options)
local wnd = awbwman_spawn(caption, options);
wnd.kind = "icon";
awbwnd_iconview(wnd, 64, 48, 32, selfun,
fill_surface(32, 32,
awb_col.dialog_caret.r, awb_col.dialog_caret.g, awb_col.dialog_caret.b),
fill_surface(32, 32,
awb_col.dialog_sbar.r, awb_col.dialog_sbar.g, awb_col.dialog_sbar.b),
"r"
);
blend_image(wnd.canvas.vid, awb_cfg.bgopa);
return wnd;
end
local function wsetup(subkind, subdescr, caption, source, options)
if (options == nil) then
options = {};
end
if (type(options) ~= "table") then
print(debug.traceback(options));
end
options.fullscreen = true;
local wnd = awbwman_spawn(caption, options);
wnd.kind = subdescr;
wnd.ttbar_bg = awb_cfg.ttactiveres;
if (subkind ~= nil) then
local res = subkind(wnd, source, options);
return wnd, res;
end
return wnd;
end
function awbwman_customwnd(fun, caption, source, options)
return wsetup(fun, "custom", caption, source, options);
end
function awbwman_aplayer(caption, source, options)
return wsetup(awbwnd_aplayer, "aplayer", caption, source, options);
end
function awbwman_modelwnd(caption, source, options)
return wsetup(awbwnd_modelview, "3dmodel", caption, source, options);
end
function awbwman_mediawnd(caption, source, options)
return wsetup(awbwnd_media, "frameserver", caption, source, options);
end
function awbwman_imagewnd(caption, source, options)
return wsetup(awbwnd_media, "static", caption, source, options);
end
function awbwman_capwnd(caption, source, options)
return wsetup(awbwnd_media, "capture", caption, source, options);
end
function awbwman_cliwnd(caption, source, options)
return wsetup(awbwnd_cli, "cli", caption, source, options);
end
function awbwman_targetwnd(caption, options, capabilities)
if (options == nil) then
options = {};
end
options.fullscreen = true;
local wnd = awbwman_spawn(caption, options);
wnd.kind = "target";
wnd:add_bar("tt", awb_cfg.ttactiveres,
awb_cfg.ttinactvres, wnd.dir.t.rsize, wnd.dir.t.bsize);
return wnd, awbwnd_target(wnd, capabilities, options.factsrc);
end
function awbwman_activepopup()
return awb_cfg.popup_active ~= nil;
end
function awbwman_inputattach(dst, lblfun, options)
--
-- Override to fit current global settings / skin
--
options.bgr = awb_col.bgcolor.r;
options.bgg = awb_col.bgcolor.g;
options.bgb = awb_col.bgcolor.b;
local dlgc = awb_col.dialog_border;
options.borderr = dlgc.r;
options.borderg = dlgc.g;
options.borderb = dlgc.b;
options.borderw = 1;
options.caretr = awb_col.dialog_caret.r;
options.caretg = awb_col.dialog_caret.g;
options.caretb = awb_col.dialog_caret.b;
return awbwnd_subwin_input(dst, lblfun, options);
end
function awbwman_listwnd(caption, lineh, linespace,
colopts, selfun, renderfun, options)
if (options == nil) then
options = {};
end
local wnd = awbwman_spawn(caption, options);
wnd.kind = "list";
local opts = {
rowhicol = {awb_col.bgcolor.r * 1.2,
awb_col.bgcolor.g * 1.2, awb_col.bgcolor.b * 1.2},
double_single = options.double_single
};
awbwnd_listview(wnd, lineh, linespace, colopts, selfun, renderfun,
fill_surface(32, 32,
awb_col.dialog_caret.r, awb_col.dialog_caret.g, awb_col.dialog_caret.b),
fill_surface(32, 32,
awb_col.dialog_sbar.r, awb_col.dialog_sbar.g,awb_col.dialog_sbar.b),
fill_surface(32, 32,
awb_col.dialog_caret.r, awb_col.dialog_caret.g, awb_col.dialog_caret.b),
"r", opts);
blend_image(wnd.canvas.vid, awb_cfg.bgopa);
return wnd;
end
function awbwman_reqglobal(wnd)
local res = awbwman_dereg(awb_cfg.global_input, wnd);
if (not res and wnd.input ~= nil) then
table.insert(awb_cfg.global_input, wnd);
return true;
end
return false;
end
function awbwman_notice(msg)
end
function awbwman_alert(msg)
end
function awbwman_warning(msg)
end
--
-- Caption is a prerendered information string
-- Buttons is a itable of {caption, trigger}
-- Trying to close the window via other means uses buttons[cancelind] trigger
-- Modal prevents other actions until response has been provided
--
function awbwman_dialog(caption, buttons, options, modal)
if (options == nil) then
options = {};
end
if (not valid_vid(caption)) then
print(debug.traceback());
return;
end
if (awb_cfg.focus_locked) then
awbwman_shadow_nonfocus();
end
options.nocaption = true;
options.noicons = true;
options.noresize = true;
options.nominimize = true;
image_tracetag(caption, "awbwman_dialog(caption)");
local wnd = awbwman_spawn(caption, options);
image_tracetag(wnd.anchor, "awbwman_dialog.anchor");
wnd.dlg_caption = caption;
--
-- Size the new buttons after the biggest supplied one
--
local maxw = 0;
local maxh = 0;
for i, v in ipairs(buttons) do
local bprop = image_surface_properties(v.caption);
maxw = bprop.width > maxw and bprop.width or maxw;
maxh = bprop.height > maxh and bprop.height or maxh;
end
-- Fit dialog to size of contents
local capp = image_surface_properties(caption);
local cpyofs = 0;
local bwidth = maxw * 1.2;
local bheight = maxh * 1.1;
local wwidth = (bwidth * #buttons + 20) > capp.width and
(bwidth * #buttons + 20) or capp.width;
local wheight = bheight + capp.height + wnd.dir.t.size;
-- attach input field if requested
if (options.input) then
options.input.owner = caption;
options.input.noborder = false;
options.input.borderw = 1;
if (not options.input.w) then
options.input.w = 128;
end
wwidth = options.input.w > wwidth and options.input.w or wwidth;
wheight = wheight + 20;
cpyofs = -20;
wnd.inputfield = awbwman_inputattach(
function(self)
wnd.msg = self.msg;
end,
desktoplbl, options.input
);
wnd.input = function(self, tbl) wnd.inputfield:input(tbl); end
wnd.inputfield.accept = function(self)
buttons[options.input.accept].trigger(wnd);
wnd:destroy(awb_cfg.animspeed);
end
move_image(wnd.inputfield.anchor,
0.5 * (capp.width - options.input.w), capp.height + 5);
end
-- center
wnd:resize(wwidth * 1.2, wheight * 2);
if (not options.nocenter) then
move_image(wnd.anchor, 0.5 * (VRESW - wnd.w), 0.5 * (VRESH - wnd.h));
end
-- Link caption to window area, center (taking buttons into account)
link_image(caption, wnd.canvas.vid);
image_inherit_order(caption, true);
show_image(caption);
wnd.update_caption = function(self, capvid)
delete_image(self.dlg_caption);
self.dlg_caption = capvid;
local props = image_surface_properties(capvid);
local cprop = image_surface_properties(self.canvas.vid);
move_image(capvid, 0.5 * (cprop.width - props.width),
0.5 * ( (cprop.height - bheight - 10) - props.height));
image_mask_set(capvid, MASK_UNPICKABLE);
link_image(capvid, self.canvas.vid);
image_inherit_order(capvid, true);
order_image(capvid, 2);
show_image(capvid);
end
local wndprop = image_surface_properties(wnd.canvas.vid);
move_image(caption, 0.5 * (wndprop.width - capp.width),
0.5 * ((wndprop.height - bheight) - capp.height) + cpyofs );
-- Generate buttons and link lifetime to parent (but track
-- mouse handlers separately)
for i, v in ipairs(buttons) do
local dlgc = awb_col.dialog_border;
local bgc = awb_col.bgcolor;
local ccol = awb_col.dialog_caret;
local border = color_surface(bwidth, bheight, dlgc.r, dlgc.g, dlgc.b);
local button = color_surface(bwidth-2, bheight-2, bgc.r, bgc.g, bgc.b);
image_tracetag(border, "awbwnd_dialog.border(" .. tostring(i) .. ")");
image_tracetag(button, "awbwnd_dialog.button(" .. tostring(i) .. ")");
link_image(border, wnd.canvas.vid);
link_image(button, border);
link_image(v.caption, button);
image_inherit_order(button, true);
image_inherit_order(border, true);
image_inherit_order(v.caption, true);
order_image(button, 1);
order_image(v.caption, 2);
image_mask_set(border, MASK_UNPICKABLE);
image_mask_set(v.caption, MASK_UNPICKABLE);
image_mask_set(caption, MASK_UNPICKABLE);
blend_image(wnd.canvas.vid, awb_cfg.bgopa);
local bevent = {
own = function(self, vid) return vid == button; end,
click = function() if (v.trigger(wnd) == nil) then
wnd:destroy(awb_cfg.animspeed); end end,
over = function() image_color(button, ccol.r, ccol.g, ccol.b); end,
out = function() image_color(button, bgc.r, bgc.g, bgc.b); end,
};
local capp = image_surface_properties(v.caption);
show_image({button, border, v.caption});
move_image(button, 1, 1);
move_image(border, wndprop.width - i * (bwidth + 10), wndprop.height -
bheight - 10);
move_image(v.caption, 0.5 * (bwidth - capp.width),
0.5 * (bheight - (capp.height - 4) ));
bevent.name = "awbdialog_button(" .. tostring(i) .. ")";
mouse_addlistener(bevent, {"over", "out", "click"});
table.insert(wnd.handlers, bevent);
end
--
-- Add an invisible surface just beneath the dialog that grabs all input
--
if (modal) then
awb_cfg.modal = true;
local a = color_surface(VRESW, VRESH, 0, 0, 0);
blend_image(a, 0.5);
image_tracetag(a, "modal_block");
order_image(a, image_surface_properties(wnd.anchor).order - 1);
link_image(a, wnd.canvas.vid);
image_mask_clear(a, MASK_POSITION);
end
--
-- Need to be first in the on_destroy chain to manage a. modal dialogs,
-- b. windows that need some kind of confirmation before being destroyed
-- as there might be unsaved state that will be lost
-- c. the special "exclusive input" mode
--
wnd.on_destroy = function()
if (wnd.confirm_destroy ~= nil) then
awbwman_confirm_dialog(wnd.confirm_destroy,
wnd.wndid,
function()
wnd.confirm_destroy = nil;
wnd:destroy();
end);
return true;
end
if (modal) then
awb_cfg.modal = nil;
end
end
wnd:reposition();
return wnd;
end
function awbwman_cursortag()
return awb_cfg.cursor_tag;
end
function cursortag_drop()
resize_image(awb_cfg.cursor_tag.vid, 1, 1, awb_cfg.animspeed);
blend_image(awb_cfg.cursor_tag.vid, 0.0, awb_cfg.animspeed);
expire_image(awb_cfg.cursor_tag.vid, awb_cfg.animspeed);
awb_cfg.cursor_tag = nil;
end
function cursortag_hint(on)
local tvid = awb_cfg.cursor_tag.vid;
if (on) then
instant_image_transform(tvid);
local props = image_surface_initial_properties(tvid);
local cprops = image_surface_properties(mouse_cursor());
move_image(tvid, cprops.width - 5, cprops.height -5);
blend_image(tvid, 1.0, awb_cfg.animspeed);
image_transform_cycle(tvid, 1);
resize_image(tvid,props.width * 1.1, props.height * 1.1, awb_cfg.animspeed);
resize_image(tvid,props.width * 0.9, props.height * 0.9, awb_cfg.animspeed);
else
image_transform_cycle(awb_cfg.cursor_tag.vid, 0);
instant_image_transform(awb_cfg.cursor_tag.vid);
blend_image(awb_cfg.cursor_tag.vid, 0.3, awb_cfg.animspeed);
end
end
function awbwman_minimize_drop(wnd)
awbwman_dereg(awb_cfg.hidden, wnd);
end
function awbwman_restore(ind)
drop_popup();
if (type(ind) == "table") then
ind = awbwman_findind(ind, awb_cfg.hidden);
if (ind == nil) then
return;
end
end
local wnd = awb_cfg.hidden[ind];
wnd.minimized = false;
table.remove(awb_cfg.hidden, ind);
table.insert(awb_wtable, wnd);
awbwman_focus(wnd);
wnd:show();
end
--
-- Similar to a regular spawn, but will always have order group 0,
-- canvas click only sets group etc. somewhat simpler than the
-- awbicon window type as we don't care about resize or rapidly
-- changing dynamic sets of lots of icons
--
function awbwman_rootwnd()
local wcont = awbwnd_create({
x = 0,
y = 0,
w = VRESW,
h = VRESH
});
wcont.kind = "root";
local r = awb_col.bgcolor.r;
local g = awb_col.bgcolor.g;