Panda3D
Loading...
Searching...
No Matches
mouseWatcherParameter.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 mouseWatcherParameter.I
10 * @author drose
11 * @date 2001-07-06
12 */
13
14/**
15 *
16 */
17INLINE MouseWatcherParameter::
18MouseWatcherParameter() {
19 _keycode = 0;
20 _flags = 0;
21}
22
23/**
24 *
25 */
26INLINE MouseWatcherParameter::
27MouseWatcherParameter(const MouseWatcherParameter &copy) :
28 _button(copy._button),
29 _keycode(copy._keycode),
30 _mods(copy._mods),
31 _mouse(copy._mouse),
32 _flags(copy._flags)
33{
34}
35
36/**
37 *
38 */
39INLINE void MouseWatcherParameter::
40operator = (const MouseWatcherParameter &copy) {
41 _button = copy._button;
42 _keycode = copy._keycode;
43 _mods = copy._mods;
44 _mouse = copy._mouse;
45 _flags = copy._flags;
46}
47
48/**
49 *
50 */
51INLINE MouseWatcherParameter::
52~MouseWatcherParameter() {
53}
54
55/**
56 * Sets the mouse or keyboard button that generated this event, if any.
57 */
59set_button(const ButtonHandle &button) {
60 _button = button;
61 _flags |= F_has_button;
62}
63
64/**
65 * Sets the state of the "keyrepeat" flag. This is true if a button-press
66 * event was generated due to keyrepeat, or false if it is an original button
67 * press.
68 */
70set_keyrepeat(bool flag) {
71 if (flag) {
72 _flags |= F_is_keyrepeat;
73 } else {
74 _flags &= ~F_is_keyrepeat;
75 }
76}
77
78/**
79 * Sets the keycode associated with this event, if any.
80 */
82set_keycode(int keycode) {
83 _keycode = keycode;
84 _flags |= F_has_keycode;
85}
86
87/**
88 * Sets the candidate string associated with this event, if any.
89 */
91set_candidate(const std::wstring &candidate_string,
92 size_t highlight_start, size_t highlight_end,
93 size_t cursor_pos) {
94 _candidate_string = candidate_string;
95 _highlight_start = highlight_start;
96 _highlight_end = highlight_end;
97 _cursor_pos = cursor_pos;
98 _flags |= F_has_candidate;
99}
100
101/**
102 * Sets the modifier buttons that were being held while this event was
103 * generated.
104 */
107 _mods = mods;
108}
109
110/**
111 * Sets the mouse position that was current at the time the event was
112 * generated.
113 */
115set_mouse(const LPoint2 &mouse) {
116 _mouse = mouse;
117 _flags |= F_has_mouse;
118}
119
120/**
121 * Sets the state of the "outside" flag. This is true if the mouse was
122 * outside the region at the time the event was generated, false otherwise.
123 * This only has meaning for "release" events.
124 */
126set_outside(bool flag) {
127 if (flag) {
128 _flags |= F_is_outside;
129 } else {
130 _flags &= ~F_is_outside;
131 }
132}
133
134/**
135 * Returns true if this parameter has an associated mouse or keyboard button,
136 * false otherwise.
137 */
139has_button() const {
140 return (_flags & F_has_button) != 0;
141}
142
143/**
144 * Returns the mouse or keyboard button associated with this event. If
145 * has_button(), above, returns false, this returns ButtonHandle::none().
146 */
148get_button() const {
149 return _button;
150}
151
152/**
153 * Returns true if the button-down even was generated due to keyrepeat, or
154 * false if it was an original button down.
155 */
157is_keyrepeat() const {
158 return (_flags & F_is_keyrepeat) != 0;
159}
160
161/**
162 * Returns true if this parameter has an associated keycode, false otherwise.
163 */
165has_keycode() const {
166 return (_flags & F_has_keycode) != 0;
167}
168
169/**
170 * Returns the keycode associated with this event. If has_keycode(), above,
171 * returns false, this returns 0.
172 */
174get_keycode() const {
175 return _keycode;
176}
177
178/**
179 * Returns true if this parameter has an associated candidate string, false
180 * otherwise.
181 */
183has_candidate() const {
184 return (_flags & F_has_candidate) != 0;
185}
186
187/**
188 * Returns the candidate string associated with this event. If
189 * has_candidate(), above, returns false, this returns the empty string.
190 */
191INLINE const std::wstring &MouseWatcherParameter::
192get_candidate_string() const {
193 return _candidate_string;
194}
195
196/**
197 * Returns the candidate string associated with this event. If
198 * has_candidate(), above, returns false, this returns the empty string.
199 */
204
205/**
206 * Returns the candidate string associated with this event. If
207 * has_candidate(), above, returns false, this returns the empty string.
208 */
209INLINE std::string MouseWatcherParameter::
210get_candidate_string_encoded(TextEncoder::Encoding encoding) const {
211 return TextEncoder::encode_wtext(_candidate_string, encoding);
212}
213
214/**
215 * Returns the first highlighted character in the candidate string.
216 */
218get_highlight_start() const {
219 return _highlight_start;
220}
221
222/**
223 * Returns one more than the last highlighted character in the candidate
224 * string.
225 */
227get_highlight_end() const {
228 return _highlight_end;
229}
230
231/**
232 * Returns the position of the user's edit cursor within the candidate string.
233 */
235get_cursor_pos() const {
236 return _cursor_pos;
237}
238
239/**
240 * Returns the set of modifier buttons that were being held down while the
241 * event was generated.
242 */
244get_modifier_buttons() const {
245 return _mods;
246}
247
248/**
249 * Returns true if this parameter has an associated mouse position, false
250 * otherwise.
251 */
253has_mouse() const {
254 return (_flags & F_has_mouse) != 0;
255}
256
257/**
258 * Returns the mouse position at the time the event was generated, in the
259 * normalized range (-1 .. 1). It is valid to call this only if has_mouse()
260 * returned true.
261 */
262INLINE const LPoint2 &MouseWatcherParameter::
263get_mouse() const {
264 nassertr(has_mouse(), _mouse);
265 return _mouse;
266}
267
268/**
269 * Returns true if the mouse was outside the region at the time the event was
270 * generated, false otherwise. This is only valid for "release" type events.
271 */
273is_outside() const {
274 return (_flags & F_is_outside) != 0;
275}
276
277INLINE std::ostream &
278operator << (std::ostream &out, const MouseWatcherParameter &parm) {
279 parm.output(out);
280 return out;
281}
A ButtonHandle represents a single button from any device, including keyboard buttons and mouse butto...
This class monitors the state of a number of individual buttons and tracks whether each button is kno...
This is sent along as a parameter to most events generated for a region to indicate the mouse and but...
void set_keyrepeat(bool flag)
Sets the state of the "keyrepeat" flag.
const ModifierButtons & get_modifier_buttons() const
Returns the set of modifier buttons that were being held down while the event was generated.
bool has_candidate() const
Returns true if this parameter has an associated candidate string, false otherwise.
std::string get_candidate_string_encoded() const
Returns the candidate string associated with this event.
const std::wstring & get_candidate_string() const
Returns the candidate string associated with this event.
ButtonHandle get_button() const
Returns the mouse or keyboard button associated with this event.
void set_mouse(const LPoint2 &mouse)
Sets the mouse position that was current at the time the event was generated.
void set_keycode(int keycode)
Sets the keycode associated with this event, if any.
size_t get_highlight_end() const
Returns one more than the last highlighted character in the candidate string.
bool has_mouse() const
Returns true if this parameter has an associated mouse position, false otherwise.
void set_modifier_buttons(const ModifierButtons &mods)
Sets the modifier buttons that were being held while this event was generated.
const LPoint2 & get_mouse() const
Returns the mouse position at the time the event was generated, in the normalized range (-1 .
bool has_keycode() const
Returns true if this parameter has an associated keycode, false otherwise.
bool is_keyrepeat() const
Returns true if the button-down even was generated due to keyrepeat, or false if it was an original b...
size_t get_highlight_start() const
Returns the first highlighted character in the candidate string.
size_t get_cursor_pos() const
Returns the position of the user's edit cursor within the candidate string.
void set_candidate(const std::wstring &candidate_string, size_t highlight_start, size_t higlight_end, size_t cursor_pos)
Sets the candidate string associated with this event, if any.
void set_outside(bool flag)
Sets the state of the "outside" flag.
bool has_button() const
Returns true if this parameter has an associated mouse or keyboard button, false otherwise.
int get_keycode() const
Returns the keycode associated with this event.
bool is_outside() const
Returns true if the mouse was outside the region at the time the event was generated,...
void set_button(const ButtonHandle &button)
Sets the mouse or keyboard button that generated this event, if any.
get_default_encoding
Specifies the default encoding to be used for all subsequently created TextEncoder objects.
Definition textEncoder.h:54
std::string encode_wtext(const std::wstring &wtext) const
Encodes a wide-text string into a single-char string, according to the current encoding.