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 HSlider::HSlider(const Resources &r):
25 void HSlider::button_press(int x, int y, unsigned btn)
27 if(geom.is_inside(x, y))
29 int sw=get_slider_width();
30 int sx=geom.x+static_cast<int>((geom.w-sw)*(value-min)/(max-min));
31 if(btn==1 && x>=sx && x<sx+sw)
36 drag_start_value=value;
41 void HSlider::button_release(int, int, unsigned btn)
50 void HSlider::pointer_motion(int x, int)
54 set_value(drag_start_value+(x-drag_start_x)*(max-min)/(geom.w-get_slider_width()));
58 void HSlider::render_special(const Part &part) const
60 if(part.get_name()=="slider")
62 const Geometry &pgeom=part.get_geometry();
64 unsigned gh=(part.get_fill_y() ? geom.h : pgeom.h);
66 GL::translate((geom.w-gw)*(value-min)/(max-min), (geom.h-gh)*(part.get_alignment().y+1)/2, 0);
67 const Graphic *graphic=part.get_graphic(state);
68 graphic->render(gw, gh);
73 unsigned HSlider::get_slider_width() const
75 for(PartSeq::const_iterator i=style->get_parts().begin(); i!=style->get_parts().end(); ++i)
76 if(i->get_name()=="slider")
77 return i->get_geometry().w;