Tucano  0.1
A library for rapid prototyping with modern OpenGL and GLSL
selectgroup.hpp
Go to the documentation of this file.
1 
23 #ifndef __SELECTGROUP__
24 #define __SELECTGROUP__
25 
26 #include <tucano/gui/element.hpp>
27 #include <Eigen/Dense>
28 
29 namespace Tucano
30 {
31 
32 namespace GUI
33 {
34 
40 
41 protected:
42 
44  vector < Tucano::GUI::SelectButton* > buttons;
45 
47  int selected = -1;
48 
49  // position of bottom right corner
50  Eigen::Vector2i end_position;
51 
52 public:
53 
57  SelectGroup (void)
58  {
60  dimensions << 0, 0;
61  position << 0, 0;
62  end_position << 0, 0;
63  }
64 
69  void add (SelectButton *el)
70  {
71  buttons.push_back(el);
72 
73  // redimension select group to contain all buttons
74  if (el->position[0] < position[0] || buttons.size() == 1)
75  position[0] = el->position[0];
76  if (el->position[1] < position[1] || buttons.size() == 1)
77  position[1] = el->position[1];
78 
79  if (el->position[0] + el->dimensions[0] > end_position[0])
80  end_position[0] = el->position[0] + el->dimensions[0];
81  if (el->position[1] + el->dimensions[1] > end_position[1])
82  end_position[1] = el->position[1] + el->dimensions[1];
83 
84  dimensions = end_position - position;
85  }
86 
90  int getType (void)
91  {
93  }
94 
98  void resetSelection (void)
99  {
100  if (buttons.empty())
101  return;
102 
103  for (unsigned int i = 1; i < buttons.size(); ++i)
104  {
105  if (buttons[i]->selected)
106  {
107  buttons[i]->clicked();
108  }
109  }
110  if (!buttons[0]->selected)
111  buttons[0]->clicked();
112 
113  selected = 0;
114  }
115 
122  bool checkClicked (int x, int y)
123  {
124  for (unsigned int i = 0; i < buttons.size(); ++i)
125  {
126  if (buttons[i]->isVisible() && buttons[i]->isInside(x, y))
127  {
128  if (selected != -1)
129  {
130  buttons[selected]->clicked();
131  }
132  buttons[i]->clicked();
133  selected = i;
134  return true;
135  }
136  }
137  return false;
138  }
139 
145  void render ( Tucano::Camera &camera_2d, Shader &shader )
146  {
147  for (unsigned int i = 0; i < buttons.size(); ++i)
148  {
149  buttons[i]->render(camera_2d, shader);
150  }
151 
152  }
153 
154 };
155 }
156 }
157 #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
Base class for all GUI elements (buttons, sliders ...)
Definition: element.hpp:52
bool isVisible(void)
Return whether element is visible or not.
Definition: element.hpp:359
Definition: bufferobject.hpp:34
The button class draws a clickable rectangle on the screen to be used as a callback interface The sel...
Definition: selectbutton.hpp:43
A Shader object represents one GLSL program.
Definition: shader.hpp:45
vector< Tucano::GUI::SelectButton * > buttons
Vector containing select buttons inside box.
Definition: selectgroup.hpp:44
The gui select group is a placeholder for many selection buttons, so only one can be active at a time...
Definition: selectgroup.hpp:39
int selected
ID of currently selected button, -1 if no button is selected.
Definition: selectgroup.hpp:47
void add(SelectButton *el)
Adds an element to the gui The dimensions of the select group adjusts to fit all included select butt...
Definition: selectgroup.hpp:69
Definition: element.hpp:44
Eigen::Vector2i end_position
Definition: selectgroup.hpp:50
int getType(void)
Returns this element type, SELECTGROUP.
Definition: selectgroup.hpp:90
void render(Tucano::Camera &camera_2d, Shader &shader)
Renders all elements inside group.
Definition: selectgroup.hpp:145
SelectGroup(void)
Default constructor.
Definition: selectgroup.hpp:57
int element_type
Type of element.
Definition: element.hpp:57
Defines an abstract camera with a projection and view matrices.
Definition: camera.hpp:37
void resetSelection(void)
Select first element of group and makes sure all others are unselected.
Definition: selectgroup.hpp:98
bool checkClicked(int x, int y)
Check if any element inside select group was clicked.
Definition: selectgroup.hpp:122