1 #include <msp/gl/matrix.h>
2 #include <msp/gl/meshbuilder.h>
15 void HSlider::autosize()
22 if(const Part *slider_part = style->get_part("slider"))
24 const Sides &margin = slider_part->get_margin();
25 const Geometry &pgeom = slider_part->get_geometry();
26 geom.w = std::max(geom.w, pgeom.w*3/2+margin.left+margin.right);
27 geom.h = std::max(geom.h, pgeom.h+margin.top+margin.bottom);
31 void HSlider::rebuild_special(const Part &part, CachedPart &cache)
33 if(part.get_name()=="slider")
35 Alignment align = part.get_alignment();
37 align.x = (value-min)/(max-min);
39 Geometry pgeom = part.get_geometry();
40 align.apply(pgeom, geom, part.get_margin());
42 cache.texture = part.get_graphic(state)->get_texture();
45 GL::MeshBuilder bld(*cache.mesh);
46 bld.matrix() *= GL::Matrix::translation(pgeom.x, pgeom.y, 0);
47 part.get_graphic(state)->build(pgeom.w, pgeom.h, bld);
51 void HSlider::button_press(int x, int y, unsigned btn)
53 if(btn==1 && geom.is_inside_relative(x, y) && max>min)
55 int sx = static_cast<int>((geom.w-slider_size)*(value-min)/(max-min));
57 set_value(value-step*10);
58 else if(x>=static_cast<int>(sx+slider_size))
59 set_value(value+step*10);
65 void HSlider::button_release(int, int, unsigned btn)
67 if(btn==1 && dragging)
71 void HSlider::pointer_motion(int x, int)
77 void HSlider::on_geometry_change()
79 drag_area_size = geom.w-slider_size;
82 void HSlider::on_style_change()
87 if(const Part *slider_part = style->get_part("slider"))
88 slider_size = slider_part->get_geometry().w;