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