]> git.tdb.fi Git - libs/gltk.git/blob - source/button.cpp
Change State into a bitmask to allow more fine-grained control of styles
[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_leave()
49 {
50         Widget::pointer_leave();
51         state&=~ACTIVE;
52 }
53
54 void Button::render_special(const Part &part) const
55 {
56         if(part.get_name()=="text")
57                 render_text(part, text);
58 }
59
60
61 Button::Loader::Loader(Button &btn):
62         Widget::Loader(btn)
63 {
64         add("text", &Button::text);
65 }
66
67 Button &Button::Loader::get_object() const
68 {
69         return static_cast<Button &>(wdg);
70 }
71
72 } // namespace GLtk
73 } // namespace Msp