]> git.tdb.fi Git - libs/gltk.git/blob - source/button.cpp
Add Dropdown widget
[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                 {
42                         state=HOVER;
43                         signal_clicked.emit();
44                 }
45                 else
46                         state=NORMAL;
47                 
48                 pressed=false;
49         }
50 }
51
52 void Button::pointer_enter()
53 {
54         state=HOVER;
55 }
56
57 void Button::pointer_leave()
58 {
59         state=NORMAL;
60 }
61
62 void Button::render_special(const Part &part) const
63 {
64         if(part.get_name()=="text")
65                 render_text(part, text);
66 }
67
68
69 Button::Loader::Loader(Button &btn):
70         Widget::Loader(btn)
71 {
72         add("text", &Button::text);
73 }
74
75 Button &Button::Loader::get_object() const
76 {
77         return static_cast<Button &>(wdg);
78 }
79
80 } // namespace GLtk
81 } // namespace Msp