namespace GLtk {
HSlider::HSlider():
- slider_size(1)
+ total_margin(0)
{ }
-void HSlider::autosize()
+void HSlider::autosize_special(const Part &part, Geometry &ageom) const
{
- if(!style)
- return;
-
- Widget::autosize();
-
- if(const Part *slider_part = style->get_part("slider"))
+ if(part.get_name()=="slider")
{
- const Sides &margin = slider_part->get_margin();
- const Geometry &pgeom = slider_part->get_geometry();
- geom.w = std::max(geom.w, pgeom.w*3/2+margin.left+margin.right);
- geom.h = std::max(geom.h, pgeom.h+margin.top+margin.bottom);
+ const Sides &margin = part.get_margin();
+ const Geometry &pgeom = part.get_geometry();
+ ageom.w = std::max(ageom.w, pgeom.w*3/2+margin.left+margin.right);
+ ageom.h = std::max(ageom.h, pgeom.h+margin.top+margin.bottom);
}
}
-void HSlider::rebuild_special(const Part &part, CachedPart &cache)
+void HSlider::rebuild_special(const Part &part)
{
if(part.get_name()=="slider")
{
+ const Graphic *graphic = part.get_graphic(state);
+ if(!graphic || !graphic->get_texture())
+ return;
+
Alignment align = part.get_alignment();
if(max>min)
align.x = (value-min)/(max-min);
Geometry pgeom = part.get_geometry();
align.apply(pgeom, geom, part.get_margin());
- cache.texture = part.get_graphic(state)->get_texture();
- cache.clear_mesh();
-
- GL::MeshBuilder bld(*cache.mesh);
+ GL::MeshBuilder bld(part_cache.create_mesh(part, *graphic->get_texture()));
bld.matrix() *= GL::Matrix::translation(pgeom.x, pgeom.y, 0);
- part.get_graphic(state)->build(pgeom.w, pgeom.h, bld);
+ graphic->build(pgeom.w, pgeom.h, bld);
}
}
-void HSlider::button_press(int x, int y, unsigned btn)
+void HSlider::button_press(int x, int, unsigned btn)
{
- if(btn==1 && geom.is_inside_relative(x, y) && max>min)
- {
- int sx = static_cast<int>((geom.w-slider_size)*(value-min)/(max-min));
- if(x<sx)
- set_value(value-step*10);
- else if(x>=static_cast<int>(sx+slider_size))
- set_value(value+step*10);
- else
- start_drag(x);
- }
+ if(btn==1 && max>min)
+ click(x);
}
void HSlider::button_release(int, int, unsigned btn)
drag(x);
}
-void HSlider::on_geometry_change()
+void HSlider::on_size_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();
+ on_size_change();
}
} // namespace GLtk