/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2018 Robert Osfield * * This library is open source and may be redistributed and/or modified under * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or * (at your option) any later version. The full license is in LICENSE file * included with this distribution, and on the openscenegraph.org website. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * OpenSceneGraph Public License for more details. */ #include #include #include #include #include #include #include using namespace osgPresentation; KeyEventHandler::KeyEventHandler(int key, osgPresentation::Operation operation, const JumpData& jumpData): _key(key), _operation(operation), _jumpData(jumpData) { } KeyEventHandler::KeyEventHandler(int key, const std::string& str, osgPresentation::Operation operation, const JumpData& jumpData): _key(key), _command(str), _operation(operation), _jumpData(jumpData) { } KeyEventHandler::KeyEventHandler(int key, const osgPresentation::KeyPosition& keyPos, const JumpData& jumpData): _key(key), _keyPos(keyPos), _operation(osgPresentation::EVENT), _jumpData(jumpData) { } bool KeyEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& /*aa*/, osg::Object*, osg::NodeVisitor* /*nv*/) { if (ea.getHandled()) return false; switch(ea.getEventType()) { case(osgGA::GUIEventAdapter::KEYDOWN): { if (ea.getKey()==_key) { doOperation(); return true; } break; } default: break; } return false; } void KeyEventHandler::getUsage(osg::ApplicationUsage& /*usage*/) const { } void KeyEventHandler::doOperation() { switch(_operation) { case(osgPresentation::RUN): { OSG_NOTICE<<"Run "<<_command<dispatchEvent(_keyPos); break; } case(osgPresentation::JUMP): { OSG_INFO<<"Requires jump "<