3 This file is part of the Free Pascal run time library
.
4 Copyright (c
) 1999-2000 by Florian Klaempfl
6 This file implements the linux GGI support
for the graph unit
8 See the file COPYING
.FPC
, included
in this distribution
,
9 for details about the copyright
.
11 This program is distributed
in the hope that it will be useful
,
12 but WITHOUT ANY WARRANTY
; without even the implied warranty of
13 MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE
.
15 **********************************************************************}
19 { objfpc is needed
for array of const support
}
26 {(sg
) GTEXT deactivated because we need mode
#0 as default mode}
27 {GTEXT
= 0; Compatible with VGAlib v1
.2
}
42 G1280x1024x256
= 13; { Additional modes
. }
64 G720x348x2
= 32; { Hercules emulation mode
}
66 G320x200x16M32
= 33; { 32-bit per pixel modes
. }
70 G1280x1024x16M32
= 37;
72 { additional resolutions
}
85 G1600x1200x16M32
= 49;
95 Procedure
SetRawMode(b
:boolean);
107 TCSetAttr(1,TCSANOW
,Tio
);
111 InternalDriverName
= 'LinuxGGI';
115 { ---------------------------------------------------------------------
116 GGI bindings
[(c
) 1999 Sebastian Guenther
]
117 ---------------------------------------------------------------------}
123 ModeNames
: array
[0..GLastMode
] of PChar
=
124 ('[]', {Let GGI choose a default mode
}
133 'S640x480x[GT_1BIT]',
136 'S1024x768[GT_8BIT]',
137 'S1280x1024[GT_8BIT]',
138 'S320x200[GT_15BIT]',
139 'S320x200[GT_16BIT]',
140 'S320x200[GT_24BIT]',
141 'S640x480[GT_15BIT]',
142 'S640x480[GT_16BIT]',
143 'S640x480[GT_24BIT]',
144 'S800x600[GT_15BIT]',
145 'S800x600[GT_16BIT]',
146 'S800x600[GT_24BIT]',
147 'S1024x768[GT_15BIT]',
148 'S1024x768[GT_16BIT]',
149 'S1024x768[GT_24BIT]',
150 'S1280x1024[GT_15BIT]',
151 'S1280x1024[GT_16BIT]',
152 'S1280x1024[GT_24BIT]',
154 'S1024x768[GT_4BIT]',
155 'S1280x1024[GT_4BIT]',
156 'S720x348x[GT_1BIT]',
157 'S320x200[GT_32BIT]',
158 'S640x480[GT_32BIT]',
159 'S800x600[GT_32BIT]',
160 'S1024x768[GT_32BIT]',
161 'S1280x1024[GT_32BIT]',
162 'S1152x864[GT_4BIT]',
163 'S1152x864[gt_8BIT]',
164 'S1152x864[GT_15BIT]',
165 'S1152x864[GT_16BIT]',
166 'S1152x864[GT_24BIT]',
167 'S1152x864[GT_32BIT]',
168 'S1600x1200[GT_4BIT]',
169 'S1600x1200[gt_8BIT]',
170 'S1600x1200[GT_15BIT]',
171 'S1600x1200[GT_16BIT]',
172 'S1600x1200[GT_24BIT]',
173 'S1600x1200[GT_32BIT]');
176 TGGIVisual
= Pointer
;
177 TGGIResource
= Pointer
;
181 TGGIPixel
= LongWord
;
182 PGGIColor
= ^TGGIColor
;
186 PGGIClut
= ^TGGIClut
;
191 TGGIGraphType
= LongWord
;
193 TGGIMode
= record
// requested by user
and changed by driver
194 Frames
: LongInt
; // frames needed
195 Visible
: TGGICoord
; // vis
. pixels
, may change slightly
196 Virt
: TGGICoord
; // virtual pixels
, may change
197 Size
: TGGICoord
; // size of visible
in mm
198 GraphType
: TGGIGraphType
; // which mode
?
199 dpp
: TGGICoord
; // dots per pixel
204 function ggiInit
: Longint
; cdecl
; external libggi
;
205 procedure ggiExit
; cdecl
; external libggi
;
206 function
ggiOpen(display
: PChar
; args
: Array of const
): TGGIVisual
; cdecl
; external libggi
;
207 function
ggiClose(vis
: TGGIVisual
): Longint
; cdecl
; external libggi
;
208 function
ggiParseMode(s
: PChar
; var m
: TGGIMode
): Longint
; cdecl
; external libggi
;
209 function
ggiSetMode(visual
: TGGIVisual
; var tm
: TGGIMode
): Longint
; cdecl
; external libggi
;
210 function
ggiGetMode(visual
: TGGIVisual
; var tm
: TGGIMode
): Longint
; cdecl
; external libggi
;
211 function
ggiCheckMode(visual
: TGGIVisual
; var tm
: TGGIMode
): Longint
; cdecl
; external libggi
;
213 function
ggiMapColor(vis
: TGGIVisual
; Color
: TGGIColor
): TGGIPixel
; cdecl
; external libggi
;
215 function
ggiPutPixel(vis
: TGGIVisual
; x
, y
: Longint
; pixel
: TGGIPixel
): Longint
; cdecl
; external libggi
;
216 function
ggiGetPixel(vis
: TGGIVisual
; x
, y
: Longint
; var pixel
: TGGIPixel
): Longint
; cdecl
; external libggi
;
217 function
ggiDrawBox(vis
: TGGIVisual
; x
, y
, w
, h
: Longint
): Longint
; cdecl
; external libggi
;
218 function
ggiPutBox(vis
: TGGIVisual
; x
, y
, w
, h
: Longint
; var buffer
): Longint
; cdecl
; external libggi
;
219 function
ggiGetBox(vis
: TGGIVisual
; x
, y
, w
, h
: Longint
; var buffer
): Longint
; cdecl
; external libggi
;
221 function
ggiGetPalette(vis
: TGGIVisual
; s
, len
: Longint
; var cmap
: TGGIColor
): Longint
; cdecl
; external libggi
;
222 function
ggiSetPalette(vis
: TGGIVisual
; s
, len
: Longint
; var cmap
: TGGIColor
): Longint
; cdecl
; external libggi
;
227 CurrentMode
, OldMode
: TGGIMode
;
230 procedure ggi_savevideostate
;
232 ggiGetMode(Visual
, OldMode
);
235 procedure ggi_restorevideostate
;
237 ggiSetMode(Visual
, OldMode
);
241 BgiColors
: array
[0..15] of TGGIColor
= (
242 (r
: $0000; g
: $0000; b
: $0000; a
: 0),
243 (r
: $0000; g
: $0000; b
: $8000; a
: 0),
244 (r
: $0000; g
: $8000; b
: $0000; a
: 0),
245 (r
: $0000; g
: $8000; b
: $8000; a
: 0),
246 (r
: $8000; g
: $0000; b
: $0000; a
: 0),
247 (r
: $8000; g
: $0000; b
: $8000; a
: 0),
248 (r
: $8000; g
: $8000; b
: $0000; a
: 0),
249 (r
: $C000; g
: $C000; b
: $C000; a
: 0),
250 (r
: $8000; g
: $8000; b
: $8000; a
: 0),
251 (r
: $0000; g
: $0000; b
: $FFFF; a
: 0),
252 (r
: $0000; g
: $FFFF; b
: $0000; a
: 0),
253 (r
: $0000; g
: $FFFF; b
: $FFFF; a
: 0),
254 (r
: $FFFF; g
: $0000; b
: $0000; a
: 0),
255 (r
: $FFFF; g
: $0000; b
: $FFFF; a
: 0),
256 (r
: $FFFF; g
: $FFFF; b
: $0000; a
: 0),
257 (r
: $FFFF; g
: $FFFF; b
: $FFFF; a
: 0));
259 procedure ggi_initmodeproc
;
261 ggiParseMode(ModeNames
[IntCurrentMode
], CurrentMode
);
262 ggiSetMode(Visual
, CurrentMode
);
265 function
ClipCoords(var x
, y
: SmallInt
): Boolean
;
266 { Adapt to viewport
, return TRUE if still
in viewport
,
267 false if outside viewport
}
269 x
:= x
+ StartXViewPort
;
270 x
:= y
+ StartYViewPort
;
271 ClipCoords
:= not ClipPixels
;
272 if ClipCoords
then begin
273 ClipCoords
:= (y
< StartXViewPort
) or (x
> (StartXViewPort
+ ViewWidth
));
274 ClipCoords
:= ClipCoords
or
275 ((y
< StartYViewPort
) or (y
> (StartYViewPort
+ ViewHeight
)));
276 ClipCoords
:= not ClipCoords
;
281 procedure
ggi_directpixelproc(X
, Y
: smallint
);
283 Color
, CurCol
: TGGIPixel
;
285 CurCol
:= ggiMapColor(Visual
, BgiColors
[CurrentColor
]);
286 case CurrentWriteMode of
288 { getpixel wants local
/relative coordinates
}
289 ggiGetPixel(Visual
, x-StartXViewPort
, y-StartYViewPort
, Color
);
290 Color
:= CurCol xor Color
;
293 { getpixel wants local
/relative coordinates
}
294 ggiGetPixel(Visual
, x-StartXViewPort
, y-StartYViewPort
, Color
);
295 Color
:= CurCol
or Color
;
298 { getpixel wants local
/relative coordinates
}
299 ggiGetPixel(Visual
, x-StartXViewPort
, y-StartYViewPort
, Color
);
300 Color
:= CurCol
and Color
;
307 ggiPutPixel(Visual
, x
, y
, Color
);
310 procedure
ggi_putpixelproc(X
,Y
: smallint
; Color
: Word
);
312 If Not
ClipCoords(X
,Y
) Then exit
;
313 ggiputpixel(Visual
,x
, y
, Color
);
316 function
ggi_getpixelproc (X
,Y
: smallint
): word
;
322 ggigetpixel(Visual
,x
, y
,I
);
326 procedure ggi_clrviewproc
;
328 ggidrawbox(Visual
,StartXViewPort
,StartYViewPort
,ViewWidth
,ViewHeight
);
335 Width
, Height
: longint
;
340 procedure
ggi_putimageproc (X
,Y
: smallint
; var Bitmap
; BitBlt
: Word
);
342 With
TBitMap(BitMap
) do
343 ggiputbox(Visual
,x
, y
, width
, height
, Data
);
346 procedure
ggi_getimageproc (X1
,Y1
,X2
,Y2
: smallint
; Var Bitmap
);
348 with
TBitmap(Bitmap
) do
350 Width
:= x2
- x1
+ 1;
351 Height
:= y2
- y1
+ 1;
352 ggigetbox(Visual
,x1
,y1
, x2
- x1
+ 1, y2
- y1
+ 1, Data
);
356 function
ggi_imagesizeproc (X1
,Y1
,X2
,Y2
: smallint
): longint
;
358 // 32 bits per pixel
-- change ASAP
!!
359 ggi_imagesizeproc
:= SizeOf(TBitmap
) + (x2
- x1
+ 1) * (y2
- y1
+ 1) * SizeOF(longint
);
362 procedure
ggi_hlineproc (x
, x2
,y
: smallint
);
366 procedure
ggi_vlineproc (x
,y
,y2
: smallint
);
370 procedure
ggi_patternlineproc (x1
,x2
,y
: smallint
);
374 procedure
ggi_ellipseproc (X
,Y
: smallint
;XRadius
: word
;
375 YRadius
:word; stAngle
,EndAngle
: word
; fp
: PatternLineProc
);
379 procedure
ggi_lineproc (X1
, Y1
, X2
, Y2
: smallint
);
383 procedure
ggi_getscanlineproc (X1
, X2
, Y
: smallint
; var
data);
387 procedure
ggi_setactivepageproc (page
: word
);
391 procedure
ggi_setvisualpageproc (page
: word
);
396 procedure ggi_savestateproc
;
400 procedure ggi_restorestateproc
;
404 procedure
ggi_setrgbpaletteproc(ColorNum
, RedValue
, GreenValue
, BlueValue
: smallint
);
412 ggisetpalette(Visual
,ColorNum
,1,col
);
415 procedure
ggi_getrgbpaletteproc (ColorNum
: smallint
;
416 var RedValue
, GreenValue
, BlueValue
: smallint
);
421 ggigetpalette(Visual
,ColorNum
,1,col
);
427 {************************************************************************}
428 {* General routines
*}
429 {************************************************************************}
431 procedure CloseGraph
;
433 if not IsGraphMode
then
435 _graphresult
:= grnoinitgraph
;
439 isgraphmode
:= false;
442 function QueryAdapterInfo
:PModeInfo;
443 { This routine returns the head pointer to the list
}
444 { of supported graphics modes
. }
445 { Returns
nil if no graphics mode supported
. }
446 { This list is READ ONLY
! }
451 procedure
AddGGIMode(i
: smallint
); // i is the mode number
458 ModeName
:= ModeNames
[i
];
459 // Pretend we
're VGA always.
461 MaxX := ModeInfo.Visible.X-1;
462 MaxY := ModeInfo.Visible.Y-1;
463 MaxColor := 1 shl (ModeInfo.graphtype and $ff);
465 PaletteSize := MaxColor;
467 // necessary hooks ...
468 DirectPutPixel := @ggi_DirectPixelProc;
469 GetPixel := @ggi_GetPixelProc;
470 PutPixel := @ggi_PutPixelProc;
471 SetRGBPalette := @ggi_SetRGBPaletteProc;
472 GetRGBPalette := @ggi_GetRGBPaletteProc;
473 ClearViewPort := @ggi_ClrViewProc;
474 PutImage := @ggi_PutImageProc;
475 GetImage := @ggi_GetImageProc;
476 ImageSize := @ggi_ImageSizeProc;
478 SetVisualPage := SetVisualPageProc;
479 SetActivePage := SetActivePageProc;
480 GetScanLine := @ggi_GetScanLineProc;
481 Line := @ggi_LineProc;
482 InternalEllipse:= @ggi_EllipseProc;
483 PatternLine := @ggi_PatternLineProc;
484 HLine := @ggi_HLineProc;
485 VLine := @ggi_VLineProc;
487 InitMode := @ggi_InitModeProc;
496 QueryAdapterInfo := ModeList;
497 { If the mode listing already exists... }
498 { simply return it, without changing }
500 if Assigned(ModeList) then
502 SaveVideoState:=ggi_savevideostate;
503 RestoreVideoState:=ggi_restorevideostate;
505 If ggiInit <> 0 then begin
506 _graphresult := grNoInitGraph;
510 Visual := ggiOpen(nil, []); // Use default visual
512 ggiGetMode(Visual, OldMode);
513 ggiParseMode('', ModeInfo);
514 ggiSetMode(Visual, ModeInfo);
515 ggiGetMode(Visual, ModeInfo);
516 ggiSetMode(Visual, OldMode);
519 for i := 1 to GLastMode do begin
520 // WriteLn('Testing mode
: ', ModeNames[i]);
521 ggiParseMode(ModeNames[i], ModeInfo);
522 If ggiCheckMode(visual, ModeInfo) = 0 then begin
523 Writeln('OK
for mode
',i,' : ', ModeNames[i]);
537 Revision 1.1 2002/02/19 08:26:16 sasu
540 Revision 1.1.2.1 2000/09/14 13:38:25 marco
541 * Moved from Linux dir. now start of generic unix dir, from which the
542 really exotic features should be moved to the target specific dirs.
544 Revision 1.1 2000/07/13 06:30:53 michael
547 Revision 1.4 2000/07/09 07:22:51 peter
548 * fixed maxx,maxy setting
550 Revision 1.3 2000/07/08 21:22:16 peter
551 * finalization added with setrawmode(false)
553 Revision 1.2 2000/05/26 18:21:04 peter
554 * fixed @ with var parameters
556 Revision 1.1 2000/03/19 11:20:14 peter
557 * graph unit include is now independent and the dependent part
559 * ggigraph unit for linux added