Tucano  0.1
A library for rapid prototyping with modern OpenGL and GLSL
button.hpp
Go to the documentation of this file.
1 
23 #ifndef __BUTTON__
24 #define __BUTTON__
25 
26 #include <tucano/shapes/quad.hpp>
27 #include <tucano/gui/element.hpp>
28 #include <Eigen/Dense>
29 
30 namespace Tucano
31 {
32 
33 namespace GUI
34 {
35 
40 class Button : public Element {
41 
42 protected:
43 
45  function< void() > click_callback;
46 
48  function< void() > hover_callback;
49 
50 public:
51 
55  Button (void)
56  {
57  Button(10, 10, 0, 0);
58  }
59 
67  Button (int w, int h, int x, int y)
68  {
69  dimensions << w, h;
70  position << x, y;
73  num_params = 0;
74  }
75 
84  Button (int w, int h, int x, int y, string texture)
85  {
86  Button (w, h, x, y);
87  setTexture (texture);
88  }
89 
90 
91  int getType (void)
92  {
93  return Tucano::GUI::BUTTON;
94  }
95 
100  void onClick (function<void()> f)
101  {
102  click_callback = f;
103  }
104 
108  void clicked (void)
109  {
110  click_callback();
111  }
112 
116  void onHover (function<void()> f)
117  {
118  hover_callback = f;
119  }
120 
124  void hovering (void)
125  {
126  hover_callback();
127  }
128 
133  void setColor (const Eigen::Vector4f& c)
134  {
135  color = c;
136  }
137 
138 };
139 }
140 }
141 #endif
Eigen::Vector2i dimensions
Dimensions in pixels.
Definition: element.hpp:66
Eigen::Vector2i position
Position of top-left corner in pixels.
Definition: element.hpp:69
void hovering(void)
Calls hovering callback.
Definition: button.hpp:124
Base class for all GUI elements (buttons, sliders ...)
Definition: element.hpp:52
Definition: element.hpp:39
virtual void setModelMatrix(void)
Sets the element model matrix.
Definition: element.hpp:195
Tucano::Texture texture
Element texture.
Definition: element.hpp:75
Button(int w, int h, int x, int y, string texture)
Overload constructor that receives dimensions and texture file.
Definition: button.hpp:84
Definition: bufferobject.hpp:34
int getType(void)
Returns the element type.
Definition: button.hpp:91
void onClick(function< void()> f)
Sets the button callback with no parameters.
Definition: button.hpp:100
void setColor(const Eigen::Vector4f &c)
Sets the button color.
Definition: button.hpp:133
Button(void)
Default constructor.
Definition: button.hpp:55
function< void() > hover_callback
Hovering callback without parameters.
Definition: button.hpp:48
The button class draws a clickable rectangle on the screen to be used as a callback interface...
Definition: button.hpp:40
void clicked(void)
Calls clicked callback.
Definition: button.hpp:108
int num_params
Number of parameters for the callback.
Definition: element.hpp:60
void onHover(function< void()> f)
Sets the button hover callback with no parameters.
Definition: button.hpp:116
Eigen::Vector4f color
Color.
Definition: element.hpp:90
virtual void setTexture(string file)
Loads the button texture file.
Definition: element.hpp:173
Button(int w, int h, int x, int y)
Overload Constructor.
Definition: button.hpp:67
int element_type
Type of element.
Definition: element.hpp:57
function< void() > click_callback
Clicked callback without parameters.
Definition: button.hpp:45