FIFE  be64c707dea6b3250bd4355bf5c825d25920087d
mouseevent.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2019 by the FIFE team *
3  * http://www.fifengine.net *
4  * This file is part of FIFE. *
5  * *
6  * FIFE is free software; you can redistribute it and/or *
7  * modify it under the terms of the GNU Lesser General Public *
8  * License as published by the Free Software Foundation; either *
9  * version 2.1 of the License, or (at your option) any later version. *
10  * *
11  * This library 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 GNU *
14  * Lesser General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU Lesser General Public *
17  * License along with this library; if not, write to the *
18  * Free Software Foundation, Inc., *
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20  ***************************************************************************/
21 
22 #ifndef FIFE_EVENTCHANNEL_MOUSEEVENT_H
23 #define FIFE_EVENTCHANNEL_MOUSEEVENT_H
24 
25 // Standard C++ library includes
26 //
27 
28 // 3rd party library includes
29 //
30 
31 // FIFE includes
32 // These includes are split up in two parts, separated by one empty line
33 // First block: files included from the FIFE root src directory
34 // Second block: files included from the same folder
35 //
37 
38 namespace FIFE {
39 
42  class MouseEvent: public InputEvent {
43  public:
48  {
50  MOVED = 0,
61  };
62 
67  {
68  EMPTY = 0,
69  LEFT = 1,
70  RIGHT = 2,
71  MIDDLE = 4,
72  X1 = 8,
73  X2 = 16,
75  };
76 
77 
81  InputEvent(),
84  m_x(-1),
85  m_y(-1) {}
86 
89  virtual ~MouseEvent() {}
90 
96  void setButton(MouseButtonType type) { m_buttonType = type; }
97 
102  MouseEventType getType() const { return m_eventType; }
103  void setType(MouseEventType type) { m_eventType = type; }
104 
110  int32_t getX() const { return m_x; }
111  void setX(int32_t x) { m_x = x; }
112 
118  int32_t getY() const { return m_y; }
119  void setY(int32_t y) { m_y = y; }
120 
121  virtual bool isAltPressed() const { return InputEvent::isAltPressed(); }
122  virtual void setAltPressed(bool pressed) { InputEvent::setAltPressed(pressed); }
123  virtual bool isControlPressed() const { return InputEvent::isControlPressed(); }
124  virtual void setControlPressed(bool pressed) { InputEvent::setControlPressed(pressed); }
125  virtual bool isMetaPressed() const { return InputEvent::isMetaPressed(); }
126  virtual void setMetaPressed(bool pressed) { InputEvent::setMetaPressed(pressed); }
127  virtual bool isShiftPressed() const { return InputEvent::isShiftPressed(); }
128  virtual void setShiftPressed(bool pressed) { InputEvent::setShiftPressed(pressed); }
129 
130  virtual void consume() { InputEvent::consume(); }
131  virtual bool isConsumed() const { return InputEvent::isConsumed(); }
133  virtual bool isConsumedByWidgets() const { return InputEvent::isConsumedByWidgets(); }
134  virtual IEventSource* getSource() const { return InputEvent::getSource(); }
135  virtual void setSource(IEventSource* source) { InputEvent::setSource(source); }
136  virtual int32_t getTimeStamp() const { return InputEvent::getTimeStamp(); }
137  virtual void setTimeStamp(int32_t timestamp ) { InputEvent::setTimeStamp(timestamp); }
138 
139  virtual const std::string& getName() const {
140  const static std::string eventName("MouseEvent");
141  return eventName;
142  }
143  virtual std::string getDebugString() const { return InputEvent::getDebugString(); }
144  virtual std::string getAttrStr() const {
145  std::stringstream ss;
146  ss << InputEvent::getAttrStr() << std::endl;
147  ss << "event = " << mouseEventType2str(m_eventType) << ", ";
148  ss << "button = " << mouseButtonType2str(m_buttonType) << ", ";
149  ss << "x = " << m_x << ", ";
150  ss << "y = " << m_y;
151  return ss.str();
152  }
153 
156  inline static std::string mouseEventType2str(MouseEventType t) {
157  std::string s("unknown");
158  switch (t) {
159  case MouseEvent::MOVED:
160  s = "moved";
161  break;
162  case MouseEvent::PRESSED:
163  s = "pressed";
164  break;
166  s = "released";
167  break;
169  s = "wheel_moved_down";
170  break;
172  s = "wheel_moved_up";
173  break;
175  s = "wheel_moved_right";
176  break;
178  s = "wheel_moved_left";
179  break;
180  case MouseEvent::CLICKED:
181  s = "clicked";
182  break;
183  case MouseEvent::ENTERED:
184  s = "entered";
185  break;
186  case MouseEvent::EXITED:
187  s = "excited";
188  break;
189  case MouseEvent::DRAGGED:
190  s = "dragged";
191  break;
192  default:
193  break;
194  }
195  return s;
196  }
197 
200  inline static std::string mouseButtonType2str(MouseButtonType t) {
201  std::string s("unknown");
202  switch (t) {
203  case MouseEvent::EMPTY:
204  s = "empty";
205  break;
206  case MouseEvent::LEFT:
207  s = "left";
208  break;
209  case MouseEvent::RIGHT:
210  s = "right";
211  break;
212  case MouseEvent::MIDDLE:
213  s = "middle";
214  break;
215  case MouseEvent::X1:
216  s = "x1";
217  break;
218  case MouseEvent::X2:
219  s = "x2";
220  break;
222  s = "unknown button";
223  break;
224  default:
225  break;
226  }
227  return s;
228  }
229 
230 
231 
232  private:
235  int32_t m_x;
236  int32_t m_y;
237 
238  };
239 
240 } //FIFE
241 
242 #endif
virtual bool isConsumedByWidgets() const
Checks whether event is consumed by widget library.
Definition: inputevent.h:96
virtual bool isAltPressed() const
Checks whether alt is pressed.
Definition: mouseevent.h:121
MouseButtonType getButton() const
Gets the button of the mouse event.
Definition: mouseevent.h:95
virtual void setControlPressed(bool pressed)
Sets control to pressed.
Definition: inputevent.h:72
virtual int32_t getTimeStamp() const
Gets the timestamp of the event.
Definition: mouseevent.h:136
void setY(int32_t y)
Definition: mouseevent.h:119
Class for mouse events.
Definition: mouseevent.h:42
virtual void setTimeStamp(int32_t timestamp)
Sets the timestamp of the event.
Definition: mouseevent.h:137
virtual void consume()
Marks events as consumed.
Definition: mouseevent.h:130
virtual bool isControlPressed() const
Checks whether control is pressed.
Definition: mouseevent.h:123
Base class for input events (like mouse and keyboard)
Definition: inputevent.h:42
virtual std::string getDebugString() const
Gets the debugstring of the event.
Definition: mouseevent.h:143
virtual void setControlPressed(bool pressed)
Sets control to pressed.
Definition: mouseevent.h:124
virtual void setShiftPressed(bool pressed)
Sets shift to pressed.
Definition: inputevent.h:88
virtual void setShiftPressed(bool pressed)
Sets shift to pressed.
Definition: mouseevent.h:128
virtual bool isShiftPressed() const
Checks whether shift is pressed.
Definition: inputevent.h:84
virtual void setSource(IEventSource *source)
Sets the source of the event.
Definition: mouseevent.h:135
virtual std::string getAttrStr() const
Gets attribute string of the event.
Definition: mouseevent.h:144
virtual void setTimeStamp(int32_t timestamp)
Sets the timestamp of the event.
Definition: inputevent.h:120
virtual bool isConsumed() const
Checks whether event is consumed.
Definition: inputevent.h:104
virtual void setAltPressed(bool pressed)
Sets alt to pressed.
Definition: inputevent.h:64
virtual void setAltPressed(bool pressed)
Sets alt to pressed.
Definition: mouseevent.h:122
virtual bool isConsumedByWidgets() const
Checks whether event is consumed by widget library.
Definition: mouseevent.h:133
MouseEventType
Mouse event types.
Definition: mouseevent.h:47
virtual std::string getAttrStr() const
Gets attribute string of the event.
Definition: inputevent.h:135
virtual void consumedByWidgets()
Marks events as consumed by widget library.
Definition: inputevent.h:92
int32_t getY() const
Gets the y coordinate of the mouse event.
Definition: mouseevent.h:118
virtual bool isShiftPressed() const
Checks whether shift is pressed.
Definition: mouseevent.h:127
MouseEventType getType() const
Gets the type of the event.
Definition: mouseevent.h:102
virtual ~MouseEvent()
Destructor.
Definition: mouseevent.h:89
MouseEventType m_eventType
Definition: mouseevent.h:233
virtual bool isConsumed() const
Checks whether event is consumed.
Definition: mouseevent.h:131
void setX(int32_t x)
Definition: mouseevent.h:111
void setButton(MouseButtonType type)
Definition: mouseevent.h:96
virtual bool isAltPressed() const
Checks whether alt is pressed.
Definition: inputevent.h:60
virtual std::string getDebugString() const
Gets the debugstring of the event.
Definition: inputevent.h:131
virtual bool isMetaPressed() const
Checks whether meta is pressed.
Definition: mouseevent.h:125
virtual int32_t getTimeStamp() const
Gets the timestamp of the event.
Definition: inputevent.h:116
virtual void setMetaPressed(bool pressed)
Sets meta to pressed.
Definition: mouseevent.h:126
MouseButtonType
Mouse button types.
Definition: mouseevent.h:66
virtual void consumedByWidgets()
Marks events as consumed by widget library.
Definition: mouseevent.h:132
static std::string mouseEventType2str(MouseEventType t)
Returns string representation of given event type.
Definition: mouseevent.h:156
MouseEvent()
Constructor.
Definition: mouseevent.h:80
virtual bool isControlPressed() const
Checks whether control is pressed.
Definition: inputevent.h:68
void setType(MouseEventType type)
Definition: mouseevent.h:103
virtual IEventSource * getSource() const
Gets the source of the event.
Definition: mouseevent.h:134
virtual void setSource(IEventSource *source)
Sets the source of the event.
Definition: inputevent.h:112
virtual bool isMetaPressed() const
Checks whether meta is pressed.
Definition: inputevent.h:76
virtual void consume()
Marks events as consumed.
Definition: inputevent.h:100
static std::string mouseButtonType2str(MouseButtonType t)
Returns string representation of given button type.
Definition: mouseevent.h:200
MouseButtonType m_buttonType
Definition: mouseevent.h:234
Representation of event source (a thing sending events)
Definition: ieventsource.h:42
int32_t getX() const
Gets the x coordinate of the mouse event.
Definition: mouseevent.h:110
virtual void setMetaPressed(bool pressed)
Sets meta to pressed.
Definition: inputevent.h:80
virtual const std::string & getName() const
Gets the name of the event.
Definition: mouseevent.h:139
virtual IEventSource * getSource() const
Gets the source of the event.
Definition: inputevent.h:108