(* ========================================================= Simple graphics interface for gpm using X calls Written by Andrew Tridgell, March 1994 This module relies on the C module graph.c Version 1 Change log: - Version 1.0 released 11/3/94 Initial version - version 1.01 released 15/3/94 Added FillArc, FillEllipse and FillCircle. Fixed bug that caused a "events processed" error message on EndGraphics. Fixed save and restore of graphics settings clean up of much of the C code added AvailableColors call. - version 1.02 released 17/3/94 added backing store made the returned mouse positions never be negative - version 1.03 fixed height bug in StartGraphics() allowed ScreenHeight() and ScreenWidth() to be called before StartGraphics() ========================================================= *) FOREIGN DEFINITION MODULE Graph; IMPORT IMPLEMENTATION FROM "Graph.o & -lX11 & libXpm.a"; (* ************************ *) (* some types for events *) (* ************************ *) TYPE (* mouse and key events *) Event = (Expose, KeyPress, KeyRelease, ButtonPress, ButtonRelease, Motion); EventSet = SET OF Event; (* styles of line drawing *) LineStyle = (LineSolid, LineDoubleDash, LineOnOffDash); (* logical function used to comine source and destination when drawing *) DrawingFunction = (Clear,And,AndReverse,Copy,AndInverted, Noop,Xor,Or,Nor,Equiv,Invert,OrReverse, CopyInverted,OrInverted,Nand,Set); (* ************************ *) (* initialisation functions *) (* ************************ *) PROCEDURE StartGraphics(Width, Height : INTEGER; Shadow: BOOLEAN); (* open a graphics window with the specified width and height *) PROCEDURE EndGraphics; (* close the graphics window *) PROCEDURE ClearWindow; (* clear the graphics window *) PROCEDURE ClearArea(Xpos, Ypos, Width, Height : INTEGER); (* clear a graphics region *) PROCEDURE SetTitle(Title : ARRAY OF CHAR); (* set the window title *) PROCEDURE Display; (* display the shadow buffer on screen (if shadowing enabled) *) (* *********************** *) (* event functions *) (* *********************** *) PROCEDURE WaitForButtonPress; (* wait till a mouse button is pressed *) PROCEDURE WaitForEvent(Event : EventSet); (* wait for one of the events in the event set *) PROCEDURE LastEvent() : EventSet; (* return the set of the last event *) (* *********************** *) (* drawing functions *) (* *********************** *) PROCEDURE DrawLine(Left, Top, Right, Bottom : INTEGER); (* draw a line *) PROCEDURE DrawRectangle(Xpos, Ypos, Width, Height : INTEGER); (* draw a rectangle *) PROCEDURE DrawPoint(Xpos, Ypos : INTEGER); (* draw a single point *) PROCEDURE DrawArc(Xpos,Ypos, Width, Height, StartAngle, EndAngle : INTEGER); (* draw an arc with the given start and end angles *) PROCEDURE DrawEllipse(Xpos, Ypos, Width, Height : INTEGER); (* draw an ellipse *) PROCEDURE DrawCircle(Xpos, Ypos, Radius : INTEGER); (* draw a circle *) (* *********************** *) (* fill functions *) (* *********************** *) PROCEDURE FillRectangle(Xpos, Ypos, Width, Height : INTEGER); (* draw a filled rectangle *) PROCEDURE FillArc(Xpos,Ypos, Width, Height, StartAngle, EndAngle : INTEGER); (* fill an arc with the given start and end angles *) PROCEDURE FillEllipse(Xpos, Ypos, Width, Height : INTEGER); (* fill an ellipse *) PROCEDURE FillCircle(Xpos, Ypos, Radius : INTEGER); (* fill a circle *) (* *********************** *) (* string functions *) (* *********************** *) PROCEDURE DrawString(Xpos, Ypos : INTEGER; Str : ARRAY OF CHAR); (* draw a string at the given position *) PROCEDURE LoadFont(FontName : ARRAY OF CHAR); (* load a font by name *) PROCEDURE StringWidth(Str : ARRAY OF CHAR) : INTEGER; (* the width a string would be in pixels *) PROCEDURE StringHeight(Str : ARRAY OF CHAR) : INTEGER; (* the height a string would be in pixels *) (* *************** *) (* image functions *) (* *************** *) PROCEDURE LoadImage(Str : ARRAY OF CHAR) : INTEGER; (* return a handle for a xpm image from a file *) PROCEDURE ImageWidth(Handle : INTEGER) : INTEGER; (* return width of a image *) PROCEDURE ImageHeight(Handle : INTEGER) : INTEGER; (* return height of a image *) PROCEDURE PlaceImage(Handle, X, Y : INTEGER); (* display a loaded image at the specified location. *) PROCEDURE RestoreImage(Handle : INTEGER); (* restore a displayed image at the last display location. *) PROCEDURE FreeImage(Handle : INTEGER); (* free the allocation for the loaded image *) (* *********************** *) (* miscellaneous functions *) (* *********************** *) PROCEDURE AvailableColors() : INTEGER; (* return the number of colors available *) PROCEDURE FlushGraphics; (* flush all graphics commands *) PROCEDURE MousePosition(VAR Xpos, Ypos : INTEGER); (* return the mouses current position *) PROCEDURE EventPosition(VAR Xpos, Ypos : INTEGER); (* return the position of the last event *) PROCEDURE ScreenWidth() : INTEGER; (* return the width of the whole screen *) PROCEDURE ScreenHeight() : INTEGER; (* return the height of the whole screen *) PROCEDURE WindowWidth() : INTEGER; (* return the width of the drawing window *) PROCEDURE WindowHeight() : INTEGER; (* return the height of the drawing window *) PROCEDURE SetLineStyle(Style : LineStyle); (* set the line style. Could be LineSolid,LineDoubleDash,LineOnOffDash *) PROCEDURE SetLineWidth(Width : INTEGER); (* set the line width *) PROCEDURE AlwaysFlush(Setting : BOOLEAN); (* set whether a implicit graphics flush should be performed after each operation. The default is TRUE *) PROCEDURE SetDrawingFunction(Function : DrawingFunction); (* set the logical operation applied to all drawing operations *) PROCEDURE SaveSettings; (* save the current graphics settings *) PROCEDURE RestoreSettings; (* restore the previously saved graphics settings *) PROCEDURE RandomCard() : INTEGER; (* return a random cardinal - useful for pretty graphics *) PROCEDURE GetColor(ColorName : ARRAY OF CHAR) : INTEGER; (* return a cardinal color value for the given color *) PROCEDURE GetColorRGB(Red, Green, Blue : INTEGER) : INTEGER; (* return a cardinal color value for the given color *) PROCEDURE SetForeground(Color : INTEGER); (* set the foreground color *) PROCEDURE SetBackground(Color : INTEGER); (* set the background color *) PROCEDURE Sleep(Seconds : REAL); (* Sleep for that many seconds *) PROCEDURE Wait(Seconds : REAL); (* Sleep for that many seconds (same as Sleep) *) END Graph.