Foundations of hover support in pick-callbacks.
This commit is contained in:
parent
adb7db9229
commit
d9b01ca5de
@ -40,6 +40,15 @@ using namespace simgear;
|
|||||||
using OpenThreads::Mutex;
|
using OpenThreads::Mutex;
|
||||||
using OpenThreads::ScopedLock;
|
using OpenThreads::ScopedLock;
|
||||||
|
|
||||||
|
static void readOptionalBindingList(const SGPropertyNode* aNode, SGPropertyNode* modelRoot,
|
||||||
|
const std::string& aName, SGBindingList& aBindings)
|
||||||
|
{
|
||||||
|
const SGPropertyNode* n = aNode->getChild(aName);
|
||||||
|
if (n)
|
||||||
|
aBindings = readBindingList(n->getChildren("binding"), modelRoot);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
class SGPickAnimation::PickCallback : public SGPickCallback {
|
class SGPickAnimation::PickCallback : public SGPickCallback {
|
||||||
public:
|
public:
|
||||||
PickCallback(const SGPropertyNode* configNode,
|
PickCallback(const SGPropertyNode* configNode,
|
||||||
@ -47,37 +56,23 @@ using OpenThreads::ScopedLock;
|
|||||||
_repeatable(configNode->getBoolValue("repeatable", false)),
|
_repeatable(configNode->getBoolValue("repeatable", false)),
|
||||||
_repeatInterval(configNode->getDoubleValue("interval-sec", 0.1))
|
_repeatInterval(configNode->getDoubleValue("interval-sec", 0.1))
|
||||||
{
|
{
|
||||||
SG_LOG(SG_INPUT, SG_DEBUG, "Reading all bindings");
|
|
||||||
std::vector<SGPropertyNode_ptr> bindings;
|
std::vector<SGPropertyNode_ptr> bindings;
|
||||||
|
|
||||||
bindings = configNode->getChildren("button");
|
bindings = configNode->getChildren("button");
|
||||||
for (unsigned int i = 0; i < bindings.size(); ++i) {
|
for (unsigned int i = 0; i < bindings.size(); ++i) {
|
||||||
_buttons.push_back( bindings[i]->getIntValue() );
|
_buttons.insert( bindings[i]->getIntValue() );
|
||||||
}
|
|
||||||
bindings = configNode->getChildren("binding");
|
|
||||||
for (unsigned int i = 0; i < bindings.size(); ++i) {
|
|
||||||
_bindingsDown.push_back(new SGBinding(bindings[i], modelRoot));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const SGPropertyNode* upNode = configNode->getChild("mod-up");
|
_bindingsDown = readBindingList(configNode->getChildren("binding"), modelRoot);
|
||||||
if (!upNode)
|
readOptionalBindingList(configNode, modelRoot, "mod-up", _bindingsUp);
|
||||||
return;
|
readOptionalBindingList(configNode, modelRoot, "hovered", _hover);
|
||||||
bindings = upNode->getChildren("binding");
|
|
||||||
for (unsigned int i = 0; i < bindings.size(); ++i) {
|
|
||||||
_bindingsUp.push_back(new SGBinding(bindings[i], modelRoot));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool buttonPressed(int button, const osgGA::GUIEventAdapter* ea, const Info&)
|
virtual bool buttonPressed(int button, const osgGA::GUIEventAdapter* ea, const Info&)
|
||||||
{
|
{
|
||||||
bool found = false;
|
if (_buttons.find(button) == _buttons.end()) {
|
||||||
for( std::vector<int>::iterator it = _buttons.begin(); it != _buttons.end(); ++it ) {
|
return false;
|
||||||
if( *it == button ) {
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (!found )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
fireBindingList(_bindingsDown);
|
fireBindingList(_bindingsDown);
|
||||||
_repeatTime = -_repeatInterval; // anti-bobble: delay start of repeat
|
_repeatTime = -_repeatInterval; // anti-bobble: delay start of repeat
|
||||||
@ -98,10 +93,22 @@ using OpenThreads::ScopedLock;
|
|||||||
fireBindingList(_bindingsDown);
|
fireBindingList(_bindingsDown);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual bool hover(const osg::Vec2d& windowPos, const Info& info)
|
||||||
|
{
|
||||||
|
if (_hover.empty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME - make x,y available to the binding
|
||||||
|
fireBindingList(_hover);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
private:
|
private:
|
||||||
SGBindingList _bindingsDown;
|
SGBindingList _bindingsDown;
|
||||||
SGBindingList _bindingsUp;
|
SGBindingList _bindingsUp;
|
||||||
std::vector<int> _buttons;
|
SGBindingList _hover;
|
||||||
|
std::set<int> _buttons;
|
||||||
bool _repeatable;
|
bool _repeatable;
|
||||||
double _repeatInterval;
|
double _repeatInterval;
|
||||||
double _repeatTime;
|
double _repeatTime;
|
||||||
@ -352,15 +359,6 @@ static void repeatBindings(const SGBindingList& a, SGBindingList& out, int count
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void readOptionalBindingList(const SGPropertyNode* aNode, SGPropertyNode* modelRoot,
|
|
||||||
const std::string& aName, SGBindingList& aBindings)
|
|
||||||
{
|
|
||||||
const SGPropertyNode* n = aNode->getChild(aName);
|
|
||||||
if (n)
|
|
||||||
aBindings = readBindingList(n->getChildren("binding"), modelRoot);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool static_knobMouseWheelAlternateDirection = false;
|
static bool static_knobMouseWheelAlternateDirection = false;
|
||||||
|
|
||||||
class SGKnobAnimation::KnobPickCallback : public SGPickCallback {
|
class SGKnobAnimation::KnobPickCallback : public SGPickCallback {
|
||||||
@ -376,6 +374,7 @@ public:
|
|||||||
readOptionalBindingList(configNode, modelRoot, "ccw", _bindingsCCW);
|
readOptionalBindingList(configNode, modelRoot, "ccw", _bindingsCCW);
|
||||||
|
|
||||||
readOptionalBindingList(configNode, modelRoot, "release", _releaseAction);
|
readOptionalBindingList(configNode, modelRoot, "release", _releaseAction);
|
||||||
|
readOptionalBindingList(configNode, modelRoot, "hovered", _hover);
|
||||||
|
|
||||||
if (configNode->hasChild("shift-action") || configNode->hasChild("shift-cw") ||
|
if (configNode->hasChild("shift-action") || configNode->hasChild("shift-cw") ||
|
||||||
configNode->hasChild("shift-ccw"))
|
configNode->hasChild("shift-ccw"))
|
||||||
@ -433,6 +432,17 @@ public:
|
|||||||
fire(_stickyShifted);
|
fire(_stickyShifted);
|
||||||
} // of repeat iteration
|
} // of repeat iteration
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual bool hover(const osg::Vec2d& windowPos, const Info& info)
|
||||||
|
{
|
||||||
|
if (_hover.empty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME - make x,y available to the binding
|
||||||
|
fireBindingList(_hover);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
private:
|
private:
|
||||||
void fire(bool isShifted)
|
void fire(bool isShifted)
|
||||||
{
|
{
|
||||||
@ -457,6 +467,7 @@ private:
|
|||||||
SGBindingList _releaseAction;
|
SGBindingList _releaseAction;
|
||||||
SGBindingList _bindingsCW, _shiftedCW,
|
SGBindingList _bindingsCW, _shiftedCW,
|
||||||
_bindingsCCW, _shiftedCCW;
|
_bindingsCCW, _shiftedCCW;
|
||||||
|
SGBindingList _hover;
|
||||||
|
|
||||||
enum Direction
|
enum Direction
|
||||||
{
|
{
|
||||||
|
@ -50,11 +50,15 @@ public:
|
|||||||
virtual ~SGPickCallback() {}
|
virtual ~SGPickCallback() {}
|
||||||
virtual bool buttonPressed(int button, const osgGA::GUIEventAdapter* event, const Info& info)
|
virtual bool buttonPressed(int button, const osgGA::GUIEventAdapter* event, const Info& info)
|
||||||
{ return false; }
|
{ return false; }
|
||||||
|
|
||||||
virtual void update(double dt)
|
virtual void update(double dt)
|
||||||
{ }
|
{ }
|
||||||
virtual void buttonReleased(void)
|
virtual void buttonReleased(void)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
virtual bool hover(const osg::Vec2d& windowPos, const Info& info)
|
||||||
|
{ return false; }
|
||||||
|
|
||||||
Priority getPriority() const
|
Priority getPriority() const
|
||||||
{ return _priority; }
|
{ return _priority; }
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user