Panda3D
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  */
17 INLINE MouseWatcherParameter::
18 MouseWatcherParameter() {
19  _keycode = 0;
20  _flags = 0;
21 }
22 
23 /**
24  *
25  */
26 INLINE MouseWatcherParameter::
27 MouseWatcherParameter(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  */
39 INLINE void MouseWatcherParameter::
40 operator = (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  */
51 INLINE MouseWatcherParameter::
52 ~MouseWatcherParameter() {
53 }
54 
55 /**
56  * Sets the mouse or keyboard button that generated this event, if any.
57  */
58 INLINE void MouseWatcherParameter::
59 set_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  */
69 INLINE void MouseWatcherParameter::
70 set_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  */
81 INLINE void MouseWatcherParameter::
82 set_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  */
90 INLINE void MouseWatcherParameter::
91 set_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  */
105 INLINE void MouseWatcherParameter::
107  _mods = mods;
108 }
109 
110 /**
111  * Sets the mouse position that was current at the time the event was
112  * generated.
113  */
114 INLINE void MouseWatcherParameter::
115 set_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  */
125 INLINE void MouseWatcherParameter::
126 set_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  */
138 INLINE bool MouseWatcherParameter::
139 has_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  */
148 get_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  */
156 INLINE bool MouseWatcherParameter::
157 is_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  */
164 INLINE bool MouseWatcherParameter::
165 has_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  */
173 INLINE int MouseWatcherParameter::
174 get_keycode() const {
175  return _keycode;
176 }
177 
178 /**
179  * Returns true if this parameter has an associated candidate string, false
180  * otherwise.
181  */
182 INLINE bool MouseWatcherParameter::
183 has_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  */
191 INLINE const std::wstring &MouseWatcherParameter::
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  */
200 INLINE std::string MouseWatcherParameter::
202  return get_candidate_string_encoded(TextEncoder::get_default_encoding());
203 }
204 
205 /**
206  * Returns the candidate string associated with this event. If
207  * has_candidate(), above, returns false, this returns the empty string.
208  */
209 INLINE std::string MouseWatcherParameter::
210 get_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  */
217 INLINE size_t MouseWatcherParameter::
219  return _highlight_start;
220 }
221 
222 /**
223  * Returns one more than the last highlighted character in the candidate
224  * string.
225  */
226 INLINE size_t MouseWatcherParameter::
228  return _highlight_end;
229 }
230 
231 /**
232  * Returns the position of the user's edit cursor within the candidate string.
233  */
234 INLINE size_t MouseWatcherParameter::
235 get_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  */
245  return _mods;
246 }
247 
248 /**
249  * Returns true if this parameter has an associated mouse position, false
250  * otherwise.
251  */
252 INLINE bool MouseWatcherParameter::
253 has_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  */
262 INLINE const LPoint2 &MouseWatcherParameter::
263 get_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  */
272 INLINE bool MouseWatcherParameter::
273 is_outside() const {
274  return (_flags & F_is_outside) != 0;
275 }
276 
277 INLINE std::ostream &
278 operator << (std::ostream &out, const MouseWatcherParameter &parm) {
279  parm.output(out);
280  return out;
281 }
std::string get_candidate_string_encoded() const
Returns the candidate string associated with this event.
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.
This class monitors the state of a number of individual buttons and tracks whether each button is kno...
const ModifierButtons & get_modifier_buttons() const
Returns the set of modifier buttons that were being held down while the event was generated.
int get_keycode() const
Returns the keycode associated with this event.
void set_button(const ButtonHandle &button)
Sets the mouse or keyboard button that generated this event, if any.
bool is_outside() const
Returns true if the mouse was outside the region at the time the event was generated,...
A ButtonHandle represents a single button from any device, including keyboard buttons and mouse butto...
Definition: buttonHandle.h:26
void set_keyrepeat(bool flag)
Sets the state of the "keyrepeat" flag.
bool is_keyrepeat() const
Returns true if the button-down even was generated due to keyrepeat, or false if it was an original b...
bool has_button() const
Returns true if this parameter has an associated mouse or keyboard button, false otherwise.
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.
const LPoint2 & get_mouse() const
Returns the mouse position at the time the event was generated, in the normalized range (-1 .
size_t get_cursor_pos() const
Returns the position of the user's edit cursor within the candidate string.
void set_keycode(int keycode)
Sets the keycode associated with this event, if any.
std::string encode_wtext(const std::wstring &wtext) const
Encodes a wide-text string into a single-char string, according to the current encoding.
Definition: textEncoder.I:481
bool has_candidate() const
Returns true if this parameter has an associated candidate string, false otherwise.
void set_outside(bool flag)
Sets the state of the "outside" flag.
size_t get_highlight_start() const
Returns the first highlighted character in the candidate string.
This is sent along as a parameter to most events generated for a region to indicate the mouse and but...
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.
size_t get_highlight_end() const
Returns one more than the last highlighted character in the candidate string.
const std::wstring & get_candidate_string() const
Returns the candidate string associated with this event.
bool has_keycode() const
Returns true if this parameter has an associated keycode, false otherwise.