next up previous contents index search.gif
Next: 6. The HEAPTRC unit. Up: Unit reference for Free Previous: 4. The GO32 unit

Subsections


5. The GRAPH unit.

This document describes the GRAPH unit for Free Pascal, under DOS. The unit was first written for DOS by Florian klämpfl. This chapter is divided in three sections.


5.1 Introduction

5.1.1 Requirements

The unit Graph exports functions and procedures for graphical output. It requires at least a VESA compatible VGA-Card or a VGA-Card with software-driver (min. 512Kb video memory). Before the graph unit can be used, be sure your graphics adapter supports the VESA-Standard. Otherwise in the most cases you can try to use a VESA-TSR to make your adapter VESA compatible (e.g. UNIVBE).

5.2 Constants, Types and Variables

5.2.1 Types


ArcCoordsType = record
 X,Y,Xstart,Ystart,Xend,Yend : Integer;
end;
FillPatternType = Array [1..8] of Byte;
FillSettingsType = Record
 Pattern,Color : Word
end;
LineSettingsType = Record
  LineStyle,Pattern, Width : Word;
end;
PaletteType = Record
 Size : Byte;
 Colors : array[0..MAxColor] of shortint;
end;
PointType = Record
  X,Y : Integer;
end;
TextSettingsType = Record
 Font,Direction, CharSize, Horiz, Vert : Word
end;
ViewPortType = Record
  X1,Y1,X2,Y2 : Integer;
  Clip : Boolean
end;

5.3 Functions and procedures


5.3.1 Arc

Declaration
Procedure Arc (X,Y : Integer; start,stop, radius : Word);

Description
Arc draws part of a circle with center at (X,Y), radius radius, starting from angle start, stopping at angle stop. These angles are measured counterclockwise.
Errors
None.
See also
Circle,Ellipse GetArcCoords,PieSlice, Sector


5.3.2 Bar

Declaration
Procedure Bar (X1,Y1,X2,Y2 : Integer);

Description
Draws a rectangle with corners at (X1,Y1) and (X2,Y2) and fills it with the current color and fill-style.
Errors
None.
See also
Bar3D, Rectangle


5.3.3 Bar3D

Declaration
Procedure Bar3D (X1,Y1,X2,Y2 : Integer; depth : Word; Top : Boolean);

Description
Draws a 3-dimensional Bar with corners at (X1,Y1) and (X2,Y2) and fills it with the current color and fill-style. Depth specifies the number of pixels used to show the depth of the bar. If Top is true; then a 3-dimensional top is drawn.
Errors
None.
See also
Bar, Rectangle


5.3.4 Circle

Declaration
Procedure Circle (X,Y : Integer; Radius : Word);

Description
Circle draws part of a circle with center at (X,Y), radius radius.
Errors
None.
See also
Ellipse,Arc GetArcCoords,PieSlice, Sector


5.3.5 ClearDevice

Declaration
Procedure ClearDevice ;

Description
Clears the graphical screen (with the current background color), and sets the pointer at (0,0)
Errors
None.
See also
ClearViewPort, SetBkColor


5.3.6 ClearViewPort

Declaration
Procedure ClearViewPort ;

Description
Clears the current view-port. The current background color is used as filling color. The pointer is set at (0,0)
Errors
None.
See also
ClearDevice,SetViewPort, SetBkColor


5.3.7 CloseGraph

Declaration
Procedure CloseGraph ;

Description
Closes the graphical system, and restores the screen modus which was active before the graphical modus was activated.
Errors
None.
See also
InitGraph


5.3.8 DetectGraph

Declaration
Procedure DetectGraph (Var Driver, Modus : Integer);

Description
Checks the hardware in the PC and determines the driver and screen-modus to be used. These are returned in Driver and Modus, and can be fed to InitGraph. See the InitGraph for a list of drivers and modi.
Errors
None.
See also
InitGraph


5.3.9 DrawPoly

Declaration
Procedure DrawPoly (NumberOfPoints : Word; Var PolyPoints;

Description

Draws a polygone with NumberOfPoints corner points, using the current color and line-style. PolyPoints is an array of type PointType.

Errors
None.
See also
Bar, seepBar3D, Rectangle


5.3.10 Ellipse

Declaration
Procedure Ellipse (X,Y : Integer; Start,Stop,XRadius,YRadius : Word);

Description
Ellipse draws part of an ellipse with center at (X,Y). XRadius and Yradius are the horizontal and vertical radii of the ellipse. Start and Stop are the starting and stopping angles of the part of the ellipse. They are measured counterclockwise from the X-axis.
Errors
None.
See also
Arc Circle, FillEllipse


5.3.11 FillEllipse

Declaration
Procedure FillEllipse (X,Y : Integer; Xradius,YRadius: Word);

Description
Ellipse draws an ellipse with center at (X,Y). XRadius and Yradius are the horizontal and vertical radii of the ellipse. The ellipse is filled with the current color and fill-style.
Errors
None.
See also
Arc Circle, GetArcCoords,PieSlice, Sector


5.3.12 FillPoly

Declaration
Procedure FillPoly (NumberOfPoints : Word; Var PolyPoints);

Description

Draws a polygone with NumberOfPoints corner points and fills it using the current color and line-style. PolyPoints is an array of type PointType.

Errors
None.
See also
Bar, seepBar3D, Rectangle


5.3.13 FloodFill

Declaration
Procedure FloodFill (X,Y : Integer; BorderColor : Word);

Description

Fills the area containing the point (X,Y), bounded by the color BorderColor.

Errors
None
See also
SetColor, SetBkColor


5.3.14 GetArcCoords

Declaration
Procedure GetArcCoords (Var ArcCoords : ArcCoordsType);

Description
GetArcCoords returns the coordinates of the latest Arc or Ellipse call.
Errors
None.
See also
Arc, Ellipse


5.3.15 GetAspectRatio

Declaration
Procedure GetAspectRatio (Var Xasp,Yasp : Word);

Description
GetAspectRatio determines the effective resolution of the screen. The aspect ration can the be calculated as Xasp/Yasp.
Errors
None.
See also
InitGraph,SetAspectRatio


5.3.16 GetBkColor

Declaration
Function GetBkColor : Word;

Description
GetBkColor returns the current background color (the palette entry).
Errors
None.
See also
GetColor,SetBkColor


5.3.17 GetColor

Declaration
Function GetColor : Word;

Description
GetColor returns the current drawing color (the palette entry).
Errors
None.
See also
GetColor,SetBkColor


5.3.18 GetDefaultPalette

Declaration
Procedure GetDefaultPalette (Var Palette : PaletteType);

Description
Returns the current palette in Palette.
Errors
None.
See also
GetColor, GetBkColor


5.3.19 GetDriverName

Declaration
Function GetDriverName : String;

Description
GetDriverName returns a string containing the name of the current driver.
Errors
None.
See also
GetModeName, InitGraph


5.3.20 GetFillPattern

Declaration
Procedure GetFillPattern (Var FillPattern : FillPatternType);

Description
GetFillPattern returns an array with the current fill-pattern in FillPattern
Errors
None
See also
SetFillPattern


5.3.21 GetFillSettings

Declaration
Procedure GetFillSettings (Var FillInfo : FillSettingsType);

Description
GetFillSettings returns the current fill-settings in FillInfo
Errors
None.
See also
SetFillPattern


5.3.22 GetGraphMode

Declaration
Function GetGraphMode : Integer;

Description
GetGraphMode returns the current graphical modus
Errors
None.
See also
InitGraph


5.3.23 GetImage

Declaration
Procedure GetImage (X1,Y1,X2,Y2 : Integer, Var Bitmap;

Description
GetImage Places a copy of the screen area (X1,Y1) to X2,Y2 in BitMap
Errors
Bitmap must have enough room to contain the image.
See also
ImageSize, PutImage


5.3.24 GetLineSettings

Declaration
Procedure GetLineSettings (Var LineInfo : LineSettingsType);

Description
GetLineSettings returns the current Line settings in LineInfo
Errors
None.
See also
SetLineStyle


5.3.25 GetMaxColor

Declaration
Function GetMaxColor : Word;

Description
GetMaxColor returns the maximum color-number which can be set with SetColor
Errors
None.
See also
SetColor, GetPaletteSize


5.3.26 GetMaxMode

Declaration
Function GetMaxMode : Word;

Description
GetMaxMode returns the highest modus for the current driver.
Errors
None.
See also
InitGraph


5.3.27 GetMaxX

Declaration
Function GetMaxX : Word;

Description
GetMaxX returns the maximum horizontal screen length
Errors
None.
See also
GetMaxY


5.3.28 GetMaxY

Declaration
Function GetMaxY : Word;

Description
GetMaxY returns the maximum number of screen lines
Errors
None.
See also
GetMaxY


5.3.29 GetModeName

Declaration
Function GetModeName (Var modus : Integer) : String;

Description

Returns a string with the name of modus Modus

Errors
None.
See also
GetDriverName, InitGraph


5.3.30 GetModeRange

Declaration
Procedure GetModeRange (Driver : Integer;
LoModus, HiModus: Integer);

Description
GetModeRange returns the Lowest and Highest modus of the currently installed driver.
Errors
None.
See also
InitGraph


5.3.31 GetPalette

Declaration
Procedure GetPalette (Var Palette : PaletteType);

Description
GetPalette returns in Palette the current palette.
Errors
None.
See also
GetPaletteSize, SetPalette


5.3.32 GetPaletteSize

Declaration
Function GetPaletteSize : Word;

Description
GetPaletteSize returns the maximum number of entries in the current palette.
Errors
None.
See also
GetPalette, SetPalette


5.3.33 GetPixel

Declaration
Function GetPixel (X,Y : Integer) : Word;

Description
GetPixel returns the color of the point at (X,Y)
Errors
None.
See also


5.3.34 GetTextSettings

Declaration
Procedure GetTextSettings (Var TextInfo : TextSettingsType);

Description
GetTextSettings returns the current text style settings : The font, direction, size and placement as set with SetTextStyle and SetTextJustify
Errors
None.
See also
SetTextStyle, SetTextJustify


5.3.35 GetViewSettings

Declaration
Procedure GetViewSettings (Var ViewPort : ViewPortType);

Description
GetViewSettings returns the current view-port and clipping settings in ViewPort.
Errors
None.
See also
SetViewPort


5.3.36 GetX

Declaration
Function GetX : Integer;

Description
GetX returns the X-coordinate of the current position of the graphical pointer
Errors
None.
See also
GetY


5.3.37 GetY

Declaration
Function GetY : Integer;

Description
GetY returns the Y-coordinate of the current position of the graphical pointer
Errors
None.
See also
GetX


5.3.38 GraphDefaults

Declaration
Procedure GraphDefaults ;

Description
GraphDefaults resets all settings for view-port, palette, foreground and background pattern, line-style and pattern, filling style, filling color and pattern, font, text-placement and text size.
Errors
None.
See also
SetViewPort, SetFillStyle, SetColor, SetBkColor, SetLineStyle


5.3.39 GraphErrorMsg

Declaration
Function GraphErrorMsg (ErrorCode : Integer) : String;

Description
GraphErrorMsg returns a string describing the error Errorcode. This string can be used to let the user know what went wrong.
Errors
None.
See also
GraphResult


5.3.40 GraphResult

Declaration
Function GraphResult : Integer;

Description
GraphResult returns an error-code for the last graphical operation. If the returned value is zero, all went well. A value different from zero means an error has occurred. Except for all operations which draw something on the screen, the following procedures also can produce a GraphResult different from zero:

Errors
None.
See also
GraphErrorMsg


5.3.41 ImageSize

Declaration
Function ImageSize (X1,Y1,X2,Y2 : Integer) : Word;

Description
ImageSize returns the number of bytes needed to store the image in the rectangle defined by (X1,Y1) and (X2,Y2).
Errors
None.
See also
GetImage


5.3.42 InitGraph

Declaration
Procedure InitGraph (var GraphDriver,GraphModus : integer;
const PathToDriver : string);

Description

InitGraph initializes the graph package. GraphDriver has two valid values: GraphDriver=0 which performs an auto detect and initializes the highest possible mode with the most colors. 1024x768x64K is the highest possible resolution supported by the driver, if you need a higher resolution, you must edit MODES.PPI. If you need another mode, then set GraphDriver to a value different from zero and graphmode to the mode you wish (VESA modes where 640x480x256 is 101h etc.). PathToDriver is only needed, if you use the BGI fonts from Borland.

Errors
None.
See also
Introduction, (page [*]), DetectGraph, CloseGraph, GraphResult
Example:

var 
   gd,gm : integer; 
   PathToDriver : string; 
begin 
   gd:=detect; { highest possible resolution } 
   gm:=0; { not needed, auto detection } 
   PathToDriver:='C:\PP\BGI'; { path to BGI fonts, 
                                drivers aren't needed } 
   InitGraph(gd,gm,PathToDriver); 
   if GraphResult<>grok then 
     halt; ..... { whatever you need } 
   CloseGraph; { restores the old graphics mode } 
end.


5.3.43 InstallUserDriver

Declaration
Function InstallUserDriver (DriverPath : String;
AutoDetectPtr: Pointer) : Integer;

Description
InstallUserDriver adds the device-driver DriverPath to the list of .BGI drivers. AutoDetectPtr is a pointer to a possible auto-detect function.
Errors
None.
See also
InitGraph, InstallUserFont


5.3.44 InstallUserFont

Declaration
Function InstallUserFont (FontPath : String) : Integer;

Description
InstallUserFont adds the font in FontPath to the list of fonts of the .BGI system.
Errors
None.
See also
InitGraph, InstallUserDriver


5.3.45 Line

Declaration
Procedure Line (X1,Y1,X2,Y2 : Integer);

Description
Line draws a line starting from (X1,Y1 to (X2,Y2), in the current line style and color. The current position is put to (X2,Y2)
Errors
None.
See also
LineRel,LineTo


5.3.46 LineRel

Declaration
Procedure LineRel (DX,DY : Integer);

Description
LineRel draws a line starting from the current pointer position to the point(DX,DY, relative to the current position, in the current line style and color. The Current Position is set to the endpoint of the line.
Errors
None.
See also
Line, LineTo


5.3.47 LineTo

Declaration
Procedure LineTo (DX,DY : Integer);

Description
LineTo draws a line starting from the current pointer position to the point(DX,DY, relative to the current position, in the current line style and color. The Current position is set to the end of the line.
Errors
None.
See also
LineRel,Line


5.3.48 MoveRel

Declaration
Procedure MoveRel (DX,DY : Integer;

Description
MoveRel moves the pointer to the point (DX,DY), relative to the current pointer position
Errors
None.
See also
MoveTo


5.3.49 MoveTo

Declaration
Procedure MoveTo (X,Y : Integer;

Description
MoveTo moves the pointer to the point (X,Y).
Errors
None.
See also
MoveRel


5.3.50 OutText

Declaration
Procedure OutText (Const TextString : String);

Description
OutText puts TextString on the screen, at the current pointer position, using the current font and text settings. The current position is moved to the end of the text.
Errors
None.
See also
OutTextXY


5.3.51 OutTextXY

Declaration
Procedure OutTextXY (X,Y : Integer; Const TextString : String);

Description
OutText puts TextString on the screen, at position (X,Y), using the current font and text settings. The current position is moved to the end of the text.
Errors
None.
See also
OutText


5.3.52 PieSlice

Declaration
Procedure PieSlice (X,Y : Integer;
Start,Stop,Radius : Word);

Description
PieSlice draws and fills a sector of a circle with center (X,Y) and radius Radius, starting at angle Start and ending at angle Stop.
Errors
None.
See also
Arc, Circle, Sector


5.3.53 PutImage

Declaration
Procedure PutImage (X1,Y1 : Integer; Var Bitmap; How : word) ;

Description
PutImage Places the bitmap in Bitmap on the screen at (X1,Y1). How determines how the bitmap will be placed on the screen. Possible values are :
Errors
None
See also
ImageSize,GetImage


5.3.54 PutPixel

Declaration
Procedure PutPixel (X,Y : Integer; Color : Word);

Description
Puts a point at (X,Y) using color Color
Errors
None.
See also
GetPixel


5.3.55 Rectangle

Declaration
Procedure Rectangle (X1,Y1,X2,Y2 : Integer);

Description
Draws a rectangle with corners at (X1,Y1) and (X2,Y2), using the current color and style.
Errors
None.
See also
Bar, Bar3D


5.3.56 RegisterBGIDriver

Declaration
Function RegisterBGIDriver (Driver : Pointer) : Integer;

Description
Registers a user-defined BGI driver
Errors
None.
See also
InstallUserDriver, RegisterBGIFont


5.3.57 RegisterBGIFont

Declaration
Function RegisterBGIFont (Font : Pointer) : Integer;

Description
Registers a user-defined BGI driver
Errors
None.
See also
InstallUserFont, RegisterBGIDriver


5.3.58 RestoreCRTMode

Declaration
Procedure RestoreCRTMode ;

Description
Restores the screen modus which was active before the graphical modus was started.
Errors
None.
See also
InitGraph


5.3.59 Sector

Declaration
Procedure Sector (X,Y : Integer;
Start,Stop,XRadius,YRadius : Word);

Description
Sector draws and fills a sector of an ellipse with center (X,Y) and radii XRadius and YRadius, starting at angle Start and ending at angle Stop.
Errors
None.
See also
Arc, Circle, PieSlice


5.3.60 SetActivePage

Declaration
Procedure SetActivePage (Page : Word);

Description
Sets Page as the active page for all graphical output.
Errors
None.
See also


5.3.61 SetAllPallette

Declaration
Procedure SetAllPallette (Var Palette);

Description
Sets the current palette to Palette. Palette is an untyped variable, usually pointing to a record of type PaletteType
Errors
None.
See also
GetPalette


5.3.62 SetAspectRatio

Declaration
Procedure SetAspectRatio (Xasp,Yasp : Word);

Description
Sets the aspect ratio of the current screen to Xasp/Yasp.
Errors
None
See also
InitGraph, GetAspectRatio


5.3.63 SetBkColor

Declaration
Procedure SetBkColor (Color : Word);

Description
Sets the background color to Color.
Errors
None.
See also
GetBkColor, SetColor


5.3.64 SetColor

Declaration
Procedure SetColor (Color : Word);

Description
Sets the foreground color to Color.
Errors
None.
See also
GetColor, SetBkColor


5.3.65 SetFillPattern

Declaration
Procedure SetFillPattern (FillPattern : FillPatternType,
Color : Word);

Description
SetFillPattern sets the current fill-pattern to FillPattern, and the filling color to Color The pattern is an 8x8 raster, corresponding to the 64 bits in FillPattern.
Errors
None
See also
GetFillPattern, SetFillStyle


5.3.66 SetFillStyle

Declaration
Procedure SetFillStyle (Pattern,Color : word);

Description
SetFillStyle sets the filling pattern and color to one of the predefined filling patterns. Pattern can be one of the following predefined constants :

Errors
None.
See also
SetFillPattern


5.3.67 SetGraphBufSize

Declaration
Procedure SetGraphBufSize (BufSize : Word);

Description
SetGraphBufSize sets the graphical buffer size. The default size is 4Kb
Errors
None.
See also


5.3.68 SetGraphMode

Declaration
Procedure SetGraphMode (Mode : Integer);

Description
SetGraphMode sets the graphical mode and clears the screen.
Errors
None.
See also
InitGraph


5.3.69 SetLineStyle

Declaration
Procedure SetLineStyle (LineStyle,Pattern,Width : Word);

Description
SetLineStyle sets the drawing style for lines. You can specify a LineStyle which is one of the following pre-defined constants: If UserBitln is specified then Pattern contains the bit pattern. In all another cases, Pattern is ignored. The parameter Width indicates how thick the line should be. You can specify one of the following pre-defined constants:

Errors
None.
See also
GetLineSettings


5.3.70 SetPalette

Declaration
Procedure SetPalette (ColorNr : Word; NewColor : ShortInt);

Description
SetPalette changes the ColorNr-th entry in the palette to NewColor
Errors
None.
See also
SetAllPallette,SetRGBPalette


5.3.71 SetRGBPalette

Declaration
Procedure SetRGBPalette (ColorNr,Red,Green,Blue : Integer);

Description
SetRGBPalette sets the ColorNr-th entry in the palette to the color with RGB-values Red, Green Blue.
Errors
None.
See also
SetAllPallette, SetPalette


5.3.72 SetTextJustify

Declaration
Procedure SetTextJustify (Horizontal,Vertical : Word);

Description
SetTextJustify controls the placement of new text, relative to the (graphical) cursor position. Horizontal controls horizontal placement, and can be one of the following pre-defined constants: Vertical controls the vertical placement of the text, relative to the (graphical) cursor position. Its value can be one of the following pre-defined constants :

Errors
None.
See also
OutText, OutTextXY


5.3.73 SetTextStyle

Declaration
Procedure SetTextStyle (Font,Direction,Magnitude : Word);

Description
SetTextStyle controls the style of text to be put on the screen. pre-defined constants for Font are: Pre-defined constants for Direction are :
Errors
None.
See also
GetTextSettings


5.3.74 SetUserCharSize

Declaration
Procedure SetUserCharSize (Xasp1,Xasp2,Yasp1,Yasp2 : Word);

Description
Sets the width and height of vector-fonts. The horizontal size is given by Xasp1/Xasp2, and the vertical size by Yasp1/Yasp2.
Errors
None.
See also
SetTextStyle


5.3.75 SetViewPort

Declaration
Procedure SetViewPort (X1,Y1,X2,Y2 : Integer; Clip : Boolean);

Description
Sets the current graphical view-port (window) to the rectangle defined by the top-left corner (X1,Y1) and the bottom-right corner (X2,Y2). If Clip is true, anything drawn outside the view-port (window) will be clipped (i.e. not drawn). Coordinates specified after this call are relative to the top-left corner of the view-port.
Errors
None.
See also
GetViewSettings


5.3.76 SetVisualPage

Declaration
Procedure SetVisualPage (Page : Word);

Description
SetVisualPage sets the video page to page number Page.
Errors
None
See also
SetActivePage


5.3.77 SetWriteMode

Declaration
Procedure SetWriteMode (Mode : Integer);

Description
SetWriteMode controls the drawing of lines on the screen. It controls the binary operation used when drawing lines on the screen. Mode can be one of the following pre-defined constants:
Errors
None.
See also


5.3.78 TextHeight

Declaration
Function TextHeight (S : String) : Word;

Description
TextHeight returns the height (in pixels) of the string S in the current font and text-size.

Errors
None.
See also
TextWidth


5.3.79 TextWidth

Declaration
Function TextWidth (S : String) : Word;

Description
TextHeight returns the width (in pixels) of the string S in the current font and text-size.

Errors
None.
See also
TextHeight



root
1999-06-10