max(1),
value(0),
step(0.1),
+ page_size(0.25),
dragging(false),
drag_area_size(0),
drag_area_offset(0),
+ slider_min_size(1),
slider_size(1),
total_margin(0)
{ }
set_value(value);
}
+void Slider::set_page_size(double p)
+{
+ page_size = p;
+ mark_rebuild();
+}
+
void Slider::autosize_special(const Part &part, Geometry &ageom) const
{
if(part.get_name()=="slider")
return;
float pos_fraction = ((max>min) ? (value-min)/(max-min) : 0);
+ float fill_fraction = ((max>min) ? page_size/(max-min+page_size) : 1);
Alignment align = part.get_alignment();
+ Geometry sgeom = geom;
if(dir==HORIZONTAL)
+ {
align.x = pos_fraction;
+ sgeom.w = std::max(slider_min_size+total_margin, static_cast<unsigned>(sgeom.w*fill_fraction));
+ }
else
+ {
align.y = pos_fraction;
+ sgeom.h = std::max(slider_min_size+total_margin, static_cast<unsigned>(sgeom.h*fill_fraction));
+ }
+
+ sgeom.x = static_cast<unsigned>((geom.w-sgeom.w)*pos_fraction);
+ sgeom.y = static_cast<unsigned>((geom.h-sgeom.h)*pos_fraction);
Geometry rgeom = part.get_geometry();
- align.apply(rgeom, geom, part.get_margin());
+ align.apply(rgeom, sgeom, part.get_margin());
+ slider_size = (dir==HORIZONTAL ? rgeom.w : rgeom.h);
GL::MeshBuilder bld(part_cache.create_mesh(part, *graphic->get_texture()));
- bld.matrix() *= GL::Matrix::translation(rgeom.x, rgeom.y, 0);
+ bld.matrix() *= GL::Matrix::translation(sgeom.x+rgeom.x, sgeom.y+rgeom.y, 0);
graphic->build(rgeom.w, rgeom.h, bld);
}
}
int sp = static_cast<int>((drag_area_size-slider_size)*(value-min)/(max-min));
if(p<sp)
- set_value(value-step*10);
+ set_value(value-page_size);
else if(p>=static_cast<int>(sp+slider_size))
- set_value(value+step*10);
+ set_value(value+page_size);
else
{
dragging = true;
const Sides &margin = slider_part->get_margin();
if(dir==HORIZONTAL)
{
- slider_size = pgeom.w;
+ slider_min_size = pgeom.w;
drag_area_offset = margin.left;
total_margin = margin.left+margin.right;
}
else
{
- slider_size = pgeom.h;
+ slider_min_size = pgeom.h;
drag_area_offset = margin.bottom;
total_margin = margin.bottom+margin.top;
}
{
add("range", &Slider::min, &Slider::max);
add("step", &Slider::step);
+ add("page_size", &Slider::page_size);
add("value", &Slider::value);
}