| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
4.1 mglGraphAB class
#cindex mglDraw
Generally this class is a bit less abstract class than mglGraph class (see section MathGL core). It provide many protected methods for handling intermediate data from mglGraph methods and require a few methods to be defined by derived class. The developers of derived classes should look on file ‘mgl_ab.h’ and comments inside it or contact me.
Here I just show new public methods for class mglGraphAB. There are functions returning the created picture (bitmap), its width and height. You may display it by yourself in any graphical library (see also, Widget classes) or save in file (see also, Export to file).
- Method on mglGraphAB:
const unsigned char *GetBits () Gets RGB bitmap of the current state of the image. Format of each element of bits is: {red, green, blue}. Number of elements is Width*Height. Position of element {i,j} is [3*i + 3*Width*j].
- Method on mglGraphAB:
const unsigned char *GetRGBA () Gets RGBA bitmap of the current state of the image. Format of each element of bits is: {red, green, blue, alpha}. Number of elements is Width*Height. Position of element {i,j} is [4*i + 4*Width*j].
Class mglGraphAB is the base class for “widget classes”. So there are set of functions for handling window behavior. Most of them are applicable only for “window” classes (like mglGraphFLTK and so on, see section Widget classes). In all other classes these functions just do nothing. You should provide the corresponding interface in derived “widget” classes for user convenience.
- Method on mglGraphAB:
voidWindow (intargc,char **argv,int (*draw)(mglGraph *gr,void *p),const char *title,void *par=NULL,void (*reload)(intnext,void *p)=NULL) This function creates a window for plotting. Parameters argc, argv contain OS specific information and should be the same as in function
main(int argc,char **argv). Parameter draw sets a pointer (this is the name of function) to drawing function. There is support of a list of plots (frames). So as one can prepare a set of frames at first and redraw it fast later (but it requires more memory). Function should return positive number of frames for the list or zero if it will plot directly. Parameter title sets the title of the window. Parameter par contains pointer to data for the plotting function draw.There are some keys handles for manipulating by the plot: 'a', 'd', 'w', 's' for the rotating; ',', '.' for viewing of the previous or next frames in the list; 'r' for the switching of transparency; 'f' for the switching of lightning; 'x' for hiding (closing) the window.
IMPORTANT!!! You need to add a call of Rotate() (see section Transformation matrix) function for having possibility of plot rotation. If plot should be unrotated by default just add
Rotate(0,0)in drawing function.
- Method on mglGraphAB:
voidWindow (intargc,char **argv,mglDraw *draw,const char *title) This function is mostly the same as previous one. The only difference is that the drawing function and function for data reloading are specified as methods on a class inherited from class
mglDraw. This class is defined in#include <mgl/mgl_data.h>and have only 2 methods:class mglDraw { public: virtual int Draw(mglGraph *) { return 0; }; virtual void Reload(int) {}; };You should inherit yours class from
mglDrawand reimplement one or both functions for using this function.
- Method on mglGraphAB:
voidToggleAlpha () Switch on/off transparency but do not overwrite switches in user drawing function.
- Method on mglGraphAB:
voidToggleLight () Switch on/off lighting but do not overwrite switches in user drawing function.
- Method on mglGraphAB:
voidToggleRotate () Switch on/off rotation by mouse. Usually, left button is used for rotation, middle button for shift, right button for zoom/perspective.
- Method on mglGraphAB:
voidToggleNo () Switch off all zooming and rotation and restore initial state.
- Widget option of mglGraphAB:
boolAutoClf Clear canvas between drawing. You may switch it off for accumulate previous drawing (for example some points or parts of a picture).
- Method on mglGraphAB:
mglPointCalcXYZ (intxs,intys) Calculate 3D coordinate {x,y,z} for screen point {xs,ys}. At this moment it ignore perspective and transformation formulas (curvilinear coordinates). The calculation are done for the last used InPlot (see section Transformation matrix).
- Widget option of mglGraphAB:
floatShowMousePos Switch to show or not in the widget the last mouse click position.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
