1 /***********************************************************************
2 	created:	30/5/2004
3 	author:		Paul D Turner
4 
5 	purpose:	Defines interface to input event classes
6 *************************************************************************/
7 /***************************************************************************
8  *   Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team
9  *
10  *   Permission is hereby granted, free of charge, to any person obtaining
11  *   a copy of this software and associated documentation files (the
12  *   "Software"), to deal in the Software without restriction, including
13  *   without limitation the rights to use, copy, modify, merge, publish,
14  *   distribute, sublicense, and/or sell copies of the Software, and to
15  *   permit persons to whom the Software is furnished to do so, subject to
16  *   the following conditions:
17  *
18  *   The above copyright notice and this permission notice shall be
19  *   included in all copies or substantial portions of the Software.
20  *
21  *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22  *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23  *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24  *   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
25  *   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26  *   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27  *   OTHER DEALINGS IN THE SOFTWARE.
28  ***************************************************************************/
29 #ifndef _CEGUIInputEvent_h_
30 #define _CEGUIInputEvent_h_
31 
32 #include "CEGUI/Base.h"
33 #include "CEGUI/EventArgs.h"
34 #include "CEGUI/String.h"
35 #include "CEGUI/Vector.h"
36 #include "CEGUI/Size.h"
37 
38 #if defined(_MSC_VER)
39 #	pragma warning(push)
40 #	pragma warning(disable : 4251)
41 #endif
42 
43 // Start of CEGUI namespace section
44 namespace CEGUI
45 {
46 /*!
47 \brief
48 	struct to give scope to scan code enumeration.
49 */
50 struct CEGUIEXPORT Key
51 {
52 	// enumeration of scan codes.  Customised from table taken from Ogre, which took them from DirectInput...
53 	enum Scan
54     {
55         Unknown         =0x00,
56         Escape          =0x01,
57         One             =0x02,
58         Two             =0x03,
59         Three           =0x04,
60         Four            =0x05,
61         Five            =0x06,
62         Six             =0x07,
63         Seven           =0x08,
64         Eight           =0x09,
65         Nine            =0x0A,
66         Zero            =0x0B,
67         Minus           =0x0C,    /* - on main keyboard */
68         Equals			=0x0D,
69         Backspace		=0x0E,    /* backspace */
70         Tab				=0x0F,
71         Q               =0x10,
72         W               =0x11,
73         E               =0x12,
74         R               =0x13,
75         T               =0x14,
76         Y               =0x15,
77         U               =0x16,
78         I               =0x17,
79         O               =0x18,
80         P               =0x19,
81         LeftBracket     =0x1A,
82         RightBracket    =0x1B,
83         Return			=0x1C,    /* Enter on main keyboard */
84         LeftControl		=0x1D,
85         A               =0x1E,
86         S               =0x1F,
87         D               =0x20,
88         F               =0x21,
89         G               =0x22,
90         H               =0x23,
91         J               =0x24,
92         K               =0x25,
93         L               =0x26,
94         Semicolon       =0x27,
95         Apostrophe		=0x28,
96         Grave           =0x29,    /* accent grave */
97         LeftShift       =0x2A,
98         Backslash       =0x2B,
99         Z               =0x2C,
100         X               =0x2D,
101         C               =0x2E,
102         V               =0x2F,
103         B               =0x30,
104         N               =0x31,
105         M               =0x32,
106         Comma           =0x33,
107         Period          =0x34,    /* . on main keyboard */
108         Slash           =0x35,    /* '/' on main keyboard */
109         RightShift      =0x36,
110         Multiply        =0x37,    /* * on numeric keypad */
111         LeftAlt        =0x38,    /* left Alt */
112         Space           =0x39,
113         Capital         =0x3A,
114         F1              =0x3B,
115         F2              =0x3C,
116         F3              =0x3D,
117         F4              =0x3E,
118         F5              =0x3F,
119         F6              =0x40,
120         F7              =0x41,
121         F8              =0x42,
122         F9              =0x43,
123         F10             =0x44,
124         NumLock         =0x45,
125         ScrollLock      =0x46,    /* Scroll Lock */
126         Numpad7         =0x47,
127         Numpad8         =0x48,
128         Numpad9         =0x49,
129         Subtract        =0x4A,    /* - on numeric keypad */
130         Numpad4         =0x4B,
131         Numpad5         =0x4C,
132         Numpad6         =0x4D,
133         Add				=0x4E,    /* + on numeric keypad */
134         Numpad1         =0x4F,
135         Numpad2         =0x50,
136         Numpad3         =0x51,
137         Numpad0         =0x52,
138         Decimal			=0x53,    /* . on numeric keypad */
139         OEM_102         =0x56,    /* < > | on UK/Germany keyboards */
140         F11             =0x57,
141         F12             =0x58,
142         F13             =0x64,    /*                     (NEC PC98) */
143         F14             =0x65,    /*                     (NEC PC98) */
144         F15             =0x66,    /*                     (NEC PC98) */
145         Kana            =0x70,    /* (Japanese keyboard)            */
146         ABNT_C1         =0x73,    /* / ? on Portugese (Brazilian) keyboards */
147         Convert         =0x79,    /* (Japanese keyboard)            */
148         NoConvert       =0x7B,    /* (Japanese keyboard)            */
149         Yen             =0x7D,    /* (Japanese keyboard)            */
150         ABNT_C2         =0x7E,    /* Numpad . on Portugese (Brazilian) keyboards */
151         NumpadEquals    =0x8D,    /* = on numeric keypad (NEC PC98) */
152         PrevTrack       =0x90,    /* Previous Track (KC_CIRCUMFLEX on Japanese keyboard) */
153         At              =0x91,    /*                     (NEC PC98) */
154         Colon           =0x92,    /*                     (NEC PC98) */
155         Underline       =0x93,    /*                     (NEC PC98) */
156         Kanji           =0x94,    /* (Japanese keyboard)            */
157         Stop            =0x95,    /*                     (NEC PC98) */
158         AX              =0x96,    /*                     (Japan AX) */
159         Unlabeled       =0x97,    /*                        (J3100) */
160         NextTrack       =0x99,    /* Next Track */
161         NumpadEnter     =0x9C,    /* Enter on numeric keypad */
162         RightControl    =0x9D,
163         Mute            =0xA0,    /* Mute */
164         Calculator      =0xA1,    /* Calculator */
165         PlayPause       =0xA2,    /* Play / Pause */
166         MediaStop       =0xA4,    /* Media Stop */
167         VolumeDown      =0xAE,    /* Volume - */
168         VolumeUp        =0xB0,    /* Volume + */
169         WebHome         =0xB2,    /* Web home */
170         NumpadComma     =0xB3,    /* , on numeric keypad (NEC PC98) */
171         Divide          =0xB5,    /* / on numeric keypad */
172         SysRq           =0xB7,
173         RightAlt        =0xB8,    /* right Alt */
174         Pause           =0xC5,    /* Pause */
175         Home            =0xC7,    /* Home on arrow keypad */
176         ArrowUp         =0xC8,    /* UpArrow on arrow keypad */
177         PageUp          =0xC9,    /* PgUp on arrow keypad */
178         ArrowLeft       =0xCB,    /* LeftArrow on arrow keypad */
179         ArrowRight      =0xCD,    /* RightArrow on arrow keypad */
180         End             =0xCF,    /* End on arrow keypad */
181         ArrowDown       =0xD0,    /* DownArrow on arrow keypad */
182         PageDown		=0xD1,    /* PgDn on arrow keypad */
183         Insert          =0xD2,    /* Insert on arrow keypad */
184         Delete          =0xD3,    /* Delete on arrow keypad */
185         LeftWindows     =0xDB,    /* Left Windows key */
186         RightWindows    =0xDC,    /* Right Windows key - Correct spelling :) */
187         AppMenu         =0xDD,    /* AppMenu key */
188         Power           =0xDE,    /* System Power */
189         Sleep           =0xDF,    /* System Sleep */
190         Wake			=0xE3,    /* System Wake */
191         WebSearch		=0xE5,    /* Web Search */
192         WebFavorites	=0xE6,    /* Web Favorites */
193         WebRefresh		=0xE7,    /* Web Refresh */
194         WebStop			=0xE8,    /* Web Stop */
195         WebForward		=0xE9,    /* Web Forward */
196         WebBack			=0xEA,    /* Web Back */
197         MyComputer		=0xEB,    /* My Computer */
198         Mail			=0xEC,    /* Mail */
199         MediaSelect		=0xED     /* Media Select */
200     };
201 
202 };
203 
204 
205 /*!
206 \brief
207     Enumeration of mouse buttons
208 */
209 enum MouseButton
210 {
211     //! The left mouse button.
212     LeftButton,
213     //! The right mouse button.
214     RightButton,
215     //! The middle mouse button.
216     MiddleButton,
217     //! The first 'extra' mouse button.
218     X1Button,
219     //! The second 'extra' mouse button.
220     X2Button,
221     //! Value that equals the number of mouse buttons supported by CEGUI.
222     MouseButtonCount,
223     //! Value set for no mouse button.  NB: This is not 0, do not assume!
224     NoButton
225 };
226 
227 
228 /*!
229 \brief
230 	System key flag values
231 */
232 enum SystemKey
233 {
234 	LeftMouse		= 0x0001,			//!< The left mouse button.
235 	RightMouse		= 0x0002,			//!< The right mouse button.
236 	Shift			= 0x0004,			//!< Either shift key.
237 	Control			= 0x0008,			//!< Either control key.
238 	MiddleMouse		= 0x0010,			//!< The middle mouse button.
239 	X1Mouse			= 0x0020,			//!< The first 'extra' mouse button
240 	X2Mouse			= 0x0040,			//!< The second 'extra' mouse button.
241 	Alt				= 0x0080,			//!< Either alt key.
242     InvalidSysKey   = 0x8000
243 };
244 
245 
246 /*!
247 \brief
248 	EventArgs based class that is used for objects passed to handlers triggered for events
249 	concerning some Window object.
250 */
251 class CEGUIEXPORT WindowEventArgs : public EventArgs
252 {
253 public:
WindowEventArgs(Window * wnd)254 	WindowEventArgs(Window* wnd) : window(wnd) {}
255 
256 	Window*	window;		//!< pointer to a Window object of relevance to the event.
257 };
258 
259 /*!
260 \brief
261 	WindowEventArgs class that is primarily used by lua scripts
262 */
263 class CEGUIEXPORT UpdateEventArgs : public WindowEventArgs
264 {
265 public:
UpdateEventArgs(Window * window,float tslf)266     UpdateEventArgs(Window* window, float tslf) :
267         WindowEventArgs(window),
268         d_timeSinceLastFrame(tslf)
269     {}
270 
271 	float d_timeSinceLastFrame; //!< Time since the last frame update
272 };
273 
274 
275 /*!
276 \brief
277 	EventArgs based class that is used for objects passed to input event handlers
278 	concerning mouse input.
279 */
280 class CEGUIEXPORT MouseEventArgs : public WindowEventArgs
281 {
282 public:
MouseEventArgs(Window * wnd)283 	MouseEventArgs(Window* wnd) : WindowEventArgs(wnd) {}
284 
285 	Vector2f	position;		//!< holds current mouse position.
286 	Vector2f	moveDelta;		//!< holds variation of mouse position from last mouse input
287 	MouseButton	button;			//!< one of the MouseButton enumerated values describing the mouse button causing the event (for button inputs only)
288 	uint		sysKeys;		//!< current state of the system keys and mouse buttons.
289 	float		wheelChange;	//!< Holds the amount the scroll wheel has changed.
290 	uint        clickCount;     //!< Holds number of mouse button down events currently counted in a multi-click sequence (for button inputs only).
291 };
292 
293 
294 /*!
295 \brief
296 	EventArgs based class that is used for objects passed to input event handlers
297 	concerning mouse cursor events.
298 */
299 class CEGUIEXPORT MouseCursorEventArgs : public EventArgs
300 {
301 public:
MouseCursorEventArgs(MouseCursor * cursor)302 	MouseCursorEventArgs(MouseCursor* cursor) : mouseCursor(cursor) {}
303 
304 	MouseCursor* mouseCursor;	//!< pointer to a MouseCursor object of relevance to the event.
305 	const Image* image;			//!< pointer to an Image object of relevance to the event.
306 };
307 
308 
309 /*!
310 \brief
311 	EventArgs based class that is used for objects passed to input event handlers
312 	concerning keyboard input.
313 */
314 class CEGUIEXPORT KeyEventArgs : public WindowEventArgs
315 {
316 public:
KeyEventArgs(Window * wnd)317 	KeyEventArgs(Window* wnd) : WindowEventArgs(wnd) {}
318 
319 	String::value_type codepoint; //!< utf32 or char (depends on used String class) codepoint for the key (only used for Character inputs).
320 	Key::Scan          scancode;  //!< Scan code of key that caused event (only used for key up & down inputs.
321 	uint               sysKeys;   //!< current state of the system keys and mouse buttons.
322 };
323 
324 
325 /*!
326 \brief
327 	EventArgs based class that is used for Activated and Deactivated window events
328 */
329 class CEGUIEXPORT ActivationEventArgs : public WindowEventArgs
330 {
331 public:
ActivationEventArgs(Window * wnd)332 	ActivationEventArgs(Window* wnd) : WindowEventArgs(wnd) {}
333 
334 	Window*	otherWindow;	//!< Pointer to the other window involved in the activation change.
335 };
336 
337 /*!
338 \brief
339 	EventArgs based class used for certain drag/drop notifications
340 */
341 class CEGUIEXPORT DragDropEventArgs : public WindowEventArgs
342 {
343 public:
DragDropEventArgs(Window * wnd)344 	DragDropEventArgs(Window* wnd) : WindowEventArgs(wnd) {}
345 	DragContainer*	dragDropItem; //!< pointer to the DragContainer window being dragged / dropped.
346 };
347 
348 /*!
349 \brief
350     EventArgs based class that is used for notifications regarding the main
351     display.
352 */
353 class CEGUIEXPORT DisplayEventArgs : public EventArgs
354 {
355 public:
DisplayEventArgs(const Sizef & sz)356     DisplayEventArgs(const Sizef& sz):
357         size(sz)
358     {}
359 
360     //! current / new size of the display.
361     Sizef size;
362 };
363 
364 //! EventArgs based class that is used for notifications regarding resources.
365 class CEGUIEXPORT ResourceEventArgs : public EventArgs
366 {
367 public:
ResourceEventArgs(const String & type,const String & name)368     ResourceEventArgs(const String& type, const String& name) :
369        resourceType(type),
370        resourceName(name)
371     {}
372 
373     //! String identifying the resource type this notification is about.
374     String resourceType;
375     //! String identifying the name of the resource this notification is about.
376     String resourceName;
377 };
378 
379 //! EventArgs based class that is used for notifications regarding Font objects.
380 class CEGUIEXPORT FontEventArgs : public EventArgs
381 {
382 public:
FontEventArgs(Font * font)383     FontEventArgs(Font* font) :
384        font(font)
385     {}
386 
387     //! Pointer to the font object related to the event notification.
388     Font* font;
389 };
390 
391 } // End of  CEGUI namespace section
392 
393 #if defined(_MSC_VER)
394 #	pragma warning(pop)
395 #endif
396 
397 #endif	// end of guard _CEGUIInputEvent_h_
398