Panda3D
 All Classes Functions Variables Enumerations
pgSliderBar.I
00001 // Filename: pgSliderBar.I
00002 // Created by:  masad (19Oct04)
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: PGSliderBar::set_notify
00018 //       Access: Published
00019 //  Description: Sets the object which will be notified when the
00020 //               PGSliderBar changes.  Set this to NULL to disable
00021 //               this effect.  The PGSliderBar does not retain
00022 //               ownership of the pointer; it is your responsibility
00023 //               to ensure that the notify object does not destruct.
00024 ////////////////////////////////////////////////////////////////////
00025 INLINE void PGSliderBar:: 
00026 set_notify(PGSliderBarNotify *notify) {
00027   PGItem::set_notify(notify);
00028 }
00029 
00030 ////////////////////////////////////////////////////////////////////
00031 //     Function: PGSliderBar::get_notify
00032 //       Access: Published
00033 //  Description: Returns the object which will be notified when the
00034 //               PGSliderBar changes, if any.  Returns NULL if there
00035 //               is no such object configured.
00036 ////////////////////////////////////////////////////////////////////
00037 INLINE PGSliderBarNotify *PGSliderBar:: 
00038 get_notify() const {
00039   return (PGSliderBarNotify *)PGItem::get_notify();
00040 }
00041 
00042 ////////////////////////////////////////////////////////////////////
00043 //     Function: PGSliderBar::set_axis
00044 //       Access: Published
00045 //  Description: Specifies the axis of the slider bar's motion.  This
00046 //               should be only one of four vectors: (1, 0, 0), (0, 0,
00047 //               1), (-1, 0, 0), or (0, 0, -1).
00048 //
00049 //               This specifies the vector in which the thumb moves
00050 //               when it is moving from the minimum to the maximum
00051 //               value.
00052 //
00053 //               The axis must be parallel to one of the screen axes,
00054 //               and it must be normalized.  Hence, it may only be one
00055 //               of the above four possibilities; anything else is an
00056 //               error and will result in indeterminate behavior.
00057 //
00058 //               Normally, you should not try to set the axis
00059 //               directly.
00060 ////////////////////////////////////////////////////////////////////
00061 INLINE void PGSliderBar:: 
00062 set_axis(const LVector3 &axis) {
00063   LightReMutexHolder holder(_lock);
00064   _axis = axis;
00065   _needs_remanage = true;
00066   _needs_recompute = true;
00067 }
00068 
00069 ////////////////////////////////////////////////////////////////////
00070 //     Function: PGSliderBar::get_axis
00071 //       Access: Published
00072 //  Description: Returns the axis of the slider bar's motion.  See
00073 //               set_axis().
00074 ////////////////////////////////////////////////////////////////////
00075 INLINE const LVector3 &PGSliderBar:: 
00076 get_axis() const {
00077   LightReMutexHolder holder(_lock);
00078   return _axis;
00079 }
00080 
00081 ////////////////////////////////////////////////////////////////////
00082 //     Function: PGSliderBar::set_range
00083 //       Access: Published
00084 //  Description: Sets the minimum and maxmimum value for the slider.
00085 ////////////////////////////////////////////////////////////////////
00086 INLINE void PGSliderBar:: 
00087 set_range(PN_stdfloat min_value, PN_stdfloat max_value) {
00088   LightReMutexHolder holder(_lock);
00089   nassertv(min_value != max_value);
00090   _min_value = min_value;
00091   _max_value = max_value;
00092   _needs_recompute = true;
00093 
00094   if (has_notify()) {
00095     get_notify()->slider_bar_set_range(this);
00096   }
00097 }
00098 
00099 ////////////////////////////////////////////////////////////////////
00100 //     Function: PGSliderBar::get_min_value
00101 //       Access: Published
00102 //  Description: Returns the value when the slider is all the way to
00103 //               the left.
00104 ////////////////////////////////////////////////////////////////////
00105 INLINE PN_stdfloat PGSliderBar:: 
00106 get_min_value() const {
00107   LightReMutexHolder holder(_lock);
00108   return _min_value;
00109 }
00110 
00111 ////////////////////////////////////////////////////////////////////
00112 //     Function: PGSliderBar::get_max_value
00113 //       Access: Published
00114 //  Description: Returns the value when the slider is all the way to
00115 //               the right.
00116 ////////////////////////////////////////////////////////////////////
00117 INLINE PN_stdfloat PGSliderBar:: 
00118 get_max_value() const {
00119   LightReMutexHolder holder(_lock);
00120   return _max_value;
00121 }
00122 
00123 ////////////////////////////////////////////////////////////////////
00124 //     Function: PGSliderBar::set_scroll_size
00125 //       Access: Published
00126 //  Description: Specifies the amount the slider will move when the
00127 //               user clicks on the left or right buttons.
00128 ////////////////////////////////////////////////////////////////////
00129 INLINE void PGSliderBar:: 
00130 set_scroll_size(PN_stdfloat value) {
00131   LightReMutexHolder holder(_lock);
00132   _scroll_value = value;
00133   _needs_recompute = true;
00134 }
00135 
00136 ////////////////////////////////////////////////////////////////////
00137 //     Function: PGSliderBar::get_scroll_size
00138 //       Access: Published
00139 //  Description: Returns the value last set by set_scroll_size().
00140 ////////////////////////////////////////////////////////////////////
00141 INLINE PN_stdfloat PGSliderBar:: 
00142 get_scroll_size() const {
00143   LightReMutexHolder holder(_lock);
00144   return _scroll_value;
00145 }
00146 
00147 ////////////////////////////////////////////////////////////////////
00148 //     Function: PGSliderBar::set_page_size
00149 //       Access: Published
00150 //  Description: Specifies the amount of data contained in a single
00151 //               page.  This indicates how much the thumb will jump
00152 //               when the trough is directly clicked; and if
00153 //               resize_thumb is true, it also controls the visible
00154 //               size of the thumb button.
00155 ////////////////////////////////////////////////////////////////////
00156 INLINE void PGSliderBar:: 
00157 set_page_size(PN_stdfloat value) {
00158   LightReMutexHolder holder(_lock);
00159   _page_value = value;
00160   _needs_recompute = true;
00161 }
00162 
00163 ////////////////////////////////////////////////////////////////////
00164 //     Function: PGSliderBar::get_page_size
00165 //       Access: Published
00166 //  Description: Returns the value last set by set_page_size().
00167 ////////////////////////////////////////////////////////////////////
00168 INLINE PN_stdfloat PGSliderBar:: 
00169 get_page_size() const {
00170   LightReMutexHolder holder(_lock);
00171   return _page_value;
00172 }
00173 
00174 ////////////////////////////////////////////////////////////////////
00175 //     Function: PGSliderBar::set_value
00176 //       Access: Published
00177 //  Description: Sets the current value of the slider
00178 //               programmatically.  This should range between
00179 //               get_min_value() and get_max_value().
00180 ////////////////////////////////////////////////////////////////////
00181 INLINE void PGSliderBar:: 
00182 set_value(PN_stdfloat value) {
00183   LightReMutexHolder holder(_lock);
00184   set_ratio((value - _min_value) / (_max_value - _min_value));
00185 }
00186 
00187 ////////////////////////////////////////////////////////////////////
00188 //     Function: PGSliderBar::get_value
00189 //       Access: Published
00190 //  Description: Returns the current value of the slider.
00191 ////////////////////////////////////////////////////////////////////
00192 INLINE PN_stdfloat PGSliderBar:: 
00193 get_value() const {
00194   LightReMutexHolder holder(_lock);
00195   return get_ratio() * (_max_value - _min_value) + _min_value;
00196 }
00197 
00198 ////////////////////////////////////////////////////////////////////
00199 //     Function: PGSliderBar::set_ratio
00200 //       Access: Published
00201 //  Description: Sets the current value of the slider, expressed in
00202 //               the range 0 .. 1.
00203 ////////////////////////////////////////////////////////////////////
00204 INLINE void PGSliderBar:: 
00205 set_ratio(PN_stdfloat ratio) {
00206   LightReMutexHolder holder(_lock);
00207   if (!is_button_down()) {
00208     internal_set_ratio(ratio);
00209   }
00210 }
00211 
00212 ////////////////////////////////////////////////////////////////////
00213 //     Function: PGSliderBar::get_ratio
00214 //       Access: Published
00215 //  Description: Returns the current value of the slider, expressed in
00216 //               the range 0 .. 1.
00217 ////////////////////////////////////////////////////////////////////
00218 INLINE PN_stdfloat PGSliderBar:: 
00219 get_ratio() const {
00220   LightReMutexHolder holder(_lock);
00221   return _ratio;
00222 }
00223 
00224 ////////////////////////////////////////////////////////////////////
00225 //     Function: PGSliderBar::is_button_down
00226 //       Access: Published
00227 //  Description: Returns true if the user is currently holding down
00228 //               the mouse button to manipulate the slider.  When
00229 //               true, calls to set_ratio() or set_value() will have
00230 //               no effect.
00231 ////////////////////////////////////////////////////////////////////
00232 INLINE bool PGSliderBar:: 
00233 is_button_down() const {
00234   LightReMutexHolder holder(_lock);
00235   return _dragging || _mouse_button_page || 
00236     (_scroll_button_held != (PGItem *)NULL);
00237 }
00238 
00239 ////////////////////////////////////////////////////////////////////
00240 //     Function: PGSliderBar::set_resize_thumb
00241 //       Access: Published
00242 //  Description: Sets the resize_thumb flag.  When this is true, the
00243 //               thumb button's frame will be adjusted so that its
00244 //               width visually represents the page size.  When this
00245 //               is false, the thumb button will be left alone.
00246 ////////////////////////////////////////////////////////////////////
00247 INLINE void PGSliderBar:: 
00248 set_resize_thumb(bool resize_thumb) {
00249   LightReMutexHolder holder(_lock);
00250   _resize_thumb = resize_thumb;
00251   _needs_recompute = true;
00252 }
00253 
00254 ////////////////////////////////////////////////////////////////////
00255 //     Function: PGSliderBar::get_resize_thumb
00256 //       Access: Published
00257 //  Description: Returns the resize_thumb flag.  See
00258 //               set_resize_thumb().
00259 ////////////////////////////////////////////////////////////////////
00260 INLINE bool PGSliderBar:: 
00261 get_resize_thumb() const {
00262   LightReMutexHolder holder(_lock);
00263   return _resize_thumb;
00264 }
00265 
00266 ////////////////////////////////////////////////////////////////////
00267 //     Function: PGSliderBar::set_manage_pieces
00268 //       Access: Published
00269 //  Description: Sets the manage_pieces flag.  When this is true, the
00270 //               sub-pieces of the slider bar--that is, the thumb, and
00271 //               the left and right scroll buttons--are automatically
00272 //               positioned and/or resized when the slider bar's
00273 //               overall frame is changed.
00274 ////////////////////////////////////////////////////////////////////
00275 INLINE void PGSliderBar:: 
00276 set_manage_pieces(bool manage_pieces) {
00277   LightReMutexHolder holder(_lock);
00278   _manage_pieces = manage_pieces;
00279   _needs_remanage = true;
00280   _needs_recompute = true;
00281 }
00282 
00283 ////////////////////////////////////////////////////////////////////
00284 //     Function: PGSliderBar::get_manage_pieces
00285 //       Access: Published
00286 //  Description: Returns the manage_pieces flag.  See
00287 //               set_manage_pieces().
00288 ////////////////////////////////////////////////////////////////////
00289 INLINE bool PGSliderBar:: 
00290 get_manage_pieces() const {
00291   LightReMutexHolder holder(_lock);
00292   return _manage_pieces;
00293 }
00294 
00295 ////////////////////////////////////////////////////////////////////
00296 //     Function: PGSliderBar::set_thumb_button
00297 //       Access: Published
00298 //  Description: Sets the PGButton object that will serve as the thumb
00299 //               for this slider.  This button visually represents the
00300 //               position of the slider, and can be dragged left and
00301 //               right by the user.
00302 //
00303 //               It is the responsibility of the caller to ensure that
00304 //               the button object is parented to the PGSliderBar
00305 //               node.
00306 ////////////////////////////////////////////////////////////////////
00307 INLINE void PGSliderBar::
00308 set_thumb_button(PGButton *thumb_button) {
00309   LightReMutexHolder holder(_lock);
00310   if (_thumb_button != (PGButton *)NULL) {
00311     _thumb_button->set_notify(NULL);
00312   }
00313   _thumb_button = thumb_button;
00314   if (_thumb_button != (PGButton *)NULL) {
00315     _thumb_button->set_notify(this);
00316   }
00317   _needs_remanage = true;
00318   _needs_recompute = true;
00319 }
00320 
00321 ////////////////////////////////////////////////////////////////////
00322 //     Function: PGSliderBar::clear_thumb_button
00323 //       Access: Published
00324 //  Description: Removes the thumb button object from control of the
00325 //               frame.  It is your responsibility to actually remove
00326 //               or hide the button itself.
00327 ////////////////////////////////////////////////////////////////////
00328 INLINE void PGSliderBar::
00329 clear_thumb_button() {
00330   set_thumb_button(NULL);
00331 }
00332 
00333 ////////////////////////////////////////////////////////////////////
00334 //     Function: PGSliderBar::get_thumb_button
00335 //       Access: Published
00336 //  Description: Returns the PGButton that serves as the thumb for
00337 //               this slider, or NULL if it is not set.
00338 ////////////////////////////////////////////////////////////////////
00339 INLINE PGButton *PGSliderBar::
00340 get_thumb_button() const {
00341   LightReMutexHolder holder(_lock);
00342   return _thumb_button;
00343 }
00344 
00345 ////////////////////////////////////////////////////////////////////
00346 //     Function: PGSliderBar::set_left_button
00347 //       Access: Published
00348 //  Description: Sets the PGButton object that will serve as the left
00349 //               scroll button for this slider.  This button is
00350 //               optional; if present, the user can click on it to
00351 //               move scroll_size units at a time to the left.
00352 //
00353 //               It is the responsibility of the caller to ensure that
00354 //               the button object is parented to the PGSliderBar
00355 //               node.
00356 ////////////////////////////////////////////////////////////////////
00357 INLINE void PGSliderBar::
00358 set_left_button(PGButton *left_button) {
00359   LightReMutexHolder holder(_lock);
00360   if (_left_button != (PGButton *)NULL) {
00361     _left_button->set_notify(NULL);
00362   }
00363   _left_button = left_button;
00364   if (_left_button != (PGButton *)NULL) {
00365     _left_button->set_notify(this);
00366   }
00367   _needs_remanage = true;
00368   _needs_recompute = true;
00369 }
00370 
00371 ////////////////////////////////////////////////////////////////////
00372 //     Function: PGSliderBar::clear_left_button
00373 //       Access: Published
00374 //  Description: Removes the left button object from control of the
00375 //               frame.  It is your responsibility to actually remove
00376 //               or hide the button itself.
00377 ////////////////////////////////////////////////////////////////////
00378 INLINE void PGSliderBar::
00379 clear_left_button() {
00380   set_left_button(NULL);
00381 }
00382 
00383 ////////////////////////////////////////////////////////////////////
00384 //     Function: PGSliderBar::get_left_button
00385 //       Access: Published
00386 //  Description: Returns the PGButton that serves as the left scroll
00387 //               button for this slider, if any, or NULL if it is not
00388 //               set.
00389 ////////////////////////////////////////////////////////////////////
00390 INLINE PGButton *PGSliderBar::
00391 get_left_button() const {
00392   LightReMutexHolder holder(_lock);
00393   return _left_button;
00394 }
00395 
00396 ////////////////////////////////////////////////////////////////////
00397 //     Function: PGSliderBar::set_right_button
00398 //       Access: Published
00399 //  Description: Sets the PGButton object that will serve as the right
00400 //               scroll button for this slider.  This button is
00401 //               optional; if present, the user can click on it to
00402 //               move scroll_size units at a time to the right.
00403 //
00404 //               It is the responsibility of the caller to ensure that
00405 //               the button object is parented to the PGSliderBar
00406 //               node.
00407 ////////////////////////////////////////////////////////////////////
00408 INLINE void PGSliderBar::
00409 set_right_button(PGButton *right_button) {
00410   LightReMutexHolder holder(_lock);
00411   if (_right_button != (PGButton *)NULL) {
00412     _right_button->set_notify(NULL);
00413   }
00414   _right_button = right_button;
00415   if (_right_button != (PGButton *)NULL) {
00416     _right_button->set_notify(this);
00417   }
00418   _needs_remanage = true;
00419   _needs_recompute = true;
00420 }
00421 
00422 ////////////////////////////////////////////////////////////////////
00423 //     Function: PGSliderBar::clear_right_button
00424 //       Access: Published
00425 //  Description: Removes the right button object from control of the
00426 //               frame.  It is your responsibility to actually remove
00427 //               or hide the button itself.
00428 ////////////////////////////////////////////////////////////////////
00429 INLINE void PGSliderBar::
00430 clear_right_button() {
00431   set_right_button(NULL);
00432 }
00433 
00434 ////////////////////////////////////////////////////////////////////
00435 //     Function: PGSliderBar::get_right_button
00436 //       Access: Published
00437 //  Description: Returns the PGButton that serves as the right scroll
00438 //               button for this slider, if any, or NULL if it is not
00439 //               set.
00440 ////////////////////////////////////////////////////////////////////
00441 INLINE PGButton *PGSliderBar::
00442 get_right_button() const {
00443   LightReMutexHolder holder(_lock);
00444   return _right_button;
00445 }
00446 
00447 ////////////////////////////////////////////////////////////////////
00448 //     Function: PGSliderBar::get_adjust_prefix
00449 //       Access: Published, Static
00450 //  Description: Returns the prefix that is used to define the adjust
00451 //               event for all PGSliderBars.  The adjust event is the
00452 //               concatenation of this string followed by get_id().
00453 ////////////////////////////////////////////////////////////////////
00454 INLINE string PGSliderBar::
00455 get_adjust_prefix() {
00456   return "adjust-";
00457 }
00458 
00459 ////////////////////////////////////////////////////////////////////
00460 //     Function: PGSliderBar::get_adjust_event
00461 //       Access: Published
00462 //  Description: Returns the event name that will be thrown when the
00463 //               slider bar value is adjusted by the user or
00464 //               programmatically.
00465 ////////////////////////////////////////////////////////////////////
00466 INLINE string PGSliderBar::
00467 get_adjust_event() const {
00468   LightReMutexHolder holder(_lock);
00469   return get_adjust_prefix() + get_id();
00470 }
00471 
00472 ////////////////////////////////////////////////////////////////////
00473 //     Function: PGSliderBar::internal_set_ratio
00474 //       Access: Private
00475 //  Description: Sets the current value of the slider, expressed in
00476 //               the range 0 .. 1, without checking whether the user
00477 //               is currently manipulating the slider.
00478 ////////////////////////////////////////////////////////////////////
00479 INLINE void PGSliderBar:: 
00480 internal_set_ratio(PN_stdfloat ratio) {
00481   _ratio = max(min(ratio, (PN_stdfloat)1.0), (PN_stdfloat)0.0);
00482   _needs_reposition = true;
00483   adjust();
00484 }
 All Classes Functions Variables Enumerations