Line data Source code
1 :
2 : /* Copyright (c) 2006-2013, Stefan Eilemann <eile@equalizergraphics.com>
3 : * 2011, Cedric Stalder <cedric.stalder@gmail.com>
4 : * 2012, Daniel Nachbaur <danielnachbaur@gmail.com>
5 : *
6 : * This library is free software; you can redistribute it and/or modify it under
7 : * the terms of the GNU Lesser General Public License version 2.1 as published
8 : * by the Free Software Foundation.
9 : *
10 : * This library is distributed in the hope that it will be useful, but WITHOUT
11 : * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 : * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 : * details.
14 : *
15 : * You should have received a copy of the GNU Lesser General Public License
16 : * along with this library; if not, write to the Free Software Foundation, Inc.,
17 : * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 : */
19 :
20 : #ifndef EQ_EVENT_H
21 : #define EQ_EVENT_H
22 :
23 : #include <eq/client/api.h>
24 : #include <eq/client/statistic.h> // member
25 : #include <eq/client/types.h>
26 : #include <eq/fabric/renderContext.h> // member
27 :
28 :
29 : namespace eq
30 : {
31 : /**
32 : * Yet another key code table to report keys in a window system independent
33 : * way. Ordinary keys (letters, numbers, etc) are reported using the
34 : * corresponding ascii code. The naming is oriented on the X11 keysym naming.
35 : */
36 : enum KeyCode
37 : {
38 : KC_ESCAPE = 256,
39 : KC_BACKSPACE,
40 : KC_RETURN,
41 : KC_TAB,
42 : KC_HOME,
43 : KC_LEFT,
44 : KC_UP,
45 : KC_RIGHT,
46 : KC_DOWN,
47 : KC_PAGE_UP,
48 : KC_PAGE_DOWN,
49 : KC_END,
50 : KC_F1,
51 : KC_F2,
52 : KC_F3,
53 : KC_F4,
54 : KC_F5,
55 : KC_F6,
56 : KC_F7,
57 : KC_F8,
58 : KC_F9,
59 : KC_F10,
60 : KC_F11,
61 : KC_F12,
62 : KC_F13,
63 : KC_F14,
64 : KC_F15,
65 : KC_F16,
66 : KC_F17,
67 : KC_F18,
68 : KC_F19,
69 : KC_F20,
70 : KC_F21,
71 : KC_F22,
72 : KC_F23,
73 : KC_F24,
74 : KC_SHIFT_L,
75 : KC_SHIFT_R,
76 : KC_CONTROL_L,
77 : KC_CONTROL_R,
78 : KC_ALT_L,
79 : KC_ALT_R,
80 : KC_VOID = 0xFFFFFF /* == XK_VoidSymbol */
81 : };
82 :
83 : /**
84 : * Mouse pointer button definition. The enums are defined as masks, so that
85 : * the state of all buttons can be OR'd using the same enum.
86 : * @version 1.0
87 : */
88 : enum PointerButton
89 : {
90 : PTR_BUTTON_NONE = LB_BIT_NONE,
91 : PTR_BUTTON1 = LB_BIT1,
92 : PTR_BUTTON2 = LB_BIT2,
93 : PTR_BUTTON3 = LB_BIT3,
94 : PTR_BUTTON4 = LB_BIT4,
95 : PTR_BUTTON5 = LB_BIT5,
96 : PTR_BUTTON6 = LB_BIT6,
97 : PTR_BUTTON7 = LB_BIT7
98 : };
99 :
100 : /**
101 : * Event for a size or position change on a Window, Channel or View.
102 : * @version 1.0
103 : */
104 : struct ResizeEvent
105 : {
106 : int32_t x; //!< new X position, relative to parent
107 : int32_t y; //!< new Y position, relative to parent
108 : int32_t w; //!< new width
109 : int32_t h; //!< new height
110 : float dw; //!< view only: new width relative to initial width
111 : float dh; //!< view only: new height relative to initial height
112 : };
113 :
114 : /** Event for a pointer (mouse) motion or click. @version 1.0 */
115 : struct PointerEvent
116 : {
117 : int32_t x; //!< X position relative to entity
118 : int32_t y; //!< Y position relative to entity (0 is on top)
119 : int32_t dx; //!< X position change since last event
120 : int32_t dy; //!< Y position change since last event
121 : uint32_t buttons; //!< current state of all buttons
122 : uint32_t button; //!< fired button
123 : int32_t xAxis; //!< x wheel rotation
124 : int32_t yAxis; //!< y wheel rotation
125 : };
126 :
127 : /** Event for a key press or release. @version 1.0 */
128 : struct KeyEvent
129 : {
130 : uint32_t key; //!< KeyCode for special keys, ascii code otherwise
131 : // TODO modifier state
132 : };
133 :
134 : /**
135 : * Event for a SpaceMouse movement or click.
136 : * @warning experimental - may not be supported in the future.
137 : */
138 : struct MagellanEvent
139 : {
140 : uint32_t button; //!< fired button
141 : uint32_t buttons; //!< current state of all buttons
142 : int16_t xAxis; //!< X translation
143 : int16_t yAxis; //!< Y translation
144 : int16_t zAxis; //!< Z translation
145 : int16_t xRotation; //!< X rotation
146 : int16_t yRotation; //!< Y rotation
147 : int16_t zRotation; //!< Z rotation
148 : };
149 :
150 : # define EQ_USER_EVENT_SIZE 128
151 : /**
152 : * User-defined event.
153 : *
154 : * See the eqPixelBench example on how to use user-defined events.
155 : * @version 1.0
156 : */
157 : struct UserEvent
158 : {
159 : char data[ EQ_USER_EVENT_SIZE ]; //!< Application-specific data
160 : };
161 :
162 : /**
163 : * Event structure to report window system and other events.
164 : *
165 : * Depending on the Event::Type, the corresponding specific event data is filled
166 : * into the anonymous union. The originator typically contains the co::Object
167 : * identifier of the entity emitting the event. The rendering context is only
168 : * set for pointer events.
169 : * @version 1.0
170 : */
171 234 : struct Event
172 : {
173 : /** Construct a new event. */
174 : EQ_API Event();
175 :
176 : /** The type of the event. */
177 : enum Type // Also update string table in event.cpp
178 : {
179 : WINDOW_EXPOSE = 0, //!< A window is dirty
180 : WINDOW_RESIZE, //!< Window resize data in resize
181 : WINDOW_CLOSE, //!< A window has been closed
182 : WINDOW_HIDE, //!< A window is hidden
183 : WINDOW_SHOW, //!< A window is shown
184 : WINDOW_SCREENSAVER, //!< A window screensaver request (Win32 only)
185 : #ifdef EQ_USE_DEPRECATED
186 : POINTER_MOTION, //!< Pointer movement data in pointerMotion
187 : /** Pointer button press data in pointerButtonPress */
188 : POINTER_BUTTON_PRESS,
189 : /** Pointer button release data in pointerButtonRelease */
190 : POINTER_BUTTON_RELEASE,
191 : POINTER_WHEEL, //!< Mouse wheel data in wheel
192 : //!< Channel pointer movement data in pointerMotion
193 : CHANNEL_POINTER_MOTION = POINTER_MOTION,
194 : /** Channel pointer button press data in pointerButtonPress */
195 : CHANNEL_POINTER_BUTTON_PRESS = POINTER_BUTTON_PRESS,
196 : /** Channel pointer button release data in pointerButtonRelease */
197 : CHANNEL_POINTER_BUTTON_RELEASE = POINTER_BUTTON_RELEASE,
198 : //!< Window pointer Mouse wheel data in wheel
199 : WINDOW_POINTER_WHEEL = POINTER_WHEEL,
200 : #else
201 : //!< Channel pointer movement data in pointerMotion
202 : CHANNEL_POINTER_MOTION,
203 : /** Channel pointer button press data in pointerButtonPress */
204 : CHANNEL_POINTER_BUTTON_PRESS,
205 : /** Channel pointer button release data in pointerButtonRelease */
206 : CHANNEL_POINTER_BUTTON_RELEASE,
207 : //!< Channel pointer Mouse wheel data in wheel
208 : CHANNEL_POINTER_WHEEL,
209 : //!< Window pointer Mouse wheel data in wheel
210 : WINDOW_POINTER_WHEEL,
211 : #endif
212 : //!< Window pointer movement data in pointerMotion
213 : WINDOW_POINTER_MOTION,
214 : /** Window pointer button press data in pointerButtonPress */
215 : WINDOW_POINTER_BUTTON_PRESS,
216 : /** Window pointer button release data in pointerButtonRelease */
217 : WINDOW_POINTER_BUTTON_RELEASE,
218 : /** Window pointer grabbed by system window */
219 : WINDOW_POINTER_GRAB,
220 : /** Window pointer to be released by system window */
221 : WINDOW_POINTER_UNGRAB,
222 :
223 : KEY_PRESS, //!< Key press data in keyPress
224 : KEY_RELEASE, //!< Key release data in keyRelease
225 : CHANNEL_RESIZE, //!< Channel resize data in resize
226 : STATISTIC, //!< Statistic event in statistic
227 : VIEW_RESIZE, //!< View resize data in resize
228 : EXIT, //!< Exit request due to runtime error
229 : MAGELLAN_AXIS, //!< SpaceMouse movement data in magellan
230 : MAGELLAN_BUTTON, //!< SpaceMouse button data in magellan
231 : NODE_TIMEOUT, //!< Node has timed out
232 :
233 : /**
234 : * Observer moved (head tracking update). Contains observer originator
235 : * identifier and 4x4 float tracking matrix.
236 : * @version 1.5.2
237 : */
238 : OBSERVER_MOTION,
239 :
240 : /**
241 : * Config error event. Contains the originator id, the error code and
242 : * 0-n Strings with additional information.
243 : * @version 1.7.1
244 : */
245 : CONFIG_ERROR,
246 : NODE_ERROR, //!< Node error event. @sa CONFIG_ERROR
247 : PIPE_ERROR, //!< Pipe error event. @sa CONFIG_ERROR
248 : WINDOW_ERROR, //!< Window error event. @sa CONFIG_ERROR
249 : CHANNEL_ERROR, //!< Channel error event. @sa CONFIG_ERROR
250 :
251 : UNKNOWN, //!< Event type not known by the event handler
252 : /** User-defined events have to be of this type or higher */
253 : USER = UNKNOWN + 5, // some buffer for binary-compatible patches
254 : ALL // must be last
255 : };
256 :
257 : uint32_t type; //!< The event type
258 :
259 : // keep before 'uint128_t originator' for alignment
260 : uint32_t serial; //!< server-unique originator serial number
261 :
262 : /** The config time when the event was created. @version 1.1.1 */
263 : int64_t time;
264 :
265 : /** The identifier of the entity emitting the event. */
266 : uint128_t originator;
267 :
268 : /** Data for the event corresponding to the event type. */
269 : union
270 : {
271 : ResizeEvent resize; //!< Resize event data
272 : ResizeEvent show; //!< Window show event data
273 : ResizeEvent hide; //!< Window hide event data
274 :
275 : PointerEvent pointer; //!< Pointer event data
276 : PointerEvent pointerMotion; //!< Pointer motion data
277 : PointerEvent pointerButtonPress; //!< Mouse button press data
278 : PointerEvent pointerButtonRelease; //!< Mouse button release data
279 : PointerEvent pointerWheel; //!< Mouse wheel motion data
280 :
281 : KeyEvent key; //!< Key event data
282 : KeyEvent keyPress; //!< Key press event data
283 : KeyEvent keyRelease; //!< Key release event data
284 :
285 : Statistic statistic; //!< Statistic event
286 : MagellanEvent magellan; //!< SpaceMouse data
287 :
288 : UserEvent user; //!< User-defined event data
289 : };
290 :
291 : /** The last rendering context for the pointer position. */
292 : RenderContext context;
293 : };
294 :
295 : /** Print the event to the given output stream. @version 1.0 */
296 : EQ_API std::ostream& operator << ( std::ostream&, const Event& );
297 : /** Print the event type to the given output stream. @version 1.0 */
298 : EQ_API std::ostream& operator << ( std::ostream&, const Event::Type& );
299 : /** Print the resize event to the given output stream. @version 1.0 */
300 : EQ_API std::ostream& operator << ( std::ostream&, const ResizeEvent& );
301 : /** Print the pointer event to the given output stream. @version 1.0 */
302 : EQ_API std::ostream& operator << ( std::ostream&, const PointerEvent& );
303 : /** Print the key event to the given output stream. @version 1.0 */
304 : EQ_API std::ostream& operator << ( std::ostream&, const KeyEvent& );
305 : /** Print the space mouse event to the given output stream. @version 1.0 */
306 : EQ_API std::ostream& operator << ( std::ostream&, const MagellanEvent& );
307 : }
308 :
309 : namespace lunchbox
310 : {
311 0 : template<> inline void byteswap( eq::Event& value )
312 : {
313 0 : byteswap( value.type );
314 0 : byteswap( value.serial );
315 0 : byteswap( value.time );
316 0 : byteswap( value.originator );
317 : // #145 Todo byteswap union
318 : //byteswap( value.union );
319 0 : byteswap( value.context );
320 0 : }
321 : }
322 :
323 : #endif // EQ_EVENT_H
|