]> git.tdb.fi Git - libs/gltk.git/blob - source/button.cpp
bc6fd274d7362dae651c7d15f37eafdbb62f7be7
[libs/gltk.git] / source / button.cpp
1 /* $Id$
2
3 This file is part of libmspgltk
4 Copyright © 2007  Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #include "button.h"
9 #include "part.h"
10
11 namespace Msp {
12 namespace GLtk {
13
14 Button::Button(const Resources &r, const std::string &t):
15         Widget(r)
16 {
17         set_text(t);
18         update_style();
19 }
20
21 void Button::set_text(const std::string &t)
22 {
23         text=t;
24 }
25
26 void Button::button_press(int, int, unsigned btn)
27 {
28         if(btn==1)
29                 state=ACTIVE;
30 }
31
32 void Button::button_release(int x, int y, unsigned btn)
33 {
34         if(btn==1)
35         {
36                 if(geom.is_inside_relative(x, y))
37                 {
38                         state=HOVER;
39                         signal_clicked.emit();
40                 }
41                 else
42                         state=NORMAL;
43         }
44 }
45
46 void Button::pointer_enter()
47 {
48         state=HOVER;
49 }
50
51 void Button::pointer_leave()
52 {
53         state=NORMAL;
54 }
55
56 void Button::render_special(const Part &part) const
57 {
58         if(part.get_name()=="text")
59                 render_text(part, text);
60 }
61
62
63 Button::Loader::Loader(Button &btn):
64         Widget::Loader(btn)
65 {
66         add("text", &Button::text);
67 }
68
69 Button &Button::Loader::get_object() const
70 {
71         return static_cast<Button &>(wdg);
72 }
73
74 } // namespace GLtk
75 } // namespace Msp