1 #include <msp/gl/immediate.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);
44 void Button::set_text(const std::string &t)
47 signal_autosize_changed.emit();
50 void Button::set_icon(const GL::Texture2D *i)
55 void Button::render_special(const Part &part) const
57 if(part.get_name()=="text")
58 text.render(part, geom);
59 if(part.get_name()=="icon" && icon)
62 rgeom.w = icon->get_width();
63 rgeom.h = icon->get_height();
64 part.get_alignment().apply(rgeom, geom, part.get_margin());
67 GL::Immediate imm((GL::COLOR4_UBYTE, GL::TEXCOORD2, GL::VERTEX2));
68 imm.color(1.0f, 1.0f, 1.0f);
71 imm.vertex(rgeom.x, rgeom.y);
73 imm.vertex(rgeom.x+rgeom.w, rgeom.y);
75 imm.vertex(rgeom.x+rgeom.w, rgeom.y+rgeom.h);
77 imm.vertex(rgeom.x, rgeom.y+rgeom.h);
79 GL::Texture::unbind();
83 void Button::button_press(int, int, unsigned btn)
92 void Button::button_release(int x, int y, unsigned btn)
99 if(geom.is_inside_relative(x, y))
100 signal_clicked.emit();
104 void Button::pointer_motion(int x, int y)
108 if(!geom.is_inside_relative(x, y))
115 void Button::on_style_change()
117 text.set_style(style);
121 Button::Loader::Loader(Button &btn):
124 add("text", &Loader::text);
127 void Button::Loader::text(const std::string &t)
129 static_cast<Button &>(obj).text = t;