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