cgv
Loading...
Searching...
No Matches
key_event.cxx
1#include "key_event.h"
2#include "shortcut.h"
3
4namespace cgv {
5 namespace gui {
6
7
10{
11 switch (action) {
12 case KA_PRESS: return "press";
13 case KA_RELEASE: return "release";
14 case KA_REPEAT: return "repeat";
15 default: return "unknown";
16 }
17}
18
19// construct a key event from its textual description
20key_event::key_event(unsigned short _key, KeyAction _action, unsigned char _char, unsigned char _modifiers, unsigned char _toggle_keys, double _time, int _x, int _y)
21 : event(EID_KEY,_modifiers, _toggle_keys, _time), key(_key), action(_action), character(_char), x(_x), y(_y)
22{
23}
24
25// write to stream
26void key_event::stream_out(std::ostream& os) const
27{
29 os << get_key_string(key).c_str();
30 switch (action) {
31 case KA_RELEASE:
32 os << " up";
33 break;
34 case KA_PRESS:
35 if (get_char())
36 os << " = '" << get_char() << "'";
37 break;
38 case KA_REPEAT:
39 os << " repeat ";
40 break;
41 }
42}
43
44// read from stream
45void key_event::stream_in(std::istream&)
46{
47 std::cerr << "key_event::stream_in not implemented yet" << std::endl;
48}
49
50//
51unsigned short key_event::get_key() const
52{
53 return key;
54}
55//
56void key_event::set_key(unsigned short _key)
57{
58 key = _key;
59}
60//
61unsigned char key_event::get_char() const
62{
63 return character;
64}
65//
66void key_event::set_char(unsigned char _char)
67{
68 character = _char;
69}
70//
72{
73 return (KeyAction)action;
74}
75//
77{
78 action = _action;
79}
80//
81short key_event::get_x() const
82{
83 return x;
84}
85//
86short key_event::get_y() const
87{
88 return y;
89}
90
91 }
92}
virtual void stream_out(std::ostream &os) const
write to stream
Definition event.cxx:139
unsigned char get_char() const
return the key as a character
Definition key_event.cxx:61
short get_x() const
current mouse x position (origin is top-left of window)
Definition key_event.cxx:81
short x
x position of mouse pointer
Definition key_event.h:32
key_event(unsigned short _key=0, KeyAction _action=KA_PRESS, unsigned char _char=0, unsigned char _modifiers=0, unsigned char _toggle_keys=0, double _time=0, int _x=0, int _y=0)
construct a key event from its textual description
Definition key_event.cxx:20
void set_action(KeyAction _action)
set the key event action
Definition key_event.cxx:76
unsigned char character
store the corresponding ascii character
Definition key_event.h:30
void set_key(unsigned short _key)
set the key
Definition key_event.cxx:56
short get_y() const
current mouse y position (origin is top-left of window)
Definition key_event.cxx:86
void set_char(unsigned char _char)
set the alpha numeric character
Definition key_event.cxx:66
unsigned char action
store whether
Definition key_event.h:28
void stream_in(std::istream &is)
read from stream
Definition key_event.cxx:45
void stream_out(std::ostream &os) const
write to stream
Definition key_event.cxx:26
unsigned short key
store the pressed key
Definition key_event.h:26
unsigned short get_key() const
return the key being a capital letter, digit or a value from the Keys enum
Definition key_event.cxx:51
KeyAction get_action() const
return the key event action
Definition key_event.cxx:71
short y
y position of mouse pointer
Definition key_event.h:34
KeyAction
different actions that a key can perform
Definition key_event.h:12
@ KA_REPEAT
key repeated press action
Definition key_event.h:15
@ KA_PRESS
key press action
Definition key_event.h:14
@ KA_RELEASE
key release action
Definition key_event.h:13
std::string get_key_action_string(KeyAction action)
convert a key action into a readable string
Definition key_event.cxx:9
@ EID_KEY
id for key event
Definition event.h:17
std::string get_key_string(unsigned short key)
convert a key code into a readable string
Definition shortcut.cxx:70
the cgv namespace
Definition print.h:11