]> git.mxchange.org Git - flightgear.git/blobdiff - src/Cockpit/panel.cxx
Updates from David Megginson:
[flightgear.git] / src / Cockpit / panel.cxx
index 9a3cd00a48ec8d48410fb6b7494248be83cf77e4..606f6100951b7965151fc29c93c7cefbaf3ea1d2 100644 (file)
@@ -132,7 +132,12 @@ FGPanel::update () const
   glEnable(GL_BLEND);
   glEnable(GL_ALPHA_TEST);
   glEnable(GL_COLOR_MATERIAL);
-  glColor4f(1.0, 1.0, 1.0, 1.0);
+  // glColor4f(1.0, 1.0, 1.0, 1.0);
+  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);
+  }
   glBindTexture(GL_TEXTURE_2D, _bg->getHandle());
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
@@ -185,6 +190,7 @@ bool
 FGPanel::doMouseAction (int button, int updown, int x, int y)
 {
                                // Note a released button and return
+  // cerr << "Doing mouse action\n";
   if (updown == 1) {
     _mouseDown = false;
     _mouseInstrument = 0;
@@ -201,7 +207,7 @@ FGPanel::doMouseAction (int button, int updown, int x, int y)
     int iw = inst->getWidth() / 2;
     int ih = inst->getHeight() / 2;
     if (x >= ix - iw && x < ix + iw && y >= iy - ih && y < iy + ih) {
-      cout << "Do mouse action for component " << i << '\n';
+//       cout << "Do mouse action for component " << i << '\n';
       _mouseDown = true;
       _mouseDelay = 20;
       _mouseInstrument = inst;
@@ -213,7 +219,7 @@ FGPanel::doMouseAction (int button, int updown, int x, int y)
       return true;
     }
   }
-  cout << "Did not click on an instrument\n";
+//   cout << "Did not click on an instrument\n";
   return false;
 }
 
@@ -224,7 +230,7 @@ FGPanel::doMouseAction (int button, int updown, int x, int y)
 ////////////////////////////////////////////////////////////////////////
 
 FGAdjustAction::FGAdjustAction (getter_type getter, setter_type setter,
-                               double increment, double min, double max,
+                               float increment, float min, float max,
                                bool wrap=false)
   : _getter(getter), _setter(setter), _increment(increment),
     _min(min), _max(max), _wrap(wrap)
@@ -238,15 +244,15 @@ FGAdjustAction::~FGAdjustAction ()
 void
 FGAdjustAction::doAction ()
 {
-  double value = (*_getter)();
-  cout << "Do action; value=" << value << '\n';
+  float value = (*_getter)();
+//   cout << "Do action; value=" << value << '\n';
   value += _increment;
   if (value < _min) {
     value = (_wrap ? _max : _min);
   } else if (value > _max) {
     value = (_wrap ? _min : _max);
   }
-  cout << "New value is " << value << '\n';
+//   cout << "New value is " << value << '\n';
   (*_setter)(value);
 }
 
@@ -270,7 +276,7 @@ FGSwapAction::~FGSwapAction ()
 void
 FGSwapAction::doAction ()
 {
-  double value = (*_getter1)();
+  float value = (*_getter1)();
   (*_setter1)((*_getter2)());
   (*_setter2)(value);
 }
@@ -382,10 +388,10 @@ FGPanelInstrument::doMouseAction (int button, int x, int y)
 {
   action_list_type::iterator it = _actions.begin();
   action_list_type::iterator last = _actions.end();
-  cout << "Mouse action at " << x << ',' << y << '\n';
+//   cout << "Mouse action at " << x << ',' << y << '\n';
   for ( ; it != last; it++) {
-    cout << "Trying action at " << it->x << ',' << it->y << ','
-        << it->w <<',' << it->h << '\n';
+//     cout << "Trying action at " << it->x << ',' << it->y << ','
+//      << it->w <<',' << it->h << '\n';
     if (button == it->button &&
        x >= it->x && x < it->x + it->w && y >= it->y && y < it->y + it->h) {
       it->action->doAction();
@@ -426,21 +432,28 @@ int
 FGLayeredInstrument::addLayer (FGInstrumentLayer *layer)
 {
   int n = _layers.size();
+  if (layer->getWidth() == -1) {
+    layer->setWidth(getWidth());
+  }
+  if (layer->getHeight() == -1) {
+    layer->setHeight(getHeight());
+  }
   _layers.push_back(layer);
   return n;
 }
 
 int
-FGLayeredInstrument::addLayer (ssgTexture * texture)
+FGLayeredInstrument::addLayer (CroppedTexture &texture,
+                              int w = -1, int h = -1)
 {
-  return addLayer(new FGTexturedLayer(texture, _w, _h));
+  return addLayer(new FGTexturedLayer(texture, w, h));
 }
 
 void
 FGLayeredInstrument::addTransformation (FGInstrumentLayer::transform_type type,
                                        FGInstrumentLayer::transform_func func,
-                                       double min, double max,
-                                       double factor, double offset)
+                                       float min, float max,
+                                       float factor, float offset)
 {
   int layer = _layers.size() - 1;
   _layers[layer]->addTransformation(type, func, min, max, factor, offset);
@@ -448,7 +461,7 @@ FGLayeredInstrument::addTransformation (FGInstrumentLayer::transform_type type,
 
 void
 FGLayeredInstrument::addTransformation (FGInstrumentLayer::transform_type type,
-                                       double offset)
+                                       float offset)
 {
   addTransformation(type, 0, 0.0, 0.0, 1.0, offset);
 }
@@ -482,7 +495,7 @@ FGInstrumentLayer::transform () const
   transformation_list::const_iterator last = _transformations.end();
   while (it != last) {
     transformation *t = *it;
-    double value = (t->func == 0 ? 0.0 : (*(t->func))());
+    float value = (t->func == 0 ? 0.0 : (*(t->func))());
     if (value < t->min) {
       value = t->min;
     } else if (value > t->max) {
@@ -508,8 +521,8 @@ FGInstrumentLayer::transform () const
 void
 FGInstrumentLayer::addTransformation (transform_type type,
                                      transform_func func,
-                                     double min, double max,
-                                     double factor, double offset)
+                                     float min, float max,
+                                     float factor, float offset)
 {
   transformation *t = new transformation;
   t->type = type;
@@ -527,13 +540,21 @@ FGInstrumentLayer::addTransformation (transform_type type,
 // Implementation of FGTexturedLayer.
 ////////////////////////////////////////////////////////////////////////
 
-FGTexturedLayer::FGTexturedLayer (ssgTexture * texture, int w, int h,
-                                 double texX1 = 0.0, double texY1 = 0.0,
-                                 double texX2 = 1.0, double texY2 = 1.0)
+// FGTexturedLayer::FGTexturedLayer (ssgTexture * texture, int w, int h,
+//                               float texX1 = 0.0, float texY1 = 0.0,
+//                               float texX2 = 1.0, float texY2 = 1.0)
+//   : FGInstrumentLayer(w, h),
+//     _texX1(texX1), _texY1(texY1), _texX2(texX2), _texY2(texY2)
+// {
+//   setTexture(texture);
+// }
+
+FGTexturedLayer::FGTexturedLayer (CroppedTexture &texture, int w, int h)
   : FGInstrumentLayer(w, h),
-    _texX1(texX1), _texY1(texY1), _texX2(texX2), _texY2(texY2)
+    _texX1(texture.minX), _texY1(texture.minY),
+    _texX2(texture.maxX), _texY2(texture.maxY)
 {
-  setTexture(texture);
+  setTexture(texture.texture);
 }
 
 FGTexturedLayer::~FGTexturedLayer ()
@@ -549,7 +570,11 @@ FGTexturedLayer::draw () const
   transform();
   glBindTexture(GL_TEXTURE_2D, _texture->getHandle());
   glBegin(GL_POLYGON);
-
+  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(_texX1, _texY1); glVertex2f(-w2, -h2);
   glTexCoord2f(_texX2, _texY1); glVertex2f(w2, -h2);
   glTexCoord2f(_texX2, _texY2); glVertex2f(w2, h2);
@@ -563,11 +588,18 @@ FGTexturedLayer::draw () const
 // Implementation of FGTextLayer.
 ////////////////////////////////////////////////////////////////////////
 
-FGTextLayer::FGTextLayer (int w, int h)
+FGTextLayer::FGTextLayer (int w, int h, Chunk * chunk1, Chunk * chunk2,
+                         Chunk * chunk3)
   : FGInstrumentLayer(w, h)
 {
   _color[0] = _color[1] = _color[2] = 0.0;
   _color[3] = 1.0;
+  if (chunk1)
+    addChunk(chunk1);
+  if (chunk2)
+    addChunk(chunk2);
+  if (chunk3)
+    addChunk(chunk3);
 }
 
 FGTextLayer::~FGTextLayer ()
@@ -648,7 +680,7 @@ FGTextLayer::Chunk::Chunk (text_func func, char * fmt = "%s")
 }
 
 FGTextLayer::Chunk::Chunk (double_func func, char * fmt = "%.2f",
-                          double mult = 1.0)
+                          float mult = 1.0)
   : _type(FGTextLayer::DOUBLE_FUNC), _fmt(fmt), _mult(mult)
 {
   _value._dfunc = func;