X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fhslider.cpp;h=e9db05f16cf950860cccd69002e82356c79c71dd;hb=14843a7e876b02d1ade422c929a066a7bab16f3b;hp=c1d334d3d3cbff366b37b59bae72ee63fbf7e40c;hpb=c1f038acb91eb3bfaa34dfd4729d19ed3f871a42;p=libs%2Fgltk.git diff --git a/source/hslider.cpp b/source/hslider.cpp index c1d334d..e9db05f 100644 --- a/source/hslider.cpp +++ b/source/hslider.cpp @@ -1,4 +1,16 @@ +/* $Id$ + +This file is part of libmspgltk +Copyright © 2007 Mikko Rasa, Mikkosoft Productions +Distributed under the LGPL +*/ + +#include +#include +#include "graphic.h" #include "hslider.h" +#include "part.h" +#include "style.h" namespace Msp { namespace GLtk { @@ -6,19 +18,62 @@ namespace GLtk { HSlider::HSlider(const Resources &r): Slider(r) { + update_style(); +} + +void HSlider::button_press(int x, int y, unsigned btn) +{ + if(geom.is_inside_relative(x, y) && max>min) + { + int sx=static_cast((geom.w-slider_size)*(value-min)/(max-min)); + if(btn==1 && x>=sx && x(sx+slider_size)) + start_drag(x); + } +} + +void HSlider::button_release(int, int, unsigned btn) +{ + if(btn==1 && dragging) + end_drag(); +} + +void HSlider::pointer_motion(int x, int) +{ + if(dragging) + drag(x); } -void HSlider::render_part(const Part &part) +void HSlider::render_special(const Part &part) const { if(part.get_name()=="slider") { - const Graphic *graphic=part.get_graphic(state); - const Graphic::Sides &shadow=graphic->get_shadow(); - unsigned gw=graphic->get_slice().w-shadow.left-shadow.right; - unsigned gh=(part.get_fill_x() ? geom.h, graphic->get_slice().h)-shadow.bottom-shadow.top; - GL::translate((geom.w-gw)*(value-min)/(max-min), part.get_alignment().y + Alignment align=part.get_alignment(); + if(max>min) + align.x=(value-min)/(max-min); + + Geometry pgeom=part.get_geometry(); + align.apply(pgeom, geom, part.get_margin()); + + GL::push_matrix(); + GL::translate(pgeom.x, pgeom.y, 0); + part.get_graphic(state)->render(pgeom.w, pgeom.h); + GL::pop_matrix(); } } +void HSlider::on_geometry_change() +{ + drag_area_size=geom.w-slider_size; +} + +void HSlider::on_style_change() +{ + for(PartSeq::const_iterator i=style->get_parts().begin(); i!=style->get_parts().end(); ++i) + if(i->get_name()=="slider") + slider_size=i->get_geometry().w; + + on_geometry_change(); +} + } // namespace GLtk } // namespace Msp