1 #include <msp/gl/matrix.h>
2 #include <msp/gl/meshbuilder.h>
15 void VSlider::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+margin.left+margin.right);
27 geom.h = std::max(geom.h, pgeom.h*3/2+margin.top+margin.bottom);
31 void VSlider::rebuild_special(const Part &part, CachedPart &cache)
33 if(part.get_name()=="slider")
35 const Graphic *graphic = part.get_graphic(state);
39 Alignment align = part.get_alignment();
41 align.y = (value-min)/(max-min);
43 Geometry pgeom = part.get_geometry();
44 align.apply(pgeom, geom, part.get_margin());
46 cache.texture = part.get_graphic(state)->get_texture();
49 GL::MeshBuilder bld(*cache.mesh);
50 bld.matrix() *= GL::Matrix::translation(pgeom.x, pgeom.y, 0);
51 graphic->build(pgeom.w, pgeom.h, bld);
55 void VSlider::button_press(int x, int y, unsigned btn)
57 if(btn==1 && geom.is_inside_relative(x, y) && max>min)
59 int sy = static_cast<int>((geom.h-slider_size)*(value-min)/(max-min));
61 set_value(value-step*10);
62 else if(y>=static_cast<int>(sy+slider_size))
63 set_value(value+step*10);
69 void VSlider::button_release(int, int, unsigned btn)
71 if(btn==1 && dragging)
75 void VSlider::pointer_motion(int, int y)
81 void VSlider::on_geometry_change()
83 drag_area_size = geom.h-slider_size;
86 void VSlider::on_style_change()
91 if(const Part *slider_part = style->get_part("slider"))
92 slider_size = slider_part->get_geometry().h;