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 //render_text(part, text);
71 text.render(part, geom);
72 if(part.get_name()=="icon" && icon)
75 rgeom.w=icon->get_width();
76 rgeom.h=icon->get_height();
77 part.get_alignment().apply(rgeom, geom, part.get_margin());
80 GL::Immediate imm((GL::COLOR4_UBYTE, GL::TEXCOORD2, GL::VERTEX2));
81 imm.color(1.0f, 1.0f, 1.0f);
84 imm.vertex(rgeom.x, rgeom.y);
86 imm.vertex(rgeom.x+rgeom.w, rgeom.y);
88 imm.vertex(rgeom.x+rgeom.w, rgeom.y+rgeom.h);
90 imm.vertex(rgeom.x, rgeom.y+rgeom.h);
92 GL::Texture::unbind();
97 Button::Loader::Loader(Button &btn):
100 add("text", &Loader::text);
103 void Button::Loader::text(const std::string &t)
105 static_cast<Button &>(wdg).text=t;