Debian Codegraph @

engine/core/eventchannel/mouse/mouseevent.h

raw
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 //
36 #include "eventchannel/base/inputevent.h"
37
38 namespace FIFE {
39
40 /** Class for mouse events
41 */
42 class MouseEvent: public InputEvent {
43 public:
44 /**
45 * Mouse event types.
46 */
47 enum MouseEventType
48 {
49 UNKNOWN_EVENT = -1,
50 MOVED = 0,
51 PRESSED,
52 RELEASED,
53 WHEEL_MOVED_DOWN,
54 WHEEL_MOVED_UP,
55 WHEEL_MOVED_RIGHT,
56 WHEEL_MOVED_LEFT,
57 CLICKED,
58 ENTERED,
59 EXITED,
60 DRAGGED
61 };
62
63 /**
64 * Mouse button types.
65 */
66 enum MouseButtonType
67 {
68 EMPTY = 0,
69 LEFT = 1,
70 RIGHT = 2,
71 MIDDLE = 4,
72 X1 = 8,
73 X2 = 16,
74 UNKNOWN_BUTTON = 32
75 };
76
77
78 /** Constructor.
79 */
80 MouseEvent():
81 InputEvent(),
82 m_eventType(UNKNOWN_EVENT),
83 m_buttonType(UNKNOWN_BUTTON),
84 m_x(-1),
85 m_y(-1) {}
86
87 /** Destructor.
88 */
89 virtual ~MouseEvent() {}
90
91 /**
92 * Gets the button of the mouse event.
93 * @return the button of the mouse event.
94 */
95 MouseButtonType getButton() const { return m_buttonType; }
96 void setButton(MouseButtonType type) { m_buttonType = type; }
97
98 /**
99 * Gets the type of the event.
100 * @return the type of the event.
101 */
102 MouseEventType getType() const { return m_eventType; }
103 void setType(MouseEventType type) { m_eventType = type; }
104
105 /**
106 * Gets the x coordinate of the mouse event. The coordinate is relative to
107 * the source event source.
108 * @return the x coordinate of the mouse event.
109 */
110 int32_t getX() const { return m_x; }
111 void setX(int32_t x) { m_x = x; }
112
113 /**
114 * Gets the y coordinate of the mouse event. The coordinate is relative to
115 * the source event source.
116 * @return the y coordinate of the mouse event.
117 */
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(); }
132 virtual void consumedByWidgets() { InputEvent::consumedByWidgets(); }
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
154 /** Returns string representation of given event type
155 */
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;
165 case MouseEvent::RELEASED:
166 s = "released";
167 break;
168 case MouseEvent::WHEEL_MOVED_DOWN:
169 s = "wheel_moved_down";
170 break;
171 case MouseEvent::WHEEL_MOVED_UP:
172 s = "wheel_moved_up";
173 break;
174 case MouseEvent::WHEEL_MOVED_RIGHT:
175 s = "wheel_moved_right";
176 break;
177 case MouseEvent::WHEEL_MOVED_LEFT:
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
198 /** Returns string representation of given button type
199 */
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;
221 case MouseEvent::UNKNOWN_BUTTON:
222 s = "unknown button";
223 break;
224 default:
225 break;
226 }
227 return s;
228 }
229
230
231
232 private:
233 MouseEventType m_eventType;
234 MouseButtonType m_buttonType;
235 int32_t m_x;
236 int32_t m_y;
237
238 };
239
240 } //FIFE
241
242 #endif