Panda3D
Loading...
Searching...
No Matches
buttonEvent.I
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file buttonEvent.I
10 * @author drose
11 * @date 2000-03-01
12 */
13
14/**
15 *
16 */
17INLINE ButtonEvent::
18ButtonEvent() :
19 _button(ButtonHandle::none()),
20 _keycode(0),
21 _type(T_down),
22 _time(0.0)
23{
24}
25
26/**
27 *
28 */
29INLINE ButtonEvent::
30ButtonEvent(ButtonHandle button, ButtonEvent::Type type, double time) :
31 _button(button),
32 _keycode(0),
33 _highlight_start(0),
34 _highlight_end(0),
35 _type(type),
36 _time(time)
37{
38}
39
40/**
41 *
42 */
43INLINE ButtonEvent::
44ButtonEvent(int keycode, double time) :
45 _button(ButtonHandle::none()),
46 _keycode(keycode),
47 _highlight_start(0),
48 _highlight_end(0),
49 _type(T_keystroke),
50 _time(time)
51{
52}
53
54/**
55 *
56 */
57INLINE ButtonEvent::
58ButtonEvent(const std::wstring &candidate_string, size_t highlight_start,
59 size_t highlight_end, size_t cursor_pos) :
60 _button(ButtonHandle::none()),
61 _keycode(0),
62 _candidate_string(candidate_string),
63 _highlight_start(highlight_start),
64 _highlight_end(highlight_end),
65 _cursor_pos(cursor_pos),
66 _type(T_candidate),
67 _time(ClockObject::get_global_clock()->get_frame_time())
68{
69}
70
71/**
72 *
73 */
74INLINE ButtonEvent::
75ButtonEvent(const ButtonEvent &copy) :
76 _button(copy._button),
77 _keycode(copy._keycode),
78 _candidate_string(copy._candidate_string),
79 _highlight_start(copy._highlight_start),
80 _highlight_end(copy._highlight_end),
81 _cursor_pos(copy._cursor_pos),
82 _type(copy._type),
83 _time(copy._time)
84{
85}
86
87/**
88 *
89 */
90INLINE void ButtonEvent::
91operator = (const ButtonEvent &copy) {
92 _button = copy._button;
93 _keycode = copy._keycode;
94 _candidate_string = copy._candidate_string;
95 _highlight_start = copy._highlight_start;
96 _highlight_end = copy._highlight_end;
97 _cursor_pos = copy._cursor_pos;
98 _type = copy._type;
99 _time = copy._time;
100}
101
102/**
103 * The equality operator does not consider time significant.
104 */
105INLINE bool ButtonEvent::
106operator == (const ButtonEvent &other) const {
107 return (_button == other._button &&
108 _keycode == other._keycode &&
109 _type == other._type);
110}
111
112/**
113 *
114 */
115INLINE bool ButtonEvent::
116operator != (const ButtonEvent &other) const {
117 return !operator == (other);
118}
119
120/**
121 *
122 */
123INLINE bool ButtonEvent::
124operator < (const ButtonEvent &other) const {
125 if (_button != other._button) {
126 return _button < other._button;
127 }
128 if (_keycode != other._keycode) {
129 return _keycode < other._keycode;
130 }
131
132 return _type < other._type;
133}
134
135/**
136 * Calls button_down() or button_up(), as appropriate, according to the
137 * ButtonEvent.
138 */
139INLINE bool ButtonEvent::
140update_mods(ModifierButtons &mods) const {
141 switch (_type) {
142 case T_down:
143 return mods.button_down(_button);
144
145 case T_up:
146 return mods.button_up(_button);
147
148 default:
149 return false;
150 }
151}
152
153/**
154 *
155 */
156INLINE ButtonHandle ButtonEvent::
157get_button() const {
158 return _button;
159}
160
161/**
162 *
163 */
164INLINE int ButtonEvent::
165get_keycode() const {
166 return _keycode;
167}
168
169/**
170 *
171 */
172INLINE ButtonEvent::Type ButtonEvent::
173get_type() const {
174 return _type;
175}
176
177/**
178 *
179 */
180INLINE double ButtonEvent::
181get_time() const {
182 return _time;
183}
Records a button event of some kind.
Definition buttonEvent.h:49
bool operator==(const ButtonEvent &other) const
The equality operator does not consider time significant.
bool update_mods(ModifierButtons &mods) const
Calls button_down() or button_up(), as appropriate, according to the ButtonEvent.
A ButtonHandle represents a single button from any device, including keyboard buttons and mouse butto...
A ClockObject keeps track of elapsed real time and discrete time.
Definition clockObject.h:58
This class monitors the state of a number of individual buttons and tracks whether each button is kno...
bool button_up(ButtonHandle button)
Records that a particular button has been released.
bool button_down(ButtonHandle button)
Records that a particular button has been pressed.