1 /*
2  * Seven Kingdoms: Ancient Adversaries
3  *
4  * Copyright 1997,1998 Enlight Software Ltd.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 //Filename    : vgautil2.cpp
22 //Description : VGA drawing functions
23 
24 #include <ALL.h>
25 #include <IMGFUN.h>
26 #include <OMOUSE.h>
27 #include <OMOUSECR.h>
28 #include <OCOLTBL.h>
29 #include <OVGA.h>
30 #include <vga_util.h>
31 
32 //-------- Define constant --------//
33 
34 #define UP_OPAQUE_COLOR       (VGA_GRAY+10)
35 #define DOWN_OPAQUE_COLOR     (VGA_GRAY+13)
36 
37 
38 //--------- Begin of function VgaUtil::blt_buf ----------//
39 //
40 // Blt the back buffer to the front buffer.
41 //
42 // <int> x1, y1, x2, y2 - the coordinations of the area to be blit
43 // [int] putBackCursor  - whether put a mouse cursor onto the back buffer
44 //                        before blitting.
45 //                        (default: 1)
46 //
blt_buf(int x1,int y1,int x2,int y2,int putBackCursor)47 void VgaUtil::blt_buf(int x1, int y1, int x2, int y2, int putBackCursor)
48 {
49    if( putBackCursor )
50    {
51       mouse_cursor.hide_area_flag = 0;    // do not call mouse.hide_area() which will double paint the cursor
52 
53       mouse_cursor.hide_x1 = x1;
54       mouse_cursor.hide_y1 = y1;
55       mouse_cursor.hide_x2 = x2;
56       mouse_cursor.hide_y2 = y2;
57 
58       //-------- put mouse cursor ---------//
59 
60       mouse_cursor.disp_back_buf(x1, y1, x2, y2);
61    }
62    else
63    {
64       mouse.hide_area(x1, y1, x2, y2);
65    }
66 
67    //--------------------------------------//
68 
69    IMGcopy( vga_front.buf_ptr(), vga_front.buf_pitch(),
70       vga_back.buf_ptr(), vga_back.buf_pitch(), x1, y1, x2, y2 );
71 
72    //--------------------------------------//
73 
74    if( putBackCursor )
75       mouse_cursor.hide_area_flag = 0;    // do not call mouse.show_area() which will double paint the cursor
76    else
77       mouse.show_area();
78 }
79 //---------- End of function VgaUtil::blt_buf ----------//
80 
81 
82 //----------- Begin of function VgaUtil::d3_panel_up ------------//
83 //
84 // <int> x1,y1,x2,y2  = the four vertex of the panel
85 // [int] vgaFrontOnly = do all the bitmap processing on the front buffer only
86 //                      (default: 0)
87 // [int] drawBorderOnly = draw border only, do not brighten the center area
88 //                        (default: 0)
89 //
d3_panel_up(int x1,int y1,int x2,int y2,int vgaFrontOnly,int drawBorderOnly)90 void VgaUtil::d3_panel_up(int x1,int y1,int x2,int y2,int vgaFrontOnly,int drawBorderOnly)
91 {
92    err_when( x1>x2 || y1>y2 || x1<0 || y1<0 || x2>=VGA_WIDTH || y2>=VGA_HEIGHT );
93 
94    VgaBuf* vgaBuf;
95 
96    if( vgaFrontOnly )
97       vgaBuf = &vga_front;
98    else
99       vgaBuf = &vga_back;
100 
101    if( !drawBorderOnly )
102    {
103       if( Vga::opaque_flag )
104          vgaBuf->bar(x1+1, y1+1, x2-1, y2-1, UP_OPAQUE_COLOR);
105       else
106          vgaBuf->adjust_brightness(x1+1, y1+1, x2-1, y2-1, IF_UP_BRIGHTNESS_ADJUST);
107    }
108 
109    mouse.hide_area( x1,y1,x2,y2 );
110 
111    //--------- white border on top and left sides -----------//
112 
113    IMGbar( vgaBuf->buf_ptr(), vgaBuf->buf_pitch(), x1+1,y1,x2,y1, IF_LIGHT_BORDER_COLOR );    // top side
114    IMGbar( vgaBuf->buf_ptr(), vgaBuf->buf_pitch(), x1,y1,x1,y2  , IF_LIGHT_BORDER_COLOR );    // left side
115 
116    //--------- black border on bottom and right sides -----------//
117 
118    IMGbar( vgaBuf->buf_ptr(), vgaBuf->buf_pitch(), x1+1,y2,x2,y2, IF_DARK_BORDER_COLOR );     // bottom side
119    IMGbar( vgaBuf->buf_ptr(), vgaBuf->buf_pitch(), x2,y1+1,x2,y2, IF_DARK_BORDER_COLOR );     // right side
120 
121    //-------------------------------------------//
122 
123    mouse.show_area();
124 
125    //----- blt the area from the back buffer to the front buffer ------//
126 
127    if( !vgaFrontOnly && !vga.use_back_buf )      // only blt the back to the front is the active buffer is the front
128       blt_buf(x1, y1, x2, y2, 0);
129 }
130 //------------- End of function VgaUtil::d3_panel_up ------------//
131 
132 
133 //----------- Begin of function VgaUtil::d3_panel_down ------------//
134 //
135 // <int> x1,y1,x2,y2  = the four vertex of the panel
136 // [int] vgaFrontOnly = do all the bitmap processing on the front buffer only
137 //                      (default: 0)
138 // [int] drawBorderOnly = draw border only, do not brighten the center area
139 //                        (default: 0)
140 //
d3_panel_down(int x1,int y1,int x2,int y2,int vgaFrontOnly,int drawBorderOnly)141 void VgaUtil::d3_panel_down(int x1,int y1,int x2,int y2,int vgaFrontOnly,int drawBorderOnly)
142 {
143    err_when( x1>x2 || y1>y2 || x1<0 || y1<0 || x2>=VGA_WIDTH || y2>=VGA_HEIGHT );
144 
145    VgaBuf* vgaBuf;
146 
147    if( vgaFrontOnly )
148       vgaBuf = &vga_front;
149    else
150       vgaBuf = &vga_back;
151 
152    if( !drawBorderOnly )
153    {
154       if( Vga::opaque_flag )
155          vgaBuf->bar(x1+1, y1+1, x2-1, y2-1, DOWN_OPAQUE_COLOR);
156       else
157          vgaBuf->adjust_brightness(x1+1, y1+1, x2-1, y2-1, IF_DOWN_BRIGHTNESS_ADJUST);
158    }
159 
160    mouse.hide_area( x1,y1,x2,y2 );
161 
162    //--------- white border on top and left sides -----------//
163 
164    IMGbar( vgaBuf->buf_ptr(), vgaBuf->buf_pitch(), x1+1,y1,x2,y1, IF_DARK_BORDER_COLOR );    // top side
165    IMGbar( vgaBuf->buf_ptr(), vgaBuf->buf_pitch(), x1,y1,x1,y2  , IF_DARK_BORDER_COLOR );    // left side
166 
167    //--------- black border on bottom and right sides -----------//
168 
169    IMGbar( vgaBuf->buf_ptr(), vgaBuf->buf_pitch(), x1+1,y2,x2,y2, IF_LIGHT_BORDER_COLOR );   // bottom side
170    IMGbar( vgaBuf->buf_ptr(), vgaBuf->buf_pitch(), x2,y1+1,x2,y2, IF_LIGHT_BORDER_COLOR );   // right side
171 
172    //-------------------------------------------//
173 
174    mouse.show_area();
175 
176    //----- blt the area from the back buffer to the front buffer ------//
177 
178    if( !vgaFrontOnly && !vga.use_back_buf )      // only blt the back to the front is the active buffer is the front
179       blt_buf(x1, y1, x2, y2, 0);
180 }
181 //------------- End of function VgaUtil::d3_panel_down ------------//
182 
183 
184 //----------- Begin of function VgaUtil::d3_panel2_up ------------//
185 //
186 // <int> x1,y1,x2,y2  = the four vertex of the panel
187 // [int] vgaFrontOnly = do all the bitmap processing on the front buffer only
188 //                      (default: 0)
189 // [int] drawBorderOnly = draw border only, do not brighten the center area
190 //                        (default: 0)
191 //
d3_panel2_up(int x1,int y1,int x2,int y2,int vgaFrontOnly,int drawBorderOnly)192 void VgaUtil::d3_panel2_up(int x1,int y1,int x2,int y2,int vgaFrontOnly,int drawBorderOnly)
193 {
194    err_when( x1>x2 || y1>y2 || x1<0 || y1<0 || x2>=VGA_WIDTH || y2>=VGA_HEIGHT );
195 
196    VgaBuf* vgaBuf;
197 
198    if( vgaFrontOnly )
199       vgaBuf = &vga_front;
200    else
201       vgaBuf = &vga_back;
202 
203    if( !drawBorderOnly )
204       vgaBuf->adjust_brightness(x1+2, y1+2, x2-3, y2-3, IF_UP_BRIGHTNESS_ADJUST);
205 
206    mouse.hide_area( x1,y1,x2,y2 );
207 
208    //--------- white border on top and left sides -----------//
209 
210    IMGbar( vgaBuf->buf_ptr(), vgaBuf->buf_pitch(), x1,y1,x2-3,y1+1,0x9a );
211    vgaBuf->draw_pixel(x2-2, y1, 0x9a);
212    IMGbar( vgaBuf->buf_ptr(), vgaBuf->buf_pitch(), x1,y1+2,x1+1,y2-3, 0x9a );    // left side
213    vgaBuf->draw_pixel(x1, y2-2, 0x9a);
214 
215    //--------- black border on bottom and right sides -----------//
216 
217    IMGbar( vgaBuf->buf_ptr(), vgaBuf->buf_pitch(), x2-2,y1+2,x2-1,y2-1, 0x90 );     // bottom side
218    vgaBuf->draw_pixel(x2-1, y1+1, 0x90);
219    IMGbar( vgaBuf->buf_ptr(), vgaBuf->buf_pitch(), x1+2,y2-2,x2-3,y2-1, 0x90 );      // right side
220    vgaBuf->draw_pixel(x1+1, y2-1, 0x90);
221 
222    //--------- junction between white and black border --------//
223    vgaBuf->draw_pixel(x2-1, y1, 0x97);
224    vgaBuf->draw_pixel(x2-2, y1+1, 0x97);
225    vgaBuf->draw_pixel(x1, y2-1, 0x97);
226    vgaBuf->draw_pixel(x1+1, y2-2, 0x97);
227 
228    //--------- gray shadow on bottom and right sides -----------//
229    IMGbar( vgaBuf->buf_ptr(), vgaBuf->buf_pitch(), x2, y1+1, x2, y2, 0x97);
230    IMGbar( vgaBuf->buf_ptr(), vgaBuf->buf_pitch(), x1+1, y2, x2-1, y2, 0x97);
231 
232    //-------------------------------------------//
233 
234    mouse.show_area();
235 
236    //----- blt the area from the back buffer to the front buffer ------//
237 
238    if( !vgaFrontOnly && !vga.use_back_buf )      // only blt the back to the front is the active buffer is the front
239       blt_buf(x1, y1, x2, y2, 0);
240 }
241 //------------- End of function VgaUtil::d3_panel_up ------------//
242 
243 
244 //----------- Begin of function VgaUtil::d3_panel2_down ------------//
245 //
246 // <int> x1,y1,x2,y2  = the four vertex of the panel
247 // [int] vgaFrontOnly = do all the bitmap processing on the front buffer only
248 //                      (default: 0)
249 // [int] drawBorderOnly = draw border only, do not brighten the center area
250 //                        (default: 0)
251 //
d3_panel2_down(int x1,int y1,int x2,int y2,int vgaFrontOnly,int drawBorderOnly)252 void VgaUtil::d3_panel2_down(int x1,int y1,int x2,int y2,int vgaFrontOnly,int drawBorderOnly)
253 {
254    err_when( x1>x2 || y1>y2 || x1<0 || y1<0 || x2>=VGA_WIDTH || y2>=VGA_HEIGHT );
255 
256    VgaBuf* vgaBuf;
257 
258    if( vgaFrontOnly )
259       vgaBuf = &vga_front;
260    else
261       vgaBuf = &vga_back;
262 
263    if( !drawBorderOnly )
264       vgaBuf->adjust_brightness(x1+2, y1+2, x2-3, y2-3, IF_DOWN_BRIGHTNESS_ADJUST);
265 
266    mouse.hide_area( x1,y1,x2,y2 );
267 
268    //--------- black border on top and left sides -----------//
269 
270    IMGbar( vgaBuf->buf_ptr(), vgaBuf->buf_pitch(), x1,y1,x2-3,y1+1,0x90 );
271    vgaBuf->draw_pixel(x2-2, y1, 0x90);
272    IMGbar( vgaBuf->buf_ptr(), vgaBuf->buf_pitch(), x1,y1+2,x1+1,y2-3, 0x90 );    // left side
273    vgaBuf->draw_pixel(x1, y2-2, 0x90);
274 
275    //--------- while border on bottom and right sides -----------//
276 
277    IMGbar( vgaBuf->buf_ptr(), vgaBuf->buf_pitch(), x2-2,y1+2,x2-1,y2-1, 0x9a );     // bottom side
278    vgaBuf->draw_pixel(x2-1, y1+1, 0x9a);
279    IMGbar( vgaBuf->buf_ptr(), vgaBuf->buf_pitch(), x1+2,y2-2,x2-3,y2-1, 0x9a );      // right side
280    vgaBuf->draw_pixel(x1+1, y2-1, 0x9a);
281 
282    //--------- junction between white and black border --------//
283    vgaBuf->draw_pixel(x2-1, y1, 0x97);
284    vgaBuf->draw_pixel(x2-2, y1+1, 0x97);
285    vgaBuf->draw_pixel(x1, y2-1, 0x97);
286    vgaBuf->draw_pixel(x1+1, y2-2, 0x97);
287 
288    //--------- remove shadow, copy from back  -----------//
289    IMGbar( vgaBuf->buf_ptr(), vgaBuf->buf_pitch(), x2, y1+1, x2, y2, 0x9c);
290    IMGbar( vgaBuf->buf_ptr(), vgaBuf->buf_pitch(), x1+1, y2, x2-1, y2, 0x9c);
291 
292    mouse.show_area();
293 
294    //----- blt the area from the back buffer to the front buffer ------//
295 
296    if( !vgaFrontOnly && !vga.use_back_buf )      // only blt the back to the front is the active buffer is the front
297       blt_buf(x1, y1, x2, y2, 0);
298 }
299 //------------- End of function VgaUtil::d3_panel2_down ------------//
300 
301 
302 //------------- Start of function VgaUtil::separator --------------//
303 //
304 // Draw a VGA separator line
305 //
306 // Syntax : separator( x1, y1, x2, y2 )
307 //
308 // int x1,y1       - the top left vertex of the separator
309 // int x2,y2       - the bottom right vertex of the separator
310 //
separator(int x1,int y1,int x2,int y2)311 void VgaUtil::separator(int x1, int y1, int x2, int y2)
312 {
313    err_when( x1>x2 || y1>y2 || x1<0 || y1<0 || x2>=VGA_WIDTH || y2>=VGA_HEIGHT );
314 
315    if( y1+1==y2 )       // horizontal line
316    {
317       vga_front.adjust_brightness(x1, y1, x2, y1, IF_UP_BRIGHTNESS_ADJUST);
318       vga_front.adjust_brightness(x1, y2, x2, y2, IF_DOWN_BRIGHTNESS_ADJUST);
319    }
320    else
321    {
322       vga_front.adjust_brightness(x1, y1, x1, y2, IF_UP_BRIGHTNESS_ADJUST);
323       vga_front.adjust_brightness(x2, y1, x2, y2, IF_DOWN_BRIGHTNESS_ADJUST);
324    }
325 }
326 //--------------- End of function VgaUtil::separator --------------//
327