Point Cloud Library (PCL)  1.14.1-dev
mouse_event.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2011, Willow Garage, Inc.
6  * Copyright (c) 2012-, Open Perception, Inc.
7  *
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  *
14  * * Redistributions of source code must retain the above copyright
15  * notice, this list of conditions and the following disclaimer.
16  * * Redistributions in binary form must reproduce the above
17  * copyright notice, this list of conditions and the following
18  * disclaimer in the documentation and/or other materials provided
19  * with the distribution.
20  * * Neither the name of the copyright holder(s) nor the names of its
21  * contributors may be used to endorse or promote products derived
22  * from this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35  * POSSIBILITY OF SUCH DAMAGE.
36  *
37  */
38 
39 #pragma once
40 
41 #include <pcl/visualization/keyboard_event.h>
42 
43 namespace pcl
44 {
45  namespace visualization
46  {
47  class MouseEvent
48  {
49  public:
50  enum Type
51  {
52  MouseMove = 1,
58  };
59 
61  {
62  NoButton = 0,
66  VScroll /*other buttons, scroll wheels etc. may follow*/
67  };
68 
69  /** Constructor.
70  * \param[in] type event type
71  * \param[in] button The Button that causes the event
72  * \param[in] x x position of mouse pointer at that time where event got fired
73  * \param[in] y y position of mouse pointer at that time where event got fired
74  * \param[in] alt whether the ALT key was pressed at that time where event got fired
75  * \param[in] ctrl whether the CTRL key was pressed at that time where event got fired
76  * \param[in] shift whether the Shift key was pressed at that time where event got fired
77  * \param[in] selection_mode whether we are in selection mode
78  */
79  inline MouseEvent (const Type& type, const MouseButton& button,
80  unsigned int x, unsigned int y,
81  bool alt, bool ctrl, bool shift,
82  bool selection_mode = false);
83 
84  /**
85  * \return type of mouse event
86  */
87  inline const Type&
88  getType () const;
89 
90  /**
91  * \brief Sets the mouse event type
92  */
93  inline void
94  setType (const Type& type);
95 
96  /**
97  * \return the Button that caused the action
98  */
99  inline const MouseButton&
100  getButton () const;
101 
102  /** \brief Set the button that caused the event */
103  inline void
104  setButton (const MouseButton& button);
105 
106  /**
107  * \return the x position of the mouse pointer at that time where the event got fired
108  */
109  inline unsigned int
110  getX () const;
111 
112  /**
113  * \return the y position of the mouse pointer at that time where the event got fired
114  */
115  inline unsigned int
116  getY () const;
117 
118  /**
119  * \return returns the keyboard modifiers state at that time where the event got fired
120  */
121  inline unsigned int
122  getKeyboardModifiers () const;
123 
124  /**
125  * \return selection mode status
126  */
127  inline bool
128  getSelectionMode () const;
129 
130  protected:
133  unsigned int pointer_x_;
134  unsigned int pointer_y_;
135  unsigned int key_state_{0};
137  };
138 
139  MouseEvent::MouseEvent (const Type& type, const MouseButton& button,
140  unsigned x, unsigned y,
141  bool alt, bool ctrl, bool shift,
142  bool selection_mode)
143  : type_ (type)
144  , button_ (button)
145  , pointer_x_ (x)
146  , pointer_y_ (y)
147  ,
148  selection_mode_ (selection_mode)
149  {
150  if (alt)
152 
153  if (ctrl)
155 
156  if (shift)
158  }
159 
160  const MouseEvent::Type&
162  {
163  return (type_);
164  }
165 
166  void
167  MouseEvent::setType (const Type& type)
168  {
169  type_ = type;
170  }
171 
174  {
175  return (button_);
176  }
177 
178  void
180  {
181  button_ = button;
182  }
183 
184  unsigned int
186  {
187  return (pointer_x_);
188  }
189 
190  unsigned int
192  {
193  return (pointer_y_);
194  }
195 
196  unsigned int
198  {
199  return (key_state_);
200  }
201 
202  bool
204  {
205  return (selection_mode_);
206  }
207 
208  } //namespace visualization
209 } //namespace pcl
static const unsigned int Alt
bit pattern for the ALT key
static const unsigned int Shift
bit pattern for the Shift key
static const unsigned int Ctrl
bit pattern for the Control key
void setType(const Type &type)
Sets the mouse event type.
Definition: mouse_event.h:167
const MouseButton & getButton() const
Definition: mouse_event.h:173
unsigned int getX() const
Definition: mouse_event.h:185
unsigned int getY() const
Definition: mouse_event.h:191
void setButton(const MouseButton &button)
Set the button that caused the event.
Definition: mouse_event.h:179
MouseEvent(const Type &type, const MouseButton &button, unsigned int x, unsigned int y, bool alt, bool ctrl, bool shift, bool selection_mode=false)
Constructor.
Definition: mouse_event.h:139
unsigned int getKeyboardModifiers() const
Definition: mouse_event.h:197
const Type & getType() const
Definition: mouse_event.h:161