namespace Msp {
namespace GLtk {
-HSlider::HSlider()
+HSlider::HSlider():
+ total_margin(0)
{ }
void HSlider::autosize_special(const Part &part, Geometry &ageom) const
void HSlider::on_geometry_change()
{
- drag_area_size = geom.w-slider_size;
+ drag_area_size = geom.w-total_margin;
}
void HSlider::on_style_change()
return;
if(const Part *slider_part = style->get_part("slider"))
+ {
slider_size = slider_part->get_geometry().w;
+ const Sides &margin = slider_part->get_margin();
+ drag_area_offset = margin.left;
+ total_margin = margin.left+margin.right;
+ }
on_geometry_change();
}
*/
class HSlider: public Slider
{
+private:
+ unsigned total_margin;
+
public:
HSlider();
step(0.1),
dragging(false),
drag_area_size(0),
+ drag_area_offset(0),
slider_size(1)
{ }
void Slider::click(int p)
{
- int sp = static_cast<int>(drag_area_size*(value-min)/(max-min));
+ p -= drag_area_offset;
+ if(p<0 || p>=static_cast<int>(drag_area_size))
+ return;
+
+ int sp = static_cast<int>((drag_area_size-slider_size)*(value-min)/(max-min));
if(p<sp)
set_value(value-step*10);
else if(p>=static_cast<int>(sp+slider_size))
set_value(value+step*10);
else
- start_drag(p);
+ start_drag(drag_area_offset+p);
}
void Slider::start_drag(int p)
void Slider::drag(int p)
{
if(max>min)
- set_value(drag_start_value+(p-drag_start_pos)*(max-min)/drag_area_size);
+ set_value(drag_start_value+(p-drag_start_pos)*(max-min)/(drag_area_size-slider_size));
}
void Slider::end_drag()
double drag_start_pos;
double drag_start_value;
unsigned drag_area_size;
+ unsigned drag_area_offset;
unsigned slider_size;
Slider();
namespace Msp {
namespace GLtk {
-VSlider::VSlider()
+VSlider::VSlider():
+ total_margin(0)
{ }
void VSlider::autosize_special(const Part &part, Geometry &ageom) const
void VSlider::on_geometry_change()
{
- drag_area_size = geom.h-slider_size;
+ drag_area_size = geom.h-total_margin;
}
void VSlider::on_style_change()
return;
if(const Part *slider_part = style->get_part("slider"))
+ {
slider_size = slider_part->get_geometry().h;
+ const Sides &margin = slider_part->get_margin();
+ drag_area_offset = margin.bottom;
+ total_margin = margin.bottom+margin.top;
+ }
on_geometry_change();
}
class VSlider: public Slider
{
+private:
+ unsigned total_margin;
+
public:
VSlider();