00001 // Filename: pgItem.I 00002 // Created by: drose (13Mar02) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 00020 //////////////////////////////////////////////////////////////////// 00021 // Function: PGItem::get_region 00022 // Access: Public 00023 // Description: Returns the MouseWatcherRegion associated with this 00024 // item. Every PGItem has a MouseWatcherRegion 00025 // associated with it, that is created when the PGItem 00026 // is created; it does not change during the lifetime of 00027 // the PGItem. Even items that do not have a frame have 00028 // an associated MouseWatcherRegion, although it will 00029 // not be used in this case. 00030 //////////////////////////////////////////////////////////////////// 00031 INLINE PGMouseWatcherRegion *PGItem:: 00032 get_region() const { 00033 return _region; 00034 } 00035 00036 //////////////////////////////////////////////////////////////////// 00037 // Function: PGItem::set_frame 00038 // Access: Published 00039 // Description: Sets the bounding rectangle of the item, in local 00040 // coordinates. This is the region on screen within 00041 // which the mouse will be considered to be within the 00042 // item. Normally, it should correspond to the bounding 00043 // rectangle of the visible geometry of the item. 00044 //////////////////////////////////////////////////////////////////// 00045 INLINE void PGItem:: 00046 set_frame(float left, float right, float bottom, float top) { 00047 set_frame(LVecBase4f(left, right, bottom, top)); 00048 } 00049 00050 //////////////////////////////////////////////////////////////////// 00051 // Function: PGItem::set_frame 00052 // Access: Published 00053 // Description: Sets the bounding rectangle of the item, in local 00054 // coordinates. This is the region on screen within 00055 // which the mouse will be considered to be within the 00056 // item. Normally, it should correspond to the bounding 00057 // rectangle of the visible geometry of the item. 00058 //////////////////////////////////////////////////////////////////// 00059 INLINE void PGItem:: 00060 set_frame(const LVecBase4f &frame) { 00061 _has_frame = true; 00062 _frame = frame; 00063 mark_frames_stale(); 00064 } 00065 00066 //////////////////////////////////////////////////////////////////// 00067 // Function: PGItem::get_frame 00068 // Access: Published 00069 // Description: Returns the bounding rectangle of the item. See 00070 // set_frame(). It is an error to call this if 00071 // has_frame() returns false. 00072 //////////////////////////////////////////////////////////////////// 00073 INLINE const LVecBase4f &PGItem:: 00074 get_frame() const { 00075 nassertr(has_frame(), _frame); 00076 return _frame; 00077 } 00078 00079 //////////////////////////////////////////////////////////////////// 00080 // Function: PGItem::has_frame 00081 // Access: Published 00082 // Description: Returns true if the item has a bounding rectangle; 00083 // see set_frame(). 00084 //////////////////////////////////////////////////////////////////// 00085 INLINE bool PGItem:: 00086 has_frame() const { 00087 return _has_frame; 00088 } 00089 00090 //////////////////////////////////////////////////////////////////// 00091 // Function: PGItem::clear_frame 00092 // Access: Published 00093 // Description: Removes the bounding rectangle from the item. It 00094 // will no longer be possible to position the mouse 00095 // within the item; see set_frame(). 00096 //////////////////////////////////////////////////////////////////// 00097 INLINE void PGItem:: 00098 clear_frame() { 00099 _has_frame = false; 00100 mark_frames_stale(); 00101 } 00102 00103 //////////////////////////////////////////////////////////////////// 00104 // Function: PGItem::set_state 00105 // Access: Published 00106 // Description: Sets the "state" of this particular PGItem. 00107 // 00108 // The PGItem node will render as if it were the 00109 // subgraph assigned to the corresponding index via 00110 // set_state_def(). 00111 //////////////////////////////////////////////////////////////////// 00112 INLINE void PGItem:: 00113 set_state(int state) { 00114 _state = state; 00115 } 00116 00117 //////////////////////////////////////////////////////////////////// 00118 // Function: PGItem::get_state 00119 // Access: Published 00120 // Description: Returns the "state" of this particular PGItem. See 00121 // set_state(). 00122 //////////////////////////////////////////////////////////////////// 00123 INLINE int PGItem:: 00124 get_state() const { 00125 return _state; 00126 } 00127 00128 //////////////////////////////////////////////////////////////////// 00129 // Function: PGItem::get_active 00130 // Access: Published 00131 // Description: Returns whether the PGItem is currently active for 00132 // mouse events. See set_active(). 00133 //////////////////////////////////////////////////////////////////// 00134 INLINE bool PGItem:: 00135 get_active() const { 00136 return (_flags & F_active) != 0; 00137 } 00138 00139 //////////////////////////////////////////////////////////////////// 00140 // Function: PGItem::get_focus 00141 // Access: Published 00142 // Description: Returns whether the PGItem currently has focus for 00143 // keyboard events. See set_focus(). 00144 //////////////////////////////////////////////////////////////////// 00145 INLINE bool PGItem:: 00146 get_focus() const { 00147 return (_flags & F_focus) != 0; 00148 } 00149 00150 //////////////////////////////////////////////////////////////////// 00151 // Function: PGItem::get_background_focus 00152 // Access: Published 00153 // Description: Returns whether background_focus is currently 00154 // enabled. See set_background_focus(). 00155 //////////////////////////////////////////////////////////////////// 00156 INLINE bool PGItem:: 00157 get_background_focus() const { 00158 return (_flags & F_background_focus) != 0; 00159 } 00160 00161 //////////////////////////////////////////////////////////////////// 00162 // Function: PGItem::set_suppress_flags 00163 // Access: Published 00164 // Description: This is just an interface to set the suppress flags 00165 // on the underlying MouseWatcherRegion. See 00166 // MouseWatcherRegion::set_suppress_flags(). 00167 //////////////////////////////////////////////////////////////////// 00168 INLINE void PGItem:: 00169 set_suppress_flags(int suppress_flags) { 00170 _region->set_suppress_flags(suppress_flags); 00171 } 00172 00173 //////////////////////////////////////////////////////////////////// 00174 // Function: PGItem::get_suppress_flags 00175 // Access: Published 00176 // Description: This is just an interface to get the suppress flags 00177 // on the underlying MouseWatcherRegion. See 00178 // MouseWatcherRegion::get_suppress_flags(). 00179 //////////////////////////////////////////////////////////////////// 00180 INLINE int PGItem:: 00181 get_suppress_flags() const { 00182 return _region->get_suppress_flags(); 00183 } 00184 00185 //////////////////////////////////////////////////////////////////// 00186 // Function: PGItem::get_id 00187 // Access: Published 00188 // Description: Returns the unique ID assigned to this PGItem. This 00189 // will be assigned to the region created with the 00190 // MouseWatcher, and will thus be used to generate event 00191 // names. 00192 //////////////////////////////////////////////////////////////////// 00193 INLINE const string &PGItem:: 00194 get_id() const { 00195 return _region->get_name(); 00196 } 00197 00198 //////////////////////////////////////////////////////////////////// 00199 // Function: PGItem::set_id 00200 // Access: Published 00201 // Description: Set the unique ID assigned to this PGItem. It is the 00202 // user's responsibility to ensure that this ID is 00203 // unique. 00204 // 00205 // Normally, this should not need to be called, as the 00206 // PGItem will assign itself an ID when it is created, 00207 // but this function allows the user to decide to 00208 // redefine the ID to be something possibly more 00209 // meaningful. 00210 //////////////////////////////////////////////////////////////////// 00211 INLINE void PGItem:: 00212 set_id(const string &id) { 00213 _region->set_name(id); 00214 } 00215 00216 //////////////////////////////////////////////////////////////////// 00217 // Function: PGItem::get_enter_prefix 00218 // Access: Published, Static 00219 // Description: Returns the prefix that is used to define the enter 00220 // event for all PGItems. The enter event is the 00221 // concatenation of this string followed by get_id(). 00222 //////////////////////////////////////////////////////////////////// 00223 INLINE string PGItem:: 00224 get_enter_prefix() { 00225 return "enter-"; 00226 } 00227 00228 //////////////////////////////////////////////////////////////////// 00229 // Function: PGItem::get_exit_prefix 00230 // Access: Published, Static 00231 // Description: Returns the prefix that is used to define the exit 00232 // event for all PGItems. The exit event is the 00233 // concatenation of this string followed by get_id(). 00234 //////////////////////////////////////////////////////////////////// 00235 INLINE string PGItem:: 00236 get_exit_prefix() { 00237 return "exit-"; 00238 } 00239 00240 //////////////////////////////////////////////////////////////////// 00241 // Function: PGItem::get_within_prefix 00242 // Access: Published, Static 00243 // Description: Returns the prefix that is used to define the within 00244 // event for all PGItems. The within event is the 00245 // concatenation of this string followed by get_id(). 00246 //////////////////////////////////////////////////////////////////// 00247 INLINE string PGItem:: 00248 get_within_prefix() { 00249 return "within-"; 00250 } 00251 00252 //////////////////////////////////////////////////////////////////// 00253 // Function: PGItem::get_without_prefix 00254 // Access: Published, Static 00255 // Description: Returns the prefix that is used to define the without 00256 // event for all PGItems. The without event is the 00257 // concatenation of this string followed by get_id(). 00258 //////////////////////////////////////////////////////////////////// 00259 INLINE string PGItem:: 00260 get_without_prefix() { 00261 return "without-"; 00262 } 00263 00264 //////////////////////////////////////////////////////////////////// 00265 // Function: PGItem::get_focus_in_prefix 00266 // Access: Published, Static 00267 // Description: Returns the prefix that is used to define the focus_in 00268 // event for all PGItems. The focus_in event is the 00269 // concatenation of this string followed by get_id(). 00270 // 00271 // Unlike most item events, this event is thrown with no 00272 // parameters. 00273 //////////////////////////////////////////////////////////////////// 00274 INLINE string PGItem:: 00275 get_focus_in_prefix() { 00276 return "fin-"; 00277 } 00278 00279 //////////////////////////////////////////////////////////////////// 00280 // Function: PGItem::get_focus_out_prefix 00281 // Access: Published, Static 00282 // Description: Returns the prefix that is used to define the focus_out 00283 // event for all PGItems. The focus_out event is the 00284 // concatenation of this string followed by get_id(). 00285 // 00286 // Unlike most item events, this event is thrown with no 00287 // parameters. 00288 //////////////////////////////////////////////////////////////////// 00289 INLINE string PGItem:: 00290 get_focus_out_prefix() { 00291 return "fout-"; 00292 } 00293 00294 //////////////////////////////////////////////////////////////////// 00295 // Function: PGItem::get_press_prefix 00296 // Access: Published, Static 00297 // Description: Returns the prefix that is used to define the press 00298 // event for all PGItems. The press event is the 00299 // concatenation of this string followed by a button 00300 // name, followed by a hyphen and get_id(). 00301 //////////////////////////////////////////////////////////////////// 00302 INLINE string PGItem:: 00303 get_press_prefix() { 00304 return "press-"; 00305 } 00306 00307 //////////////////////////////////////////////////////////////////// 00308 // Function: PGItem::get_release_prefix 00309 // Access: Published, Static 00310 // Description: Returns the prefix that is used to define the release 00311 // event for all PGItems. The release event is the 00312 // concatenation of this string followed by a button 00313 // name, followed by a hyphen and get_id(). 00314 //////////////////////////////////////////////////////////////////// 00315 INLINE string PGItem:: 00316 get_release_prefix() { 00317 return "release-"; 00318 } 00319 00320 //////////////////////////////////////////////////////////////////// 00321 // Function: PGItem::get_keystroke_prefix 00322 // Access: Published, Static 00323 // Description: Returns the prefix that is used to define the 00324 // keystroke event for all PGItems. The keystroke event 00325 // is the concatenation of this string followed by a 00326 // hyphen and get_id(). 00327 //////////////////////////////////////////////////////////////////// 00328 INLINE string PGItem:: 00329 get_keystroke_prefix() { 00330 return "keystroke-"; 00331 } 00332 00333 //////////////////////////////////////////////////////////////////// 00334 // Function: PGItem::get_enter_event 00335 // Access: Published 00336 // Description: Returns the event name that will be thrown when the 00337 // item is active and the mouse enters its frame, but 00338 // not any nested frames. 00339 //////////////////////////////////////////////////////////////////// 00340 INLINE string PGItem:: 00341 get_enter_event() const { 00342 return get_enter_prefix() + get_id(); 00343 } 00344 00345 //////////////////////////////////////////////////////////////////// 00346 // Function: PGItem::get_exit_event 00347 // Access: Published 00348 // Description: Returns the event name that will be thrown when the 00349 // item is active and the mouse exits its frame, or 00350 // enters a nested frame. 00351 //////////////////////////////////////////////////////////////////// 00352 INLINE string PGItem:: 00353 get_exit_event() const { 00354 return get_exit_prefix() + get_id(); 00355 } 00356 00357 //////////////////////////////////////////////////////////////////// 00358 // Function: PGItem::get_within_event 00359 // Access: Published 00360 // Description: Returns the event name that will be thrown when the 00361 // item is active and the mouse moves within the 00362 // boundaries of the frame. This is different from the 00363 // enter_event in that the mouse is considered within 00364 // the frame even if it is also within a nested frame. 00365 //////////////////////////////////////////////////////////////////// 00366 INLINE string PGItem:: 00367 get_within_event() const { 00368 return get_within_prefix() + get_id(); 00369 } 00370 00371 //////////////////////////////////////////////////////////////////// 00372 // Function: PGItem::get_without_event 00373 // Access: Published 00374 // Description: Returns the event name that will be thrown when the 00375 // item is active and the mouse moves completely outside 00376 // the boundaries of the frame. This is different from 00377 // the exit_event in that the mouse is considered 00378 // within the frame even if it is also within a nested 00379 // frame. 00380 //////////////////////////////////////////////////////////////////// 00381 INLINE string PGItem:: 00382 get_without_event() const { 00383 return get_without_prefix() + get_id(); 00384 } 00385 00386 //////////////////////////////////////////////////////////////////// 00387 // Function: PGItem::get_focus_in_event 00388 // Access: Published 00389 // Description: Returns the event name that will be thrown when the 00390 // item gets the keyboard focus. 00391 //////////////////////////////////////////////////////////////////// 00392 INLINE string PGItem:: 00393 get_focus_in_event() const { 00394 return get_focus_in_prefix() + get_id(); 00395 } 00396 00397 //////////////////////////////////////////////////////////////////// 00398 // Function: PGItem::get_focus_out_event 00399 // Access: Published 00400 // Description: Returns the event name that will be thrown when the 00401 // item loses the keyboard focus. 00402 //////////////////////////////////////////////////////////////////// 00403 INLINE string PGItem:: 00404 get_focus_out_event() const { 00405 return get_focus_out_prefix() + get_id(); 00406 } 00407 00408 //////////////////////////////////////////////////////////////////// 00409 // Function: PGItem::get_press_event 00410 // Access: Published 00411 // Description: Returns the event name that will be thrown when the 00412 // item is active and the indicated mouse or keyboard 00413 // button is depressed while the mouse is within the 00414 // frame. 00415 //////////////////////////////////////////////////////////////////// 00416 INLINE string PGItem:: 00417 get_press_event(const ButtonHandle &button) const { 00418 return get_press_prefix() + button.get_name() + "-" + get_id(); 00419 } 00420 00421 //////////////////////////////////////////////////////////////////// 00422 // Function: PGItem::get_release_event 00423 // Access: Published 00424 // Description: Returns the event name that will be thrown when the 00425 // item is active and the indicated mouse or keyboard 00426 // button, formerly clicked down is within the frame, is 00427 // released. 00428 //////////////////////////////////////////////////////////////////// 00429 INLINE string PGItem:: 00430 get_release_event(const ButtonHandle &button) const { 00431 return get_release_prefix() + button.get_name() + "-" + get_id(); 00432 } 00433 00434 //////////////////////////////////////////////////////////////////// 00435 // Function: PGItem::get_keystroke_event 00436 // Access: Published 00437 // Description: Returns the event name that will be thrown when the 00438 // item is active and any key is pressed by the user. 00439 //////////////////////////////////////////////////////////////////// 00440 INLINE string PGItem:: 00441 get_keystroke_event() const { 00442 return get_keystroke_prefix() + get_id(); 00443 } 00444 00445 //////////////////////////////////////////////////////////////////// 00446 // Function: PGItem::set_text_node 00447 // Access: Published, Static 00448 // Description: Changes the TextNode object that will be used by all 00449 // PGItems to generate default labels given a string. 00450 // This can be loaded with the default font, etc. 00451 //////////////////////////////////////////////////////////////////// 00452 INLINE void PGItem:: 00453 set_text_node(TextNode *node) { 00454 _text_node = node; 00455 } 00456 00457 //////////////////////////////////////////////////////////////////// 00458 // Function: PGItem::get_focus_item 00459 // Access: Published, Static 00460 // Description: Returns the one PGItem in the world that currently 00461 // has keyboard focus, if any, or NULL if no item has 00462 // keyboard focus. Use PGItem::set_focus() to activate 00463 // or deactivate keyboard focus on a particular item. 00464 //////////////////////////////////////////////////////////////////// 00465 INLINE PGItem *PGItem:: 00466 get_focus_item() { 00467 return _focus_item; 00468 }