1 #include <msp/gl/matrix.h>
2 #include <msp/gl/meshbuilder.h>
15 void VSlider::autosize_special(const Part &part, Geometry &ageom)
17 if(part.get_name()=="slider")
19 const Sides &margin = part.get_margin();
20 const Geometry &pgeom = part.get_geometry();
21 ageom.w = std::max(ageom.w, pgeom.w+margin.left+margin.right);
22 ageom.h = std::max(ageom.h, pgeom.h*3/2+margin.top+margin.bottom);
26 void VSlider::rebuild_special(const Part &part)
28 if(part.get_name()=="slider")
30 const Graphic *graphic = part.get_graphic(state);
31 if(!graphic || !graphic->get_texture())
34 Alignment align = part.get_alignment();
36 align.y = (value-min)/(max-min);
38 Geometry pgeom = part.get_geometry();
39 align.apply(pgeom, geom, part.get_margin());
41 GL::MeshBuilder bld(part_cache.create_mesh(part, *graphic->get_texture()));
42 bld.matrix() *= GL::Matrix::translation(pgeom.x, pgeom.y, 0);
43 graphic->build(pgeom.w, pgeom.h, bld);
47 void VSlider::button_press(int x, int y, unsigned btn)
49 if(btn==1 && geom.is_inside_relative(x, y) && max>min)
51 int sy = static_cast<int>((geom.h-slider_size)*(value-min)/(max-min));
53 set_value(value-step*10);
54 else if(y>=static_cast<int>(sy+slider_size))
55 set_value(value+step*10);
61 void VSlider::button_release(int, int, unsigned btn)
63 if(btn==1 && dragging)
67 void VSlider::pointer_motion(int, int y)
73 void VSlider::on_geometry_change()
75 drag_area_size = geom.h-slider_size;
78 void VSlider::on_style_change()
83 if(const Part *slider_part = style->get_part("slider"))
84 slider_size = slider_part->get_geometry().h;