TGUI  0.8.6
Gui.hpp
1 //
3 // TGUI - Texus' Graphical User Interface
4 // Copyright (C) 2012-2019 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 
148 #ifndef TGUI_REMOVE_DEPRECATED_CODE
149  TGUI_DEPRECATED("Use setTabKeyUsageEnabled instead") void enableTabKeyUsage();
153 
154 
158  TGUI_DEPRECATED("Use setTabKeyUsageEnabled instead") void disableTabKeyUsage();
159 #endif
160 
164  void setTabKeyUsageEnabled(bool enabled);
165 
166 
170  bool isTabKeyUsageEnabled() const;
171 
172 
177  void draw();
178 
179 
191  GuiContainer::Ptr getContainer() const;
192 
193 
200  void setFont(const Font& font);
201 
202 
209  std::shared_ptr<sf::Font> getFont() const;
210 
211 
218  const std::vector<Widget::Ptr>& getWidgets() const;
219 
220 
227  const std::vector<sf::String>& getWidgetNames() const;
228 
229 
239  void add(const Widget::Ptr& widgetPtr, const sf::String& widgetName = "");
240 
241 
255  Widget::Ptr get(const sf::String& widgetName) const;
256 
257 
272  template <class T>
273  typename T::Ptr get(const sf::String& widgetName) const
274  {
275  return m_container->get<T>(widgetName);
276  }
277 
278 
285  bool remove(const Widget::Ptr& widget);
286 
287 
292  void removeAllWidgets();
293 
294 
304  bool setWidgetName(const Widget::Ptr& widget, const std::string& name);
305 
306 
315  std::string getWidgetName(const Widget::Ptr& widget) const;
316 
317 
321  void focusNextWidget();
322 
323 
327  void focusPreviousWidget();
328 
329 
333  void unfocusAllWidgets();
334 
335 
340  void uncheckRadioButtons();
341 
342 
349  void setOpacity(float opacity);
350 
351 
358  float getOpacity() const;
359 
360 
367  void loadWidgetsFromFile(const std::string& filename);
368 
369 
376  void saveWidgetsToFile(const std::string& filename);
377 
378 
385  void loadWidgetsFromStream(std::stringstream& stream);
386 
387 
394  void loadWidgetsFromStream(std::stringstream&& stream);
395 
396 
403  void saveWidgetsToStream(std::stringstream& stream) const;
404 
405 
408  // Updates the internal clock to make animation possible. This function is called automatically by the draw function.
409  // You will thus only need to call it yourself when you are drawing everything manually.
411  void updateTime(const sf::Time& elapsedTime);
412 
413 
415  private:
416 
418  // Code that has to be run in each constructor
420  void init();
421 
422 
424  protected:
425 
426  // The internal clock which is used for animation of widgets
427  sf::Clock m_clock;
428 
429  // The sfml render target to draw on
430  sf::RenderTarget* m_target;
431  bool m_windowFocused = true;
432 
433  #if SFML_VERSION_MAJOR == 2 && SFML_VERSION_MINOR < 5
434  // Does m_target contains a sf::RenderWindow?
435  bool m_accessToWindow;
436  #endif
437 
438  // Internal container to store all widgets
439  GuiContainer::Ptr m_container = std::make_shared<GuiContainer>();
440 
441  Widget::Ptr m_visibleToolTip = nullptr;
442  sf::Time m_tooltipTime;
443  bool m_tooltipPossible = false;
444  Vector2f m_lastMousePos;
445 
446  sf::View m_view{{0, 0, 1, 1}};
447 
448  bool m_TabKeyUsageEnabled = true;
449 
450 
452  };
453 
455 
456 }
457 
459 
460 #endif // TGUI_GUI_HPP
Definition: Font.hpp:42
Gui class.
Definition: Gui.hpp:42
T::Ptr get(const sf::String &widgetName) const
Returns a pointer to an earlier created widget.
Definition: Gui.hpp:273
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:77
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
Definition: Vector2f.hpp:38