9.2. Simple Drawing

Up: Contents Next: Line Graphs Previous: Windows as Viewers

One can open a window that is not associated with a viewer directly under the X11 Window System with the command

   ierr = DrawOpenX(MPI_Comm comm,char *display,char *title,int x,int y,int w, 
                    int h,Draw *win); 
All drawing routines are done relative to the windows coordinate system and viewport. By default the drawing coordinates are from (0,0) to (1,1), where (0,0) indicates the lower left corner of the window. The application program can change the window coordinates with the command
   ierr = DrawSetCoordinates(Draw win,double xl,double yl,double xr,double yr); 
By default, graphics will be drawn in the entire window. To restrict the drawing to a portion of the window, one may use the command
   ierr = DrawSetViewPort(Draw win,double xl,double yl,double xr,double yr); 
These arguments, which indicate the fraction of the window in which the drawing should be done, must satisfy and

To draw a line, one uses the command

   ierr = DrawLine(Draw win,double xl,double yl,double xr,double yr,int cl); 
The argument cl indicates the color (which is an integer between 0 and 255) of the line. A list of predefined colors may be found in include/draw.h and includes DRAW_BLACK, DRAW_RED, DRAW_BLUE etc.

To ensure that all graphics actually have been displayed, one should use the command

   ierr = DrawFlush(Draw win); 
When displaying by using double buffering, which is set with the command
   ierr = DrawSetDoubleBuffer(Draw win); 
all processors must call
   ierr = DrawSynchronizedFlush(Draw win); 
in order to swap the buffers. From the options database one may use -draw_pause n, which causes the PETSc application to pause n seconds at each DrawPause(). A time of -1 indicates that the application should pause until receiving mouse input from the user.

Text can be drawn with either of the two commands

   ierr = DrawString(Draw win,double x,double y,int color,char *text); 
   ierr = DrawStringVertical(Draw win,double x,double y,int color,char *text); 
The user can set the text font size or determine it with the commands
   ierr = DrawStringSetSize(Draw win,double width,double height); 
   ierr = DrawStringGetSize(Draw win,double *width,double *height); 


Up: Contents Next: Line Graphs Previous: Windows as Viewers