1 #include <msp/gl/meshbuilder.h>
11 Button::Button(const std::string &t):
19 void Button::autosize()
26 if(const Part *text_part = style->get_part("text"))
28 const Sides &margin = text_part->get_margin();
29 geom.w = max(geom.w, text.get_width()+margin.left+margin.right);
30 geom.h = max(geom.h, text.get_height()+margin.top+margin.bottom);
35 if(const Part *icon_part = style->get_part("icon"))
37 const Sides &margin = icon_part->get_margin();
38 geom.w = max(geom.w, icon->get_width()+margin.left+margin.right);
39 geom.h = max(geom.h, icon->get_height()+margin.top+margin.bottom);
46 void Button::set_text(const std::string &t)
49 signal_autosize_changed.emit();
53 void Button::set_icon(const GL::Texture2D *i)
59 void Button::rebuild_special(const Part &part, CachedPart &cache)
61 if(part.get_name()=="text")
62 text.build(part, geom, cache);
63 if(part.get_name()=="icon")
69 rgeom.w = icon->get_width();
70 rgeom.h = icon->get_height();
71 part.get_alignment().apply(rgeom, geom, part.get_margin());
75 GL::MeshBuilder bld(*cache.mesh);
76 bld.color(1.0f, 1.0f, 1.0f);
79 bld.vertex(rgeom.x, rgeom.y);
81 bld.vertex(rgeom.x+rgeom.w, rgeom.y);
83 bld.vertex(rgeom.x+rgeom.w, rgeom.y+rgeom.h);
85 bld.vertex(rgeom.x, rgeom.y+rgeom.h);
91 void Button::button_press(int, int, unsigned btn)
100 void Button::button_release(int x, int y, unsigned btn)
102 if(pressed && btn==1)
107 if(geom.is_inside_relative(x, y))
108 signal_clicked.emit();
112 void Button::pointer_motion(int x, int y)
116 if(!geom.is_inside_relative(x, y))
123 void Button::on_style_change()
125 text.set_style(style);
129 Button::Loader::Loader(Button &btn):
132 add("text", &Loader::text);
135 void Button::Loader::text(const std::string &t)
137 static_cast<Button &>(obj).text = t;