Panda3D
|
00001 // Filename: mouseWatcherRegion.I 00002 // Created by: drose (13Jul00) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 00016 //////////////////////////////////////////////////////////////////// 00017 // Function: MouseWatcherRegion::Constructor 00018 // Access: Published 00019 // Description: 00020 //////////////////////////////////////////////////////////////////// 00021 INLINE MouseWatcherRegion:: 00022 MouseWatcherRegion(const string &name, PN_stdfloat left, PN_stdfloat right, 00023 PN_stdfloat bottom, PN_stdfloat top) : 00024 Namable(name), 00025 _frame(left, right, bottom, top) 00026 { 00027 _sort = 0; 00028 _flags = F_active; 00029 } 00030 00031 //////////////////////////////////////////////////////////////////// 00032 // Function: MouseWatcherRegion::Constructor 00033 // Access: Published 00034 // Description: 00035 //////////////////////////////////////////////////////////////////// 00036 INLINE MouseWatcherRegion:: 00037 MouseWatcherRegion(const string &name, const LVecBase4 &frame) : 00038 Namable(name), 00039 _frame(frame) 00040 { 00041 _sort = 0; 00042 _flags = F_active; 00043 } 00044 00045 //////////////////////////////////////////////////////////////////// 00046 // Function: MouseWatcherRegion::set_frame 00047 // Access: Published 00048 // Description: 00049 //////////////////////////////////////////////////////////////////// 00050 INLINE void MouseWatcherRegion:: 00051 set_frame(PN_stdfloat left, PN_stdfloat right, PN_stdfloat bottom, PN_stdfloat top) { 00052 set_frame(LVecBase4(left, right, bottom, top)); 00053 } 00054 00055 //////////////////////////////////////////////////////////////////// 00056 // Function: MouseWatcherRegion::set_frame 00057 // Access: Published 00058 // Description: 00059 //////////////////////////////////////////////////////////////////// 00060 INLINE void MouseWatcherRegion:: 00061 set_frame(const LVecBase4 &frame) { 00062 _frame = frame; 00063 _area = (_frame[1] - _frame[0]) * (_frame[3] - _frame[2]); 00064 } 00065 00066 //////////////////////////////////////////////////////////////////// 00067 // Function: MouseWatcherRegion::get_frame 00068 // Access: Published 00069 // Description: 00070 //////////////////////////////////////////////////////////////////// 00071 INLINE const LVecBase4 &MouseWatcherRegion:: 00072 get_frame() const { 00073 return _frame; 00074 } 00075 00076 //////////////////////////////////////////////////////////////////// 00077 // Function: MouseWatcherRegion::get_area 00078 // Access: Published 00079 // Description: Returns the area of the rectangular region. 00080 //////////////////////////////////////////////////////////////////// 00081 INLINE PN_stdfloat MouseWatcherRegion:: 00082 get_area() const { 00083 return _area; 00084 } 00085 00086 //////////////////////////////////////////////////////////////////// 00087 // Function: MouseWatcherRegion::set_sort 00088 // Access: Published 00089 // Description: Changes the sorting order of this particular region. 00090 // The sorting order is used to resolve conflicts in the 00091 // case of overlapping region; the region with the 00092 // highest sort value will be preferred, and between 00093 // regions of the same sort value, the smallest region 00094 // will be preferred. The default sorting order, if 00095 // none is explicitly specified, is 0. 00096 //////////////////////////////////////////////////////////////////// 00097 INLINE void MouseWatcherRegion:: 00098 set_sort(int sort) { 00099 _sort = sort; 00100 } 00101 00102 //////////////////////////////////////////////////////////////////// 00103 // Function: MouseWatcherRegion::get_sort 00104 // Access: Published 00105 // Description: Returns the current sorting order of this region. 00106 // See set_sort(). 00107 //////////////////////////////////////////////////////////////////// 00108 INLINE int MouseWatcherRegion:: 00109 get_sort() const { 00110 return _sort; 00111 } 00112 00113 //////////////////////////////////////////////////////////////////// 00114 // Function: MouseWatcherRegion::set_active 00115 // Access: Published 00116 // Description: Sets whether the region is active or not. If it is 00117 // not active, the MouseWatcher will never consider the 00118 // mouse to be over the region. The region might still 00119 // receive keypress events if its set_keyboard() flag is 00120 // true. 00121 //////////////////////////////////////////////////////////////////// 00122 INLINE void MouseWatcherRegion:: 00123 set_active(bool active) { 00124 if (active) { 00125 _flags |= F_active; 00126 } else { 00127 _flags &= ~F_active; 00128 } 00129 } 00130 00131 //////////////////////////////////////////////////////////////////// 00132 // Function: MouseWatcherRegion::get_active 00133 // Access: Published 00134 // Description: Returns whether the region is active or not. See 00135 // set_active(). 00136 //////////////////////////////////////////////////////////////////// 00137 INLINE bool MouseWatcherRegion:: 00138 get_active() const { 00139 return ((_flags & F_active) != 0); 00140 } 00141 00142 //////////////////////////////////////////////////////////////////// 00143 // Function: MouseWatcherRegion::set_keyboard 00144 // Access: Published 00145 // Description: Sets whether the region is interested in global 00146 // keyboard events. If this is true, then any keyboard 00147 // button events will be passed to press() and release() 00148 // regardless of the position of the mouse onscreen; 00149 // otherwise, these events will only be passed if the 00150 // mouse is over the region. 00151 //////////////////////////////////////////////////////////////////// 00152 INLINE void MouseWatcherRegion:: 00153 set_keyboard(bool keyboard) { 00154 if (keyboard) { 00155 _flags |= F_keyboard; 00156 } else { 00157 _flags &= ~F_keyboard; 00158 } 00159 } 00160 00161 //////////////////////////////////////////////////////////////////// 00162 // Function: MouseWatcherRegion::get_keyboard 00163 // Access: Published 00164 // Description: Returns whether the region is interested in global 00165 // keyboard events; see set_keyboard(). 00166 //////////////////////////////////////////////////////////////////// 00167 INLINE bool MouseWatcherRegion:: 00168 get_keyboard() const { 00169 return ((_flags & F_keyboard) != 0); 00170 } 00171 00172 //////////////////////////////////////////////////////////////////// 00173 // Function: MouseWatcherRegion::set_suppress_flags 00174 // Access: Published 00175 // Description: Sets which events are suppressed when the mouse is 00176 // over the region. This is the union of zero or more 00177 // various SF_* values. Normally, this is 0, indicating 00178 // that no events are suppressed. 00179 // 00180 // If you set this to a non-zero value, for instance 00181 // SF_mouse_position, then the mouse position will not 00182 // be sent along the data graph when the mouse is over 00183 // this particular region. 00184 //////////////////////////////////////////////////////////////////// 00185 INLINE void MouseWatcherRegion:: 00186 set_suppress_flags(int suppress_flags) { 00187 _flags = ((_flags & ~F_suppress_flags) | (suppress_flags & F_suppress_flags)); 00188 } 00189 00190 //////////////////////////////////////////////////////////////////// 00191 // Function: MouseWatcherRegion::get_suppress_flags 00192 // Access: Published 00193 // Description: Returns the current suppress_flags. See 00194 // set_suppress_flags(). 00195 //////////////////////////////////////////////////////////////////// 00196 INLINE int MouseWatcherRegion:: 00197 get_suppress_flags() const { 00198 return (_flags & F_suppress_flags); 00199 } 00200 00201 //////////////////////////////////////////////////////////////////// 00202 // Function: MouseWatcherRegion::Ordering Operator 00203 // Access: Public 00204 // Description: Returns true if this region should be preferred over 00205 // the other region when they overlap, false otherwise. 00206 //////////////////////////////////////////////////////////////////// 00207 INLINE bool MouseWatcherRegion:: 00208 operator < (const MouseWatcherRegion &other) const { 00209 if (_sort != other._sort) { 00210 return _sort > other._sort; 00211 } 00212 return _area < other._area; 00213 }