2
This file is part of the Free Pascal run time library.
3
Copyright (c) 1999-2000 by Florian Klaempfl
5
This file implements the win32 gui support for the graph unit
7
See the file COPYING.FPC, included in this distribution,
8
for details about the copyright.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
**********************************************************************}
24
{ this procedure allows to hook keyboard messages }
25
charmessagehandler : WndProc;
26
{ this procedure allows to hook mouse messages }
27
mousemessagehandler : WndProc;
28
{ this procedure allows to wm_command messages }
29
commandmessagehandler : WndProc;
30
NotifyMessageHandler : WndProc;
32
OnGraphWindowCreation : procedure;
34
GraphWindow,ParentWindow : HWnd;
35
// this allows direct drawing to the window
40
{ predefined window style }
41
{ we shouldn't set CS_DBLCLKS here }
42
{ because most dos applications }
43
{ handle double clicks on it's own }
44
graphwindowstyle : DWord = cs_hRedraw or cs_vRedraw;
46
windowtitle : pchar = 'Graph window application';
49
drawtoscreen : boolean = true;
50
drawtobitmap : boolean = true;
51
// the graph window can be a child window, this allows to add toolbars
53
UseChildWindow : boolean = false;
54
// this allows to specify an offset for the child child window
55
ChildOffset : rect = (left:0;top:0;right:0;bottom:0);
63
{ VESA Specific video modes. }
84
m1280x1024x256 = $107;
85
m1280x1024x32k = $119;
86
m1280x1024x64k = $11A;
88
{ some extra modes which applies only to GUI }
89
mLargestWindow16 = $f0;
90
mLargestWindow256 = $f1;
91
mLargestWindow32k = $f2;
92
mLargestWindow64k = $f3;
93
mLargestWindow16M = $f4;
94
mMaximizedWindow16 = $f5;
95
mMaximizedWindow256 = $f6;
96
mMaximizedWindow32k = $f7;
97
mMaximizedWindow64k = $f8;
98
mMaximizedWindow16M = $f9;
108
Colors in 16 color mode:
109
------------------------
110
- the behavior of xor/or/and put isn't 100%:
111
it is done using the RGB color getting from windows
112
instead of the palette index!
113
- palette operations aren't supported
114
To solve these drawbacks, setpalette must be implemented
115
by exchanging the colors in the DCs, further GetPaletteEntry
116
must be used when doing xor/or/and operations
121
InternalDriverName = 'WIN32GUI';
126
{ used to create a file containing all calls to WM_PAINT
127
WARNING this probably creates HUGE files PM }
128
{ $define DEBUG_WM_PAINT}
130
savedscreen : hbitmap;
131
graphrunning : boolean;
132
graphdrawing : tcriticalsection;
133
pens : array[0..15] of HPEN;
134
{$ifdef DEBUG_WM_PAINT}
138
wm_paint_count : longint = 0;
140
{$endif DEBUG_WM_PAINT}
143
// SavePtr : pointer; { we don't use that pointer }
144
MessageThreadHandle : Handle;
145
MessageThreadID : DWord;
147
function GetPaletteEntry(r,g,b : word) : word;
150
dist,i,index,currentdist : longint;
155
for i:=0 to maxcolors do
157
currentdist:=abs(r-pal[i].red)+abs(g-pal[i].green)+
159
if currentdist<dist then
167
GetPaletteEntry:=index;
170
procedure PutPixel16Win32GUI(x,y : smallint;pixel : word);
178
{ convert to absolute coordinates and then verify clipping...}
181
if (x<startxviewport) or (x>(startxviewport+viewwidth)) or
182
(y<StartyViewPort) or (y>(startyviewport+viewheight)) then
187
c:=RGB(pal[pixel].red,pal[pixel].green,pal[pixel].blue);
188
EnterCriticalSection(graphdrawing);
190
SetPixelV(bitmapdc,x,y,c);
192
SetPixelV(windc,x,y,c);
193
LeaveCriticalSection(graphdrawing);
197
function GetPixel16Win32GUI(x,y : smallint) : word;
205
{ convert to absolute coordinates and then verify clipping...}
208
if (x<startxviewport) or (x>(startxviewport+viewwidth)) or
209
(y<StartyViewPort) or (y>(startyviewport+viewheight)) then
214
EnterCriticalSection(graphdrawing);
215
c:=Windows.GetPixel(bitmapdc,x,y);
216
LeaveCriticalSection(graphdrawing);
217
GetPixel16Win32GUI:=GetPaletteEntry(GetRValue(c),GetGValue(c),GetBValue(c));
221
_graphresult:=grerror;
226
procedure DirectPutPixel16Win32GUI(x,y : smallint);
235
EnterCriticalSection(graphdrawing);
237
case currentwritemode of
240
c2:=Windows.GetPixel(windc,x,y);
241
c:=RGB(pal[col].red,pal[col].green,pal[col].blue) xor c2;
243
SetPixelV(bitmapdc,x,y,c);
245
SetPixelV(windc,x,y,c);
249
c2:=Windows.GetPixel(windc,x,y);
250
c:=RGB(pal[col].red,pal[col].green,pal[col].blue) and c2;
252
SetPixelV(bitmapdc,x,y,c);
254
SetPixelV(windc,x,y,c);
258
c2:=Windows.GetPixel(windc,x,y);
259
c:=RGB(pal[col].red,pal[col].green,pal[col].blue) or c2;
261
SetPixelV(bitmapdc,x,y,c);
263
SetPixelV(windc,x,y,c);
267
If CurrentWriteMode<>NotPut Then
269
Else col := Not(CurrentColor);
270
c:=RGB(pal[col].red,pal[col].green,pal[col].blue);
272
SetPixelV(bitmapdc,x,y,c);
274
SetPixelV(windc,x,y,c);
277
LeaveCriticalSection(graphdrawing);
282
bitmapfontverticalcache : array[0..255] of HBITMAP;
283
bitmapfonthorizoncache : array[0..255] of HBITMAP;
285
procedure OutTextXYWin32GUI(x,y : smallint;const TextString : string);
295
cnt1,cnt2 : smallint;
296
cnt3,cnt4 : smallint;
299
curX2, curY2, xpos2, ypos2, x2, y2: graph_float;
300
oldvalues : linesettingstype;
301
fontbitmap : TBitmapChar;
304
xpos2i,ypos2i : longint;
305
charbitmap,oldcharbitmap : HBITMAP;
308
brushwin,oldbrushwin,brushbitmap,oldbrushbitmap : HBRUSH;
309
bitmaprgn,winrgn : HRGN;
312
{ save current write mode }
313
WriteMode := CurrentWriteMode;
314
CurrentWriteMode := NormalPut;
315
GetTextPosition(xpos,ypos,textstring);
316
X:=X-XPos; Y:=Y+YPos;
318
CharSize := CurrentTextInfo.Charsize;
319
if Currenttextinfo.font=DefaultFont then
321
if CurrentTextInfo.direction=HorizDir then
322
{ Horizontal direction }
324
if (x>viewwidth) or (y>viewheight) or
327
CurrentWriteMode:=WriteMode;
330
EnterCriticalSection(graphdrawing);
331
c:=length(textstring);
332
chardc:=CreateCompatibleDC(windc);
333
if currentcolor<>white then
335
color:=RGB(pal[currentcolor].red,pal[currentcolor].green,
336
pal[currentcolor].blue);
340
brushwin:=CreateSolidBrush(color);
341
oldbrushwin:=SelectObject(windc,brushwin);
346
brushbitmap:=CreateSolidBrush(color);
347
oldbrushbitmap:=SelectObject(bitmapdc,brushbitmap);
350
inc(x,startxviewport);
351
inc(y,startyviewport);
353
{ let windows do the clipping }
356
bitmaprgn:=CreateRectRgn(startxviewport,startyviewport,
357
startxviewport+viewwidth+1,startyviewport+viewheight+1);
358
SelectClipRgn(bitmapdc,bitmaprgn);
363
winrgn:=CreateRectRgn(startxviewport,startyviewport,
364
startxviewport+viewwidth+1,startyviewport+viewheight+1);
365
SelectClipRgn(windc,winrgn);
370
xpos:=x+(i*8)*Charsize;
371
if bitmapfonthorizoncache[byte(textstring[i+1])]=0 then
373
charbitmap:=CreateCompatibleBitmap(windc,8,8);
375
writeln('Bitmap konnte nicht erzeugt werden!');
376
oldcharbitmap:=SelectObject(chardc,charbitmap);
377
Fontbitmap:=TBitmapChar(DefaultFontData[textstring[i+1]]);
381
if Fontbitmap[j,k]<>0 then
382
SetPixelV(chardc,k,j,$ffffff)
384
SetPixelV(chardc,k,j,0);
385
bitmapfonthorizoncache[byte(textstring[i+1])]:=charbitmap;
386
SelectObject(chardc,oldcharbitmap);
388
oldcharbitmap:=SelectObject(chardc,bitmapfonthorizoncache[byte(textstring[i+1])]);
391
if currentcolor=white then
394
BitBlt(windc,xpos,y,8,8,chardc,0,0,SRCPAINT);
396
BitBlt(bitmapdc,xpos,y,8,8,chardc,0,0,SRCPAINT);
400
{ could we do this with one pattern operation ?? }
401
{ we would need something like DSnaSPao }
404
// ROP $00220326=DSna
405
BitBlt(windc,xpos,y,8,8,chardc,0,0,$00220326);
406
// ROP $00EA02E9 = DPSao
407
BitBlt(windc,xpos,y,8,8,chardc,0,0,$00EA02E9);
412
BitBlt(bitmapdc,xpos,y,8,8,chardc,0,0,$00220326);
413
BitBlt(bitmapdc,xpos,y,8,8,chardc,0,0,$00EA02E9);
419
if currentcolor=white then
422
StretchBlt(windc,xpos,y,8*charsize,8*charsize,chardc,0,0,8,8,SRCPAINT);
424
StretchBlt(bitmapdc,xpos,y,8*charsize,8*charsize,chardc,0,0,8,8,SRCPAINT);
428
{ could we do this with one pattern operation ?? }
429
{ we would need something like DSnaSPao }
432
// ROP $00220326=DSna
433
StretchBlt(windc,xpos,y,8*charsize,8*charsize,chardc,0,0,8,8,$00220326);
434
// ROP $00EA02E9 = DPSao
435
StretchBlt(windc,xpos,y,8*charsize,8*charsize,chardc,0,0,8,8,$00EA02E9);
439
StretchBlt(bitmapdc,xpos,y,8*charsize,8*charsize,chardc,0,0,8,8,$00220326);
440
StretchBlt(bitmapdc,xpos,y,8*charsize,8*charsize,chardc,0,0,8,8,$00EA02E9);
444
SelectObject(chardc,oldcharbitmap);
446
if currentcolor<>white then
450
SelectObject(windc,oldbrushwin);
451
DeleteObject(brushwin);
456
SelectObject(bitmapdc,oldbrushbitmap);
457
DeleteObject(brushbitmap);
460
{ release clip regions }
463
SelectClipRgn(bitmapdc,0);
464
DeleteObject(bitmaprgn);
468
SelectClipRgn(windc,0);
469
DeleteObject(winrgn);
472
LeaveCriticalSection(graphdrawing);
475
{ Vertical direction }
477
if (x>viewwidth) or (y>viewheight) or
480
CurrentWriteMode:=WriteMode;
483
EnterCriticalSection(graphdrawing);
484
c:=length(textstring);
485
chardc:=CreateCompatibleDC(windc);
486
if currentcolor<>white then
488
color:=RGB(pal[currentcolor].red,pal[currentcolor].green,
489
pal[currentcolor].blue);
493
brushwin:=CreateSolidBrush(color);
494
oldbrushwin:=SelectObject(windc,brushwin);
499
brushbitmap:=CreateSolidBrush(color);
500
oldbrushbitmap:=SelectObject(bitmapdc,brushbitmap);
503
inc(x,startxviewport);
504
inc(y,startyviewport);
505
{ let windows do the clipping }
508
winrgn:=CreateRectRgn(startxviewport,startyviewport,
509
startxviewport+viewwidth+1,startyviewport+viewheight+1);
510
SelectClipRgn(windc,winrgn);
515
bitmaprgn:=CreateRectRgn(startxviewport,startyviewport,
516
startxviewport+viewwidth+1,startyviewport+viewheight+1);
517
SelectClipRgn(bitmapdc,bitmaprgn);
521
ypos:=y+1-((i+1)*8)*CharSize;
522
if bitmapfontverticalcache[byte(textstring[i+1])]=0 then
524
charbitmap:=CreateCompatibleBitmap(windc,8,8);
526
writeln('Bitmap konnte nicht erzeugt werden!');
527
oldcharbitmap:=SelectObject(chardc,charbitmap);
528
Fontbitmap:=TBitmapChar(DefaultFontData[textstring[i+1]]);
532
if Fontbitmap[j,k]<>0 then
533
SetPixelV(chardc,j,7-k,$ffffff)
535
SetPixelV(chardc,j,7-k,0);
536
bitmapfontverticalcache[byte(textstring[i+1])]:=charbitmap;
537
SelectObject(chardc,oldcharbitmap);
539
oldcharbitmap:=SelectObject(chardc,bitmapfontverticalcache[byte(textstring[i+1])]);
542
if currentcolor=white then
545
BitBlt(windc,x,ypos,8,8,chardc,0,0,SRCPAINT);
547
BitBlt(bitmapdc,x,ypos,8,8,chardc,0,0,SRCPAINT);
551
{ could we do this with one pattern operation ?? }
552
{ we would need something like DSnaSPao }
555
// ROP $00220326=DSna
556
BitBlt(windc,x,ypos,8,8,chardc,0,0,$00220326);
557
// ROP $00EA02E9 = DPSao
558
BitBlt(windc,x,ypos,8,8,chardc,0,0,$00EA02E9);
562
BitBlt(bitmapdc,x,ypos,8,8,chardc,0,0,$00220326);
563
BitBlt(bitmapdc,x,ypos,8,8,chardc,0,0,$00EA02E9);
569
if currentcolor=white then
572
StretchBlt(windc,x,ypos,8*charsize,8*charsize,chardc,0,0,8,8,SRCPAINT);
574
StretchBlt(bitmapdc,x,ypos,8*charsize,8*charsize,chardc,0,0,8,8,SRCPAINT);
578
{ could we do this with one pattern operation ?? }
579
{ we would need something like DSnaSPao }
582
// ROP $00220326=DSna
583
StretchBlt(windc,x,ypos,8*charsize,8*charsize,chardc,0,0,8,8,$00220326);
584
// ROP $00EA02E9 = DPSao
585
StretchBlt(windc,x,ypos,8*charsize,8*charsize,chardc,0,0,8,8,$00EA02E9);
589
StretchBlt(bitmapdc,x,ypos,8*charsize,8*charsize,chardc,0,0,8,8,$00220326);
590
StretchBlt(bitmapdc,x,ypos,8*charsize,8*charsize,chardc,0,0,8,8,$00EA02E9);
594
SelectObject(chardc,oldcharbitmap);
596
if currentcolor<>white then
600
SelectObject(windc,oldbrushwin);
601
DeleteObject(brushwin);
606
SelectObject(bitmapdc,oldbrushbitmap);
607
DeleteObject(brushbitmap);
610
{ release clip regions }
613
SelectClipRgn(windc,0);
614
DeleteObject(winrgn);
618
SelectClipRgn(bitmapdc,0);
619
DeleteObject(bitmaprgn);
622
LeaveCriticalSection(graphdrawing);
625
{ This is a stroked font which is already loaded into memory }
627
getlinesettings(oldvalues);
628
{ reset line style to defaults }
629
setlinestyle(solidln,oldvalues.pattern,normwidth);
630
if Currenttextinfo.direction=vertdir then
631
xpos:=xpos + Textheight(textstring);
632
CurX2:=xpos; xpos2 := curX2; x2 := xpos2;
633
CurY2:=ypos; ypos2 := curY2; y2 := ypos2;
636
for i:=1 to length(textstring) do
638
c:=byte(textstring[i]);
639
{ Stroke_Count[c] := }
640
unpack( fonts[CurrentTextInfo.font].instr,
641
fonts[CurrentTextInfo.font].Offsets[c], Strokes );
645
if CurrentTextInfo.direction=VertDir then
647
xpos2:=x2-(Strokes[counter].Y*CurrentYRatio);
648
ypos2:=y2-(Strokes[counter].X*CurrentXRatio);
652
xpos2:=x2+(Strokes[counter].X*CurrentXRatio) ;
653
ypos2:=y2-(Strokes[counter].Y*CurrentYRatio) ;
655
case opcodes(Strokes[counter].opcode) of
658
{ Currently unsupported };
665
curx2i:=trunc(CurX2);
666
cury2i:=trunc(CurY2);
667
xpos2i:=trunc(xpos2);
668
ypos2i:=trunc(ypos2);
669
{ this optimization doesn't matter that much
670
if (curx2i=xpos2i) then
672
if (cury2i=ypos2i) then
673
putpixel(curx2i,cury2i,currentcolor)
674
else if (cury2i+1=ypos2i) or
675
(cury2i=ypos2i+1) then
677
putpixel(curx2i,cury2i,currentcolor);
678
putpixel(curx2i,ypos2i,currentcolor);
681
Line(curx2i,cury2i,xpos2i,ypos2i);
683
else if (cury2i=ypos2i) then
685
if (curx2i+1=xpos2i) or
686
(curx2i=xpos2i+1) then
688
putpixel(curx2i,cury2i,currentcolor);
689
putpixel(xpos2i,cury2i,currentcolor);
692
Line(curx2i,cury2i,xpos2i,ypos2i);
696
Line(curx2i,cury2i,xpos2i,ypos2i);
706
if Currenttextinfo.direction=VertDir then
707
y2:=y2-(byte(fonts[CurrenttextInfo.font].widths[c])*CurrentXRatio)
709
x2:=x2+(byte(fonts[Currenttextinfo.font].widths[c])*CurrentXRatio);
711
setlinestyle( oldvalues.linestyle, oldvalues.pattern, oldvalues.thickness);
713
{ restore write mode }
714
CurrentWriteMode := WriteMode;
717
procedure HLine16Win32GUI(x,x2,y: smallint);
727
{ must we swap the values? }
736
if (x>ViewWidth) or (y<0) or (y>ViewHeight) or (x2<0) then
744
X2:=X2+StartXViewPort;
746
Case CurrentWriteMode of
749
EnterCriticalSection(graphdrawing);
753
c2:=Windows.GetPixel(windc,i,y);
754
c:=RGB(pal[col].red,pal[col].green,pal[col].blue) and c2;
756
SetPixelV(bitmapdc,i,y,c);
759
SetPixelV(windc,i,y,c);
761
LeaveCriticalSection(graphdrawing);
765
EnterCriticalSection(graphdrawing);
769
c2:=Windows.GetPixel(windc,i,y);
770
c:=RGB(pal[col].red,pal[col].green,pal[col].blue) xor c2;
773
SetPixelV(bitmapdc,i,y,c);
776
SetPixelV(windc,i,y,c);
778
LeaveCriticalSection(graphdrawing);
782
EnterCriticalSection(graphdrawing);
786
c2:=Windows.GetPixel(windc,i,y);
787
c:=RGB(pal[col].red,pal[col].green,pal[col].blue) or c2;
790
SetPixelV(bitmapdc,i,y,c);
793
SetPixelV(windc,i,y,c);
795
LeaveCriticalSection(graphdrawing);
799
If CurrentWriteMode<>NotPut Then
801
Else col:=Not(CurrentColor);
802
EnterCriticalSection(graphdrawing);
805
c:=RGB(pal[col].red,pal[col].green,pal[col].blue);
809
SetPixelV(bitmapdc,x,y,c);
811
SetPixelV(windc,x,y,c);
816
if (col>=0) and (col<=high(pens)) then
820
c:=RGB(pal[col].red,pal[col].green,pal[col].blue);
821
pens[col]:=CreatePen(PS_SOLID,1,c);
827
c:=RGB(pal[col].red,pal[col].green,pal[col].blue);
828
pen:=CreatePen(PS_SOLID,1,c);
833
oldpen:=SelectObject(bitmapdc,pen);
834
Windows.MoveToEx(bitmapdc,x,y,nil);
835
Windows.LineTo(bitmapdc,x2+1,y);
836
SelectObject(bitmapdc,oldpen);
841
oldpen:=SelectObject(windc,pen);
842
Windows.MoveToEx(windc,x,y,nil);
843
Windows.LineTo(windc,x2+1,y);
844
SelectObject(windc,oldpen);
847
if (col<0) or (col>high(pens)) then
850
LeaveCriticalSection(graphdrawing);
856
procedure VLine16Win32GUI(x,y,y2: smallint); {$ifndef fpc}far;{$endif fpc}
864
{ must we swap the values? }
873
if (x>ViewWidth) or (x<0) or (y>ViewHeight) or (y2<0) then
877
if y2>ViewHeight then
880
{ First convert to global coordinates }
881
X := X + StartXViewPort;
882
Y2 := Y2 + StartYViewPort;
883
Y := Y + StartYViewPort;
884
if currentwritemode=normalput then
887
EnterCriticalSection(graphdrawing);
890
c:=RGB(pal[col].red,pal[col].green,pal[col].blue);
894
SetPixelV(bitmapdc,x,y,c);
896
SetPixelV(windc,x,y,c);
901
if (col>=0) and (col<=high(pens)) then
905
c:=RGB(pal[col].red,pal[col].green,pal[col].blue);
906
pens[col]:=CreatePen(PS_SOLID,1,c);
912
c:=RGB(pal[col].red,pal[col].green,pal[col].blue);
913
pen:=CreatePen(PS_SOLID,1,c);
918
oldpen:=SelectObject(bitmapdc,pen);
919
Windows.MoveToEx(bitmapdc,x,y,nil);
920
Windows.LineTo(bitmapdc,x,y2+1);
921
SelectObject(bitmapdc,oldpen);
926
oldpen:=SelectObject(windc,pen);
927
Windows.MoveToEx(windc,x,y,nil);
928
Windows.LineTo(windc,x,y2+1);
929
SelectObject(windc,oldpen);
931
if (col<0) or (col>high(pens)) then
934
LeaveCriticalSection(graphdrawing);
937
for y := y to y2 do Directputpixel(x,y)
940
procedure Circle16Win32GUI(X, Y: smallint; Radius:Word);
943
bitmaprgn,winrgn : HRGN;
946
OriginalArcInfo: ArcCoordsType;
955
{ only normal put mode is supported by a call to PutPixel }
956
PutPixel(X, Y, CurrentColor);
962
{ only normal put mode is supported by a call to PutPixel }
963
PutPixel(X-1, Y, CurrentColor);
964
PutPixel(X+1, Y, CurrentColor);
965
PutPixel(X, Y-1, CurrentColor);
966
PutPixel(X, Y+1, CurrentColor);
970
if LineInfo.Thickness = Normwidth then
972
EnterCriticalSection(graphdrawing);
973
{ let windows do the clipping }
976
bitmaprgn:=CreateRectRgn(startxviewport,startyviewport,
977
startxviewport+viewwidth+1,startyviewport+viewheight+1);
978
SelectClipRgn(bitmapdc,bitmaprgn);
983
winrgn:=CreateRectRgn(startxviewport,startyviewport,
984
startxviewport+viewwidth+1,startyviewport+viewheight+1);
985
SelectClipRgn(windc,winrgn);
988
inc(x,StartXViewPort);
989
inc(y,StartYViewPort);
992
if (col>=0) and (col<=high(pens)) then
996
c:=RGB(pal[col].red,pal[col].green,pal[col].blue);
997
pens[col]:=CreatePen(PS_SOLID,1,c);
1003
c:=RGB(pal[col].red,pal[col].green,pal[col].blue);
1004
pen:=CreatePen(PS_SOLID,1,c);
1007
if drawtobitmap then
1009
oldpen:=SelectObject(bitmapdc,pen);
1010
windows.arc(bitmapdc,x-radius,y-radius,x+radius,y+radius,
1011
x,y-radius,x,y-radius);
1012
SelectObject(bitmapdc,oldpen);
1015
if drawtoscreen then
1017
oldpen:=SelectObject(windc,pen);
1018
windows.arc(windc,x-radius,y-radius,x+radius,y+radius,
1019
x,y-radius,x,y-radius);
1020
SelectObject(windc,oldpen);
1023
if (col<0) or (col>high(pens)) then
1025
{ release clip regions }
1026
if drawtoscreen then
1028
SelectClipRgn(windc,0);
1029
DeleteObject(winrgn);
1031
if drawtobitmap then
1033
SelectClipRgn(bitmapdc,0);
1034
DeleteObject(bitmaprgn);
1036
LeaveCriticalSection(graphdrawing);
1040
{ save state of arc information }
1041
{ because it is not needed for }
1043
move(ArcCall,OriginalArcInfo, sizeof(ArcCall));
1044
InternalEllipse(X,Y,Radius,Radius,0,360,{$ifdef fpc}@{$endif}DummyPatternLine);
1045
{ restore arc information }
1046
move(OriginalArcInfo, ArcCall,sizeof(ArcCall));
1051
Procedure PutImageWin32GUI(X,Y: smallint; var Bitmap; BitBlt: Word); {$ifndef fpc}far;{$endif fpc}
1053
pt = array[0..$fffffff] of word;
1054
ptw = array[0..2] of longint;
1057
oldCurrentColor: word;
1058
oldCurrentWriteMode, i, j, y1, x1, deltaX, deltaX1, deltaY: smallint;
1061
LogLn('putImage at ('+strf(x)+','+strf(y)+') with width '+strf(ptw(Bitmap)[0])+
1062
' and height '+strf(ptw(Bitmap)[1]));
1065
inc(x,startXViewPort);
1066
inc(y,startYViewPort);
1067
x1 := ptw(Bitmap)[0]+x; { get width and adjust end coordinate accordingly }
1068
y1 := ptw(Bitmap)[1]+y; { get height and adjust end coordinate accordingly }
1072
k := 3 * sizeOf(Longint) div sizeOf(Word); { Three reserved longs at start of bitmap }
1073
{ check which part of the image is in the viewport }
1076
if y < startYViewPort then
1078
deltaY := startYViewPort - y;
1079
inc(k,(x1-x+1)*deltaY);
1080
y := startYViewPort;
1082
if y1 > startYViewPort+viewHeight then
1083
y1 := startYViewPort+viewHeight;
1084
if x < startXViewPort then
1086
deltaX := startXViewPort-x;
1087
x := startXViewPort;
1089
if x1 > startXViewPort + viewWidth then
1091
deltaX1 := x1 - (startXViewPort + viewWidth);
1092
x1 := startXViewPort + viewWidth;
1096
LogLn('deltax: '+strf(deltax)+', deltax1: '+strf(deltax1)+',deltay: '+strf(deltay));
1100
oldCurrentColor := currentColor;
1101
oldCurrentWriteMode := currentWriteMode;
1102
currentWriteMode := bitBlt;
1108
currentColor := pt(bitmap)[k];
1109
directPutPixel(i,j);
1114
currentWriteMode := oldCurrentWriteMode;
1115
currentColor := oldCurrentColor;
1118
procedure SetRGBPaletteWin32GUI(colorNum,redValue,greenvalue,
1119
bluevalue : smallint);
1122
if directcolor or (colornum<0) or (colornum>=maxcolor) then
1124
_graphresult:=grerror;
1127
pal[colorNum].red:=redValue;
1128
pal[colorNum].green:=greenValue;
1129
pal[colorNum].blue:=blueValue;
1130
if (colorNum>=0) and (colorNum<=high(pens)) and (pens[colorNum]<>0) then
1132
DeleteObject(pens[colorNum]);
1137
procedure GetRGBPaletteWin32GUI(colorNum : smallint;
1138
var redValue,greenvalue,bluevalue : smallint);
1141
if directcolor or (colornum<0) or (colornum>=maxcolor) then
1143
_graphresult:=grerror;
1146
redValue:=pal[colorNum].red;
1147
greenValue:=pal[colorNum].green;
1148
blueValue:=pal[colorNum].blue;
1151
procedure savestate;
1157
procedure restorestate;
1162
function WindowProcGraph(Window: HWnd; AMessage:UInt; WParam : WParam;
1163
LParam: LParam): Longint; stdcall;
1174
WindowProcGraph := 0;
1187
This leads to problem, i.e. the menu etc doesn't work any longer
1199
if assigned(mousemessagehandler) then
1200
WindowProcGraph:=mousemessagehandler(window,amessage,wparam,lparam);
1204
if assigned(notifymessagehandler) then
1205
WindowProcGraph:=notifymessagehandler(window,amessage,wparam,lparam);
1208
if assigned(commandmessagehandler) then
1209
WindowProcGraph:=commandmessagehandler(window,amessage,wparam,lparam);
1214
if assigned(charmessagehandler) then
1215
WindowProcGraph:=charmessagehandler(window,amessage,wparam,lparam);
1219
{$ifdef DEBUG_WM_PAINT}
1220
inc(wm_paint_count);
1221
{$endif DEBUG_WM_PAINT}
1222
{$ifdef DEBUGCHILDS}
1223
writeln('Start child painting');
1224
{$endif DEBUGCHILDS}
1225
if not GetUpdateRect(Window,@r,false) then
1227
EnterCriticalSection(graphdrawing);
1229
dc:=BeginPaint(Window,@ps);
1230
{$ifdef DEBUG_WM_PAINT}
1231
Writeln(graphdebug,'WM_PAINT in ((',r.left,',',r.top,
1232
'),(',r.right,',',r.bottom,'))');
1233
{$endif def DEBUG_WM_PAINT}
1234
if graphrunning then
1235
{BitBlt(dc,0,0,maxx+1,maxy+1,bitmapdc,0,0,SRCCOPY);}
1236
BitBlt(dc,r.left,r.top,r.right-r.left+1,r.bottom-r.top+1,bitmapdc,r.left,r.top,SRCCOPY);
1237
EndPaint(Window,ps);
1238
LeaveCriticalSection(graphdrawing);
1243
{$ifdef DEBUG_WM_PAINT}
1244
assign(graphdebug,'wingraph.log');
1245
rewrite(graphdebug);
1246
{$endif DEBUG_WM_PAINT}
1247
{$ifdef DEBUGCHILDS}
1248
writeln('Creating window (HWND: ',window,')... ');
1249
{$endif DEBUGCHILDS}
1250
GraphWindow:=window;
1251
EnterCriticalSection(graphdrawing);
1253
{$ifdef DEBUGCHILDS}
1254
writeln('Window DC: ',dc);
1255
{$endif DEBUGCHILDS}
1256
bitmapdc:=CreateCompatibleDC(dc);
1257
savedscreen:=CreateCompatibleBitmap(dc,maxx+1,maxy+1);
1258
ReleaseDC(window,dc);
1259
oldbitmap:=SelectObject(bitmapdc,savedscreen);
1260
windc:=GetDC(window);
1262
oldpen:=SelectObject(bitmapdc,GetStockObject(BLACK_PEN));
1263
oldbrush:=SelectObject(bitmapdc,GetStockObject(BLACK_BRUSH));
1264
Windows.Rectangle(bitmapdc,0,0,maxx,maxy);
1265
SelectObject(bitmapdc,oldpen);
1266
SelectObject(bitmapdc,oldbrush);
1267
// ... the window too
1268
oldpen:=SelectObject(windc,GetStockObject(BLACK_PEN));
1269
oldbrush:=SelectObject(windc,GetStockObject(BLACK_BRUSH));
1270
Windows.Rectangle(windc,0,0,maxx,maxy);
1271
SelectObject(windc,oldpen);
1272
SelectObject(windc,oldbrush);
1274
fillchar(bitmapfonthorizoncache,sizeof(bitmapfonthorizoncache),0);
1275
fillchar(bitmapfontverticalcache,sizeof(bitmapfontverticalcache),0);
1277
// clear predefined pens
1278
fillchar(pens,sizeof(pens),0);
1279
if assigned(OnGraphWindowCreation) then
1280
OnGraphWindowCreation;
1281
LeaveCriticalSection(graphdrawing);
1282
{$ifdef DEBUGCHILDS}
1284
GetClientRect(window,@r);
1285
writeln('Window size: ',r.right,',',r.bottom);
1286
{$endif DEBUGCHILDS}
1290
EnterCriticalSection(graphdrawing);
1291
graphrunning:=false;
1292
ReleaseDC(GraphWindow,windc);
1293
SelectObject(bitmapdc,oldbitmap);
1294
DeleteObject(savedscreen);
1296
// release font cache
1298
if bitmapfonthorizoncache[i]<>0 then
1299
DeleteObject(bitmapfonthorizoncache[i]);
1301
if bitmapfontverticalcache[i]<>0 then
1302
DeleteObject(bitmapfontverticalcache[i]);
1304
for i:=0 to high(pens) do
1306
DeleteObject(pens[i]);
1308
LeaveCriticalSection(graphdrawing);
1309
{$ifdef DEBUG_WM_PAINT}
1311
{$endif DEBUG_WM_PAINT}
1316
WindowProcGraph := DefWindowProc(Window, AMessage, WParam, LParam);
1320
function WindowProcParent(Window: HWnd; AMessage:UInt; WParam : WParam;
1321
LParam: LParam): Longint; stdcall;
1324
WindowProcParent := 0;
1330
if assigned(charmessagehandler) then
1331
WindowProcParent:=charmessagehandler(window,amessage,wparam,lparam);
1335
if assigned(notifymessagehandler) then
1336
WindowProcParent:=notifymessagehandler(window,amessage,wparam,lparam);
1339
if assigned(commandmessagehandler) then
1340
WindowProcParent:=commandmessagehandler(window,amessage,wparam,lparam);
1342
WindowProcParent := DefWindowProc(Window, AMessage, WParam, LParam);
1346
function WinRegister: Boolean;
1348
WindowClass: WndClass;
1350
WindowClass.Style := graphwindowstyle;
1351
WindowClass.lpfnWndProc := WndProc(@WindowProcGraph);
1352
WindowClass.cbClsExtra := 0;
1353
WindowClass.cbWndExtra := 0;
1354
WindowClass.hInstance := system.MainInstance;
1356
WindowClass.hIcon := icon
1358
WindowClass.hIcon := LoadIcon(0, idi_Application);
1359
WindowClass.hCursor := LoadCursor(0, idc_Arrow);
1360
WindowClass.hbrBackground := GetStockObject(BLACK_BRUSH);
1362
WindowClass.lpszMenuName := MAKEINTRESOURCE(menu)
1364
WindowClass.lpszMenuName := nil;
1365
WindowClass.lpszClassName := 'FPCGraphWindow';
1367
winregister:=RegisterClass(WindowClass) <> 0;
1370
function WinRegisterWithChild: Boolean;
1372
WindowClass: WndClass;
1374
WindowClass.Style := graphwindowstyle;
1375
WindowClass.lpfnWndProc := WndProc(@WindowProcParent);
1376
WindowClass.cbClsExtra := 0;
1377
WindowClass.cbWndExtra := 0;
1378
WindowClass.hInstance := system.MainInstance;
1380
WindowClass.hIcon := icon
1382
WindowClass.hIcon := LoadIcon(0, idi_Application);
1383
WindowClass.hCursor := LoadCursor(0, idc_Arrow);
1384
WindowClass.hbrBackground := GetStockObject(BLACK_BRUSH);
1386
WindowClass.lpszMenuName := MAKEINTRESOURCE(menu)
1388
WindowClass.lpszMenuName := nil;
1389
WindowClass.lpszClassName := 'FPCGraphWindowMain';
1391
WinRegisterWithChild:=RegisterClass(WindowClass) <> 0;
1392
{$ifdef DEBUGCHILDS}
1393
writeln('Main window successfully registered: WinRegisterWithChild is ',WinRegisterWithChild);
1394
{$endif DEBUGCHILDS}
1395
if WinRegisterWithChild then
1397
WindowClass.Style := CS_HREDRAW or CS_VREDRAW;
1398
WindowClass.lpfnWndProc := WndProc(@WindowProcGraph);
1399
WindowClass.cbClsExtra := 0;
1400
WindowClass.cbWndExtra := 0;
1401
WindowClass.hInstance := system.MainInstance;
1402
WindowClass.hIcon := 0;
1403
WindowClass.hCursor := LoadCursor(0, idc_Arrow);
1404
WindowClass.hbrBackground := GetStockObject(BLACK_BRUSH);
1405
WindowClass.lpszMenuName := nil;
1406
WindowClass.lpszClassName := 'FPCGraphWindowChild';
1407
WinRegisterWithChild:=RegisterClass(WindowClass)<>0;
1408
{$ifdef DEBUGCHILDS}
1409
writeln('Child window registered: WinRegisterWithChild is ',WinRegisterWithChild);
1410
{$endif DEBUGCHILDS}
1415
// here we can force the creation of a maximized window }
1416
extrastyle : cardinal;
1418
{ Create the Window Class }
1419
function WinCreate : HWnd;
1424
if UseChildWindow then
1426
ParentWindow:=CreateWindow('FPCGraphWindowMain', windowtitle,
1427
WS_OVERLAPPEDWINDOW or WS_CLIPCHILDREN or extrastyle, longint(CW_USEDEFAULT), 0,
1428
maxx+ChildOffset.Left+ChildOffset.Right+1+
1429
2*GetSystemMetrics(SM_CXFRAME),
1430
maxy+ChildOffset.Top+ChildOffset.Bottom+1+
1431
2*GetSystemMetrics(SM_CYFRAME)+
1432
GetSystemMetrics(SM_CYCAPTION),
1433
0, 0, system.MainInstance, nil);
1434
if ParentWindow<>0 then
1436
ShowWindow(ParentWindow, SW_SHOW);
1437
UpdateWindow(ParentWindow);
1441
hWindow:=CreateWindow('FPCGraphWindowChild',nil,
1442
WS_CHILD, ChildOffset.Left,ChildOffset.Top,
1444
ParentWindow, 0, system.MainInstance, nil);
1447
ShowWindow(hwindow, SW_SHOW);
1448
UpdateWindow(hwindow);
1456
hWindow:=CreateWindow('FPCGraphWindow', windowtitle,
1457
ws_OverlappedWindow or extrastyle, longint(CW_USEDEFAULT), 0,
1458
maxx+1+2*GetSystemMetrics(SM_CXFRAME),
1459
maxy+1+2*GetSystemMetrics(SM_CYFRAME)+
1460
GetSystemMetrics(SM_CYCAPTION),
1461
0, 0, system.MainInstance, nil);
1462
if hWindow <> 0 then
1464
ShowWindow(hWindow, SW_SHOW);
1465
UpdateWindow(hWindow);
1472
winregistered : boolean = false;
1474
function MessageHandleThread(p : pointer) : DWord;StdCall;
1480
if not(winregistered) then
1482
if UseChildWindow then
1484
if not(WinRegisterWithChild) then
1486
MessageBox(0, 'Window registration failed', nil, mb_Ok);
1492
if not(WinRegister) then
1494
MessageBox(0, 'Window registration failed', nil, mb_Ok);
1498
winregistered:=true;
1500
GraphWindow:=WinCreate;
1501
if longint(GraphWindow) = 0 then begin
1502
MessageBox(0, 'Window creation failed', nil, mb_Ok);
1505
while longint(GetMessage(@AMessage, 0, 0, 0))=longint(true) do
1507
TranslateMessage(AMessage);
1508
DispatchMessage(AMessage);
1510
MessageHandleThread:=0;
1513
procedure InitWin32GUI16colors;
1516
threadexitcode : longint;
1518
getmem(pal,sizeof(RGBrec)*maxcolor);
1519
move(DefaultColors,pal^,sizeof(RGBrec)*maxcolor);
1520
if (IntCurrentMode=mMaximizedWindow16) or
1521
(IntCurrentMode=mMaximizedWindow256) or
1522
(IntCurrentMode=mMaximizedWindow32k) or
1523
(IntCurrentMode=mMaximizedWindow64k) or
1524
(IntCurrentMode=mMaximizedWindow16M) then
1525
extrastyle:=ws_maximize
1528
{ start graph subsystem }
1529
InitializeCriticalSection(graphdrawing);
1530
graphrunning:=false;
1531
MessageThreadHandle:=CreateThread(nil,0,@MessageHandleThread,
1532
nil,0,MessageThreadID);
1534
GetExitCodeThread(MessageThreadHandle,@threadexitcode);
1535
until graphrunning or (threadexitcode<>STILL_ACTIVE);
1536
if threadexitcode<>STILL_ACTIVE then
1537
_graphresult := grerror;
1540
procedure CloseGraph;
1543
If not isgraphmode then
1545
_graphresult := grnoinitgraph;
1548
if UseChildWindow then
1550
{ if the child window isn't destroyed }
1551
{ the main window can't be closed }
1552
{ I don't know any other way (FK) }
1553
PostMessage(GraphWindow,wm_destroy,0,0);
1554
PostMessage(ParentWindow,wm_destroy,0,0)
1557
PostMessage(GraphWindow,wm_destroy,0,0);
1559
PostThreadMessage(MessageThreadHandle,wm_quit,0,0);
1560
WaitForSingleObject(MessageThreadHandle,Infinite);
1561
CloseHandle(MessageThreadHandle);
1562
DeleteCriticalSection(graphdrawing);
1563
freemem(pal,sizeof(RGBrec)*maxcolor);
1565
MessageThreadID := 0;
1566
MessageThreadHandle := 0;
1567
isgraphmode := false;
1570
procedure LineWin32GUI(X1, Y1, X2, Y2: smallint); {$ifndef fpc}far;{$endif fpc}
1572
var X, Y : smallint;
1573
deltax, deltay : smallint;
1574
d, dinc1, dinc2: smallint;
1580
Flag : Boolean; { determines pixel direction in thick lines }
1581
NumPixels : smallint;
1582
PixelCount : smallint;
1583
OldCurrentColor: Word;
1585
TmpNumPixels : smallint;
1590
if graphrunning then
1592
{******************************************}
1594
{******************************************}
1595
if lineinfo.LineStyle = SolidLn then
1597
{ Convert to global coordinates. }
1598
x1 := x1 + StartXViewPort;
1599
x2 := x2 + StartXViewPort;
1600
y1 := y1 + StartYViewPort;
1601
y2 := y2 + StartYViewPort;
1602
{ if fully clipped then exit... }
1605
if LineClipped(x1,y1,x2,y2,StartXViewPort, StartYViewPort,
1606
StartXViewPort+ViewWidth, StartYViewPort+ViewHeight) then
1608
If LineInfo.Thickness=NormWidth then
1610
EnterCriticalSection(graphdrawing);
1612
if currentwritemode<>normalput then
1614
case currentwritemode of
1617
SetROP2(windc,R2_XORPEN);
1618
SetROP2(bitmapdc,R2_XORPEN);
1622
SetROP2(windc,R2_MASKPEN);
1623
SetROP2(bitmapdc,R2_MASKPEN);
1627
SetROP2(windc,R2_MERGEPEN);
1628
SetROP2(bitmapdc,R2_MERGEPEN);
1633
col:=RGB(pal[CurrentColor].red,pal[CurrentColor].green,pal[CurrentColor].blue);
1634
pen:=CreatePen(PS_SOLID,1,col);
1636
writeln('Pen konnte nicht erzeugt werden!');
1638
oldpen:=SelectObject(windc,pen);
1639
MoveToEx(windc,x1,y1,nil);
1640
Windows.LineTo(windc,x2,y2);
1641
SetPixel(windc,x2,y2,col);
1642
SelectObject(windc,oldpen);
1644
oldpen:=SelectObject(bitmapdc,pen);
1645
MoveToEx(bitmapdc,x1,y1,nil);
1646
Windows.LineTo(bitmapdc,x2,y2);
1647
SetPixel(bitmapdc,x2,y2,col);
1648
SelectObject(bitmapdc,oldpen);
1652
if currentwritemode<>normalput then
1654
SetROP2(windc,R2_COPYPEN);
1655
SetROP2(bitmapdc,R2_COPYPEN);
1658
LeaveCriticalSection(graphdrawing);
1661
{ Thick width lines }
1664
for i := 1 to numpixels do
1666
{ all depending on the slope, we can determine }
1667
{ in what direction the extra width pixels will be put }
1670
DirectPutPixelClip(x-1,y);
1671
DirectPutPixelClip(x,y);
1672
DirectPutPixelClip(x+1,y);
1676
DirectPutPixelClip(x, y-1);
1677
DirectPutPixelClip(x, y);
1678
DirectPutPixelClip(x, y+1);
1697
{******************************************}
1698
{ begin patterned lines }
1699
{******************************************}
1701
{ Convert to global coordinates. }
1702
x1 := x1 + StartXViewPort;
1703
x2 := x2 + StartXViewPort;
1704
y1 := y1 + StartYViewPort;
1705
y2 := y2 + StartYViewPort;
1706
{ if fully clipped then exit... }
1709
if LineClipped(x1,y1,x2,y2,StartXViewPort, StartYViewPort,
1710
StartXViewPort+ViewWidth, StartYViewPort+ViewHeight) then
1714
OldCurrentColor := CurrentColor;
1718
{ Check if we must swap }
1725
if LineInfo.Thickness = NormWidth then
1727
for PixelCount:=x1 to x2 do
1728
{ optimization: PixelCount mod 16 }
1729
if LinePatterns[PixelCount and 15] = TRUE then
1731
DirectPutPixel(PixelCount,y2);
1738
for PixelCount:=x1 to x2 do
1739
{ Optimization from Thomas - mod 16 = and 15 }
1740
{this optimization has been performed by the compiler
1741
for while as well (JM)}
1742
if LinePatterns[PixelCount and 15] = TRUE then
1744
DirectPutPixelClip(PixelCount,y2+i);
1752
{ Check if we must swap }
1759
if LineInfo.Thickness = NormWidth then
1761
for PixelCount:=y1 to y2 do
1762
{ compare if we should plot a pixel here , compare }
1763
{ with predefined line patterns... }
1764
if LinePatterns[PixelCount and 15] = TRUE then
1766
DirectPutPixel(x1,PixelCount);
1773
for PixelCount:=y1 to y2 do
1774
{ compare if we should plot a pixel here , compare }
1775
{ with predefined line patterns... }
1776
if LinePatterns[PixelCount and 15] = TRUE then
1778
DirectPutPixelClip(x1+i,PixelCount);
1785
oldCurrentColor := CurrentColor;
1786
{ Calculate deltax and deltay for initialisation }
1787
deltax := abs(x2 - x1);
1788
deltay := abs(y2 - y1);
1790
{ Initialize all vars based on which is the independent variable }
1791
if deltax >= deltay then
1795
{ x is independent variable }
1796
numpixels := deltax + 1;
1797
d := (2 * deltay) - deltax;
1798
dinc1 := deltay Shl 1;
1799
dinc2 := (deltay - deltax) shl 1;
1809
{ y is independent variable }
1810
numpixels := deltay + 1;
1811
d := (2 * deltax) - deltay;
1812
dinc1 := deltax Shl 1;
1813
dinc2 := (deltax - deltay) shl 1;
1820
{ Make sure x and y move in the right directions }
1832
{ Start drawing at <x1, y1> }
1836
If LineInfo.Thickness=ThickWidth then
1839
TmpNumPixels := NumPixels-1;
1841
for i := 0 to TmpNumPixels do
1843
{ all depending on the slope, we can determine }
1844
{ in what direction the extra width pixels will be put }
1847
{ compare if we should plot a pixel here , compare }
1848
{ with predefined line patterns... }
1849
if LinePatterns[i and 15] = TRUE then
1851
DirectPutPixelClip(x-1,y);
1852
DirectPutPixelClip(x,y);
1853
DirectPutPixelClip(x+1,y);
1858
{ compare if we should plot a pixel here , compare }
1859
{ with predefined line patterns... }
1860
if LinePatterns[i and 15] = TRUE then
1862
DirectPutPixelClip(x,y-1);
1863
DirectPutPixelClip(x,y);
1864
DirectPutPixelClip(x,y+1);
1883
{ instead of putting in loop , substract by one now }
1884
TmpNumPixels := NumPixels-1;
1886
for i := 0 to TmpNumPixels do
1888
if LinePatterns[i and 15] = TRUE then
1890
DirectPutPixel(x,y);
1907
{******************************************}
1908
{ end patterned lines }
1909
{******************************************}
1911
CurrentColor:=OldCurrentColor;
1916
{ multipage support could be done by using more than one background bitmap }
1917
procedure SetVisualWin32GUI(page: word);
1922
procedure SetActiveWin32GUI(page: word);
1926
function queryadapterinfo : pmodeinfo;
1930
ScreenWidth,ScreenHeight : longint;
1931
ScreenWidthMaximized,ScreenHeightMaximized : longint;
1933
procedure SetupWin32GUIDefault;
1936
mode.DirectPutPixel:={$ifdef fpc}@{$endif}DirectPutPixel16Win32GUI;
1937
mode.PutPixel:={$ifdef fpc}@{$endif}PutPixel16Win32GUI;
1938
mode.GetPixel:={$ifdef fpc}@{$endif}GetPixel16Win32GUI;
1939
mode.HLine := {$ifdef fpc}@{$endif}HLine16Win32GUI;
1940
mode.SetRGBPalette := {$ifdef fpc}@{$endif}SetRGBPaletteWin32GUI;
1941
mode.GetRGBPalette := {$ifdef fpc}@{$endif}GetRGBPaletteWin32GUI;
1942
mode.SetVisualPage := {$ifdef fpc}@{$endif}SetVisualWin32GUI;
1943
mode.SetActivePage := {$ifdef fpc}@{$endif}SetActiveWin32GUI;
1944
mode.InitMode := {$ifdef fpc}@{$endif}InitWin32GUI16colors;
1945
mode.OuttextXY:={$ifdef fpc}@{$endif}OuttextXYWin32GUI;
1946
mode.VLine := {$ifdef fpc}@{$endif}VLine16Win32GUI;
1947
// mode.circle := {$ifdef fpc}@{$endif}Circle16Win32GUI;
1949
// mode.Line:={$ifdef fpc}@{$endif}LineWin32GUI;
1953
SaveVideoState:={$ifdef fpc}@{$endif}savestate;
1954
RestoreVideoState:={$ifdef fpc}@{$endif}restorestate;
1955
{ we must take care of the border and caption }
1956
ScreenWidth:=GetSystemMetrics(SM_CXSCREEN)-
1957
2*GetSystemMetrics(SM_CXFRAME);
1958
ScreenHeight:=GetSystemMetrics(SM_CYSCREEN)-
1959
2*GetSystemMetrics(SM_CYFRAME)-
1960
GetSystemMetrics(SM_CYCAPTION);
1961
{ for maximozed windows it's again different }
1962
{ here we've only a caption }
1963
ScreenWidthMaximized:=GetSystemMetrics(SM_CXFULLSCREEN);
1964
{ neither GetSystemMetrics(SM_CYFULLSCREEN nor }
1965
{ SystemParametersInfo(SPI_GETWORKAREA) }
1966
{ takes a hidden try into account :( FK }
1967
ScreenHeightMaximized:=GetSystemMetrics(SM_CYFULLSCREEN);
1969
QueryAdapterInfo := ModeList;
1970
{ If the mode listing already exists... }
1971
{ simply return it, without changing }
1973
if assigned(ModeList) then
1975
{ the first one becomes the standard mode }
1976
if (ScreenWidth>=640) and (ScreenHeight>=480) then
1979
mode.DriverNumber:= VGA;
1980
mode.HardwarePages:= 0;
1981
mode.ModeNumber:=VGAHi;
1982
mode.ModeName:='640 x 480 x 16 Win32GUI';
1983
mode.MaxColor := 16;
1984
mode.PaletteSize := mode.MaxColor;
1985
mode.DirectColor := FALSE;
1988
SetupWin32GUIDefault;
1989
mode.XAspect := 10000;
1990
mode.YAspect := 10000;
1993
if (ScreenWidth>=640) and (ScreenHeight>=200) then
1996
{ now add all standard VGA modes... }
1997
mode.DriverNumber:= VGA;
1998
mode.HardwarePages:= 0;
1999
mode.ModeNumber:=VGALo;
2000
mode.ModeName:='640 x 200 x 16 Win32GUI';
2001
mode.MaxColor := 16;
2002
mode.PaletteSize := mode.MaxColor;
2003
mode.DirectColor := FALSE;
2006
SetupWin32GUIDefault;
2007
mode.XAspect := 10000;
2008
mode.YAspect := 10000;
2011
if (ScreenWidth>=640) and (ScreenHeight>=350) then
2014
mode.DriverNumber:= VGA;
2015
mode.HardwarePages:= 0;
2016
mode.ModeNumber:=VGAMed;
2017
mode.ModeName:='640 x 350 x 16 Win32GUI';
2018
mode.MaxColor := 16;
2019
mode.PaletteSize := mode.MaxColor;
2020
mode.DirectColor := FALSE;
2023
SetupWin32GUIDefault;
2024
mode.XAspect := 10000;
2025
mode.YAspect := 10000;
2028
if (ScreenWidth>=640) and (ScreenHeight>=400) then
2031
mode.DriverNumber:= VESA;
2032
mode.HardwarePages:= 0;
2033
mode.ModeNumber:=m640x400x256;
2034
mode.ModeName:='640 x 400 x 256 Win32GUI';
2035
mode.MaxColor := 256;
2036
mode.PaletteSize := mode.MaxColor;
2037
mode.DirectColor := FALSE;
2040
SetupWin32GUIDefault;
2041
mode.XAspect := 10000;
2042
mode.YAspect := 10000;
2045
if (ScreenWidth>=640) and (ScreenHeight>=480) then
2048
mode.DriverNumber:= VESA;
2049
mode.HardwarePages:= 0;
2050
mode.ModeNumber:=m640x480x256;
2051
mode.ModeName:='640 x 480 x 256 Win32GUI';
2052
mode.MaxColor := 256;
2053
mode.PaletteSize := mode.MaxColor;
2054
mode.DirectColor := FALSE;
2057
SetupWin32GUIDefault;
2058
mode.XAspect := 10000;
2059
mode.YAspect := 10000;
2062
{ add 800x600 only if screen is large enough }
2063
If (ScreenWidth>=800) and (ScreenHeight>=600) then
2066
mode.DriverNumber:= VESA;
2067
mode.HardwarePages:= 0;
2068
mode.ModeNumber:=m800x600x16;
2069
mode.ModeName:='800 x 600 x 16 Win32GUI';
2070
mode.MaxColor := 16;
2071
mode.PaletteSize := mode.MaxColor;
2072
mode.DirectColor := FALSE;
2075
SetupWin32GUIDefault;
2076
mode.XAspect := 10000;
2077
mode.YAspect := 10000;
2080
mode.DriverNumber:= VESA;
2081
mode.HardwarePages:= 0;
2082
mode.ModeNumber:=m800x600x256;
2083
mode.ModeName:='800 x 600 x 256 Win32GUI';
2084
mode.MaxColor := 256;
2085
mode.PaletteSize := mode.MaxColor;
2086
mode.DirectColor := FALSE;
2089
SetupWin32GUIDefault;
2090
mode.XAspect := 10000;
2091
mode.YAspect := 10000;
2094
{ add 1024x768 only if screen is large enough }
2095
If (ScreenWidth>=1024) and (ScreenHeight>=768) then
2098
mode.DriverNumber:= VESA;
2099
mode.HardwarePages:= 0;
2100
mode.ModeNumber:=m1024x768x16;
2101
mode.ModeName:='1024 x 768 x 16 Win32GUI';
2102
mode.MaxColor := 16;
2103
mode.PaletteSize := mode.MaxColor;
2104
mode.DirectColor := FALSE;
2107
SetupWin32GUIDefault;
2108
mode.XAspect := 10000;
2109
mode.YAspect := 10000;
2112
mode.DriverNumber:= VESA;
2113
mode.HardwarePages:= 0;
2114
mode.ModeNumber:=m1024x768x256;
2115
mode.ModeName:='1024 x 768 x 256 Win32GUI';
2116
mode.MaxColor := 256;
2117
mode.PaletteSize := mode.MaxColor;
2118
mode.DirectColor := FALSE;
2121
SetupWin32GUIDefault;
2122
mode.XAspect := 10000;
2123
mode.YAspect := 10000;
2126
{ add 1280x1024 only if screen is large enough }
2127
If (ScreenWidth>=1280) and (ScreenHeight>=1024) then
2130
mode.DriverNumber:= VESA;
2131
mode.HardwarePages:= 0;
2132
mode.ModeNumber:=m1280x1024x16;
2133
mode.ModeName:='1280 x 1024 x 16 Win32GUI';
2134
mode.MaxColor := 16;
2135
mode.PaletteSize := mode.MaxColor;
2136
mode.DirectColor := FALSE;
2139
SetupWin32GUIDefault;
2140
mode.XAspect := 10000;
2141
mode.YAspect := 10000;
2144
mode.DriverNumber:= VESA;
2145
mode.HardwarePages:= 0;
2146
mode.ModeNumber:=m1280x1024x256;
2147
mode.ModeName:='1280 x 1024 x 256 Win32GUI';
2148
mode.MaxColor := 256;
2149
mode.PaletteSize := mode.MaxColor;
2150
mode.DirectColor := FALSE;
2153
SetupWin32GUIDefault;
2154
mode.XAspect := 10000;
2155
mode.YAspect := 10000;
2158
{ at least we add a mode with the largest possible window }
2160
mode.DriverNumber:= VESA;
2161
mode.HardwarePages:= 0;
2162
mode.ModeNumber:=mLargestWindow16;
2163
mode.ModeName:='Largest Window x 16';
2164
mode.MaxColor := 16;
2165
mode.PaletteSize := mode.MaxColor;
2166
mode.DirectColor := FALSE;
2167
mode.MaxX := ScreenWidth-1;
2168
mode.MaxY := ScreenHeight-1;
2169
SetupWin32GUIDefault;
2170
mode.XAspect := 10000;
2171
mode.YAspect := 10000;
2174
mode.DriverNumber:= VESA;
2175
mode.HardwarePages:= 0;
2176
mode.ModeNumber:=mLargestWindow256;
2177
mode.ModeName:='Largest Window x 256';
2178
mode.MaxColor := 256;
2179
mode.PaletteSize := mode.MaxColor;
2180
mode.DirectColor := FALSE;
2181
mode.MaxX := ScreenWidth-1;
2182
mode.MaxY := ScreenHeight-1;
2183
SetupWin32GUIDefault;
2184
mode.XAspect := 10000;
2185
mode.YAspect := 10000;
2187
{ .. and a maximized window }
2189
mode.DriverNumber:= VESA;
2190
mode.HardwarePages:= 0;
2191
mode.ModeNumber:=mMaximizedWindow16;
2192
mode.ModeName:='Maximized Window x 16';
2193
mode.MaxColor := 16;
2194
mode.PaletteSize := mode.MaxColor;
2195
mode.DirectColor := FALSE;
2196
mode.MaxX := ScreenWidthMaximized-1;
2197
mode.MaxY := ScreenHeightMaximized-1;
2198
SetupWin32GUIDefault;
2199
mode.XAspect := 10000;
2200
mode.YAspect := 10000;
2203
mode.DriverNumber:= VESA;
2204
mode.HardwarePages:= 0;
2205
mode.ModeNumber:=mMaximizedWindow256;
2206
mode.ModeName:='Maximized Window x 256';
2207
mode.MaxColor := 256;
2208
mode.PaletteSize := mode.MaxColor;
2209
mode.DirectColor := FALSE;
2210
mode.MaxX := ScreenWidthMaximized-1;
2211
mode.MaxY := ScreenHeightMaximized-1;
2212
SetupWin32GUIDefault;
2213
mode.XAspect := 10000;
2214
mode.YAspect := 10000;
2220
charmessagehandler:=nil;
2221
mousemessagehandler:=nil;
2222
commandmessagehandler:=nil;
2223
notifymessagehandler:=nil;
2224
OnGraphWindowCreation:=nil;