home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / pc / progrmng / stk110.lzh / STKSRC.COM / SPR.H < prev    next >
Encoding:
C/C++ Source or Header  |  1991-02-25  |  7.9 KB  |  192 lines

  1. /**********************************************************************
  2. * spr.h
  3. *
  4. * The basic sprite support system prototypes and structures.
  5. **********************************************************************
  6.                     This file is part of
  7.  
  8.           STK -- The sprite toolkit -- version 1.1
  9.  
  10.               Copyright (C) Jari Karjala 1991
  11.  
  12. The sprite toolkit (STK) is a FreeWare toolkit for creating high
  13. resolution sprite graphics with PCompatible hardware. This toolkit 
  14. is provided as is without any warranty or such thing. See the file
  15. COPYING for further information.
  16.  
  17. **********************************************************************
  18. **********************************************************************/
  19.  
  20. #ifndef __SPR_H_
  21. #define __SPR_H_
  22.  
  23. #include "grtypes.h"
  24.  
  25. extern int spr_pass_delay;
  26. /**********************************************************************
  27. * The delay after setvisualpage() before removing old objects in
  28. * the funtion spr_next_pass(). 
  29. * Many EGA/VGA cards need some milliseconds to switch pages, 
  30. * the sprites flicker if this delay is too short.
  31. *
  32. * If someone has better solutions in dealing with this problem,
  33. * I sure would like to know about them.
  34. *
  35. * Time is given in milliseconds and the default is 10 ms for EGA
  36. * and 0 ms for Hercules (use spr_regulate_speed to balance the frame
  37. * rate with different display adapters).
  38. **********************************************************************/
  39.  
  40. #define spr_max_x gr_max_x
  41. #define spr_max_y gr_max_y
  42. /**********************************************************************
  43. * The maximum coordinate values for current graphics adapter.
  44. * Variables defined in module gr.c, and initialized in gr_start.
  45. * (It is faster to use variables instead of getmaxx() and getmaxy());
  46. **********************************************************************/
  47.  
  48. #ifndef __SPRITE_
  49. typedef void *SPRITE;
  50. #endif
  51. /**********************************************************************
  52. * The sprite type is private. The handle must be void pointer due
  53. * to the Turbo C which does not allow "struct _sprite *SPRITE" without
  54. * struct _sprite definition in the same file.
  55. **********************************************************************/
  56.  
  57. void spr_initialize(int graphicsdriver);
  58. /**********************************************************************
  59. * Initialize the sprite system to the given display hardware.
  60. * Supported graphicsdrivers: EGA (only two colors), EGAMONO and HERCMONO.
  61. * The visual page is set to 0.
  62. *
  63. * NOTE: This function must be called before any other sprite funtions
  64. *       and the graphics mode must have been set before this call.
  65. * graphicsdriver  The BGI identifier for the graphics driver used.
  66. **********************************************************************/
  67.  
  68. SPRITE spr_create(WORD w, WORD h, 
  69.                   BITMAP pic, BITMAP mask, 
  70.                   BYTE res, WORD ID);
  71. /**********************************************************************
  72. * Create a sprite from the given bitmaps.
  73. *
  74. * w,h   Width (must be < 512) and height (<256) of sprite in pixels
  75. * pic   The picture bitmap for the sprite
  76. * mask  The mask bitmap for the sprite
  77. * res   The number of steps wanted per 8 bit interval in horizontal
  78. *       direction (1,2,4,8). For example, the value 8 gives one
  79. *       pixel resolution in X-direction.
  80. * ID    The user supplied ID for the sprite (usually index into an 
  81. *       array and/or sprite type identifier).
  82. *
  83. * Return: the newly created sprite or NULL if parameter error,
  84. *           sprite too big or out-of-memory
  85. **********************************************************************/
  86.  
  87. SPRITE spr_share(SPRITE spr, BYTE n);
  88. /**********************************************************************
  89. * Create a shared version of the given sprite. This allows at
  90. * most n spr_copies which all share the shape data thus saving
  91. * quite much memory.
  92. *
  93. * spr   The sprite to share
  94. * n     The maximum number of shared copies
  95. *
  96. * Return: New SPRITE or NULL if error (out of memory, spr==NULL)
  97. **********************************************************************/
  98.  
  99. SPRITE spr_copy(SPRITE spr, WORD id);
  100. /**********************************************************************
  101. * Create a copy of the given sprite. If the sprite was shared
  102. * with spr_share then a shared copy is created. 
  103. *
  104. * spr   The sprite to share
  105. * id    The ID for the new sprite
  106. *
  107. * Return: New SPRITE or NULL if error (out of memory, spr was NULL, 
  108. *           no more shared copies)
  109. **********************************************************************/
  110.  
  111. void spr_put(SPRITE spr, WORD x, WORD y);
  112. /**********************************************************************
  113. * Put the sprite into the given position in the display. 
  114. * Actually the call has no effect on screen until spr_next_pass() is
  115. * called next time and the sprite will disappear after the next
  116. * spr_next_pass() call after that.
  117. *
  118. * NOTE: Cannot be called twice for the same sprite before spr_hide() or
  119. *       spr_next_pass().
  120. *
  121. * spr   The sprite to put
  122. * x     The X coordinate
  123. * y     The Y coordinate
  124. **********************************************************************/
  125.  
  126. void spr_hide(SPRITE spr);
  127. /**********************************************************************
  128. * Undo a spr_put for the sprite. This function only removes the sprite
  129. * from internal display list since the spr_put did not actually put the 
  130. * sprite into the screen.
  131. *
  132. * spr   The sprite to hide
  133. **********************************************************************/
  134.  
  135. void spr_delete(SPRITE spr);
  136. /**********************************************************************
  137. * Delete the given sprite and release associated memory buffers.
  138. * Also spr_hides the sprite.
  139. *
  140. * spr   The sprite to delete
  141. **********************************************************************/
  142.  
  143. WORD spr_next_pass(void);
  144. /**********************************************************************
  145. * 1. Draw all sprites into the hidden screen page.
  146. * 2. Make the hidden screen page visible.
  147. * 3. Delete old sprites from the new hidden page.
  148. *
  149. * Return: The current visual page number
  150. **********************************************************************/
  151.  
  152. void spr_regulate_speed(void);
  153. /**********************************************************************
  154. * This function tries to regulate the frame speed by delaying if
  155. * we are doing more frames per second than we should. The target 
  156. * speed is 1 frame per one clock tick (about 18 frames per second).
  157. * This is a reasonable target speed for 286 machines.
  158. * This function should be called after each spr_next_pass() call.
  159. **********************************************************************/
  160.  
  161.  
  162. /***** Information retrieving functions *****/
  163.  
  164. WORD spr_get_id(SPRITE spr);
  165. /**********************************************************************
  166. * Return the user supplied identifier of the sprite
  167. **********************************************************************/
  168.  
  169. WORD spr_get_x(SPRITE spr);
  170. /**********************************************************************
  171. * Return the X coordinate of the sprite in pixels from top-left
  172. **********************************************************************/
  173.  
  174. WORD spr_get_y(SPRITE spr);
  175. /**********************************************************************
  176. * Return the Y coordinate of the sprite in pixels from top-left
  177. **********************************************************************/
  178.  
  179. WORD spr_get_width(SPRITE spr);
  180. /**********************************************************************
  181. * Return the width of the sprite in pixels
  182. **********************************************************************/
  183.  
  184. WORD spr_get_height(SPRITE spr);
  185. /**********************************************************************
  186. * Return the height of the sprite in pixels
  187. **********************************************************************/
  188.  
  189. #endif
  190.