X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fhslider.cpp;h=2a3644367ea52adb85beeb1f2f02abad007fc25c;hb=712f0cdee978088b29be3ef67310b26a048334ff;hp=a4378f0c9e62fbf491b6b73c2759ca97e11baf7c;hpb=91997dd3189b93a67179822ec2fed5f2a7bddb74;p=libs%2Fgltk.git diff --git a/source/hslider.cpp b/source/hslider.cpp index a4378f0..2a36443 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" @@ -19,6 +12,46 @@ HSlider::HSlider(): slider_size(1) { } +void HSlider::autosize() +{ + if(!style) + return; + + Widget::autosize(); + + if(const Part *slider_part = style->get_part("slider")) + { + const Sides &margin = slider_part->get_margin(); + const Geometry &pgeom = slider_part->get_geometry(); + geom.w = std::max(geom.w, pgeom.w*3/2+margin.left+margin.right); + geom.h = std::max(geom.h, pgeom.h+margin.top+margin.bottom); + } +} + +void HSlider::rebuild_special(const Part &part, CachedPart &cache) +{ + if(part.get_name()=="slider") + { + const Graphic *graphic = part.get_graphic(state); + if(!graphic) + 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()); + + cache.texture = part.get_graphic(state)->get_texture(); + cache.clear_mesh(); + + GL::MeshBuilder bld(*cache.mesh); + 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) { if(btn==1 && geom.is_inside_relative(x, y) && max>min) @@ -45,24 +78,6 @@ void HSlider::pointer_motion(int x, int) drag(x); } -void HSlider::render_special(const Part &part) const -{ - if(part.get_name()=="slider") - { - 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;