vrecko
virtual reality framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
KeyboardMouse.h
Go to the documentation of this file.
1 /***************************************************************************
2  KeyboardMouse.h - description
3  -------------------
4  begin : April 2004
5  copyright : (C) 2004 by Jan Flasar
6  email : flasar@fi.muni.cz
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU L General Public License as published by*
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef KEYBOARDMOUSE_H
19 #define KEYBOARDMOUSE_H
20 
21 #include <vrecko/IOPins.h>
22 #include <vrecko/Device.h>
23 #include <vrecko/EventDispatcher.h>
24 
25 #include <osgGA/GUIEventHandler>
26 //#include <osgProducer/EventAdapter>
27 #include <osg/Vec2>
28 #include <osg/Timer>
29 
30 
31 using namespace vrecko;
32 
33 namespace vreckoDP_base {
34 
36 class DP_EXPORT KeyboardMouse : public vrecko::Device, public osgGA::GUIEventHandler {
37  public:
38  KeyboardMouse();
39  ~KeyboardMouse();
40 
41  virtual int openDevice(void);
42  int closeDevice(void);
43  int calibrateDevice(void) {return 0;}
44 
45  bool isKeyDown(int keyCode) { return keydown_map[keyCode]; };
46 
47  void update(void);
48 
49  virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&);
50  virtual void accept(osgGA::GUIEventHandlerVisitor& v) { v.visit(*this); };
51 
52  // --- KeyboardMouseCallback functions (V.K.: "callbacks"? Really?)
53  void mouseScroll( osgGA::GUIEventAdapter::ScrollingMotion );
54  void mouseMotion( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa);
55  void passiveMouseMotion( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa, float mx, float my);
56  void buttonPress( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa, float mx, float my, unsigned int mb);
57  void doubleButtonPress( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa, float mx, float my, unsigned int mb);
58  void buttonRelease( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa, float mx, float my, unsigned int mb);
59  void keyPress( int );
60  void keyRelease( int );
61  void specialKeyPress( int );
62  void specialKeyRelease( int );
63  void shutdown() {}
64  bool idle() { return false; }
65 
66  protected:
67  unsigned int mouse_button;
68  osg::Vec2 mouse_position;
69  std::map<int, osg::Timer_t> autorepeat_map;
70 
71  std::map<int, bool> keydown_map;
72  osg::Timer timer;
74 
75  int mouseUpdateCounter; // helper counter, so we can ignore first few frames after start or after switching form another app (and reset the mouse pos appropriately)
76 
78 
79  bool sendMousePosIfReady(); // if a new position data are ready, it will send the event and resets the data
80  bool keyToString(int key, std::string *str);
81 
83  DECLARE_OUTPUT(MousePosition, MessageVec2);
84  DECLARE_OUTPUT(MouseButton, MessageString);
85  DECLARE_OUTPUT(MouseDoubleButton, MessageString);
86  DECLARE_OUTPUT(MouseScroll, MessageString);
87 };
88 
89 }
90 
91 #endif
92