TGUI  0.8-beta
Gui.hpp
1 //
3 // TGUI - Texus' Graphical User Interface
4 // Copyright (C) 2012-2018 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 
151  void enableTabKeyUsage();
152 
153 
157  void disableTabKeyUsage();
158 
159 
163  bool isTabKeyUsageEnabled() const;
164 
165 
170  void draw();
171 
172 
184  GuiContainer::Ptr getContainer() const;
185 
186 
193  void setFont(const Font& font);
194 
195 
202  std::shared_ptr<sf::Font> getFont() const;
203 
204 
211  const std::vector<Widget::Ptr>& getWidgets() const;
212 
213 
220  const std::vector<sf::String>& getWidgetNames() const;
221 
222 
232  void add(const Widget::Ptr& widgetPtr, const sf::String& widgetName = "");
233 
234 
248  Widget::Ptr get(const sf::String& widgetName) const;
249 
250 
265  template <class T>
266  typename T::Ptr get(const sf::String& widgetName) const
267  {
268  return m_container->get<T>(widgetName);
269  }
270 
271 
278  bool remove(const Widget::Ptr& widget);
279 
280 
285  void removeAllWidgets();
286 
287 
297  bool setWidgetName(const Widget::Ptr& widget, const std::string& name);
298 
299 
308  std::string getWidgetName(const Widget::Ptr& widget) const;
309 
310 
314  void focusNextWidget();
315 
316 
320  void focusPreviousWidget();
321 
322 
326  void unfocusAllWidgets();
327 
328 
333  void uncheckRadioButtons();
334 
335 
342  void setOpacity(float opacity);
343 
344 
351  float getOpacity() const;
352 
353 
360  void loadWidgetsFromFile(const std::string& filename);
361 
362 
369  void saveWidgetsToFile(const std::string& filename);
370 
371 
378  void loadWidgetsFromStream(std::stringstream& stream);
379 
380 
387  void loadWidgetsFromStream(std::stringstream&& stream);
388 
389 
396  void saveWidgetsToStream(std::stringstream& stream) const;
397 
398 
401  // Updates the internal clock to make animation possible. This function is called automatically by the draw function.
402  // You will thus only need to call it yourself when you are drawing everything manually.
404  void updateTime(const sf::Time& elapsedTime);
405 
406 
408  private:
409 
411  // Code that has to be run in each constructor
413  void init();
414 
415 
417  protected:
418 
419  // The internal clock which is used for animation of widgets
420  sf::Clock m_clock;
421 
422  // The sfml render target to draw on
423  sf::RenderTarget* m_target;
424  bool m_windowFocused = true;
425 
426  #if SFML_VERSION_MAJOR == 2 && SFML_VERSION_MINOR < 5
427  // Does m_target contains a sf::RenderWindow?
428  bool m_accessToWindow;
429  #endif
430 
431  // Internal container to store all widgets
432  GuiContainer::Ptr m_container = std::make_shared<GuiContainer>();
433 
434  Widget::Ptr m_visibleToolTip = nullptr;
435  sf::Time m_tooltipTime;
436  bool m_tooltipPossible = false;
437  Vector2f m_lastMousePos;
438 
439  sf::View m_view;
440 
441  bool m_TabKeyUsageEnabled = true;
442 
443 
445  };
446 
448 
449 }
450 
452 
453 #endif // TGUI_GUI_HPP
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
Definition: Font.hpp:42
Gui class.
Definition: Gui.hpp:42
Definition: Vector2f.hpp:37
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:76