]> git.mxchange.org Git - flightgear.git/blobdiff - src/Cockpit/panel.cxx
Sep. 22, 2000 panel updates from David Megginson to make the new config file
[flightgear.git] / src / Cockpit / panel.cxx
index d8e7e4c2b197121db8c8fc6b639717afeca6f69b..8a5bb68b6fd1e986a182b2fc4fa0d12a455b5757 100644 (file)
@@ -68,6 +68,44 @@ FGTextureManager::createTexture (const string &relativePath)
 }
 
 
+
+\f
+////////////////////////////////////////////////////////////////////////
+// Implementation of FGCropped Texture.
+////////////////////////////////////////////////////////////////////////
+
+
+FGCroppedTexture::FGCroppedTexture ()
+  : _path(""), _texture(0),
+    _minX(0.0), _minY(0.0), _maxX(1.0), _maxY(1.0)
+{
+}
+
+
+FGCroppedTexture::FGCroppedTexture (const string &path,
+                                   float minX, float minY,
+                                   float maxX, float maxY)
+  : _path(path), _texture(0),
+    _minX(minX), _minY(minY), _maxX(maxX), _maxY(maxY)
+{
+}
+
+
+FGCroppedTexture::~FGCroppedTexture ()
+{
+}
+
+
+ssgTexture *
+FGCroppedTexture::getTexture ()
+{
+  if (_texture == 0) {
+    _texture = FGTextureManager::createTexture(_path);
+  }
+  return _texture;
+}
+
+
 \f
 ////////////////////////////////////////////////////////////////////////
 // Implementation of FGPanel.
@@ -200,7 +238,7 @@ FGPanel::doMouseAction (int button, int updown, int x, int y)
   x = (int)(((float)x / current_view.get_winWidth()) * _w);
   y = (int)(_h - (((float)y / current_view.get_winHeight()) * _h));
 
-  for (int i = 0; i < _instruments.size(); i++) {
+  for (int i = 0; i < (int)_instruments.size(); i++) {
     FGPanelInstrument *inst = _instruments[i];
     int ix = inst->getXPos();
     int iy = inst->getYPos();
@@ -248,7 +286,7 @@ FGPanelAction::~FGPanelAction ()
 
 FGAdjustAction::FGAdjustAction (int button, int x, int y, int w, int h,
                                SGValue * value, float increment, 
-                               float min, float max, bool wrap=false)
+                               float min, float max, bool wrap)
   : FGPanelAction(button, x, y, w, h),
     _value(value), _increment(increment), _min(min), _max(max), _wrap(wrap)
 {
@@ -450,7 +488,7 @@ FGLayeredInstrument::~FGLayeredInstrument ()
 void
 FGLayeredInstrument::draw ()
 {
-  for (int i = 0; i < _layers.size(); i++) {
+  for (int i = 0; i < (int)_layers.size(); i++) {
     glPushMatrix();
     glTranslatef(0.0, 0.0, (i / 100.0) + 0.1);
     _layers[i]->draw();
@@ -473,8 +511,8 @@ FGLayeredInstrument::addLayer (FGInstrumentLayer *layer)
 }
 
 int
-FGLayeredInstrument::addLayer (CroppedTexture &texture,
-                              int w = -1, int h = -1)
+FGLayeredInstrument::addLayer (FGCroppedTexture &texture,
+                              int w, int h)
 {
   return addLayer(new FGTexturedLayer(texture, w, h));
 }
@@ -551,7 +589,7 @@ FGInstrumentLayer::addTransformation (FGPanelTransformation * transformation)
 ////////////////////////////////////////////////////////////////////////
 
 
-FGTexturedLayer::FGTexturedLayer (CroppedTexture &texture, int w, int h)
+FGTexturedLayer::FGTexturedLayer (const FGCroppedTexture &texture, int w, int h)
   : FGInstrumentLayer(w, h)
 {
   setTexture(texture);
@@ -570,21 +608,53 @@ FGTexturedLayer::draw ()
   int h2 = _h / 2;
 
   transform();
-  glBindTexture(GL_TEXTURE_2D, _texture.texture->getHandle());
+  glBindTexture(GL_TEXTURE_2D, _texture.getTexture()->getHandle());
   glBegin(GL_POLYGON);
+
+                               // From Curt: turn on the panel
+                               // lights after sundown.
   if ( cur_light_params.sun_angle * RAD_TO_DEG < 95.0 ) {
       glColor4fv( cur_light_params.scene_diffuse );
   } else {
       glColor4f(0.7, 0.2, 0.2, 1.0);
   }
-  glTexCoord2f(_texture.minX, _texture.minY); glVertex2f(-w2, -h2);
-  glTexCoord2f(_texture.maxX, _texture.minY); glVertex2f(w2, -h2);
-  glTexCoord2f(_texture.maxX, _texture.maxY); glVertex2f(w2, h2);
-  glTexCoord2f(_texture.minX, _texture.maxY); glVertex2f(-w2, h2);
+
+
+  glTexCoord2f(_texture.getMinX(), _texture.getMinY()); glVertex2f(-w2, -h2);
+  glTexCoord2f(_texture.getMaxX(), _texture.getMinY()); glVertex2f(w2, -h2);
+  glTexCoord2f(_texture.getMaxX(), _texture.getMaxY()); glVertex2f(w2, h2);
+  glTexCoord2f(_texture.getMinX(), _texture.getMaxY()); glVertex2f(-w2, h2);
   glEnd();
 }
 
 
+\f
+////////////////////////////////////////////////////////////////////////
+// Implementation of FGWindowLayer.
+////////////////////////////////////////////////////////////////////////
+
+FGWindowLayer::FGWindowLayer (int w, int h)
+  : FGTexturedLayer (w, h)
+{
+}
+
+FGWindowLayer::FGWindowLayer (const FGCroppedTexture &texture, int w, int h)
+  : FGTexturedLayer(texture, w, h)
+{
+}
+
+FGWindowLayer::~FGWindowLayer ()
+{
+}
+
+void
+FGWindowLayer::draw ()
+{
+  // doesn't do anything yet
+  FGTexturedLayer::draw();
+}
+
+
 \f
 ////////////////////////////////////////////////////////////////////////
 // Implementation of FGTextLayer.
@@ -592,7 +662,7 @@ FGTexturedLayer::draw ()
 
 FGTextLayer::FGTextLayer (int w, int h, Chunk * chunk1, Chunk * chunk2,
                          Chunk * chunk3)
-  : FGInstrumentLayer(w, h)
+  : FGInstrumentLayer(w, h), _pointSize(14.0)
 {
   _color[0] = _color[1] = _color[2] = 0.0;
   _color[3] = 1.0;
@@ -620,7 +690,7 @@ FGTextLayer::draw ()
   glColor4fv(_color);
   transform();
   _renderer.setFont(guiFntHandle);
-  _renderer.setPointSize(14);
+  _renderer.setPointSize(_pointSize);
   _renderer.begin();
   _renderer.start3f(0, 0, 0);
 
@@ -628,7 +698,7 @@ FGTextLayer::draw ()
   chunk_list::const_iterator it = _chunks.begin();
   chunk_list::const_iterator last = _chunks.end();
   for ( ; it != last; it++) {
-    _renderer.puts((*it)->getValue());
+    _renderer.puts((char *)((*it)->getValue()));
   }
 
   _renderer.end();
@@ -652,9 +722,9 @@ FGTextLayer::setColor (float r, float g, float b)
 }
 
 void
-FGTextLayer::setPointSize (const float size)
+FGTextLayer::setPointSize (float size)
 {
-  _renderer.setPointSize(size);
+  _pointSize = size;
 }
 
 void
@@ -669,37 +739,39 @@ FGTextLayer::setFont(fntFont * font)
 // Implementation of FGTextLayer::Chunk.
 ////////////////////////////////////////////////////////////////////////
 
-FGTextLayer::Chunk::Chunk (char * text, char * fmt = "%s")
+FGTextLayer::Chunk::Chunk (const string &text, const string &fmt)
   : _type(FGTextLayer::TEXT), _fmt(fmt)
 {
-  _value._text = text;
+  _text = text;
+  if (_fmt == "") 
+    _fmt = "%s";
 }
 
 FGTextLayer::Chunk::Chunk (ChunkType type, const SGValue * value,
-                          char * fmt = 0, float mult = 1.0)
+                          const string &fmt, float mult)
   : _type(type), _fmt(fmt), _mult(mult)
 {
-  if (_fmt == 0) {
+  if (_fmt == "") {
     if (type == TEXT_VALUE)
       _fmt = "%s";
     else
       _fmt = "%.2f";
   }
-  _value._value = value;
+  _value = value;
 }
 
-char *
+const char *
 FGTextLayer::Chunk::getValue () const
 {
   switch (_type) {
   case TEXT:
-    sprintf(_buf, _fmt, _value._text);
+    sprintf(_buf, _fmt.c_str(), _text.c_str());
     return _buf;
   case TEXT_VALUE:
-    sprintf(_buf, _fmt, _value._value->getStringValue().c_str());
+    sprintf(_buf, _fmt.c_str(), _value->getStringValue().c_str());
     break;
   case DOUBLE_VALUE:
-    sprintf(_buf, _fmt, _value._value->getFloatValue() * _mult);
+    sprintf(_buf, _fmt.c_str(), _value->getFloatValue() * _mult);
     break;
   }
   return _buf;