]> git.mxchange.org Git - flightgear.git/blobdiff - src/Model/panelnode.cxx
Make 2D panel mouse action repeat independent of the frame-rate.
[flightgear.git] / src / Model / panelnode.cxx
index 46988d8e61597c87c5fa40984164d13ef79c5daf..150b2ef40654f505bbfe1a12a9d36aabf547fc1f 100644 (file)
@@ -13,7 +13,7 @@
 #include <simgear/structure/exception.hxx>
 #include <simgear/debug/logstream.hxx>
 
-#include <simgear/scene/util/OSGMath.hxx>
+#include <simgear/scene/util/OsgMath.hxx>
 #include <simgear/scene/util/SGPickCallback.hxx>
 #include <simgear/scene/util/SGSceneUserData.hxx>
 #include <simgear/scene/util/SGNodeMasks.hxx>
@@ -44,9 +44,9 @@ public:
                                           picked.x(), picked.y());
   }
   
-  virtual void update(double /* dt */)
+  virtual void update(double dt)
   {
-    panel->getPanel()->updateMouseDelay();
+    panel->getPanel()->updateMouseDelay(dt);
   }
   
   virtual void buttonReleased(void)
@@ -110,10 +110,11 @@ void FGPanelNode::initWithPanel()
     _panel->init();
 
     // Read out the pixel-space info
-    _xmax = _panel->getWidth();
-    _ymax = _panel->getHeight();
-
+    float panelWidth = _panel->getWidth();
+    float panelHeight = _panel->getHeight();
 
+    _panel->getLogicalExtent(_xmin, _ymin, _xmax, _ymax);
+  
     // Now generate our transformation matrix.  For shorthand, use
     // "a", "b", and "c" as our corners and "m" as the matrix. The
     // vector u goes from a to b, v from a to c, and w is a
@@ -138,8 +139,8 @@ void FGPanelNode::initWithPanel()
     // rectangle.  Postmultiply scaling factors that match the
     // pixel-space size of the panel.
     for(i=0; i<4; ++i) {
-        m(0,i) *= 1.0/_xmax;
-        m(1,i) *= 1.0/_ymax;
+        m(0,i) *= 1.0/panelWidth;
+        m(1,i) *= 1.0/panelHeight;
     }
 
     dirtyBound();
@@ -152,7 +153,6 @@ void FGPanelNode::initWithPanel()
 
 FGPanelNode::~FGPanelNode()
 {
-    delete _panel;
 }
 
 osg::Matrix FGPanelNode::transformMatrix() const
@@ -181,28 +181,29 @@ FGPanelNode::drawImplementation(osg::State& state) const
 osg::BoundingBox
 FGPanelNode::computeBound() const
 {
-    osg::Vec3 coords[4];
-    osg::Matrix m(transformMatrix());
-    coords[0] = m.preMult(osg::Vec3(0,0,0));
-    coords[1] = m.preMult(osg::Vec3(_xmax,0,0));
-    coords[2] = m.preMult(osg::Vec3(0,_ymax,0));
-  
-    osg::BoundingBox bb;
-    bb.expandBy(coords[0]);
-    bb.expandBy(coords[1]);
-    bb.expandBy(coords[2]);
-    return bb;
+
+  osg::Vec3 coords[3];
+  osg::Matrix m(transformMatrix());
+  coords[0] = m.preMult(osg::Vec3(_xmin,_ymin,0));
+  coords[1] = m.preMult(osg::Vec3(_xmax,_ymin,0));
+  coords[2] = m.preMult(osg::Vec3(_xmin,_ymax,0));
+
+  osg::BoundingBox bb;
+  bb.expandBy(coords[0]);
+  bb.expandBy(coords[1]);
+  bb.expandBy(coords[2]);
+  return bb;
 }
 
 void FGPanelNode::accept(osg::PrimitiveFunctor& functor) const
 {
   osg::Vec3 coords[4];
   osg::Matrix m(transformMatrix());
-
-  coords[0] = m.preMult(osg::Vec3(0,0,0));
-  coords[1] = m.preMult(osg::Vec3(_xmax,0,0));
+  
+  coords[0] = m.preMult(osg::Vec3(_xmin,_ymin,0));
+  coords[1] = m.preMult(osg::Vec3(_xmax,_ymin,0));
   coords[2] = m.preMult(osg::Vec3(_xmax, _ymax, 0));
-  coords[3] = m.preMult(osg::Vec3(0,_ymax,0));
+  coords[3] = m.preMult(osg::Vec3(_xmin,_ymax,0));
 
   functor.setVertexArray(4, coords);
   functor.drawArrays( GL_QUADS, 0, 4);