ebmDevMag.com home
ebm Developer's Magazine
links

developer's mag
main page

article
part 1
part 2
part 3
part 4
part 5
part 6
part 7
part 8
part 9


4 - The CWindow Calls

The img_ functions still refer to the display as a whole, meaning that drawing on specific windows can be a problem. Not only is clipping lacking (which would prevent us from writing off the edge of a window), but there is no knowledge of window border sizes, meaning we have to calculate the offset for our calls to account for our window frame.

A much easier solution is in the CWindow class, which wraps the img_ calls and includes additional safety checks:
  • void DrawLine(S16 x1, S16 y1, S16 x2, S16 y2, COLOR color);
  • void DrawRect(S16 x, S16 y, U16 width, U16 height, COLOR color);
  • void DrawRect(const RECT *rect, COLOR color);
  • void DrawRectFilled(S16 x, S16 y, S16 width, S16 height, COLOR color);
  • void DrawRectFilled(const RECT *rect, COLOR color);
  • S16 DrawText(const char *text, S16 x, S16 y, const FONT *font, COLOR foreground, COLOR background, S32 len, ImgCmb mode );
  • void DrawImage(S16 x, S16 y, const IMAGE *image, COLOR foreground, COLOR background, S16 srcx, S16 srcy, U16 srcwidth, U16 srcheight, ImgCmb mode);
  • void DrawTiledImage(S16 x, S16 y, U16 width, U16 height, const IMAGE *image, COLOR foreground, COLOR background, S16 srcx, S16 srcy, U16 srcwidth, U16 srcheight, ImgCmb mode);
  • void Recolor(const RECT *rect, COLOR oldcolor1, COLOR newcolor1, COLOR oldcolor2, COLOR newcolor2);
  • void InvertRect( S16 x, S16 y, U16 width, U16 height );
  • void InvertRect( const RECT *rect );
  • IMAGE *SaveRect(S16 x, S16 y, U16 width, U16 height);
  • IMAGE *SaveRect(const RECT *rect);

The SDK documentation goes into these in some detail, but a few things should be noted. These functions are overloaded in many cases, allowing you to use either a RECT structure or four individual values. As well, they have various default values, making the use of them less complicated than they may first appear.

The RECT structure deserves additional mentioning, since it can lead to some confusion for Windows programmers. In Windows the RECT structure looks like this:
  struct RECT 
  { 
    LONG left; 
    LONG top; 
    LONG right; 
    LONG bottom;
  }; 
The ebm uses a slightly different format and different names to define the structure:
  struct RECT 
  {
    S16 x; 
    S16 y;
    U16 width;
    U16 height;
  };
This is an important distinction for programmers 'crossing over' - other systems may actually outline the rectangle with two points (top/left and bottom/right), while the ebm uses a single point with height and width values. Many problems in moving to ebm graphics coding arise from this assumption; however the problem is often easy to spot since usually only the bottom and right sides are misaligned.

Previous Section
Next Section

Copyright © 2001-2006 ebmDevMag.com - Legal Notice