]> icculus.org git repositories - btb/d2x.git/blob - 2d/canvas.c
moved old ChangeLog to NEWS
[btb/d2x.git] / 2d / canvas.c
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 #include <conf.h>
15 #include <stdlib.h>
16 //#include <d_malloc.h>
17 #include <stdio.h>
18
19 #include "u_mem.h"
20
21
22 #include "gr.h"
23 #include "grdef.h"
24 #ifdef __ENV_DJGPP__
25 #include "modex.h"
26 #include "vesa.h"
27 #endif
28
29 grs_canvas * grd_curcanv;    //active canvas
30 grs_screen * grd_curscreen;  //active screen
31
32 grs_canvas *gr_create_canvas(int w, int h)
33 {
34         grs_canvas *new;
35         
36         new = (grs_canvas *)d_malloc( sizeof(grs_canvas) );
37         gr_init_bitmap_alloc (&new->cv_bitmap, BM_LINEAR, 0, 0, w, h, w);
38
39         new->cv_color = 0;
40         new->cv_drawmode = 0;
41         new->cv_font = NULL;
42         new->cv_font_fg_color = 0;
43         new->cv_font_bg_color = 0;
44         return new;
45 }
46
47 grs_canvas *gr_create_sub_canvas(grs_canvas *canv, int x, int y, int w, int h)
48 {
49     grs_canvas *new;
50
51         new = (grs_canvas *)d_malloc( sizeof(grs_canvas) );
52         gr_init_sub_bitmap (&new->cv_bitmap, &canv->cv_bitmap, x, y, w, h);
53
54         new->cv_color = canv->cv_color;
55         new->cv_drawmode = canv->cv_drawmode;
56         new->cv_font = canv->cv_font;
57         new->cv_font_fg_color = canv->cv_font_fg_color;
58         new->cv_font_bg_color = canv->cv_font_bg_color;
59         return new;
60 }
61
62 void gr_init_canvas(grs_canvas *canv, unsigned char * pixdata, int pixtype, int w, int h)
63 {
64         int wreal;
65     canv->cv_color = 0;
66     canv->cv_drawmode = 0;
67     canv->cv_font = NULL;
68         canv->cv_font_fg_color = 0;
69         canv->cv_font_bg_color = 0;
70
71
72 #ifndef __ENV_DJGPP__
73         wreal = w;
74 #else
75         wreal = (pixtype == BM_MODEX) ? w / 4 : w;
76 #endif
77         gr_init_bitmap (&canv->cv_bitmap, pixtype, 0, 0, w, h, wreal, pixdata);
78 }
79
80 void gr_init_sub_canvas(grs_canvas *new, grs_canvas *src, int x, int y, int w, int h)
81 {
82         new->cv_color = src->cv_color;
83         new->cv_drawmode = src->cv_drawmode;
84         new->cv_font = src->cv_font;
85         new->cv_font_fg_color = src->cv_font_fg_color;
86         new->cv_font_bg_color = src->cv_font_bg_color;
87
88         gr_init_sub_bitmap (&new->cv_bitmap, &src->cv_bitmap, x, y, w, h);
89 }
90
91 void gr_free_canvas(grs_canvas *canv)
92 {
93         gr_free_bitmap_data(&canv->cv_bitmap);
94     d_free(canv);
95 }
96
97 void gr_free_sub_canvas(grs_canvas *canv)
98 {
99     d_free(canv);
100 }
101
102 int gr_wait_for_retrace = 1;
103
104 void gr_show_canvas( grs_canvas *canv )
105 {
106 #ifdef __ENV_DJGPP__
107         if (canv->cv_bitmap.bm_type == BM_MODEX )
108                 gr_modex_setstart( canv->cv_bitmap.bm_x, canv->cv_bitmap.bm_y, gr_wait_for_retrace );
109
110         else if (canv->cv_bitmap.bm_type == BM_SVGA )
111                 gr_vesa_setstart( canv->cv_bitmap.bm_x, canv->cv_bitmap.bm_y );
112 #endif
113                 //      else if (canv->cv_bitmap.bm_type == BM_LINEAR )
114                 // Int3();              // Get JOHN!
115                 //gr_linear_movsd( canv->cv_bitmap.bm_data, (void *)gr_video_memory, 320*200);
116 }
117
118 void gr_set_current_canvas( grs_canvas *canv )
119 {
120         if (canv==NULL)
121                 grd_curcanv = &(grd_curscreen->sc_canvas);
122         else
123                 grd_curcanv = canv;
124 #ifndef NO_ASM
125         if ( (grd_curcanv->cv_color >= 0) && (grd_curcanv->cv_color <= 255) )   {
126                 gr_var_color = grd_curcanv->cv_color;
127         } else
128                 gr_var_color  = 0;
129         gr_var_bitmap = grd_curcanv->cv_bitmap.bm_data;
130         gr_var_bwidth = grd_curcanv->cv_bitmap.bm_rowsize;
131 #endif
132 }
133
134 void gr_clear_canvas(int color)
135 {
136         gr_setcolor(color);
137         gr_rect(0,0,GWIDTH-1,GHEIGHT-1);
138 }
139
140 void gr_setcolor(int color)
141 {
142         grd_curcanv->cv_color=color;
143 #ifndef NO_ASM
144         gr_var_color = color;
145 #endif
146 }
147