FIFE  2008.0
ec_mouseevent.h
1 /***************************************************************************
2  * Copyright (C) 2005-2008 by the FIFE team *
3  * http://www.fifengine.de *
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 //
36 #include "eventchannel/base/ec_inputevent.h"
37 
38 namespace FIFE {
39 
42  class MouseEvent: public InputEvent {
43  public:
48  {
49  UNKNOWN_EVENT = -1,
50  MOVED = 0,
51  PRESSED,
52  RELEASED,
53  WHEEL_MOVED_DOWN,
54  WHEEL_MOVED_UP,
55  CLICKED,
56  ENTERED,
57  EXITED,
58  DRAGGED
59  };
60 
65  {
66  EMPTY = 0,
67  LEFT = 1,
68  RIGHT = 2,
69  MIDDLE = 4,
70  UNKNOWN_BUTTON = 8
71  };
72 
73 
77  InputEvent(),
78  m_eventtype(UNKNOWN_EVENT),
79  m_buttontype(UNKNOWN_BUTTON),
80  m_x(-1),
81  m_y(-1) {}
82 
85  virtual ~MouseEvent() {}
86 
91  MouseButtonType getButton() const { return m_buttontype; }
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() { 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;
161  case MouseEvent::RELEASED:
162  s = "released";
163  break;
164  case MouseEvent::WHEEL_MOVED_DOWN:
165  s = "wheel_moved_down";
166  break;
167  case MouseEvent::WHEEL_MOVED_UP:
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:
214  MouseEventType m_eventtype;
215  MouseButtonType m_buttontype;
216  int32_t m_x;
217  int32_t m_y;
218 
219  };
220 
221 } //FIFE
222 
223 #endif
virtual int32_t getTimeStamp() const
int32_t getY() const
virtual void setTimeStamp(int32_t timestamp)
virtual void consume()
MouseEventType getType() const
Definition: ec_mouseevent.h:98
virtual bool isAltPressed() const
Definition: ec_inputevent.h:60
virtual bool isControlPressed() const
virtual bool isAltPressed() const
virtual void setSource(IEventSource *source)
virtual int32_t getTimeStamp() const
Definition: ec_inputevent.h:87
MouseButtonType getButton() const
Definition: ec_mouseevent.h:91
virtual std::string getDebugString() const
Definition: ec_inputevent.h:94
virtual void setTimeStamp(int32_t timestamp)
Definition: ec_inputevent.h:88
virtual std::string getAttrStr() const
virtual bool isShiftPressed() const
Definition: ec_inputevent.h:75
virtual bool isMetaPressed() const
virtual void consumedByWidgets()
Definition: ec_inputevent.h:80
virtual ~MouseEvent()
Definition: ec_mouseevent.h:85
virtual bool isConsumed() const
Definition: ec_inputevent.h:84
virtual bool isConsumed() const
virtual void consumedByWidgets()
virtual bool isShiftPressed() const
virtual std::string getDebugString() const
static std::string mouseEventType2str(MouseEventType t)
virtual std::string getAttrStr() const
Definition: ec_inputevent.h:96
int32_t getX() const
virtual const std::string & getName() const
virtual void setSource(IEventSource *source)
Definition: ec_inputevent.h:86
virtual void consume()
Definition: ec_inputevent.h:83
static std::string mouseButtonType2str(MouseButtonType t)
virtual bool isMetaPressed() const
Definition: ec_inputevent.h:70
virtual bool isControlPressed() const
Definition: ec_inputevent.h:65
credit to phoku for his NodeDisplay example which the visitor code is adapted from ( he coded the qua...
Definition: soundclip.cpp:39