Panda3D
Loading...
Searching...
No Matches
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 */
17INLINE MouseWatcherRegion::
18MouseWatcherRegion(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 */
30INLINE MouseWatcherRegion::
31MouseWatcherRegion(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 */
42INLINE void MouseWatcherRegion::
43set_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 */
50INLINE void MouseWatcherRegion::
51set_frame(const LVecBase4 &frame) {
52 _frame = frame;
53 _area = (_frame[1] - _frame[0]) * (_frame[3] - _frame[2]);
54}
55
56/**
57 *
58 */
59INLINE const LVecBase4 &MouseWatcherRegion::
60get_frame() const {
61 return _frame;
62}
63
64/**
65 * Returns the area of the rectangular region.
66 */
67INLINE PN_stdfloat MouseWatcherRegion::
68get_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 */
79INLINE void MouseWatcherRegion::
80set_sort(int sort) {
81 _sort = sort;
82}
83
84/**
85 * Returns the current sorting order of this region. See set_sort().
86 */
87INLINE int MouseWatcherRegion::
88get_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 */
98INLINE void MouseWatcherRegion::
99set_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 */
110INLINE bool MouseWatcherRegion::
111get_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 */
121INLINE void MouseWatcherRegion::
122set_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 */
134INLINE bool MouseWatcherRegion::
135get_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 */
148INLINE void MouseWatcherRegion::
149set_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 */
156INLINE int MouseWatcherRegion::
157get_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 */
166operator < (const MouseWatcherRegion &other) const {
167 if (_sort != other._sort) {
168 return _sort > other._sort;
169 }
170 return _area < other._area;
171}
This is the class that defines a rectangular region on the screen for the MouseWatcher.
get_area
Returns the area of the rectangular region.
set_suppress_flags
Sets which events are suppressed when the mouse is over the region.
get_sort
Returns the current sorting order of this region.
get_active
Returns whether the region is active or not.
set_keyboard
Sets whether the region is interested in global keyboard events.
bool operator<(const MouseWatcherRegion &other) const
Returns true if this region should be preferred over the other region when they overlap,...
get_suppress_flags
Returns the current suppress_flags.
set_active
Sets whether the region is active or not.
get_keyboard
Returns whether the region is interested in global keyboard events; see set_keyboard().
set_sort
Changes the sorting order of this particular region.
A base class for all things which can have a name.
Definition namable.h:26