Drawing Functions


  int  draw_point(Graphics *g, Point p);
  int  draw_rect(Graphics *g, Rect r);
  int  fill_rect(Graphics *g, Rect r);
  int  draw_shadow_rect(Graphics *g, Rect r,
                            Colour c1, Colour c2);
  int  draw_line(Graphics *g, Point p1, Point p2);
  int  draw_round_rect(Graphics *g, Rect r);
  int  fill_round_rect(Graphics *g, Rect r);
  int  draw_ellipse(Graphics *g, Rect r);
  int  fill_ellipse(Graphics *g, Rect r);
  int  draw_arc(Graphics *g, Rect r,
                    int start_angle, int end_angle);
  int  fill_arc(Graphics *g, Rect r,
                    int start_angle, int end_angle);
  int  draw_polyline(Graphics *g, Point *p, int n);
  int  draw_polygon(Graphics *g, Point *p, int n);
  int  fill_polygon(Graphics *g, Point *p, int n);
  void draw_all(App *app);


All drawing operations require a valid Graphics object to allow drawing. This graphics object is used to determine where and how pixels will be drawn. See the section on graphics object for details on how to obtain a graphics object to draw to a window, control, bitmap or image.

All of the drawing operations described here return 1 on success, or 0 if a memory error prevents successful completion.

The draw_point function sets the colour of the given point to be the current drawing colour. It will change only one pixel, regardless of the current line width.

The draw_rect function draws a rectangle within the given rectangle. The lines will have a thickness defined by the current line width and will be wholly within the rectangle.

The draw_shadow_rect function is similar, but draws the box in two colours. The first colour c1 is used to draw the top and left portions of the box, and the second colour c2 is used to draw the bottom and right portions. This creates a raised border effect, as used by push-buttons and some other controls.

The fill_rect function fills the specified rectangle with the current colour.

The draw_line function draws a line starting at point p1 and extending up to but not including point p2. The line will have a width equal to the current line width.

The draw_round_rect function draws a box with rounded edges. The fill_round_rect function fills the rounded box with the current colour.

The draw_ellipse function draws a complete ellipse within the supplied rectangle. Remember that the right and bottom edges of a rectangle are not included within the rectangle. To draw a circle, make the rectangle a square. The fill_ellipse function fills the corresponding ellipse with the current colour.

The draw_arc function draws an ellipsoid arc centred in the middle of the rectangle r, extending anti-clockwise from the start_angle to the end_angle. Angles are measured in degrees, with 0 degrees being in the 3 o'clock position on the arc. The arc will fit within the rectangle. The fill_arc function creates a pie-shape with the end-points of the arc joined to the centre point.

To draw many lines at once, the draw_polyline function is used. It is passed an array of n points, and connects each point to the next in the array using draw_line.

The draw_polygon function is given an array of n points. It will draw lines from the first point in the array to the next, and so on until it joins the last point back to the first. The fill_polygon function will create a polygon filled with the current colour.

Graphics operations on some platforms (such as X-Windows) may be buffered, and for those platforms calling draw_all ensures all pending graphics requests are processed immediately. On other platforms the function exists and does nothing. This function is called during event handling anyway, and so is not generally called explicitly.