src/tron/cockpit/cGauges.cpp

Go to the documentation of this file.
00001 /*
00002 
00003 *************************************************************************
00004 
00005 ArmageTron -- Just another Tron Lightcycle Game in 3D.
00006 Copyright (C) 2000  Manuel Moos (manuel@moosnet.de)
00007 
00008 **************************************************************************
00009 
00010 This program is free software; you can redistribute it and/or
00011 modify it under the terms of the GNU General Public License
00012 as published by the Free Software Foundation; either version 2
00013 of the License, or (at your option) any later version.
00014 
00015 This program is distributed in the hope that it will be useful,
00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 GNU General Public License for more details.
00019 
00020 You should have received a copy of the GNU General Public License
00021 along with this program; if not, write to the Free Software
00022 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00023 
00024 ***************************************************************************
00025 
00026 */
00027 
00028 #include "cockpit/cGauges.h"
00029 
00030 #ifndef DEDICATED
00031 #include "rRender.h"
00032 #include "rFont.h"
00033 #include "rScreen.h"
00034 
00035 namespace cWidget {
00036 
00037 bool BarGauge::Process(tXmlParser::node cur) {
00038     if (
00039         WithAngles      ::Process(cur) ||
00040         WithSingleData  ::Process(cur) ||
00041         WithBackground  ::Process(cur) ||
00042         WithForeground  ::Process(cur) ||
00043         WithLineColor   ::Process(cur) ||
00044         WithCoordinates ::Process(cur) ||
00045         WithCaption     ::Process(cur) ||
00046         WithShowSettings::Process(cur) ||
00047         WithReverse     ::Process(cur))
00048         return true;
00049     else {
00050         DisplayError(cur);
00051         return false;
00052     }
00053 }
00054 
00055 void BarGauge::RenderMinMax(tValue::Base const &min_s, tValue::Base const &max_s) {
00056     //Max and min
00057     if((m_showmin && !m_reverse) || (m_showmax && m_reverse))
00058         DisplayText(
00059             m_position.x-m_size.x, m_position.y-.15*m_size.x,
00060             .24*m_size.x,
00061             ((m_reverse?max_s:min_s).GetString()).c_str(), sr_fontCockpit);
00062     if((m_showmax && !m_reverse) || (m_showmin && m_reverse))
00063         DisplayText( m_position.x+m_size.x, m_position.y-.15*m_size.x,
00064                      .24*m_size.x,
00065                      ((m_reverse?min_s:max_s).GetString()).c_str(), sr_fontCockpit);
00066 }
00067 
00068 void BarGauge::RenderCaption(void) {
00069     if ( m_captionloc != off ) {
00070         const float y=(m_captionloc==top ? m_position.y+m_size.y+.2*m_size.x : m_position.y-.15*m_size.x);
00071         DisplayText(m_position.x,y,.24*m_size.x,m_caption.c_str(),sr_fontCockpit);
00072     }
00073 }
00074 
00075 void VerticalBarGauge::RenderCaption(void) {
00076     if ( m_captionloc != off ) {
00077         const float y=
00078             (m_captionloc==top ?
00079              m_position.y+1.2*m_size.y :
00080              m_position.y-1.2*m_size.y);
00081         DisplayText(m_position.x,y,.24*m_size.y,m_caption.c_str(),sr_fontCockpit);
00082     }
00083 }
00084 
00085 void BarGauge::Render() {
00086     glDisable(GL_TEXTURE_2D);
00087     //sr_ResetRenderState(0); //needs this because rFont has bugs i presume.. Ie I have problems as soon as rTextFirld is used
00088     // z-man: actually, it is needed because per-frame-tasks get called without rendering context, so it has to be set.
00089 
00090     const tValue::Base &val_s = m_data.GetVal();
00091     const tValue::Base &min_s = m_data.GetMin();
00092     const tValue::Base &max_s = m_data.GetMax();
00093 
00094     float min = min_s.GetFloat();
00095     float max = max_s.GetFloat();
00096     float val = val_s.GetFloat();
00097 
00098     if (val > max) val = max;
00099     if (val < min) val = min;
00100     if (min >= max) return;
00101 
00102     RenderGraph(min, max, val,m_reverse?-1.:1., val_s);
00103 
00104     RenderMinMax(min_s, max_s);
00105     RenderCaption();
00106 
00107     //if (!sr_glOut)
00108     //    return;
00109 
00110     //glColor3f(1,1,1);
00111 }
00112 
00113 void BarGauge::RenderGraph(float min, float max, float val, float factor, tValue::Base const &val_s) {
00114     float x= factor * ((val-min)/(max-min)*2. - 1.);
00115     float y= (x+1.)/2.;
00116 
00117     const tCoord edge1(tCoord(m_position.x-m_size.x, m_position.y));
00118     const tCoord edge2(tCoord(m_position.x+m_size.x, m_position.y+m_size.y));
00119 
00120     rGradient &left = (factor < .0) ? m_background : m_foreground;
00121     rGradient &right = (factor < .0) ? m_foreground : m_background;
00122 
00123     left.SetGradientEdges(edge1, edge2);
00124     right.SetGradientEdges(edge1, edge2);
00125     m_line_color.SetGradientEdges(edge1, edge2);
00126 
00127     left.SetValue(y);
00128     right.SetValue(y);
00129     m_line_color.SetValue(y);
00130 
00131     right.DrawRect(
00132         tCoord(m_size.x*x+m_position.x, m_position.y),
00133         tCoord(m_size.x+m_position.x, m_position.y+m_size.y));
00134 
00135     left.DrawRect(
00136         tCoord(m_size.x*x+m_position.x, m_position.y),
00137         tCoord(m_position.x-m_size.x, m_position.y+m_size.y));
00138 
00139     m_line_color.BeginDraw();
00140     BeginLines();
00141     m_line_color.DrawPoint(tCoord(m_size.x*x+m_position.x,m_position.y));
00142     m_line_color.DrawPoint(tCoord(m_size.x*x+m_position.x,m_size.y+m_position.y));
00143     RenderEnd();
00144 
00145     //Value
00146     if(m_showvalue)
00147         DisplayText( m_position.x, m_position.y+.20*m_size.x, .24*m_size.x, (val_s.GetString()).c_str(), sr_fontCockpit);
00148 }
00149 
00150 
00151 void VerticalBarGauge::RenderGraph(float min, float max, float val, float factor, tValue::Base const &val_s) {
00152     float x= factor * ((val-min)/(max-min)*2. - 1.);
00153     float y= (x+1.)/2.;
00154 
00155     const tCoord edge1(tCoord(m_position.x-m_size.x, m_position.y-m_size.y));
00156     const tCoord edge2(tCoord(m_position.x+m_size.x, m_position.y+m_size.y));
00157 
00158     m_foreground.SetGradientEdges(edge1, edge2);
00159     m_background.SetGradientEdges(edge1, edge2);
00160     m_line_color.SetGradientEdges(edge1, edge2);
00161 
00162     m_foreground.SetValue(y);
00163     m_background.SetValue(y);
00164     m_line_color.SetValue(y);
00165 
00166     m_background.DrawRect(
00167         tCoord(m_position.x+m_size.x, m_position.y+m_size.y*x),
00168         tCoord(m_position.x-m_size.x, m_position.y+m_size.y));
00169 
00170     m_foreground.DrawRect(
00171         tCoord(m_position.x+m_size.x, m_position.y-m_size.y),
00172         tCoord(m_position.x-m_size.x, m_position.y+m_size.y*x));
00173 
00174     m_line_color.BeginDraw();
00175     BeginLines();
00176     m_line_color.DrawPoint(tCoord(m_position.x+m_size.x,m_position.y+m_size.y*x));
00177     m_line_color.DrawPoint(tCoord(m_position.x-m_size.x,m_position.y+m_size.y*x));
00178     RenderEnd();
00179 
00180     //Value
00181     if(m_showvalue)
00182         DisplayText( m_position.x, m_position.y, .05*m_size.y, (val_s.GetString()).c_str(), sr_fontCockpit);
00183 }
00184 
00185 
00186 void NeedleGauge::RenderGraph(float min, float max, float val, float factor, tValue::Base const &val_s) {
00187     float x, y;
00188     float t = m_reverse ? (val - max) / (min - max) : (val - min) / (max - min);
00189     float a = m_angle_min * (1 - t) + m_angle_max * t;
00190     x= cos(a);
00191     y= sin(a);
00192 
00193     /* Draws an ugly background on the gauge
00194     BeginQuads();
00195     Color(1.,1.,1.,.8);
00196     Vertex(m_position.x-m_size-.04,m_position.y-.04,0);
00197     Vertex(m_position.x-m_size-.04,m_position.y+m_size+.04,0);
00198     Vertex(m_position.x+m_size+.04,m_position.y+m_size+.04,0);
00199     Vertex(m_position.x+m_size+.04,m_position.y-.04,0);
00200 
00201     Color(.1,.1,.1,.8);
00202     Vertex(m_position.x-m_size-.02,m_position.y-.02,0);
00203     Vertex(m_position.x-m_size-.02,m_position.y+m_size+.02,0);
00204     Vertex(m_position.x+m_size+.02,m_position.y+m_size+.02,0);
00205     Vertex(m_position.x+m_size+.02,m_position.y-.02,0);
00206 
00207     RenderEnd();*/
00208 
00209     BeginLines();
00210     m_foreground.SetValue((factor * ((val-min)/(max-min)*2. - 1.)+1.)/2.);
00211     m_foreground.DrawAt(tCoord(0.,0.));
00212     Vertex(-.1*x*m_size.x+m_position.x,.1*y*m_size.y+m_position.y,0);
00213     Vertex(-x*m_size.x+m_position.x,y*m_size.y+m_position.y,0);
00214     RenderEnd();
00215 
00216     if(m_showvalue)
00217         DisplayText( -x*1.45*m_size.x+m_position.x, y*1.35*m_size.y+m_position.y,
00218                      .2*m_size.x,
00219                      val_s.GetString().c_str(),
00220                      sr_fontCockpit);
00221     if (!sr_glOut)
00222         return;
00223 }
00224 
00225 }
00226 
00227 #endif

Generated on Sat Mar 15 22:56:04 2008 for Armagetron Advanced by  doxygen 1.5.4