Imagine++
Events.h
1 // ===========================================================================
2 // Imagine++ Libraries
3 // Copyright (C) Imagine
4 // For detailed information: http://imagine.enpc.fr/software
5 // ===========================================================================
6 
7 #ifndef IMAGINE_GRAPHICS_EVENTS_H
8 #define IMAGINE_GRAPHICS_EVENTS_H
9 
10 #include "Types.h"
11 
12 namespace Imagine {
15 
17  enum KeyCode {
18  KEY_BACK=16777219, KEY_TAB=16777217,
19  KEY_RETURN=16777220, KEY_NUMPAD_ENTER=16777221,
20  KEY_ESCAPE=16777216,
21  KEY_INSERT=16777222, KEY_DELETE=16777223,
22  KEY_HOME=16777232, KEY_END=16777233,
23  KEY_PAGEUP=16777238, KEY_PAGEDOWN,
24  KEY_LEFT=16777234, KEY_UP, KEY_RIGHT, KEY_DOWN,
25  KEY_SHIFT=16777248, KEY_CONTROL=16777249,
26  KEY_CMD=16777299, KEY_ALT=16777251,
27  KEY_PRINT=16777225, KEY_SCROLL=16777254,
28  KEY_PAUSE=16777224, KEY_MENU=16777301,
29  KEY_F1=16777264, KEY_F2, KEY_F3, KEY_F4, KEY_F5, KEY_F6,
30  KEY_F7, KEY_F8, KEY_F9, KEY_F10, KEY_F11, KEY_F12,
31  KEY_NUMLOCK=16777253
32  };
33 
34  // =============== Events ==========================
43  enum EventType {
44  EVT_NONE = 0,
45  EVT_BUT_ON = 2,
46  EVT_BUT_OFF = 3,
47  EVT_MOTION = 5,
48  EVT_KEY_ON,
49  EVT_KEY_OFF
50  };
59  enum EventState {
60  EVS_NONE =0,
61  EVS_SHIFT =(1<<0),
62  EVS_CONTROL=(1<<1),
63  EVS_ALT =(1<<2)
64  };
69  struct Event {
75  int button;
78  int key;
84  int subWin;
85  };
94  void milliSleep(int msec);
95 
96  // I/O control functions
97 
105  int getMouse(int& x, int& y);
113  inline int getMouse(IntPoint2& p) { return getMouse(p.x(), p.y()); }
127  int getKey(bool ignoreModifier=true);
135  int click();
142  int anyClick();
151  int anyClick(Window &win, int &subWin);
165  int anyGetKey(Window &win, int &subWin, bool ignoreModifier=true);
175  int anyGetMouse(int &x, int&y, Window &win, int &subWin);
185  inline int anyGetMouse(IntPoint2 &p, Window &win, int &subWin)
186  { return anyGetMouse(p.x(), p.y(), win, subWin); }
202  void getEvent(int ms, Event &ev);
210  void flushEvents();
219  void unGetEvent(const Event &ev);
220 
222 } /* namespace Imagine */
223 
224 #endif /* IMAGINE_GRAPHICS_EVENTS_H */
IntPoint2 pix
Mouse position (only for EVT_BUT_ON, EVT_BUT_OFF and EVT_MOTION).
Definition: Events.h:73
int anyClick()
Wait for mouse click in any window.
void milliSleep(int msec)
...
Window win
Window where the event occurred.
Definition: Events.h:82
int subWin
SubWindow where the event occurred.
Definition: Events.h:84
EventState
Event State.
Definition: Events.h:59
int button
Mouse button (1,2,3) that triggered the event, if any.
Definition: Events.h:75
void flushEvents()
Flush event queue, discarding unhandled events.
const T & x() const
Read alias.
Definition: FVector.h:104
void unGetEvent(const Event &ev)
Unget event.
int key
Key code that triggered the event, if any (only for types EVT_KEY_ON and EVT_KEY_OFF).
Definition: Events.h:78
WindowInternal * Window
Handle to a display window.
Definition: Types.h:48
void getEvent(int ms, Event &ev)
Get keyboard and mouse events.
int anyGetKey(Window &win, int &subWin, bool ignoreModifier=true)
Wait for key press in any window.
int getKey(bool ignoreModifier=true)
Wait for key press in active window.
EventType
Event type (keyboard or mouse event).
Definition: Events.h:43
EventType type
Event type.
Definition: Events.h:71
EventState state
Keyboard state (bitfield) just before the event occured.
Definition: Events.h:80
KeyCode
Keyboard codes for characterless keys.
Definition: Events.h:17
Event info.
Definition: Events.h:69
const T & y() const
Read alias.
Definition: FVector.h:118
Imagine++ namespace.
Definition: Array.h:7
int getMouse(int &x, int &y)
Wait for mouse click in active window (returning position).
int click()
Wait for mouse click in active window.
int anyGetMouse(int &x, int &y, Window &win, int &subWin)
Wait for mouse click in any window (returning window and position).