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 Resources &r, const std::string &t):
25 void Button::set_text(const std::string &t)
30 void Button::set_icon(const GL::Texture2D *i)
35 void Button::button_press(int, int, unsigned btn)
44 void Button::button_release(int x, int y, unsigned btn)
51 if(geom.is_inside_relative(x, y))
52 signal_clicked.emit();
56 void Button::pointer_motion(int x, int y)
60 if(!geom.is_inside_relative(x, y))
67 void Button::render_special(const Part &part) const
69 if(part.get_name()=="text")
70 text.render(part, geom);
71 if(part.get_name()=="icon" && icon)
74 rgeom.w=icon->get_width();
75 rgeom.h=icon->get_height();
76 part.get_alignment().apply(rgeom, geom, part.get_margin());
79 GL::Immediate imm((GL::COLOR4_UBYTE, GL::TEXCOORD2, GL::VERTEX2));
80 imm.color(1.0f, 1.0f, 1.0f);
83 imm.vertex(rgeom.x, rgeom.y);
85 imm.vertex(rgeom.x+rgeom.w, rgeom.y);
87 imm.vertex(rgeom.x+rgeom.w, rgeom.y+rgeom.h);
89 imm.vertex(rgeom.x, rgeom.y+rgeom.h);
91 GL::Texture::unbind();
96 Button::Loader::Loader(Button &btn):
99 add("text", &Loader::text);
102 void Button::Loader::text(const std::string &t)
104 static_cast<Button &>(wdg).text=t;