TGUI  v0.7.5
Gui.hpp
1 //
3 // TGUI - Texus's 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_WINDOW_HPP
27 #define TGUI_WINDOW_HPP
28 
29 
30 #include <queue>
31 
32 #include <TGUI/Container.hpp>
33 
35 
36 namespace tgui
37 {
42  class TGUI_API Gui
43  {
44  public:
45 
52  Gui();
53 
54 
63  Gui(sf::RenderWindow& window);
64 
65 
74  Gui(sf::RenderTarget& window);
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 
95  void setWindow(sf::RenderWindow& window);
96 
97 
104  void setWindow(sf::RenderTarget& window);
105 
106 
113  sf::RenderTarget* getWindow() const
114  {
115  return m_window;
116  }
117 
118 
125  void setView(const sf::View& view);
126 
127 
134  const sf::View& getView() const
135  {
136  return m_view;
137  }
138 
139 
151  bool handleEvent(sf::Event event);
152 
153 
158  void draw();
159 
160 
169  sf::Vector2f getSize() const;
170 
171 
183  GuiContainer::Ptr getContainer() const
184  {
185  return m_container;
186  }
187 
188 
195  void setFont(const Font& font)
196  {
197  m_container->setFont(font);
198  }
199 
200 
207  std::shared_ptr<sf::Font> getFont() const
208  {
209  return m_container->getFont();
210  }
211 
212 
219  const std::vector< Widget::Ptr >& getWidgets()
220  {
221  return m_container->getWidgets();
222  }
223 
224 
231  const std::vector<sf::String>& getWidgetNames()
232  {
233  return m_container->getWidgetNames();
234  }
235 
236 
253  void add(const Widget::Ptr& widgetPtr, const sf::String& widgetName = "");
254 
255 
273  Widget::Ptr get(const sf::String& widgetName, bool recursive = false) const;
274 
275 
294  template <class T>
295  typename T::Ptr get(const sf::String& widgetName, bool recursive = false) const
296  {
297  return m_container->get<T>(widgetName, recursive);
298  }
299 
300 
315  bool remove(const Widget::Ptr& widget);
316 
317 
322  void removeAllWidgets();
323 
324 
334  bool setWidgetName(const Widget::Ptr& widget, const std::string& name);
335 
336 
345  std::string getWidgetName(const Widget::Ptr& widget) const;
346 
347 
356  void focusWidget(const Widget::Ptr& widget);
357 
358 
366  void focusNextWidget();
367 
368 
376  void focusPreviousWidget();
377 
378 
383  void unfocusWidgets();
384 
385 
390  void uncheckRadioButtons();
391 
392 
399  void setOpacity(float opacity);
400 
401 
408  float getOpacity() const;
409 
410 
417  void loadWidgetsFromFile(const std::string& filename);
418 
419 
426  void saveWidgetsToFile(const std::string& filename);
427 
428 
435  void loadWidgetsFromStream(std::stringstream& stream);
436 
437 
444  void saveWidgetsToStream(std::stringstream& stream);
445 
446 
449  // Update the internal clock to make animation possible. This function is called automatically by the draw function.
450  // You will thus only need to call it yourself when you are drawing everything manually.
452  void updateTime(const sf::Time& elapsedTime);
453 
454 
456  protected:
457 
458  // The internal clock which is used for animation of widgets
459  sf::Clock m_clock;
460 
461  // The sfml window or other target to draw on
462  sf::RenderTarget* m_window;
463 
464  #if SFML_VERSION_MAJOR == 2 && SFML_VERSION_MINOR < 5
465  // Does m_Window contains a sf::RenderWindow?
466  bool m_accessToWindow;
467  #endif
468 
469  // Internal container to store all widgets
470  GuiContainer::Ptr m_container = std::make_shared<GuiContainer>();
471 
472  Widget::Ptr m_visibleToolTip = nullptr;
473  sf::Time m_tooltipTime;
474  bool m_tooltipPossible = false;
475  sf::Vector2f m_lastMousePos;
476 
477  sf::View m_view;
478 
479 
481  };
482 
484 
485 }
486 
488 
489 #endif // TGUI_WINDOW_HPP
Namespace that contains all TGUI functions and classes.
Definition: Animation.hpp:33
Definition: Font.hpp:37
Gui class.
Definition: Gui.hpp:42
const std::vector< sf::String > & getWidgetNames()
Returns a list of the names of all the widgets.
Definition: Gui.hpp:231
sf::RenderTarget * getWindow() const
Returns the window on which the gui is being drawn.
Definition: Gui.hpp:113
std::shared_ptr< sf::Font > getFont() const
Returns the global font.
Definition: Gui.hpp:207
GuiContainer::Ptr getContainer() const
Returns the internal container of the Gui.
Definition: Gui.hpp:183
const std::vector< Widget::Ptr > & getWidgets()
Returns a list of all the widgets.
Definition: Gui.hpp:219
void setFont(const Font &font)
Changes the global font.
Definition: Gui.hpp:195
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:75
const sf::View & getView() const
Return the view that is currently used by the gui.
Definition: Gui.hpp:134