home *** CD-ROM | disk | FTP | other *** search
- /*
- #### # # # #
- # # # # # The FreeWare C library for
- # # ## ### # # # # ### RISC OS machines
- # # # # # # # # # # # ___________________________________
- # # #### ### ## # # # #
- # # # # # # # # # # Please refer to the accompanying
- #### ### #### # # ##### # ### documentation for conditions of use
- ________________________________________________________________________
-
- File: Sprite.h
- Author: Copyright © 1992, 1993 John Winters and Jason Williams
- Version: 0.26 (29 Jul 1993)
- Purpose: Sprite-SWI interfaces.
- This version of the Sprite library only includes the most common
- sprite operations, and only on "user" sprite areas, and "named"
- sprites. (i.e. not pointers-to-sprites)
- More Sprite operations may appear as the moderator gets time
- to include them into the library.
- */
-
-
- #ifndef __dl_sprite_h
- #define __dl_sprite_h
-
- #ifndef __dl_core_h
- #include "Core.h"
- #endif
-
- #ifndef __dl_wimp_h
- #include "Wimp.h"
- #endif
-
- #ifndef __dl_coord_h
- #include "Coord.h"
- #endif
-
- #ifdef __cplusplus
- extern "C" {
- #endif
-
- #define sprite_MAXNAME 12
-
- #define spritepool_SYSTEM 0
- #define spritepool_WIMP 1
-
-
- typedef struct {
- unsigned int areasize ;
- unsigned int numsprites ;
- unsigned int firstoffset ;
- unsigned int freeoffset ;
- } sprite_areainfo ;
-
- typedef sprite_areainfo *sprite_area;
-
- typedef struct {
- unsigned int width ;
- unsigned int height ;
- unsigned int maskstatus ;
- unsigned int mode ;
- } sprite_info ;
-
- typedef sprite_info *sprite;
-
-
- typedef struct {
- int callno ;
- sprite_area spritearea ;
- sprite sprite ;
- void *savearea ;
- } sprite_outputstate ;
-
-
- typedef struct
- {
- int offset_next;
- char name[sprite_MAXNAME];
- int width;
- int height;
- int leftbit;
- int rightbit;
- int imageoffset;
- int maskoffset;
- int screenmode;
- } sprite_header;
-
-
- typedef struct
- {
- wimp_point multiply;
- wimp_point divide;
- } sprite_scalefactors;
-
-
- /* Save the screen as a sprite file - SpriteOp 2 */
- extern os_error *Sprite_ScreenSave(char *filename, BOOL savepalette);
-
-
- /* ScreenLoad a sprite file - SpriteOp 3 */
- extern os_error *Sprite_ScreenLoad(char *filename);
-
- /* Initialise a sprite area - SpriteOp 9 */
- extern os_error *Sprite_InitArea(sprite_area area);
-
- /* Load a file into a sprite area - SpriteOp 10 */
- extern os_error *Sprite_Load(sprite_area area, char *filename) ;
-
- /* Merge a file into a sprite area - SpriteOp 11 */
- extern os_error *Sprite_Merge(sprite_area area, char *filename);
-
- /* Save a sprite area into a file - SpriteOp 12 */
- extern os_error *Sprite_Save(sprite_area area, char *filename);
-
-
- /*
- * Sprite_Create() - SpriteOp 15
- * Creates a sprite according to the parameters.
- */
- extern os_error *Sprite_Create(sprite_area area, char *name, int haspalette,
- int width, int height, int screenmode);
-
- /*
- * Sprite_Delete() - SpriteOp 25
- * Deletes the given sprite
- */
- extern os_error *Sprite_Delete(sprite_area area, char *name);
-
-
- /*
- * Sprite_Rename() and Sprite_Copy() - SpriteOps 25, 26
- * Unsurprisingly, these rename and copy a sprite, respectively.
- */
- extern os_error *Sprite_Rename(sprite_area area, char *oldname, char *newname);
- extern os_error *Sprite_Copy(sprite_area area, char *oldname, char *newname);
-
-
- /*
- * Sprite_Get() - SpriteOp 16
- * Gets (creates and copies) a sprite from the given screen rectangle
- */
- extern os_error *Sprite_Get(sprite_area area, char *name, int with_palette,
- int left, int bottom, int right, int top,
- sprite *sprite_ptr);
-
- /*
- * Sprite_Plot() - SpriteOp 34
- * Plots a sprite with it's bottom-left corners at the given coordinate,
- * using the given GCOL plot action (see GFX.h for plot actions)
- */
- extern os_error *Sprite_Plot(sprite_area area, char *name, /* "PutUser" */
- int x, int y, int plot_action);
-
-
- /* Reads sprite information - SpriteOp 40 */
- extern os_error *Sprite_ReadInfo(sprite_area area, char *name,
- sprite_info *info);
-
- /* redirects VDU output into the named sprite - SpriteOp 60 */
- extern os_error *Sprite_Redirect(sprite_area area, char *name,
- void *savearea, sprite_outputstate *oldstate);
-
- /* Un-redirects VDU output back to the saved state - SpriteOp 60 */
- extern os_error *Sprite_UnRedirect(sprite_outputstate *oldstate);
-
-
- /* Sprite_ReadSaveAreaSize
- * Given a sprite area and a sprite name, returns the save area size needed
- * for the given sprite. (SpriteOp 62 veneer)
- */
- extern os_error *Sprite_ReadSaveAreaSize(sprite_area area, char *name,
- int *saveareasize);
-
-
- /* Sprite_ReadControl (8)
- * Read information about sprite area
- * Returns number of sprites in area
- * If you aren't interested in any of the returned variables, then put NULL
- * pointers in
- */
-
- extern int Sprite_ReadControl(sprite_area area, int *size, sprite *firstsprite,
- void *firstfree);
-
- /* Sprite_GetName (13)
- * Read name of sprite, given number (starts from 1)
- * Buffer passed in 'name' must be at least 13 chars long
- * Returns length of name.
- */
-
- extern int Sprite_GetName(sprite_area area, char *name, int spritenumber);
-
- /* Sprite_CreateMask (29)
- * Creates a mask for a sprite
- */
-
- extern os_error *Sprite_CreateMask(sprite_area area, char *name);
-
- /* Sprite_RemoveMask (30)
- * Removes a mask from a sprite
- */
-
- extern os_error *Sprite_RemoveMask(sprite_area area, char *name);
-
- /* Sprite_InsertRow (31)
- * Inserts a row at the specified row, and shuffles the rest on
- */
-
- extern os_error *Sprite_InsertRow(sprite_area area, char *name, int pos);
-
- /* Sprite_DeleteRow (32)
- * Deletes a row at the specified row, and shuffles the rest on
- */
-
- extern os_error *Sprite_DeleteRow(sprite_area area, char *name, int pos);
-
- /* Sprite_FlipX (33)
- * Flips sprite about x axis (top<>bottom)
- */
-
- extern os_error *Sprite_FlipX(sprite_area area, char *name);
-
- /* Sprite_Append (35)
- * Glues two sprites together
- * Sprite 2 is deleted, and sprite 1 becomes them both added together
- * Sprites must be the same width if appending vertically, or the same height if
- * appending horizontally
- * 'dir' is 0 for horizontal, 1 for vertical
- */
-
- extern os_error *Sprite_Append(sprite_area area, char *name1, char *name2,
- int dir);
-
- /* Sprite_CreatePalette (37)
- * Returns size of palette created
- * If 'big' is true, then a 256 entry palette is created (RO3 only)
- */
-
- extern int Sprite_CreatePalette(sprite_area area, char *name, BOOL big);
-
- /* Sprite_RemovePalette (37)
- */
-
- extern os_error *Sprite_RemovePalette(sprite_area area, char *name);
-
- /* Sprite_ReadPixel (41)
- * Returns colour
- * Tint is returned, so long as 'tint' isn't NULL (0)
- */
-
- extern int Sprite_ReadPixel(sprite_area area, char *name, wimp_point *pos);
-
- /* Sprite_WritePixel (42)
- */
-
- extern os_error *Sprite_WritePixel(sprite_area area, char *name,
- wimp_point *pos, int colour, int tint);
-
- /* Sprite_ReadMask (43)
- * Returns TRUE if solid
- */
-
- extern BOOL Sprite_ReadMask(sprite_area area, char *name, wimp_point *pos);
-
- /* Sprite_WriteMask (43)
- */
-
- extern os_error *Sprite_WriteMask(sprite_area area, char *name, wimp_point *pos,
- BOOL solid);
-
- /* Sprite_InsertColumn (45)
- * Inserts a column at the specified column, and shuffles the rest on
- */
-
- extern os_error *Sprite_InsertColumn(sprite_area area, char *name, int pos);
-
- /* Sprite_DeleteColumn (46)
- * Deletes a column at the specified column, and shuffles the rest on
- */
-
- extern os_error *Sprite_DeleteColumn(sprite_area area, char *name, int pos);
-
- /* Sprite_FlipY (47)
- * Flips sprite about y axis (left<>right)
- */
-
- extern os_error *Sprite_FlipY(sprite_area area, char *name);
-
- /* Sprite_PlotMask (49)
- */
-
- extern os_error *Sprite_PlotMask(sprite_area area, char *name, wimp_point *pos);
-
- /* Sprite_PlotMaskScaled (50)
- */
-
- extern os_error *Sprite_PlotMaskScaled(sprite_area area, char *name,
- wimp_point *pos, sprite_scalefactors sc);
-
- /* Sprite_PlotScaled (52)
- * pixtrans can be up to 16 bytes long, it's left as a void * so that you can
- * use a char *, or a pixtrans * if one gets defined in the future
- */
-
- extern os_error *Sprite_PlotScaled(sprite_area area, char *name,
- wimp_point *pos, sprite_scalefactors *scale,
- void *pixtrans);
-
- /* Sprite_PlotGrey (53)
- * pixtrans should be a greyscale for the antialiasing to work properly
- * (or a blue scale or whatever)
- */
-
- extern os_error *Sprite_PlotGrey(sprite_area area, char *name,
- wimp_point *pos, sprite_scalefactors scale,
- void *pixtrans);
-
- /* Sprite_WimpPlot
- * Plots a sprite in a window.
- * 'pos' should be work area coordinates, and convert is the convert block for
- * the window.
- * All relevant scaling/colour translating is taken to plot the sprite at 1:1 in
- * the current mode
- */
-
- extern os_error *Sprite_WimpPlot(sprite_area area, char *name, wimp_point *pos,
- convert_block *convert, int plot_action);
-
-
- /* Sprite manipulation functions ------------------------------------------ */
-
- typedef enum
- {
- sprite_HASNOMASKPAL = 0x00, /* Sprite has no mask or palette */
- sprite_HASNOPALMASK = 0x00,
- sprite_HASMASK = 0x01, /* Sprite has a mask only */
- sprite_HASPAL = 0x02, /* Sprite has a palette only */
- sprite_HASMASKPAL = 0x03, /* Has both mask and palette */
- sprite_HASPALMASK = 0x03
- } spritemem_flags;
-
-
- /* Sprite_MemorySize
- * Returns the amount of memory to malloc to hold the sprite
- * defined by the parameters.
- *
- * -- Example, create sprite area large enough for 3 identical sprites
- * which are mode 12, 34x17, and have their own palettes.
- *
- * sprite_areainfo *pUserSprites;
- *
- * size = 3 * Sprite_MemorySize( 34, 17, 12, sprite_HASPAL );
- * size += sizeof( sprite_areainfo );
- * pUserSprites = (sprite_areainfo*) malloc( size );
- */
-
- extern int Sprite_MemorySize(int width, int height, int mode,
- spritemem_flags flags);
-
-
- /* Sprite_IconMemorySize
- * This takes the given WIMP icon, and calculates the size of the sprite
- * needed to exactly fill it, by calling Sprite_MemorySize for you.
- * If 'dimensions' is not NULL, then it will be filled in with the needed
- * size (width/height) of the sprite in pixels.
- *
- * The window is passed in as a window_block so that this can be applied
- * to templates as well as open windows.
- *
- * Example:
- * {
- * window_info winfo;
- * int s;
- *
- * Window_GetInfo(mainwindow, &winfo);
- * s = Sprite_IconMemorySize(&winfo.block, 5, |* Get info for icon 5 *|
- * screen_mode, |* in current screen mode *|
- * sprite_HASNOMASKPAL, |* with no mask/palette *|
- * NULL); |* Don't return dimensions*|
- */
-
- extern int Sprite_IconMemorySize(window_block *pWinBlock, icon_handle icon,
- int mode, spritemem_flags flags,
- wimp_point *dimensions);
-
-
- /* Sprite_LoadFile
- * This loads the given sprite file into a sprite area, & returns a pointer to
- * it. The memory is automatically allocated with malloc(), so to free it
- * later, simply call free() on the returned pointer.
- */
- extern sprite_area Sprite_LoadFile(char *filename);
-
-
- #ifdef __cplusplus
- }
- #endif
-
- #endif
-