3 This file is part of libmspgltk
4 Copyright © 2007-2011 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
8 #include <msp/gl/immediate.h>
18 Button::Button(const std::string &t):
26 void Button::autosize()
33 if(const Part *text_part = style->get_part("text"))
35 const Sides &margin = text_part->get_margin();
36 geom.w = max(geom.w, text.get_width()+margin.left+margin.right);
37 geom.h = max(geom.h, text.get_height()+margin.top+margin.bottom);
42 if(const Part *icon_part = style->get_part("icon"))
44 const Sides &margin = icon_part->get_margin();
45 geom.w = max(geom.w, icon->get_width()+margin.left+margin.right);
46 geom.h = max(geom.h, icon->get_height()+margin.top+margin.bottom);
51 void Button::set_text(const std::string &t)
54 signal_autosize_changed.emit();
57 void Button::set_icon(const GL::Texture2D *i)
62 void Button::render_special(const Part &part) const
64 if(part.get_name()=="text")
65 text.render(part, geom);
66 if(part.get_name()=="icon" && icon)
69 rgeom.w = icon->get_width();
70 rgeom.h = icon->get_height();
71 part.get_alignment().apply(rgeom, geom, part.get_margin());
74 GL::Immediate imm((GL::COLOR4_UBYTE, GL::TEXCOORD2, GL::VERTEX2));
75 imm.color(1.0f, 1.0f, 1.0f);
78 imm.vertex(rgeom.x, rgeom.y);
80 imm.vertex(rgeom.x+rgeom.w, rgeom.y);
82 imm.vertex(rgeom.x+rgeom.w, rgeom.y+rgeom.h);
84 imm.vertex(rgeom.x, rgeom.y+rgeom.h);
86 GL::Texture::unbind();
90 void Button::button_press(int, int, unsigned btn)
99 void Button::button_release(int x, int y, unsigned btn)
101 if(pressed && btn==1)
106 if(geom.is_inside_relative(x, y))
107 signal_clicked.emit();
111 void Button::pointer_motion(int x, int y)
115 if(!geom.is_inside_relative(x, y))
122 void Button::on_style_change()
124 text.set_style(style);
128 Button::Loader::Loader(Button &btn):
131 add("text", &Loader::text);
134 void Button::Loader::text(const std::string &t)
136 static_cast<Button &>(obj).text = t;