]> git.tdb.fi Git - libs/gltk.git/blob - source/button.cpp
2c8bedb17c17a34e45be58003caac18067e2d843
[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::button_press(int x, int y, unsigned btn)
20 {
21         if(geom.is_inside(x, y) && btn==1)
22                 state=ACTIVE;
23 }
24
25 void Button::button_release(int x, int y, unsigned btn)
26 {
27         if(btn==1)
28         {
29                 state=NORMAL;
30                 if(geom.is_inside(x, y))
31                         signal_clicked.emit();
32         }
33 }
34
35 void Button::render_part(const Part &part) const
36 {
37         if(part.get_name()=="text")
38                 render_text(part, text);
39         else
40                 Widget::render_part(part);
41 }
42
43 } // namespace GLtk
44 } // namespace Msp