forked from panda3d/panda3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuttonEvent.cxx
More file actions
135 lines (117 loc) · 3.08 KB
/
buttonEvent.cxx
File metadata and controls
135 lines (117 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/**
* PANDA 3D SOFTWARE
* Copyright (c) Carnegie Mellon University. All rights reserved.
*
* All use of this software is subject to the terms of the revised BSD
* license. You should have received a copy of this license along
* with this source code in a file named "LICENSE."
*
* @file buttonEvent.cxx
* @author drose
* @date 2000-03-01
*/
#include "buttonEvent.h"
#include "datagram.h"
#include "datagramIterator.h"
#include "buttonRegistry.h"
#include "textEncoder.h"
/**
*
*/
void ButtonEvent::
output(std::ostream &out) const {
switch (_type) {
case T_down:
out << "button " << _button << " down";
break;
case T_resume_down:
out << "button " << _button << " resume down";
break;
case T_up:
out << "button " << _button << " up";
break;
case T_repeat:
out << "button " << _button << " repeat";
break;
case T_keystroke:
out << "keystroke " << _keycode;
break;
case T_candidate:
out << "candidate "
<< TextEncoder::encode_wtext(_candidate_string,
TextEncoder::get_default_encoding());
break;
case T_move:
out << "move";
break;
case T_raw_down:
out << "raw button " << _button << " down";
break;
case T_raw_up:
out << "raw button " << _button << " up";
break;
}
}
/**
* Writes the event into a datagram.
*/
void ButtonEvent::
write_datagram(Datagram &dg) const {
dg.add_uint8(_type);
switch (_type) {
case T_down:
case T_resume_down:
case T_up:
case T_repeat:
case T_raw_down:
case T_raw_up:
// We write the button name. This is not particularly compact, but
// presumably we don't get thousands of button events per frame, and it is
// robust as the button index may change between sessions but the button
// name will not.
dg.add_string(_button.get_name());
break;
case T_keystroke:
dg.add_uint16(_keycode);
break;
case T_candidate:
// We should probably store the wtext directly in the datagram rather than
// encoding it, but I don't feel like adding add_wstring() to datagram
// right now.
dg.add_string(TextEncoder::encode_wtext(_candidate_string,
TextEncoder::get_default_encoding()));
dg.add_uint16(_highlight_start);
dg.add_uint16(_highlight_end);
dg.add_uint16(_cursor_pos);
case T_move:
break;
}
}
/**
* Restores the event from the datagram.
*/
void ButtonEvent::
read_datagram(DatagramIterator &scan) {
_type = (Type)scan.get_uint8();
switch (_type) {
case T_down:
case T_resume_down:
case T_up:
case T_repeat:
case T_raw_down:
case T_raw_up:
_button = ButtonRegistry::ptr()->get_button(scan.get_string());
break;
case T_keystroke:
_keycode = scan.get_uint16();
break;
case T_candidate:
_candidate_string = TextEncoder::decode_text(scan.get_string(),
TextEncoder::get_default_encoding());
_highlight_start = scan.get_uint16();
_highlight_end = scan.get_uint16();
_cursor_pos = scan.get_uint16();
case T_move:
break;
}
}