]> git.tdb.fi Git - libs/gltk.git/blob - source/button.cpp
f6cf56c1f07ecbd8b0fa41a7b49e13d269b50156
[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         pressed(false)
17 {
18         set_text(t);
19         update_style();
20 }
21
22 void Button::set_text(const std::string &t)
23 {
24         text=t;
25 }
26
27 void Button::button_press(int, int, unsigned btn)
28 {
29         if(btn==1)
30         {
31                 pressed=true;
32                 state|=ACTIVE;
33         }
34 }
35
36 void Button::button_release(int x, int y, unsigned btn)
37 {
38         if(pressed && btn==1)
39         {
40                 if(geom.is_inside_relative(x, y))
41                         signal_clicked.emit();
42                 
43                 state&=~ACTIVE;
44                 pressed=false;
45         }
46 }
47
48 void Button::pointer_motion(int x, int y)
49 {
50         if(pressed)
51         {
52                 if(!geom.is_inside_relative(x, y))
53                         state&=~ACTIVE;
54                 else
55                         state|=ACTIVE;
56         }
57 }
58
59 void Button::render_special(const Part &part) const
60 {
61         if(part.get_name()=="text")
62                 render_text(part, text);
63 }
64
65
66 Button::Loader::Loader(Button &btn):
67         Widget::Loader(btn)
68 {
69         add("text", &Button::text);
70 }
71
72 Button &Button::Loader::get_object() const
73 {
74         return static_cast<Button &>(wdg);
75 }
76
77 } // namespace GLtk
78 } // namespace Msp