3
{ *********************************************************************
7
This units mimics some parts of borland's graph unit for
10
You have to use crt for readln, readkey and stuff like
11
that for your programs. When the show is over you should
12
just press a key or hit return to close everything down.
14
If that doesn't work just flip the screens with left-Amiga n
15
and activate the shell you started from.
17
I have compiled and run mandel.pp without any problems.
19
This version requires Free Pascal 0.99.5c or higher.
21
It will also use some amigaunits, when the unit gets
22
better we can remove those units.
24
Large parts have not yet been implemented or tested.
26
nils.sjoholm@mailbox.swipnet.se (Nils Sjoholm)
30
Date Version Who Comments
31
---------- -------- ------- -------------------------------------
32
27-Nov-98 0.1 nsjoholm Initial version.
36
This library is free software; you can redistribute it and/or
37
modify it under the terms of the GNU Library General Public
38
License as published by the Free Software Foundation; either
39
version 2 of the License, or (at your option) any later version.
41
This library is distributed in the hope that it will be useful,
42
but WITHOUT ANY WARRANTY; without even the implied warranty of
43
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
44
Library General Public License for more details.
46
You should have received a copy of the GNU Library General Public
47
License along with this library; if not, write to the Free
48
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
51
*********************************************************************}
56
uses Exec, Intuition, Graphics, Utility;
58
{ ---------------------------------------------------------------------
61
---------------------------------------------------------------------}
128
grInvalidDriver = -4;
138
grInvalidFontNum = -14;
141
FillPatternType = array[1..8] of byte;
143
ArcCoordsType = record
145
xstart,ystart : integer;
156
Colors : array[0..767]of Byte;
160
LineSettingsType = record
166
TextSettingsType = record
174
FillSettingsType = record
183
ViewPortType = record
184
x1,y1,x2,y2 : integer;
189
fillpattern : array[0..12] of FillPatternType = (
190
($00,$00,$00,$00,$00,$00,$00,$00), { Hintergrundfarbe }
191
($ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff), { Vordergrundfarbe }
192
($ff,$ff,$00,$00,$ff,$ff,$00,$00), { === }
193
($01,$02,$04,$08,$10,$20,$40,$80), { /// }
194
($07,$0e,$1c,$38,$70,$e0,$c1,$83), { /// als dicke Linien }
195
($07,$83,$c1,$e0,$70,$38,$1c,$0e), { \\\ als dicke Linien }
196
($5a,$2d,$96,$4b,$a5,$d2,$69,$b4), { \ \\ \ }
197
($ff,$88,$88,$88,$ff,$88,$88,$88), { K�stchen }
198
($18,$24,$42,$81,$81,$42,$24,$18), { Rauten }
199
($cc,$33,$cc,$33,$cc,$33,$cc,$33), { "Mauermuster" }
200
($80,$00,$08,$00,$80,$00,$08,$00), { weit auseinanderliegende Punkte }
201
($88,$00,$22,$00,$88,$00,$22,$00), { dichte Punkte}
202
(0,0,0,0,0,0,0,0) { benutzerdefiniert }
209
{ ---------------------------------------------------------------------
210
Function Declarations
212
---------------------------------------------------------------------}
214
{ Retrieving coordinates }
215
function GetX: Integer;
216
function GetY: Integer;
218
{ Pixel-oriented routines }
219
procedure PutPixel(X, Y: Integer; Pixel: Word);
220
function GetPixel(X, Y: Integer): Integer;
222
{ Line-oriented primitives }
223
procedure LineTo(X, Y: Integer);
224
procedure LineRel(Dx, Dy: Integer);
225
procedure MoveTo(X, Y: Integer);
226
procedure MoveRel(Dx, Dy: Integer);
227
procedure Line(x1, y1, x2, y2: Integer);
229
{ Linearly bounded primitives }
230
procedure Rectangle(x1, y1, x2, y2: Integer);
231
procedure Bar(x1, y1, x2, y2: Integer);
232
procedure Bar3D(x1, y1, x2, y2: Integer; Depth: Word; Top: Boolean);
233
procedure FloodFill(X, Y: Integer; Border: Word);
235
{ Nonlinearly bounded primitives }
237
procedure Arc(X, Y: Integer; StAngle, EndAngle, Radius: Word);
238
procedure GetArcCoords(var ArcCoords: ArcCoordsType);
239
procedure Circle(X, Y: Integer; Radius: Word);
240
procedure Ellipse(X, Y: Integer; StAngle, EndAngle: Word; XRadius, YRadius : Word);
241
procedure FillEllipse(X, Y: Integer; XRadius, YRadius : Word);
242
procedure SetAspectRatio(Xasp, Yasp: Word);
243
procedure PieSlice(X, Y: Integer; StAngle, EndAngle, Radius: Word);
244
procedure Sector(X, Y: Integer; StAngle, EndAngle, XRadius, YRadius: Word);
247
procedure SetBkColor(ColorNum: Word);
248
procedure SetColor(Color: Word);
249
Function GetBkColor : Word;
250
Function GetColor : Word;
251
function GetMaxColor : Word;
253
function GetMaxX : Integer;
254
function GetMAxY : Integer;
255
function GetAspect: Real;
256
procedure GetAspectRatio(var x,y : Word);
258
{ Graph clipping method }
259
Procedure ClearViewPort;
261
function GraphResult: Integer;
263
{ For compatibility }
264
Procedure InitGraph (Var Driver,Mode : Integer;DriverPath : String);
265
Procedure CloseGraph;
268
NoGraphics: Boolean = false;
271
GTEXT = 0; { Compatible with VGAlib v1.2 }
286
G1280x1024x256 = 13; { Additional modes. }
308
G720x348x2 = 32; { Hercules emulation mode }
310
G320x200x16M32 = 33; { 32-bit per pixel modes. }
313
G1024x768x16M32 = 36;
314
G1280x1024x16M32 = 37;
316
{ additional resolutions }
322
G1152x864x16M32 = 43;
329
G1600x1200x16M32 = 49;
338
{ ---------------------------------------------------------------------
339
Types, constants and variables
341
---------------------------------------------------------------------}
342
VAR GraphScr :pScreen;
344
CurrentRastPort : pRastPort;
346
GraphResultCode : Integer;
354
TheColor, TheFillColor: LongInt;
356
ColorTable: array[0..15] of LongInt;
357
TheFillPattern : FillPatternType;
358
TheLineSettings : LineSettingsType;
359
ThePalette : PaletteType;
360
TheTextSettings : TextSettingsType;
361
TheFillSettings : FillSettingsType;
364
BgiColors: array[0..15] of LongInt
365
= ($000000, $000080, $008000, $008080,
366
$800000, $800080, $808000, $C0C0C0,
367
$808080, $0000FF, $00FF00, $00FFFF,
368
$FF0000, $FF00FF, $FFFF00, $FFFFFF);
371
DoUseMarker: Boolean = true;
372
TheMarker: Char = '~';
373
TextColor: LongInt = 15;
374
MarkColor: LongInt = 15;
375
BackColor: LongInt = 0;
376
FontWidth: Integer = 8;
377
FontHeight: Integer = 8;
382
{ initialisierte Variablen }
384
SourcePage: Word = 0;
387
{ Retrieves the capabilities for the current mode }
395
{ ---------------------------------------------------------------------
396
Graphics Vision Layer
397
---------------------------------------------------------------------}
400
{ Types and constants }
422
Width, Height: Integer;
434
SetRGB4(@GraphScr^.ViewPort, Black , 0,0,0);
435
SetRGB4(@GraphScr^.ViewPort, Blue , 0,0,15);
436
SetRGB4(@GraphScr^.ViewPort, Green , 0,15,0);
437
SetRGB4(@GraphScr^.ViewPort, Cyan , 0,15,15);
438
SetRGB4(@GraphScr^.ViewPort, Red , 15,0,0);
439
SetRGB4(@GraphScr^.ViewPort, Magenta , 15,0,15);
440
SetRGB4(@GraphScr^.ViewPort, Brown , 6,2,0);
441
SetRGB4(@GraphScr^.ViewPort, LightGray, 13,13,13);
442
SetRGB4(@GraphScr^.ViewPort, DarkGray , 4,4,4);
443
SetRGB4(@GraphScr^.ViewPort, LightBlue, 5,5,5);
444
SetRGB4(@GraphScr^.ViewPort, LightGreen ,9,15,1);
445
SetRGB4(@GraphScr^.ViewPort, LightRed ,14,5,0);
446
SetRGB4(@GraphScr^.ViewPort, LightMagenta ,0,15,8);
447
SetRGB4(@GraphScr^.ViewPort, Yellow ,15,15,0);
448
SetRGB4(@GraphScr^.ViewPort, White ,15,15,15);
452
{ ---------------------------------------------------------------------
453
Real graph implementation
454
---------------------------------------------------------------------}
456
function GraphResult: Integer;
458
GraphResult := GraphResultCode;
461
Procedure ClearViewPort;
463
SetRast(CurrentRastPort,Black);
466
function GetX: Integer;
471
function GetY: Integer;
476
function GetAspect: Real;
478
GetAspect := GetMaxY/GetMaxX;
481
procedure GetAspectRatio(var x,y : Word);
487
{ Pixel-oriented routines }
488
procedure PutPixel(x,y : Integer; Pixel : Word);
490
SetAPen(CurrentRastPort,Pixel);
491
WritePixel(CurrentRastPort,x,y);
496
function GetPixel(X, Y: Integer): Integer;
498
GetPixel := ReadPixel(CurrentRastPort,X,Y);
501
{ Line-oriented primitives }
503
procedure LineTo(X, Y: Integer);
505
Draw(CurrentRastPort,X,Y);
510
procedure LineRel(Dx, Dy: Integer);
514
Draw(CurrentRastPort, Curx, CurY);
517
procedure MoveTo(X, Y: Integer);
519
Move(CurrentRastPort, X , Y);
524
procedure MoveRel(Dx, Dy: Integer);
528
Move(CurrentRastPort, Curx, CurY);
531
procedure Line(x1,y1,x2,y2: Integer);
533
Move(CurrentRastPort,x1,y1);
534
Draw(CurrentRastPort,x2,y2);
535
Move(CurrentRastPort,CurX, CurY);
538
procedure Rectangle(x1, y1, x2, y2: Integer);
540
Move(CurrentRastPort, x1, y1);
541
Draw(CurrentRastPort, x2, y1);
542
Draw(CurrentRastPort, x2, y2);
543
Draw(CurrentRastPort, x1, y2);
544
Draw(CurrentRastPort, x1, y1);
549
procedure Bar(x1, y1, x2, y2: Integer);
551
RectFill(CurrentRastPort, x1, y1, x2, y2);
556
procedure Bar3D(x1, y1, x2, y2: Integer; Depth: Word; Top: Boolean);
559
Rectangle(x1,y1,x2,y2);
562
Lineto(x1+depth,y1-depth);
563
Lineto(x2+depth,y1-depth);
566
Moveto(x2+depth,y1-depth);
567
Lineto(x2+depth,y2-depth);
572
procedure FloodFill(X, Y: Integer; Border: Word);
577
Var LastArcCoords : ArcCoordsType;
580
procedure SetArcCoords (X,y,xradius,yradius,Stangle,endangle : integer);
585
Lastarccoords.xstart:=x+round(xradius*cos(stangle*pi/180));
586
Lastarccoords.ystart:=y-round(yradius*sin(stangle*pi/180));
587
LastArccoords.xend:=x+round(xradius*cos(endangle*pi/180));
588
LastArccoords.yend:=y-round(yradius*sin(endangle*pi/180));
592
procedure GetArcCoords(var ArcCoords: ArcCoordsType);
595
ArcCoords:=LastArcCoords;
598
procedure Arc(X, Y: Integer; StAngle, EndAngle, Radius: Word);
601
Ellipse (X,y,stangle,endangle,Radius,radius);
604
procedure Circle(X, Y: Integer; Radius: Word);
606
DrawEllipse(CurrentRastPort, x, y, Round(Radius * TheAspect), Radius);
609
procedure Ellipse(X, Y: Integer;
610
StAngle, EndAngle: Word; XRadius, YRadius : Word);
616
SetArcCoords (X,Y,xradius,yradius,Stangle,EndAngle);
617
For i:= StAngle To EndAngle Do
620
curX:= X + Round (xRadius*Cos (tmpAng));
621
curY:= Y - Round (YRadius*Sin (tmpAng));
622
PutPixel (curX, curY, TheColor);
626
procedure FillEllipse(X, Y: Integer; XRadius, YRadius : Word);
628
Var I,tmpcolor : longint;
634
SetColor(TheFillColor);
638
curX:= Round (xRadius*Cos (tmpAng));
639
curY:= Round (YRadius*Sin (tmpAng));
644
Line (curX, curY,tmpx,tmpy);
645
PutPixel (curx,cury,tmpcolor);
646
PutPixel (tmpx,tmpy,tmpcolor);
651
procedure SetAspectRatio(Xasp, Yasp: Word);
653
//!! Needs implementing.
656
procedure PieSlice(X, Y: Integer; StAngle, EndAngle, Radius: Word);
659
sector (x,y,stangle,endangle,radius,radius);
662
procedure Sector(X, Y: Integer;
663
StAngle, EndAngle, XRadius, YRadius: Word);
665
Var I,tmpcolor : longint;
671
SetColor(TheFillColor);
672
For i:= stangle to endangle Do
675
curX:= x+Round (xRadius*Cos (tmpAng));
676
curY:= y-Round (YRadius*Sin (tmpAng));
677
Line (x,y,curX, curY);
678
PutPixel (curx,cury,tmpcolor);
682
Line (x,y,ac.xstart,ac.ystart);
683
Line (x,y,ac.xend,ac.yend);
689
procedure SetBkColor(ColorNum: Word);
691
SetBPen(CurrentRastPort, ColorNum);
692
BackColor := ColorNum;
695
Function GetBkColor : Word;
698
GetBkColor:=BackColor;
701
Function GetColor : Word;
707
procedure SetColor(color : Word);
709
SetAPen(CurrentRastPort,color);
713
function GetMaxColor: word;
718
function GetMaxX: Integer;
720
GetMaxX := GraphWin^.Width;
723
function GetMaxY: Integer;
725
GetMaxY := GraphWin^.Height;
728
Procedure InitGraph (Var Driver,Mode : Integer;DriverPath : String);
730
thetags : array[0..3] of tTagItem;
733
GraphResultCode := grOK;
734
GfxBase := OpenLibrary(GRAPHICSNAME,0);
735
if GfxBase = nil then begin
736
GraphResultCode := grNoInitGraph;
740
GraphScr:=Nil; GraphWin:=Nil;
742
{ Will open an hires interlace screen, if you
743
want just an hires screen change HIRESLACE_KEY
746
thetags[0] := TagItem(SA_Depth, 4);
747
thetags[1] := TagItem(SA_DisplayID, HIRESLACE_KEY);
748
thetags[2].ti_Tag := TAG_END;
750
GraphScr := OpenScreenTagList(NIL,@thetags);
751
If GraphScr=Nil Then begin
752
GraphResultCode := grNoInitGraph;
756
thetags[0] := TagItem(WA_Flags, WFLG_BORDERLESS);
757
thetags[1] := TagItem(WA_IDCMP, IDCMP_MOUSEBUTTONS);
758
thetags[2] := TagItem(WA_CustomScreen, Longint(GraphScr));
759
thetags[3].ti_Tag := TAG_DONE;
761
GraphWin:=OpenWindowTagList(Nil, @thetags);
762
If GraphWin=Nil Then CloseGraph;
764
CurrentRastPort := GraphWin^.RPort;
767
TheAspect := GetAspect;
770
PROCEDURE CloseGraph;
774
Msg:=pIntuiMessage(GetMsg(GraphWin^.UserPort));
775
If Msg<>Nil Then Begin
776
ReplyMsg(Pointer(Msg));
780
If GraphWin<>Nil Then
781
CloseWindow(GraphWin);
782
If (GraphScr<>Nil) then CloseScreen(GraphScr);
783
if GfxBase <> nil then CloseLibrary(GfxBase);