|
|
|
This TFormer maintains a list of rectangular regions on the screen that are considered special mouse regions; typically these will be click buttons.
More...
#include "mouseWatcher.h"
List of all members.
Public Member Functions |
|
| MouseWatcher (const string &name="") |
| bool | add_group (MouseWatcherGroup *group) |
| | Adds the indicated group of regions to the set of regions the MouseWatcher will monitor each frame.
|
| void | clear_display_region () |
| | Removes the display region constraint from the MouseWatcher, and restores it to the default behavior of watching the whole window.
|
| void | clear_geometry () |
| | Stops the use of the software cursor set up via set_geometry().
|
| void | clear_inactivity_timeout () |
| | Removes the inactivity timeout and restores the MouseWatcher to its default behavior of allowing a key to be held indefinitely.
|
| void | clear_trail_log () |
| | Clears the mouse trail log.
|
| void | clear_trail_node () |
| | If you have previously fetched the trail node using get_trail_node, then the MouseWatcher is continually updating the trail node every frame.
|
|
| CPT (PointerEventList) get_trail_log() const |
|
virtual TypeHandle | force_init_type () |
| const string & | get_button_down_pattern () const |
| | Returns the string that indicates how event names are generated when a button is depressed.
|
| const string & | get_button_repeat_pattern () const |
| | Returns the string that indicates how event names are names are generated when a button is continuously held and generates keyrepeat "down" events.
|
| const string & | get_button_up_pattern () const |
| | Returns the string that indicates how event names are generated when a button is released.
|
| DisplayRegion * | get_display_region () const |
| | Returns the display region the MouseWatcher is constrained to by set_display_region(), or NULL if it is not constrained.
|
| const string & | get_enter_pattern () const |
| | Returns the string that indicates how event names are generated when the mouse enters a region.
|
| EventHandler * | get_extra_handler () const |
| | As an optimization for the C++ Gui, an extra handler can be registered with a mouseWatcher so that events can be dealt with much sooner.
|
| const LVecBase4 & | get_frame () const |
| | Returns the frame of the MouseWatcher.
|
| PandaNode * | get_geometry () const |
| | Returns the node that has been set as the software mouse pointer, or NULL if no node has been set.
|
| MouseWatcherGroup * | get_group (int n) const |
| | Returns the nth group added to the MouseWatcher via add_group().
|
| double | get_inactivity_timeout () const |
| | Returns the inactivity timeout that has been set.
|
| const string & | get_inactivity_timeout_event () const |
| | Returns the event string that will be generated when the inactivity timeout counter expires.
|
| const string & | get_leave_pattern () const |
| | Returns the string that indicates how event names are generated when the mouse leaves a region.
|
| ModifierButtons | get_modifier_buttons () const |
| | Returns the set of buttons that are being monitored as modifier buttons, as well as their current state.
|
| const LPoint2 & | get_mouse () const |
| | It is only valid to call this if has_mouse() returns true.
|
| PN_stdfloat | get_mouse_x () const |
| | It is only valid to call this if has_mouse() returns true.
|
| PN_stdfloat | get_mouse_y () const |
| | It is only valid to call this if has_mouse() returns true.
|
| int | get_num_groups () const |
| | Returns the number of separate groups added to the MouseWatcher via add_group().
|
| MouseWatcherRegion * | get_over_region () const |
| | Returns the smallest region the mouse is currently over, or NULL if it is over no region.
|
| MouseWatcherRegion * | get_over_region (PN_stdfloat x, PN_stdfloat y) const |
| | Returns the smallest region the indicated point is over, or NULL if it is over no region.
|
| MouseWatcherRegion * | get_over_region (const LPoint2 &pos) const |
| | Returns the preferred region the mouse is over.
|
|
virtual TypeHandle | get_type () const |
| const string & | get_within_pattern () const |
| | Returns the string that indicates how event names are generated when the mouse wanders over a region.
|
| const string & | get_without_pattern () const |
| | Returns the string that indicates how event names are generated when the mouse wanders out of a region.
|
| bool | has_display_region () const |
| | Returns true if the MouseWatcher has been constrained to a particular region of the screen via set_display_region(), or false otherwise.
|
| bool | has_geometry () const |
| | Returns true if a software mouse pointer has been setup via set_geometry(), or false otherwise.
|
| bool | has_inactivity_timeout () const |
| | Returns true if an inactivity timeout has been set, false otherwise.
|
| bool | has_mouse () const |
| | Returns true if the mouse is anywhere within the window, false otherwise.
|
| bool | is_button_down (ButtonHandle button) const |
| | Returns true if the indicated button is currently being held down, false otherwise.
|
| bool | is_mouse_open () const |
| | Returns true if the mouse is within the window and not over some particular MouseWatcherRegion that is marked to suppress mouse events; that is, that the mouse is in open space within the window.
|
| bool | is_over_region () const |
| | Returns true if the mouse is over any rectangular region, false otherwise.
|
| bool | is_over_region (PN_stdfloat x, PN_stdfloat y) const |
| | Returns true if the mouse is over any rectangular region, false otherwise.
|
| bool | is_over_region (const LPoint2 &pos) const |
| | Returns true if the mouse is over any rectangular region, false otherwise.
|
|
| MAKE_SEQ (get_groups, get_num_groups, get_group) |
| void | note_activity () |
| | Can be used in conjunction with the inactivity timeout to inform the MouseWatcher that the user has just performed some action which proves he/she is present.
|
| int | num_trail_recent () const |
| | This counter indicates how many events were added to the trail log this frame.
|
|
virtual void | output (ostream &out) const |
|
| PT (GeomNode) get_trail_node() |
| bool | remove_group (MouseWatcherGroup *group) |
| | Removes the indicated group from the set of extra groups associated with the MouseWatcher.
|
| bool | remove_region (MouseWatcherRegion *region) |
| | Removes the indicated region from the group.
|
| bool | replace_group (MouseWatcherGroup *old_group, MouseWatcherGroup *new_group) |
| | Atomically removes old_group from the MouseWatcher, and replaces it with new_group.
|
| void | set_button_down_pattern (const string &pattern) |
| | Sets the pattern string that indicates how the event names are generated when a button is depressed.
|
| void | set_button_repeat_pattern (const string &pattern) |
| | Sets the pattern string that indicates how the event names are generated when a button is continuously held and generates keyrepeat "down" events.
|
| void | set_button_up_pattern (const string &pattern) |
| | Sets the pattern string that indicates how the event names are generated when a button is released.
|
| void | set_display_region (DisplayRegion *dr) |
| | Constrains the MouseWatcher to watching the mouse within a particular indicated region of the screen.
|
| void | set_enter_pattern (const string &pattern) |
| | Sets the pattern string that indicates how the event names are generated when the mouse enters a region.
|
| void | set_extra_handler (EventHandler *eh) |
| | As an optimization for the C++ Gui, an extra handler can be registered with a mouseWatcher so that events can be dealt with much sooner.
|
| void | set_frame (PN_stdfloat left, PN_stdfloat right, PN_stdfloat bottom, PN_stdfloat top) |
| | Sets the frame of the MouseWatcher.
|
| void | set_frame (const LVecBase4 &frame) |
| | Sets the frame of the MouseWatcher.
|
| void | set_geometry (PandaNode *node) |
| | Sets the node that will be transformed each frame by the mouse's coordinates.
|
| void | set_inactivity_timeout (double timeout) |
| | Sets an inactivity timeout on the mouse activity.
|
| void | set_inactivity_timeout_event (const string &event) |
| | Specifies the event string that will be generated when the inactivity timeout counter expires.
|
| void | set_leave_pattern (const string &pattern) |
| | Sets the pattern string that indicates how the event names are generated when the mouse leaves a region.
|
| void | set_modifier_buttons (const ModifierButtons &mods) |
| | Sets the buttons that should be monitored as modifier buttons for generating events to the MouseWatcherRegions.
|
| void | set_trail_log_duration (double duration) |
| | If the duration is nonzero, causes the MouseWatcher to log the mouse's trail.
|
| void | set_within_pattern (const string &pattern) |
| | Sets the pattern string that indicates how the event names are generated when the mouse wanders over a region.
|
| void | set_without_pattern (const string &pattern) |
| | Sets the pattern string that indicates how the event names are generated when the mouse wanders out of a region.
|
|
virtual void | write (ostream &out, int indent_level=0) const |
Static Public Member Functions |
|
static TypeHandle | get_class_type () |
|
static void | init_type () |
Protected Member Functions |
| void | candidate (const wstring &candidate, size_t highlight_start, size_t highlight_end, size_t cursor_pos) |
| | Records that the indicated candidate string has been highlighted in the IME.
|
| void | clear_current_regions () |
| | Empties the set of current regions.
|
| virtual void | do_hide_regions () |
| | The protected implementation of hide_regions().
|
| virtual void | do_show_regions (const NodePath &render2d, const string &bin_name, int draw_order) |
| | The protected implementation of show_regions().
|
| virtual void | do_transmit_data (DataGraphTraverser *trav, const DataNodeTransmit &input, DataNodeTransmit &output) |
| | The virtual implementation of transmit_data().
|
| void | enter_region (MouseWatcherRegion *region, const MouseWatcherParameter ¶m) |
| | Called internally to indicate the mouse pointer is favoring the indicated region.
|
| void | exit_region (MouseWatcherRegion *region, const MouseWatcherParameter ¶m) |
| | Called internally to indicate the mouse pointer is no longer favoring the indicated region.
|
| void | get_over_regions (Regions ®ions, const LPoint2 &pos) const |
| | Fills up the "regions" list with the set of regions that the indicated point is over, sorted in order by pointer.
|
| void | global_keyboard_press (const MouseWatcherParameter ¶m) |
| | Calls press() on all regions that are interested in receiving global keyboard events, except for the current region (which already received this one).
|
| void | global_keyboard_release (const MouseWatcherParameter ¶m) |
| | Calls release() on all regions that are interested in receiving global keyboard events, except for the current region (which already received this one).
|
| void | keystroke (int keycode) |
| | Records that the indicated keystroke has been generated.
|
| void | move () |
| | Records the indicated mouse or keyboard button as being moved from last position.
|
| void | press (ButtonHandle button, bool keyrepeat) |
| | Records the indicated mouse or keyboard button as being depressed.
|
| void | release (ButtonHandle button) |
| | Records the indicated mouse or keyboard button as being released.
|
| void | set_current_regions (Regions ®ions) |
| | Changes the "current" regions--the one we consider the mouse to be over--to the indicated list, and throws whatever events are appropriate because of that.
|
| void | set_mouse (const LVecBase2 &xy, const LVecBase2 &pixel_xy) |
| | Called from do_transmit_data() to indicate the mouse is within the window, and to specify its current position.
|
| void | set_no_mouse () |
| | Called from do_transmit_data() to indicate the mouse is not within the window.
|
| void | throw_event_pattern (const string &pattern, const MouseWatcherRegion *region, const ButtonHandle &button) |
| | Throws an event associated with the indicated region, using the given pattern.
|
| void | within_region (MouseWatcherRegion *region, const MouseWatcherParameter ¶m) |
| | Called internally to indicate the mouse pointer has moved within the indicated region's boundaries.
|
| void | without_region (MouseWatcherRegion *region, const MouseWatcherParameter ¶m) |
| | Called internally to indicate the mouse pointer has moved outside of the indicated region's boundaries.
|
Static Protected Member Functions |
| static MouseWatcherRegion * | get_preferred_region (const Regions ®ions) |
| | Returns the innermost region of all the regions indicated in the given vector (usually, the regions the mouse is over).
|
| static bool | has_region_in (const Regions ®ions, MouseWatcherRegion *region) |
| | Returns true if the indicated region is a member of the given sorted list, false otherwise.
|
| static void | intersect_regions (Regions &only_a, Regions &only_b, Regions &both, const Regions ®ions_a, const Regions ®ions_b) |
| | Computes the list of regions that are in both regions_a and regions_b, as well as the list of regions only in regions_a, and the list of regions only in regions_b.
|
| static bool | remove_region_from (Regions ®ions, MouseWatcherRegion *region) |
| | Removes the indicated region from the given vector.
|
Detailed Description
This TFormer maintains a list of rectangular regions on the screen that are considered special mouse regions; typically these will be click buttons.
When the mouse passes in or out of one of these regions, or when a button is clicked while the mouse is in one of these regions, an event is thrown.
Mouse events may also be suppressed from the rest of the datagraph in these special regions.
This class can also implement a software mouse pointer by automatically generating a transform to apply to a piece of geometry placed under the 2-d scene graph. It will move the geometry around according to the mouse's known position.
Finally, this class can keep a record of the mouse trail. This is useful if you want to know, not just where the mouse is, but the exact sequence of movements it took to get there. This information is mainly useful for gesture-recognition code. To use trail logging, you need to enable the generation of pointer events in the GraphicsWindowInputDevice and set the trail log duration in the MouseWatcher. Otherwise, the trail log will be empty.
Definition at line 68 of file mouseWatcher.h.
Member Function Documentation
Adds the indicated group of regions to the set of regions the MouseWatcher will monitor each frame.
Since the MouseWatcher itself inherits from MouseWatcherGroup, this operation is normally not necessary--you can simply add the Regions you care about one at a time. Adding a complete group is useful when you may want to explicitly remove the regions as a group later.
Returns true if the group was successfully added, or false if it was already on the list.
Definition at line 169 of file mouseWatcher.cxx.
References NodePath::is_empty(), and MouseWatcherGroup::show_regions().
| void MouseWatcher::candidate |
( |
const wstring & |
candidate, |
|
|
size_t |
highlight_start, |
|
|
size_t |
highlight_end, |
|
|
size_t |
cursor_pos |
|
) |
| [protected] |
Removes the display region constraint from the MouseWatcher, and restores it to the default behavior of watching the whole window.
Definition at line 520 of file mouseWatcher.I.
Clears the mouse trail log.
This does not prevent further accumulation of the log given future events.
Definition at line 671 of file mouseWatcher.I.
If you have previously fetched the trail node using get_trail_node, then the MouseWatcher is continually updating the trail node every frame.
Using clear_trail_node causes the MouseWatcher to forget the trail node and stop updating it.
Definition at line 460 of file mouseWatcher.cxx.
The virtual implementation of transmit_data().
This function receives an array of input parameters and should generate an array of output parameters. The input parameters may be accessed with the index numbers returned by the define_input() calls that were made earlier (presumably in the constructor); likewise, the output parameters should be set with the index numbers returned by the define_output() calls.
Reimplemented from DataNode.
Definition at line 1396 of file mouseWatcher.cxx.
References ButtonEventList::add_event(), candidate(), BitArray::clear_bit(), BitArray::get_bit(), DataGraphTraverser::get_current_thread(), DataNodeTransmit::get_data(), ButtonEventList::get_event(), ClockObject::get_frame_time(), ClockObject::get_global_clock(), PointerEventList::get_in_window(), ButtonHandle::get_index(), BitArray::get_num_bits(), PointerEventList::get_num_events(), ButtonEventList::get_num_events(), EventParameter::get_ptr(), PointerEventList::get_sequence(), PointerEventList::get_time(), EventStoreValue< Type >::get_value(), PointerEventList::get_xpos(), PointerEventList::get_ypos(), DataNodeTransmit::has_data(), MouseButton::is_mouse_button(), keystroke(), move(), note_activity(), press(), release(), BitArray::set_bit(), DataNodeTransmit::set_data(), set_mouse(), set_no_mouse(), and ButtonEvent::update_mods().
Called internally to indicate the mouse pointer is no longer favoring the indicated region.
Definition at line 1301 of file mouseWatcher.cxx.
References LightMutexDirect::debug_is_locked(), MouseWatcherRegion::exit_region(), ButtonHandle::none(), MouseButton::one(), MouseWatcherRegion::release(), MouseWatcherParameter::set_button(), and throw_event_pattern().
Referenced by remove_group(), remove_region(), replace_group(), set_current_regions(), and without_region().
Returns the string that indicates how event names are names are generated when a button is continuously held and generates keyrepeat "down" events.
See set_button_repeat_pattern().
Definition at line 275 of file mouseWatcher.I.
Returns the string that indicates how event names are generated when the mouse enters a region.
This is different from within_pattern, in that a mouse is only "entered" in the topmost region at a given time, while it might be "within" multiple nested regions.
Definition at line 304 of file mouseWatcher.I.
As an optimization for the C++ Gui, an extra handler can be registered with a mouseWatcher so that events can be dealt with much sooner.
Definition at line 465 of file mouseWatcher.I.
Returns the string that indicates how event names are generated when the mouse leaves a region.
This is different from without_pattern, in that a mouse is only "entered" in the topmost region at a given time, while it might be "within" multiple nested regions.
Definition at line 333 of file mouseWatcher.I.
Returns the set of buttons that are being monitored as modifier buttons, as well as their current state.
Definition at line 488 of file mouseWatcher.I.
It is only valid to call this if has_mouse() returns true.
If so, this returns the current position of the mouse within the window.
Definition at line 48 of file mouseWatcher.I.
It is only valid to call this if has_mouse() returns true.
If so, this returns the current X position of the mouse within the window.
Definition at line 64 of file mouseWatcher.I.
It is only valid to call this if has_mouse() returns true.
If so, this returns the current Y position of the mouse within the window.
Definition at line 77 of file mouseWatcher.I.
Returns the preferred region the mouse is over.
In the case of overlapping regions, the region with the largest sort order is preferred; if two regions have the same sort order, then the smaller region is preferred.
Definition at line 144 of file mouseWatcher.cxx.
References get_over_regions(), and get_preferred_region().
Returns the innermost region of all the regions indicated in the given vector (usually, the regions the mouse is over).
This is the "preferred" region that gets some special treatment. Assumes the lock is already held.
Definition at line 649 of file mouseWatcher.cxx.
Referenced by get_over_region(), and set_current_regions().
Returns the string that indicates how event names are generated when the mouse wanders over a region.
This is different from enter_pattern, in that a mouse is only "entered" in the topmost region at a given time, while it might be "within" multiple nested regions.
Definition at line 362 of file mouseWatcher.I.
Returns the string that indicates how event names are generated when the mouse wanders out of a region.
This is different from leave_pattern, in that a mouse is only "entered" in the topmost region at a given time, while it might be "within" multiple nested regions.
Definition at line 392 of file mouseWatcher.I.
Returns true if an inactivity timeout has been set, false otherwise.
Definition at line 579 of file mouseWatcher.I.
| void MouseWatcher::intersect_regions |
( |
MouseWatcher::Regions & |
only_a, |
|
|
MouseWatcher::Regions & |
only_b, |
|
|
MouseWatcher::Regions & |
both, |
|
|
const Regions & |
regions_a, |
|
|
const Regions & |
regions_b |
|
) |
| [static, protected] |
Computes the list of regions that are in both regions_a and regions_b, as well as the list of regions only in regions_a, and the list of regions only in regions_b.
Any or all of the three output lists may be the same object, but they must be different objects from both of the input lists.
It is assumed that both vectors are already sorted in pointer order. It is also assumed that any relevant locks are already held.
Definition at line 870 of file mouseWatcher.cxx.
Referenced by remove_group(), and replace_group().
Returns true if the mouse is within the window and not over some particular MouseWatcherRegion that is marked to suppress mouse events; that is, that the mouse is in open space within the window.
Definition at line 36 of file mouseWatcher.I.
This counter indicates how many events were added to the trail log this frame.
The trail log is updated once per frame, during the process_events operation.
Definition at line 702 of file mouseWatcher.I.
Removes the indicated region from the given vector.
Assumes the vector is sorted in pointer order. Returns true if removed, false if it wasn't there. Assumes any relevent locks are already held.
Definition at line 908 of file mouseWatcher.cxx.
Referenced by remove_region().
Atomically removes old_group from the MouseWatcher, and replaces it with new_group.
Presumably old_group and new_group might have some regions in common; these are handled properly.
If old_group is not already present, simply adds new_group and returns false. Otherwise, removes old_group and adds new_group, and then returns true.
Definition at line 256 of file mouseWatcher.cxx.
References MouseWatcherGroup::do_hide_regions(), MouseWatcherGroup::do_show_regions(), MouseWatcherGroup::do_sort_regions(), MouseWatcherGroup::do_update_regions(), exit_region(), has_region_in(), intersect_regions(), NodePath::is_empty(), and set_current_regions().
Sets the pattern string that indicates how the event names are generated when a button is depressed.
This is a string that may contain any of the following:
r - the name of the region the mouse is over b - the name of the button pressed.
The event name will be based on the in_pattern string specified here, with all occurrences of the above strings replaced with the corresponding values.
Definition at line 206 of file mouseWatcher.I.
Sets the pattern string that indicates how the event names are generated when a button is continuously held and generates keyrepeat "down" events.
This is a string that may contain any of the following:
r - the name of the region the mouse is over b - the name of the button pressed.
The event name will be based on the in_pattern string specified here, with all occurrences of the above strings replaced with the corresponding values.
Definition at line 262 of file mouseWatcher.I.
Constrains the MouseWatcher to watching the mouse within a particular indicated region of the screen.
DataNodes parented under the MouseWatcher will observe the mouse and keyboard events only when the mouse is within the indicated region, and the observed range will be from -1 .. 1 across the region.
Do not delete the DisplayRegion while it is owned by the MouseWatcher.
Definition at line 507 of file mouseWatcher.I.
Sets the pattern string that indicates how the event names are generated when the mouse enters a region.
This is different from within_pattern, in that a mouse is only "entered" in the topmost region at a given time, while it might be "within" multiple nested regions.
Definition at line 290 of file mouseWatcher.I.
As an optimization for the C++ Gui, an extra handler can be registered with a mouseWatcher so that events can be dealt with much sooner.
Definition at line 453 of file mouseWatcher.I.
Sets the frame of the MouseWatcher.
See the next flavor of this method for a more verbose explanation.
Definition at line 89 of file mouseWatcher.I.
Sets the frame of the MouseWatcher.
This determines the coordinate space in which the MouseWatcherRegions should be expected to live. Normally, this is left at -1, 1, -1, 1, which is the default setting, and matches the mouse coordinate range.
Whatever values you specify here indicate the shape of the full screen, and the MouseWatcherRegions will be given in coordinate space matching it. For instance, if you specify (0, 1, 0, 1), then a MouseWatcherRegion with the frame (0, 1, 0, .5) will cover the lower half of the screen.
Definition at line 110 of file mouseWatcher.I.
Sets the node that will be transformed each frame by the mouse's coordinates.
It will also be hidden when the mouse goes outside the window. This can be used to implement a software mouse pointer for when a hardware (or system) mouse pointer is unavailable.
Definition at line 406 of file mouseWatcher.I.
Sets an inactivity timeout on the mouse activity.
When this timeout (in seconds) is exceeded with no keyboard or mouse activity, all currently-held buttons are automatically released. This is intended to help protect against people who inadvertently (or intentionally) leave a keyboard key stuck down and then wander away from the keyboard.
Also, when this timeout expires, the event specified by set_inactivity_timeout_event() will be generated.
Definition at line 566 of file mouseWatcher.I.
References note_activity().
Sets the pattern string that indicates how the event names are generated when the mouse leaves a region.
This is different from without_pattern, in that a mouse is only "entered" in the topmost region at a given time, while it might be "within" multiple nested regions.
Definition at line 319 of file mouseWatcher.I.
Sets the buttons that should be monitored as modifier buttons for generating events to the MouseWatcherRegions.
Definition at line 477 of file mouseWatcher.I.
If the duration is nonzero, causes the MouseWatcher to log the mouse's trail.
Events older than the specified duration are discarded. If the duration is zero, logging is disabled.
Definition at line 389 of file mouseWatcher.cxx.
Sets the pattern string that indicates how the event names are generated when the mouse wanders over a region.
This is different from enter_pattern, in that a mouse is only "entered" in the topmost region at a given time, while it might be "within" multiple nested regions.
Definition at line 348 of file mouseWatcher.I.
Sets the pattern string that indicates how the event names are generated when the mouse wanders out of a region.
This is different from leave_pattern, in that a mouse is only "entered" in the topmost region at a given time, while it might be "within" multiple nested regions.
Definition at line 377 of file mouseWatcher.I.
Throws an event associated with the indicated region, using the given pattern.
Definition at line 942 of file mouseWatcher.cxx.
References ButtonHandle::get_name(), ModifierButtons::get_prefix(), ModifierButtons::has_button(), ButtonHandle::none(), and ReferenceCount::test_ref_count_integrity().
Referenced by clear_current_regions(), enter_region(), exit_region(), press(), release(), within_region(), and without_region().
The documentation for this class was generated from the following files:
| | |