~ubuntu-branches/debian/lenny/fpc/lenny

« back to all changes in this revision

Viewing changes to fpcsrc/packages/base/graph/win32/graph.pp

  • Committer: Bazaar Package Importer
  • Author(s): Mazen Neifer, Torsten Werner, Mazen Neifer
  • Date: 2008-05-17 17:12:11 UTC
  • mfrom: (3.1.9 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080517171211-9qi33xhd9evfa0kg
Tags: 2.2.0-dfsg1-9
[ Torsten Werner ]
* Add Mazen Neifer to Uploaders field.

[ Mazen Neifer ]
* Moved FPC sources into a version dependent directory from /usr/share/fpcsrc
  to /usr/share/fpcsrc/${FPCVERSION}. This allow installing more than on FPC
  release.
* Fixed far call issue in compiler preventing building huge binearies.
  (closes: #477743)
* Updated building dependencies, recomennded and suggested packages.
* Moved fppkg to fp-utils as it is just a helper tool and is not required by
  compiler.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
{
 
2
    This file is part of the Free Pascal run time library.
 
3
    Copyright (c) 1999-2000 by Florian Klaempfl
 
4
 
 
5
    This file implements the win32 gui support for the graph unit
 
6
 
 
7
    See the file COPYING.FPC, included in this distribution,
 
8
    for details about the copyright.
 
9
 
 
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.
 
13
 
 
14
 **********************************************************************}
 
15
unit Graph;
 
16
interface
 
17
 
 
18
uses
 
19
  windows;
 
20
 
 
21
{$i graphh.inc}
 
22
 
 
23
  var
 
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;
 
31
 
 
32
    OnGraphWindowCreation : procedure;
 
33
 
 
34
    GraphWindow,ParentWindow : HWnd;
 
35
    // this allows direct drawing to the window
 
36
    bitmapdc : hdc;
 
37
    windc : hdc;
 
38
 
 
39
  const
 
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;
 
45
 
 
46
    windowtitle : pchar = 'Graph window application';
 
47
    menu : hmenu = 0;
 
48
    icon : hicon = 0;
 
49
    drawtoscreen : boolean = true;
 
50
    drawtobitmap : boolean = true;
 
51
    // the graph window can be a child window, this allows to add toolbars
 
52
    // to the main window
 
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);
 
56
 
 
57
CONST
 
58
 
 
59
  m640x200x16       = VGALo;
 
60
  m640x400x16       = VGAMed;
 
61
  m640x480x16       = VGAHi;
 
62
 
 
63
  { VESA Specific video modes. }
 
64
  m320x200x32k      = $10D;
 
65
  m320x200x64k      = $10E;
 
66
 
 
67
  m640x400x256      = $100;
 
68
 
 
69
  m640x480x256      = $101;
 
70
  m640x480x32k      = $110;
 
71
  m640x480x64k      = $111;
 
72
 
 
73
  m800x600x16       = $102;
 
74
  m800x600x256      = $103;
 
75
  m800x600x32k      = $113;
 
76
  m800x600x64k      = $114;
 
77
 
 
78
  m1024x768x16      = $104;
 
79
  m1024x768x256     = $105;
 
80
  m1024x768x32k     = $116;
 
81
  m1024x768x64k     = $117;
 
82
 
 
83
  m1280x1024x16     = $106;
 
84
  m1280x1024x256    = $107;
 
85
  m1280x1024x32k    = $119;
 
86
  m1280x1024x64k    = $11A;
 
87
 
 
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;
 
99
 
 
100
 
 
101
implementation
 
102
 
 
103
uses
 
104
  strings;
 
105
 
 
106
{
 
107
   Remarks:
 
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
 
117
}
 
118
 
 
119
 
 
120
const
 
121
   InternalDriverName = 'WIN32GUI';
 
122
 
 
123
{$i graph.inc}
 
124
 
 
125
 
 
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}
 
129
var
 
130
   savedscreen : hbitmap;
 
131
   graphrunning : boolean;
 
132
   graphdrawing : tcriticalsection;
 
133
   pens : array[0..15] of HPEN;
 
134
{$ifdef DEBUG_WM_PAINT}
 
135
   graphdebug : text;
 
136
 
 
137
const
 
138
   wm_paint_count : longint = 0;
 
139
var
 
140
{$endif DEBUG_WM_PAINT}
 
141
   oldbitmap : hgdiobj;
 
142
   pal : ^rgbrec;
 
143
//   SavePtr : pointer; { we don't use that pointer }
 
144
   MessageThreadHandle : Handle;
 
145
   MessageThreadID : DWord;
 
146
 
 
147
function GetPaletteEntry(r,g,b : word) : word;
 
148
 
 
149
  var
 
150
     dist,i,index,currentdist : longint;
 
151
 
 
152
  begin
 
153
     dist:=$7fffffff;
 
154
     index:=0;
 
155
     for i:=0 to maxcolors do
 
156
       begin
 
157
          currentdist:=abs(r-pal[i].red)+abs(g-pal[i].green)+
 
158
            abs(b-pal[i].blue);
 
159
          if currentdist<dist then
 
160
            begin
 
161
               index:=i;
 
162
               dist:=currentdist;
 
163
               if dist=0 then
 
164
                 break;
 
165
            end;
 
166
       end;
 
167
     GetPaletteEntry:=index;
 
168
  end;
 
169
 
 
170
procedure PutPixel16Win32GUI(x,y : smallint;pixel : word);
 
171
 
 
172
  var
 
173
     c : colorref;
 
174
 
 
175
  begin
 
176
    x:=x+startxviewport;
 
177
    y:=y+startyviewport;
 
178
    { convert to absolute coordinates and then verify clipping...}
 
179
    if clippixels then
 
180
      begin
 
181
         if (x<startxviewport) or (x>(startxviewport+viewwidth)) or
 
182
           (y<StartyViewPort) or (y>(startyviewport+viewheight)) then
 
183
           exit;
 
184
      end;
 
185
    if graphrunning then
 
186
      begin
 
187
         c:=RGB(pal[pixel].red,pal[pixel].green,pal[pixel].blue);
 
188
         EnterCriticalSection(graphdrawing);
 
189
         if drawtobitmap then
 
190
           SetPixelV(bitmapdc,x,y,c);
 
191
         if drawtoscreen then
 
192
           SetPixelV(windc,x,y,c);
 
193
         LeaveCriticalSection(graphdrawing);
 
194
      end;
 
195
  end;
 
196
 
 
197
function GetPixel16Win32GUI(x,y : smallint) : word;
 
198
 
 
199
  var
 
200
     c : COLORREF;
 
201
 
 
202
  begin
 
203
    x:=x+startxviewport;
 
204
    y:=y+startyviewport;
 
205
    { convert to absolute coordinates and then verify clipping...}
 
206
    if clippixels then
 
207
      begin
 
208
         if (x<startxviewport) or (x>(startxviewport+viewwidth)) or
 
209
           (y<StartyViewPort) or (y>(startyviewport+viewheight)) then
 
210
           exit;
 
211
      end;
 
212
    if graphrunning then
 
213
      begin
 
214
         EnterCriticalSection(graphdrawing);
 
215
         c:=Windows.GetPixel(bitmapdc,x,y);
 
216
         LeaveCriticalSection(graphdrawing);
 
217
         GetPixel16Win32GUI:=GetPaletteEntry(GetRValue(c),GetGValue(c),GetBValue(c));
 
218
      end
 
219
    else
 
220
      begin
 
221
        _graphresult:=grerror;
 
222
        exit;
 
223
      end;
 
224
  end;
 
225
 
 
226
procedure DirectPutPixel16Win32GUI(x,y : smallint);
 
227
 
 
228
  var
 
229
     col : longint;
 
230
     c,c2 : COLORREF;
 
231
 
 
232
  begin
 
233
    if graphrunning then
 
234
      begin
 
235
         EnterCriticalSection(graphdrawing);
 
236
         col:=CurrentColor;
 
237
         case currentwritemode of
 
238
           XorPut:
 
239
             Begin
 
240
                c2:=Windows.GetPixel(windc,x,y);
 
241
                c:=RGB(pal[col].red,pal[col].green,pal[col].blue) xor c2;
 
242
                if drawtobitmap then
 
243
                  SetPixelV(bitmapdc,x,y,c);
 
244
                if drawtoscreen then
 
245
                  SetPixelV(windc,x,y,c);
 
246
             End;
 
247
           AndPut:
 
248
             Begin
 
249
                c2:=Windows.GetPixel(windc,x,y);
 
250
                c:=RGB(pal[col].red,pal[col].green,pal[col].blue) and c2;
 
251
                if drawtobitmap then
 
252
                  SetPixelV(bitmapdc,x,y,c);
 
253
                if drawtoscreen then
 
254
                  SetPixelV(windc,x,y,c);
 
255
             End;
 
256
           OrPut:
 
257
             Begin
 
258
                c2:=Windows.GetPixel(windc,x,y);
 
259
                c:=RGB(pal[col].red,pal[col].green,pal[col].blue) or c2;
 
260
                if drawtobitmap then
 
261
                  SetPixelV(bitmapdc,x,y,c);
 
262
                if drawtoscreen then
 
263
                  SetPixelV(windc,x,y,c);
 
264
             End
 
265
           else
 
266
             Begin
 
267
                If CurrentWriteMode<>NotPut Then
 
268
                  col:=CurrentColor
 
269
                Else col := Not(CurrentColor);
 
270
                c:=RGB(pal[col].red,pal[col].green,pal[col].blue);
 
271
                if drawtobitmap then
 
272
                  SetPixelV(bitmapdc,x,y,c);
 
273
                if drawtoscreen then
 
274
                  SetPixelV(windc,x,y,c);
 
275
             End
 
276
         end;
 
277
         LeaveCriticalSection(graphdrawing);
 
278
      end;
 
279
  end;
 
280
 
 
281
var
 
282
   bitmapfontverticalcache : array[0..255] of HBITMAP;
 
283
   bitmapfonthorizoncache : array[0..255] of HBITMAP;
 
284
 
 
285
procedure OutTextXYWin32GUI(x,y : smallint;const TextString : string);
 
286
 
 
287
  type
 
288
   Tpoint = record
 
289
     X,Y: smallint;
 
290
   end;
 
291
  var
 
292
     i,j,k,c       : longint;
 
293
     xpos,ypos     : longint;
 
294
     counter       : longint;
 
295
     cnt1,cnt2     : smallint;
 
296
     cnt3,cnt4     : smallint;
 
297
     charsize      : word;
 
298
     WriteMode     : word;
 
299
     curX2, curY2, xpos2, ypos2, x2, y2: graph_float;
 
300
     oldvalues     : linesettingstype;
 
301
     fontbitmap    : TBitmapChar;
 
302
     chr           : char;
 
303
     curx2i,cury2i,
 
304
     xpos2i,ypos2i : longint;
 
305
     charbitmap,oldcharbitmap : HBITMAP;
 
306
     chardc : HDC;
 
307
     color : longint;
 
308
     brushwin,oldbrushwin,brushbitmap,oldbrushbitmap : HBRUSH;
 
309
     bitmaprgn,winrgn : HRGN;
 
310
 
 
311
  begin
 
312
     { save current write mode }
 
313
     WriteMode := CurrentWriteMode;
 
314
     CurrentWriteMode := NormalPut;
 
315
     GetTextPosition(xpos,ypos,textstring);
 
316
     X:=X-XPos; Y:=Y+YPos;
 
317
     XPos:=X; YPos:=Y;
 
318
     CharSize := CurrentTextInfo.Charsize;
 
319
     if Currenttextinfo.font=DefaultFont then
 
320
     begin
 
321
       if CurrentTextInfo.direction=HorizDir then
 
322
       { Horizontal direction }
 
323
         begin
 
324
            if (x>viewwidth) or (y>viewheight) or
 
325
              (x<0) or (y<0) then
 
326
              begin
 
327
                 CurrentWriteMode:=WriteMode;
 
328
                 exit;
 
329
              end;
 
330
            EnterCriticalSection(graphdrawing);
 
331
            c:=length(textstring);
 
332
            chardc:=CreateCompatibleDC(windc);
 
333
            if currentcolor<>white then
 
334
              begin
 
335
                 color:=RGB(pal[currentcolor].red,pal[currentcolor].green,
 
336
                   pal[currentcolor].blue);
 
337
 
 
338
                 if drawtoscreen then
 
339
                   begin
 
340
                      brushwin:=CreateSolidBrush(color);
 
341
                      oldbrushwin:=SelectObject(windc,brushwin);
 
342
                   end;
 
343
 
 
344
                 if drawtobitmap then
 
345
                   begin
 
346
                      brushbitmap:=CreateSolidBrush(color);
 
347
                      oldbrushbitmap:=SelectObject(bitmapdc,brushbitmap);
 
348
                   end;
 
349
              end;
 
350
            inc(x,startxviewport);
 
351
            inc(y,startyviewport);
 
352
 
 
353
            { let windows do the clipping }
 
354
            if drawtobitmap then
 
355
              begin
 
356
                 bitmaprgn:=CreateRectRgn(startxviewport,startyviewport,
 
357
                   startxviewport+viewwidth+1,startyviewport+viewheight+1);
 
358
                 SelectClipRgn(bitmapdc,bitmaprgn);
 
359
              end;
 
360
 
 
361
            if drawtoscreen then
 
362
              begin
 
363
                 winrgn:=CreateRectRgn(startxviewport,startyviewport,
 
364
                   startxviewport+viewwidth+1,startyviewport+viewheight+1);
 
365
                 SelectClipRgn(windc,winrgn);
 
366
              end;
 
367
 
 
368
            for i:=0 to c-1 do
 
369
              begin
 
370
                 xpos:=x+(i*8)*Charsize;
 
371
                 if bitmapfonthorizoncache[byte(textstring[i+1])]=0 then
 
372
                   begin
 
373
                      charbitmap:=CreateCompatibleBitmap(windc,8,8);
 
374
                      if charbitmap=0 then
 
375
                        writeln('Bitmap konnte nicht erzeugt werden!');
 
376
                      oldcharbitmap:=SelectObject(chardc,charbitmap);
 
377
                      Fontbitmap:=TBitmapChar(DefaultFontData[textstring[i+1]]);
 
378
 
 
379
                      for j:=0 to 7 do
 
380
                         for k:=0 to 7 do
 
381
                           if Fontbitmap[j,k]<>0 then
 
382
                             SetPixelV(chardc,k,j,$ffffff)
 
383
                           else
 
384
                             SetPixelV(chardc,k,j,0);
 
385
                      bitmapfonthorizoncache[byte(textstring[i+1])]:=charbitmap;
 
386
                      SelectObject(chardc,oldcharbitmap);
 
387
                   end;
 
388
                 oldcharbitmap:=SelectObject(chardc,bitmapfonthorizoncache[byte(textstring[i+1])]);
 
389
                 if CharSize=1 then
 
390
                   begin
 
391
                      if currentcolor=white then
 
392
                        begin
 
393
                           if drawtoscreen then
 
394
                             BitBlt(windc,xpos,y,8,8,chardc,0,0,SRCPAINT);
 
395
                           if drawtobitmap then
 
396
                             BitBlt(bitmapdc,xpos,y,8,8,chardc,0,0,SRCPAINT);
 
397
                        end
 
398
                      else
 
399
                        begin
 
400
                           { could we do this with one pattern operation ?? }
 
401
                           { we would need something like DSnaSPao }
 
402
                           if drawtoscreen then
 
403
                             begin
 
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);
 
408
                             end;
 
409
 
 
410
                           if drawtobitmap then
 
411
                             begin
 
412
                                BitBlt(bitmapdc,xpos,y,8,8,chardc,0,0,$00220326);
 
413
                                BitBlt(bitmapdc,xpos,y,8,8,chardc,0,0,$00EA02E9);
 
414
                             end;
 
415
                        end;
 
416
                   end
 
417
                 else
 
418
                   begin
 
419
                      if currentcolor=white then
 
420
                        begin
 
421
                           if drawtoscreen then
 
422
                             StretchBlt(windc,xpos,y,8*charsize,8*charsize,chardc,0,0,8,8,SRCPAINT);
 
423
                           if drawtobitmap then
 
424
                             StretchBlt(bitmapdc,xpos,y,8*charsize,8*charsize,chardc,0,0,8,8,SRCPAINT);
 
425
                        end
 
426
                      else
 
427
                        begin
 
428
                           { could we do this with one pattern operation ?? }
 
429
                           { we would need something like DSnaSPao }
 
430
                           if drawtoscreen then
 
431
                             begin
 
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);
 
436
                             end;
 
437
                           if drawtobitmap then
 
438
                             begin
 
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);
 
441
                             end;
 
442
                        end;
 
443
                   end;
 
444
                 SelectObject(chardc,oldcharbitmap);
 
445
              end;
 
446
           if currentcolor<>white then
 
447
             begin
 
448
                 if drawtoscreen then
 
449
                   begin
 
450
                      SelectObject(windc,oldbrushwin);
 
451
                      DeleteObject(brushwin);
 
452
                   end;
 
453
 
 
454
                 if drawtobitmap then
 
455
                   begin
 
456
                      SelectObject(bitmapdc,oldbrushbitmap);
 
457
                      DeleteObject(brushbitmap);
 
458
                   end;
 
459
             end;
 
460
           { release clip regions }
 
461
           if drawtobitmap then
 
462
             begin
 
463
               SelectClipRgn(bitmapdc,0);
 
464
               DeleteObject(bitmaprgn);
 
465
             end;
 
466
           if drawtoscreen then
 
467
             begin
 
468
                SelectClipRgn(windc,0);
 
469
                DeleteObject(winrgn);
 
470
             end;
 
471
           DeleteDC(chardc);
 
472
           LeaveCriticalSection(graphdrawing);
 
473
         end
 
474
       else
 
475
       { Vertical direction }
 
476
         begin
 
477
            if (x>viewwidth) or (y>viewheight) or
 
478
              (x<0) or (y<0) then
 
479
              begin
 
480
                 CurrentWriteMode:=WriteMode;
 
481
                 exit;
 
482
              end;
 
483
            EnterCriticalSection(graphdrawing);
 
484
            c:=length(textstring);
 
485
            chardc:=CreateCompatibleDC(windc);
 
486
            if currentcolor<>white then
 
487
              begin
 
488
                 color:=RGB(pal[currentcolor].red,pal[currentcolor].green,
 
489
                   pal[currentcolor].blue);
 
490
 
 
491
                 if drawtoscreen then
 
492
                   begin
 
493
                      brushwin:=CreateSolidBrush(color);
 
494
                      oldbrushwin:=SelectObject(windc,brushwin);
 
495
                   end;
 
496
 
 
497
                 if drawtobitmap then
 
498
                   begin
 
499
                      brushbitmap:=CreateSolidBrush(color);
 
500
                      oldbrushbitmap:=SelectObject(bitmapdc,brushbitmap);
 
501
                   end;
 
502
              end;
 
503
            inc(x,startxviewport);
 
504
            inc(y,startyviewport);
 
505
            { let windows do the clipping }
 
506
            if drawtoscreen then
 
507
              begin
 
508
                 winrgn:=CreateRectRgn(startxviewport,startyviewport,
 
509
                   startxviewport+viewwidth+1,startyviewport+viewheight+1);
 
510
                 SelectClipRgn(windc,winrgn);
 
511
              end;
 
512
 
 
513
            if drawtobitmap then
 
514
              begin
 
515
                 bitmaprgn:=CreateRectRgn(startxviewport,startyviewport,
 
516
                   startxviewport+viewwidth+1,startyviewport+viewheight+1);
 
517
                 SelectClipRgn(bitmapdc,bitmaprgn);
 
518
              end;
 
519
            for i:=0 to c-1 do
 
520
              begin
 
521
                 ypos:=y+1-((i+1)*8)*CharSize;
 
522
                 if bitmapfontverticalcache[byte(textstring[i+1])]=0 then
 
523
                   begin
 
524
                      charbitmap:=CreateCompatibleBitmap(windc,8,8);
 
525
                      if charbitmap=0 then
 
526
                        writeln('Bitmap konnte nicht erzeugt werden!');
 
527
                      oldcharbitmap:=SelectObject(chardc,charbitmap);
 
528
                      Fontbitmap:=TBitmapChar(DefaultFontData[textstring[i+1]]);
 
529
 
 
530
                      for j:=0 to 7 do
 
531
                         for k:=0 to 7 do
 
532
                           if Fontbitmap[j,k]<>0 then
 
533
                             SetPixelV(chardc,j,7-k,$ffffff)
 
534
                           else
 
535
                             SetPixelV(chardc,j,7-k,0);
 
536
                      bitmapfontverticalcache[byte(textstring[i+1])]:=charbitmap;
 
537
                      SelectObject(chardc,oldcharbitmap);
 
538
                   end;
 
539
                 oldcharbitmap:=SelectObject(chardc,bitmapfontverticalcache[byte(textstring[i+1])]);
 
540
                 if CharSize=1 then
 
541
                   begin
 
542
                      if currentcolor=white then
 
543
                        begin
 
544
                           if drawtoscreen then
 
545
                             BitBlt(windc,x,ypos,8,8,chardc,0,0,SRCPAINT);
 
546
                           if drawtobitmap then
 
547
                             BitBlt(bitmapdc,x,ypos,8,8,chardc,0,0,SRCPAINT);
 
548
                        end
 
549
                      else
 
550
                        begin
 
551
                           { could we do this with one pattern operation ?? }
 
552
                           { we would need something like DSnaSPao }
 
553
                           if drawtoscreen then
 
554
                             begin
 
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);
 
559
                             end;
 
560
                           if drawtobitmap then
 
561
                             begin
 
562
                                BitBlt(bitmapdc,x,ypos,8,8,chardc,0,0,$00220326);
 
563
                                BitBlt(bitmapdc,x,ypos,8,8,chardc,0,0,$00EA02E9);
 
564
                             end;
 
565
                        end;
 
566
                   end
 
567
                 else
 
568
                   begin
 
569
                      if currentcolor=white then
 
570
                        begin
 
571
                           if drawtoscreen then
 
572
                             StretchBlt(windc,x,ypos,8*charsize,8*charsize,chardc,0,0,8,8,SRCPAINT);
 
573
                           if drawtobitmap then
 
574
                             StretchBlt(bitmapdc,x,ypos,8*charsize,8*charsize,chardc,0,0,8,8,SRCPAINT);
 
575
                        end
 
576
                      else
 
577
                        begin
 
578
                           { could we do this with one pattern operation ?? }
 
579
                           { we would need something like DSnaSPao }
 
580
                           if drawtoscreen then
 
581
                             begin
 
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);
 
586
                             end;
 
587
                           if drawtobitmap then
 
588
                             begin
 
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);
 
591
                             end;
 
592
                        end;
 
593
                   end;
 
594
                 SelectObject(chardc,oldcharbitmap);
 
595
              end;
 
596
           if currentcolor<>white then
 
597
             begin
 
598
                if drawtoscreen then
 
599
                  begin
 
600
                     SelectObject(windc,oldbrushwin);
 
601
                     DeleteObject(brushwin);
 
602
                  end;
 
603
 
 
604
                if drawtobitmap then
 
605
                  begin
 
606
                     SelectObject(bitmapdc,oldbrushbitmap);
 
607
                     DeleteObject(brushbitmap);
 
608
                  end;
 
609
             end;
 
610
           { release clip regions }
 
611
           if drawtoscreen then
 
612
             begin
 
613
                SelectClipRgn(windc,0);
 
614
                DeleteObject(winrgn);
 
615
             end;
 
616
           if drawtobitmap then
 
617
             begin
 
618
                SelectClipRgn(bitmapdc,0);
 
619
                DeleteObject(bitmaprgn);
 
620
             end;
 
621
           DeleteDC(chardc);
 
622
           LeaveCriticalSection(graphdrawing);
 
623
        end;
 
624
     end else
 
625
     { This is a stroked font which is already loaded into memory }
 
626
       begin
 
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;
 
634
{              x:=xpos; y:=ypos;}
 
635
 
 
636
          for i:=1 to length(textstring) do
 
637
            begin
 
638
               c:=byte(textstring[i]);
 
639
{                   Stroke_Count[c] := }
 
640
               unpack( fonts[CurrentTextInfo.font].instr,
 
641
                 fonts[CurrentTextInfo.font].Offsets[c], Strokes );
 
642
               counter:=0;
 
643
               while true do
 
644
                 begin
 
645
                     if CurrentTextInfo.direction=VertDir then
 
646
                       begin
 
647
                         xpos2:=x2-(Strokes[counter].Y*CurrentYRatio);
 
648
                         ypos2:=y2-(Strokes[counter].X*CurrentXRatio);
 
649
                       end
 
650
                     else
 
651
                       begin
 
652
                         xpos2:=x2+(Strokes[counter].X*CurrentXRatio) ;
 
653
                         ypos2:=y2-(Strokes[counter].Y*CurrentYRatio) ;
 
654
                       end;
 
655
                     case opcodes(Strokes[counter].opcode) of
 
656
                       _END_OF_CHAR: break;
 
657
                       _DO_SCAN: begin
 
658
                                { Currently unsupported };
 
659
                                end;
 
660
                       _MOVE : Begin
 
661
                                 CurX2 := XPos2;
 
662
                                 CurY2 := YPos2;
 
663
                               end;
 
664
                       _DRAW: Begin
 
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
 
671
                                  begin
 
672
                                     if (cury2i=ypos2i) then
 
673
                                       putpixel(curx2i,cury2i,currentcolor)
 
674
                                     else if (cury2i+1=ypos2i) or
 
675
                                       (cury2i=ypos2i+1) then
 
676
                                        begin
 
677
                                           putpixel(curx2i,cury2i,currentcolor);
 
678
                                           putpixel(curx2i,ypos2i,currentcolor);
 
679
                                        end
 
680
                                      else
 
681
                                        Line(curx2i,cury2i,xpos2i,ypos2i);
 
682
                                  end
 
683
                                else if (cury2i=ypos2i) then
 
684
                                  begin
 
685
                                     if (curx2i+1=xpos2i) or
 
686
                                       (curx2i=xpos2i+1) then
 
687
                                        begin
 
688
                                           putpixel(curx2i,cury2i,currentcolor);
 
689
                                           putpixel(xpos2i,cury2i,currentcolor);
 
690
                                        end
 
691
                                      else
 
692
                                        Line(curx2i,cury2i,xpos2i,ypos2i);
 
693
                                  end
 
694
                                else
 
695
                                }
 
696
                                Line(curx2i,cury2i,xpos2i,ypos2i);
 
697
                                CurX2:=xpos2;
 
698
                                CurY2:=ypos2;
 
699
                              end;
 
700
                         else
 
701
                           Begin
 
702
                           end;
 
703
                        end;
 
704
                    Inc(counter);
 
705
                 end; { end while }
 
706
               if Currenttextinfo.direction=VertDir then
 
707
                 y2:=y2-(byte(fonts[CurrenttextInfo.font].widths[c])*CurrentXRatio)
 
708
               else
 
709
                 x2:=x2+(byte(fonts[Currenttextinfo.font].widths[c])*CurrentXRatio);
 
710
            end;
 
711
          setlinestyle( oldvalues.linestyle, oldvalues.pattern, oldvalues.thickness);
 
712
       end;
 
713
    { restore write mode }
 
714
    CurrentWriteMode := WriteMode;
 
715
  end;
 
716
 
 
717
procedure HLine16Win32GUI(x,x2,y: smallint);
 
718
 
 
719
   var
 
720
      c,c2 : COLORREF;
 
721
      col,i : longint;
 
722
      oldpen,pen : HPEN;
 
723
 
 
724
   Begin
 
725
      if graphrunning then
 
726
        begin
 
727
           { must we swap the values? }
 
728
           if x>x2 then
 
729
             Begin
 
730
               x:=x xor x2;
 
731
               x2:=x xor x2;
 
732
               x:=x xor x2;
 
733
             end;
 
734
           if ClipPixels then
 
735
             begin
 
736
                if (x>ViewWidth) or (y<0) or (y>ViewHeight) or (x2<0) then
 
737
                  exit;
 
738
                if x<0 then
 
739
                  x:=0;
 
740
                if x2>ViewWidth then
 
741
                  x2:=ViewWidth;
 
742
             end;
 
743
           X:=X+StartXViewPort;
 
744
           X2:=X2+StartXViewPort;
 
745
           Y:=Y+StartYViewPort;
 
746
           Case CurrentWriteMode of
 
747
             AndPut:
 
748
               Begin
 
749
                  EnterCriticalSection(graphdrawing);
 
750
                  col:=CurrentColor;
 
751
                  for i:=x to x2 do
 
752
                    begin
 
753
                       c2:=Windows.GetPixel(windc,i,y);
 
754
                       c:=RGB(pal[col].red,pal[col].green,pal[col].blue) and c2;
 
755
                       if drawtobitmap then
 
756
                         SetPixelV(bitmapdc,i,y,c);
 
757
 
 
758
                       if drawtoscreen then
 
759
                         SetPixelV(windc,i,y,c);
 
760
                    end;
 
761
                  LeaveCriticalSection(graphdrawing);
 
762
               End;
 
763
             XorPut:
 
764
               Begin
 
765
                  EnterCriticalSection(graphdrawing);
 
766
                  col:=CurrentColor;
 
767
                  for i:=x to x2 do
 
768
                    begin
 
769
                       c2:=Windows.GetPixel(windc,i,y);
 
770
                       c:=RGB(pal[col].red,pal[col].green,pal[col].blue) xor c2;
 
771
 
 
772
                       if drawtobitmap then
 
773
                         SetPixelV(bitmapdc,i,y,c);
 
774
 
 
775
                       if drawtoscreen then
 
776
                         SetPixelV(windc,i,y,c);
 
777
                    end;
 
778
                  LeaveCriticalSection(graphdrawing);
 
779
               End;
 
780
             OrPut:
 
781
               Begin
 
782
                  EnterCriticalSection(graphdrawing);
 
783
                  col:=CurrentColor;
 
784
                  for i:=x to x2 do
 
785
                    begin
 
786
                       c2:=Windows.GetPixel(windc,i,y);
 
787
                       c:=RGB(pal[col].red,pal[col].green,pal[col].blue) or c2;
 
788
 
 
789
                       if drawtobitmap then
 
790
                         SetPixelV(bitmapdc,i,y,c);
 
791
 
 
792
                       if drawtoscreen then
 
793
                         SetPixelV(windc,i,y,c);
 
794
                    end;
 
795
                  LeaveCriticalSection(graphdrawing);
 
796
               End
 
797
             Else
 
798
               Begin
 
799
                  If CurrentWriteMode<>NotPut Then
 
800
                    col:=CurrentColor
 
801
                  Else col:=Not(CurrentColor);
 
802
                  EnterCriticalSection(graphdrawing);
 
803
                  if x2-x<=2 then
 
804
                    begin
 
805
                       c:=RGB(pal[col].red,pal[col].green,pal[col].blue);
 
806
                       for x := x to x2 do
 
807
                         begin
 
808
                            if drawtobitmap then
 
809
                              SetPixelV(bitmapdc,x,y,c);
 
810
                            if drawtoscreen then
 
811
                              SetPixelV(windc,x,y,c);
 
812
                         end;
 
813
                    end
 
814
                  else
 
815
                    begin
 
816
                       if (col>=0) and (col<=high(pens)) then
 
817
                         begin
 
818
                            if pens[col]=0 then
 
819
                              begin
 
820
                                 c:=RGB(pal[col].red,pal[col].green,pal[col].blue);
 
821
                                 pens[col]:=CreatePen(PS_SOLID,1,c);
 
822
                              end;
 
823
                            pen:=pens[col];
 
824
                         end
 
825
                       else
 
826
                         begin
 
827
                            c:=RGB(pal[col].red,pal[col].green,pal[col].blue);
 
828
                            pen:=CreatePen(PS_SOLID,1,c);
 
829
                         end;
 
830
 
 
831
                       if drawtobitmap then
 
832
                         begin
 
833
                            oldpen:=SelectObject(bitmapdc,pen);
 
834
                            Windows.MoveToEx(bitmapdc,x,y,nil);
 
835
                            Windows.LineTo(bitmapdc,x2+1,y);
 
836
                            SelectObject(bitmapdc,oldpen);
 
837
                         end;
 
838
 
 
839
                       if drawtoscreen then
 
840
                         begin
 
841
                            oldpen:=SelectObject(windc,pen);
 
842
                            Windows.MoveToEx(windc,x,y,nil);
 
843
                            Windows.LineTo(windc,x2+1,y);
 
844
                            SelectObject(windc,oldpen);
 
845
                         end;
 
846
 
 
847
                       if (col<0) or (col>high(pens)) then
 
848
                         DeleteObject(pen);
 
849
                    end;
 
850
                   LeaveCriticalSection(graphdrawing);
 
851
               End;
 
852
           End;
 
853
        end;
 
854
   end;
 
855
 
 
856
procedure VLine16Win32GUI(x,y,y2: smallint); {$ifndef fpc}far;{$endif fpc}
 
857
 
 
858
 var
 
859
  ytmp: smallint;
 
860
  col,c : longint;
 
861
  oldpen,pen : HPEN;
 
862
 
 
863
Begin
 
864
  { must we swap the values? }
 
865
  if y >= y2 then
 
866
   Begin
 
867
     ytmp := y2;
 
868
     y2 := y;
 
869
     y:= ytmp;
 
870
   end;
 
871
 if ClipPixels then
 
872
   begin
 
873
      if (x>ViewWidth) or (x<0) or (y>ViewHeight) or (y2<0) then
 
874
        exit;
 
875
      if y<0 then
 
876
        y:=0;
 
877
      if y2>ViewHeight then
 
878
        y2:=ViewHeight;
 
879
   end;
 
880
  { First convert to global coordinates }
 
881
  X   := X + StartXViewPort;
 
882
  Y2  := Y2 + StartYViewPort;
 
883
  Y   := Y + StartYViewPort;
 
884
  if currentwritemode=normalput then
 
885
    begin
 
886
       col:=CurrentColor;
 
887
       EnterCriticalSection(graphdrawing);
 
888
       if y2-y<=2 then
 
889
         begin
 
890
            c:=RGB(pal[col].red,pal[col].green,pal[col].blue);
 
891
            for y := y to y2 do
 
892
              begin
 
893
                 if drawtobitmap then
 
894
                   SetPixelV(bitmapdc,x,y,c);
 
895
                 if drawtoscreen then
 
896
                   SetPixelV(windc,x,y,c);
 
897
              end;
 
898
         end
 
899
       else
 
900
         begin
 
901
            if (col>=0) and (col<=high(pens)) then
 
902
              begin
 
903
                 if pens[col]=0 then
 
904
                   begin
 
905
                      c:=RGB(pal[col].red,pal[col].green,pal[col].blue);
 
906
                      pens[col]:=CreatePen(PS_SOLID,1,c);
 
907
                   end;
 
908
                 pen:=pens[col];
 
909
              end
 
910
            else
 
911
              begin
 
912
                 c:=RGB(pal[col].red,pal[col].green,pal[col].blue);
 
913
                 pen:=CreatePen(PS_SOLID,1,c);
 
914
              end;
 
915
 
 
916
            if drawtobitmap then
 
917
              begin
 
918
                 oldpen:=SelectObject(bitmapdc,pen);
 
919
                 Windows.MoveToEx(bitmapdc,x,y,nil);
 
920
                 Windows.LineTo(bitmapdc,x,y2+1);
 
921
                 SelectObject(bitmapdc,oldpen);
 
922
              end;
 
923
 
 
924
            if drawtoscreen then
 
925
              begin
 
926
                 oldpen:=SelectObject(windc,pen);
 
927
                 Windows.MoveToEx(windc,x,y,nil);
 
928
                 Windows.LineTo(windc,x,y2+1);
 
929
                 SelectObject(windc,oldpen);
 
930
              end;
 
931
            if (col<0) or (col>high(pens)) then
 
932
              DeleteObject(pen);
 
933
         end;
 
934
       LeaveCriticalSection(graphdrawing);
 
935
    end
 
936
  else
 
937
    for y := y to y2 do Directputpixel(x,y)
 
938
End;
 
939
 
 
940
procedure Circle16Win32GUI(X, Y: smallint; Radius:Word);
 
941
 
 
942
  var
 
943
     bitmaprgn,winrgn : HRGN;
 
944
     col,c : longint;
 
945
     oldpen,pen : HPEN;
 
946
     OriginalArcInfo: ArcCoordsType;
 
947
     OldWriteMode: word;
 
948
 
 
949
  begin
 
950
     if (Radius = 0) then
 
951
          Exit;
 
952
 
 
953
     if (Radius = 1) then
 
954
       begin
 
955
          { only normal put mode is supported by a call to PutPixel }
 
956
          PutPixel(X, Y, CurrentColor);
 
957
          Exit;
 
958
       end;
 
959
 
 
960
     if (Radius = 2) then
 
961
       begin
 
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);
 
967
          Exit;
 
968
       end;
 
969
 
 
970
     if LineInfo.Thickness = Normwidth then
 
971
       begin
 
972
          EnterCriticalSection(graphdrawing);
 
973
          { let windows do the clipping }
 
974
          if drawtobitmap then
 
975
            begin
 
976
               bitmaprgn:=CreateRectRgn(startxviewport,startyviewport,
 
977
                 startxviewport+viewwidth+1,startyviewport+viewheight+1);
 
978
               SelectClipRgn(bitmapdc,bitmaprgn);
 
979
            end;
 
980
 
 
981
          if drawtoscreen then
 
982
            begin
 
983
               winrgn:=CreateRectRgn(startxviewport,startyviewport,
 
984
                 startxviewport+viewwidth+1,startyviewport+viewheight+1);
 
985
               SelectClipRgn(windc,winrgn);
 
986
            end;
 
987
 
 
988
          inc(x,StartXViewPort);
 
989
          inc(y,StartYViewPort);
 
990
          col:=CurrentColor;
 
991
 
 
992
          if (col>=0) and (col<=high(pens)) then
 
993
            begin
 
994
               if pens[col]=0 then
 
995
                 begin
 
996
                    c:=RGB(pal[col].red,pal[col].green,pal[col].blue);
 
997
                    pens[col]:=CreatePen(PS_SOLID,1,c);
 
998
                 end;
 
999
               pen:=pens[col];
 
1000
            end
 
1001
          else
 
1002
            begin
 
1003
               c:=RGB(pal[col].red,pal[col].green,pal[col].blue);
 
1004
               pen:=CreatePen(PS_SOLID,1,c);
 
1005
            end;
 
1006
 
 
1007
          if drawtobitmap then
 
1008
            begin
 
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);
 
1013
            end;
 
1014
 
 
1015
          if drawtoscreen then
 
1016
            begin
 
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);
 
1021
            end;
 
1022
 
 
1023
          if (col<0) or (col>high(pens)) then
 
1024
            DeleteObject(pen);
 
1025
          { release clip regions }
 
1026
          if drawtoscreen then
 
1027
            begin
 
1028
               SelectClipRgn(windc,0);
 
1029
               DeleteObject(winrgn);
 
1030
            end;
 
1031
          if drawtobitmap then
 
1032
            begin
 
1033
               SelectClipRgn(bitmapdc,0);
 
1034
               DeleteObject(bitmaprgn);
 
1035
            end;
 
1036
          LeaveCriticalSection(graphdrawing);
 
1037
       end
 
1038
     else
 
1039
       begin
 
1040
          { save state of arc information }
 
1041
          { because it is not needed for  }
 
1042
          { a circle call.                }
 
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));
 
1047
       end;
 
1048
 end;
 
1049
 
 
1050
{
 
1051
Procedure PutImageWin32GUI(X,Y: smallint; var Bitmap; BitBlt: Word); {$ifndef fpc}far;{$endif fpc}
 
1052
type
 
1053
  pt = array[0..$fffffff] of word;
 
1054
  ptw = array[0..2] of longint;
 
1055
var
 
1056
  k: longint;
 
1057
  oldCurrentColor: word;
 
1058
  oldCurrentWriteMode, i, j, y1, x1, deltaX, deltaX1, deltaY: smallint;
 
1059
Begin
 
1060
{$ifdef logging}
 
1061
  LogLn('putImage at ('+strf(x)+','+strf(y)+') with width '+strf(ptw(Bitmap)[0])+
 
1062
    ' and height '+strf(ptw(Bitmap)[1]));
 
1063
  deltaY := 0;
 
1064
{$endif logging}
 
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 }
 
1069
 
 
1070
  deltaX := 0;
 
1071
  deltaX1 := 0;
 
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 }
 
1074
  if clipPixels then
 
1075
    begin
 
1076
      if y < startYViewPort then
 
1077
        begin
 
1078
          deltaY := startYViewPort - y;
 
1079
          inc(k,(x1-x+1)*deltaY);
 
1080
          y := startYViewPort;
 
1081
         end;
 
1082
      if y1 > startYViewPort+viewHeight then
 
1083
        y1 := startYViewPort+viewHeight;
 
1084
      if x < startXViewPort then
 
1085
        begin
 
1086
          deltaX := startXViewPort-x;
 
1087
          x := startXViewPort;
 
1088
        end;
 
1089
      if x1 > startXViewPort + viewWidth then
 
1090
        begin
 
1091
          deltaX1 := x1 - (startXViewPort + viewWidth);
 
1092
          x1 := startXViewPort + viewWidth;
 
1093
        end;
 
1094
    end;
 
1095
{$ifdef logging}
 
1096
  LogLn('deltax: '+strf(deltax)+', deltax1: '+strf(deltax1)+',deltay: '+strf(deltay));
 
1097
{$endif logging}
 
1098
  case bitBlt of
 
1099
  end;
 
1100
  oldCurrentColor := currentColor;
 
1101
  oldCurrentWriteMode := currentWriteMode;
 
1102
  currentWriteMode := bitBlt;
 
1103
  for j:=Y to Y1 do
 
1104
   Begin
 
1105
     inc(k,deltaX);
 
1106
     for i:=X to X1 do
 
1107
      begin
 
1108
        currentColor := pt(bitmap)[k];
 
1109
        directPutPixel(i,j);
 
1110
        inc(k);
 
1111
     end;
 
1112
     inc(k,deltaX1);
 
1113
   end;
 
1114
  currentWriteMode := oldCurrentWriteMode;
 
1115
  currentColor := oldCurrentColor;
 
1116
end;
 
1117
}
 
1118
procedure SetRGBPaletteWin32GUI(colorNum,redValue,greenvalue,
 
1119
      bluevalue : smallint);
 
1120
 
 
1121
  begin
 
1122
     if directcolor or (colornum<0) or (colornum>=maxcolor) then
 
1123
       begin
 
1124
         _graphresult:=grerror;
 
1125
         exit;
 
1126
       end;
 
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
 
1131
       begin
 
1132
          DeleteObject(pens[colorNum]);
 
1133
          pens[colorNum]:=0;
 
1134
       end;
 
1135
  end;
 
1136
 
 
1137
procedure GetRGBPaletteWin32GUI(colorNum : smallint;
 
1138
      var redValue,greenvalue,bluevalue : smallint);
 
1139
 
 
1140
  begin
 
1141
     if directcolor or (colornum<0) or (colornum>=maxcolor) then
 
1142
       begin
 
1143
         _graphresult:=grerror;
 
1144
         exit;
 
1145
       end;
 
1146
     redValue:=pal[colorNum].red;
 
1147
     greenValue:=pal[colorNum].green;
 
1148
     blueValue:=pal[colorNum].blue;
 
1149
  end;
 
1150
 
 
1151
procedure savestate;
 
1152
 
 
1153
  begin
 
1154
  end;
 
1155
 
 
1156
 
 
1157
procedure restorestate;
 
1158
 
 
1159
  begin
 
1160
  end;
 
1161
 
 
1162
function WindowProcGraph(Window: HWnd; AMessage:UInt; WParam : WParam;
 
1163
                    LParam: LParam): Longint; stdcall;
 
1164
 
 
1165
  var
 
1166
     dc : hdc;
 
1167
     ps : paintstruct;
 
1168
     r : rect;
 
1169
     oldbrush : hbrush;
 
1170
     oldpen : hpen;
 
1171
     i : longint;
 
1172
 
 
1173
begin
 
1174
  WindowProcGraph := 0;
 
1175
 
 
1176
  case AMessage of
 
1177
    wm_lbuttondown,
 
1178
    wm_rbuttondown,
 
1179
    wm_mbuttondown,
 
1180
    wm_lbuttonup,
 
1181
    wm_rbuttonup,
 
1182
    wm_mbuttonup,
 
1183
    wm_lbuttondblclk,
 
1184
    wm_rbuttondblclk,
 
1185
    wm_mbuttondblclk:
 
1186
    {
 
1187
    This leads to problem, i.e. the menu etc doesn't work any longer
 
1188
    wm_nclbuttondown,
 
1189
    wm_ncrbuttondown,
 
1190
    wm_ncmbuttondown,
 
1191
    wm_nclbuttonup,
 
1192
    wm_ncrbuttonup,
 
1193
    wm_ncmbuttonup,
 
1194
    wm_nclbuttondblclk,
 
1195
    wm_ncrbuttondblclk,
 
1196
    wm_ncmbuttondblclk:
 
1197
    }
 
1198
      begin
 
1199
         if assigned(mousemessagehandler) then
 
1200
           WindowProcGraph:=mousemessagehandler(window,amessage,wparam,lparam);
 
1201
      end;
 
1202
    wm_notify:
 
1203
      begin
 
1204
         if assigned(notifymessagehandler) then
 
1205
           WindowProcGraph:=notifymessagehandler(window,amessage,wparam,lparam);
 
1206
      end;
 
1207
    wm_command:
 
1208
      if assigned(commandmessagehandler) then
 
1209
        WindowProcGraph:=commandmessagehandler(window,amessage,wparam,lparam);
 
1210
    wm_keydown,
 
1211
    wm_keyup,
 
1212
    wm_char:
 
1213
      begin
 
1214
         if assigned(charmessagehandler) then
 
1215
           WindowProcGraph:=charmessagehandler(window,amessage,wparam,lparam);
 
1216
      end;
 
1217
    wm_paint:
 
1218
      begin
 
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
 
1226
           exit;
 
1227
         EnterCriticalSection(graphdrawing);
 
1228
         graphrunning:=true;
 
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);
 
1239
         Exit;
 
1240
      end;
 
1241
    wm_create:
 
1242
      begin
 
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);
 
1252
         dc:=GetDC(window);
 
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);
 
1261
         // clear everything
 
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);
 
1273
         // clear font cache
 
1274
         fillchar(bitmapfonthorizoncache,sizeof(bitmapfonthorizoncache),0);
 
1275
         fillchar(bitmapfontverticalcache,sizeof(bitmapfontverticalcache),0);
 
1276
 
 
1277
         // clear predefined pens
 
1278
         fillchar(pens,sizeof(pens),0);
 
1279
         if assigned(OnGraphWindowCreation) then
 
1280
           OnGraphWindowCreation;
 
1281
         LeaveCriticalSection(graphdrawing);
 
1282
{$ifdef DEBUGCHILDS}
 
1283
         writeln('done');
 
1284
         GetClientRect(window,@r);
 
1285
         writeln('Window size: ',r.right,',',r.bottom);
 
1286
{$endif DEBUGCHILDS}
 
1287
      end;
 
1288
    wm_Destroy:
 
1289
      begin
 
1290
         EnterCriticalSection(graphdrawing);
 
1291
         graphrunning:=false;
 
1292
         ReleaseDC(GraphWindow,windc);
 
1293
         SelectObject(bitmapdc,oldbitmap);
 
1294
         DeleteObject(savedscreen);
 
1295
         DeleteDC(bitmapdc);
 
1296
         // release font cache
 
1297
         for i:=0 to 255 do
 
1298
           if bitmapfonthorizoncache[i]<>0 then
 
1299
             DeleteObject(bitmapfonthorizoncache[i]);
 
1300
         for i:=0 to 255 do
 
1301
           if bitmapfontverticalcache[i]<>0 then
 
1302
             DeleteObject(bitmapfontverticalcache[i]);
 
1303
 
 
1304
         for i:=0 to high(pens) do
 
1305
           if pens[i]<>0 then
 
1306
             DeleteObject(pens[i]);
 
1307
 
 
1308
         LeaveCriticalSection(graphdrawing);
 
1309
{$ifdef DEBUG_WM_PAINT}
 
1310
         close(graphdebug);
 
1311
{$endif DEBUG_WM_PAINT}
 
1312
         PostQuitMessage(0);
 
1313
         Exit;
 
1314
      end
 
1315
    else
 
1316
      WindowProcGraph := DefWindowProc(Window, AMessage, WParam, LParam);
 
1317
  end;
 
1318
end;
 
1319
 
 
1320
function WindowProcParent(Window: HWnd; AMessage:UInt; WParam : WParam;
 
1321
                    LParam: LParam): Longint; stdcall;
 
1322
 
 
1323
begin
 
1324
  WindowProcParent := 0;
 
1325
  case AMessage of
 
1326
    wm_keydown,
 
1327
    wm_keyup,
 
1328
    wm_char:
 
1329
      begin
 
1330
         if assigned(charmessagehandler) then
 
1331
           WindowProcParent:=charmessagehandler(window,amessage,wparam,lparam);
 
1332
      end;
 
1333
    wm_notify:
 
1334
      begin
 
1335
         if assigned(notifymessagehandler) then
 
1336
           WindowProcParent:=notifymessagehandler(window,amessage,wparam,lparam);
 
1337
      end;
 
1338
    wm_command:
 
1339
      if assigned(commandmessagehandler) then
 
1340
        WindowProcParent:=commandmessagehandler(window,amessage,wparam,lparam);
 
1341
    else
 
1342
      WindowProcParent := DefWindowProc(Window, AMessage, WParam, LParam);
 
1343
  end;
 
1344
end;
 
1345
 
 
1346
function WinRegister: Boolean;
 
1347
var
 
1348
  WindowClass: WndClass;
 
1349
begin
 
1350
  WindowClass.Style := graphwindowstyle;
 
1351
  WindowClass.lpfnWndProc := WndProc(@WindowProcGraph);
 
1352
  WindowClass.cbClsExtra := 0;
 
1353
  WindowClass.cbWndExtra := 0;
 
1354
  WindowClass.hInstance := system.MainInstance;
 
1355
  if icon<>0 then
 
1356
    WindowClass.hIcon := icon
 
1357
  else
 
1358
    WindowClass.hIcon := LoadIcon(0, idi_Application);
 
1359
  WindowClass.hCursor := LoadCursor(0, idc_Arrow);
 
1360
  WindowClass.hbrBackground := GetStockObject(BLACK_BRUSH);
 
1361
  if menu<>0 then
 
1362
    WindowClass.lpszMenuName := MAKEINTRESOURCE(menu)
 
1363
  else
 
1364
    WindowClass.lpszMenuName := nil;
 
1365
  WindowClass.lpszClassName := 'FPCGraphWindow';
 
1366
 
 
1367
  winregister:=RegisterClass(WindowClass) <> 0;
 
1368
end;
 
1369
 
 
1370
function WinRegisterWithChild: Boolean;
 
1371
var
 
1372
  WindowClass: WndClass;
 
1373
begin
 
1374
  WindowClass.Style := graphwindowstyle;
 
1375
  WindowClass.lpfnWndProc := WndProc(@WindowProcParent);
 
1376
  WindowClass.cbClsExtra := 0;
 
1377
  WindowClass.cbWndExtra := 0;
 
1378
  WindowClass.hInstance := system.MainInstance;
 
1379
  if icon<>0 then
 
1380
    WindowClass.hIcon := icon
 
1381
  else
 
1382
    WindowClass.hIcon := LoadIcon(0, idi_Application);
 
1383
  WindowClass.hCursor := LoadCursor(0, idc_Arrow);
 
1384
  WindowClass.hbrBackground := GetStockObject(BLACK_BRUSH);
 
1385
  if menu<>0 then
 
1386
    WindowClass.lpszMenuName := MAKEINTRESOURCE(menu)
 
1387
  else
 
1388
    WindowClass.lpszMenuName := nil;
 
1389
  WindowClass.lpszClassName := 'FPCGraphWindowMain';
 
1390
 
 
1391
  WinRegisterWithChild:=RegisterClass(WindowClass) <> 0;
 
1392
{$ifdef DEBUGCHILDS}
 
1393
  writeln('Main window successfully registered: WinRegisterWithChild is ',WinRegisterWithChild);
 
1394
{$endif DEBUGCHILDS}
 
1395
  if WinRegisterWithChild then
 
1396
    begin
 
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}
 
1411
    end;
 
1412
end;
 
1413
 
 
1414
var
 
1415
   // here we can force the creation of a maximized window }
 
1416
   extrastyle : cardinal;
 
1417
 
 
1418
 { Create the Window Class }
 
1419
function WinCreate : HWnd;
 
1420
var
 
1421
  hWindow: HWnd;
 
1422
begin
 
1423
  WinCreate:=0;
 
1424
  if UseChildWindow then
 
1425
    begin
 
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
 
1435
         begin
 
1436
            ShowWindow(ParentWindow, SW_SHOW);
 
1437
            UpdateWindow(ParentWindow);
 
1438
         end
 
1439
       else
 
1440
         exit;
 
1441
       hWindow:=CreateWindow('FPCGraphWindowChild',nil,
 
1442
                  WS_CHILD, ChildOffset.Left,ChildOffset.Top,
 
1443
                  maxx+1,maxy+1,
 
1444
                  ParentWindow, 0, system.MainInstance, nil);
 
1445
       if hwindow<>0 then
 
1446
         begin
 
1447
            ShowWindow(hwindow, SW_SHOW);
 
1448
            UpdateWindow(hwindow);
 
1449
         end
 
1450
       else
 
1451
         exit;
 
1452
       WinCreate:=hWindow;
 
1453
    end
 
1454
  else
 
1455
    begin
 
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
 
1463
         begin
 
1464
            ShowWindow(hWindow, SW_SHOW);
 
1465
            UpdateWindow(hWindow);
 
1466
            WinCreate:=hWindow;
 
1467
         end;
 
1468
    end;
 
1469
end;
 
1470
 
 
1471
const
 
1472
   winregistered : boolean = false;
 
1473
 
 
1474
function MessageHandleThread(p : pointer) : DWord;StdCall;
 
1475
 
 
1476
  var
 
1477
     AMessage: Msg;
 
1478
 
 
1479
  begin
 
1480
     if not(winregistered) then
 
1481
       begin
 
1482
          if UseChildWindow then
 
1483
            begin
 
1484
               if not(WinRegisterWithChild) then
 
1485
                 begin
 
1486
                    MessageBox(0, 'Window registration failed', nil, mb_Ok);
 
1487
                    ExitThread(1);
 
1488
                 end;
 
1489
            end
 
1490
          else
 
1491
            begin
 
1492
               if not(WinRegister) then
 
1493
                 begin
 
1494
                    MessageBox(0, 'Window registration failed', nil, mb_Ok);
 
1495
                    ExitThread(1);
 
1496
                 end;
 
1497
            end;
 
1498
          winregistered:=true;
 
1499
       end;
 
1500
     GraphWindow:=WinCreate;
 
1501
     if longint(GraphWindow) = 0 then begin
 
1502
       MessageBox(0, 'Window creation failed', nil, mb_Ok);
 
1503
       ExitThread(1);
 
1504
     end;
 
1505
     while longint(GetMessage(@AMessage, 0, 0, 0))=longint(true) do
 
1506
       begin
 
1507
          TranslateMessage(AMessage);
 
1508
          DispatchMessage(AMessage);
 
1509
       end;
 
1510
     MessageHandleThread:=0;
 
1511
  end;
 
1512
 
 
1513
procedure InitWin32GUI16colors;
 
1514
 
 
1515
  var
 
1516
     threadexitcode : longint;
 
1517
  begin
 
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
 
1526
     else
 
1527
       extrastyle:=0;
 
1528
     { start graph subsystem }
 
1529
     InitializeCriticalSection(graphdrawing);
 
1530
     graphrunning:=false;
 
1531
     MessageThreadHandle:=CreateThread(nil,0,@MessageHandleThread,
 
1532
       nil,0,MessageThreadID);
 
1533
     repeat
 
1534
       GetExitCodeThread(MessageThreadHandle,@threadexitcode);
 
1535
     until graphrunning or (threadexitcode<>STILL_ACTIVE);
 
1536
     if threadexitcode<>STILL_ACTIVE then
 
1537
        _graphresult := grerror;
 
1538
  end;
 
1539
 
 
1540
procedure CloseGraph;
 
1541
 
 
1542
  begin
 
1543
     If not isgraphmode then
 
1544
       begin
 
1545
         _graphresult := grnoinitgraph;
 
1546
         exit
 
1547
       end;
 
1548
     if UseChildWindow then
 
1549
       begin
 
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)
 
1555
       end
 
1556
     else
 
1557
       PostMessage(GraphWindow,wm_destroy,0,0);
 
1558
 
 
1559
     PostThreadMessage(MessageThreadHandle,wm_quit,0,0);
 
1560
     WaitForSingleObject(MessageThreadHandle,Infinite);
 
1561
     CloseHandle(MessageThreadHandle);
 
1562
     DeleteCriticalSection(graphdrawing);
 
1563
     freemem(pal,sizeof(RGBrec)*maxcolor);
 
1564
 
 
1565
     MessageThreadID := 0;
 
1566
     MessageThreadHandle := 0;
 
1567
     isgraphmode := false;
 
1568
  end;
 
1569
 
 
1570
procedure LineWin32GUI(X1, Y1, X2, Y2: smallint); {$ifndef fpc}far;{$endif fpc}
 
1571
 
 
1572
  var X, Y :           smallint;
 
1573
      deltax, deltay : smallint;
 
1574
      d, dinc1, dinc2: smallint;
 
1575
      xinc1          : smallint;
 
1576
      xinc2          : smallint;
 
1577
      yinc1          : smallint;
 
1578
      yinc2          : smallint;
 
1579
      i              : smallint;
 
1580
      Flag           : Boolean; { determines pixel direction in thick lines }
 
1581
      NumPixels      : smallint;
 
1582
      PixelCount     : smallint;
 
1583
      OldCurrentColor: Word;
 
1584
      swtmp          : smallint;
 
1585
      TmpNumPixels   : smallint;
 
1586
      col : longint;
 
1587
      pen,oldpen : hpen;
 
1588
 
 
1589
 begin
 
1590
    if graphrunning then
 
1591
      begin
 
1592
         {******************************************}
 
1593
         {  SOLID LINES                             }
 
1594
         {******************************************}
 
1595
         if lineinfo.LineStyle = SolidLn then
 
1596
           Begin
 
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... }
 
1603
              if ClipPixels then
 
1604
                begin
 
1605
                   if LineClipped(x1,y1,x2,y2,StartXViewPort, StartYViewPort,
 
1606
                     StartXViewPort+ViewWidth, StartYViewPort+ViewHeight) then
 
1607
                       exit;
 
1608
                  If LineInfo.Thickness=NormWidth then
 
1609
                   Begin
 
1610
                      EnterCriticalSection(graphdrawing);
 
1611
                      {
 
1612
                      if currentwritemode<>normalput then
 
1613
                        begin
 
1614
                           case currentwritemode of
 
1615
                              XORPut:
 
1616
                                begin
 
1617
                                   SetROP2(windc,R2_XORPEN);
 
1618
                                   SetROP2(bitmapdc,R2_XORPEN);
 
1619
                                end;
 
1620
                              AndPut:
 
1621
                                begin
 
1622
                                   SetROP2(windc,R2_MASKPEN);
 
1623
                                   SetROP2(bitmapdc,R2_MASKPEN);
 
1624
                                end;
 
1625
                              OrPut:
 
1626
                                begin
 
1627
                                   SetROP2(windc,R2_MERGEPEN);
 
1628
                                   SetROP2(bitmapdc,R2_MERGEPEN);
 
1629
                                end;
 
1630
                           end;
 
1631
                        end;
 
1632
                      }
 
1633
                      col:=RGB(pal[CurrentColor].red,pal[CurrentColor].green,pal[CurrentColor].blue);
 
1634
                      pen:=CreatePen(PS_SOLID,1,col);
 
1635
                      if pen=0 then
 
1636
                        writeln('Pen konnte nicht erzeugt werden!');
 
1637
 
 
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);
 
1643
 
 
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);
 
1649
 
 
1650
                      DeleteObject(pen);
 
1651
                      {
 
1652
                      if currentwritemode<>normalput then
 
1653
                        begin
 
1654
                           SetROP2(windc,R2_COPYPEN);
 
1655
                           SetROP2(bitmapdc,R2_COPYPEN);
 
1656
                        end;
 
1657
                      }
 
1658
                      LeaveCriticalSection(graphdrawing);
 
1659
                   end
 
1660
                 else
 
1661
                  { Thick width lines }
 
1662
                   begin
 
1663
                     { Draw the pixels }
 
1664
                      for i := 1 to numpixels do
 
1665
                        begin
 
1666
                         { all depending on the slope, we can determine         }
 
1667
                         { in what direction the extra width pixels will be put }
 
1668
                         If Flag then
 
1669
                           Begin
 
1670
                             DirectPutPixelClip(x-1,y);
 
1671
                             DirectPutPixelClip(x,y);
 
1672
                             DirectPutPixelClip(x+1,y);
 
1673
                           end
 
1674
                         else
 
1675
                           Begin
 
1676
                             DirectPutPixelClip(x, y-1);
 
1677
                             DirectPutPixelClip(x, y);
 
1678
                             DirectPutPixelClip(x, y+1);
 
1679
                           end;
 
1680
                         if d < 0 then
 
1681
                           begin
 
1682
                             d := d + dinc1;
 
1683
                             x := x + xinc1;
 
1684
                             y := y + yinc1;
 
1685
                           end
 
1686
                         else
 
1687
                           begin
 
1688
                             d := d + dinc2;
 
1689
                             x := x + xinc2;
 
1690
                             y := y + yinc2;
 
1691
                           end;
 
1692
                        end;
 
1693
                   end;
 
1694
                 end;
 
1695
           end
 
1696
          else
 
1697
       {******************************************}
 
1698
       {  begin patterned lines                   }
 
1699
       {******************************************}
 
1700
           Begin
 
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... }
 
1707
             if ClipPixels then
 
1708
              begin
 
1709
              if LineClipped(x1,y1,x2,y2,StartXViewPort, StartYViewPort,
 
1710
                  StartXViewPort+ViewWidth, StartYViewPort+ViewHeight) then
 
1711
                     exit;
 
1712
              end;
 
1713
 
 
1714
             OldCurrentColor := CurrentColor;
 
1715
             PixelCount:=0;
 
1716
             if y1 = y2 then
 
1717
                   Begin
 
1718
                    { Check if we must swap }
 
1719
                if x1 >= x2 then
 
1720
                      Begin
 
1721
                        swtmp := x1;
 
1722
                        x1 := x2;
 
1723
                        x2 := swtmp;
 
1724
                      end;
 
1725
                if LineInfo.Thickness = NormWidth then
 
1726
                     Begin
 
1727
                      for PixelCount:=x1 to x2 do
 
1728
                            { optimization: PixelCount mod 16 }
 
1729
                            if LinePatterns[PixelCount and 15] = TRUE then
 
1730
                             begin
 
1731
                               DirectPutPixel(PixelCount,y2);
 
1732
                             end;
 
1733
                     end
 
1734
                    else
 
1735
                     Begin
 
1736
                      for i:=-1 to 1 do
 
1737
                            Begin
 
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
 
1743
                                  begin
 
1744
                                        DirectPutPixelClip(PixelCount,y2+i);
 
1745
                                  end;
 
1746
                            end;
 
1747
                     end;
 
1748
               end
 
1749
             else
 
1750
             if x1 = x2 then
 
1751
                  Begin
 
1752
                   { Check if we must swap }
 
1753
                   if y1 >= y2 then
 
1754
                     Begin
 
1755
                       swtmp := y1;
 
1756
                       y1 := y2;
 
1757
                       y2 := swtmp;
 
1758
                     end;
 
1759
                   if LineInfo.Thickness = NormWidth then
 
1760
                     Begin
 
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
 
1765
                             begin
 
1766
                           DirectPutPixel(x1,PixelCount);
 
1767
                             end;
 
1768
                     end
 
1769
                   else
 
1770
                     Begin
 
1771
                       for i:=-1 to 1 do
 
1772
                            Begin
 
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
 
1777
                                  begin
 
1778
                                    DirectPutPixelClip(x1+i,PixelCount);
 
1779
                                  end;
 
1780
                            end;
 
1781
                     end;
 
1782
                  end
 
1783
             else
 
1784
                  Begin
 
1785
                    oldCurrentColor := CurrentColor;
 
1786
                    { Calculate deltax and deltay for initialisation }
 
1787
                    deltax := abs(x2 - x1);
 
1788
                    deltay := abs(y2 - y1);
 
1789
 
 
1790
                    { Initialize all vars based on which is the independent variable }
 
1791
                    if deltax >= deltay then
 
1792
                      begin
 
1793
 
 
1794
                        Flag := FALSE;
 
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;
 
1800
                        xinc1 := 1;
 
1801
                        xinc2 := 1;
 
1802
                        yinc1 := 0;
 
1803
                        yinc2 := 1;
 
1804
                     end
 
1805
                   else
 
1806
                     begin
 
1807
 
 
1808
                       Flag := TRUE;
 
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;
 
1814
                       xinc1 := 0;
 
1815
                       xinc2 := 1;
 
1816
                       yinc1 := 1;
 
1817
                       yinc2 := 1;
 
1818
                     end;
 
1819
 
 
1820
                   { Make sure x and y move in the right directions }
 
1821
                   if x1 > x2 then
 
1822
                     begin
 
1823
                       xinc1 := - xinc1;
 
1824
                       xinc2 := - xinc2;
 
1825
                     end;
 
1826
                   if y1 > y2 then
 
1827
                     begin
 
1828
                       yinc1 := - yinc1;
 
1829
                       yinc2 := - yinc2;
 
1830
                     end;
 
1831
 
 
1832
                   { Start drawing at <x1, y1> }
 
1833
                   x := x1;
 
1834
                   y := y1;
 
1835
 
 
1836
                   If LineInfo.Thickness=ThickWidth then
 
1837
 
 
1838
                    Begin
 
1839
                      TmpNumPixels := NumPixels-1;
 
1840
                      { Draw the pixels }
 
1841
                      for i := 0 to TmpNumPixels do
 
1842
                        begin
 
1843
                            { all depending on the slope, we can determine         }
 
1844
                            { in what direction the extra width pixels will be put }
 
1845
                              If Flag then
 
1846
                                 Begin
 
1847
                                   { compare if we should plot a pixel here , compare }
 
1848
                                   { with predefined line patterns...                 }
 
1849
                                   if LinePatterns[i and 15] = TRUE then
 
1850
                                     begin
 
1851
                                       DirectPutPixelClip(x-1,y);
 
1852
                                       DirectPutPixelClip(x,y);
 
1853
                                       DirectPutPixelClip(x+1,y);
 
1854
                                     end;
 
1855
                                 end
 
1856
                              else
 
1857
                                 Begin
 
1858
                                   { compare if we should plot a pixel here , compare }
 
1859
                                   { with predefined line patterns...                 }
 
1860
                                   if LinePatterns[i and 15] = TRUE then
 
1861
                                    begin
 
1862
                                      DirectPutPixelClip(x,y-1);
 
1863
                                      DirectPutPixelClip(x,y);
 
1864
                                      DirectPutPixelClip(x,y+1);
 
1865
                                    end;
 
1866
                                 end;
 
1867
                          if d < 0 then
 
1868
                                begin
 
1869
                                  d := d + dinc1;
 
1870
                                  x := x + xinc1;
 
1871
                                  y := y + yinc1;
 
1872
                                end
 
1873
                          else
 
1874
                                begin
 
1875
                          d := d + dinc2;
 
1876
                          x := x + xinc2;
 
1877
                          y := y + yinc2;
 
1878
                                end;
 
1879
                       end;
 
1880
                   end
 
1881
                  else
 
1882
                   Begin
 
1883
                    { instead of putting in loop , substract by one now }
 
1884
                    TmpNumPixels := NumPixels-1;
 
1885
                   { NormWidth }
 
1886
                    for i := 0 to TmpNumPixels do
 
1887
                    begin
 
1888
                         if LinePatterns[i and 15] = TRUE then
 
1889
                           begin
 
1890
                                 DirectPutPixel(x,y);
 
1891
                           end;
 
1892
                    if d < 0 then
 
1893
                        begin
 
1894
                          d := d + dinc1;
 
1895
                          x := x + xinc1;
 
1896
                          y := y + yinc1;
 
1897
                        end
 
1898
                    else
 
1899
                        begin
 
1900
                          d := d + dinc2;
 
1901
                          x := x + xinc2;
 
1902
                          y := y + yinc2;
 
1903
                        end;
 
1904
                    end;
 
1905
                   end
 
1906
               end;
 
1907
       {******************************************}
 
1908
       {  end patterned lines                     }
 
1909
       {******************************************}
 
1910
              { restore color }
 
1911
              CurrentColor:=OldCurrentColor;
 
1912
          end;
 
1913
    end;
 
1914
 end;  { Line }
 
1915
 
 
1916
{ multipage support could be done by using more than one background bitmap }
 
1917
procedure SetVisualWin32GUI(page: word);
 
1918
 
 
1919
  begin
 
1920
  end;
 
1921
 
 
1922
procedure SetActiveWin32GUI(page: word);
 
1923
  begin
 
1924
  end;
 
1925
 
 
1926
function queryadapterinfo : pmodeinfo;
 
1927
 
 
1928
  var
 
1929
     mode: TModeInfo;
 
1930
     ScreenWidth,ScreenHeight : longint;
 
1931
     ScreenWidthMaximized,ScreenHeightMaximized : longint;
 
1932
 
 
1933
  procedure SetupWin32GUIDefault;
 
1934
 
 
1935
    begin
 
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;
 
1948
       // doesn't work yet
 
1949
       // mode.Line:={$ifdef fpc}@{$endif}LineWin32GUI;
 
1950
    end;
 
1951
 
 
1952
  begin
 
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);
 
1968
 
 
1969
     QueryAdapterInfo := ModeList;
 
1970
     { If the mode listing already exists... }
 
1971
     { simply return it, without changing    }
 
1972
     { anything...                           }
 
1973
     if assigned(ModeList) then
 
1974
       exit;
 
1975
     { the first one becomes the standard mode }
 
1976
     if (ScreenWidth>=640) and (ScreenHeight>=480) then
 
1977
       begin
 
1978
          InitMode(mode);
 
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;
 
1986
          mode.MaxX := 639;
 
1987
          mode.MaxY := 479;
 
1988
          SetupWin32GUIDefault;
 
1989
          mode.XAspect := 10000;
 
1990
          mode.YAspect := 10000;
 
1991
          AddMode(mode);
 
1992
       end;
 
1993
     if (ScreenWidth>=640) and (ScreenHeight>=200) then
 
1994
       begin
 
1995
          InitMode(mode);
 
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;
 
2004
          mode.MaxX := 639;
 
2005
          mode.MaxY := 199;
 
2006
          SetupWin32GUIDefault;
 
2007
          mode.XAspect := 10000;
 
2008
          mode.YAspect := 10000;
 
2009
          AddMode(mode);
 
2010
       end;
 
2011
     if (ScreenWidth>=640) and (ScreenHeight>=350) then
 
2012
       begin
 
2013
          InitMode(mode);
 
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;
 
2021
          mode.MaxX := 639;
 
2022
          mode.MaxY := 349;
 
2023
          SetupWin32GUIDefault;
 
2024
          mode.XAspect := 10000;
 
2025
          mode.YAspect := 10000;
 
2026
          AddMode(mode);
 
2027
       end;
 
2028
     if (ScreenWidth>=640) and (ScreenHeight>=400) then
 
2029
       begin
 
2030
          InitMode(mode);
 
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;
 
2038
          mode.MaxX := 639;
 
2039
          mode.MaxY := 399;
 
2040
          SetupWin32GUIDefault;
 
2041
          mode.XAspect := 10000;
 
2042
          mode.YAspect := 10000;
 
2043
          AddMode(mode);
 
2044
       end;
 
2045
     if (ScreenWidth>=640) and (ScreenHeight>=480) then
 
2046
       begin
 
2047
          InitMode(mode);
 
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;
 
2055
          mode.MaxX := 639;
 
2056
          mode.MaxY := 479;
 
2057
          SetupWin32GUIDefault;
 
2058
          mode.XAspect := 10000;
 
2059
          mode.YAspect := 10000;
 
2060
          AddMode(mode);
 
2061
       end;
 
2062
     { add 800x600 only if screen is large enough }
 
2063
     If (ScreenWidth>=800) and (ScreenHeight>=600) then
 
2064
       begin
 
2065
          InitMode(mode);
 
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;
 
2073
          mode.MaxX := 799;
 
2074
          mode.MaxY := 599;
 
2075
          SetupWin32GUIDefault;
 
2076
          mode.XAspect := 10000;
 
2077
          mode.YAspect := 10000;
 
2078
          AddMode(mode);
 
2079
          InitMode(mode);
 
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;
 
2087
          mode.MaxX := 799;
 
2088
          mode.MaxY := 599;
 
2089
          SetupWin32GUIDefault;
 
2090
          mode.XAspect := 10000;
 
2091
          mode.YAspect := 10000;
 
2092
          AddMode(mode);
 
2093
       end;
 
2094
     { add 1024x768 only if screen is large enough }
 
2095
     If (ScreenWidth>=1024) and (ScreenHeight>=768) then
 
2096
       begin
 
2097
          InitMode(mode);
 
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;
 
2105
          mode.MaxX := 1023;
 
2106
          mode.MaxY := 767;
 
2107
          SetupWin32GUIDefault;
 
2108
          mode.XAspect := 10000;
 
2109
          mode.YAspect := 10000;
 
2110
          AddMode(mode);
 
2111
          InitMode(mode);
 
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;
 
2119
          mode.MaxX := 1023;
 
2120
          mode.MaxY := 768;
 
2121
          SetupWin32GUIDefault;
 
2122
          mode.XAspect := 10000;
 
2123
          mode.YAspect := 10000;
 
2124
          AddMode(mode);
 
2125
       end;
 
2126
     { add 1280x1024 only if screen is large enough }
 
2127
     If (ScreenWidth>=1280) and (ScreenHeight>=1024) then
 
2128
       begin
 
2129
          InitMode(mode);
 
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;
 
2137
          mode.MaxX := 1279;
 
2138
          mode.MaxY := 1023;
 
2139
          SetupWin32GUIDefault;
 
2140
          mode.XAspect := 10000;
 
2141
          mode.YAspect := 10000;
 
2142
          AddMode(mode);
 
2143
          InitMode(mode);
 
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;
 
2151
          mode.MaxX := 1279;
 
2152
          mode.MaxY := 1023;
 
2153
          SetupWin32GUIDefault;
 
2154
          mode.XAspect := 10000;
 
2155
          mode.YAspect := 10000;
 
2156
          AddMode(mode);
 
2157
       end;
 
2158
     { at least we add a mode with the largest possible window }
 
2159
      InitMode(mode);
 
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;
 
2172
      AddMode(mode);
 
2173
      InitMode(mode);
 
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;
 
2186
      AddMode(mode);
 
2187
      { .. and a maximized window }
 
2188
      InitMode(mode);
 
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;
 
2201
      AddMode(mode);
 
2202
      InitMode(mode);
 
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;
 
2215
      AddMode(mode);
 
2216
  end;
 
2217
 
 
2218
begin
 
2219
  InitializeGraph;
 
2220
  charmessagehandler:=nil;
 
2221
  mousemessagehandler:=nil;
 
2222
  commandmessagehandler:=nil;
 
2223
  notifymessagehandler:=nil;
 
2224
  OnGraphWindowCreation:=nil;
 
2225
end.