]> git.tdb.fi Git - libs/gltk.git/blob - source/button.h
Improve widget part caching
[libs/gltk.git] / source / button.h
1 #ifndef MSP_GLTK_BUTTON_H_
2 #define MSP_GLTK_BUTTON_H_
3
4 #include <sigc++/sigc++.h>
5 #include <msp/gl/texture2d.h>
6 #include "text.h"
7 #include "widget.h"
8
9 namespace Msp {
10 namespace GLtk {
11
12 /**
13 A clickable button widget.  Buttons can have a text label, which is displayed
14 in a spacial part "text".
15 */
16 class Button: public Widget
17 {
18 public:
19         class Loader: public DataFile::DerivedObjectLoader<Button, Widget::Loader>
20         {
21         public:
22                 Loader(Button &);
23         private:
24                 void text(const std::string &);
25         };
26
27         sigc::signal<void> signal_clicked;
28
29 private:
30         Text text;
31         const GL::Texture2D *icon;
32         bool pressed;
33
34 public:
35         Button(const std::string & = std::string());
36
37         virtual const char *get_class() const { return "button"; }
38
39         virtual void autosize();
40
41         void set_text(const std::string &);
42         void set_icon(const GL::Texture2D *);
43
44 private:
45         virtual void rebuild_special(const Part &);
46
47 public:
48         virtual void button_press(int, int, unsigned);
49         virtual void button_release(int, int, unsigned);
50         virtual void pointer_motion(int, int);
51 private:
52         virtual void on_style_change();
53 };
54
55 } // namespace GLtk
56 } // namespace Msp
57
58 #endif