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 Alignment align = part.get_alignment();
37 align.y = (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 VSlider::button_press(int x, int y, unsigned btn)
53 if(btn==1 && geom.is_inside_relative(x, y) && max>min)
55 int sy = static_cast<int>((geom.h-slider_size)*(value-min)/(max-min));
57 set_value(value-step*10);
58 else if(y>=static_cast<int>(sy+slider_size))
59 set_value(value+step*10);
65 void VSlider::button_release(int, int, unsigned btn)
67 if(btn==1 && dragging)
71 void VSlider::pointer_motion(int, int y)
77 void VSlider::on_geometry_change()
79 drag_area_size = geom.h-slider_size;
82 void VSlider::on_style_change()
87 if(const Part *slider_part = style->get_part("slider"))
88 slider_size = slider_part->get_geometry().h;