From cd58df820e07677c438ce1b70ae82135951ea195 Mon Sep 17 00:00:00 2001 From: James Turner Date: Mon, 11 Mar 2013 18:07:27 +0000 Subject: [PATCH] Standardise location (in XML) of hovered elements. Hovered bindings are always direction children of the pick animation, since having different hovered behaviours per-action makes no sense. --- simgear/scene/model/SGPickAnimation.cxx | 29 +++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/simgear/scene/model/SGPickAnimation.cxx b/simgear/scene/model/SGPickAnimation.cxx index abdeec82..68da16fb 100644 --- a/simgear/scene/model/SGPickAnimation.cxx +++ b/simgear/scene/model/SGPickAnimation.cxx @@ -85,13 +85,19 @@ osg::Vec2d eventToWindowCoords(const osgGA::GUIEventAdapter* ea) _bindingsDown = readBindingList(configNode->getChildren("binding"), modelRoot); readOptionalBindingList(configNode, modelRoot, "mod-up", _bindingsUp); - readOptionalBindingList(configNode, modelRoot, "hovered", _hover); + if (configNode->hasChild("cursor")) { _cursorName = configNode->getStringValue("cursor"); } } - + + void addHoverBindings(const SGPropertyNode* hoverNode, + SGPropertyNode* modelRoot) + { + _hover = readBindingList(hoverNode->getChildren("binding"), modelRoot); + } + virtual bool buttonPressed(int button, const osgGA::GUIEventAdapter* ea, const Info&) { if (_buttons.find(button) == _buttons.end()) { @@ -367,11 +373,26 @@ SGPickAnimation::innerSetupPickGroup(osg::Group* commonGroup, osg::Group& parent innerSetupPickGroup(commonGroup, parent); SGSceneUserData* ud = SGSceneUserData::getOrCreateSceneUserData(commonGroup); + PickCallback* pickCb = NULL; + // add actions that become macro and command invocations std::vector actions; actions = getConfig()->getChildren("action"); - for (unsigned int i = 0; i < actions.size(); ++i) - ud->addPickCallback(new PickCallback(actions[i], getModelRoot())); + for (unsigned int i = 0; i < actions.size(); ++i) { + pickCb = new PickCallback(actions[i], getModelRoot()); + ud->addPickCallback(pickCb); + } + + if (getConfig()->hasChild("hovered")) { + if (!pickCb) { + // make a trivial PickCallback to hang the hovered off of + SGPropertyNode_ptr dummyNode(new SGPropertyNode); + pickCb = new PickCallback(dummyNode.ptr(), getModelRoot()); + } + + pickCb->addHoverBindings(getConfig()->getNode("hovered"), getModelRoot()); + } + // Look for the VNC sessions that want raw mouse input actions = getConfig()->getChildren("vncaction"); for (unsigned int i = 0; i < actions.size(); ++i) -- 2.39.5