From: Mikko Rasa Date: Tue, 21 Jan 2014 20:53:24 +0000 (+0200) Subject: Move some more common slider code to the base class X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=08b66dd1b4478fef61525ad2dad1a1fb54eab0f0;p=libs%2Fgltk.git Move some more common slider code to the base class --- diff --git a/source/hslider.cpp b/source/hslider.cpp index dcb7634..4fecfa4 100644 --- a/source/hslider.cpp +++ b/source/hslider.cpp @@ -8,8 +8,7 @@ namespace Msp { namespace GLtk { -HSlider::HSlider(): - slider_size(1) +HSlider::HSlider() { } void HSlider::autosize_special(const Part &part, Geometry &ageom) const @@ -47,15 +46,7 @@ void HSlider::rebuild_special(const Part &part) void HSlider::button_press(int x, int, unsigned btn) { if(btn==1 && max>min) - { - int sx = static_cast((geom.w-slider_size)*(value-min)/(max-min)); - if(x=static_cast(sx+slider_size)) - set_value(value+step*10); - else - start_drag(x); - } + click(x); } void HSlider::button_release(int, int, unsigned btn) diff --git a/source/hslider.h b/source/hslider.h index 774c736..f0cf8d3 100644 --- a/source/hslider.h +++ b/source/hslider.h @@ -12,9 +12,6 @@ the current value of the widget. */ class HSlider: public Slider { -private: - unsigned slider_size; - public: HSlider(); diff --git a/source/slider.cpp b/source/slider.cpp index 7123458..15621db 100644 --- a/source/slider.cpp +++ b/source/slider.cpp @@ -9,7 +9,8 @@ Slider::Slider(): value(0), step(0.1), dragging(false), - drag_area_size(0) + drag_area_size(0), + slider_size(1) { } void Slider::set_value(double v) @@ -46,6 +47,17 @@ void Slider::set_step(double s) set_value(value); } +void Slider::click(int p) +{ + int sp = static_cast(drag_area_size*(value-min)/(max-min)); + if(p=static_cast(sp+slider_size)) + set_value(value+step*10); + else + start_drag(p); +} + void Slider::start_drag(int p) { dragging = true; diff --git a/source/slider.h b/source/slider.h index 6612c61..a239576 100644 --- a/source/slider.h +++ b/source/slider.h @@ -32,6 +32,7 @@ protected: double drag_start_pos; double drag_start_value; unsigned drag_area_size; + unsigned slider_size; Slider(); @@ -42,6 +43,7 @@ public: double get_value() const { return value; } protected: + void click(int); void start_drag(int); void drag(int); void end_drag(); diff --git a/source/vslider.cpp b/source/vslider.cpp index d32c57d..4776e67 100644 --- a/source/vslider.cpp +++ b/source/vslider.cpp @@ -8,8 +8,7 @@ namespace Msp { namespace GLtk { -VSlider::VSlider(): - slider_size(1) +VSlider::VSlider() { } void VSlider::autosize_special(const Part &part, Geometry &ageom) const @@ -47,15 +46,7 @@ void VSlider::rebuild_special(const Part &part) void VSlider::button_press(int, int y, unsigned btn) { if(btn==1 && max>min) - { - int sy = static_cast((geom.h-slider_size)*(value-min)/(max-min)); - if(y=static_cast(sy+slider_size)) - set_value(value+step*10); - else - start_drag(y); - } + click(y); } void VSlider::button_release(int, int, unsigned btn) diff --git a/source/vslider.h b/source/vslider.h index ee12689..987d83a 100644 --- a/source/vslider.h +++ b/source/vslider.h @@ -8,9 +8,6 @@ namespace GLtk { class VSlider: public Slider { -private: - unsigned slider_size; - public: VSlider();