00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
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
00088
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
00108
00109
00110
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
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
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
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
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