]> git.tdb.fi Git - libs/gltk.git/blob - source/vslider.cpp
Fix list positioning logic in Dropdown
[libs/gltk.git] / source / vslider.cpp
1 #include <msp/gl/matrix.h>
2 #include <msp/gl/meshbuilder.h>
3 #include "graphic.h"
4 #include "part.h"
5 #include "style.h"
6 #include "vslider.h"
7
8 namespace Msp {
9 namespace GLtk {
10
11 VSlider::VSlider():
12         total_margin(0)
13 { }
14
15 void VSlider::autosize_special(const Part &part, Geometry &ageom) const
16 {
17         if(part.get_name()=="slider")
18         {
19                 const Sides &margin = part.get_margin();
20                 const Geometry &pgeom = part.get_geometry();
21                 ageom.w = std::max(ageom.w, pgeom.w+margin.left+margin.right);
22                 ageom.h = std::max(ageom.h, pgeom.h*3/2+margin.top+margin.bottom);
23         }
24 }
25
26 void VSlider::rebuild_special(const Part &part)
27 {
28         if(part.get_name()=="slider")
29         {
30                 const Graphic *graphic = part.get_graphic(state);
31                 if(!graphic || !graphic->get_texture())
32                         return;
33
34                 Alignment align = part.get_alignment();
35                 if(max>min)
36                         align.y = (value-min)/(max-min);
37
38                 Geometry pgeom = part.get_geometry();
39                 align.apply(pgeom, geom, part.get_margin());
40
41                 GL::MeshBuilder bld(part_cache.create_mesh(part, *graphic->get_texture()));
42                 bld.matrix() *= GL::Matrix::translation(pgeom.x, pgeom.y, 0);
43                 graphic->build(pgeom.w, pgeom.h, bld);
44         }
45 }
46
47 void VSlider::button_press(int, int y, unsigned btn)
48 {
49         if(btn==1 && max>min)
50                 click(y);
51 }
52
53 void VSlider::button_release(int, int, unsigned btn)
54 {
55         if(btn==1 && dragging)
56                 end_drag();
57 }
58
59 void VSlider::pointer_motion(int, int y)
60 {
61         if(dragging)
62                 drag(y);
63 }
64
65 void VSlider::on_geometry_change()
66 {
67         drag_area_size = geom.h-total_margin;
68 }
69
70 void VSlider::on_style_change()
71 {
72         if(!style)
73                 return;
74
75         if(const Part *slider_part = style->get_part("slider"))
76         {
77                 slider_size = slider_part->get_geometry().h;
78                 const Sides &margin = slider_part->get_margin();
79                 drag_area_offset = margin.bottom;
80                 total_margin = margin.bottom+margin.top;
81         }
82
83         on_geometry_change();
84 }
85
86 } // namespace GLtk
87 } // namespace Msp
88