]> git.tdb.fi Git - libs/gltk.git/blob - source/button.cpp
Reorder class members
[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 x, int y, unsigned btn)
27 {
28         if(geom.is_inside(x, y) && 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(x, y))
37                 {
38                         signal_clicked.emit();
39                         state=HOVER;
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_part(const Part &part) const
57 {
58         if(part.get_name()=="text")
59                 render_text(part, text);
60         else
61                 Widget::render_part(part);
62 }
63
64
65 Button::Loader::Loader(Button &btn):
66         Widget::Loader(btn)
67 {
68         add("text", &Button::text);
69 }
70
71 Button &Button::Loader::get_object() const
72 {
73         return static_cast<Button &>(wdg);
74 }
75
76 } // namespace GLtk
77 } // namespace Msp