FIFE
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ec_mouseevent.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2013 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,
59  };
60 
65  {
66  EMPTY = 0,
67  LEFT = 1,
68  RIGHT = 2,
69  MIDDLE = 4,
71  };
72 
73 
77  InputEvent(),
80  m_x(-1),
81  m_y(-1) {}
82 
85  virtual ~MouseEvent() {}
86 
92  void setButton(MouseButtonType type) { m_buttontype = type; }
93 
98  MouseEventType getType() const { return m_eventtype; }
99  void setType(MouseEventType type) { m_eventtype = type; }
100 
106  int32_t getX() const { return m_x; }
107  void setX(int32_t x) { m_x = x; }
108 
114  int32_t getY() const { return m_y; }
115  void setY(int32_t y) { m_y = y; }
116 
117  virtual bool isAltPressed() const { return InputEvent::isAltPressed(); }
118  virtual void setAltPressed(bool pressed) { InputEvent::setAltPressed(pressed); }
119  virtual bool isControlPressed() const { return InputEvent::isControlPressed(); }
120  virtual void setControlPressed(bool pressed) { InputEvent::setControlPressed(pressed); }
121  virtual bool isMetaPressed() const { return InputEvent::isMetaPressed(); }
122  virtual void setMetaPressed(bool pressed) { InputEvent::setMetaPressed(pressed); }
123  virtual bool isShiftPressed() const { return InputEvent::isShiftPressed(); }
124  virtual void setShiftPressed(bool pressed) { InputEvent::setShiftPressed(pressed); }
125 
126  virtual void consume() { InputEvent::consume(); }
127  virtual bool isConsumed() const { return InputEvent::isConsumed(); }
129  virtual bool isConsumedByWidgets() const { return InputEvent::isConsumedByWidgets(); }
130  virtual IEventSource* getSource() const { return InputEvent::getSource(); }
131  virtual void setSource(IEventSource* source) { InputEvent::setSource(source); }
132  virtual int32_t getTimeStamp() const { return InputEvent::getTimeStamp(); }
133  virtual void setTimeStamp(int32_t timestamp ) { InputEvent::setTimeStamp(timestamp); }
134 
135  virtual const std::string& getName() const {
136  const static std::string eventName("MouseEvent");
137  return eventName;
138  }
139  virtual std::string getDebugString() const { return InputEvent::getDebugString(); }
140  virtual std::string getAttrStr() const {
141  std::stringstream ss;
142  ss << InputEvent::getAttrStr() << std::endl;
143  ss << "event = " << mouseEventType2str(m_eventtype) << ", ";
144  ss << "button = " << mouseButtonType2str(m_buttontype) << ", ";
145  ss << "x = " << m_x << ", ";
146  ss << "y = " << m_y;
147  return ss.str();
148  }
149 
152  inline static std::string mouseEventType2str(MouseEventType t) {
153  std::string s("unknown");
154  switch (t) {
155  case MouseEvent::MOVED:
156  s = "moved";
157  break;
158  case MouseEvent::PRESSED:
159  s = "pressed";
160  break;
162  s = "released";
163  break;
165  s = "wheel_moved_down";
166  break;
168  s = "wheel_moved_up";
169  break;
170  case MouseEvent::CLICKED:
171  s = "clicked";
172  break;
173  case MouseEvent::ENTERED:
174  s = "entered";
175  break;
176  case MouseEvent::EXITED:
177  s = "excited";
178  break;
179  case MouseEvent::DRAGGED:
180  s = "dragged";
181  break;
182  default:
183  break;
184  }
185  return s;
186  }
187 
190  inline static std::string mouseButtonType2str(MouseButtonType t) {
191  std::string s("unknown");
192  switch (t) {
193  case MouseEvent::EMPTY:
194  s = "empty";
195  break;
196  case MouseEvent::LEFT:
197  s = "left";
198  break;
199  case MouseEvent::RIGHT:
200  s = "right";
201  break;
202  case MouseEvent::MIDDLE:
203  s = "middle";
204  break;
205  default:
206  break;
207  }
208  return s;
209  }
210 
211 
212 
213  private:
216  int32_t m_x;
217  int32_t m_y;
218 
219  };
220 
221 } //FIFE
222 
223 #endif
virtual IEventSource * getSource() const
Gets the source of the event.
Definition: ec_inputevent.h:85
virtual int32_t getTimeStamp() const
Gets the timestamp of the event.
virtual void setControlPressed(bool pressed)
Definition: ec_inputevent.h:66
void setY(int32_t y)
int32_t getY() const
Gets the y coordinate of the mouse event.
Class for mouse events.
Definition: ec_mouseevent.h:42
virtual void setTimeStamp(int32_t timestamp)
Sets the timestamp of the event.
virtual void consume()
Marks the event as consumed.
Base class for input events (like mouse and keyboard)
Definition: ec_inputevent.h:42
MouseEventType getType() const
Gets the type of the event.
Definition: ec_mouseevent.h:98
virtual bool isAltPressed() const
Checks whether alt is pressed.
Definition: ec_inputevent.h:60
virtual void setControlPressed(bool pressed)
virtual bool isControlPressed() const
Checks whether control is pressed.
virtual void setShiftPressed(bool pressed)
Definition: ec_inputevent.h:76
virtual bool isAltPressed() const
Checks whether alt is pressed.
virtual void setShiftPressed(bool pressed)
virtual void setSource(IEventSource *source)
Sets the source of the event.
virtual int32_t getTimeStamp() const
Gets the timestamp of the event.
Definition: ec_inputevent.h:87
MouseButtonType getButton() const
Gets the button of the mouse event.
Definition: ec_mouseevent.h:91
virtual std::string getDebugString() const
Gets the debugstring of the event.
Definition: ec_inputevent.h:94
virtual bool isConsumedByWidgets() const
Definition: ec_inputevent.h:81
virtual void setTimeStamp(int32_t timestamp)
Sets the timestamp of the event.
Definition: ec_inputevent.h:88
virtual void setAltPressed(bool pressed)
Definition: ec_inputevent.h:61
virtual IEventSource * getSource() const
Gets the source of the event.
virtual std::string getAttrStr() const
Gets attribute string of the event.
virtual void setAltPressed(bool pressed)
virtual bool isShiftPressed() const
Checks whether shift is pressed.
Definition: ec_inputevent.h:75
virtual bool isMetaPressed() const
Checks whether meta is pressed.
MouseEventType
Mouse event types.
Definition: ec_mouseevent.h:47
virtual void consumedByWidgets()
Marks events as consumed by widget library.
Definition: ec_inputevent.h:80
MouseEventType m_eventtype
virtual ~MouseEvent()
Destructor.
Definition: ec_mouseevent.h:85
virtual bool isConsumed() const
Checks if the event is consumed.
Definition: ec_inputevent.h:84
void setX(int32_t x)
void setButton(MouseButtonType type)
Definition: ec_mouseevent.h:92
virtual bool isConsumed() const
Checks if the event is consumed.
virtual void setMetaPressed(bool pressed)
MouseButtonType
Mouse button types.
Definition: ec_mouseevent.h:64
virtual void consumedByWidgets()
Marks events as consumed by widget library.
virtual bool isShiftPressed() const
Checks whether shift is pressed.
virtual std::string getDebugString() const
Gets the debugstring of the event.
static std::string mouseEventType2str(MouseEventType t)
Returns string representation of given event type.
virtual std::string getAttrStr() const
Gets attribute string of the event.
Definition: ec_inputevent.h:96
MouseEvent()
Constructor.
Definition: ec_mouseevent.h:76
int32_t getX() const
Gets the x coordinate of the mouse event.
virtual const std::string & getName() const
Gets the name of the event.
void setType(MouseEventType type)
Definition: ec_mouseevent.h:99
MouseButtonType m_buttontype
virtual void setSource(IEventSource *source)
Sets the source of the event.
Definition: ec_inputevent.h:86
virtual void consume()
Marks the event as consumed.
Definition: ec_inputevent.h:83
static std::string mouseButtonType2str(MouseButtonType t)
Returns string representation of given button type.
virtual bool isMetaPressed() const
Checks whether meta is pressed.
Definition: ec_inputevent.h:70
Representation of event source (a thing sending events)
virtual void setMetaPressed(bool pressed)
Definition: ec_inputevent.h:71
virtual bool isControlPressed() const
Checks whether control is pressed.
Definition: ec_inputevent.h:65
virtual bool isConsumedByWidgets() const