From Stephan Hunber, "attached you’ll find some changes to osg/p3d:
* a new command-line-option to present3d and a new option to the p3d-plugin to suppress any found <env> tags * a new command-line-option to present3d to forward mouse-events via osgGA::Device (defaults to off) so we can test the interface-files with present3d better * I added a new attribute forward_to_devices for click_to_event to forward the event to all attached devices instead of handling the event locally. This will fix the annoyance with the new interface-files when toggling polygon-mode or switching light on/off. Here’s an example: <click_to_event forward_to_devices="true">0x72</click_to_event> "
This commit is contained in:
parent
02120e188e
commit
f16f278fea
@ -133,17 +133,44 @@ void setViewer(osgViewer::Viewer& viewer, float width, float height, float dista
|
||||
|
||||
class ForwardToDeviceEventHandler : public osgGA::GUIEventHandler {
|
||||
public:
|
||||
ForwardToDeviceEventHandler(osgGA::Device* device) : osgGA::GUIEventHandler(), _device(device) {}
|
||||
ForwardToDeviceEventHandler(osgGA::Device* device, bool format_mouse_events) : osgGA::GUIEventHandler(), _device(device), _forwardMouseEvents(format_mouse_events) {}
|
||||
|
||||
virtual bool handle (const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa, osg::Object *, osg::NodeVisitor *)
|
||||
{
|
||||
OSG_INFO<<"ForwardToDeviceEventHandler::setEvent("<<ea.getKey()<<")"<<std::endl;
|
||||
_device->sendEvent(ea);
|
||||
switch (ea.getEventType())
|
||||
{
|
||||
case osgGA::GUIEventAdapter::PUSH:
|
||||
case osgGA::GUIEventAdapter::RELEASE:
|
||||
case osgGA::GUIEventAdapter::MOVE:
|
||||
case osgGA::GUIEventAdapter::DRAG:
|
||||
case osgGA::GUIEventAdapter::SCROLL:
|
||||
if (_forwardMouseEvents)
|
||||
_device->sendEvent(ea);
|
||||
break;
|
||||
|
||||
default:
|
||||
_device->sendEvent(ea);
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool handle(osgGA::Event* event, osg::Object* object, osg::NodeVisitor* nv)
|
||||
{
|
||||
if (event->asGUIEventAdapter())
|
||||
return osgGA::GUIEventHandler::handle(event, object, nv);
|
||||
else
|
||||
{
|
||||
_device->sendEvent(*event);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
osg::ref_ptr<osgGA::Device> _device;
|
||||
bool _forwardMouseEvents;
|
||||
};
|
||||
|
||||
|
||||
@ -183,7 +210,7 @@ void processLoadedModel(osg::ref_ptr<osg::Node>& loadedModel, int optimizer_opti
|
||||
}
|
||||
}
|
||||
|
||||
void addDeviceTo(osgViewer::Viewer& viewer, const std::string& device_name)
|
||||
void addDeviceTo(osgViewer::Viewer& viewer, const std::string& device_name, bool forward_mouse_events)
|
||||
{
|
||||
osg::ref_ptr<osgGA::Device> dev = osgDB::readFile<osgGA::Device>(device_name);
|
||||
if (dev.valid())
|
||||
@ -191,8 +218,8 @@ void addDeviceTo(osgViewer::Viewer& viewer, const std::string& device_name)
|
||||
OSG_INFO << "Adding Device : " << device_name << std::endl;
|
||||
viewer.addDevice(dev.get());
|
||||
|
||||
if (dev->getCapabilities() & osgGA::Device::SEND_EVENTS)
|
||||
viewer.getEventHandlers().push_front(new ForwardToDeviceEventHandler(dev.get()));
|
||||
if ((dev->getCapabilities() & osgGA::Device::SEND_EVENTS))
|
||||
viewer.getEventHandlers().push_front(new ForwardToDeviceEventHandler(dev.get(), forward_mouse_events));
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -226,6 +253,8 @@ int main( int argc, char **argv )
|
||||
arguments.getApplicationUsage()->addCommandLineOption("--html <filename>","Print out slides to a series of html & image files.");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("--loop","Switch on looping of presentation.");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("--devices","Print the Video input capability via QuickTime and exit.");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("--forwardMouseEvents","forward also mouse/touch-events to the devices");
|
||||
arguments.getApplicationUsage()->addCommandLineOption("--suppressEnvTags", "suppresses all found ENV-tags in the presentation");
|
||||
|
||||
// add alias from xml to p3d to provide backwards compatibility for old p3d files.
|
||||
osgDB::Registry::instance()->addFileExtensionAlias("xml","p3d");
|
||||
@ -238,10 +267,13 @@ int main( int argc, char **argv )
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool suppress_env_tags = false;
|
||||
if (arguments.read("--suppressEnvTags"))
|
||||
suppress_env_tags = true;
|
||||
|
||||
// read any env vars from presentations before we create viewer to make sure the viewer
|
||||
// utilises these env vars
|
||||
if (p3d::readEnvVars(arguments))
|
||||
if (!suppress_env_tags && p3d::readEnvVars(arguments))
|
||||
{
|
||||
osg::DisplaySettings::instance()->readEnvironmentalVariables();
|
||||
}
|
||||
@ -328,6 +360,10 @@ int main( int argc, char **argv )
|
||||
viewer.readConfiguration(configurationFile);
|
||||
doSetViewer = false;
|
||||
}
|
||||
|
||||
bool forwardMouseEvents = false;
|
||||
if (arguments.read("--forwardMouseEvents"))
|
||||
forwardMouseEvents = true;
|
||||
|
||||
const char* p3dDevice = getenv("P3D_DEVICE");
|
||||
if (p3dDevice)
|
||||
@ -336,7 +372,7 @@ int main( int argc, char **argv )
|
||||
osgDB::split(p3dDevice, devices);
|
||||
for(osgDB::StringList::iterator i = devices.begin(); i != devices.end(); ++i)
|
||||
{
|
||||
addDeviceTo(viewer, *i);
|
||||
addDeviceTo(viewer, *i, forwardMouseEvents);
|
||||
}
|
||||
}
|
||||
|
||||
@ -344,7 +380,7 @@ int main( int argc, char **argv )
|
||||
std::string device;
|
||||
while (arguments.read("--device", device))
|
||||
{
|
||||
addDeviceTo(viewer, device);
|
||||
addDeviceTo(viewer, device, forwardMouseEvents);
|
||||
|
||||
}
|
||||
|
||||
@ -658,6 +694,9 @@ int main( int argc, char **argv )
|
||||
|
||||
|
||||
osg::ref_ptr<osgDB::ReaderWriter::Options> cacheAllOption = new osgDB::ReaderWriter::Options;
|
||||
if(suppress_env_tags)
|
||||
cacheAllOption->setPluginStringData("suppressEnvTags", "true");
|
||||
|
||||
cacheAllOption->setObjectCacheHint(osgDB::ReaderWriter::Options::CACHE_ALL);
|
||||
osgDB::Registry::instance()->setOptions(cacheAllOption.get());
|
||||
|
||||
|
@ -110,22 +110,25 @@ struct HomePosition : public virtual osg::Referenced
|
||||
|
||||
struct KeyPosition
|
||||
{
|
||||
KeyPosition(unsigned int key=0, float x=FLT_MAX, float y=FLT_MAX):
|
||||
KeyPosition(unsigned int key=0, float x=FLT_MAX, float y=FLT_MAX, bool forward_to_devices = false):
|
||||
_key((osgGA::GUIEventAdapter::KeySymbol)key),
|
||||
_x(x),
|
||||
_y(y) {}
|
||||
_y(y),
|
||||
_forwardToDevices(forward_to_devices) {}
|
||||
|
||||
|
||||
void set(unsigned int key=0, float x=FLT_MAX, float y=FLT_MAX)
|
||||
void set(unsigned int key=0, float x=FLT_MAX, float y=FLT_MAX, bool forward_to_devices = false)
|
||||
{
|
||||
_key = (osgGA::GUIEventAdapter::KeySymbol)key;
|
||||
_x = x;
|
||||
_y = y;
|
||||
_forwardToDevices = forward_to_devices;
|
||||
}
|
||||
|
||||
osgGA::GUIEventAdapter::KeySymbol _key;
|
||||
float _x;
|
||||
float _y;
|
||||
bool _forwardToDevices;
|
||||
};
|
||||
|
||||
struct LayerCallback : public virtual osg::Referenced
|
||||
@ -313,6 +316,7 @@ public:
|
||||
bool getLoopPresentation() const { return _loopPresentation; }
|
||||
|
||||
void dispatchEvent(const KeyPosition& keyPosition);
|
||||
void forwardEventToDevices(osgGA::Event* event);
|
||||
|
||||
void setRequestReload(bool flag);
|
||||
bool getRequestReload() const { return _requestReload; }
|
||||
|
@ -41,6 +41,8 @@ class ReaderWriterP3DXML : public osgDB::ReaderWriter
|
||||
public:
|
||||
ReaderWriterP3DXML()
|
||||
{
|
||||
supportsOption("suppressEnvTags", "if set to (true|1) all env-tags in the p3d-file will be suppressed");
|
||||
|
||||
_colorMap["WHITE"] .set(1.0f,1.0f,1.0f,1.0f);
|
||||
_colorMap["BLACK"] .set(0.0f,0.0f,0.0f,1.0f);
|
||||
_colorMap["PURPLE"] .set(1.0f,0.0f,1.0f,1.0f);
|
||||
@ -112,6 +114,7 @@ public:
|
||||
return osgDB::equalCaseInsensitive(extension,"p3d") ||
|
||||
osgDB::equalCaseInsensitive(extension,"xml") ;
|
||||
}
|
||||
|
||||
|
||||
virtual ReadResult readNode(const std::string& fileName,
|
||||
const osgDB::ReaderWriter::Options* options) const;
|
||||
@ -175,7 +178,8 @@ public:
|
||||
inline bool read(const char* str, osg::Vec2& value) const;
|
||||
inline bool read(const char* str, osg::Vec3& value) const;
|
||||
inline bool read(const char* str, osg::Vec4& value) const;
|
||||
|
||||
|
||||
inline bool read(const std::string& str, bool& value) const;
|
||||
inline bool read(const std::string& str, int& value) const;
|
||||
inline bool read(const std::string& str, float& value) const;
|
||||
inline bool read(const std::string& str, double& value) const;
|
||||
@ -186,6 +190,7 @@ public:
|
||||
|
||||
bool getProperty(osgDB::XmlNode*cur, const char* token) const;
|
||||
bool getKeyProperty(osgDB::XmlNode*cur, const char* token, int& value) const;
|
||||
bool getProperty(osgDB::XmlNode*cur, const char* token, bool& value) const;
|
||||
bool getProperty(osgDB::XmlNode*cur, const char* token, int& value) const;
|
||||
bool getProperty(osgDB::XmlNode*cur, const char* token, float& value) const;
|
||||
bool getProperty(osgDB::XmlNode*cur, const char* token, double& value) const;
|
||||
@ -324,6 +329,17 @@ bool ReaderWriterP3DXML::read(const char* str, osg::Vec4& value) const
|
||||
return !iss.fail();
|
||||
}
|
||||
|
||||
bool ReaderWriterP3DXML::read(const std::string& str, bool& value) const
|
||||
{
|
||||
if ((str == "1") || (str == "0")) {
|
||||
value = (str == "1");
|
||||
return true;
|
||||
}
|
||||
std::string s(osgDB::convertToLowerCase(str));
|
||||
value = (s == "true");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ReaderWriterP3DXML::read(const std::string& str, int& value) const
|
||||
{
|
||||
std::istringstream iss(str);
|
||||
@ -383,6 +399,13 @@ bool ReaderWriterP3DXML::getProperty(osgDB::XmlNode* cur, const char* token) con
|
||||
return cur->properties.count(token)!=0;
|
||||
}
|
||||
|
||||
bool ReaderWriterP3DXML::getProperty(osgDB::XmlNode*cur, const char* token, bool& value) const
|
||||
{
|
||||
osgDB::XmlNode::Properties::iterator itr = cur->properties.find(token);
|
||||
if (itr==cur->properties.end()) return false;
|
||||
return read(itr->second,value);
|
||||
}
|
||||
|
||||
bool ReaderWriterP3DXML::getProperty(osgDB::XmlNode*cur, const char* token, int& value) const
|
||||
{
|
||||
osgDB::XmlNode::Properties::iterator itr = cur->properties.find(token);
|
||||
@ -1426,7 +1449,7 @@ bool ReaderWriterP3DXML::getKeyPosition(osgDB::XmlNode*cur, osgPresentation::Key
|
||||
cur->name == "esc" ||
|
||||
cur->name == "exit")
|
||||
{
|
||||
keyPosition.set(osgGA::GUIEventAdapter::KEY_Escape, 0.0f, 0.0f);
|
||||
keyPosition.set(osgGA::GUIEventAdapter::KEY_Escape, 0.0f, 0.0f, false);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -1455,7 +1478,9 @@ bool ReaderWriterP3DXML::getKeyPositionInner(osgDB::XmlNode*cur, osgPresentation
|
||||
// v in range 0.0 to 1, from bottom to top
|
||||
y = v*2.0f-1.0f;
|
||||
}
|
||||
|
||||
|
||||
bool forward_to_devices = false;
|
||||
getProperty(cur, "forward_to_devices", forward_to_devices);
|
||||
|
||||
std::string key = cur->getTrimmedContents();
|
||||
unsigned int keyValue = 0;
|
||||
@ -1494,7 +1519,7 @@ bool ReaderWriterP3DXML::getKeyPositionInner(osgDB::XmlNode*cur, osgPresentation
|
||||
return false;
|
||||
}
|
||||
|
||||
keyPosition.set(keyValue,x,y);
|
||||
keyPosition.set(keyValue,x,y, forward_to_devices);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -2855,13 +2880,15 @@ osg::Node* ReaderWriterP3DXML::parseXmlGraph(osgDB::XmlNode* root, bool readOnly
|
||||
|
||||
osgDB::FilePathList previousPaths = osgDB::getDataFilePathList();
|
||||
|
||||
bool env_tag_suppressed = false || (options && ((options->getPluginStringData("suppressEnvTags") == "1") || (options->getPluginStringData("suppressEnvTags") == "true")));
|
||||
|
||||
for(osgDB::XmlNode::Children::iterator itr = root->children.begin();
|
||||
itr != root->children.end();
|
||||
++itr)
|
||||
{
|
||||
osgDB::XmlNode* cur = itr->get();
|
||||
|
||||
if (cur->name=="env")
|
||||
if (cur->name=="env" && !env_tag_suppressed)
|
||||
{
|
||||
char* str = strdup(cur->contents.c_str());
|
||||
OSG_INFO<<"putenv("<<str<<")"<<std::endl;
|
||||
|
@ -87,16 +87,7 @@ bool PickEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionA
|
||||
|
||||
// std::cout << transformed_x << "/" << transformed_x << " -> " << cloned_ea->getX() << "/" <<cloned_ea->getY() << std::endl;
|
||||
|
||||
|
||||
// dispatch cloned event to devices
|
||||
osgViewer::View::Devices& devices = viewer->getDevices();
|
||||
for(osgViewer::View::Devices::iterator i = devices.begin(); i != devices.end(); ++i)
|
||||
{
|
||||
if((*i)->getCapabilities() & osgGA::Device::SEND_EVENTS)
|
||||
{
|
||||
(*i)->sendEvent(*cloned_ea);
|
||||
}
|
||||
}
|
||||
SlideEventHandler::instance()->forwardEventToDevices(cloned_ea);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1550,8 +1550,39 @@ void SlideEventHandler::releaseSlide(unsigned int slideNum)
|
||||
_presentationSwitch->getChild(slideNum)->accept(globjVisitor);
|
||||
}
|
||||
|
||||
void SlideEventHandler::forwardEventToDevices(osgGA::Event* event)
|
||||
{
|
||||
// dispatch cloned event to devices
|
||||
osgViewer::View::Devices& devices = _viewer->getDevices();
|
||||
for(osgViewer::View::Devices::iterator i = devices.begin(); i != devices.end(); ++i)
|
||||
{
|
||||
if((*i)->getCapabilities() & osgGA::Device::SEND_EVENTS)
|
||||
{
|
||||
(*i)->sendEvent(*event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SlideEventHandler::dispatchEvent(const KeyPosition& keyPosition)
|
||||
{
|
||||
if (keyPosition._forwardToDevices)
|
||||
{
|
||||
osg::ref_ptr<osgGA::GUIEventAdapter> event = new osgGA::GUIEventAdapter();
|
||||
event->setKey(keyPosition._key);
|
||||
event->setTime(_viewer->getEventQueue()->getTime());
|
||||
|
||||
// forward key-down
|
||||
event->setEventType(osgGA::GUIEventAdapter::KEYDOWN);
|
||||
forwardEventToDevices(event);
|
||||
|
||||
// forward key-up
|
||||
event->setEventType(osgGA::GUIEventAdapter::KEYUP);
|
||||
forwardEventToDevices(event);
|
||||
|
||||
// ignore local event-queue
|
||||
return;
|
||||
}
|
||||
|
||||
osgGA::EventQueue* eq = _viewer->getEventQueue();
|
||||
|
||||
// reset the time of the last key press to ensure that the event is disgarded as a key repeat.
|
||||
|
Loading…
Reference in New Issue
Block a user