]> git.tdb.fi Git - libs/gltk.git/blob - source/button.cpp
Initial revision
[libs/gltk.git] / source / button.cpp
1 #include "button.h"
2 #include "part.h"
3
4 namespace Msp {
5 namespace GLtk {
6
7 Button::Button(const Resources &r, const std::string &t):
8         Widget(r)
9 {
10         set_text(t);
11         update_style();
12 }
13
14 void Button::set_text(const std::string &t)
15 {
16         text=t;
17 }
18
19 void Button::render_part(const Part &part) const
20 {
21         if(part.get_name()=="text")
22         {
23                 render_text(part, text);
24                 /*const GL::Font *const font=style->get_font();
25
26                 const float font_size=font->get_default_size();
27                 unsigned text_w=static_cast<unsigned>(font->get_string_width(text)*font_size);
28
29                 part.get_alignment().apply(geom, text_w, static_cast<unsigned>(font_size));
30
31                 GL::push_matrix();
32                 GL::scale_uniform(font_size);
33
34                 const Color &color=style->get_font_color();
35                 glColor3f(color.r, color.g, color.b);
36                 font->draw_string(text);
37                 glColor3f(1, 1, 1);
38
39                 GL::pop_matrix();*/
40         }
41         else
42                 Widget::render_part(part);
43 }
44
45 void Button::on_button_press(int, int, unsigned btn)
46 {
47         if(btn==1)
48                 state=ACTIVE;
49 }
50
51 void Button::on_button_release(int, int, unsigned btn)
52 {
53         if(btn==1/* && x>=0 && y>=0 && x<static_cast<int>(geom.w) && y<static_cast<int>(geom.h)*/)
54         {
55                 state=NORMAL;
56                 signal_clicked.emit();
57         }
58 }
59
60 } // namespace GLtk
61 } // namespace Msp