SimpleCxxLib package#include "gevents.h"GEvent hierarchy looks like this:
| Classes | |
| This event subclass represents an action event. | |
| This class is the root of the hierarchy for all events. | |
| This event subclass represents a key event. | |
| This event subclass represents a mouse event. | |
| This event subclass represents a timer event. | |
| This event subclass represents a window event. | |
| Types | |
| This enumeration type defines the event classes. | |
| This enumeration type defines the event types for all events. | |
| This type defines the names of the key codes returned in a key event. | |
| This enumeration type defines a set of constants used to check whether modifiers are in effect. | |
| Functions | |
| Checks to see if there are any events of the desired type waiting on the event queue. | |
| Waits for a mouse click in any window, discarding any other events. | |
| Dismisses the process until an event occurs whose type is covered by the event mask. | |
enum EventClassType {
NULL_EVENT x000,
ACTION_EVENTx010,
KEY_EVENT x020,
TIMER_EVENT x040,
WINDOW_EVENTx080,
MOUSE_EVENT x100,
CLICK_EVENT x200,
ANY_EVENT x3F0
};
CLICK_EVENT class responds only to
the MOUSE_CLICKED event type. The ANY_EVENT class
selects any event.
typedef enum {
WINDOW_CLOSED = WINDOW_EVENT + 1,
WINDOW_RESIZED = WINDOW_EVENT + 2,
ACTION_PERFORMED = ACTION_EVENT + 1,
MOUSE_CLICKED = MOUSE_EVENT + 1,
MOUSE_PRESSED = MOUSE_EVENT + 2,
MOUSE_RELEASED = MOUSE_EVENT + 3,
MOUSE_MOVED = MOUSE_EVENT + 4,
MOUSE_DRAGGED = MOUSE_EVENT + 5,
KEY_PRESSED = KEY_EVENT + 1,
KEY_RELEASED = KEY_EVENT + 2,
KEY_TYPED = KEY_EVENT + 3,
TIMER_TICKED = TIMER_EVENT + 1,
} EventType;
enum ModifierCodes {
SHIFT_DOWN = 1 << 0,
CTRL_DOWN = 1 << 1,
META_DOWN = 1 << 2,
ALT_DOWN = 1 << 3,
ALT_GRAPH_DOWN = 1 << 4,
BUTTON1_DOWN = 1 << 5,
BUTTON2_DOWN = 1 << 6,
BUTTON3_DOWN = 1 << 7
};
enum KeyCodes {
BACKSPACE_KEY = 8,
TAB_KEY = 9,
ENTER_KEY = 10,
CLEAR_KEY = 12,
ESCAPE_KEY = 27,
PAGE_UP_KEY = 33,
PAGE_DOWN_KEY = 34,
END_KEY = 35,
HOME_KEY = 36,
LEFT_ARROW_KEY = 37,
UP_ARROW_KEY = 38,
RIGHT_ARROW_KEY = 39,
DOWN_ARROW_KEY = 40,
F1_KEY = 112,
F2_KEY = 113,
F3_KEY = 114,
F4_KEY = 115,
F5_KEY = 116,
F6_KEY = 117,
F7_KEY = 118,
F8_KEY = 119,
F9_KEY = 120,
F10_KEY = 121,
F11_KEY = 122,
F12_KEY = 123,
DELETE_KEY = 127,
HELP_KEY = 156
};
void waitForClick();
Usage:
waitForClick();
GEvent waitForEvent(int mask = ANY_EVENT);
e = waitForEvent(MOUSE_EVENT + ACTION_EVENT);The
mask parameter is optional. If it is missing,
waitForEvent accepts any event.
As a more sophisticated example, the following code is the canonical event loop for an animated application that needs to respond to mouse, key, and timer events:
GTimer timer(ANIMATION_DELAY_IN_MILLISECONDS);
timer.start();
while (true) {
GEvent e = waitForEvent(TIMER_EVENT + MOUSE_EVENT + KEY_EVENT);
switch (e.getEventClass()) {
case TIMER_EVENT:
takeAnimationStep();
break;
case MOUSE_EVENT:
handleMouseEvent(GMouseEvent(e));
break;
case KEY_EVENT:
handleKeyEvent(GKeyEvent(e));
break;
}
}
Usage:
GEvent e = waitForEvent(mask);
GEvent getNextEvent(int mask = ANY_EVENT);
waitForEvent; if not, getNextEvent
returns an invalid event. The mask parameter is optional.
If it is missing, getNextEvent accepts any event.
Usage:
GEvent e = getNextEvent(mask);