V-ARTContributions
mousecontrol.h
Go to the documentation of this file.
1 
5 #ifndef VART_MOUSECONTROL_H
6 #define VART_MOUSECONTROL_H
7 
8 #include <bitset>
9 
10 namespace VART {
11  class ViewerGlutOGL;
17  class MouseControl {
18  public:
19  // PUBLIC TYPES
22  enum StateID { DOWN, UP };
25  {
26  friend class MouseControl;
27  public:
28  //~ ClickHandler() { }
30  virtual void OnClick() = 0;
31  virtual ~ClickHandler() {};
32  protected:
38 
43  };
48  {
49  friend class MouseControl;
50  public:
51  virtual ~DragHandler() {};
52  virtual void OnDrag() = 0;
53  protected:
63  };
68  {
69  friend class MouseControl;
70  public:
71  virtual ~MotionHandler() {};
72  virtual void OnMotion() = 0;
73  protected:
83  };
84  // PUBLIC METHODS
86  MouseControl();
88  bool LastClickButtonIs(ButtonID btValue) const { return button == btValue; }
90  ButtonID GetLastClickButton() const { return button; }
92  void SetLastClickButton(ButtonID btValue) { button = btValue; }
94  bool ModifierIsActive(ModifierID mdValue) const { return modifiers[mdValue]; }
96  void SetModifierState(ModifierID mdValue, bool state);
98  bool LastClickIsDown() const { return state == DOWN; }
100  StateID GetLastClickState() const { return state; }
102  void SetLastClickState(StateID newState) { state = newState; }
104  int GetClickXPosition() const { return clickX; }
106  void SetClickXPosition(int newValue) { clickX = newValue; }
108  int GetClickYPosition() const { return clickY; }
110  void SetClickYPosition(int newValue) { clickY = newValue; }
112  void SetClickPosition(int newX, int newY) {
113  clickX = newX; clickY = newY; }
115  int GetCurrentX() const { return currentX; }
117  void SetCurrentX(int newValue) { currentX = newValue; }
119  int GetCurrentY() const { return currentY; }
121  void SetCurrentY(int newValue) { currentY = newValue; }
123  void SetCurrentPosititon(int newX, int newY) {
124  currentX = newX; currentY = newY; }
126  int GetReleasedXPosition() const { return releasedX; }
128  void SetReleasedXPosition(int newValue) { releasedX = newValue; }
130  int GetReleasedYPosition() const { return releasedY; }
132  void SetReleasedYPosition(int newValue) { releasedY = newValue; }
134  void SetReleasedPosition(int newX, int newY) {
135  releasedX = newX; releasedY = newY; }
137  void OnClick();
139  void OnDrag() { if (dragHndPtr) dragHndPtr->OnDrag(); }
141  void OnMotion() { if (motionHndPtr) motionHndPtr->OnMotion(); }
143  void SetClickHandler(ClickHandler* handlerPtr);
145  void SetDragHandler(DragHandler* handlerPtr);
147  void SetMotionHandler(MotionHandler* handlerPtr);
149  void SetOwner(ViewerGlutOGL* ownerPtr) { viewerPtr = ownerPtr; }
151  void NewEvent(ButtonID btn, StateID newState);
153  bool AnyButtonIsDown() const { return buttonsState.any(); }
155  bool ButtonIsDown(ButtonID btn) const { return buttonsState[btn]; }
159  int GetYDrag() const { return currentY - clickY; }
163  int GetXDrag() const { return currentX - clickX; }
164  protected:
168  std::bitset<3> modifiers;
170  std::bitset<5> buttonsState;
174  int clickX;
176  int clickY;
178  int currentX;
180  int currentY;
187  private:
188  ClickHandler* clickHndPtr;
189  DragHandler* dragHndPtr;
190  MotionHandler* motionHndPtr;
191  }; // end class declaration
192 } // end namespace
193 
194 #endif
void SetReleasedYPosition(int newValue)
Sets the y postion of last button release.
Definition: mousecontrol.h:132
void SetDragHandler(DragHandler *handlerPtr)
Sets the drag handler.
void SetClickYPosition(int newValue)
Sets the y postion of last click.
Definition: mousecontrol.h:110
int GetCurrentY() const
Returns the current y postion.
Definition: mousecontrol.h:119
StateID state
state of button event (DOWN/UP)
Definition: mousecontrol.h:172
bool LastClickButtonIs(ButtonID btValue) const
Checks if last event is relative to given button.
Definition: mousecontrol.h:88
void SetModifierState(ModifierID mdValue, bool state)
Sets the modifier state on last event.
MouseControl * mouseCtrlPtr
Pointer to mouse controller.
Definition: mousecontrol.h:78
MouseControl()
Creates an unitialized mouse controller.
StateID GetLastClickState() const
Returns the button state of last click.
Definition: mousecontrol.h:100
int GetClickXPosition() const
Returns the x positon of last click.
Definition: mousecontrol.h:104
virtual void OnClick()=0
Called upon activation of MouseHandler::OnClick.
bool ButtonIsDown(ButtonID btn) const
Returns true if given button is down.
Definition: mousecontrol.h:155
void OnMotion()
Activates motion (with no buttons pressed) handler, if any.
Definition: mousecontrol.h:141
MouseControl * mouseCtrlPtr
Pointer to mouse controller.
Definition: mousecontrol.h:31
void SetClickXPosition(int newValue)
Sets the x postion of last click.
Definition: mousecontrol.h:106
V-ART Viewer that uses GLUT/OpenGL.
Definition: viewerglutogl.h:41
std::bitset< 5 > buttonsState
state (down if set) of LEFT, MIDDLE, RIGHT, WHEEL_UP and WHEEL_DOWN buttons
Definition: mousecontrol.h:170
std::bitset< 3 > modifiers
state of modifiers upon last button event
Definition: mousecontrol.h:168
void SetCurrentPosititon(int newX, int newY)
Set the current position.
Definition: mousecontrol.h:123
void SetCurrentY(int newValue)
Sets the current y position.
Definition: mousecontrol.h:121
int GetCurrentX() const
Returns the current x postion.
Definition: mousecontrol.h:115
void SetOwner(ViewerGlutOGL *ownerPtr)
Set the owner viewer.
Definition: mousecontrol.h:149
void SetClickHandler(ClickHandler *handlerPtr)
Sets the click handler.
int GetYDrag() const
Definition: mousecontrol.h:159
void SetLastClickButton(ButtonID btValue)
Sets button relative to last event.
Definition: mousecontrol.h:92
void SetCurrentX(int newValue)
Sets the current x position.
Definition: mousecontrol.h:117
ViewerGlutOGL * viewerPtr
Pointer to the viewer that owns the mouse control.
Definition: mousecontrol.h:186
int currentX
Current mouse X position.
Definition: mousecontrol.h:178
int clickY
Mouse Y position for last button down event.
Definition: mousecontrol.h:176
int GetReleasedXPosition() const
Returns the x positon of last button release.
Definition: mousecontrol.h:126
int GetClickYPosition() const
Returns the y positon of last click.
Definition: mousecontrol.h:108
void OnDrag()
Activates drag (motion with buttons pressed) handler, if any.
Definition: mousecontrol.h:139
ViewerGlutOGL * viewerPtr
Pointer to owner viewer.
Definition: mousecontrol.h:42
void NewEvent(ButtonID btn, StateID newState)
Registers new button event.
void SetReleasedXPosition(int newValue)
Sets the x postion of last button release.
Definition: mousecontrol.h:128
void SetLastClickState(StateID newState)
Set the button state on last click.
Definition: mousecontrol.h:102
Keeps track of mouse events and state.
Definition: mousecontrol.h:17
ViewerGlutOGL * viewerPtr
Pointer to owner viewer.
Definition: mousecontrol.h:82
void OnClick()
Activates click handler, if any.
ViewerGlutOGL * viewerPtr
Pointer to owner viewer.
Definition: mousecontrol.h:62
ButtonID button
which button was last pressed or released
Definition: mousecontrol.h:166
int clickX
Mouse X position for last button down event.
Definition: mousecontrol.h:174
int releasedX
Mouse X position for last button up event.
Definition: mousecontrol.h:182
int currentY
Current mouse Y position.
Definition: mousecontrol.h:180
int releasedY
Mouse Y position for last button up event.
Definition: mousecontrol.h:184
bool LastClickIsDown() const
Checks whether state is DOWN.
Definition: mousecontrol.h:98
void SetMotionHandler(MotionHandler *handlerPtr)
Sets the motion handler.
void SetReleasedPosition(int newX, int newY)
Sets the position of last button release.
Definition: mousecontrol.h:134
ButtonID GetLastClickButton() const
Returns button relative to last event.
Definition: mousecontrol.h:90
MouseControl * mouseCtrlPtr
Pointer to mouse controller.
Definition: mousecontrol.h:58
int GetXDrag() const
Definition: mousecontrol.h:163
bool AnyButtonIsDown() const
Checks whether any of LEFT, MIDDLE, RIGHT buttons are down.
Definition: mousecontrol.h:153
bool ModifierIsActive(ModifierID mdValue) const
Checks if given modifier was active on last event.
Definition: mousecontrol.h:94
int GetReleasedYPosition() const
Returns the y positon of last button release.
Definition: mousecontrol.h:130
void SetClickPosition(int newX, int newY)
Sets the position of last click.
Definition: mousecontrol.h:112