-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmwindows.old
3677 lines (2984 loc) · 99.3 KB
/
mwindows.old
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
unit mwindows;
{$mode objfpc}{$H+}
//------------------------------------------------------------------------------
// The window manager unit for use with the retromachine
// v.0.03 - 20180127
// Piotr Kardasz [email protected]
// gpl v. 2.0 or higher
// alpha code quality
//------------------------------------------------------------------------------
interface
uses
Classes, SysUtils, threads, retro, icons, retromalina, platform, vc4;
const mapbase=mainscreen+$800000;
framewidth=4;
moved:integer=-10;
wt:int64=0;
type TWindow=class;
TDecoration=class;
TWidget=class;
TButton=class;
TIcon=class;
TMenuItem=class;
TMenu=class;
TStatusBar=class;
TWindows= class(TThread)
private
protected
procedure Execute; override;
public
Constructor Create(CreateSuspended : boolean);
end;
//------------------------------------------------------------------------------
// Basic window class
//------------------------------------------------------------------------------
type TWindow=class(TObject)
handle:TWindow;
prev,next:TWindow; // 2-way list
x,y:integer; // position on screen
l,h:integer; // dmensions on screen
vx,vy:integer; // visible upper left
vcl,vch:integer; // virtual canvas dimensions
vcx,vcy:integer; // virtual canvas x,y
mx,my,mk:integer; // mouse events
wl,wh:integer; // windows l,h
tcx,tcy:integer; // text cursor
bg:integer; // background color
tc:integer; // text color
canvas:pointer; // graphic memory
decoration:TDecoration; // the decoration or nil if none
visible:boolean; // visible or hidden
resizable:boolean; // if true windows not resizable
movable:boolean; // if true windows not movable by mouse
redraw:boolean; // set true by redrawing process after redraw
active:boolean; // if false, window doesn't need redrawing
title:string; // window title
buttons:TWidget; // widget chain start
icons:TIcon;
menu:TMenu;
statusbar:TStatusbar;
mstate:integer; // mouse position state
dclick:boolean;
needclose:boolean;
activey:integer;
selected:boolean;
virtualcanvas:boolean;
a32bit:boolean;
// The constructor. al, ah - graphic canvas dimensions
// atitle - title to set, if '' then windows will have no decoration
constructor create (al,ah:integer; atitle:string);
destructor destroy; override;
procedure draw(dest:integer); // redraw a window
procedure move(ax,ay,al,ah,avx,avy:integer); // move and resize. ax,ay - position on screen
// al, ah - visible dimensions without decoration
// avy, avy - upper left visible canvas pixel
function checkmouse:TWindow; // check and react to mouse events
procedure resize(nwl,nwh:integer); // resize the canvas
procedure select; // select the window and place it on top
// graphic methods
procedure cls(c:integer); // clear window and fill with color
procedure putpixel(ax,ay,color:integer); inline; // put a pixel to window
function getpixel(ax,ay:integer):integer; inline; // get a pixel from window
procedure putchar(ax,ay:integer;ch:char;col:integer); // put a 8x16 char on window
procedure putchar8(ax,ay:integer;ch:char;col:integer); // put a 8x16 char on window
procedure putcharz(ax,ay:integer;ch:char;col,xz,yz:integer); // put a zoomed char, xz,yz - zoom
procedure outtextxy8(ax,ay:integer; t:string;c:integer); // output a string from x,y position
procedure outtextxy(ax,ay:integer; t:string;c:integer); // output a string from x,y position
procedure outtextxyz(ax,ay:integer; t:string;c,xz,yz:integer); // output a zoomed string
procedure box(ax,ay,al,ah,c:integer); // draw a filled box
procedure print(line:string); // print a string at the text cursor
procedure println(line:string); // print a string and add a new line
procedure scrollup;
// TODO: add the rest of graphic procedures from retromalina unit
end;
type TWindow32=class(TObject)
handle:TWindow32;
prev,next:TWindow32; // 2-way list
x,y:integer; // position on screen
l,h:integer; // dmensions on screen
vx,vy:integer; // visible upper left
vcl,vch:integer; // virtual canvas dimensions
vcx,vcy:integer; // virtual canvas x,y
mx,my,mk:integer; // mouse events
wl,wh:integer; // windows l,h
tcx,tcy:integer; // text cursor
bg:integer; // background color
tc:integer; // text color
canvas:pointer; // graphic memory
decoration:TDecoration; // the decoration or nil if none
visible:boolean; // visible or hidden
resizable:boolean; // if true windows not resizable
movable:boolean; // if true windows not movable by mouse
redraw:boolean; // set true by redrawing process after redraw
active:boolean; // if false, window doesn't need redrawing
title:string; // window title
buttons:TWidget; // widget chain start
icons:TIcon;
menu:TMenu;
statusbar:TStatusbar;
mstate:integer; // mouse position state
dclick:boolean;
needclose:boolean;
activey:integer;
selected:boolean;
virtualcanvas:boolean;
a32bit:boolean;
// The constructor. al, ah - graphic canvas dimensions
// atitle - title to set, if '' then windows will have no decoration
constructor create (al,ah:integer; atitle:string);
destructor destroy; override;
procedure draw(dest:integer); // redraw a window
procedure move(ax,ay,al,ah,avx,avy:integer); // move and resize. ax,ay - position on screen
// al, ah - visible dimensions without decoration
// avy, avy - upper left visible canvas pixel
function checkmouse:TWindow; // check and react to mouse events
procedure resize(nwl,nwh:integer); // resize the canvas
procedure select; // select the window and place it on top
// graphic methods
procedure cls(c:integer); // clear window and fill with color
procedure putpixel(ax,ay,color:integer); inline; // put a pixel to window
function getpixel(ax,ay:integer):integer; inline; // get a pixel from window
procedure putchar(ax,ay:integer;ch:char;col:integer); // put a 8x16 char on window
procedure putchar8(ax,ay:integer;ch:char;col:integer); // put a 8x16 char on window
procedure putcharz(ax,ay:integer;ch:char;col,xz,yz:integer); // put a zoomed char, xz,yz - zoom
procedure outtextxy8(ax,ay:integer; t:string;c:integer); // output a string from x,y position
procedure outtextxy(ax,ay:integer; t:string;c:integer); // output a string from x,y position
procedure outtextxyz(ax,ay:integer; t:string;c,xz,yz:integer); // output a zoomed string
procedure box(ax,ay,al,ah,c:integer); // draw a filled box
procedure print(line:string); // print a string at the text cursor
procedure println(line:string); // print a string and add a new line
// TODO: add the rest of graphic procedures from retromalina unit
end;
//------------------------------------------------------------------------------
// Panel. A special window displayed at the bottom of the screen.
// A place for start button, minimized windows, speedbuttons etc
// Always on top
//------------------------------------------------------------------------------
Tpanel=class(TWindow)
constructor create;
end;
//------------------------------------------------------------------------------
// File selector. A window with methods for directory display and file select.
//------------------------------------------------------------------------------
type Tfileselector=class(Twindow)
done:boolean;
currentdir:string;
currentdir2:string;
filename:string;
sr:TSearchRec;
s:string;
filenames:array[0..1000,0..2] of string;
ilf,ild:integer;
sel:integer;
selstart:integer;
drivetable:array['A'..'Z'] of boolean;
dir:string;
constructor create(adir:string);
procedure dirlist;
procedure sort;
procedure checkselected;
procedure selectnext;
// TODO: remove the mess. Add "Selectnext" method
end;
//------------------------------------------------------------------------------
// Window decoration
//------------------------------------------------------------------------------
type TDecoration=class(TObject)
title:pointer;
parent:TWindow;
hscroll,vscroll,menu,status,up,down,close:boolean;
leftc,rightc,upc,downc:pointer;
ll,lh,rl,rh,ul,uh,dl,dh:integer;
constructor create;
destructor destroy;
procedure draw;
end;
type TWidget=class(TObject)
next,prev:TWidget;
granny:TWindow;
procedure draw;
procedure checkall;
procedure setparent(parent:TWidget);
procedure setdesc(desc:TWidget);
function gofirst:TWidget;
end;
//------------------------------------------------------------------------------
// Button
//------------------------------------------------------------------------------
type TButton=class(TWidget)
x,y:integer; // upper left pixel position on window
l,h:integer; // dimensions
c1,c2:integer; // basic background color, text color
clicked:integer; // mouse event
s:string; // title
fsx,fsy:integer; // font size x,y
value:integer;
canvas:pointer;
visible,highlighted,selected,radiobutton,selectable,down:boolean;
radiogroup:integer;
constructor create(ax,ay,al,ah,ac1,ac2:integer;aname:string;g:TWindow);
destructor destroy; override;
function append(ax,ay,al,ah,ac1,ac2:integer;aname:string):TButton;
function checkmouse:boolean;
procedure highlight;
procedure unhighlight;
procedure show;
procedure hide;
procedure select;
procedure unselect;
procedure draw;
function findselected:TButton;
procedure setvalue(v:integer);
procedure checkall;
procedure box(ax,ay,al,ah,c:integer);
end;
type TIcon=class(TObject)
x,y,l,h:integer;
mx,my:integer;
size:integer;
title:string;
granny:TWindow;
g2:TMenuItem;
icon16:TIcon16;
icon32:TIcon32;
icon48:TIcon48;
highlighted:boolean;
bg:array[0..12287] of byte;
next,prev:TIcon;
clicked,dblclicked:boolean;
constructor create(atitle:string;g:TWindow);
procedure draw;
procedure move(ax,ay:integer);
function append(atitle:string):TIcon;
function checkmouse:boolean;
procedure highlight;
procedure unhighlight;
procedure arrange;
procedure checkall;
end;
//
type TMenuItem=class(TObject)
title:string;
icon:TIcon;
next,prev,sub:TMenuItem;
x,y,l:integer;
level:integer;
visible:boolean;
selected:boolean;
highlighted:boolean;
clicked:boolean;
horizontal:boolean;
granny:TWindow;
constructor create(atitle:string; w:twindow);
function append(atitle:string):TMenuItem;
function addsub(atitle:string):TMenuItem;
procedure draw(dest:integer);
function checkmouse:boolean;
end;
TMenu=class (TObject)
item:TMenuItem;
granny:TWindow;
horizontal:boolean;
constructor create(g:TWindow);
function append(atitle:string):TMenuItem;
procedure checkall(dest:integer);
end;
TStatusBar=class (TObject)
height:integer;
canvas:pointer;
end;
type PRectangle=^TRectangle;
trectangle=record
x1,y1,x2,y2,handle:integer;
next,prev:PRectangle
end;
var background:TWindow=nil; // A mother of all windows except the panel
background32:TWindow32=nil; // 32bit version
panel:TPanel=nil; // The panel
vertex:array[0..1023,0..2] of integer; // x, y, handle
rectangles:array[0..4096,0..4] of integer; //x, y, l, h, handle
xtable, ytable:array[0..63] of integer;
lastchecked:TWindow;
Arectangle:TRectangle;
// Theme colors.
activecolor:integer=120;
inactivecolor:integer=13;
activetextcolor:integer=15;
inactivetextcolor:integer=0;
borderwidth:integer=6;
scrollwidth:integer=16;
borderdelta:integer=2;
scrollcolor:integer=12;
activescrollcolor:integer=124;
titleheight:integer=24;
menuheight:integer=24;
menucolor:integer=142;
// A temporary icon. TODO: Icon class and methods
icon:array[0..15,0..15] of byte;
semaphore:boolean=false;
//------------------------------------------------------------------------------
// Helper procedures
//------------------------------------------------------------------------------
procedure gouttextxy(g:pointer;x,y:integer; t:string;c:integer);
procedure gputpixel(g:pointer; x,y,color:integer); inline;
procedure gpouttextxy(g:pointer;x,y:integer; t:string;c,pitch:integer);
procedure gpputpixel(g:pointer; x,y,color,pitch:integer); inline;
procedure makeicon;
procedure getrectanglelist;
implementation
uses blitter;
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// Main window thread
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
constructor TWindows.Create(CreateSuspended : boolean);
begin
FreeOnTerminate := True;
inherited Create(CreateSuspended);
end;
procedure TWindows.Execute;
var scr2,scr:integer;
wh:TWindow;
t:int64;
q:integer=0;
const dblinvalid=0;
begin
Arectangle.handle:=-1;
q:=0;
scr:=mainscreen+$800000;
ThreadSetAffinity(ThreadGetCurrent,4);
threadsleep(1);
cls(100);
repeat
inc(q);
// getrectanglelist;
t:=gettime;
lastchecked:=background.checkmouse;
getrectanglelist;
windowsdone:=false;
wh:=background;
repeat
// if scr=mainscreen+$800000 then scr2:=integer(p2) else scr2:=integer(p2+(xres+64)*(yres));
wh.draw(scr) ;
wh:=wh.next;
until wh=nil;
panel.draw(scr);
windowsdone:=true;
wt:=gettime-t;
repeat threadsleep(1) until screenaddr<>scr;
scr:=screenaddr;
until terminated;
end;
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// Window methods
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// TWindow constructor.
// Parameters:
// wl: window canvas length
// wh: window canvas height (the canvas can be resized later)
// title - if empt, windows will have no decoration
//------------------------------------------------------------------------------
constructor TWindow.create (al,ah:integer; atitle:string);
var who:TWindow;
i,j:integer;
begin
inherited create;
semaphore:=true;
mstate:=0;
dclick:=false;
needclose:=false;
if background<>nil then // there ia s background so create a normal window
begin
who:=background;
while who.next<>nil do who:=who.next;
makeicon; // Temporary icon, todo: icon class
handle:=self;
x:=0; // initialize the fields
y:=0;
mx:=-1;
my:=-1;
mk:=0;
vx:=0;
vy:=0;
vcx:=0;
vcy:=0;
l:=0;
h:=0;
bg:=0;
wl:=al;
wh:=ah;
vcl:=0;
vch:=0;
tcx:=0;
tcy:=0;
tc:=15;
virtualcanvas:=false;
buttons:=nil;
icons:=nil;
next:=nil;
visible:=false;
resizable:=true;
prev:=who;
canvas:=getmem(wl*wh); // get a memory for graphics. 8-bit only in this version
for i:=0 to wl*wh-1 do poke(cardinal(canvas)+i,0); // clear the graphic memory
title:=atitle;
if atitle<>'' then // create a decoration
begin
decoration:=TDecoration.create;
decoration.title:=getmem(wl*titleheight);
decoration.hscroll:=true;
decoration.vscroll:=true;
decoration.up:=true;
decoration.down:=true;
decoration.close:=true;
activey:=0;
end
else begin decoration:=nil; activey:=24; end;
who.next:=self;
end
else // no background, create one
begin
handle:=self;
prev:=nil;
next:=nil;
x:=0;
y:=0; // position on screen
l:=al;
h:=ah; // dimensions on screen
vx:=0;
vy:=0; // visible upper left
vcx:=0;
vcy:=0;
wl:=al;
wh:=ah; // windows l,h
vcl:=0;
vch:=0;
virtualcanvas:=false;
bg:=132; // todo: get color from a theme
buttons:=nil;
icons:=nil;
canvas:=pointer(backgroundaddr); // graphic memory address
// The window manager works at the top
// of the retromachine. The background window
// replaces the retromachine background with
// graphic memory a the same address, so
// non-windowed retromachine programs will not
// notice any difference when running on
// the window manager
decoration:=nil; //+48
visible:=true;
redraw:=true;
mx:=-1;
my:=-1;
decoration:=nil;
title:='';
end;
selected:=true;
semaphore:=false;
//moved:=0;
end;
//------------------------------------------------------------------------------
// TWindow destructor
//------------------------------------------------------------------------------
destructor TWindow.destroy;
var i,j:integer;
begin
visible:=false;
prev.next:=next;
if next<>nil then next.prev:=prev;
if canvas<>nil then freemem(canvas);
if decoration<>nil then
begin
decoration.destroy
end;
end;
//------------------------------------------------------------------------------
// TWindow draw method
// Draw a window on compositing canvas
// dest - address of the canvas
//------------------------------------------------------------------------------
procedure TWindow.draw(dest:integer);
var dt,dg,dh,dx,dy,dx2,dy2,dl,dsh,dsv,i,j,c,ct,a,dm:integer;
dxr,dyr:integer;
wt1:int64;
q1,q2,q3:integer;
hsw,vsh,hsp,vsp:integer;
rectangle:PRectangle;
begin
redraw:=false; // tell the other procedures that the drawing is on its way
if decoration=nil then // adjust window dimensions
begin
dg:=0;
dh:=0;
dt:=0;
dl:=0;
dsh:=0;
dsv:=0;
hsw:=0;
vsh:=0;
hsp:=0;
vsp:=0;
end
else
begin
dt:=titleheight;
dl:=borderwidth;
dg:=borderwidth;
dh:=borderwidth;
if decoration.hscroll then dsh:=scrollwidth else dsh:=0;
if decoration.vscroll then dsv:=scrollwidth else dsv:=0;
if decoration.menu then dm:=menuheight else dm:=0;
if not virtualcanvas then
begin
hsw:=round((l/wl)*l); if hsw<11 then hsw:=10;
vsh:=round((h/wh)*h); if vsh<11 then vsh:=10;
hsp:=round((vx/(wl-l))*(l-hsw));
vsp:=round((vy/(wh-h))*(h-vsh));
end
else
begin
hsw:=round((l/vcl)*l); if hsw<11 then hsw:=10;
vsh:=round((h/vch)*h); if vsh<11 then vsh:=10;
hsp:=round((vcx/(vcl-l))*(l-hsw));
vsp:=round((vcy/(vch-h))*(h-vsh));
end;
end;
//if self=background then begin fastmove(mainscreen,dest,xres*yres); end
//else
begin
if buttons<>nil then buttons.draw; // update the wigdets
// instead of full window, draw rectangles
if self is tpanel then blit8(integer(canvas),vx,vy,dest,x,y,l,h,wl,xres)
else begin
rectangle:=@arectangle;
repeat
// wt1:=gettime;
repeat rectangle:=rectangle^.next until (rectangle^.handle=integer(self.handle)) or (rectangle^.next=nil);
// wt1:=gettime-wt1;
// retromalina.box(0,0,100,32,0);retromalina.outtextxy(0,0,inttostr(wt1),15);
if rectangle^.handle=integer(self.handle) then
begin
dxr:=rectangle^.x1-x; // todo if dxr<0, correct the rectangle
dyr:=rectangle^.y1-y;
blit8(integer(canvas),vx+dxr,vy+dyr,dest,rectangle^.x1,rectangle^.y1, rectangle^.x2-rectangle^.x1+1,rectangle^.y2-rectangle^.y1+1,wl,xres);
end;
until rectangle^.next=nil;
end;
// blit8(integer(canvas),vx,vy,dest,x,y,l,h,wl,xres); // then blit the window to the canvas
if next<>nil then // and draw the decoration
begin
selected:=false;
c:=inactivecolor;
ct:=inactivetextcolor;
a:=0;
end
else
begin
selected:=true;
c:=activecolor;
ct:=activetextcolor;
a:=32
end;
if decoration<>nil then
begin
if (mousex>(x+l+dsv-60)) and (mousey>(y-titleheight-dm+4)) and (mousex<(x+l+dsv-44)) and (mousey<(y-4)-dm) then q1:=122 else q1:=0;
if (mousex>(x+l+dsv-40)) and (mousey>(y-titleheight-dm+4)) and (mousex<(x+l+dsv-24)) and (mousey<(y-4-dm)) then q2:=122 else q2:=0;
if (mousex>(x+l+dsv-20)) and (mousey>(y-titleheight-dm+4)) and (mousex<(x+l+dsv-4)) and (mousey<(y-4-dm)) then begin q3:=32; a:=32; end else q3:=0;
if selected and (mx>(l+dsv-20)) and (my>(-titleheight-dm+4)) and (mx<(l+dsv-4)) and (my<(-4-dm)) and (mousek=1) then needclose:=true;
fill2d(dest,x-dl,y-dt-dm-dl,l+dl+dsv,dl,xres,c+borderdelta); //upper border
fill2d(dest,x-dl,y-dt-dm,l+dl+dsv,dt,xres,c); //title bar
fill2d(dest,x-dl,y-dm,l+dl+dsv,dm,xres,menucolor); //menu
if (decoration.menu) and (menu<>nil) then menu.checkall(dest);
fill2d(dest,x-dl,y-dt-dl-dm,dl,h+dt+dl+dsh+dh+dm,xres,c+borderdelta); //left border
fill2d(dest,x-dl,y+h+dsh,l+dl+dg+dsv,dh,xres,c+borderdelta); //lower border
fill2d(dest,x+l+dsv,y-dt-dl-dm,dg,h+dt+dl+dsh+dl+dm,xres,c+borderdelta);//right border
fill2d(dest,x,y+h,l,dsh,xres,scrollcolor); //horizontal scroll bar
fill2d(dest,x+3+hsp,y+h+3,hsw-6,dsh-6,xres,activescrollcolor); //horizontal scroll bar active part
fill2d(dest,x+l,y,dsv,h,xres,scrollcolor); //vertical scroll bar
fill2d(dest,x+l+3,y+3+vsp,dsv-6,vsh-6,xres,activescrollcolor); //vertical scroll bar active part
fill2d(dest,x+l,y+h,dsv,dsh,xres,c); //down right corner
gouttextxy(pointer(dest),x+32,y-titleheight-dm+4,title,ct);
for i:=0 to 15 do for j:=0 to 15 do if down_icon[i+16*j]>0 then gputpixel(pointer(dest),x+l+dsv-60+i,y-titleheight-dm+4+j,down_icon[i+16*j]);
if q1<>0 then
for i:=0 to 15 do
for j:=0 to 15 do
if down_icon[i+16*j]>0 then gputpixel(pointer(dest),x+l+dsv-60+i,y-titleheight-dm+4+j,down_icon[i+16*j])
else gputpixel(pointer(dest),x+l+dsv-60+i,y-titleheight-dm+4+j,q1);
if q2<>0 then
for i:=0 to 15 do
for j:=0 to 15 do
if up_icon[i+16*j]>0 then gputpixel(pointer(dest),x+l+dsv-40+i,y-titleheight-dm+4+j,up_icon[i+16*j])
else gputpixel(pointer(dest),x+l+dsv-40+i,y-titleheight-dm+4+j,q2)
else for i:=0 to 15 do for j:=0 to 15 do if up_icon[i+16*j]>0 then gputpixel(pointer(dest),x+l+dsv-40+i,y-titleheight-dm+4+j,up_icon[i+16*j]);
for i:=0 to 15 do for j:=0 to 15 do if close_icon[i+16*j]>0 then gputpixel(pointer(dest),x+l+dsv-20+i,y-titleheight-dm+4+j,a+q3+close_icon[i+16*j]);
for i:=0 to 15 do for j:=0 to 15 do if icon[i,j]>0 then gputpixel(pointer(dest),x+4+i,y-titleheight-dm+4+j,icon[i,j]);
end;
end;
redraw:=true;
wt1:=gettime-wt;
end;
//------------------------------------------------------------------------------
// TWindow move method
// move and resize the window
// ax,ay - new position on screen if >-2048
// al,ah - new visible dimensions without decoration if >0
// avy,avy - new upper left visible canvas pixel if >-1
//------------------------------------------------------------------------------
procedure TWindow.move(ax,ay,al,ah,avx,avy:integer);
var q:integer;
begin
if ay>yres-25 then ay:=yres-25;
if al>0 then begin l:=al; end; // now set new window parameters
if ah>0 then begin h:=ah; end;
q:=8*length(title)+96;
if (decoration<>nil) and (al>0) and (al<q) then l:=q;
if (ah>0) and (ah<64) then h:=64;
if al>wl then l:=wl;
if ah>wh then h:=wh;
if ax>-2048 then begin x:=ax; end;
if ay>-2048 then begin y:=ay; end;
if avx>-1 then vx:=avx;
if avy>-1 then vy:=avy;
end;
//------------------------------------------------------------------------------
// Twindow checkmouse function
// This function should be called every vblank for the background window
// Called for any window returns the window handler for the window on which
// there is the mouse cursor and reacts to events:
// by selecting, resizing or moving the clicked window
//------------------------------------------------------------------------------
function TWindow.checkmouse:TWindow;
label p999;
var window:TWindow;
mmx,mmy,mmk,mmw,dt,dg,dh,dl,dsh,dsv,dm:integer;
i,j,x1,y1,x2,y2,q,q2,sy2,vcount,rcount:integer;
ttttt:int64;
rect,r2:PRectangle;
const state:integer=0;
deltax:integer=0;
deltay:integer=0;
sx:integer=0;
sy:integer=0;
hsw:integer=0;
vsp:integer=0;
vsh:integer=0;
hsp:integer=0;
oldhsp:integer=0;
oldvsp:integer=0;
qqqqq:integer=0;
begin
result:=background;
mmx:=mousex;
mmy:=mousey;
mmk:=mousek;
mmw:=mousewheel;
if mmk=0 then
begin
state:=6;
window:=background;
while (window.next<>nil) do begin window.mk:=0; window:=window.next; end;
end;
// if mouse key pressed and there is a window set to move, move it
if mmk=1 then // find a window with mk=1
begin
window:=background;
while (window.next<>nil) and (window.mk<>1) do window:=window.next;
if window.mk=1 then
begin
if state=0 then window.move(mmx-window.mx,mmy-window.my,0,0,-1,-1)
else if state=1 then
begin
q:=mmx-window.x+deltax;
if q+window.vx>window.wl then begin window.vx:=window.wl-q; if window.vx<0 then begin window.vx:=0; q:=window.wl; end; end;
window.move(window.x,window.y, q ,window.h,-1,-1)
end
else if state=2 then
begin
q:=mmy-window.y+deltay;
if q+window.vy>window.wh then begin window.vy:=window.wh-q; if window.vy<0 then begin window.vy:=0; q:=window.wh; end; end;
window.move(window.x,window.y, window.l, q,-1,-1)
end
else if state=3 then
begin
q:=mmx-window.x+deltax;
if q+window.vx>window.wl then begin window.vx:=window.wl-q; if window.vx<0 then begin window.vx:=0; q:=window.wl; end; end;
q2:=mmy-window.y+deltay;
if q2+window.vy>window.wh then begin window.vy:=window.wh-q2; if window.vy<0 then begin window.vy:=0; q2:=window.wh; end; end;
window.move(window.x,window.y, q ,q2, -1, -1)
end
else if state=4 then
begin
if not window.virtualcanvas then
begin
q:=round((mmy-window.y-sy)*(window.wh-window.h)/(window.h-vsh));
if q<0 then q:=0;
if q>window.wh-window.h then q:=window.wh-window.h;
window.move(window.x,window.y,0,0,-1,q);
end
else
begin
q:=round((mmy-window.y-sy)*(window.vch-window.h)/(window.h-vsh));
if q<0 then q:=0;
if q>window.vch-window.h then q:=window.vch-window.h;
window.vcy:=q;
end;
end
else if state=5 then
begin
if not window.virtualcanvas then
begin
q:=round((mmx-window.x-sx)*(window.wl-window.l)/(window.l-hsw));
if q<0 then q:=0;
if q>window.wl-window.l then q:=window.wl-window.l;
window.move(window.x,window.y,0,0,q,-1);
end
else
begin
q:=round((mmx-window.x-sx)*(window.vcl-window.l)/(window.l-hsw));
if q<0 then q:=0;
if q>window.vcl-window.l then q:=window.vcl-window.l;
window.vcx:=q;
end;
end;
result:=window;
// getrectanglelist;
goto p999;
end;
end;
// we are here if mousekey=0 or there is no windows to move
window:=background;
while window.next<>nil do window:=window.next;
if window.decoration=nil then
begin
dg:=0;
dh:=0;
dt:=0;
dl:=0;
dsh:=0;
dsv:=0;
dm:=0;
end
else
begin
dt:=titleheight;
dl:=borderwidth;
dg:=borderwidth;
dh:=borderwidth;
if window.decoration.menu then dm:=menuheight else dm:=0;
if window.decoration.hscroll then dsh:=scrollwidth else dsh:=0;
if window.decoration.vscroll then dsv:=scrollwidth else dsv:=0;
end;
// go back with windows chain until you found the window on which there is the mouse cursor
while ((mmx<window.x-dg) or (mmx>window.x+window.l+dg+dsv) or (mmy<window.y-dt-dg-dm) or (mmy>window.y+window.h+dh+dsh)) and (window.prev<>nil) do
begin
window.mx:=-1;
window.my:=-1;
window.mk:=-1;
window:=window.prev;
if window.decoration=nil then
begin
dg:=0;
dh:=0;
dt:=0;
dl:=0;
dsh:=0;
dsv:=0;
dm:=0;
end
else
begin
dt:= titleheight;
dl:=borderwidth;
dg:=borderwidth;
dh:=borderwidth;
if window.decoration.menu then dm:=menuheight else dm:=0;
if window.decoration.hscroll then dsh:=scrollwidth else dsh:=0;
if window.decoration.vscroll then dsv:=scrollwidth else dsv:=0;
end
end;
result:=window;
// todo: HERE::::: check all widgets on this window !!!
if window.buttons<> nil then window.buttons.checkall;
// now, here no windows to move and window=window to select
// if the window is not selected, select it
if (mmk=1) and (window.mk=0) then
if semaphore=false then window.select;
//and set mouse correction amount
window.mx:=mmx-window.x;
window.my:=mmy-window.y;
window.mk:=mmk;
if not window.virtualcanvas then
begin
hsw:=round((window.l/window.wl)*window.l); if hsw<11 then hsw:=10;
vsh:=round((window.h/window.wh)*window.h); if vsh<11 then vsh:=10;
hsp:=round((window.vx/(window.wl-window.l))*(window.l-hsw));
vsp:=round((window.vy/(window.wh-window.h))*(window.h-vsh));
end
else
begin
hsw:=round((window.l/window.vcl)*window.l); if hsw<11 then hsw:=10;
vsh:=round((window.h/window.vch)*window.h); if vsh<11 then vsh:=10;
hsp:=round((window.vcx/(window.vcl-window.l))*(window.l-hsw));
vsp:=round((window.vcy/(window.vch-window.h))*(window.h-vsh));
end;
// now set the state according to clicked area
if (not(window.resizable)) and (mmy>window.y+window.activey) then begin state:=6; goto p999; end;
if not(window.resizable) or ((mmx<(window.x+window.l)) and (mmy<(window.y-dm{window.h}))) then begin state:=0; deltax:=0; deltay:=0 end // window
else if (mmx<(window.x+window.l)) and (mmy<(window.y)) then begin state:=7; deltax:=0; deltay:=0 end // window
else if (mmx<(window.x+window.l)) and (mmy<(window.y + window.h )) then begin state:=6; deltax:=0; deltay:=0 end // window
else if (mmx>=(window.x+window.l)) and (mmx<(window.x+window.l+scrollwidth-1)) and (mmy<(window.y+vsp+vsh-3)) and (mmy>(window.y+vsp+3)) then
begin
state:=4;
if not window.virtualcanvas then oldvsp:=round((window.vy/(window.wh-window.h))*(window.h-vsh))
else oldvsp:=round((window.vcy/(window.vch-window.h))*(window.h-vsh));
sy:=mmy-window.y-vsp;
end // vertical scroll bar
else if (mmx>=(window.x+window.l)) and (mmy<(window.y+window.h)) then begin state:=1; deltax:=window.x+window.l-mmx; deltay:=0; end // right border
else if (mmx<(window.x+hsp+hsw-3)) and (mmx>(window.x+hsp+3)) and (mmy>=(window.y+window.h)) and (mmy<(window.y+window.h+scrollwidth-1)) then