add condition to pick animations
This commit is contained in:
@@ -74,10 +74,12 @@ osg::Vec2d eventToWindowCoords(const osgGA::GUIEventAdapter& ea)
|
|||||||
class SGPickAnimation::PickCallback : public SGPickCallback {
|
class SGPickAnimation::PickCallback : public SGPickCallback {
|
||||||
public:
|
public:
|
||||||
PickCallback(const SGPropertyNode* configNode,
|
PickCallback(const SGPropertyNode* configNode,
|
||||||
SGPropertyNode* modelRoot) :
|
SGPropertyNode* modelRoot,
|
||||||
|
SGSharedPtr<SGCondition const> condition) :
|
||||||
SGPickCallback(PriorityPanel),
|
SGPickCallback(PriorityPanel),
|
||||||
_repeatable(configNode->getBoolValue("repeatable", false)),
|
_repeatable(configNode->getBoolValue("repeatable", false)),
|
||||||
_repeatInterval(configNode->getDoubleValue("interval-sec", 0.1))
|
_repeatInterval(configNode->getDoubleValue("interval-sec", 0.1)),
|
||||||
|
_condition(condition)
|
||||||
{
|
{
|
||||||
std::vector<SGPropertyNode_ptr> bindings;
|
std::vector<SGPropertyNode_ptr> bindings;
|
||||||
|
|
||||||
@@ -98,63 +100,76 @@ osg::Vec2d eventToWindowCoords(const osgGA::GUIEventAdapter& ea)
|
|||||||
void addHoverBindings(const SGPropertyNode* hoverNode,
|
void addHoverBindings(const SGPropertyNode* hoverNode,
|
||||||
SGPropertyNode* modelRoot)
|
SGPropertyNode* modelRoot)
|
||||||
{
|
{
|
||||||
_hover = readBindingList(hoverNode->getChildren("binding"), modelRoot);
|
if (!_condition || _condition->test()) {
|
||||||
|
_hover = readBindingList(hoverNode->getChildren("binding"), modelRoot);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool buttonPressed( int button,
|
virtual bool buttonPressed( int button,
|
||||||
const osgGA::GUIEventAdapter&,
|
const osgGA::GUIEventAdapter&,
|
||||||
const Info& )
|
const Info& )
|
||||||
{
|
{
|
||||||
if (_buttons.find(button) == _buttons.end()) {
|
if (!_condition || _condition->test()) {
|
||||||
return false;
|
if (_buttons.find(button) == _buttons.end()) {
|
||||||
}
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (!anyBindingEnabled(_bindingsDown)) {
|
if (!anyBindingEnabled(_bindingsDown)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
fireBindingList(_bindingsDown);
|
fireBindingList(_bindingsDown);
|
||||||
_repeatTime = -_repeatInterval; // anti-bobble: delay start of repeat
|
_repeatTime = -_repeatInterval; // anti-bobble: delay start of repeat
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
virtual void buttonReleased( int keyModState,
|
virtual void buttonReleased( int keyModState,
|
||||||
const osgGA::GUIEventAdapter&,
|
const osgGA::GUIEventAdapter&,
|
||||||
const Info* )
|
const Info* )
|
||||||
{
|
{
|
||||||
SG_UNUSED(keyModState);
|
if (!_condition || _condition->test()) {
|
||||||
fireBindingList(_bindingsUp);
|
SG_UNUSED(keyModState);
|
||||||
|
fireBindingList(_bindingsUp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void update(double dt, int keyModState)
|
virtual void update(double dt, int keyModState)
|
||||||
{
|
{
|
||||||
SG_UNUSED(keyModState);
|
if (!_condition || _condition->test()) {
|
||||||
if (!_repeatable)
|
SG_UNUSED(keyModState);
|
||||||
return;
|
if (!_repeatable)
|
||||||
|
return;
|
||||||
|
|
||||||
_repeatTime += dt;
|
_repeatTime += dt;
|
||||||
while (_repeatInterval < _repeatTime) {
|
while (_repeatInterval < _repeatTime) {
|
||||||
_repeatTime -= _repeatInterval;
|
_repeatTime -= _repeatInterval;
|
||||||
fireBindingList(_bindingsDown);
|
fireBindingList(_bindingsDown);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool hover( const osg::Vec2d& windowPos,
|
virtual bool hover( const osg::Vec2d& windowPos,
|
||||||
const Info& )
|
const Info& )
|
||||||
{
|
{
|
||||||
if (!anyBindingEnabled(_hover)) {
|
if (!_condition || _condition->test()) {
|
||||||
return false;
|
if (!anyBindingEnabled(_hover)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
SGPropertyNode_ptr params(new SGPropertyNode);
|
||||||
|
params->setDoubleValue("x", windowPos.x());
|
||||||
|
params->setDoubleValue("y", windowPos.y());
|
||||||
|
fireBindingList(_hover, params.ptr());
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
SGPropertyNode_ptr params(new SGPropertyNode);
|
|
||||||
params->setDoubleValue("x", windowPos.x());
|
|
||||||
params->setDoubleValue("y", windowPos.y());
|
|
||||||
fireBindingList(_hover, params.ptr());
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string getCursor() const
|
std::string getCursor() const
|
||||||
{ return _cursorName; }
|
{ return _cursorName; }
|
||||||
private:
|
private:
|
||||||
|
SGSharedPtr<SGCondition const> _condition;
|
||||||
SGBindingList _bindingsDown;
|
SGBindingList _bindingsDown;
|
||||||
SGBindingList _bindingsUp;
|
SGBindingList _bindingsUp;
|
||||||
SGBindingList _hover;
|
SGBindingList _hover;
|
||||||
@@ -247,8 +262,9 @@ class SGPickAnimation::VncCallback : public SGPickCallback {
|
|||||||
public:
|
public:
|
||||||
VncCallback(const SGPropertyNode* configNode,
|
VncCallback(const SGPropertyNode* configNode,
|
||||||
SGPropertyNode* modelRoot,
|
SGPropertyNode* modelRoot,
|
||||||
osg::Group *node)
|
osg::Group *node,
|
||||||
: _node(node)
|
SGSharedPtr<SGCondition const> condition)
|
||||||
|
: _node(node), _condition(condition)
|
||||||
{
|
{
|
||||||
SG_LOG(SG_INPUT, SG_DEBUG, "Configuring VNC callback");
|
SG_LOG(SG_INPUT, SG_DEBUG, "Configuring VNC callback");
|
||||||
const char *cornernames[3] = {"top-left", "top-right", "bottom-left"};
|
const char *cornernames[3] = {"top-left", "top-right", "bottom-left"};
|
||||||
@@ -270,29 +286,35 @@ public:
|
|||||||
const osgGA::GUIEventAdapter&,
|
const osgGA::GUIEventAdapter&,
|
||||||
const Info& info )
|
const Info& info )
|
||||||
{
|
{
|
||||||
SGVec3d loc(info.local);
|
if (!_condition || _condition->test()) {
|
||||||
SG_LOG(SG_INPUT, SG_DEBUG, "VNC pressed " << button << ": " << loc);
|
SGVec3d loc(info.local);
|
||||||
loc -= _topLeft;
|
SG_LOG(SG_INPUT, SG_DEBUG, "VNC pressed " << button << ": " << loc);
|
||||||
_x = dot(loc, _toRight) / _squaredRight;
|
loc -= _topLeft;
|
||||||
_y = dot(loc, _toDown) / _squaredDown;
|
_x = dot(loc, _toRight) / _squaredRight;
|
||||||
if (_x<0) _x = 0; else if (_x > 1) _x = 1;
|
_y = dot(loc, _toDown) / _squaredDown;
|
||||||
if (_y<0) _y = 0; else if (_y > 1) _y = 1;
|
if (_x < 0) _x = 0; else if (_x > 1) _x = 1;
|
||||||
VncVisitor vv(_x, _y, 1 << button);
|
if (_y < 0) _y = 0; else if (_y > 1) _y = 1;
|
||||||
_node->accept(vv);
|
VncVisitor vv(_x, _y, 1 << button);
|
||||||
return vv.wasSuccessful();
|
_node->accept(vv);
|
||||||
|
return vv.wasSuccessful();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
virtual void buttonReleased( int keyModState,
|
virtual void buttonReleased( int keyModState,
|
||||||
const osgGA::GUIEventAdapter&,
|
const osgGA::GUIEventAdapter&,
|
||||||
const Info* )
|
const Info* )
|
||||||
{
|
{
|
||||||
SG_UNUSED(keyModState);
|
if (!_condition || _condition->test()) {
|
||||||
SG_LOG(SG_INPUT, SG_DEBUG, "VNC release");
|
SG_UNUSED(keyModState);
|
||||||
VncVisitor vv(_x, _y, 0);
|
SG_LOG(SG_INPUT, SG_DEBUG, "VNC release");
|
||||||
_node->accept(vv);
|
VncVisitor vv(_x, _y, 0);
|
||||||
|
_node->accept(vv);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
SGSharedPtr<SGCondition const> _condition;
|
||||||
|
|
||||||
double _x, _y;
|
double _x, _y;
|
||||||
osg::ref_ptr<osg::Group> _node;
|
osg::ref_ptr<osg::Group> _node;
|
||||||
SGVec3d _topLeft, _toRight, _toDown;
|
SGVec3d _topLeft, _toRight, _toDown;
|
||||||
@@ -304,6 +326,8 @@ private:
|
|||||||
SGPickAnimation::SGPickAnimation(simgear::SGTransientModelData &modelData) :
|
SGPickAnimation::SGPickAnimation(simgear::SGTransientModelData &modelData) :
|
||||||
SGAnimation(modelData)
|
SGAnimation(modelData)
|
||||||
{
|
{
|
||||||
|
_condition = getCondition();
|
||||||
|
|
||||||
std::vector<SGPropertyNode_ptr> names = modelData.getConfigNode()->getChildren("proxy-name");
|
std::vector<SGPropertyNode_ptr> names = modelData.getConfigNode()->getChildren("proxy-name");
|
||||||
for (unsigned i = 0; i < names.size(); ++i) {
|
for (unsigned i = 0; i < names.size(); ++i) {
|
||||||
_proxyNames.push_back(names[i]->getStringValue());
|
_proxyNames.push_back(names[i]->getStringValue());
|
||||||
@@ -451,7 +475,7 @@ SGPickAnimation::setupCallbacks(SGSceneUserData* ud, osg::Group* parent)
|
|||||||
std::vector<SGPropertyNode_ptr> actions;
|
std::vector<SGPropertyNode_ptr> actions;
|
||||||
actions = getConfig()->getChildren("action");
|
actions = getConfig()->getChildren("action");
|
||||||
for (unsigned int i = 0; i < actions.size(); ++i) {
|
for (unsigned int i = 0; i < actions.size(); ++i) {
|
||||||
pickCb = new PickCallback(actions[i], getModelRoot());
|
pickCb = new PickCallback(actions[i], getModelRoot(), _condition);
|
||||||
ud->addPickCallback(pickCb);
|
ud->addPickCallback(pickCb);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -459,7 +483,7 @@ SGPickAnimation::setupCallbacks(SGSceneUserData* ud, osg::Group* parent)
|
|||||||
if (!pickCb) {
|
if (!pickCb) {
|
||||||
// make a trivial PickCallback to hang the hovered off of
|
// make a trivial PickCallback to hang the hovered off of
|
||||||
SGPropertyNode_ptr dummyNode(new SGPropertyNode);
|
SGPropertyNode_ptr dummyNode(new SGPropertyNode);
|
||||||
pickCb = new PickCallback(dummyNode.ptr(), getModelRoot());
|
pickCb = new PickCallback(dummyNode.ptr(), getModelRoot(), _condition);
|
||||||
ud->addPickCallback(pickCb);
|
ud->addPickCallback(pickCb);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -469,7 +493,7 @@ SGPickAnimation::setupCallbacks(SGSceneUserData* ud, osg::Group* parent)
|
|||||||
// Look for the VNC sessions that want raw mouse input
|
// Look for the VNC sessions that want raw mouse input
|
||||||
actions = getConfig()->getChildren("vncaction");
|
actions = getConfig()->getChildren("vncaction");
|
||||||
for (unsigned int i = 0; i < actions.size(); ++i) {
|
for (unsigned int i = 0; i < actions.size(); ++i) {
|
||||||
ud->addPickCallback(new VncCallback(actions[i], getModelRoot(), parent));
|
ud->addPickCallback(new VncCallback(actions[i], getModelRoot(), parent, _condition));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,8 @@ protected:
|
|||||||
|
|
||||||
|
|
||||||
virtual osg::Group* createMainGroup(osg::Group* pr);
|
virtual osg::Group* createMainGroup(osg::Group* pr);
|
||||||
|
SGSharedPtr<SGCondition const> _condition;
|
||||||
|
|
||||||
virtual void setupCallbacks(SGSceneUserData* ud, osg::Group* parent);
|
virtual void setupCallbacks(SGSceneUserData* ud, osg::Group* parent);
|
||||||
private:
|
private:
|
||||||
class PickCallback;
|
class PickCallback;
|
||||||
|
|||||||
Reference in New Issue
Block a user