Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
guidefs.h
Go to the documentation of this file.
1 /*
2  * Vega Strike
3  * Copyright (C) 2003 Mike Byron
4  *
5  * http://vegastrike.sourceforge.net/
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  */
21 
22 #ifndef __GUIDEFS_H__
23 #define __GUIDEFS_H__
24 
25 #include "gfxlib.h"
26 #include "gldrv/winsys.h"
27 //Location in 2d.
28 struct Point
29 {
30  float x, y;
31 
32  //OPERATORS
33  bool operator==( const Point &other )
34  {
35  return x == other.x && y == other.y;
36  }
37  bool operator!=( const Point &other )
38  {
39  return !(*this == other);
40  }
41 
42  //CONSTRUCTION
43  Point() : x( 0.0 )
44  , y( 0.0 ) {}
45  Point( float cx, float cy ) :
46  x( cx )
47  , y( cy )
48  {}
49 };
50 
51 //Extent of an area in 2d. This is not the same as a point.
52 struct Size
53 {
54  float width, height;
55 
56  //OPERATORS
57  bool operator==( const Size &other )
58  {
59  return width == other.width && height == other.height;
60  }
61  bool operator!=( const Size &other )
62  {
63  return !(*this == other);
64  }
65 
66  //CONSTRUCTION
67  Size() : width( 0.0 )
68  , height( 0.0 ) {}
69  Size( float cwidth, float cheight ) :
70  width( cwidth )
71  , height( cheight )
72  {}
73 };
74 
75 //Rectangle in 2d.
76 class Rect
77 {
78 public:
79 //Data
82 
83  float left( void ) const
84  {
85  return origin.x;
86  }
87  float right( void ) const
88  {
89  return origin.x+size.width;
90  }
91  float bottom( void ) const
92  {
93  return origin.y;
94  }
95  float top( void ) const
96  {
97  return origin.y+size.height;
98  }
99 
100 //The center of this rectangle.
101  Point center( void ) const
102  {
103  return Point( origin.x+size.width/2, origin.y+size.height/2 );
104  }
105 
106 //Whether a Point is inside this Rect.
107  bool inside( const Point &p ) const
108  {
109  return p.x >= left() && p.x < right() && p.y >= bottom() && p.y < top();
110  }
111 
112 //Make a new Rect that is inset by the specified margins.
113  void inset( const Size &s )
114  {
115  origin.x += s.width;
116  origin.y += s.height;
117  size.width -= s.width*2;
118  size.height -= s.height*2;
119  }
120 
121 //Return a copy of the rect inset by specified margins.
122  Rect copyAndInset( const Size s )
123  {
124  Rect result = *this;
125  result.inset( s );
126  return result;
127  }
128 
129 //OPERATORS
130  bool operator==( const Rect &other )
131  {
132  return origin == other.origin && size == other.size;
133  }
134  bool operator!=( const Rect &other )
135  {
136  return !(*this == other);
137  }
138 
139 //CONSTRUCTION
140  Rect() {}
141  Rect( Point &p, Size &s ) :
142  origin( p )
143  , size( s )
144  {}
145  Rect( float x, float y, float width, float height ) :
146  origin( x, y )
147  , size( width, height )
148  {}
149 };
150 
151 //Rect that describes the coordinates of a full screen.
152 static const Rect FULL_SCREEN_RECT( -1, -1, 2, 2 );
153 
154 //Type of input event.
155 typedef enum
156 {
164 
165 //Event modifiers as a bit mask: buttons or keys.
166 typedef unsigned int EventModMask;
167 
168 //The code for a key in a keyboard event.
169 typedef unsigned int EventKeyCode;
170 
171 //The code for a button in a mouse event.
172 //(Currently, this must be the same type as a key code.)
174 
175 //Mouse button constants
176 static const unsigned int LEFT_MOUSE_BUTTON = WS_LEFT_BUTTON;
177 static const unsigned int MIDDLE_MOUSE_BUTTON = WS_MIDDLE_BUTTON;
178 static const unsigned int RIGHT_MOUSE_BUTTON = WS_RIGHT_BUTTON;
179 static const unsigned int WHEELUP_MOUSE_BUTTON = WS_WHEEL_UP;
180 static const unsigned int WHEELDOWN_MOUSE_BUTTON = WS_WHEEL_DOWN;
181 
182 /* This describes an event from an input device: mouse, keyboard, etc.
183  * It does *not* describe a command event.
184  */
186 {
187  InputEventType type; //Kind of event.
188  unsigned int code; //Key or mouse button.
189  EventModMask mask; //Modifier keys or buttons.
190  Point loc; //Coordinate of mouse.
191 
192  //CONSTRUCTION
193  InputEvent( InputEventType t, unsigned int c, EventModMask m, const Point &l ) :
194  type( t )
195  , code( c )
196  , mask( m )
197  , loc( l ) {}
200  , mask( 0 )
201  , loc( Point( 0, 0 ) ) {}
202 };
203 
204 //Text justification possibilities.
206 {
210 };
211 
212 GFXColor getConfigColor( const char *name, GFXColor defaul );
213 GFXColor SaturatedColor( float r, float g, float b, float a = 1.0f );
214 //Predefined colors.
215 GFXColor GUI_OPAQUE_BLACK(); //(0.0,0.0,0.0);
216 GFXColor GUI_OPAQUE_WHITE(); //(1.0,1.0,1.0);
217 const GFXColor GUI_CLEAR( 0.0, 0.0, 0.0, 0.0 );
218 GFXColor GUI_OPAQUE_LIGHT_GRAY(); //(0.25,0.25,0.25);
219 GFXColor GUI_OPAQUE_MEDIUM_GRAY(); //(0.5,0.5,0.5);
220 GFXColor GUI_OPAQUE_DARK_GRAY(); //(0.75,0.75,0.75);
221 
222 //Whether a color is clear -- totally transparent.
223 inline bool isClear( const GFXColor &c )
224 {
225  return c.a <= 0.0;
226 }
227 
228 //Compare two colors.
229 //Used in upgrade/downgrade to decide whether an item is OK.
230 inline bool equalColors( const GFXColor &c1, const GFXColor &c2 )
231 {
232  return c1.r == c2.r && c1.g == c2.g && c1.b == c2.b && c1.a == c2.a;
233 }
234 
236 
237 //Draw a rectangle using the specified color.
238 void drawRect( const Rect &rect, const GFXColor &color );
239 
240 //Draw the outline of a rectangle using the specified color.
241 void drawRectOutline( const Rect &rect, const GFXColor &color, float lineWidth );
242 
243 //Draw upper-left part of rectangle's "shadow".
244 void drawUpLeftShadow( const Rect &rect, const GFXColor &color, float lineWidth );
245 
246 //Draw lower-right part of rectangle's "shadow".
247 void drawLowRightShadow( const Rect &rect, const GFXColor &color, float lineWidth );
248 
249 //Fill a closed polygon.
250 void drawFilledPolygon( const std::vector< Point > &coords, const GFXColor &color );
251 
253 
254 #define guiMin( a, b ) ( (a) < (b) ? (a) : (b) )
255 #define guiMax( a, b ) ( (a) > (b) ? (a) : (b) )
256 
257 #endif //__GUIDEFS_H__
258