Drawing Controls


  typedef void (*DrawFunc)(Control *c, Graphics *g);


  void  on_control_redraw(Control *c, DrawFunc redraw);

  void  draw_control(Control *c);
  void  redraw_control(Control *c);
  void  redraw_control_rect(Control *c, Rect r);
  Rect  get_control_area(Control *c);


The on_control_redraw function is used to attach a call-back function to a control which will be called every time that control needs to be redrawn. There is no need for this call-back to clear the control's background since this will done automatically. The call-back function should use drawing operations (see later sections) to draw the entire contents of the control.

Built-in controls such as buttons, scrollbars, etc have their own redrawing functions, so it is unwise to use the functions in this section on anything except custom-defined controls.

The draw_control function calls the control's redraw call-back, as set using on_control_redraw (see above). The redraw call-back, which is supplied by the programmer, is passed two parameters: the control which needs to be redrawn, and a Graphics object which can be used to draw to the control's surface (see later sections).

The redraw_control function behaves in a similar way, except it first clears the control's visible area using the control's background colour, unless that colour is transparent.

The redraw_control_rect function redraws a rectangular portion of the control. The rectangule is specified in control-relative co-ordinates.

The get_control_area function can be used within the drawing call-back, to obtain the rectangle of the control, in its own co-ordinate system. Hence, the top-left point of this rectangle will be (0,0).