Represent and recognise simple event conditions. More...
#include <vgui_event_condition.h>
Public Types | |
enum | event_types { null_event, mouse_event, ascii_char_event, key_event } |
Public Member Functions | |
void | init (vgui_key k, vgui_key ascii_char, vgui_button b, vgui_modifier m, bool is_pressed, bool is_on, event_types use_event) |
Initialise event condition and check for impossible events. | |
vgui_event_condition () | |
Constructor - create a default event condition. | |
vgui_event_condition (vgui_key ascii_code, bool is_pressed=true) | |
Constructor for a key press event condition (using ascii char). | |
vgui_event_condition (vgui_key k, vgui_modifier m, bool is_pressed=true) | |
Constructor for a key press event condition (using key and modifier). | |
vgui_event_condition (vgui_button b, vgui_modifier m=vgui_MODIFIER_NULL, bool is_pressed=true) | |
Constructor for a mouse button press event condition. | |
void | enable (bool v=true) |
void | disable (bool v=true) |
bool | operator() (vgui_event const &e) const |
E.g. if (c_mouse_spin(e)). | |
bool | operator() (vgui_key k, vgui_modifier m) const |
bool | operator() (vgui_button b, vgui_modifier m) const |
vcl_string | as_string (int field_width=0) const |
Text representation such as "shift-middle" or "ctrl-K". | |
Public Attributes | |
bool | on |
bool | pressed |
vgui_key | key |
vgui_key | ascii_char |
vgui_button | button |
vgui_modifier | modifier |
event_types | how_checked |
Represent and recognise simple event conditions.
This makes it easy to change the key/mouse combination that causes one's tableau to do something.
The key is now always lower case. ascii_char contains the actual character returned by the keyboard. To construct a vgui_event_condition to detect a SHIFT+b event you can do either:
vgui_event_condition my_ec(vgui_key('b'), vgui_SHIFT);
or
vgui_event_condition my_ec(vgui_key('B');
The point about vgui_event_condition is that it should not be constructed just before you check the event, but placed in a standard place in the object to
(a) Make it easy to see the list of handled events
(b) Make it easy to change the keys/mouse gestures to which an action is bound. For example, if my 3D viewer tableau uses left mouse to rotate in 3D, and I wish to put it into a 2D zoomer tableau which uses left mouse to zoom, I need change one of them. If you don't use vgui_event_condition, you need to edit the code, which means other people can't use left mouse.
Concrete example: my_tableau spins a 3D model
struct my_tableau { void handle(vgui_event); vgui_event_condition c_rotate; // event which initiates rotating vgui_event_condition c_translate; vgui_event_condition c_scale; vgui_event_condition c_zoom; };
Note that the event conditions are stored in the object, not hard-coded in the handle routine. This means they can be changed by client code without modifying my_tableau.cxx
One might think it would be better to have all tableaux to use unique event codes, and maybe it is for the core tableaux, but we can't have someone use ctrl+shift+3rd button because it's the only one free, when for their application (movie player shuttle action?) it may be the application's most natural action, and should be on left-mouse.
Definition at line 82 of file vgui_event_condition.h.
Definition at line 84 of file vgui_event_condition.h.
vgui_event_condition::vgui_event_condition | ( | ) |
Constructor - create a default event condition.
Default constructor.
This type of event condition will never be triggered.
Definition at line 49 of file vgui_event_condition.cxx.
vgui_event_condition::vgui_event_condition | ( | vgui_key | ascii_code, |
bool | is_pressed = true |
||
) |
Constructor for a key press event condition (using ascii char).
Definition at line 57 of file vgui_event_condition.cxx.
vgui_event_condition::vgui_event_condition | ( | vgui_key | k, |
vgui_modifier | m, | ||
bool | is_pressed = true |
||
) |
Constructor for a key press event condition (using key and modifier).
Definition at line 66 of file vgui_event_condition.cxx.
vgui_event_condition::vgui_event_condition | ( | vgui_button | b, |
vgui_modifier | m = vgui_MODIFIER_NULL , |
||
bool | is_pressed = true |
||
) |
Constructor for a mouse button press event condition.
Definition at line 73 of file vgui_event_condition.cxx.
vcl_string vgui_event_condition::as_string | ( | int | field_width = 0 | ) | const |
Text representation such as "shift-middle" or "ctrl-K".
Return a string describing the event condition.
If field_width is supplied, pad to that width.
Definition at line 131 of file vgui_event_condition.cxx.
void vgui_event_condition::disable | ( | bool | v = true | ) | [inline] |
Definition at line 113 of file vgui_event_condition.h.
void vgui_event_condition::enable | ( | bool | v = true | ) | [inline] |
Definition at line 112 of file vgui_event_condition.h.
void vgui_event_condition::init | ( | vgui_key | k, |
vgui_key | ascii_char, | ||
vgui_button | b, | ||
vgui_modifier | m, | ||
bool | is_pressed, | ||
bool | is_on, | ||
event_types | use_event | ||
) |
Initialise event condition and check for impossible events.
Definition at line 18 of file vgui_event_condition.cxx.
bool vgui_event_condition::operator() | ( | vgui_event const & | e | ) | const |
E.g. if (c_mouse_spin(e)).
Definition at line 80 of file vgui_event_condition.cxx.
bool vgui_event_condition::operator() | ( | vgui_key | k, |
vgui_modifier | m | ||
) | const |
Definition at line 113 of file vgui_event_condition.cxx.
bool vgui_event_condition::operator() | ( | vgui_button | b, |
vgui_modifier | m | ||
) | const |
Definition at line 122 of file vgui_event_condition.cxx.
Definition at line 89 of file vgui_event_condition.h.
Definition at line 90 of file vgui_event_condition.h.
Definition at line 92 of file vgui_event_condition.h.
Definition at line 88 of file vgui_event_condition.h.
Definition at line 91 of file vgui_event_condition.h.
Definition at line 86 of file vgui_event_condition.h.
Definition at line 87 of file vgui_event_condition.h.