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