Introduction !DrWimpC Features DrWimpC library Examples


!Drawing


The !Drawing Example Illustrates ... Source Files and Functions Used

Automatic creation of the bar window. Loading and rendering of sprite and draw files in a window, plotting of text and text using fonts in a window.

!Drawing Overview.

Wimp Lib Actions

  • Redraw

Standard User Files.


.

Overview



!Drawing has a single window that is opened when SELECT is clicked with the mouse pointer over the !Drawing icon on the icon bar. The window is called main and is defined in the Templates file. The main window, info box and a standard bar menu (consisting of the three standard items of Info, Help and Quit) are loaded and created automatically.

The application loads a sprite file and draw file stored in the main application directory, then loads several fonts for text plotting. When the window is opened the sprites and draw file diagram are rendered into the window using functions in the DrWimpC library. Plotting of shapes and text using the loaded fonts in the window is also illustrated.

[Top]

Application Data


Each item is declared outside all functions in the source file so that they can be referenced in the redraw code by declaring them in the drwUredraw file (outside all functions) using the extern stoage qualifier.



drawfile_diagram *drawfile;

Pointer to a drawfile diagram. The drawfile is loaded into memory allocated when the application is started.


osspriteop_area *sprites;

Pointer to a sprite area. The sprite file is loaded into memory allocated when the application is started.


font_f trinity20, trinity20b, trinity30bi, trinity70bi, hom18, hom12;

Font handles for the various fonts loaded when the application is started.

[Back to the Function List]
[Top]


void drw_uw_init(drw_uw_data *uwd)


This function carries out initialisation actions using the DrwimpC C library built in functions to get the size of the sprite and draw files, allocate memory, and load the files into the allocated memory. Next, fonts are loaded of various point sizes - note the sizes are double types. The handle of each successfully loaded font is returned for use in the text plotting fuctions. The fonts are automatically disposed of (lost) at application closedown by the DrWimpC library, your application does need not be concerned with that.

[Back to the Function List]
[Top]


void drw_u_redraw(void drw_u_redraw(wimp_draw *r, int printing, int page))


This function is called when the DrwimpC C library receives a redraw event for a window in your application so that you can draw the contents of the visible part of the window.

The data set up in drw_uw_init is referenced by declaring the names used to hold the loaded sprite and draw files, and loaded fonts, using the extern storage qualifier to indicate that these items are actually declared in another source file.

The wimp_draw structure pointed to by r identifies the window, and rectangle to be redrawn. So you can redraw only those objects that overlap with the rectangle which is usually more efficient than redrawing the entire contents of the window.

The wimp_draw structure has two boxes in it. The first (named box) is the visible area of the window, the second (named clip) is the rectangle in the window that requires redrawing.

Although in this example it looks as if all objects are redrawn for every rectangle, the DrWimpC C library has a function drw_wint_checkbounds() that the text plotting and sprite and draw file rendering functions use to determine if the object they are working on has any part inside the rectangle. If you are redrawing your own objects you can also use drw_wint_checkbounds() to see if an object needs to be redrawn. The prototype for drw_wint_checkbounds() is in header file drwLengths.h.

The text is plotted in two ways, as a plain text string using drw_wimp_deskplotwindowtext(), and in different fonts using drw_wimp_plotwindowtexth(). Notice that for drw_wimp_plotwindowtexth() the text string is built up with the changes of font embedded in the string using drw_wimp_fontchangeh() to set the font and drw_wimp_fontcolour() to set the font colour. The prototype for drw_wimp_deskplotwindowtext() is in header file drwDeskplt.h, and the prototypes for functions that handle text with fonts are in drwWfontfn.h.

The shape plotting routines are also illustrated by plotting a coloured circle, rectangle and line in the window. See drwWplot.h and drwSetCols.h for the function prototypes. These plotiing functions don't use drw_wint_checkbounds().

Finally, the example shows the ease with which sprites can be plotted and draw files rendered in a window b the DrWimpC C library functions drw_wimp_renderwindowsprite(), prototyped in drwSprRend.h and drw_wimp_renderwindow() prototyped in drwRender.h.

[Back to the Function List]
[Top]