Drawing State

OBJECTS

  typedef struct drawstruct
  {
    drawing drawing;    /* drawing to draw to */
    rgb     rgb;        /* a RGB colour value to draw with */
    int     mode;       /* drawing mode */
    point   point;      /* location used by lineto, gprintf */
    int     linewidth;  /* width of lines drawn */
    font    font;       /* font to draw with */
    cursor  cursor;     /* mouse cursor shape */
  } *drawstate;

FUNCTIONS

  drawstate copydrawstate(void);
  void  setdrawstate(drawstate d);
  void  restoredrawstate(drawstate d);
  void  resetdrawstate(void);

  void  drawto(drawing d);
  void  setrgb(rgb c);
  void  setdrawmode(int mode);
  void  moveto(point p);
  void  setlinewidth(int width);
  void  setfont(font f);
  void  setcursor(cursor c);

  drawing currentdrawing(void);
  rgb     currentrgb(void);
  int     currentmode(void);
  point   currentpoint(void);
  int     currentlinewidth(void);
  font    currentfont(void);
  cursor  currentcursor(void);

NOTES

The current drawing state is kept in a variable of type drawstate. The entire drawing state can be saved using the copydrawstate function, which returns a copy of the current drawing state, and later restored using restoredrawstate, which also destroys the copy. The setdrawstate function can be used to quickly set the drawing state to some previously saved settings, and the current state can be reset to its initial values using resetdrawstate.

Inside window or control call-backs functions the current drawing state is a local variable, hence changes made to the drawing colour or font whilst inside a call-back do not affect other objects.

The currentdrawing is the bitmap, window or control where drawing will occur. This can be set using the drawto function.

The currentrgb contains the current colour to be used by the library when drawing. Pre-defined colours are available, such as Black, White, Grey, Blue, Red, Green, etc. The setrgb function can be used to set this value.

The currentmode controls the way in which destination and source pixels are combined during drawing. This can be set using the setdrawmode function.

The currentpoint is used by a few functions which need to remember a location between function calls. Some examples are the lineto and gprintf functions. The moveto function changes this value.

The currentlinewidth determine the width of lines drawn using functions such as drawline, drawrect, drawarc etc. The setlinewidth function can change this value from its default value of one pixel.

The currentfont determines which font will be used in subsequent text drawing functions. It can be set using the setfont function.

The currentcursor controls the shape of the mouse cursor on the screen. It is initially set to an arrow shape, but can be changed using the setcursor function.