3 This file is part of libmspgltk
4 Copyright © 2007 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
8 #include <msp/gl/matrix.h>
9 #include <msp/gl/transform.h>
18 VSlider::VSlider(const Resources &r):
25 void VSlider::button_press(int x, int y, unsigned btn)
27 if(geom.is_inside(x, y))
29 int sh=get_slider_height();
30 int sy=geom.y+static_cast<int>((geom.h-sh)*(value-min)/(max-min));
31 if(btn==1 && y>=sy && y<sy+sh)
36 drag_start_value=value;
41 void VSlider::button_release(int, int, unsigned btn)
50 void VSlider::pointer_motion(int, int y)
54 set_value(drag_start_value+(y-drag_start_y)*(max-min)/(geom.h-get_slider_height()));
58 void VSlider::render_special(const Part &part) const
60 if(part.get_name()=="slider")
62 Alignment align=part.get_alignment();
63 align.y=(value-min)/(max-min);
65 Geometry pgeom=part.get_geometry();
66 align.apply(pgeom, geom, part.get_margin());
69 GL::translate(pgeom.x, pgeom.y, 0);
70 part.get_graphic(state)->render(pgeom.w, pgeom.h);
75 unsigned VSlider::get_slider_height() const
77 for(PartSeq::const_iterator i=style->get_parts().begin(); i!=style->get_parts().end(); ++i)
78 if(i->get_name()=="slider")
79 return i->get_geometry().h;