TGUI  v0.6.10
Gui.hpp
1 //
3 // TGUI - Texus's Graphical User Interface
4 // Copyright (C) 2012-2015 Bruno Van de Velde (vdv_b@tgui.eu)
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_WINDOW_HPP
27 #define TGUI_WINDOW_HPP
28 
29 
30 #include <queue>
31 
32 #include <TGUI/Container.hpp>
33 
35 
36 namespace tgui
37 {
39 
40  class TGUI_API Gui : public sf::NonCopyable
41  {
42  public:
43 
50  Gui();
51 
52 
61  Gui(sf::RenderWindow& window);
62 
63 
72  Gui(sf::RenderTarget& window);
73 
74 
81  void setWindow(sf::RenderWindow& window);
82 
83 
90  void setWindow(sf::RenderTarget& window);
91 
92 
99  sf::RenderTarget* getWindow() const;
100 
101 
117  bool handleEvent(sf::Event event, bool resetView = true);
118 
119 
131  void draw(bool resetView = true);
132 
133 
152  bool pollCallback(Callback& callback);
153 
154 
163  bool hasFocus() const;
164 
165 
174  sf::Vector2f getSize() const;
175 
176 
188  Container& getContainer();
189 
190 
201  bool setGlobalFont(const std::string& filename);
202 
203 
212  void setGlobalFont(const sf::Font& font);
213 
214 
223  const sf::Font& getGlobalFont() const;
224 
225 
232  const std::vector< Widget::Ptr >& getWidgets();
233 
234 
241  const std::vector<sf::String>& getWidgetNames();
242 
243 
258  void add(const Widget::Ptr& widgetPtr, const sf::String& widgetName = "");
259 
260 
278  Widget::Ptr get(const sf::String& widgetName, bool recursive = false) const;
279 
280 
299  template <class T>
300  typename T::Ptr get(const sf::String& widgetName, bool recursive = false) const
301  {
302  return m_Container.get<T>(widgetName, recursive);
303  }
304 
305 
322  Widget::Ptr copy(const Widget::Ptr& oldWidget, const sf::String& newWidgetName = "");
323 
324 
339  void remove(const Widget::Ptr& widget);
340 
341 
346  void removeAllWidgets();
347 
348 
358  bool setWidgetName(const Widget::Ptr& widget, const std::string& name);
359 
360 
371  bool getWidgetName(const Widget::Ptr& widget, std::string& name) const;
372 
373 
382  void focusWidget(Widget::Ptr& widget);
383 
384 
392  void focusNextWidget();
393 
394 
402  void focusPreviousWidget();
403 
404 
409  void unfocusWidgets();
410 
411 
416  void uncheckRadioButtons();
417 
418 
425  void moveWidgetToFront(Widget::Ptr& widget);
426 
427 
434  void moveWidgetToBack(Widget::Ptr& widget);
435 
436 
446  void bindGlobalCallback(std::function<void(const Callback&)> func);
447 
448 
459  template <typename T>
460  void bindGlobalCallback(void (T::*func)(const Callback&), const T* const classPtr)
461  {
462  m_Container.bindGlobalCallback(func, classPtr);
463  }
464 
465 
470  void unbindGlobalCallback();
471 
472 
488  bool loadWidgetsFromFile(const std::string& filename);
489 
490 
501  bool saveWidgetsToFile(const std::string& filename);
502 
503 
505  // Update the internal clock to make animation possible. This function is called automatically by the draw function.
506  // You will thus only need to call it yourself when you are drawing everything manually.
508  void updateTime(const sf::Time& elapsedTime);
509 
510 
512  // TGUI uses this function internally to handle widget callbacks.
513  // When you tell a widget to send its callbacks to its parent then this function is called.
514  //
515  // When one or more global callback functions were set then these functions will be called.
516  // Otherwise, the callback will be added to the callback queue and you will be able to poll it later with pollCallback.
517  //
518  // You can use this function to fake a widget callback.
520  void addChildCallback(const Callback& callback);
521 
522 
524  protected:
525 
526  // This will store all widget callbacks until you pop them with getCallback
527  std::queue<Callback> m_Callback;
528 
529  // The internal clock which is used for animation of widgets
530  sf::Clock m_Clock;
531 
532  // The sfml window or other target to draw on
533  sf::RenderTarget* m_Window;
534 
535  // Does m_Window contains a sf::RenderWindow?
536  bool m_accessToWindow;
537 
538  // Internal container to store all widgets
539  GuiContainer m_Container;
540 
541 
543 
544  template<class T>
545  friend class SharedWidgetPtr;
546 
548  };
549 
551 
552 }
553 
555 
556 #endif // TGUI_WINDOW_HPP
Namespace that contains all TGUI functions and classes.
Definition: AnimatedPicture.hpp:33
Definition: Callback.hpp:45
Definition: Gui.hpp:40
Definition: Container.hpp:571
Parent class for widgets that store multiple widgets.
Definition: Container.hpp:43
void bindGlobalCallback(void(T::*func)(const Callback &), const T *const classPtr)
Bind a function to the callbacks of all child widgets.
Definition: Gui.hpp:460
Definition: SharedWidgetPtr.hpp:44