Added support for enable/disabling the keystone editing using the Ctrl-g key to toggle the UI and grid on/off.
This commit is contained in:
parent
efbf05cd59
commit
bc288d23dc
@ -32,6 +32,7 @@ class Keystone : public osg::Referenced
|
||||
{
|
||||
public:
|
||||
Keystone():
|
||||
keystoneEditingEnabled(false),
|
||||
bottom_left(-1.0,-1.0),
|
||||
bottom_right(1.0,-1.0),
|
||||
top_left(-1.0,1.0),
|
||||
@ -48,6 +49,7 @@ public:
|
||||
Keystone& operator = (const Keystone& rhs)
|
||||
{
|
||||
if (&rhs==this) return *this;
|
||||
keystoneEditingEnabled = rhs.keystoneEditingEnabled;
|
||||
bottom_left = rhs.bottom_left;
|
||||
bottom_right = rhs.bottom_right;
|
||||
top_left = rhs.top_left;
|
||||
@ -55,6 +57,8 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool keystoneEditingEnabled;
|
||||
|
||||
osg::Vec2d bottom_left;
|
||||
osg::Vec2d bottom_right;
|
||||
osg::Vec2d top_left;
|
||||
@ -93,6 +97,9 @@ public:
|
||||
|
||||
bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa);
|
||||
|
||||
void setKeystoneEditingEnabled(bool enabled) { if (_currentControlPoints.valid()) _currentControlPoints->keystoneEditingEnabled = enabled; }
|
||||
bool getKeystoneEditingEnabled() const { return _currentControlPoints.valid() ? _currentControlPoints->keystoneEditingEnabled : false; }
|
||||
|
||||
enum Region
|
||||
{
|
||||
NONE_SELECTED,
|
||||
@ -224,6 +231,8 @@ bool KeystoneHandler::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionA
|
||||
switch(ea.getEventType())
|
||||
{
|
||||
case(osgGA::GUIEventAdapter::PUSH):
|
||||
{
|
||||
if (getKeystoneEditingEnabled())
|
||||
{
|
||||
osg::Vec2d scale = incrementScale(ea);
|
||||
if (scale.length2()!=0.0)
|
||||
@ -236,9 +245,12 @@ bool KeystoneHandler::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionA
|
||||
{
|
||||
_selectedRegion = NONE_SELECTED;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
case(osgGA::GUIEventAdapter::DRAG):
|
||||
{
|
||||
if (getKeystoneEditingEnabled())
|
||||
{
|
||||
if (_selectedRegion!=NONE_SELECTED)
|
||||
{
|
||||
@ -249,17 +261,26 @@ bool KeystoneHandler::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionA
|
||||
move(_selectedRegion, osg::Vec2d(delta.x()*scale.x(), delta.y()*scale.y()) );
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
case(osgGA::GUIEventAdapter::RELEASE):
|
||||
{
|
||||
if (getKeystoneEditingEnabled())
|
||||
{
|
||||
_selectedRegion = NONE_SELECTED;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
case(osgGA::GUIEventAdapter::KEYDOWN):
|
||||
{
|
||||
if (ea.getKey()=='r')
|
||||
if (getKeystoneEditingEnabled())
|
||||
{
|
||||
if (ea.getUnmodifiedKey()=='g' && (ea.getModKeyMask()==osgGA::GUIEventAdapter::MODKEY_LEFT_CTRL || ea.getModKeyMask()==osgGA::GUIEventAdapter::MODKEY_RIGHT_CTRL))
|
||||
{
|
||||
setKeystoneEditingEnabled(false);
|
||||
}
|
||||
else if (ea.getKey()=='r')
|
||||
{
|
||||
_selectedRegion = NONE_SELECTED;
|
||||
_startControlPoints->reset();
|
||||
@ -297,9 +318,10 @@ bool KeystoneHandler::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionA
|
||||
{
|
||||
_currentControlPoints->bottom_left.set(ea.getXnormalized(), ea.getYnormalized());
|
||||
}
|
||||
else
|
||||
}
|
||||
else if (ea.getUnmodifiedKey()=='g' && (ea.getModKeyMask()==osgGA::GUIEventAdapter::MODKEY_LEFT_CTRL || ea.getModKeyMask()==osgGA::GUIEventAdapter::MODKEY_RIGHT_CTRL))
|
||||
{
|
||||
OSG_NOTICE<<"key = 0x"<<std::hex<<ea.getKey()<<std::dec<<std::endl;
|
||||
setKeystoneEditingEnabled(true);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -307,6 +329,22 @@ bool KeystoneHandler::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionA
|
||||
return false;
|
||||
}
|
||||
}
|
||||
struct KeystoneCullCallback : public osg::Drawable::CullCallback
|
||||
{
|
||||
KeystoneCullCallback(Keystone* keystone=0):_keystone(keystone) {}
|
||||
KeystoneCullCallback(const KeystoneCullCallback&, const osg::CopyOp&) {}
|
||||
|
||||
META_Object(osg,KeystoneCullCallback);
|
||||
|
||||
/** do customized cull code, return true if drawable should be culled.*/
|
||||
virtual bool cull(osg::NodeVisitor* nv, osg::Drawable* drawable, osg::RenderInfo* renderInfo) const
|
||||
{
|
||||
return _keystone.valid() ? !_keystone->keystoneEditingEnabled : true;
|
||||
}
|
||||
|
||||
osg::ref_ptr<Keystone> _keystone;
|
||||
};
|
||||
|
||||
|
||||
struct KeystoneUpdateCallback : public osg::Drawable::UpdateCallback
|
||||
{
|
||||
@ -429,6 +467,8 @@ osg::Node* createGrid(Keystone* keystone, const osg::Vec4& colour)
|
||||
osg::ref_ptr<KeystoneUpdateCallback> kuc = new KeystoneUpdateCallback(keystone);
|
||||
geometry->setUpdateCallback(kuc.get());
|
||||
|
||||
geometry->setCullCallback(new KeystoneCullCallback(keystone));
|
||||
|
||||
osg::ref_ptr<osg::Vec4Array> colours = new osg::Vec4Array;
|
||||
colours->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f));
|
||||
geometry->setColorArray(colours.get());
|
||||
|
Loading…
Reference in New Issue
Block a user