Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r48709 - in sandbox/guigl: boost/guigl boost/guigl/widget libs/guigl/example libs/guigl/src/widget
From: stipe_at_[hidden]
Date: 2008-09-10 17:41:47


Author: srajko
Date: 2008-09-10 17:41:46 EDT (Wed, 10 Sep 2008)
New Revision: 48709
URL: http://svn.boost.org/trac/boost/changeset/48709

Log:
slider supports min,max,step
Text files modified:
   sandbox/guigl/boost/guigl/parameters.hpp | 3 +++
   sandbox/guigl/boost/guigl/widget/slider.hpp | 11 +++++------
   sandbox/guigl/libs/guigl/example/window_example.cpp | 4 +++-
   sandbox/guigl/libs/guigl/src/widget/slider.cpp | 21 +++++++++++++++++----
   4 files changed, 28 insertions(+), 11 deletions(-)

Modified: sandbox/guigl/boost/guigl/parameters.hpp
==============================================================================
--- sandbox/guigl/boost/guigl/parameters.hpp (original)
+++ sandbox/guigl/boost/guigl/parameters.hpp 2008-09-10 17:41:46 EDT (Wed, 10 Sep 2008)
@@ -22,6 +22,9 @@
     BOOST_PARAMETER_TYPED_NAME_WDEFAULT(color,const color_type,(color_type(1,1,1)))
     BOOST_PARAMETER_TYPED_NAME_WDEFAULT(active_color,const color_type,(color_type(1,0,0)))
     BOOST_PARAMETER_TYPED_NAME_WDEFAULT(depth,const bool,false)
+ BOOST_PARAMETER_TYPED_NAME_WDEFAULT(min,const double,0.0)
+ BOOST_PARAMETER_TYPED_NAME_WDEFAULT(max,const double,1.0)
+ BOOST_PARAMETER_TYPED_NAME_WDEFAULT(step,const double,0.0)
     
     typedef boost::parameter::aux::empty_typed_arg_list default_parameters;
 }

Modified: sandbox/guigl/boost/guigl/widget/slider.hpp
==============================================================================
--- sandbox/guigl/boost/guigl/widget/slider.hpp (original)
+++ sandbox/guigl/boost/guigl/widget/slider.hpp 2008-09-10 17:41:46 EDT (Wed, 10 Sep 2008)
@@ -34,7 +34,8 @@
     template<typename ArgumentPack>
     slider(const ArgumentPack &args)
         : slider_base_type(args)
- , m_value(0)
+ , m_value(args[_min])
+ , m_min(args[_min]), m_max(args[_max]), m_step(args[_step])
     {}
 
     /// Signal emitting changed values.
@@ -45,16 +46,14 @@
     { return m_value; }
     
     /// Sets the value of the slider.
- void set_value(double value)
- {
- m_value = value;
- on_value_change(value);
- }
+ void set_value(double value);
 protected:
     BOOST_GUIGL_WIDGET_DRAW
     
 private:
     double m_value;
+ double m_min, m_max, m_step;
+
     void draggable_on_drag(const position_type &position);
     
     friend class view::draggable<slider,

Modified: sandbox/guigl/libs/guigl/example/window_example.cpp
==============================================================================
--- sandbox/guigl/libs/guigl/example/window_example.cpp (original)
+++ sandbox/guigl/libs/guigl/example/window_example.cpp 2008-09-10 17:41:46 EDT (Wed, 10 Sep 2008)
@@ -54,7 +54,9 @@
         _size=size_type(100,30),
         _position=position_type(50,80),
         _background=color_type(0.5,0.5,0.5),
- _active_color=color_type(0,1,0) ));
+ _active_color=color_type(0,1,0),
+ _min=0.1,_max=0.9,
+ _step=0.1 ));
     test_window1 << s;
 
     // clicking the button changes the slider value to 0.5

Modified: sandbox/guigl/libs/guigl/src/widget/slider.cpp
==============================================================================
--- sandbox/guigl/libs/guigl/src/widget/slider.cpp (original)
+++ sandbox/guigl/libs/guigl/src/widget/slider.cpp 2008-09-10 17:41:46 EDT (Wed, 10 Sep 2008)
@@ -24,7 +24,7 @@
     base_type::draw_prologue();
 
     use_active_color();
- glRectd(0,0,m_value * size().x, size().y);
+ glRectd(0,0,(m_value-m_min) * size().x / (m_max-m_min), size().y);
 }
 
 inline void slider::draw_epilogue()
@@ -34,9 +34,22 @@
 
 void slider::draggable_on_drag(const position_type &position)
 {
- m_value = position.x / size().x;
- guigl::window::redraw(*this);
- on_value_change(m_value);
+ double new_value = (position.x / size().x) * (m_max-m_min);
+ if(m_step!=0.0)
+ new_value = round(new_value / m_step) * m_step;
+ new_value += m_min;
+ set_value(new_value);
 }
 
+void slider::set_value(double value)
+{
+ if(m_value != value)
+ {
+ m_value = value;
+ on_value_change(value);
+ guigl::window::redraw(*this);
+ }
+}
+
+
 }}}
\ No newline at end of file


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk