CANVAS.C 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /*
  2. THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
  3. SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
  4. END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
  5. ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
  6. IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
  7. SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
  8. FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
  9. CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
  10. AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
  11. COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
  12. */
  13. /*
  14. * $Source: f:/miner/source/2d/rcs/canvas.c $
  15. * $Revision: 1.14 $
  16. * $Author: john $
  17. * $Date: 1995/03/06 09:18:45 $
  18. *
  19. * Graphical routines for manipulating grs_canvas's.
  20. *
  21. * $Log: canvas.c $
  22. * Revision 1.14 1995/03/06 09:18:45 john
  23. * Made modex page flipping wait for retrace be default.
  24. *
  25. * Revision 1.13 1995/03/01 15:37:40 john
  26. * Better ModeX support.
  27. *
  28. * Revision 1.12 1994/11/28 17:08:29 john
  29. * Took out some unused functions in linear.asm, moved
  30. * gr_linear_movsd from linear.asm to bitblt.c, made sure that
  31. * the code in ibiblt.c sets the direction flags before rep movsing.
  32. *
  33. * Revision 1.11 1994/11/18 22:50:24 john
  34. * Changed shorts to ints in parameters.
  35. *
  36. * Revision 1.10 1994/11/10 15:59:33 john
  37. * Fixed bugs with canvas's being created with bogus bm_flags.
  38. *
  39. * Revision 1.9 1994/06/24 17:26:34 john
  40. * Made rowsizes bigger than actual screen work with SVGA.
  41. *
  42. * Revision 1.8 1994/05/06 12:50:41 john
  43. * Added supertransparency; neatend things up; took out warnings.
  44. *
  45. * Revision 1.7 1993/12/08 16:41:26 john
  46. * fixed color = -1 bug
  47. *
  48. * Revision 1.6 1993/10/15 16:22:25 john
  49. * *** empty log message ***
  50. *
  51. * Revision 1.5 1993/09/29 16:14:07 john
  52. * added globol variables describing current canvas
  53. *
  54. * Revision 1.4 1993/09/14 16:03:40 matt
  55. * Added new function, gr_clear_canvas()
  56. *
  57. * Revision 1.3 1993/09/14 13:51:38 matt
  58. * in gr_init_sub_canvas(), copy bm_rowsize from source canvas
  59. *
  60. * Revision 1.2 1993/09/08 17:37:34 john
  61. * Checking for potential errors
  62. *
  63. * Revision 1.1 1993/09/08 11:43:18 john
  64. * Initial revision
  65. *
  66. *
  67. */
  68. #include <stdlib.h>
  69. #include <malloc.h>
  70. #include <stdio.h>
  71. #include "mem.h"
  72. #include "gr.h"
  73. #include "grdef.h"
  74. grs_canvas * grd_curcanv; //active canvas
  75. grs_screen * grd_curscreen; //active screen
  76. grs_canvas *gr_create_canvas(int w, int h)
  77. {
  78. unsigned char * data;
  79. grs_canvas *new;
  80. new = (grs_canvas *)malloc( sizeof(grs_canvas) );
  81. data = (unsigned char *)malloc(w*h);
  82. new->cv_bitmap.bm_x = 0;
  83. new->cv_bitmap.bm_y = 0;
  84. new->cv_bitmap.bm_w = w;
  85. new->cv_bitmap.bm_h = h;
  86. new->cv_bitmap.bm_flags = 0;
  87. new->cv_bitmap.bm_type = BM_LINEAR;
  88. new->cv_bitmap.bm_rowsize = w;
  89. new->cv_bitmap.bm_data = data;
  90. new->cv_color = 0;
  91. new->cv_drawmode = 0;
  92. new->cv_font = NULL;
  93. new->cv_font_fg_color = 0;
  94. new->cv_font_bg_color = 0;
  95. return new;
  96. }
  97. grs_canvas *gr_create_sub_canvas(grs_canvas *canv, int x, int y, int w, int h)
  98. {
  99. grs_canvas *new;
  100. new = (grs_canvas *)malloc( sizeof(grs_canvas) );
  101. new->cv_bitmap.bm_x = x+canv->cv_bitmap.bm_x;
  102. new->cv_bitmap.bm_y = y+canv->cv_bitmap.bm_y;
  103. new->cv_bitmap.bm_w = w;
  104. new->cv_bitmap.bm_h = h;
  105. new->cv_bitmap.bm_flags = 0;
  106. new->cv_bitmap.bm_type = canv->cv_bitmap.bm_type;
  107. new->cv_bitmap.bm_rowsize = canv->cv_bitmap.bm_rowsize;
  108. new->cv_bitmap.bm_data = canv->cv_bitmap.bm_data;
  109. new->cv_bitmap.bm_data += y*canv->cv_bitmap.bm_rowsize;
  110. new->cv_bitmap.bm_data += x;
  111. new->cv_color = canv->cv_color;
  112. new->cv_drawmode = canv->cv_drawmode;
  113. new->cv_font = canv->cv_font;
  114. new->cv_font_fg_color = canv->cv_font_fg_color;
  115. new->cv_font_bg_color = canv->cv_font_bg_color;
  116. return new;
  117. }
  118. void gr_init_canvas(grs_canvas *canv, unsigned char * pixdata, int pixtype, int w, int h)
  119. {
  120. canv->cv_color = 0;
  121. canv->cv_drawmode = 0;
  122. canv->cv_font = NULL;
  123. canv->cv_font_fg_color = 0;
  124. canv->cv_font_bg_color = 0;
  125. canv->cv_bitmap.bm_x = 0;
  126. canv->cv_bitmap.bm_y = 0;
  127. if (pixtype==BM_MODEX)
  128. canv->cv_bitmap.bm_rowsize = w / 4;
  129. else
  130. canv->cv_bitmap.bm_rowsize = w;
  131. canv->cv_bitmap.bm_w = w;
  132. canv->cv_bitmap.bm_h = h;
  133. canv->cv_bitmap.bm_flags = 0;
  134. canv->cv_bitmap.bm_type = pixtype;
  135. canv->cv_bitmap.bm_data = pixdata;
  136. }
  137. void gr_init_sub_canvas(grs_canvas *new, grs_canvas *src, int x, int y, int w, int h)
  138. {
  139. new->cv_color = src->cv_color;
  140. new->cv_drawmode = src->cv_drawmode;
  141. new->cv_font = src->cv_font;
  142. new->cv_font_fg_color = src->cv_font_fg_color;
  143. new->cv_font_bg_color = src->cv_font_bg_color;
  144. new->cv_bitmap.bm_x = src->cv_bitmap.bm_x+x;
  145. new->cv_bitmap.bm_y = src->cv_bitmap.bm_y+y;
  146. new->cv_bitmap.bm_w = w;
  147. new->cv_bitmap.bm_h = h;
  148. new->cv_bitmap.bm_flags = 0;
  149. new->cv_bitmap.bm_type = src->cv_bitmap.bm_type;
  150. new->cv_bitmap.bm_rowsize = src->cv_bitmap.bm_rowsize;
  151. new->cv_bitmap.bm_data = src->cv_bitmap.bm_data;
  152. new->cv_bitmap.bm_data += y*src->cv_bitmap.bm_rowsize;
  153. new->cv_bitmap.bm_data += x;
  154. }
  155. void gr_free_canvas(grs_canvas *canv)
  156. {
  157. free(canv->cv_bitmap.bm_data );
  158. free(canv);
  159. }
  160. void gr_free_sub_canvas(grs_canvas *canv)
  161. {
  162. free(canv);
  163. }
  164. int gr_wait_for_retrace = 1;
  165. void gr_show_canvas( grs_canvas *canv )
  166. {
  167. if (canv->cv_bitmap.bm_type == BM_MODEX )
  168. gr_modex_setstart( canv->cv_bitmap.bm_x, canv->cv_bitmap.bm_y, gr_wait_for_retrace );
  169. else if (canv->cv_bitmap.bm_type == BM_SVGA )
  170. gr_vesa_setstart( canv->cv_bitmap.bm_x, canv->cv_bitmap.bm_y );
  171. // else if (canv->cv_bitmap.bm_type == BM_LINEAR )
  172. // Int3(); // Get JOHN!
  173. //gr_linear_movsd( canv->cv_bitmap.bm_data, (void *)0xA0000, 320*200);
  174. }
  175. void gr_set_current_canvas( grs_canvas *canv )
  176. {
  177. if (canv==NULL)
  178. grd_curcanv = &(grd_curscreen->sc_canvas);
  179. else
  180. grd_curcanv = canv;
  181. if ( (grd_curcanv->cv_color >= 0) && (grd_curcanv->cv_color <= 255) ) {
  182. gr_var_color = grd_curcanv->cv_color;
  183. } else
  184. gr_var_color = 0;
  185. gr_var_bitmap = grd_curcanv->cv_bitmap.bm_data;
  186. gr_var_bwidth = grd_curcanv->cv_bitmap.bm_rowsize;
  187. }
  188. void gr_clear_canvas(int color)
  189. {
  190. gr_setcolor(color);
  191. gr_rect(0,0,WIDTH-1,HEIGHT-1);
  192. }
  193. void gr_setcolor(int color)
  194. {
  195. grd_curcanv->cv_color=color;
  196. gr_var_color = color;
  197. }
  198.