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

  1. /**********************************************************************
  2. * gr.h
  3. *
  4. * Support routines for graphics mode.
  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. #if     !defined(__GR_H_)
  21. #define __GR_H_
  22.  
  23.  
  24. /***** Variables *****/
  25.  
  26. extern int gr_max_x;
  27. extern int gr_max_y;
  28. /**********************************************************************
  29. * The maximum coordinate values for current graphics adapter.
  30. * (It is faster to use variables instead of getmaxx() and getmaxy());
  31. **********************************************************************/
  32.  
  33. extern int gr_text_mode;
  34. #define GR_MODE_OR      (1<<0)      /* OR the text over previous graphics */
  35. #define GR_MODE_CLEAR   (1<<1)      /* Clear the backgroud before print  */
  36. #define GR_MODE_CLEAR_FAST   (1<<2) /* Clear the bg before print FAST  */
  37. /**********************************************************************
  38. * This variable defines the text writing mode when using gr_* functions
  39. * (default GR_MODE_CLEAR)
  40. *
  41. * The GR_MODE_CLEAR_FAST is limited to 8 pixel horizontal resolution,
  42. * i.e. coordinate positions (1,0) and (5,0) are considered to be same.
  43. **********************************************************************/
  44.  
  45. extern unsigned char far *gr_font_addr;
  46. /*********************************************************************
  47. * Pointer into an byte array containing the character font for 
  48. * 8x8 pixel fixed point font. Initialized to ROM font (FFA6:000E).
  49. * Used only with GR_MODE_CLEAR_FAST in those graphics modes which
  50. * are supported by the sprite functions.
  51. ********************************************************************/
  52.  
  53. extern int gr_visualpage;
  54. extern int gr_activepage;
  55. /*********************************************************************
  56. * The current visual page and active drawing page, provided that
  57. * they have been changed only with gr_*page functions.
  58. ********************************************************************/
  59.  
  60. extern char gr_keys[128];
  61. /**********************************************************************
  62. * Array of booleans for each key of the keyboard (indexed by the scan
  63. * code value). Non-zero if key is depressed, zero otherwise.
  64. * The array is updated during the kbd_grab, see the function 
  65. * gr_start_kbd_grab below. For example gr_keys[GR_KEY_ESC] is 1
  66. * if Esc is currently depressed and 0 if not. Multiple simultaneous 
  67. * keyspresses are detected correctly.
  68. **********************************************************************/
  69.  
  70. /***** Function prototypes *****/
  71.  
  72. void gr_detect(int type, int *graphdriver, int *graphmode);
  73. #define GR_TYPE_ANY 0   /* Any mode will do */
  74. #define GR_TYPE_SPR 1   /* The best possible mode for the sprite toolkit */
  75. /**********************************************************************
  76. * Detect the graphics card and mode of the system.
  77. * The type parameter can be used to specify special requests.
  78. *
  79. * graphdriver and graphmode parameters are returned. These values can 
  80. * be used with the gr_start function. They contain the value -1
  81. * if some error occured (cannot find requested mode, etc)
  82. **********************************************************************/
  83.  
  84. void gr_start(int *graphdriver, int *graphmode);
  85. /***************************************************************************
  86. * Initializes the graphics system. 
  87. * Search BGI drivers from the path defined in the enviroment variable BGIDIR
  88. * or current directory. 
  89. * Set videomode into the BIOS to fool mouse drivers with Hercules graphics.
  90. * Set gr_end at exit and ctrl-C signals.
  91. * Terminate with error message if initialization fails.
  92. *
  93. * graphdriver   pointer to the driver ID (or DETECT)
  94. * graphmode     pointer to the mode ID
  95. ***************************************************************************/
  96.  
  97. void gr_end(void);
  98. /***************************************************************************
  99. * Returns to the text mode
  100. ***************************************************************************/
  101.  
  102.  
  103. void gr_setactivepage(int page);
  104. /*********************************************************************
  105. * Set the active graphics page for writing and reading (0/1).
  106. * Also set the 'gr_activepage' variable
  107. *********************************************************************/
  108.  
  109. void gr_setvisualpage(int page);
  110. /*********************************************************************
  111. * Set the visual graphics page
  112. * Also set the 'gr_visualpage' variable
  113. *********************************************************************/
  114.  
  115.  
  116. void gr_putch(char ch);
  117. void gr_puts(char *s);
  118. void gr_printf(char *s,...);
  119. #define gr_gotoxy(x, y) moveto(x*8, y*8)
  120. /**********************************************************************
  121. * gr_putch, gr_puts, gr_printf work as the as in text modes.
  122. * '\n', '\r' are handled as in standard text modes. 
  123. * The string to be output must not exceed 100 characters.
  124. * Scrolling or backspacing not implemented.
  125. **********************************************************************/
  126.  
  127.  
  128. void gr_center_printf(int y, char *s,...);
  129. /**********************************************************************
  130. * Print text horizontally centered.
  131. * (x centered, at given y in pixels).
  132. * The string to be output must not exceed 100 characters.
  133. **********************************************************************/
  134.  
  135. void gr_xy_printf(int x, int y, char *s,...);
  136. /**********************************************************************
  137. * printf at the given position. (x and y in pixels) 
  138. * The string to be output must not exceed 100 characters.
  139. **********************************************************************/
  140.  
  141.  
  142. void gr_dual_center_printf(int y, char *s,...);
  143. /**********************************************************************
  144. * Print text into both graphics pages at the given position.
  145. * (x centered, at given y in pixels)
  146. * The string to be output must not exceed 100 characters.
  147. **********************************************************************/
  148.  
  149. void gr_dual_xy_printf(int x, int y, char *s,...);
  150. /**********************************************************************
  151. * printf into both graphics pages at the given position.
  152. * (x and y in pixels)
  153. * The string to be output in gr_printf must not exceed 100 characters.
  154. **********************************************************************/
  155.  
  156. int gr_inkey(void);
  157. /**********************************************************************
  158. * Return a keypress if one pending, otherwise 0.
  159. * Extended codes contain 0 in the low byte.
  160. *
  161. * Keyboard buffer head and tail are set equal to disable auto-repeat,
  162. * but it doesn't always work...
  163. **********************************************************************/
  164.  
  165. char *gr_gets(char *cpdest, int max_len);
  166. /**********************************************************************
  167. * Read a string from screen in graphics mode.
  168. * The result is placed into cpdest, at most max_len characters are
  169. * read (max_len must be less than 80). Return cpdest of NULL
  170. * Backspace deletes characters, Esc returns a NULL pointer.
  171. **********************************************************************/
  172.  
  173. void gr_start_kbd_grab(void);
  174. /**********************************************************************
  175. * Set a new handler for the keyboard. This handler sets and resets
  176. * the gr_keys array values for each scancode received, then flushes the 
  177. * keyboard buffer, and after that calls the old handler.
  178. **********************************************************************/
  179.  
  180. void gr_end_kbd_grab(void);
  181. /**********************************************************************
  182. * End the kbd grab, ie restore the original keyboard handler.
  183. **********************************************************************/
  184.  
  185. /**********************************************************************
  186. * Defines for the scan codes of some keys. See others from
  187. * some book, for example Peter Norton's Programmers guide or
  188. * perhaps you could figure them out just by counting keycaps...
  189. **********************************************************************/
  190. #define GR_KEY_ESC  1
  191. #define GR_KEY_1    2
  192. #define GR_KEY_2    3
  193. #define GR_KEY_3    4
  194. #define GR_KEY_4    5
  195. #define GR_KEY_5    6
  196. #define GR_KEY_6    7
  197. #define GR_KEY_7    8
  198. #define GR_KEY_8    9
  199. #define GR_KEY_9    10
  200. #define GR_KEY_0    11
  201.  
  202. #define GR_KEY_TAB  15
  203. #define GR_KEY_Q    16
  204. #define GR_KEY_W    17
  205. #define GR_KEY_E    18
  206. #define GR_KEY_R    19 
  207. #define GR_KEY_T    20
  208. #define GR_KEY_Y    21
  209. #define GR_KEY_U    22
  210. #define GR_KEY_I    23
  211. #define GR_KEY_O    24
  212. #define GR_KEY_P    25
  213.  
  214. #define GR_KEY_A    30
  215. #define GR_KEY_S    31
  216. #define GR_KEY_D    32
  217. #define GR_KEY_F    33
  218. #define GR_KEY_G    34
  219. #define GR_KEY_H    35
  220. #define GR_KEY_J    36
  221. #define GR_KEY_K    37
  222. #define GR_KEY_L    38
  223.  
  224. #define GR_KEY_Z    44
  225. #define GR_KEY_X    45 
  226. #define GR_KEY_C    46
  227. #define GR_KEY_V    47
  228. #define GR_KEY_B    48
  229. #define GR_KEY_N    49
  230. #define GR_KEY_M    50
  231. #define GR_KEY_COMMA    51
  232. #define GR_KEY_DOT      52
  233.  
  234. #define GR_KEY_SPACE    57
  235.  
  236. #define GR_KEY_ARROW_UP     72
  237. #define GR_KEY_ARROW_DOWN   80
  238. #define GR_KEY_ARROW_LEFT   75
  239. #define GR_KEY_ARROW_RIGHT  77
  240.  
  241. #endif
  242.