1 #include <msp/gl/meshbuilder.h>
11 Button::Button(const std::string &t)
13 input_type = INPUT_NAVIGATION;
17 void Button::autosize_special(const Part &part, Geometry &ageom) const
19 if(part.get_name()=="text")
20 text.autosize(part, ageom);
21 else if(part.get_name()=="icon" && icon)
23 const Sides &margin = part.get_margin();
24 ageom.w = max(ageom.w, icon->get_width()+margin.left+margin.right);
25 ageom.h = max(ageom.h, icon->get_height()+margin.top+margin.bottom);
29 void Button::set_text(const std::string &t)
32 signal_autosize_changed.emit();
36 void Button::set_icon(const GL::Texture2D *i)
42 void Button::rebuild_special(const Part &part)
44 if(part.get_name()=="text")
45 text.build(part, state, geom, part_cache);
46 if(part.get_name()=="icon")
51 rgeom.w = icon->get_width();
52 rgeom.h = icon->get_height();
53 part.get_alignment().apply(rgeom, geom, part.get_margin());
55 GL::MeshBuilder bld(part_cache.create_mesh(part, *icon));
56 bld.color(1.0f, 1.0f, 1.0f);
57 bld.begin(GL::TRIANGLE_STRIP);
59 bld.vertex(rgeom.x, rgeom.y+rgeom.h);
61 bld.vertex(rgeom.x, rgeom.y);
63 bld.vertex(rgeom.x+rgeom.w, rgeom.y+rgeom.h);
65 bld.vertex(rgeom.x+rgeom.w, rgeom.y);
71 void Button::button_press(int, int, unsigned btn)
80 void Button::button_release(int x, int y, unsigned btn)
87 if(geom.is_inside_relative(x, y))
88 signal_clicked.emit();
92 void Button::pointer_motion(int x, int y)
96 if(!geom.is_inside_relative(x, y))
103 bool Button::navigate(Navigation nav)
105 if(nav==NAV_ACTIVATE)
106 signal_clicked.emit();
113 void Button::on_style_change()
115 text.set_style(style);
119 Button::Loader::Loader(Button &btn):
120 DataFile::DerivedObjectLoader<Button, Widget::Loader>(btn)
122 add("text", &Loader::text);
125 void Button::Loader::text(const std::string &t)