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