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.cpp
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 #include "vegastrike.h"
23 #include "xml_support.h"
24 #include "vs_globals.h"
25 #include "config_xml.h"
26 #include "guidefs.h"
27 GFXColor getConfigColor( const char *name, GFXColor defaul )
28 {
29  float color[4];
30  color[0] = defaul.r;
31  color[1] = defaul.g;
32  color[2] = defaul.b;
33  color[3] = defaul.a;
34  vs_config->getColor( std::string( "default" ), std::string( name ), color, true );
35  return GFXColor( color[0], color[1], color[2], color[3] );
36 }
37 
38 GFXColor SaturatedColor( float r, float g, float b, float a )
39 {
40  static float Saturation = XMLSupport::parse_float( vs_config->getVariable( "graphics", "base_saturation", "1.0" ) );
41 
42  return GFXColor( ( r*Saturation*3+(r+b+g)*(1-Saturation) )/3,
43  ( g*Saturation*3+(r+b+g)*(1-Saturation) )/3,
44  ( b*Saturation*3+(r+b+g)*(1-Saturation) )/3, a );
45 }
47 {
48  static GFXColor gui_black = getConfigColor( "base_black", GFXColor( 0, 0, 0, 1 ) );
49  return gui_black;
50 }
52 {
53  static GFXColor gui_white = getConfigColor( "base_white", GFXColor( 1, 1, 1, 1 ) );
54  return gui_white;
55 }
56 
58 {
59  static GFXColor gui_light_gray = getConfigColor( "base_light_gray", GFXColor( .25, .25, .25, 1 ) );
60  return gui_light_gray;
61 }
63 {
64  static GFXColor gui_gray = getConfigColor( "base_gray", GFXColor( .5, .5, .5, 1 ) );
65  return gui_gray;
66 }
68 {
69  static GFXColor gui_dark_gray = getConfigColor( "base_dark_gray", GFXColor( .75, .75, .75, 1 ) );
70  return gui_dark_gray;
71 }
72 
73 //Draw a rectangle using the specified color.
74 void drawRect( const Rect &rect, const GFXColor &color )
75 {
76  glDisable( GL_TEXTURE_2D );
77 
78  glColor4f( color.r, color.g, color.b, color.a );
79  glRectf( rect.left(), rect.bottom(), rect.right(), rect.top() );
80 
81  glEnable( GL_TEXTURE_2D );
82 }
83 
84 //Draw the outline of a rectangle using the specified color.
85 void drawRectOutline( const Rect &rect, const GFXColor &color, float lineWidth )
86 {
87  glDisable( GL_TEXTURE_2D );
88  glLineWidth( lineWidth );
89 
90  glBegin( GL_LINE_LOOP );
91  glColor4f( color.r, color.g, color.b, color.a );
92  glVertex2f( rect.left(), rect.top() );
93  glVertex2f( rect.right(), rect.top() );
94  glVertex2f( rect.right(), rect.bottom() );
95  glVertex2f( rect.left(), rect.bottom() );
96  glEnd();
97 
98  glEnable( GL_TEXTURE_2D );
99 }
100 
101 //Draw upper-left part of rectangle's "shadow".
102 void drawUpLeftShadow( const Rect &rect, const GFXColor &color, float lineWidth )
103 {
104  glDisable( GL_TEXTURE_2D );
105  glLineWidth( lineWidth );
106 
107  glBegin( GL_LINE_STRIP );
108  glColor4f( color.r, color.g, color.b, color.a );
109  glVertex2f( rect.origin.x, rect.origin.y );
110  glVertex2f( rect.origin.x, rect.origin.y+rect.size.height );
111  glVertex2f( rect.origin.x+rect.size.width, rect.origin.y+rect.size.height );
112  glEnd();
113 
114  glEnable( GL_TEXTURE_2D );
115 }
116 
117 //Draw lower-right part of rectangle's "shadow".
118 void drawLowRightShadow( const Rect &rect, const GFXColor &color, float lineWidth )
119 {
120  glDisable( GL_TEXTURE_2D );
121  glLineWidth( lineWidth );
122 
123  glBegin( GL_LINE_STRIP );
124  glColor4f( color.r, color.g, color.b, color.a );
125  glVertex2f( rect.origin.x, rect.origin.y );
126  glVertex2f( rect.origin.x+rect.size.width, rect.origin.y );
127  glVertex2f( rect.origin.x+rect.size.width, rect.origin.y+rect.size.height );
128  glEnd();
129 
130  glEnable( GL_TEXTURE_2D );
131 }
132 
133 //Fill a closed polygon.
134 void drawFilledPolygon( const std::vector< Point > &coords, const GFXColor &color )
135 {
136  glDisable( GL_TEXTURE_2D );
137 
138  glBegin( GL_POLYGON );
139  glColor4f( color.r, color.g, color.b, color.a );
140  for (std::vector< Point >::const_iterator i = coords.begin(); i != coords.end(); i++)
141  glVertex2f( i->x, i->y );
142  glEnd();
143 
144  glEnable( GL_TEXTURE_2D );
145 }
146