TGUI  v0.5.2
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
Group.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_GROUP_INCLUDED_
27 #define _TGUI_GROUP_INCLUDED_
28 
29 #include <list>
30 
32 
33 namespace tgui
34 {
38  struct TGUI_API Group
39  {
43  Group();
44 
45 
49  Group(const Group& copy);
50 
51 
55  virtual ~Group();
56 
57 
61  Group& operator= (const Group& right);
62 
63 
72  template <typename T>
73  T* add(const sf::String& objectName = "")
74  {
75  T* newObject = new T();
76  newObject->m_Parent = this;
77  m_EventManager.m_Objects.push_back(newObject);
78  m_ObjName.push_back(objectName);
79 
80  newObject->initialize();
81 
82  return newObject;
83  }
84 
85 
100  template <typename T>
101  T* get(const sf::String& objectName) const
102  {
103  for (unsigned int i=0; i<m_ObjName.size(); ++i)
104  {
105  if (m_ObjName[i].toWideString().compare(objectName) == 0)
106  return static_cast<T*>(m_EventManager.m_Objects[i]);
107  }
108 
109  return NULL;
110  }
111 
112 
122  template <typename T>
123  T* copy(T* oldObject, const sf::String& newObjectName = "")
124  {
125  T* newObject = new T(*oldObject);
126 
127  m_EventManager.m_Objects.push_back(newObject);
128  m_ObjName.push_back(newObjectName);
129 
130  return newObject;
131  }
132 
133 
145  template <typename T>
146  T* copy(const sf::String& oldObjectName, const sf::String& newObjectName = "")
147  {
148  for (unsigned int i=0; i<m_ObjName.size(); ++i)
149  {
150  if (m_ObjName[i].toWideString().compare(oldObjectName) == 0)
151  {
152  T* newObject = new T(*static_cast<T*>(m_EventManager.m_Objects[i]));
153 
154  m_EventManager.m_Objects.push_back(newObject);
155  m_ObjName.push_back(newObjectName);
156 
157  return newObject;
158  }
159  }
160 
161  return NULL;
162  }
163 
164 
177  virtual bool loadObjectsFromFile(const std::string& filename);
178 
179 
183  virtual std::vector<OBJECT*>& getObjects();
184 
185 
189  virtual std::vector<sf::String>& getObjectNames();
190 
191 
199  virtual void remove(const sf::String& objectName);
200 
201 
207  virtual void remove(OBJECT* object);
208 
209 
213  virtual void removeAllObjects();
214 
215 
227  virtual void focusObject(OBJECT* const object);
228 
229 
241  virtual void unfocusObject(OBJECT* const object);
242 
243 
251  virtual void unfocusAllObjects();
252 
253 
257  virtual void uncheckRadioButtons();
258 
259 
265  virtual void addCallback(const Callback& callback) = 0;
266 
267 
271  virtual void updateTime(const sf::Time& elapsedTime);
272 
273 
277  virtual void moveObjectToFront(OBJECT* object);
278 
279 
283  virtual void moveObjectToBack(OBJECT* object);
284 
285 
287  protected:
288 
290  // This function will call the draw function from all the objects in the correct order.
292  virtual void drawObjectGroup(sf::RenderTarget* target, const sf::RenderStates& states = sf::RenderStates::Default) const;
293 
294 
296  public:
297 
299  sf::Font globalFont;
300 
301 
303  protected:
304 
305  std::vector<sf::String> m_ObjName;
306 
307  // The internal event manager
308  EventManager m_EventManager;
309 
310  // Is the group focused? If so, then one of the objects inside the group may be focused
311  bool m_GroupFocused;
312 
313 
315  };
316 
318 }
319 
321 
322 #endif //_TGUI_GROUP_INCLUDED_
When you receive an action callback from an object then this struct will be passed as parameter...
Definition: Objects.hpp:362
The parent struct for every object.
Definition: Objects.hpp:36
Parent struct for objects that store multiple objects.
Definition: Group.hpp:38
T * copy(T *oldObject, const sf::String &newObjectName="")
Makes a copy of any existing object and returns the pointer to the new object.
Definition: Group.hpp:123
T * add(const sf::String &objectName="")
Creates and adds an object to the group.
Definition: Group.hpp:73
T * copy(const sf::String &oldObjectName, const sf::String &newObjectName="")
Makes a copy of any existing object and returns the pointer to the new object.
Definition: Group.hpp:146
sf::Font globalFont
The internal font, used by all objects by default. If not changed then this is the default SFML font...
Definition: Group.hpp:299