I designed the graph class to be reasonably simple to use so I could remember what everything meant. I also wanted something that would get a reasonably good looking graph on the screen with about 5 minutes of typing. The class definition is given by
class GMatrix { private: // Borland graphics information. bgi files must be available int GraphDriver; int GraphMode; int MaxX, MaxY; int MaxColors; int ErrorCode; struct linesettingstype lineinfo; struct viewporttype viewinfo; // reference lines. can have at most 20 reference lines double *hrefs; double *vrefs; int nvrefs, nhrefs; // output a line, and pause function ESC stops program int gprintf(int *xloc, int *yloc, char *fmt, ... ); void Pause(); // graph is stored in a VMatrix: [graphid, symbol, x, y] 4 cols int graphnum; // number of graphs in grf; VMatrix *grf; // plot a point on the screen void plotpoint( int ix, int iy, int symbol); public: // constructors and destructors GMatrix( void ); GMatrix( VMatrix &ROp, int symbol= -' '); // ROp should be rx2 matrix // column 1 is x, col 2 is y ~GMatrix( void ); // display a graph void Show( void ); // add a new vector to plot void AddVec( VMatrix &ROp, int symbol = -' '); // annotation options strtype *title, *title2, *xname, *yname, *PathToDriver; boolean RectangleOn, YGridOn, XGridOn; void Href( double href ); void Vref( double vref ); int ClearHref( void ){ int t=nhrefs; nhrefs = -1; return t;} int ClearVref( void ){ int t=nvrefs; nvrefs = -1; return t;} // save the grf matrix void SaveGraph( char *fid ) { Writea( fid, *grf ); } };
The graphics class is not automatically included in your project
since it is machine-compiler specific. To gain access to the
class you must define the global symbol VIRTGRAF
. This
can be done in the compiler options of the IDE, or with a
-DVIRTGRAF
in the command line
compiler. This sets a switch in VIRT.H
to include the
GMatrix class definition. You must also make VIRTGRAF.CPP part
of your project.
The strtype pointer PathToDriver
contains the path to the
BGI drivers. You tell your program where the BGI files are by a
command such as *PathToDriver = "c:\\tc\\bgi"
. There are
two things to note here. First, PathToDriver is a pointer, so
you must use a '*' in front of it to store a value in it.
Secondly, note the double slashes are required for the BGI
autodetection function.