Panda3D
mouseWatcherRegion.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 mouseWatcherRegion.I
10  * @author drose
11  * @date 2000-07-13
12  */
13 
14 /**
15  *
16  */
17 INLINE MouseWatcherRegion::
18 MouseWatcherRegion(const std::string &name, PN_stdfloat left, PN_stdfloat right,
19  PN_stdfloat bottom, PN_stdfloat top) :
20  Namable(name)
21 {
22  _sort = 0;
23  _flags = F_active;
24  set_frame(left, right, bottom, top);
25 }
26 
27 /**
28  *
29  */
30 INLINE MouseWatcherRegion::
31 MouseWatcherRegion(const std::string &name, const LVecBase4 &frame) :
32  Namable(name),
33  _frame(frame)
34 {
35  _sort = 0;
36  _flags = F_active;
37 }
38 
39 /**
40  *
41  */
42 INLINE void MouseWatcherRegion::
43 set_frame(PN_stdfloat left, PN_stdfloat right, PN_stdfloat bottom, PN_stdfloat top) {
44  set_frame(LVecBase4(left, right, bottom, top));
45 }
46 
47 /**
48  *
49  */
50 INLINE void MouseWatcherRegion::
51 set_frame(const LVecBase4 &frame) {
52  _frame = frame;
53  _area = (_frame[1] - _frame[0]) * (_frame[3] - _frame[2]);
54 }
55 
56 /**
57  *
58  */
59 INLINE const LVecBase4 &MouseWatcherRegion::
60 get_frame() const {
61  return _frame;
62 }
63 
64 /**
65  * Returns the area of the rectangular region.
66  */
67 INLINE PN_stdfloat MouseWatcherRegion::
68 get_area() const {
69  return _area;
70 }
71 
72 /**
73  * Changes the sorting order of this particular region. The sorting order is
74  * used to resolve conflicts in the case of overlapping region; the region
75  * with the highest sort value will be preferred, and between regions of the
76  * same sort value, the smallest region will be preferred. The default
77  * sorting order, if none is explicitly specified, is 0.
78  */
79 INLINE void MouseWatcherRegion::
80 set_sort(int sort) {
81  _sort = sort;
82 }
83 
84 /**
85  * Returns the current sorting order of this region. See set_sort().
86  */
87 INLINE int MouseWatcherRegion::
88 get_sort() const {
89  return _sort;
90 }
91 
92 /**
93  * Sets whether the region is active or not. If it is not active, the
94  * MouseWatcher will never consider the mouse to be over the region. The
95  * region might still receive keypress events if its set_keyboard() flag is
96  * true.
97  */
98 INLINE void MouseWatcherRegion::
99 set_active(bool active) {
100  if (active) {
101  _flags |= F_active;
102  } else {
103  _flags &= ~F_active;
104  }
105 }
106 
107 /**
108  * Returns whether the region is active or not. See set_active().
109  */
110 INLINE bool MouseWatcherRegion::
111 get_active() const {
112  return ((_flags & F_active) != 0);
113 }
114 
115 /**
116  * Sets whether the region is interested in global keyboard events. If this
117  * is true, then any keyboard button events will be passed to press() and
118  * release() regardless of the position of the mouse onscreen; otherwise,
119  * these events will only be passed if the mouse is over the region.
120  */
121 INLINE void MouseWatcherRegion::
122 set_keyboard(bool keyboard) {
123  if (keyboard) {
124  _flags |= F_keyboard;
125  } else {
126  _flags &= ~F_keyboard;
127  }
128 }
129 
130 /**
131  * Returns whether the region is interested in global keyboard events; see
132  * set_keyboard().
133  */
134 INLINE bool MouseWatcherRegion::
135 get_keyboard() const {
136  return ((_flags & F_keyboard) != 0);
137 }
138 
139 /**
140  * Sets which events are suppressed when the mouse is over the region. This
141  * is the union of zero or more various SF_* values. Normally, this is 0,
142  * indicating that no events are suppressed.
143  *
144  * If you set this to a non-zero value, for instance SF_mouse_position, then
145  * the mouse position will not be sent along the data graph when the mouse is
146  * over this particular region.
147  */
148 INLINE void MouseWatcherRegion::
149 set_suppress_flags(int suppress_flags) {
150  _flags = ((_flags & ~F_suppress_flags) | (suppress_flags & F_suppress_flags));
151 }
152 
153 /**
154  * Returns the current suppress_flags. See set_suppress_flags().
155  */
156 INLINE int MouseWatcherRegion::
157 get_suppress_flags() const {
158  return (_flags & F_suppress_flags);
159 }
160 
161 /**
162  * Returns true if this region should be preferred over the other region when
163  * they overlap, false otherwise.
164  */
165 INLINE bool MouseWatcherRegion::
166 operator < (const MouseWatcherRegion &other) const {
167  if (_sort != other._sort) {
168  return _sort > other._sort;
169  }
170  return _area < other._area;
171 }
set_suppress_flags
Sets which events are suppressed when the mouse is over the region.
bool operator<(const MouseWatcherRegion &other) const
Returns true if this region should be preferred over the other region when they overlap,...
set_active
Sets whether the region is active or not.
set_sort
Changes the sorting order of this particular region.
set_keyboard
Sets whether the region is interested in global keyboard events.
A base class for all things which can have a name.
Definition: namable.h:26
This is the class that defines a rectangular region on the screen for the MouseWatcher.