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>
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::render_special(const Part &part) const
35 if(part.get_name()=="text")
36 text.render(part, geom);
37 if(part.get_name()=="icon" && icon)
40 rgeom.w = icon->get_width();
41 rgeom.h = icon->get_height();
42 part.get_alignment().apply(rgeom, geom, part.get_margin());
45 GL::Immediate imm((GL::COLOR4_UBYTE, GL::TEXCOORD2, GL::VERTEX2));
46 imm.color(1.0f, 1.0f, 1.0f);
49 imm.vertex(rgeom.x, rgeom.y);
51 imm.vertex(rgeom.x+rgeom.w, rgeom.y);
53 imm.vertex(rgeom.x+rgeom.w, rgeom.y+rgeom.h);
55 imm.vertex(rgeom.x, rgeom.y+rgeom.h);
57 GL::Texture::unbind();
61 void Button::button_press(int, int, unsigned btn)
70 void Button::button_release(int x, int y, unsigned btn)
77 if(geom.is_inside_relative(x, y))
78 signal_clicked.emit();
82 void Button::pointer_motion(int x, int y)
86 if(!geom.is_inside_relative(x, y))
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;