Panda3D
 All Classes Functions Variables Enumerations
mouseWatcherParameter.I
1 // Filename: mouseWatcherParameter.I
2 // Created by: drose (06Jul01)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 
16 ////////////////////////////////////////////////////////////////////
17 // Function: MouseWatcherParameter::Constructor
18 // Access: Public
19 // Description:
20 ////////////////////////////////////////////////////////////////////
21 INLINE MouseWatcherParameter::
22 MouseWatcherParameter() {
23  _keycode = 0;
24  _flags = 0;
25 }
26 
27 ////////////////////////////////////////////////////////////////////
28 // Function: MouseWatcherParameter::Copy Constructor
29 // Access: Public
30 // Description:
31 ////////////////////////////////////////////////////////////////////
32 INLINE MouseWatcherParameter::
33 MouseWatcherParameter(const MouseWatcherParameter &copy) :
34  _button(copy._button),
35  _keycode(copy._keycode),
36  _mods(copy._mods),
37  _mouse(copy._mouse),
38  _flags(copy._flags)
39 {
40 }
41 
42 ////////////////////////////////////////////////////////////////////
43 // Function: MouseWatcherParameter::Copy Assignment Operator
44 // Access: Public
45 // Description:
46 ////////////////////////////////////////////////////////////////////
47 INLINE void MouseWatcherParameter::
48 operator = (const MouseWatcherParameter &copy) {
49  _button = copy._button;
50  _keycode = copy._keycode;
51  _mods = copy._mods;
52  _mouse = copy._mouse;
53  _flags = copy._flags;
54 }
55 
56 ////////////////////////////////////////////////////////////////////
57 // Function: MouseWatcherParameter::Destructor
58 // Access: Public
59 // Description:
60 ////////////////////////////////////////////////////////////////////
61 INLINE MouseWatcherParameter::
62 ~MouseWatcherParameter() {
63 }
64 
65 ////////////////////////////////////////////////////////////////////
66 // Function: MouseWatcherParameter::set_button
67 // Access: Public
68 // Description: Sets the mouse or keyboard button that generated this
69 // event, if any.
70 ////////////////////////////////////////////////////////////////////
71 INLINE void MouseWatcherParameter::
72 set_button(const ButtonHandle &button) {
73  _button = button;
74  _flags |= F_has_button;
75 }
76 
77 ////////////////////////////////////////////////////////////////////
78 // Function: MouseWatcherParameter::set_keyrepeat
79 // Access: Public
80 // Description: Sets the state of the "keyrepeat" flag. This is true
81 // if a button-press event was generated due to
82 // keyrepeat, or false if it is an original button
83 // press.
84 ////////////////////////////////////////////////////////////////////
85 INLINE void MouseWatcherParameter::
86 set_keyrepeat(bool flag) {
87  if (flag) {
88  _flags |= F_is_keyrepeat;
89  } else {
90  _flags &= ~F_is_keyrepeat;
91  }
92 }
93 
94 ////////////////////////////////////////////////////////////////////
95 // Function: MouseWatcherParameter::set_keycode
96 // Access: Public
97 // Description: Sets the keycode associated with this event, if any.
98 ////////////////////////////////////////////////////////////////////
99 INLINE void MouseWatcherParameter::
100 set_keycode(int keycode) {
101  _keycode = keycode;
102  _flags |= F_has_keycode;
103 }
104 
105 ////////////////////////////////////////////////////////////////////
106 // Function: MouseWatcherParameter::set_candidate
107 // Access: Public
108 // Description: Sets the candidate string associated with this event,
109 // if any.
110 ////////////////////////////////////////////////////////////////////
111 INLINE void MouseWatcherParameter::
112 set_candidate(const wstring &candidate_string,
113  size_t highlight_start, size_t highlight_end,
114  size_t cursor_pos) {
115  _candidate_string = candidate_string;
116  _highlight_start = highlight_start;
117  _highlight_end = highlight_end;
118  _cursor_pos = cursor_pos;
119  _flags |= F_has_candidate;
120 }
121 
122 ////////////////////////////////////////////////////////////////////
123 // Function: MouseWatcherParameter::set_modifier_buttons
124 // Access: Public
125 // Description: Sets the modifier buttons that were being held while
126 // this event was generated.
127 ////////////////////////////////////////////////////////////////////
128 INLINE void MouseWatcherParameter::
130  _mods = mods;
131 }
132 
133 ////////////////////////////////////////////////////////////////////
134 // Function: MouseWatcherParameter::set_mouse
135 // Access: Public
136 // Description: Sets the mouse position that was current at the time
137 // the event was generated.
138 ////////////////////////////////////////////////////////////////////
139 INLINE void MouseWatcherParameter::
140 set_mouse(const LPoint2 &mouse) {
141  _mouse = mouse;
142  _flags |= F_has_mouse;
143 }
144 
145 ////////////////////////////////////////////////////////////////////
146 // Function: MouseWatcherParameter::set_outside
147 // Access: Public
148 // Description: Sets the state of the "outside" flag. This is true
149 // if the mouse was outside the region at the time the
150 // event was generated, false otherwise. This only has
151 // meaning for "release" events.
152 ////////////////////////////////////////////////////////////////////
153 INLINE void MouseWatcherParameter::
154 set_outside(bool flag) {
155  if (flag) {
156  _flags |= F_is_outside;
157  } else {
158  _flags &= ~F_is_outside;
159  }
160 }
161 
162 ////////////////////////////////////////////////////////////////////
163 // Function: MouseWatcherParameter::has_button
164 // Access: Published
165 // Description: Returns true if this parameter has an associated
166 // mouse or keyboard button, false otherwise.
167 ////////////////////////////////////////////////////////////////////
168 INLINE bool MouseWatcherParameter::
169 has_button() const {
170  return (_flags & F_has_button) != 0;
171 }
172 
173 ////////////////////////////////////////////////////////////////////
174 // Function: MouseWatcherParameter::get_button
175 // Access: Published
176 // Description: Returns the mouse or keyboard button associated with
177 // this event. If has_button(), above, returns false,
178 // this returns ButtonHandle::none().
179 ////////////////////////////////////////////////////////////////////
181 get_button() const {
182  return _button;
183 }
184 
185 ////////////////////////////////////////////////////////////////////
186 // Function: MouseWatcherParameter::is_keyrepeat
187 // Access: Published
188 // Description: Returns true if the button-down even was generated
189 // due to keyrepeat, or false if it was an original
190 // button down.
191 ////////////////////////////////////////////////////////////////////
192 INLINE bool MouseWatcherParameter::
193 is_keyrepeat() const {
194  return (_flags & F_is_keyrepeat) != 0;
195 }
196 
197 ////////////////////////////////////////////////////////////////////
198 // Function: MouseWatcherParameter::has_keycode
199 // Access: Published
200 // Description: Returns true if this parameter has an associated
201 // keycode, false otherwise.
202 ////////////////////////////////////////////////////////////////////
203 INLINE bool MouseWatcherParameter::
204 has_keycode() const {
205  return (_flags & F_has_keycode) != 0;
206 }
207 
208 ////////////////////////////////////////////////////////////////////
209 // Function: MouseWatcherParameter::get_keycode
210 // Access: Published
211 // Description: Returns the keycode associated with this event. If
212 // has_keycode(), above, returns false, this returns 0.
213 ////////////////////////////////////////////////////////////////////
214 INLINE int MouseWatcherParameter::
215 get_keycode() const {
216  return _keycode;
217 }
218 
219 ////////////////////////////////////////////////////////////////////
220 // Function: MouseWatcherParameter::has_candidate
221 // Access: Published
222 // Description: Returns true if this parameter has an associated
223 // candidate string, false otherwise.
224 ////////////////////////////////////////////////////////////////////
225 INLINE bool MouseWatcherParameter::
226 has_candidate() const {
227  return (_flags & F_has_candidate) != 0;
228 }
229 
230 ////////////////////////////////////////////////////////////////////
231 // Function: MouseWatcherParameter::get_candidate_string
232 // Access: Published
233 // Description: Returns the candidate string associated with this
234 // event. If has_candidate(), above, returns false,
235 // this returns the empty string.
236 ////////////////////////////////////////////////////////////////////
237 INLINE const wstring &MouseWatcherParameter::
239  return _candidate_string;
240 }
241 
242 ////////////////////////////////////////////////////////////////////
243 // Function: MouseWatcherParameter::get_candidate_string_encoded
244 // Access: Published
245 // Description: Returns the candidate string associated with this
246 // event. If has_candidate(), above, returns false,
247 // this returns the empty string.
248 ////////////////////////////////////////////////////////////////////
249 INLINE string MouseWatcherParameter::
252 }
253 
254 ////////////////////////////////////////////////////////////////////
255 // Function: MouseWatcherParameter::get_candidate_string_encoded
256 // Access: Published
257 // Description: Returns the candidate string associated with this
258 // event. If has_candidate(), above, returns false,
259 // this returns the empty string.
260 ////////////////////////////////////////////////////////////////////
261 INLINE string MouseWatcherParameter::
262 get_candidate_string_encoded(TextEncoder::Encoding encoding) const {
263  return TextEncoder::encode_wtext(_candidate_string, encoding);
264 }
265 
266 ////////////////////////////////////////////////////////////////////
267 // Function: MouseWatcherParameter::get_highlight_start
268 // Access: Published
269 // Description: Returns the first highlighted character in the
270 // candidate string.
271 ////////////////////////////////////////////////////////////////////
272 INLINE size_t MouseWatcherParameter::
274  return _highlight_start;
275 }
276 
277 ////////////////////////////////////////////////////////////////////
278 // Function: MouseWatcherParameter::get_highlight_end
279 // Access: Published
280 // Description: Returns one more than the last highlighted character
281 // in the candidate string.
282 ////////////////////////////////////////////////////////////////////
283 INLINE size_t MouseWatcherParameter::
285  return _highlight_end;
286 }
287 
288 ////////////////////////////////////////////////////////////////////
289 // Function: MouseWatcherParameter::get_cursor_pos
290 // Access: Published
291 // Description: Returns the position of the user's edit cursor within
292 // the candidate string.
293 ////////////////////////////////////////////////////////////////////
294 INLINE size_t MouseWatcherParameter::
295 get_cursor_pos() const {
296  return _cursor_pos;
297 }
298 
299 ////////////////////////////////////////////////////////////////////
300 // Function: MouseWatcherParameter::get_modifier_buttons
301 // Access: Published
302 // Description: Returns the set of modifier buttons that were being
303 // held down while the event was generated.
304 ////////////////////////////////////////////////////////////////////
307  return _mods;
308 }
309 
310 ////////////////////////////////////////////////////////////////////
311 // Function: MouseWatcherParameter::has_mouse
312 // Access: Published
313 // Description: Returns true if this parameter has an associated
314 // mouse position, false otherwise.
315 ////////////////////////////////////////////////////////////////////
316 INLINE bool MouseWatcherParameter::
317 has_mouse() const {
318  return (_flags & F_has_mouse) != 0;
319 }
320 
321 ////////////////////////////////////////////////////////////////////
322 // Function: MouseWatcherParameter::get_mouse
323 // Access: Published
324 // Description: Returns the mouse position at the time the event was
325 // generated, in the normalized range (-1 .. 1). It is
326 // valid to call this only if has_mouse() returned true.
327 ////////////////////////////////////////////////////////////////////
328 INLINE const LPoint2 &MouseWatcherParameter::
329 get_mouse() const {
330  nassertr(has_mouse(), _mouse);
331  return _mouse;
332 }
333 
334 ////////////////////////////////////////////////////////////////////
335 // Function: MouseWatcherParameter::is_outside
336 // Access: Published
337 // Description: Returns true if the mouse was outside the region at
338 // the time the event was generated, false otherwise.
339 // This is only valid for "release" type events.
340 ////////////////////////////////////////////////////////////////////
341 INLINE bool MouseWatcherParameter::
342 is_outside() const {
343  return (_flags & F_is_outside) != 0;
344 }
345 
346 INLINE ostream &
347 operator << (ostream &out, const MouseWatcherParameter &parm) {
348  parm.output(out);
349  return out;
350 }
ButtonHandle get_button() const
Returns the mouse or keyboard button associated with this event.
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...
string get_candidate_string_encoded() const
Returns the candidate string associated with this event.
string encode_wtext(const wstring &wtext) const
Encodes a wide-text string into a single-char string, according to the current encoding.
Definition: textEncoder.I:557
static Encoding get_default_encoding()
Specifies the default encoding to be used for all subsequently created TextEncoder objects...
Definition: textEncoder.I:97
void set_button(const ButtonHandle &button)
Sets the mouse or keyboard button that generated this event, if any.
bool has_keycode() const
Returns true if this parameter has an associated keycode, false otherwise.
A ButtonHandle represents a single button from any device, including keyboard buttons and mouse butto...
Definition: buttonHandle.h:28
size_t get_highlight_start() const
Returns the first highlighted character in the candidate string.
void set_keyrepeat(bool flag)
Sets the state of the &quot;keyrepeat&quot; flag.
const ModifierButtons & get_modifier_buttons() const
Returns the set of modifier buttons that were being held down while 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 ...
void set_mouse(const LPoint2 &mouse)
Sets the mouse position that was current at the time the event was generated.
int get_keycode() const
Returns the keycode associated with this event.
bool has_button() const
Returns true if this parameter has an associated mouse or keyboard button, false otherwise.
void set_keycode(int keycode)
Sets the keycode associated with this event, if any.
const wstring & get_candidate_string() const
Returns the candidate string associated with this event.
void set_outside(bool flag)
Sets the state of the &quot;outside&quot; 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...
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_candidate(const 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.
This is a two-component point in space.
Definition: lpoint2.h:92
size_t get_cursor_pos() const
Returns the position of the user&#39;s edit cursor within the candidate string.
This is sent along as a parameter to most events generated for a region to indicate the mouse and but...
bool is_outside() const
Returns true if the mouse was outside the region at the time the event was generated, false otherwise.
bool has_candidate() const
Returns true if this parameter has an associated candidate string, false otherwise.