1 #include <msp/gl/meshbuilder.h>
11 Button::Button(const std::string &t):
16 input_type = INPUT_NAVIGATION;
20 void Button::autosize_special(const Part &part, Geometry &ageom) const
22 if(part.get_name()=="text")
23 text.autosize(part, ageom);
24 else if(part.get_name()=="icon" && icon)
26 const Sides &margin = part.get_margin();
27 ageom.w = max(ageom.w, icon->get_width()+margin.left+margin.right);
28 ageom.h = max(ageom.h, icon->get_height()+margin.top+margin.bottom);
32 void Button::set_text(const std::string &t)
35 signal_autosize_changed.emit();
39 void Button::set_icon(const GL::Texture2D *i)
45 void Button::rebuild_special(const Part &part)
47 if(part.get_name()=="text")
48 text.build(part, state, geom, part_cache);
49 if(part.get_name()=="icon")
54 rgeom.w = icon->get_width();
55 rgeom.h = icon->get_height();
56 part.get_alignment().apply(rgeom, geom, part.get_margin());
58 GL::MeshBuilder bld(part_cache.create_mesh(part, *icon));
59 bld.color(1.0f, 1.0f, 1.0f);
60 bld.begin(GL::TRIANGLE_STRIP);
62 bld.vertex(rgeom.x, rgeom.y+rgeom.h);
64 bld.vertex(rgeom.x, rgeom.y);
66 bld.vertex(rgeom.x+rgeom.w, rgeom.y+rgeom.h);
68 bld.vertex(rgeom.x+rgeom.w, rgeom.y);
74 void Button::button_press(int, int, unsigned btn)
83 void Button::button_release(int x, int y, unsigned btn)
90 if(geom.is_inside_relative(x, y))
91 signal_clicked.emit();
95 void Button::pointer_motion(int x, int y)
99 if(!geom.is_inside_relative(x, y))
106 bool Button::navigate(Navigation nav)
108 if(nav==NAV_ACTIVATE)
109 signal_clicked.emit();
116 void Button::on_style_change()
118 text.set_style(style);
122 Button::Loader::Loader(Button &btn):
123 DataFile::DerivedObjectLoader<Button, Widget::Loader>(btn)
125 add("text", &Loader::text);
128 void Button::Loader::text(const std::string &t)