X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2Fpanelnode.cxx;h=be6889fda55d048d80e0a63044be888fcfbb5d82;hb=461b5fe00baac88933da3c6b89dddf6d832f6a7f;hp=29b4d0e725a4a1d29222be9db25c3995c56ad925;hpb=b0f9d24f9dbab9eb2de07c48e8bfe48f3851d7e4;p=flightgear.git diff --git a/src/Model/panelnode.cxx b/src/Model/panelnode.cxx index 29b4d0e72..be6889fda 100644 --- a/src/Model/panelnode.cxx +++ b/src/Model/panelnode.cxx @@ -3,15 +3,15 @@ #endif #include -#include +#include -#include +#include #include #include #include "panelnode.hxx" -SG_USING_STD(vector); +using std::vector; // Static (!) handling for all 3D panels in the program. @@ -41,7 +41,10 @@ FGPanelNode::FGPanelNode(SGPropertyNode* props) // Make an FGPanel object. But *don't* call init() or bind() on // it -- those methods touch static state. - _panel = fgReadPanel(props->getStringValue("path")); + const char *path = props->getStringValue("path"); + _panel = fgReadPanel(path); + if (!_panel) + throw sg_io_exception(string("Failed to load panel ") + path); // Never mind. We *have* to call init to make sure the static // state is initialized (it's not, if there aren't any 2D @@ -99,6 +102,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 @@ -125,12 +133,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(_lastModelview) = state.getModelViewMatrix(); - const_cast(_lastProjection) = state.getProjectionMatrix(); - state.getCurrentViewport()->getViewport(const_cast(_lastViewport[0]), - const_cast(_lastViewport[1]), - const_cast(_lastViewport[2]), - const_cast(_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); } @@ -147,6 +157,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!