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)
56 void Button::set_icon(const GL::Texture2D *i)
61 void Button::render_special(const Part &part) const
63 if(part.get_name()=="text")
64 text.render(part, geom);
65 if(part.get_name()=="icon" && icon)
68 rgeom.w = icon->get_width();
69 rgeom.h = icon->get_height();
70 part.get_alignment().apply(rgeom, geom, part.get_margin());
73 GL::Immediate imm((GL::COLOR4_UBYTE, GL::TEXCOORD2, GL::VERTEX2));
74 imm.color(1.0f, 1.0f, 1.0f);
77 imm.vertex(rgeom.x, rgeom.y);
79 imm.vertex(rgeom.x+rgeom.w, rgeom.y);
81 imm.vertex(rgeom.x+rgeom.w, rgeom.y+rgeom.h);
83 imm.vertex(rgeom.x, rgeom.y+rgeom.h);
85 GL::Texture::unbind();
89 void Button::button_press(int, int, unsigned btn)
98 void Button::button_release(int x, int y, unsigned btn)
100 if(pressed && btn==1)
105 if(geom.is_inside_relative(x, y))
106 signal_clicked.emit();
110 void Button::pointer_motion(int x, int y)
114 if(!geom.is_inside_relative(x, y))
121 void Button::on_style_change()
123 text.set_style(style);
127 Button::Loader::Loader(Button &btn):
130 add("text", &Loader::text);
133 void Button::Loader::text(const std::string &t)
135 static_cast<Button &>(obj).text = t;