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