home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 1 / RISC_DISC_1.iso / pd_share / code / desklib / !DeskLib / h / Sprite < prev    next >
Encoding:
Text File  |  1994-05-29  |  11.6 KB  |  393 lines

  1. /*
  2.     ####             #    #     # #
  3.     #   #            #    #       #          The FreeWare C library for 
  4.     #   #  ##   ###  #  # #     # ###             RISC OS machines
  5.     #   # #  # #     # #  #     # #  #   ___________________________________
  6.     #   # ####  ###  ##   #     # #  #                                      
  7.     #   # #        # # #  #     # #  #    Please refer to the accompanying
  8.     ####   ### ####  #  # ##### # ###    documentation for conditions of use
  9.     ________________________________________________________________________
  10.  
  11.     File:    Sprite.h
  12.     Author:  Copyright © 1992, 1993 John Winters and Jason Williams
  13.     Version: 0.26 (29 Jul 1993)
  14.     Purpose: Sprite-SWI interfaces.
  15.              This version of the Sprite library only includes the most common
  16.              sprite operations, and only on "user" sprite areas, and "named"
  17.              sprites. (i.e. not pointers-to-sprites)
  18.              More Sprite operations may appear as the moderator gets time
  19.              to include them into the library.
  20. */
  21.  
  22.  
  23. #ifndef __dl_sprite_h
  24. #define __dl_sprite_h
  25.  
  26. #ifndef __dl_core_h
  27. #include "Core.h"
  28. #endif
  29.  
  30. #ifndef __dl_wimp_h
  31. #include "Wimp.h"
  32. #endif
  33.  
  34. #ifndef __dl_coord_h
  35. #include "Coord.h"
  36. #endif
  37.  
  38.  
  39. #define sprite_MAXNAME    12
  40.  
  41. #define spritepool_SYSTEM 0
  42. #define spritepool_WIMP   1
  43.  
  44.  
  45. typedef struct {
  46.     unsigned int areasize ;
  47.     unsigned int numsprites ;
  48.     unsigned int firstoffset ;
  49.     unsigned int freeoffset ;
  50. } sprite_areainfo ;
  51.  
  52. typedef sprite_areainfo *sprite_area;
  53.  
  54. typedef struct {
  55.     unsigned int width ;
  56.     unsigned int height ;
  57.     unsigned int maskstatus ;
  58.     unsigned int mode ;
  59. } sprite_info ;
  60.  
  61. typedef sprite_info *sprite;
  62.  
  63.  
  64. typedef struct {
  65.     int          callno ;
  66.     sprite_area  spritearea ;
  67.     sprite       sprite ;
  68.     void         *savearea ;
  69. } sprite_outputstate ;
  70.  
  71.  
  72. typedef struct
  73. {
  74.   int  offset_next;
  75.   char name[sprite_MAXNAME];
  76.   int  width;
  77.   int  height;
  78.   int  leftbit;
  79.   int  rightbit;
  80.   int  imageoffset;
  81.   int  maskoffset;
  82.   int  screenmode;
  83. } sprite_header;
  84.  
  85.  
  86. typedef struct
  87. {
  88.   wimp_point multiply;
  89.   wimp_point divide;
  90. } sprite_scalefactors;
  91.  
  92.  
  93.  /* Save the screen as a sprite file - SpriteOp 2 */
  94. extern os_error *Sprite_ScreenSave(char *filename, BOOL savepalette);
  95.  
  96.  
  97.  /* ScreenLoad a sprite file - SpriteOp 3 */
  98. extern os_error *Sprite_ScreenLoad(char *filename);
  99.  
  100.  /* Initialise a sprite area - SpriteOp 9 */
  101. extern os_error *Sprite_InitArea(sprite_area area);
  102.  
  103.  /* Load a file into a sprite area - SpriteOp 10 */
  104. extern os_error *Sprite_Load(sprite_area area, char *filename) ;
  105.  
  106.  /* Merge a file into a sprite area - SpriteOp 11 */
  107. extern os_error *Sprite_Merge(sprite_area area, char *filename);
  108.  
  109.  /* Save a sprite area into a file - SpriteOp 12 */
  110. extern os_error *Sprite_Save(sprite_area area, char *filename);
  111.  
  112.  
  113. /*
  114.  *  Sprite_Create() - SpriteOp 15
  115.  *    Creates a sprite according to the parameters.
  116.  */
  117. extern os_error *Sprite_Create(sprite_area area, char *name, int haspalette,
  118.                                int width, int height, int screenmode);
  119.  
  120. /*
  121.  *  Sprite_Delete() - SpriteOp 25
  122.  *    Deletes the given sprite
  123.  */
  124. extern os_error *Sprite_Delete(sprite_area area, char *name);
  125.  
  126.  
  127. /*
  128.  *  Sprite_Rename() and Sprite_Copy() - SpriteOps 25, 26
  129.  *    Unsurprisingly, these rename and copy a sprite, respectively.
  130.  */
  131. extern os_error *Sprite_Rename(sprite_area area, char *oldname, char *newname);
  132. extern os_error *Sprite_Copy(sprite_area area, char *oldname, char *newname);
  133.  
  134.  
  135. /*
  136.  *  Sprite_Get() - SpriteOp 16
  137.  *    Gets (creates and copies) a sprite from the given screen rectangle
  138.  */
  139. extern os_error *Sprite_Get(sprite_area area, char *name, int with_palette,
  140.                             int left, int bottom, int right, int top,
  141.                             sprite *sprite_ptr);
  142.  
  143. /*
  144.  *  Sprite_Plot() - SpriteOp 34
  145.  *    Plots a sprite with it's bottom-left corners at the given coordinate,
  146.  *    using the given GCOL plot action (see GFX.h for plot actions)
  147.  */
  148. extern os_error *Sprite_Plot(sprite_area area, char *name,  /* "PutUser" */
  149.                              int x, int y, int plot_action);
  150.  
  151.  
  152.  /* Reads sprite information - SpriteOp 40 */
  153. extern os_error *Sprite_ReadInfo(sprite_area area, char *name,
  154.                                  sprite_info *info);
  155.  
  156.  /* redirects VDU output into the named sprite - SpriteOp 60 */
  157. extern os_error *Sprite_Redirect(sprite_area area, char *name,
  158.                                  void *savearea, sprite_outputstate *oldstate);
  159.  
  160.  /* Un-redirects VDU output back to the saved state - SpriteOp 60 */
  161. extern os_error *Sprite_UnRedirect(sprite_outputstate *oldstate);
  162.  
  163.  
  164.  /*  Sprite_ReadSaveAreaSize
  165.   *  Given a sprite area and a sprite name, returns the save area size needed
  166.   *  for the given sprite. (SpriteOp 62 veneer)
  167.   */
  168. extern os_error *Sprite_ReadSaveAreaSize(sprite_area area, char *name,
  169.                                          int *saveareasize);
  170.  
  171.  
  172. /* Sprite_ReadControl (8)
  173.  * Read information about sprite area
  174.  * Returns number of sprites in area
  175.  * If you aren't interested in any of the returned variables, then put NULL
  176.  * pointers in
  177.  */
  178.  
  179. extern int Sprite_ReadControl(sprite_area area, int *size, sprite *firstsprite,
  180.                               void *firstfree);
  181.  
  182. /* Sprite_GetName (13)
  183.  * Read name of sprite, given number (starts from 1)
  184.  * Buffer passed in 'name' must be at least 13 chars long
  185.  * Returns length of name.
  186.  */
  187.  
  188. extern int Sprite_GetName(sprite_area area, char *name, int spritenumber);
  189.  
  190. /* Sprite_CreateMask (29)
  191.  * Creates a mask for a sprite
  192.  */
  193.  
  194. extern os_error *Sprite_CreateMask(sprite_area area, char *name);
  195.  
  196. /* Sprite_RemoveMask (30)
  197.  * Removes a mask from a sprite
  198.  */
  199.  
  200. extern os_error *Sprite_RemoveMask(sprite_area area, char *name);
  201.  
  202. /* Sprite_InsertRow (31)
  203.  * Inserts a row at the specified row, and shuffles the rest on
  204.  */
  205.  
  206. extern os_error *Sprite_InsertRow(sprite_area area, char *name, int pos);
  207.  
  208. /* Sprite_DeleteRow (32)
  209.  * Deletes a row at the specified row, and shuffles the rest on
  210.  */
  211.  
  212. extern os_error *Sprite_DeleteRow(sprite_area area, char *name, int pos);
  213.  
  214. /* Sprite_FlipX (33)
  215.  * Flips sprite about x axis (top<>bottom)
  216.  */
  217.  
  218. extern os_error *Sprite_FlipX(sprite_area area, char *name);
  219.  
  220. /* Sprite_Append (35)
  221.  * Glues two sprites together
  222.  * Sprite 2 is deleted, and sprite 1 becomes them both added together
  223.  * Sprites must be the same width if appending vertically, or the same height if
  224.  * appending horizontally
  225.  * 'dir' is 0 for horizontal, 1 for vertical
  226.  */
  227.  
  228. extern os_error *Sprite_Append(sprite_area area, char *name1, char *name2,
  229.                                int dir);
  230.  
  231. /* Sprite_CreatePalette (37)
  232.  * Returns size of palette created
  233.  * If 'big' is true, then a 256 entry palette is created (RO3 only)
  234.  */
  235.  
  236. extern int Sprite_CreatePalette(sprite_area area, char *name, BOOL big);
  237.  
  238. /* Sprite_RemovePalette (37)
  239.  */
  240.  
  241. extern os_error *Sprite_RemovePalette(sprite_area area, char *name);
  242.  
  243. /* Sprite_ReadPixel (41)
  244.  * Returns colour
  245.  * Tint is returned, so long as 'tint' isn't NULL (0)
  246.  */
  247.  
  248. extern int Sprite_ReadPixel(sprite_area area, char *name, wimp_point *pos);
  249.  
  250. /* Sprite_WritePixel (42)
  251.  */
  252.  
  253. extern os_error *Sprite_WritePixel(sprite_area area, char *name,
  254.                                    wimp_point *pos, int colour, int tint);
  255.  
  256. /* Sprite_ReadMask (43)
  257.  * Returns TRUE if solid
  258.  */
  259.  
  260. extern BOOL Sprite_ReadMask(sprite_area area, char *name, wimp_point *pos);
  261.  
  262. /* Sprite_WriteMask (43)
  263.  */
  264.  
  265. extern os_error *Sprite_WriteMask(sprite_area area, char *name, wimp_point *pos,
  266.                                   BOOL solid);
  267.  
  268. /* Sprite_InsertColumn (45)
  269.  * Inserts a column at the specified column, and shuffles the rest on
  270.  */
  271.  
  272. extern os_error *Sprite_InsertColumn(sprite_area area, char *name, int pos);
  273.  
  274. /* Sprite_DeleteColumn (46)
  275.  * Deletes a column at the specified column, and shuffles the rest on
  276.  */
  277.  
  278. extern os_error *Sprite_DeleteColumn(sprite_area area, char *name, int pos);
  279.  
  280. /* Sprite_FlipY (47)
  281.  * Flips sprite about y axis (left<>right)
  282.  */
  283.  
  284. extern os_error *Sprite_FlipY(sprite_area area, char *name);
  285.  
  286. /* Sprite_PlotMask (49)
  287.  */
  288.  
  289. extern os_error *Sprite_PlotMask(sprite_area area, char *name, wimp_point *pos);
  290.  
  291. /* Sprite_PlotMaskScaled (50)
  292.  */
  293.  
  294. extern os_error *Sprite_PlotMaskScaled(sprite_area area, char *name,
  295.                                        wimp_point *pos, sprite_scalefactors sc);
  296.  
  297. /* Sprite_PlotScaled (52)
  298.  * pixtrans can be up to 16 bytes long, it's left as a void * so that you can
  299.  * use a char *, or a pixtrans * if one gets defined in the future
  300.  */
  301.  
  302. extern os_error *Sprite_PlotScaled(sprite_area area, char *name,
  303.                                    wimp_point *pos, sprite_scalefactors *scale,
  304.                                    void *pixtrans);
  305.  
  306. /* Sprite_PlotGrey (53)
  307.  * pixtrans should be a greyscale for the antialiasing to work properly
  308.  * (or a blue scale or whatever)
  309.  */
  310.  
  311. extern os_error *Sprite_PlotGrey(sprite_area area, char *name,
  312.                                  wimp_point *pos, sprite_scalefactors scale,
  313.                                  void *pixtrans);
  314.  
  315. /* Sprite_WimpPlot
  316.  * Plots a sprite in a window.
  317.  * 'pos' should be work area coordinates, and convert is the convert block for
  318.  * the window.
  319.  * All relevant scaling/colour translating is taken to plot the sprite at 1:1 in
  320.  * the current mode
  321.  */
  322.  
  323. extern os_error *Sprite_WimpPlot(sprite_area area, char *name, wimp_point *pos,
  324.                                  convert_block *convert, int plot_action);
  325.  
  326.  
  327. /* Sprite manipulation functions ------------------------------------------ */
  328.  
  329. typedef enum
  330. {
  331.   sprite_HASNOMASKPAL = 0x00,             /* Sprite has no mask or palette */
  332.   sprite_HASNOPALMASK = 0x00,
  333.   sprite_HASMASK      = 0x01,             /* Sprite has a mask only        */
  334.   sprite_HASPAL       = 0x02,             /* Sprite has a palette only     */
  335.   sprite_HASMASKPAL   = 0x03,             /* Has both mask and palette     */
  336.   sprite_HASPALMASK   = 0x03
  337. } spritemem_flags;
  338.  
  339.  
  340.  /*  Sprite_MemorySize
  341.   *  Returns the amount of memory to malloc to hold the sprite
  342.   *  defined by the parameters.
  343.   *
  344.   *  -- Example, create sprite area large enough for 3 identical sprites
  345.   *     which are mode 12, 34x17, and have their own palettes.
  346.   *
  347.   *    sprite_areainfo *pUserSprites;
  348.   *
  349.   *    size = 3 * Sprite_MemorySize( 34, 17, 12, sprite_HASPAL );
  350.   *    size += sizeof( sprite_areainfo );
  351.   *    pUserSprites = (sprite_areainfo*) malloc( size );
  352.   */
  353.  
  354. extern int Sprite_MemorySize(int width, int height, int mode,
  355.                              spritemem_flags flags);
  356.  
  357.  
  358.  /*  Sprite_IconMemorySize
  359.   *  This takes the given WIMP icon, and calculates the size of the sprite
  360.   *  needed to exactly fill it, by calling Sprite_MemorySize for you.
  361.   *  If 'dimensions' is not NULL, then it will be filled in with the needed
  362.   *  size (width/height) of the sprite in pixels.
  363.   *
  364.   *  The window is passed in as a window_block so that this can be applied
  365.   *  to templates as well as open windows.
  366.   *
  367.   *  Example:
  368.   *  {
  369.   *    window_info winfo;
  370.   *    int         s;
  371.   *
  372.   *    Window_GetInfo(mainwindow, &winfo);
  373.   *    s = Sprite_IconMemorySize(&winfo.block, 5, |* Get info for icon 5    *|
  374.   *                          screen_mode,         |* in current screen mode *|
  375.   *                          sprite_HASNOMASKPAL, |* with no mask/palette   *|
  376.   *                          NULL);               |* Don't return dimensions*|
  377.   */
  378.  
  379. extern int Sprite_IconMemorySize(window_block *pWinBlock, icon_handle icon,
  380.                                  int mode, spritemem_flags flags,
  381.                                  wimp_point *dimensions);
  382.  
  383.  
  384. /*  Sprite_LoadFile
  385.  *  This loads the given sprite file into a sprite area, & returns a pointer to
  386.  *  it.  The memory is automatically allocated with malloc(), so to free it
  387.  *  later, simply call free() on the returned pointer.
  388.  */
  389. extern sprite_area Sprite_LoadFile(char *filename);
  390.  
  391.  
  392. #endif
  393.