Sprite Displayer

by David Spencer


This is the example program from the Desktop C article in this issue of RISC User. It displays the sprite contained in a file called Picture in a window on the Desktop. To display a different sprite in this window, change the sprite file's name to Picture and copy it into the !Display directory. This application requires the ColourTrans module, supplied in ROM with RISC OS 3, but as an extension module for RISC OS 2. Because of lack of space on this disc, we have been unable to include a copy of the module for RISC OS 2 users, so if you still use RISC OS 2, you will need to load the module from your own !System directory before using the application.

IN USE
Running the application installs its icon on the icon bar, and clicking on this icon opens a window containing the sprite. Clicking Menu over this window opens a menu containing a Zoom option, which allows you to increase or decrease the magnification of the sprite.

ABOUT THE SOURCE CODE
The source code is contained within the file 'main' in the 'c' subdirectory.

The code includes the following functions:

translate_sprite_colours
Function from the article. Note that a simplified version is also included to use the new features of RISC OS 3. To use this, comment out the RISC OS 2 version and uncomment the RISC OS 3 version. Then recompile the source.

redraw_sprite
The main redraw function from the article.

sprite_size
Returns the size of the sprite area needed to load the sprite.

close_window
Close display window and release memory used to hold sprite.

find_sprite_size
Find dimensions of sprite in order to create window of correct size.

make_sprite_area
Claim memory using flex and initialise as a sprite area.

load_sprite
Load sprite file into sprite area.

set_viewer_size
Set extent of window to match size of sprite, allowing for scaling.

display_sprite
Load sprite into new sprite area, set window extent and open window.

zoom_changed
Called by magnify code when zoom changes. Resizes the window so as to keep the same area visible.

create_window
Create a window from a named template.

create_menus
Create the menu structures needed for the program.

icon_click
Handle clicks on the icon-bar icon (excluding menu presses).

info_about_program
Display info box.

viewer_zoom
Open and handle magnifier box.

iconbar_menuproc
Deal with clicks on the icon-bar menu.

viewer_menuproc
Deal with clicks on the main menu.

redraw_request_viewer
Handle redraw requests for the main window.

viewer_window_handler
Process events for the main window.

initialise
Various steps to set up the program.

main
The main program loop.


 Copyright RISC User 1993
