From 223f3f35ad8241209efbde1740b8e112a8162773 Mon Sep 17 00:00:00 2001 From: "Asad M. Zaman" Date: Fri, 19 Aug 2005 19:29:43 +0000 Subject: [PATCH] changed one interface in anticipation of future slider rotation --- panda/src/pgui/pgSliderBar.I | 42 ++++++++++++++++++++++++++++++---- panda/src/pgui/pgSliderBar.cxx | 27 +++++++++++++--------- panda/src/pgui/pgSliderBar.h | 9 ++++++-- 3 files changed, 60 insertions(+), 18 deletions(-) diff --git a/panda/src/pgui/pgSliderBar.I b/panda/src/pgui/pgSliderBar.I index 536e275709..225fd17b7a 100755 --- a/panda/src/pgui/pgSliderBar.I +++ b/panda/src/pgui/pgSliderBar.I @@ -38,6 +38,27 @@ get_range() const { return _range; } +/* +//////////////////////////////////////////////////////////////////// +// Function: PGSliderBar::set_magnifier +// Access: Published +// Description: Sets a magnifier value for the mouseWatcherRegion in +// the Y direction. +//////////////////////////////////////////////////////////////////// +INLINE void PGSliderBar:: +set_magnifier(float value) { + PGItem::_mouseWatcherMagnifier = value; +} +//////////////////////////////////////////////////////////////////// +// Function: PGSliderBar::get_value +// Access: Published +// Description: Returns the current value of the bar. +//////////////////////////////////////////////////////////////////// +INLINE float PGSliderBar:: +get_magnifier() const { + return PGItem::_mouseWatcherMagnifier; +} +*/ //////////////////////////////////////////////////////////////////// // Function: PGSliderBar::set_value // Access: Published @@ -48,7 +69,7 @@ INLINE void PGSliderBar:: set_value(float value) { _value = value; _mapped_value = _negative_mapping ? (_value*0.5 + 0.5) : _value; - _update_position = _width * (2*_mapped_value - 1); + _update_x = _width * (2*_mapped_value - 1); _bar_state = -1; _update_slider = true; } @@ -75,14 +96,25 @@ get_mapped_value() const { } //////////////////////////////////////////////////////////////////// -// Function: PGSliderBar::get_update_position +// Function: PGSliderBar::get_update_x // Access: Published -// Description: Returns the _update_position which is caluclated from +// Description: Returns the _update_x which is caluclated from // _mapped_value with width formula //////////////////////////////////////////////////////////////////// INLINE float PGSliderBar:: -get_update_position() const { - return _update_position; +get_update_x() const { + return _update_x; +} + +//////////////////////////////////////////////////////////////////// +// Function: PGSliderBar::get_update_y +// Access: Published +// Description: Returns the _update_y which is caluclated from +// _mapped_value with width formula +//////////////////////////////////////////////////////////////////// +INLINE float PGSliderBar:: +get_update_y() const { + return _update_y; } //////////////////////////////////////////////////////////////////// diff --git a/panda/src/pgui/pgSliderBar.cxx b/panda/src/pgui/pgSliderBar.cxx index f53e247334..3bf2890d82 100755 --- a/panda/src/pgui/pgSliderBar.cxx +++ b/panda/src/pgui/pgSliderBar.cxx @@ -41,8 +41,8 @@ PGSliderBar(const string &name) : _value = 0.0; // _mapped_value is a mapping of (-1<->1) into (0<->1) _mapped_value = 0.5*_value + 0.5; - // _update_position is mapping of _mapped_value wrt slider width - _update_position = 0.0; //will be set when _width is defined + // _update_x is mapping of _mapped_value wrt slider width + _update_x = 0.0; //will be set when _width is defined _speed = 0.05; _scale = 0.05; _bar_state = -1; @@ -200,14 +200,16 @@ void PGSliderBar:: press(const MouseWatcherParameter ¶m, bool background) { PGItem::press(param, background); //pgui_cat.info() << get_name() << "::" << param << endl; - //pgui_cat.info() << _slider->get_name() << "::press:" << _slider_button.get_x() << endl; + //pgui_cat.info() << _slider->get_name() << "::press:x" << _slider_button.get_x() + // << " press:y" << _slider_button.get_y() << endl; // translate the mouse param position into frame space LPoint2f mouse_point = param.get_mouse(); LVector3f result(mouse_point[0], mouse_point[1], 0); result = get_frame_inv_xform().xform_point(result); _update_slider = true; - _update_position = result[0]; + _update_x = result[0]; + _update_y = result[1]; //_slider_button.set_x(result[0]); } @@ -220,7 +222,8 @@ press(const MouseWatcherParameter ¶m, bool background) { void PGSliderBar:: drag(const MouseWatcherParameter ¶m) { //pgui_cat.info() << get_name() << "::" << param << endl; - //pgui_cat.info() << _slider->get_name() << "::drag:" << _slider_button.get_x() << endl; + //pgui_cat.info() << _slider->get_name() << "::drag:x" << _slider_button.get_x() + // <<" drag:y" << _slider_button.get_y() << endl; // translate the mouse param position into frame space LPoint2f mouse_point = param.get_mouse(); @@ -232,7 +235,8 @@ drag(const MouseWatcherParameter ¶m) { if (result[0] > _width) result[0] = _width; _update_slider = true; - _update_position = result[0]; + _update_x = result[0]; + _update_y = result[1]; //_slider_button.set_x(result[0]); } @@ -253,7 +257,7 @@ update() { // move the slider to the left float x = _slider_button.get_x() - _speed; _update_slider = true; - _update_position = max(x, -_width); + _update_x = max(x, -_width); //_slider_button.set_x(max(x, -_width)); } @@ -261,7 +265,7 @@ update() { // move the slider to the right float x = _slider_button.get_x() + _speed; _update_slider = true; - _update_position = min(x, _width); + _update_x = min(x, _width); //_slider_button.set_x(min(x, _width)); } } @@ -270,10 +274,11 @@ update() { // applied here so that value of current slider position as a ratio // of range can be updated if (_update_slider) { - //pgui_cat.info() << "mouse_point: " << _update_position << endl; + //pgui_cat.info() << "mouse_point:x " << _update_x + // << " mouse_point:y " << _update_y << endl; if (!_slider_button.is_empty()) - _slider_button.set_x(_update_position); - _mapped_value = (_update_position + _width)/(2*_width); + _slider_button.set_x(_update_x); + _mapped_value = (_update_x + _width)/(2*_width); _value = _negative_mapping ? ((_mapped_value-0.5)*2) : _mapped_value; _update_slider = false; throw_event(get_click_event()); diff --git a/panda/src/pgui/pgSliderBar.h b/panda/src/pgui/pgSliderBar.h index 46c57afac6..7426d767d4 100755 --- a/panda/src/pgui/pgSliderBar.h +++ b/panda/src/pgui/pgSliderBar.h @@ -52,10 +52,14 @@ PUBLISHED: INLINE void set_range(float range); INLINE float get_range() const; + //INLINE void set_magnifier(float value); + //INLINE float get_magnifier() const; + INLINE void set_value(float value); INLINE float get_value() const; INLINE float get_mapped_value() const; - INLINE float get_update_position() const; + INLINE float get_update_x() const; + INLINE float get_update_y() const; INLINE void set_speed(float speed); INLINE float get_speed() const; @@ -88,7 +92,8 @@ private: // These 3 variables control slider range float _value; float _mapped_value; - float _update_position; + float _update_x; + float _update_y; float _range; float _speed, _width;