TGUI  v0.5.2
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
Grid.hpp
1 //
3 // TGUI - Texus's Graphical User Interface
4 // Copyright (C) 2012 Bruno Van de Velde (VDV_B@hotmail.com)
5 //
6 // This software is provided 'as-is', without any express or implied warranty.
7 // In no event will the authors be held liable for any damages arising from the use of this software.
8 //
9 // Permission is granted to anyone to use this software for any purpose,
10 // including commercial applications, and to alter it and redistribute it freely,
11 // subject to the following restrictions:
12 //
13 // 1. The origin of this software must not be misrepresented;
14 // you must not claim that you wrote the original software.
15 // If you use this software in a product, an acknowledgment
16 // in the product documentation would be appreciated but is not required.
17 //
18 // 2. Altered source versions must be plainly marked as such,
19 // and must not be misrepresented as being the original software.
20 //
21 // 3. This notice may not be removed or altered from any source distribution.
22 //
24 
25 
26 #ifndef _TGUI_GRID_INCLUDED_
27 #define _TGUI_GRID_INCLUDED_
28 
29 
31 
33 
34 namespace tgui
35 {
37 
38  struct TGUI_API Grid : public GroupObject
39  {
46  struct Layout
47  {
48  enum layouts
49  {
52 
54  Center
55 
56  // TODO: Add more layouts
57  };
58  };
59 
60 
65  Grid();
66 
67 
74  Grid(const Grid& copy);
75 
76 
81  virtual ~Grid();
82 
83 
92  Grid& operator= (const Grid& right);
93 
94 
96  // This function is called when the object is created (when it is added to a group).
98  virtual void initialize();
99 
100 
102  // Makes a copy of the object by calling the copy constructor.
103  // This function calls new and if you use this function then you are responsible for calling delete.
105  virtual Grid* clone();
106 
107 
120  virtual void setSize(float width, float height);
121 
122 
129  virtual Vector2u getSize() const;
130 
131 
138  virtual Vector2f getScaledSize() const;
139 
140 
149  virtual void remove(OBJECT* object);
150 
151 
156  virtual void removeAllObjects();
157 
158 
167  virtual void addToRow(OBJECT* const object, const Vector4u& borders = Vector4u(0, 0, 0, 0), Layout::layouts layout = Layout::Center);
168 
169 
176  virtual void addRow(unsigned int rowHeight = 0);
177 
178 
185  virtual void updateObjects();
186 
187 
192  virtual void changeObjectLayout(const OBJECT* const object, Layout::layouts layout = Layout::Center);
193 
194 
196  // These functions are used to receive callback from EventManager.
197  // These events are send to the childs of the grid by it's own EventManager.
198  // You normally don't need them, but you can use these functions to simulate an event.
200  virtual bool mouseOnObject(float x, float y);
201  virtual void objectFocused();
202  virtual void objectUnfocused();
203 
204 
206  // The objects inside the grid use this function to send their callbacks.
207  // This function will alert the window (or any other parent of this grid) about the callback.
209  virtual void addCallback(const Callback& callback);
210 
211 
213  protected:
214 
215 
217  // Updates the position of one of the objects.
219  virtual void updatePosition(unsigned int row, unsigned int column);
220 
221 
223  // Reposition all the objects.
225  virtual void updatePositionsOfAllObjects();
226 
227 
229  // Because this struct is derived from sf::Drawable, you can just call the draw function from your sf::RenderTarget.
230  // This function will be called and it will draw the grid object on the render target.
232  virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
233 
234 
236  protected:
237 
238  std::vector< std::vector<OBJECT*> > m_GridObjects;
239  std::vector< std::vector<Vector4u> > m_ObjBorders;
240  std::vector< std::vector<Layout::layouts> > m_ObjLayout;
241 
242  std::vector<unsigned int> m_RowHeight;
243  std::vector<unsigned int> m_ColumnWidth;
244 
245  Vector2u m_Size;
246 
247 
249  };
250 
252 }
253 
255 
256 #endif //_TGUI_GRID_INCLUDED_
Definition: GroupObject.hpp:35
When you receive an action callback from an object then this struct will be passed as parameter...
Definition: Objects.hpp:362
layouts
Definition: Grid.hpp:48
The parent struct for every object.
Definition: Objects.hpp:36
The layout of the object.
Definition: Grid.hpp:46
Definition: Grid.hpp:38
Definition: Vectors.hpp:36
Draw the object in the top left corner of the cell.
Definition: Grid.hpp:51