From: Thomas Geymayer Date: Thu, 7 Aug 2014 22:58:26 +0000 (+0200) Subject: Add simple keyboard event demo application. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=519326f7518b6e8760a53db6ebebd692655ef7be;p=simgear.git Add simple keyboard event demo application. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index a98c937c..336e54c4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -181,7 +181,7 @@ else() message(STATUS "Sound support: ENABLED") endif(ENABLE_SOUND) - find_package(OpenSceneGraph 3.2.0 REQUIRED osgText osgSim osgDB osgParticle osgGA osgUtil) + find_package(OpenSceneGraph 3.2.0 REQUIRED osgText osgSim osgDB osgParticle osgGA osgViewer osgUtil) endif(SIMGEAR_HEADLESS) find_package(ZLIB REQUIRED) diff --git a/simgear/canvas/events/CMakeLists.txt b/simgear/canvas/events/CMakeLists.txt index 8168ea5c..63508055 100644 --- a/simgear/canvas/events/CMakeLists.txt +++ b/simgear/canvas/events/CMakeLists.txt @@ -19,4 +19,10 @@ simgear_scene_component(canvas-events canvas/events "${SOURCES}" "${HEADERS}") add_boost_test(canvas_event SOURCES event_test.cpp LIBRARIES ${TEST_LIBS} +) + +add_executable(input_event_demo input_event_demo.cxx) +target_link_libraries(input_event_demo + ${TEST_LIBS} + ${OPENSCENEGRAPH_LIBRARIES} ) \ No newline at end of file diff --git a/simgear/canvas/events/input_event_demo.cxx b/simgear/canvas/events/input_event_demo.cxx new file mode 100644 index 00000000..0e7e4f31 --- /dev/null +++ b/simgear/canvas/events/input_event_demo.cxx @@ -0,0 +1,76 @@ +// Keyboard event demo. Press some keys and get some info... +// +// Copyright (C) 2014 Thomas Geymayer +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Library General Public +// License as published by the Free Software Foundation; either +// version 2 of the License, or (at your option) any later version. +// +// 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 GNU +// Library General Public License for more details. +// +// You should have received a copy of the GNU Library General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + +#include "KeyboardEvent.hxx" + +#include +#include + +class DemoEventHandler: + public osgGA::GUIEventHandler +{ + public: + bool handle( const osgGA::GUIEventAdapter& ea, + osgGA::GUIActionAdapter&, + osg::Object*, + osg::NodeVisitor* ) + { + switch( ea.getEventType() ) + { + case osgGA::GUIEventAdapter::PUSH: + case osgGA::GUIEventAdapter::RELEASE: + case osgGA::GUIEventAdapter::DRAG: + case osgGA::GUIEventAdapter::MOVE: + case osgGA::GUIEventAdapter::SCROLL: + return handleMouse(ea); + case osgGA::GUIEventAdapter::KEYDOWN: + case osgGA::GUIEventAdapter::KEYUP: + return handleKeyboard(ea); + default: + return false; + } + } + + protected: + bool handleMouse(const osgGA::GUIEventAdapter&) + { + return false; + } + + bool handleKeyboard(const osgGA::GUIEventAdapter& ea) + { + simgear::canvas::KeyboardEvent evt(ea); + std::cout << evt.getTypeString() << " '" << evt.key() << "'" + << ", loc=" << evt.location() + << ", char=" << evt.charCode() + << ", key=" << evt.keyCode() + << std::endl; + return true; + } +}; + +int main() +{ + osgViewer::Viewer viewer; + + osg::ref_ptr handler( new DemoEventHandler ); + viewer.addEventHandler(handler); + + viewer.setUpViewInWindow(100, 100, 200, 100, 0); + return viewer.run(); +}