]> icculus.org git repositories - taylor/freespace2.git/blob - src/graphics/rect.cpp
Initial revision
[taylor/freespace2.git] / src / graphics / rect.cpp
1 /*
2  * $Logfile: /Freespace2/code/Graphics/Rect.cpp $
3  * $Revision$
4  * $Date$
5  * $Author$
6  *
7  * Routines to draw rectangles.
8  *
9  * $Log$
10  * Revision 1.1  2002/05/03 03:28:09  root
11  * Initial revision
12  *
13  * 
14  * 3     12/02/98 5:47p Dave
15  * Put in interface xstr code. Converted barracks screen to new format.
16  * 
17  * 2     10/07/98 10:53a Dave
18  * Initial checkin.
19  * 
20  * 1     10/07/98 10:49a Dave
21  * 
22  * 3     3/10/98 4:18p John
23  * Cleaned up graphics lib.  Took out most unused gr functions.   Made D3D
24  * & Glide have popups and print screen.  Took out all >8bpp software
25  * support.  Made Fred zbuffer.  Made zbuffer allocate dynamically to
26  * support Fred.  Made zbuffering key off of functions rather than one
27  * global variable.
28  * 
29  * 2     10/26/96 2:56p John
30  * Got gradient code working.
31  * 
32  * 1     10/26/96 1:32p John
33  * Initial rev
34  *
35  * $NoKeywords: $
36  */
37
38 #include "2d.h"
39 #include "grinternal.h"
40
41 void grx_rect(int x,int y,int w,int h)
42 {
43         int i;
44         int x1 = x, x2;
45         int y1 = y, y2;
46
47         if ( w > 0 )
48                  x2 = x + w - 1;
49         else
50                  x2 = x + w + 1;
51
52         if ( h > 0 )
53                 y2 = y + h - 1;
54         else
55                 y2 = y + h + 1;
56                 
57         if ( x2 < x1 )  {
58                 int tmp;        
59                 tmp = x1;
60                 x1 = x2;
61                 x2 = tmp;
62         }
63
64         if ( y2 < y1 )  {
65                 int tmp;        
66                 tmp = y1;
67                 y1 = y2;
68                 y2 = tmp;
69         }
70
71         // Check for completely offscreen!
72         if ( x1 > gr_screen.clip_right )
73                 return;
74
75         if ( x2 < gr_screen.clip_left )
76                 return;
77
78         if ( y1 > gr_screen.clip_bottom )
79                 return;
80
81         if ( y2 < gr_screen.clip_top )
82                 return;
83
84         // Now clip
85         if ( x1 < gr_screen.clip_left ) 
86                 x1 = gr_screen.clip_left;
87
88         if ( x2 > gr_screen.clip_right ) 
89                 x2 = gr_screen.clip_right;
90
91         if ( y1 < gr_screen.clip_top ) 
92                 y1 = gr_screen.clip_top;
93
94         if ( y2 > gr_screen.clip_bottom ) 
95                 y2 = gr_screen.clip_bottom;
96
97         w = x2-x1+1;
98         if ( w < 1 ) return;
99
100         h = y2-y1+1;
101         if ( h < 1 ) return;
102
103         gr_lock();
104
105         ubyte *dptr;
106
107         /* HARDWARE_ONLY
108         if ( Current_alphacolor )       {
109                 for (i=0; i<h; i++ )    {
110                         dptr = GR_SCREEN_PTR(ubyte,x1,y1+i);
111
112                         int j;
113                         for( j=0; j<w; j++ )    {
114                                 *dptr++ = Current_alphacolor->table.lookup[14][*dptr];
115                         }
116                 }
117         } else {
118         */
119                 for (i=0; i<h; i++ )    {
120                         dptr = GR_SCREEN_PTR(ubyte,x1,y1+i);
121                         memset( dptr, gr_screen.current_color.raw8, w );
122                 }       
123         gr_unlock();
124
125 }
126