X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fvslider.cpp;h=e4c40d8123385ed283c1a1089a1c1346c627d946;hb=7f5b8877ae1a73d3b664d7ee6f0041b602bdd049;hp=cdd2675952a1bf3ddf2737a08bfc414be01e4d5c;hpb=91997dd3189b93a67179822ec2fed5f2a7bddb74;p=libs%2Fgltk.git diff --git a/source/vslider.cpp b/source/vslider.cpp index cdd2675..e4c40d8 100644 --- a/source/vslider.cpp +++ b/source/vslider.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 "part.h" #include "style.h" @@ -17,12 +10,43 @@ namespace GLtk { VSlider::VSlider(): slider_size(1) +{ } + +void VSlider::autosize_special(const Part &part, Geometry &ageom) { + 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+margin.left+margin.right); + ageom.h = std::max(ageom.h, pgeom.h*3/2+margin.top+margin.bottom); + } } -void VSlider::button_press(int x, int y, unsigned btn) +void VSlider::rebuild_special(const Part &part) { - if(btn==1 && geom.is_inside_relative(x, y) && max>min) + 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.y = (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 VSlider::button_press(int, int y, unsigned btn) +{ + if(btn==1 && max>min) { int sy = static_cast((geom.h-slider_size)*(value-min)/(max-min)); if(ymin) - align.y = (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 VSlider::on_geometry_change() { drag_area_size = geom.h-slider_size;