X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fhslider.cpp;h=2af6f5a4a71a621574e253c37ee802d3010979c2;hb=a380303d852a3ad3f9b73ccbfbec4cf7f118123e;hp=a4378f0c9e62fbf491b6b73c2759ca97e11baf7c;hpb=91997dd3189b93a67179822ec2fed5f2a7bddb74;p=libs%2Fgltk.git diff --git a/source/hslider.cpp b/source/hslider.cpp index a4378f0..2af6f5a 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" @@ -16,39 +9,28 @@ namespace Msp { namespace GLtk { HSlider::HSlider(): - slider_size(1) + total_margin(0) { } -void HSlider::button_press(int x, int y, unsigned btn) +void HSlider::autosize_special(const Part &part, Geometry &ageom) const { - if(btn==1 && geom.is_inside_relative(x, y) && max>min) + if(part.get_name()=="slider") { - int sx = static_cast((geom.w-slider_size)*(value-min)/(max-min)); - if(x=static_cast(sx+slider_size)) - set_value(value+step*10); - else - start_drag(x); + 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::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_special(const Part &part) const +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); @@ -56,16 +38,33 @@ 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, unsigned btn) +{ + if(btn==1 && max>min) + click(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::on_geometry_change() { - drag_area_size = geom.w-slider_size; + drag_area_size = geom.w-total_margin; } void HSlider::on_style_change() @@ -74,7 +73,12 @@ void HSlider::on_style_change() return; if(const Part *slider_part = style->get_part("slider")) + { slider_size = slider_part->get_geometry().w; + const Sides &margin = slider_part->get_margin(); + drag_area_offset = margin.left; + total_margin = margin.left+margin.right; + } on_geometry_change(); }