H3D API  2.4.1
MouseSensor.h
Go to the documentation of this file.
1 // Copyright 2004-2019, SenseGraphics AB
3 //
4 // This file is part of H3D API.
5 //
6 // H3D API is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // H3D API is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with H3D API; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 //
20 // A commercial license is also available. Please contact us at
21 // www.sensegraphics.com for more information.
22 //
23 //
27 //
29 #ifndef __MOUSESENSOR_H__
30 #define __MOUSESENSOR_H__
31 
32 
33 #include <H3D/X3DSensorNode.h>
34 #include <list>
35 #include <H3D/SFVec2f.h>
36 
37 
38 namespace H3D {
39 
47  class H3DAPI_API MouseSensor : public X3DSensorNode {
48  public:
49 
50  typedef enum {
51  LEFT_BUTTON = 1, // The left mouse button;
52  MIDDLE_BUTTON = 2, // The middle mouse button;
53  RIGHT_BUTTON = 3, // The right mouse button;
54  DOWN = 4, // The button is pressed
55  UP = 5, // The button is released
56  FROM = 6, // The wheel is scrolled from the user
57  TOWARDS = 7 // The wheel is scrolled towards the user
58  } MouseKeys;
59 
61  MouseSensor( Inst< SFBool > _enabled = 0,
62  Inst< SFNode > _metadata = 0,
63  Inst< SFBool > _isActive = 0,
64  Inst< SFVec2f > _position = 0,
65  Inst< SFBool > _leftButton = 0,
66  Inst< SFBool > _middleButton = 0,
67  Inst< SFBool > _rightButton = 0,
68  Inst< SFVec2f > _motion = 0,
69  Inst< SFBool > _scrollUp = 0,
70  Inst< SFBool > _scrollDown = 0
71  );
72 
74  virtual ~MouseSensor();
75 
78  virtual void mouseMotionAction( int x, int y );
79 
85  virtual void mouseButtonAction( int button, int state );
86 
89  virtual void mouseWheelAction( int direction );
90 
93  static void buttonCallback( int button, int state );
94 
97  static void motionCallback( int x, int y );
98 
100  static void wheelCallback( int direction );
101 
105  H3DUniquePtr< SFVec2f> position;
106 
110  H3DUniquePtr< SFBool> leftButton;
111 
115  H3DUniquePtr< SFBool> middleButton;
116 
120  H3DUniquePtr< SFBool> rightButton;
121 
125  H3DUniquePtr< SFVec2f> motion;
126 
131  H3DUniquePtr< SFBool > scrollUp;
132 
137  H3DUniquePtr< SFBool > scrollDown;
138 
141 
142  private:
143  static list< MouseSensor * > instances;
144  static bool invalid_instance_ptr;
145  };
146 }
147 
148 #endif
Contains the SFVec2f field class.
Header file for X3DSensorNode, X3D scene-graph node.
A sensor node for reading mouse values.
Definition: MouseSensor.h:47
H3DUniquePtr< SFBool > scrollUp
The scrollUp field generates a TRUE event when the mouse scroll wheel is moved up.
Definition: MouseSensor.h:131
static H3DNodeDatabase database
The H3DNodeDatabase for this node.
Definition: MouseSensor.h:140
H3DUniquePtr< SFBool > leftButton
The status of the left button.
Definition: MouseSensor.h:110
H3DUniquePtr< SFBool > scrollDown
The scrollDown field generates a TRUE event when the mouse scroll wheel is moved down.
Definition: MouseSensor.h:137
H3DUniquePtr< SFVec2f > position
The position of the mouse in window relative coordinates.
Definition: MouseSensor.h:105
H3DUniquePtr< SFBool > rightButton
The status of the right button.
Definition: MouseSensor.h:120
H3DUniquePtr< SFBool > middleButton
The status of the middle button.
Definition: MouseSensor.h:115
H3DUniquePtr< SFVec2f > motion
The relative motion since in the last change of the position field.
Definition: MouseSensor.h:125
This abstract node type is the base type for all sensors.
Definition: X3DSensorNode.h:40
H3DDouble x
H3D API namespace.
Definition: Anchor.h:38
The H3DNodeDatabase contains a mapping between a name of a Node and the constructor for the Node with...
Definition: H3DNodeDatabase.h:194