3 This file is part of libmspgltk
4 Copyright © 2007, 2009 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
8 #include <msp/gl/immediate.h>
15 Button::Button(const std::string &t):
23 void Button::set_text(const std::string &t)
28 void Button::set_icon(const GL::Texture2D *i)
33 void Button::button_press(int, int, unsigned btn)
42 void Button::button_release(int x, int y, unsigned btn)
49 if(geom.is_inside_relative(x, y))
50 signal_clicked.emit();
54 void Button::pointer_motion(int x, int y)
58 if(!geom.is_inside_relative(x, y))
65 void Button::render_special(const Part &part) const
67 if(part.get_name()=="text")
68 text.render(part, geom);
69 if(part.get_name()=="icon" && icon)
72 rgeom.w = icon->get_width();
73 rgeom.h = icon->get_height();
74 part.get_alignment().apply(rgeom, geom, part.get_margin());
77 GL::Immediate imm((GL::COLOR4_UBYTE, GL::TEXCOORD2, GL::VERTEX2));
78 imm.color(1.0f, 1.0f, 1.0f);
81 imm.vertex(rgeom.x, rgeom.y);
83 imm.vertex(rgeom.x+rgeom.w, rgeom.y);
85 imm.vertex(rgeom.x+rgeom.w, rgeom.y+rgeom.h);
87 imm.vertex(rgeom.x, rgeom.y+rgeom.h);
89 GL::Texture::unbind();
93 void Button::on_style_change()
95 text.set_style(style);
99 Button::Loader::Loader(Button &btn):
102 add("text", &Loader::text);
105 void Button::Loader::text(const std::string &t)
107 static_cast<Button &>(wdg).text = t;