]> git.mxchange.org Git - flightgear.git/blobdiff - src/Model/panelnode.cxx
Expose a radio function (receiveBeacon) to the Nasal subsystem
[flightgear.git] / src / Model / panelnode.cxx
index c32d89830b2c6fe487d04ac72333f170649766fe..7161daa2c57029eb44a1eeacc02fb9274079bdbf 100644 (file)
@@ -6,14 +6,13 @@
 #include <simgear/structure/exception.hxx>
 
 #include <vector>
-
-#include <plib/sg.h>
+#include <algorithm>
 
 #include <Cockpit/panel.hxx>
 #include <Cockpit/panel_io.hxx>
 #include "panelnode.hxx"
 
-SG_USING_STD(vector);
+using std::vector;
 
 
 // Static (!) handling for all 3D panels in the program.
@@ -104,6 +103,11 @@ FGPanelNode::FGPanelNode(SGPropertyNode* props)
         m(1,i) *= 1.0/_ymax;
     }
 
+    _lastViewport[0] = 0;
+    _lastViewport[1] = 0;
+    _lastViewport[2] = 0;
+    _lastViewport[3] = 0;
+
     dirtyBound();
 
     // All done.  Add us to the list
@@ -116,6 +120,11 @@ FGPanelNode::FGPanelNode(SGPropertyNode* props)
 
 FGPanelNode::~FGPanelNode()
 {
+    vector<FGPanelNode*>::iterator i =
+      find(all_3d_panels.begin(), all_3d_panels.end(), this);
+    if (i != all_3d_panels.end()) {
+        all_3d_panels.erase(i);
+    }
     delete _panel;
 }
 
@@ -130,12 +139,14 @@ FGPanelNode::drawImplementation(osg::State& state) const
   // coordinates to panel coordinates when the user clicks the
   // mouse.
   // OSGFIXME: we don't need that when we can really pick
-  const_cast<osg::Matrix&>(_lastModelview) = state.getModelViewMatrix();
-  const_cast<osg::Matrix&>(_lastProjection) = state.getProjectionMatrix();
-  state.getCurrentViewport()->getViewport(const_cast<int&>(_lastViewport[0]),
-                                          const_cast<int&>(_lastViewport[1]),
-                                          const_cast<int&>(_lastViewport[2]),
-                                          const_cast<int&>(_lastViewport[3]));
+  _lastModelview = state.getModelViewMatrix();
+  _lastProjection = state.getProjectionMatrix();
+
+  const osg::Viewport* vp = state.getCurrentViewport();
+  _lastViewport[0] = vp->x();
+  _lastViewport[1] = vp->y();
+  _lastViewport[2] = vp->width();
+  _lastViewport[3] = vp->height();
   
   _panel->draw(state);
 }
@@ -152,6 +163,11 @@ FGPanelNode::computeBound() const
 
 bool FGPanelNode::doMouseAction(int button, int updown, int x, int y)
 {
+    if (_lastViewport[2] == 0 || _lastViewport[3] == 0) {
+        // we haven't been drawn yet, presumably
+        return false;
+    }
+
     // Covert the screen coordinates to viewport coordinates in the
     // range [0:1], then transform to OpenGL "post projection" coords
     // in [-1:1].  Remember the difference in Y direction!