|
|
@@ -63,38 +63,61 @@ class Widget |
|
|
|
public: |
|
|
|
/** |
|
|
|
Base event data. |
|
|
|
@a mod The currently active keyboard modifiers, @see Modifier. |
|
|
|
@a time The timestamp (if any). |
|
|
|
These are the fields present on all Widget events. |
|
|
|
|
|
|
|
@a mod Currently active keyboard modifiers, @see Modifier. |
|
|
|
@a mod Event flags, @see Flag. |
|
|
|
@a time Event timestamp (if any). |
|
|
|
*/ |
|
|
|
struct BaseEvent { |
|
|
|
uint mod; |
|
|
|
uint32_t time; |
|
|
|
uint mod; |
|
|
|
uint flags; |
|
|
|
uint time; |
|
|
|
|
|
|
|
/** Constuctor */ |
|
|
|
BaseEvent() noexcept : mod(0x0), time(0) {} |
|
|
|
BaseEvent() noexcept : mod(0x0), flags(0x0), time(0) {} |
|
|
|
/** Destuctor */ |
|
|
|
virtual ~BaseEvent() noexcept {} |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|
Keyboard event. |
|
|
|
@a press True if the key was pressed, false if released. |
|
|
|
@a key Unicode point of the key pressed. |
|
|
|
|
|
|
|
This event represents low-level key presses and releases. |
|
|
|
This can be used for "direct" keyboard handing like key bindings, but must not be interpreted as text input. |
|
|
|
|
|
|
|
Keys are represented portably as Unicode code points, using the "natural" code point for the key. |
|
|
|
The @a key field is the code for the pressed key, without any modifiers applied. |
|
|
|
For example, a press or release of the 'A' key will have `key` 97 ('a') |
|
|
|
regardless of whether shift or control are being held. |
|
|
|
|
|
|
|
Alternatively, the raw @a keycode can be used to work directly with physical keys, |
|
|
|
but note that this value is not portable and differs between platforms and hardware. |
|
|
|
|
|
|
|
@a press True if the key was pressed, false if released. |
|
|
|
@a key Unicode point of the key pressed. |
|
|
|
@a keycode Raw keycode. |
|
|
|
@see onKeyboard |
|
|
|
*/ |
|
|
|
struct KeyboardEvent : BaseEvent { |
|
|
|
bool press; |
|
|
|
uint key; |
|
|
|
uint keycode; |
|
|
|
|
|
|
|
/** Constuctor */ |
|
|
|
KeyboardEvent() noexcept |
|
|
|
: BaseEvent(), |
|
|
|
press(false), |
|
|
|
key(0) {} |
|
|
|
key(0), |
|
|
|
keycode(0) {} |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|
Special keyboard event. |
|
|
|
|
|
|
|
This event allows the use of keys that do not have unicode points. |
|
|
|
Note that some are non-printable keys. |
|
|
|
|
|
|
|
@a press True if the key was pressed, false if released. |
|
|
|
@a key The key pressed. |
|
|
|
@see onSpecial |
|
|
@@ -111,54 +134,91 @@ public: |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|
Mouse event. |
|
|
|
@a button The button number (1 = left, 2 = middle, 3 = right). |
|
|
|
Character input event. |
|
|
|
|
|
|
|
This event represents text input, usually as the result of a key press. |
|
|
|
The text is given both as a Unicode character code and a UTF-8 string. |
|
|
|
|
|
|
|
Note that this event is generated by the platform's input system, |
|
|
|
so there is not necessarily a direct correspondence between text events and physical key presses. |
|
|
|
For example, with some input methods a sequence of several key presses will generate a single character. |
|
|
|
|
|
|
|
@a keycode Raw key code. |
|
|
|
@a character Unicode character code. |
|
|
|
@a string UTF-8 string. |
|
|
|
@see onCharacterInput |
|
|
|
*/ |
|
|
|
struct CharacterInputEvent : BaseEvent { |
|
|
|
uint keycode; |
|
|
|
uint character; |
|
|
|
char string[8]; |
|
|
|
|
|
|
|
/** Constuctor */ |
|
|
|
CharacterInputEvent() noexcept |
|
|
|
: BaseEvent(), |
|
|
|
keycode(0), |
|
|
|
character(0), |
|
|
|
string{'\0','\0','\0','\0','\0','\0','\0','\0'} {} |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|
Mouse press or release event. |
|
|
|
|
|
|
|
@a button The button number starting from 1 (1 = left, 2 = middle, 3 = right). |
|
|
|
@a press True if the button was pressed, false if released. |
|
|
|
@a pos The widget-relative coordinates of the pointer. |
|
|
|
@see onMouse |
|
|
|
*/ |
|
|
|
struct MouseEvent : BaseEvent { |
|
|
|
int button; |
|
|
|
uint button; |
|
|
|
bool press; |
|
|
|
Point<int> pos; |
|
|
|
Point<double> pos; |
|
|
|
|
|
|
|
/** Constuctor */ |
|
|
|
MouseEvent() noexcept |
|
|
|
: BaseEvent(), |
|
|
|
button(0), |
|
|
|
press(false), |
|
|
|
pos(0, 0) {} |
|
|
|
pos(0.0, 0.0) {} |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|
Mouse motion event. |
|
|
|
|
|
|
|
@a pos The widget-relative coordinates of the pointer. |
|
|
|
@see onMotion |
|
|
|
*/ |
|
|
|
struct MotionEvent : BaseEvent { |
|
|
|
Point<int> pos; |
|
|
|
Point<double> pos; |
|
|
|
|
|
|
|
/** Constuctor */ |
|
|
|
MotionEvent() noexcept |
|
|
|
: BaseEvent(), |
|
|
|
pos(0, 0) {} |
|
|
|
pos(0.0, 0.0) {} |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|
Mouse scroll event. |
|
|
|
|
|
|
|
The scroll distance is expressed in "lines", |
|
|
|
an arbitrary unit that corresponds to a single tick of a detented mouse wheel. |
|
|
|
For example, `delta.y` = 1.0 scrolls 1 line up. |
|
|
|
Some systems and devices support finer resolution and/or higher values for fast scrolls, |
|
|
|
so programs should handle any value gracefully. |
|
|
|
|
|
|
|
@a pos The widget-relative coordinates of the pointer. |
|
|
|
@a delta The scroll distance. |
|
|
|
@see onScroll |
|
|
|
*/ |
|
|
|
struct ScrollEvent : BaseEvent { |
|
|
|
Point<int> pos; |
|
|
|
Point<float> delta; |
|
|
|
Point<double> pos; |
|
|
|
Point<double> delta; |
|
|
|
|
|
|
|
/** Constuctor */ |
|
|
|
ScrollEvent() noexcept |
|
|
|
: BaseEvent(), |
|
|
|
pos(0, 0), |
|
|
|
delta(0.0f, 0.0f) {} |
|
|
|
pos(0.0, 0.0), |
|
|
|
delta(0.0, 0.0) {} |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
@@ -318,12 +378,14 @@ public: |
|
|
|
/** |
|
|
|
Check if this widget contains the point defined by @a x and @a y. |
|
|
|
*/ |
|
|
|
bool contains(int x, int y) const noexcept; |
|
|
|
template<typename T> |
|
|
|
bool contains(T x, T y) const noexcept; |
|
|
|
|
|
|
|
/** |
|
|
|
Check if this widget contains the point @a pos. |
|
|
|
*/ |
|
|
|
bool contains(const Point<int>& pos) const noexcept; |
|
|
|
template<typename T> |
|
|
|
bool contains(const Point<T>& pos) const noexcept; |
|
|
|
|
|
|
|
/** |
|
|
|
Tell this widget's window to repaint itself. |
|
|
|