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