diff --git a/panda/src/tform/mouseWatcher.I b/panda/src/tform/mouseWatcher.I index bfc6c76709..e67e297c8c 100644 --- a/panda/src/tform/mouseWatcher.I +++ b/panda/src/tform/mouseWatcher.I @@ -6,7 +6,7 @@ //////////////////////////////////////////////////////////////////// // Function: MouseWatcher::has_mouse -// Access: Public, Scheme +// Access: Published // Description: Returns true if the mouse is anywhere within the // window, false otherwise. //////////////////////////////////////////////////////////////////// @@ -17,7 +17,7 @@ has_mouse() const { //////////////////////////////////////////////////////////////////// // Function: MouseWatcher::get_mouse -// Access: Public, Scheme +// Access: Published // Description: 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. @@ -33,7 +33,7 @@ get_mouse() const { //////////////////////////////////////////////////////////////////// // Function: MouseWatcher::get_mouse_x -// Access: Public, Scheme +// Access: Published // Description: 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. @@ -46,7 +46,7 @@ get_mouse_x() const { //////////////////////////////////////////////////////////////////// // Function: MouseWatcher::get_mouse_y -// Access: Public, Scheme +// Access: Published // Description: 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. @@ -59,7 +59,7 @@ get_mouse_y() const { //////////////////////////////////////////////////////////////////// // Function: MouseWatcher::is_over_region -// Access: Public, Scheme +// Access: Published // Description: Returns true if the mouse is over any rectangular // region, false otherwise. //////////////////////////////////////////////////////////////////// @@ -70,7 +70,7 @@ is_over_region() const { //////////////////////////////////////////////////////////////////// // Function: MouseWatcher::is_over_region -// Access: Public, Scheme +// Access: Published // Description: Returns true if the mouse is over any rectangular // region, false otherwise. //////////////////////////////////////////////////////////////////// @@ -81,7 +81,7 @@ is_over_region(float x, float y) const { //////////////////////////////////////////////////////////////////// // Function: MouseWatcher::is_over_region -// Access: Public, Scheme +// Access: Published // Description: Returns true if the mouse is over any rectangular // region, false otherwise. //////////////////////////////////////////////////////////////////// @@ -92,7 +92,7 @@ is_over_region(const LPoint2f &pos) const { //////////////////////////////////////////////////////////////////// // Function: MouseWatcher::get_over_region -// Access: Public, Scheme +// Access: Published // Description: Returns the smallest region the mouse is currently // over, or NULL if it is over no region. //////////////////////////////////////////////////////////////////// @@ -103,7 +103,7 @@ get_over_region() const { //////////////////////////////////////////////////////////////////// // Function: MouseWatcher::get_over_region -// Access: Public, Scheme +// Access: Published // Description: Returns the smallest region the indicated point is // over, or NULL if it is over no region. //////////////////////////////////////////////////////////////////// @@ -114,7 +114,7 @@ get_over_region(float x, float y) const { //////////////////////////////////////////////////////////////////// // Function: MouseWatcher::set_button_down_pattern -// Access: Public, Scheme +// Access: Published // Description: 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: @@ -133,7 +133,7 @@ set_button_down_pattern(const string &pattern) { //////////////////////////////////////////////////////////////////// // Function: MouseWatcher::get_button_down_pattern -// Access: Public, Scheme +// Access: Published // Description: Returns the string that indicates how event names are // generated when a button is depressed. See // set_button_down_pattern(). @@ -145,7 +145,7 @@ get_button_down_pattern() const { //////////////////////////////////////////////////////////////////// // Function: MouseWatcher::set_button_up_pattern -// Access: Public, Scheme +// Access: Published // Description: Sets the pattern string that indicates how the event // names are generated when a button is released. See // set_button_down_pattern(). @@ -157,7 +157,7 @@ set_button_up_pattern(const string &pattern) { //////////////////////////////////////////////////////////////////// // Function: MouseWatcher::get_button_up_pattern -// Access: Public, Scheme +// Access: Published // Description: Returns the string that indicates how event names are // generated when a button is released. See // set_button_down_pattern(). @@ -169,7 +169,7 @@ get_button_up_pattern() const { //////////////////////////////////////////////////////////////////// // Function: MouseWatcher::set_enter_pattern -// Access: Public, Scheme +// Access: Published // Description: Sets the pattern string that indicates how the event // names are generated when the mouse wanders over a // region. See set_button_down_pattern(). @@ -181,7 +181,7 @@ set_enter_pattern(const string &pattern) { //////////////////////////////////////////////////////////////////// // Function: MouseWatcher::get_enter_pattern -// Access: Public, Scheme +// Access: Published // Description: Returns the string that indicates how event names are // generated when the mouse wanders over a region. See // set_button_down_pattern(). @@ -193,7 +193,7 @@ get_enter_pattern() const { //////////////////////////////////////////////////////////////////// // Function: MouseWatcher::set_leave_pattern -// Access: Public, Scheme +// Access: Published // Description: Sets the pattern string that indicates how the event // names are generated when the mouse leaves a region. // See set_button_down_pattern(). @@ -205,7 +205,7 @@ set_leave_pattern(const string &pattern) { //////////////////////////////////////////////////////////////////// // Function: MouseWatcher::get_leave_pattern -// Access: Public, Scheme +// Access: Published // Description: Returns the string that indicates how event names are // generated when the mouse leaves a region. See // set_button_down_pattern(). @@ -217,7 +217,7 @@ get_leave_pattern() const { //////////////////////////////////////////////////////////////////// // Function: MouseWatcher::set_geometry -// Access: Public, Scheme +// Access: Published // Description: Sets the arc 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 @@ -231,7 +231,7 @@ set_geometry(NodeRelation *arc) { //////////////////////////////////////////////////////////////////// // Function: MouseWatcher::has_geometry -// Access: Public, Scheme +// Access: Published // Description: Returns true if a software mouse pointer has been // setup via set_geometry(), or false otherwise. See // set_geometry(). @@ -243,7 +243,7 @@ has_geometry() const { //////////////////////////////////////////////////////////////////// // Function: MouseWatcher::get_geometry -// Access: Public, Scheme +// Access: Published // Description: Returns the arc that has been set as the software // mouse pointer, or NULL if no arc has been set. See // has_geometry() and set_geometry(). @@ -255,7 +255,7 @@ get_geometry() const { //////////////////////////////////////////////////////////////////// // Function: MouseWatcher::clear_geometry -// Access: Public, Scheme +// Access: Published // Description: Stops the use of the software cursor set up via // set_geometry(). //////////////////////////////////////////////////////////////////// diff --git a/panda/src/tform/mouseWatcher.cxx b/panda/src/tform/mouseWatcher.cxx index eaa4f96f5a..43ad02e702 100644 --- a/panda/src/tform/mouseWatcher.cxx +++ b/panda/src/tform/mouseWatcher.cxx @@ -25,7 +25,7 @@ TypeHandle MouseWatcher::_button_events_type; //////////////////////////////////////////////////////////////////// // Function: MouseWatcher::Constructor -// Access: Public, Scheme +// Access: Published // Description: //////////////////////////////////////////////////////////////////// MouseWatcher:: @@ -38,7 +38,7 @@ MouseWatcher(const string &name) : DataNode(name) { //////////////////////////////////////////////////////////////////// // Function: MouseWatcher::Destructor -// Access: Public, Scheme +// Access: Published // Description: //////////////////////////////////////////////////////////////////// MouseWatcher:: @@ -47,7 +47,7 @@ MouseWatcher:: //////////////////////////////////////////////////////////////////// // Function: MouseWatcher::add_region -// Access: Public, Scheme +// Access: Published // Description: Adds the indicated region to the set of regions that // are to be watched. Returns true if it was // successfully added, or false if it was already on the @@ -60,7 +60,7 @@ add_region(MouseWatcherRegion *region) { //////////////////////////////////////////////////////////////////// // Function: MouseWatcher::has_region -// Access: Public, Scheme +// Access: Published // Description: Returns true if the indicated region has already been // added to the MouseWatcher, false otherwise. //////////////////////////////////////////////////////////////////// @@ -71,7 +71,7 @@ has_region(MouseWatcherRegion *region) const { //////////////////////////////////////////////////////////////////// // Function: MouseWatcher::remove_region -// Access: Public, Scheme +// Access: Published // Description: Removes the indicated region from the Watcher. // Returns true if it was successfully removed, or false // if it wasn't there in the first place. @@ -87,16 +87,38 @@ remove_region(MouseWatcherRegion *region) { return _regions.erase(region) != 0; } +//////////////////////////////////////////////////////////////////// +// Function: MouseWatcher::find_region +// Access: Published +// Description: Returns a pointer to the first region found with the +// indicated name. If multiple regions share the same +// name, the one that is returned is indeterminate. +//////////////////////////////////////////////////////////////////// +MouseWatcherRegion *MouseWatcher:: +find_region(const string &name) const { + Regions::const_iterator ri; + for (ri = _regions.begin(); ri != _regions.end(); ++ri) { + MouseWatcherRegion *region = (*ri); + if (region->get_name() == name) { + return region; + } + } + + return (MouseWatcherRegion *)NULL; +} + //////////////////////////////////////////////////////////////////// // Function: MouseWatcher::get_over_region -// Access: Public, Scheme -// Description: Returns the smallest region the indicated point is -// over, or NULL if it is over no region. +// Access: Published +// Description: 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. //////////////////////////////////////////////////////////////////// MouseWatcherRegion *MouseWatcher:: get_over_region(const LPoint2f &pos) const { MouseWatcherRegion *over_region = (MouseWatcherRegion *)NULL; - float over_area = 0.0; Regions::const_iterator ri; for (ri = _regions.begin(); ri != _regions.end(); ++ri) { @@ -107,11 +129,10 @@ get_over_region(const LPoint2f &pos) const { pos[0] >= frame[0] && pos[0] <= frame[1] && pos[1] >= frame[2] && pos[1] <= frame[3]) { - // We're over this region. Is it the smallest? + // We're over this region. Is it preferred to the other one? if (over_region == (MouseWatcherRegion *)NULL || - region->get_area() < over_area) { + *region < *over_region) { over_region = region; - over_area = region->get_area(); } } } @@ -122,7 +143,7 @@ get_over_region(const LPoint2f &pos) const { //////////////////////////////////////////////////////////////////// // Function: MouseWatcher::output -// Access: Public +// Access: Public, Virtual // Description: //////////////////////////////////////////////////////////////////// void MouseWatcher:: @@ -133,7 +154,7 @@ output(ostream &out) const { //////////////////////////////////////////////////////////////////// // Function: MouseWatcher::write -// Access: Public +// Access: Public, Virtual // Description: //////////////////////////////////////////////////////////////////// void MouseWatcher:: diff --git a/panda/src/tform/mouseWatcher.h b/panda/src/tform/mouseWatcher.h index fdaa33165d..9a3ca5d7fd 100644 --- a/panda/src/tform/mouseWatcher.h +++ b/panda/src/tform/mouseWatcher.h @@ -45,6 +45,7 @@ PUBLISHED: bool add_region(MouseWatcherRegion *region); bool has_region(MouseWatcherRegion *region) const; bool remove_region(MouseWatcherRegion *region); + MouseWatcherRegion *find_region(const string &name) const; INLINE bool has_mouse() const; INLINE const LPoint2f &get_mouse() const; diff --git a/panda/src/tform/mouseWatcherRegion.I b/panda/src/tform/mouseWatcherRegion.I index 925850d2fc..48ee449aa6 100644 --- a/panda/src/tform/mouseWatcherRegion.I +++ b/panda/src/tform/mouseWatcherRegion.I @@ -6,7 +6,7 @@ //////////////////////////////////////////////////////////////////// // Function: MouseWatcherRegion::Constructor -// Access: Public +// Access: Published // Description: //////////////////////////////////////////////////////////////////// INLINE MouseWatcherRegion:: @@ -15,13 +15,14 @@ MouseWatcherRegion(const string &name, float left, float right, Namable(name), _frame(left, right, bottom, top) { + _sort = 0; _active = true; _suppress_below = true; } //////////////////////////////////////////////////////////////////// // Function: MouseWatcherRegion::Constructor -// Access: Public +// Access: Published // Description: //////////////////////////////////////////////////////////////////// INLINE MouseWatcherRegion:: @@ -29,13 +30,14 @@ MouseWatcherRegion(const string &name, const LVecBase4f &frame) : Namable(name), _frame(frame) { + _sort = 0; _active = true; _suppress_below = false; } //////////////////////////////////////////////////////////////////// // Function: MouseWatcherRegion::set_frame -// Access: Public +// Access: Published // Description: //////////////////////////////////////////////////////////////////// INLINE void MouseWatcherRegion:: @@ -45,7 +47,7 @@ set_frame(float left, float right, float bottom, float top) { //////////////////////////////////////////////////////////////////// // Function: MouseWatcherRegion::set_frame -// Access: Public +// Access: Published // Description: //////////////////////////////////////////////////////////////////// INLINE void MouseWatcherRegion:: @@ -56,7 +58,7 @@ set_frame(const LVecBase4f &frame) { //////////////////////////////////////////////////////////////////// // Function: MouseWatcherRegion::get_frame -// Access: Public +// Access: Published // Description: //////////////////////////////////////////////////////////////////// INLINE const LVecBase4f &MouseWatcherRegion:: @@ -66,7 +68,7 @@ get_frame() const { //////////////////////////////////////////////////////////////////// // Function: MouseWatcherRegion::get_area -// Access: Public +// Access: Published // Description: Returns the area of the rectangular region. //////////////////////////////////////////////////////////////////// INLINE float MouseWatcherRegion:: @@ -74,9 +76,36 @@ get_area() const { return _area; } +//////////////////////////////////////////////////////////////////// +// Function: MouseWatcherRegion::set_sort +// Access: Published +// Description: Changes the sorting order of this particular region. +// The sorting order is used to resolve conflicts in the +// case of overlapping region; the region with the +// highest sort value will be preferred, and between +// regions of the same sort value, the smallest region +// will be preferred. The default sorting order, if +// none is explicitly specified, is 0. +//////////////////////////////////////////////////////////////////// +INLINE void MouseWatcherRegion:: +set_sort(int sort) { + _sort = sort; +} + +//////////////////////////////////////////////////////////////////// +// Function: MouseWatcherRegion::get_sort +// Access: Published +// Description: Returns the current sorting order of this region. +// See set_sort(). +//////////////////////////////////////////////////////////////////// +INLINE int MouseWatcherRegion:: +get_sort() const { + return _sort; +} + //////////////////////////////////////////////////////////////////// // Function: MouseWatcherRegion::set_active -// Access: Public +// Access: Published // Description: Sets whether the region is active or not. If it is // not active, the MouseWatcher will totally ignore it. //////////////////////////////////////////////////////////////////// @@ -87,7 +116,7 @@ set_active(bool active) { //////////////////////////////////////////////////////////////////// // Function: MouseWatcherRegion::get_active -// Access: Public +// Access: Published // Description: Returns whether the region is active or not. See // set_active(). //////////////////////////////////////////////////////////////////// @@ -98,7 +127,7 @@ get_active() const { //////////////////////////////////////////////////////////////////// // Function: MouseWatcherRegion::set_suppress_below -// Access: Public +// Access: Published // Description: Sets the suppress_below flag. When this is true, and // the region is active, then whenever the mouse is // within the region the MouseWatcher will suppress any @@ -112,7 +141,7 @@ set_suppress_below(bool suppress_below) { //////////////////////////////////////////////////////////////////// // Function: MouseWatcherRegion::get_suppress_below -// Access: Public +// Access: Published // Description: Returns the suppress_below flag. See // set_suppress_below(). //////////////////////////////////////////////////////////////////// @@ -120,3 +149,17 @@ INLINE bool MouseWatcherRegion:: get_suppress_below() const { return _suppress_below; } + +//////////////////////////////////////////////////////////////////// +// Function: MouseWatcherRegion::Ordering Operator +// Access: Public +// Description: Returns true if this region should be preferred over +// the other region when they overlap, false otherwise. +//////////////////////////////////////////////////////////////////// +INLINE bool MouseWatcherRegion:: +operator < (const MouseWatcherRegion &other) const { + if (_sort != other._sort) { + return _sort > other._sort; + } + return _area < other._area; +} diff --git a/panda/src/tform/mouseWatcherRegion.cxx b/panda/src/tform/mouseWatcherRegion.cxx index adbb4a624f..883f70f2a0 100644 --- a/panda/src/tform/mouseWatcherRegion.cxx +++ b/panda/src/tform/mouseWatcherRegion.cxx @@ -12,7 +12,7 @@ TypeHandle MouseWatcherRegion::_type_handle; //////////////////////////////////////////////////////////////////// // Function: MouseWatcherRegion::output -// Access: Public +// Access: Published // Description: //////////////////////////////////////////////////////////////////// void MouseWatcherRegion:: @@ -22,7 +22,7 @@ output(ostream &out) const { //////////////////////////////////////////////////////////////////// // Function: MouseWatcherRegion::write -// Access: Public +// Access: Published // Description: //////////////////////////////////////////////////////////////////// void MouseWatcherRegion:: diff --git a/panda/src/tform/mouseWatcherRegion.h b/panda/src/tform/mouseWatcherRegion.h index abbab74644..41391718a5 100644 --- a/panda/src/tform/mouseWatcherRegion.h +++ b/panda/src/tform/mouseWatcherRegion.h @@ -28,6 +28,9 @@ PUBLISHED: INLINE const LVecBase4f &get_frame() const; INLINE float get_area() const; + INLINE void set_sort(int sort); + INLINE int get_sort() const; + INLINE void set_active(bool active); INLINE bool get_active() const; @@ -37,9 +40,13 @@ PUBLISHED: void output(ostream &out) const; void write(ostream &out, int indent_level = 0) const; +public: + INLINE bool operator < (const MouseWatcherRegion &other) const; + private: LVecBase4f _frame; float _area; + int _sort; bool _active; bool _suppress_below;