]> git.tdb.fi Git - libs/gltk.git/blobdiff - source/vslider.cpp
Remove obsolete inside checks
[libs/gltk.git] / source / vslider.cpp
index 397713b6c7c9bda5529fa93661205f85d402aee8..e4c40d8123385ed283c1a1089a1c1346c627d946 100644 (file)
@@ -1,12 +1,5 @@
-/* $Id$
-
-This file is part of libmspgltk
-Copyright © 2007  Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
-*/
-
 #include <msp/gl/matrix.h>
-#include <msp/gl/transform.h>
+#include <msp/gl/meshbuilder.h>
 #include "graphic.h"
 #include "part.h"
 #include "style.h"
@@ -15,70 +8,82 @@ Distributed under the LGPL
 namespace Msp {
 namespace GLtk {
 
-VSlider::VSlider(const Resources &r):
-       Slider(r),
-       dragging(false)
-{
-       update_style();
-}
+VSlider::VSlider():
+       slider_size(1)
+{ }
 
-void VSlider::button_press(int x, int y, unsigned btn)
+void VSlider::autosize_special(const Part &part, Geometry &ageom)
 {
-       if(geom.is_inside(x, y))
+       if(part.get_name()=="slider")
        {
-               int sh=get_slider_height();
-               int sy=geom.y+static_cast<int>((geom.h-sh)*(value-min)/(max-min));
-               if(btn==1 && y>=sy && y<sy+sh)
-               {
-                       dragging=true;
-                       state=ACTIVE;
-                       drag_start_y=y;
-                       drag_start_value=value;
-               }
+               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_release(int, int, unsigned btn)
+void VSlider::rebuild_special(const Part &part)
 {
-       if(btn==1)
+       if(part.get_name()=="slider")
        {
-               dragging=false;
-               state=NORMAL;
+               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::pointer_motion(int, int y)
+void VSlider::button_press(int, int y, unsigned btn)
 {
-       if(dragging)
+       if(btn==1 && max>min)
        {
-               set_value(drag_start_value+(y-drag_start_y)*(max-min)/(geom.h-get_slider_height()));
+               int sy = static_cast<int>((geom.h-slider_size)*(value-min)/(max-min));
+               if(y<sy)
+                       set_value(value-step*10);
+               else if(y>=static_cast<int>(sy+slider_size))
+                       set_value(value+step*10);
+               else
+                       start_drag(y);
        }
 }
 
-void VSlider::render_special(const Part &part) const
+void VSlider::button_release(int, int, unsigned btn)
 {
-       if(part.get_name()=="slider")
-       {
-               Alignment align=part.get_alignment();
-               align.y=(value-min)/(max-min);
+       if(btn==1 && dragging)
+               end_drag();
+}
 
-               Geometry pgeom=part.get_geometry();
-               align.apply(pgeom, geom, part.get_margin());
+void VSlider::pointer_motion(int, int y)
+{
+       if(dragging)
+               drag(y);
+}
 
-               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;
 }
 
-unsigned VSlider::get_slider_height() const
+void VSlider::on_style_change()
 {
-       for(PartSeq::const_iterator i=style->get_parts().begin(); i!=style->get_parts().end(); ++i)
-               if(i->get_name()=="slider")
-                       return i->get_geometry().h;
+       if(!style)
+               return;
+
+       if(const Part *slider_part = style->get_part("slider"))
+               slider_size = slider_part->get_geometry().h;
 
-       return 0;
+       on_geometry_change();
 }
 
 } // namespace GLtk