1 #include <msp/gl/meshbuilder.h>
11 Button::Button(const std::string &t):
19 void Button::autosize_special(const Part &part, Geometry &ageom) const
21 if(part.get_name()=="text")
22 text.autosize(part, ageom);
23 else if(part.get_name()=="icon" && icon)
25 const Sides &margin = part.get_margin();
26 ageom.w = max(ageom.w, icon->get_width()+margin.left+margin.right);
27 ageom.h = max(ageom.h, icon->get_height()+margin.top+margin.bottom);
31 void Button::set_text(const std::string &t)
34 signal_autosize_changed.emit();
38 void Button::set_icon(const GL::Texture2D *i)
44 void Button::rebuild_special(const Part &part)
46 if(part.get_name()=="text")
47 text.build(part, state, geom, part_cache);
48 if(part.get_name()=="icon")
53 rgeom.w = icon->get_width();
54 rgeom.h = icon->get_height();
55 part.get_alignment().apply(rgeom, geom, part.get_margin());
57 GL::MeshBuilder bld(part_cache.create_mesh(part, *icon));
58 bld.color(1.0f, 1.0f, 1.0f);
59 bld.begin(GL::TRIANGLE_STRIP);
61 bld.vertex(rgeom.x, rgeom.y+rgeom.h);
63 bld.vertex(rgeom.x, rgeom.y);
65 bld.vertex(rgeom.x+rgeom.w, rgeom.y+rgeom.h);
67 bld.vertex(rgeom.x+rgeom.w, rgeom.y);
73 void Button::button_press(int, int, unsigned btn)
82 void Button::button_release(int x, int y, unsigned btn)
89 if(geom.is_inside_relative(x, y))
90 signal_clicked.emit();
94 void Button::pointer_motion(int x, int y)
98 if(!geom.is_inside_relative(x, y))
105 void Button::on_style_change()
107 text.set_style(style);
111 Button::Loader::Loader(Button &btn):
112 DataFile::DerivedObjectLoader<Button, Widget::Loader>(btn)
114 add("text", &Loader::text);
117 void Button::Loader::text(const std::string &t)