]> git.mxchange.org Git - simgear.git/commitdiff
Add simple keyboard event demo application.
authorThomas Geymayer <tomgey@gmail.com>
Thu, 7 Aug 2014 22:58:26 +0000 (00:58 +0200)
committerThomas Geymayer <tomgey@gmail.com>
Thu, 7 Aug 2014 22:59:06 +0000 (00:59 +0200)
CMakeLists.txt
simgear/canvas/events/CMakeLists.txt
simgear/canvas/events/input_event_demo.cxx [new file with mode: 0644]

index a98c937c340dcbed084d570dabac388971b11821..336e54c47398976e2da5627a4416d2d3d9c759a4 100644 (file)
@@ -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)
index 8168ea5c97bbf1602258caa8907db4997d663ad5..63508055a9ccdce1827dab001a569dc5bc668476 100644 (file)
@@ -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 (file)
index 0000000..0e7e4f3
--- /dev/null
@@ -0,0 +1,76 @@
+// Keyboard event demo. Press some keys and get some info...
+//
+// Copyright (C) 2014  Thomas Geymayer <tomgey@gmail.com>
+//
+// 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 <osgViewer/Viewer>
+#include <iostream>
+
+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<DemoEventHandler> handler( new DemoEventHandler );
+  viewer.addEventHandler(handler);
+
+  viewer.setUpViewInWindow(100, 100, 200, 100, 0);
+  return viewer.run();
+}