X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fhslider.cpp;h=dcb7634da9e633b751df9315f36bc5c5088d7e1d;hb=707b59d45ae50b69c94918f8f74313283b304597;hp=ad447c7b017e627964b3f82e384f90442e16bbe0;hpb=0af3c2393bd00f39db3bfaf5b78a7a44f0fd5ff1;p=libs%2Fgltk.git diff --git a/source/hslider.cpp b/source/hslider.cpp index ad447c7..dcb7634 100644 --- a/source/hslider.cpp +++ b/source/hslider.cpp @@ -1,12 +1,5 @@ -/* $Id$ - -This file is part of libmspgltk -Copyright © 2007 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - #include -#include +#include #include "graphic.h" #include "hslider.h" #include "part.h" @@ -15,15 +8,45 @@ Distributed under the LGPL namespace Msp { namespace GLtk { -HSlider::HSlider(const Resources &r): - Slider(r) +HSlider::HSlider(): + slider_size(1) +{ } + +void HSlider::autosize_special(const Part &part, Geometry &ageom) const +{ + if(part.get_name()=="slider") + { + const Sides &margin = part.get_margin(); + const Geometry &pgeom = part.get_geometry(); + ageom.w = std::max(ageom.w, pgeom.w*3/2+margin.left+margin.right); + ageom.h = std::max(ageom.h, pgeom.h+margin.top+margin.bottom); + } +} + +void HSlider::rebuild_special(const Part &part) { - update_style(); + if(part.get_name()=="slider") + { + const Graphic *graphic = part.get_graphic(state); + if(!graphic || !graphic->get_texture()) + return; + + 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::MeshBuilder bld(part_cache.create_mesh(part, *graphic->get_texture())); + bld.matrix() *= GL::Matrix::translation(pgeom.x, pgeom.y, 0); + graphic->build(pgeom.w, pgeom.h, bld); + } } -void HSlider::button_press(int x, int y, unsigned btn) +void HSlider::button_press(int x, int, unsigned btn) { - if(btn==1 && geom.is_inside_relative(x, y) && max>min) + if(btn==1 && max>min) { int sx = static_cast((geom.w-slider_size)*(value-min)/(max-min)); if(xmin) - 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; @@ -72,9 +77,11 @@ void HSlider::on_geometry_change() 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; + if(!style) + return; + + if(const Part *slider_part = style->get_part("slider")) + slider_size = slider_part->get_geometry().w; on_geometry_change(); }