X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fhslider.cpp;h=2c6e968695439603031234b045dfb3ded26fc458;hb=7f5b8877ae1a73d3b664d7ee6f0041b602bdd049;hp=e86cc4b17da02f56f8d26906eb2382ab59af0761;hpb=2bdaf4955fdb94e73704adcdcf0adc2b353f0ff0;p=libs%2Fgltk.git diff --git a/source/hslider.cpp b/source/hslider.cpp index e86cc4b..2c6e968 100644 --- a/source/hslider.cpp +++ b/source/hslider.cpp @@ -1,12 +1,5 @@ -/* $Id$ - -This file is part of libmspgltk -Copyright © 2007-2008, 2010-2011 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - #include -#include +#include #include "graphic.h" #include "hslider.h" #include "part.h" @@ -19,10 +12,25 @@ HSlider::HSlider(): slider_size(1) { } -void HSlider::render_special(const Part &part) const +void HSlider::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*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) +{ + 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); @@ -30,16 +38,15 @@ void HSlider::render_special(const Part &part) const 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(); + 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(x