TGUI  0.8-dev
Gui.hpp
1 //
3 // TGUI - Texus' Graphical User Interface
4 // Copyright (C) 2012-2017 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_GUI_HPP
27 #define TGUI_GUI_HPP
28 
29 
30 #include <TGUI/Container.hpp>
31 #include <SFML/Graphics/RenderWindow.hpp>
32 #include <queue>
33 
35 
36 namespace tgui
37 {
42  class TGUI_API Gui
43  {
44  public:
45 
52  Gui();
53 
54 #if SFML_VERSION_MAJOR == 2 && SFML_VERSION_MINOR < 5
55  Gui(sf::RenderWindow& window);
64 #endif
65 
74  Gui(sf::RenderTarget& target);
75 
76 
78  // Deleted copy constructor
80  Gui(const Gui& copy) = delete;
81 
82 
84  // Deleted assignment operator overload
86  Gui& operator=(const Gui& right) = delete;
87 
88 #if SFML_VERSION_MAJOR == 2 && SFML_VERSION_MINOR < 5
89  void setTarget(sf::RenderWindow& window);
96 #endif
97 
104  void setTarget(sf::RenderTarget& target);
105 
106 
113  sf::RenderTarget* getTarget() const;
114 
115 
122  void setView(const sf::View& view);
123 
124 
131  const sf::View& getView() const;
132 
133 
145  bool handleEvent(sf::Event event);
146 
147 
152  void draw();
153 
154 
166  GuiContainer::Ptr getContainer() const;
167 
168 
175  void setFont(const Font& font);
176 
177 
184  std::shared_ptr<sf::Font> getFont() const;
185 
186 
193  const std::vector<Widget::Ptr>& getWidgets() const;
194 
195 
202  const std::vector<sf::String>& getWidgetNames() const;
203 
204 
214  void add(const Widget::Ptr& widgetPtr, const sf::String& widgetName = "");
215 
216 
231  Widget::Ptr get(const sf::String& widgetName) const;
232 
233 
249  template <class T>
250  typename T::Ptr get(const sf::String& widgetName) const
251  {
252  return m_container->get<T>(widgetName);
253  }
254 
255 
262  bool remove(const Widget::Ptr& widget);
263 
264 
269  void removeAllWidgets();
270 
271 
281  bool setWidgetName(const Widget::Ptr& widget, const std::string& name);
282 
283 
292  std::string getWidgetName(const Widget::Ptr& widget) const;
293 
294 
303  void focusWidget(const Widget::Ptr& widget);
304 
305 
313  void focusNextWidget();
314 
315 
323  void focusPreviousWidget();
324 
325 
330  void unfocusWidgets();
331 
332 
337  void uncheckRadioButtons();
338 
339 
346  void setOpacity(float opacity);
347 
348 
355  float getOpacity() const;
356 
357 
364  void loadWidgetsFromFile(const std::string& filename);
365 
366 
373  void saveWidgetsToFile(const std::string& filename);
374 
375 
382  void loadWidgetsFromStream(std::stringstream& stream);
383 
384 
391  void loadWidgetsFromStream(std::stringstream&& stream);
392 
393 
400  void saveWidgetsToStream(std::stringstream& stream) const;
401 
402 
405  // Updates the internal clock to make animation possible. This function is called automatically by the draw function.
406  // You will thus only need to call it yourself when you are drawing everything manually.
408  void updateTime(const sf::Time& elapsedTime);
409 
410 
412  protected:
413 
414  // The internal clock which is used for animation of widgets
415  sf::Clock m_clock;
416 
417  // The sfml render target to draw on
418  sf::RenderTarget* m_target;
419 
420  #if SFML_VERSION_MAJOR == 2 && SFML_VERSION_MINOR < 5
421  // Does m_target contains a sf::RenderWindow?
422  bool m_accessToWindow;
423  #endif
424 
425  // Internal container to store all widgets
426  GuiContainer::Ptr m_container = std::make_shared<GuiContainer>();
427 
428  Widget::Ptr m_visibleToolTip = nullptr;
429  sf::Time m_tooltipTime;
430  bool m_tooltipPossible = false;
431  sf::Vector2f m_lastMousePos;
432 
433  sf::View m_view;
434 
435 
437  };
438 
440 
441 }
442 
444 
445 #endif // TGUI_GUI_HPP
Namespace that contains all TGUI functions and classes.
Definition: Animation.hpp:33
Definition: Font.hpp:41
Gui class.
Definition: Gui.hpp:42
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:62