Mercurial > fife-parpg
comparison engine/core/eventchannel/mouse/ec_mouseevent.h @ 0:4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
author | mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Sun, 29 Jun 2008 18:44:17 +0000 |
parents | |
children | e84dccee1bb7 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4a0efb7baf70 |
---|---|
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 modify * | |
7 * it under the terms of the GNU General Public License as published by * | |
8 * the Free Software Foundation; either version 2 of the License, or * | |
9 * (at your option) any later version. * | |
10 * * | |
11 * This program 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 * | |
14 * GNU General Public License for more details. * | |
15 * * | |
16 * You should have received a copy of the GNU General Public License * | |
17 * along with this program; if not, write to the * | |
18 * Free Software Foundation, Inc., * | |
19 * 51 Franklin St, 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 | |
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 CLICKED, | |
56 ENTERED, | |
57 EXITED, | |
58 DRAGGED | |
59 }; | |
60 | |
61 /** | |
62 * Mouse button types. | |
63 */ | |
64 enum MouseButtonType | |
65 { | |
66 EMPTY = 0, | |
67 LEFT = 1, | |
68 RIGHT = 2, | |
69 MIDDLE = 4, | |
70 UNKNOWN_BUTTON = 8 | |
71 }; | |
72 | |
73 | |
74 /** Constructor. | |
75 */ | |
76 MouseEvent(): | |
77 InputEvent(), | |
78 m_eventtype(UNKNOWN_EVENT), | |
79 m_buttontype(UNKNOWN_BUTTON), | |
80 m_x(-1), | |
81 m_y(-1) {} | |
82 | |
83 /** Destructor. | |
84 */ | |
85 virtual ~MouseEvent() {} | |
86 | |
87 /** | |
88 * Gets the button of the mouse event. | |
89 * @return the button of the mouse event. | |
90 */ | |
91 MouseButtonType getButton() const { return m_buttontype; } | |
92 void setButton(MouseButtonType type) { m_buttontype = type; } | |
93 | |
94 /** | |
95 * Gets the type of the event. | |
96 * @return the type of the event. | |
97 */ | |
98 MouseEventType getType() const { return m_eventtype; } | |
99 void setType(MouseEventType type) { m_eventtype = type; } | |
100 | |
101 /** | |
102 * Gets the x coordinate of the mouse event. The coordinate is relative to | |
103 * the source event source. | |
104 * @return the x coordinate of the mouse event. | |
105 */ | |
106 int getX() const { return m_x; } | |
107 void setX(int x) { m_x = x; } | |
108 | |
109 /** | |
110 * Gets the y coordinate of the mouse event. The coordinate is relative to | |
111 * the source event source. | |
112 * @return the y coordinate of the mouse event. | |
113 */ | |
114 int getY() const { return m_y; } | |
115 void setY(int 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(); } | |
128 virtual IEventSource* getSource() { return InputEvent::getSource(); } | |
129 virtual void setSource(IEventSource* source) { InputEvent::setSource(source); } | |
130 virtual gcn::Widget* getSourceWidget() { return InputEvent::getSourceWidget(); } | |
131 virtual void setSourceWidget(gcn::Widget* widget) { InputEvent::setSourceWidget(widget); } | |
132 virtual int getTimeStamp() const { return InputEvent::getTimeStamp(); } | |
133 virtual void setTimeStamp(int 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 | |
150 /** Returns string representation of given event type | |
151 */ | |
152 inline std::string mouseEventType2str(MouseEventType t) const { | |
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 | |
188 /** Returns string representation of given button type | |
189 */ | |
190 inline std::string mouseButtonType2str(MouseButtonType t) const { | |
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 int m_x; | |
217 int m_y; | |
218 | |
219 }; | |
220 | |
221 } //FIFE | |
222 | |
223 #endif |