8#define MAX_MOD_LENGTH 5
10static const char* mod_names[4] = {
"Shift+",
"Alt+",
"Ctrl+",
"Meta+" };
13#define MAX_TOG_LENGTH 10
14static int nr_togs = 3;
15static const char* tog_names[3] = {
"CapsLock",
"NumLock",
"ScrollLock" };
20event::event(
unsigned int _kind,
unsigned char _modifiers,
unsigned char _toggle_keys,
double _time)
21 : kind(_kind), flags(0), modifiers(_modifiers), toggle_keys(_toggle_keys), time(_time)
40 for (
int mi=0; mi<nr_mods; ++mi)
41 if ( (modifiers&mod_ids[mi]) != 0)
50 for (
int ti=0; ti<nr_togs; ++ti)
51 if ( (toggle_keys&tog_ids[ti]) != 0) {
59unsigned char stream_in_toggle_keys(std::istream& is)
66 for (ti = 0; ti < nr_togs; ++ti)
67 if (tog_names[ti][0] == c)
72 int n = (int)std::string(tog_names[ti]).size();
73 int buffer[MAX_TOG_LENGTH];
74 for (
int i=1; i<n; ++i) {
75 buffer[i-1] = is.get();
80 if (tog_names[ti][i] != c) {
81 for (
int j = i; j > 0; ) {
83 is.putback(buffer[j]);
93unsigned char stream_in_modifier(std::istream& is)
100 for (mi = 0; mi < nr_mods; ++mi)
101 if (mod_names[mi][0] == c)
106 int n = (int)std::string(mod_names[mi]).size();
107 int buffer[MAX_MOD_LENGTH];
108 for (
int i=1; i<n; ++i) {
109 buffer[i-1] = is.get();
114 if (mod_names[mi][i] != c) {
115 for (
int j = i; j > 0; ) {
117 is.putback(buffer[j]);
128 unsigned char modifiers = 0;
130 unsigned char m = stream_in_modifier(is);
141 const char* flag_strs[] = {
142 "Multi",
"Drag&Drop",
"Gamepad",
"VR"
150 const char* kind_strs[] = {
"none",
"key",
"mouse",
"throttle",
"stick",
"pose" };
152 os << kind_strs[
kind] <<
"[" << std::fixed << std::showpoint << std::setprecision(3) <<
time <<
"] ";
178 for (
unsigned i = 0; i < 4; ++i) {
193 std::cerr <<
"event::stream_in not implemented yet" << std::endl;
254 static unsigned char mods = 0;
262#include <cgv/config/lib_end.h>
double get_time() const
return the time of the event in seconds
void set_toggle_keys(unsigned char _toggle_keys)
set the state of the toggle keys
void set_modifiers(unsigned char _modifiers)
set the modifiers
virtual void * get_device_id() const
return the device id, by default returns 0
unsigned get_kind() const
return, what kind of event this is, typically a value from the EventId enum
unsigned char get_toggle_keys() const
return the state of the toggle keys as values from EventToggleKeys combined with a logical or-operati...
virtual void stream_out(std::ostream &os) const
write to stream
unsigned char kind
store which kind of event we have
unsigned char toggle_keys
store the active toggle keys
void set_kind(unsigned char _kind)
set the kind of the event
unsigned char modifiers
store the active modifiers
unsigned get_flags() const
return the event flags
virtual ~event()
virtual destructor for events
double time
store the time of the event in seconds
unsigned char flags
store event flags
unsigned char get_modifiers() const
return the active modifiers as values from EventModifier combined with a logical or-operation
virtual void stream_in(std::istream &is)
read from stream
void set_flags(unsigned char _flags)
return the set the event flags
event(unsigned int _kind=EID_NONE, unsigned char _modifiers=0, unsigned char _toggle_keys=0, double _time=0)
construct event from its kind
void set_time(const double &_time)
set the time of the event
unsigned char stream_in_modifiers(std::istream &is)
read modifiers in string format from a stream and set the passed reference to EventModifier s ored to...
std::string get_modifier_string(EventModifier modifiers)
convert a modifier combination into a readable string ending on a '+' sign if not empty,...
unsigned char & ref_current_modifiers()
read out the current modifiers
EventToggleKeys
define constants for toggle keys
@ ETK_SCROLL_LOCK
scroll lock
EventModifier
define constants for event modifiers
@ EM_META
meta modifier (windows or mac key)
std::string get_toggle_keys_string(EventToggleKeys toggle_keys)
convert a toggle key combination into a readable string separated by '+' signs, i....
@ EF_DND
whether mouse has a drag and drop target attached
@ EF_MULTI
whether event is tagged with id of the device that generated the event
@ EF_VR
whether event is from VR kit
@ EF_PAD
whether event is from gamepad
char to_lower(char c)
convert char to lower case
char to_upper(char c)
convert char to upper case
Helper functions to process strings.