TGUI  0.9-dev
Gui.hpp
1 //
3 // TGUI - Texus' Graphical User Interface
4 // Copyright (C) 2012-2020 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 <chrono>
33 #include <queue>
34 
36 
37 namespace tgui
38 {
43  class TGUI_API Gui
44  {
45  public:
46 
53  Gui();
54 
55 #if SFML_VERSION_MAJOR == 2 && SFML_VERSION_MINOR < 5
56  Gui(sf::RenderWindow& window);
65 #endif
66 
75  Gui(sf::RenderTarget& target);
76 
77 
79  // Deleted copy constructor
81  Gui(const Gui& copy) = delete;
82 
83 
85  // Deleted assignment operator overload
87  Gui& operator=(const Gui& right) = delete;
88 
89 #if SFML_VERSION_MAJOR == 2 && SFML_VERSION_MINOR < 5
90  void setTarget(sf::RenderWindow& window);
97 #endif
98 
105  void setTarget(sf::RenderTarget& target);
106 
107 
114  sf::RenderTarget* getTarget() const;
115 
116 
123  void setView(const sf::View& view);
124 
125 
132  const sf::View& getView() const;
133 
134 
146  bool handleEvent(sf::Event event);
147 
148 
152  void setTabKeyUsageEnabled(bool enabled);
153 
154 
158  bool isTabKeyUsageEnabled() const;
159 
160 
165  void draw();
166 
167 
179  GuiContainer::Ptr getContainer() const;
180 
181 
188  void setFont(const Font& font);
189 
190 
197  std::shared_ptr<sf::Font> getFont() const;
198 
199 
206  const std::vector<Widget::Ptr>& getWidgets() const;
207 
208 
218  void add(const Widget::Ptr& widgetPtr, const String& widgetName = "");
219 
220 
234  Widget::Ptr get(const String& widgetName) const;
235 
236 
251  template <class T>
252  typename T::Ptr get(const String& widgetName) const
253  {
254  return m_container->get<T>(widgetName);
255  }
256 
257 
264  bool remove(const Widget::Ptr& widget);
265 
266 
271  void removeAllWidgets();
272 
273 
278  bool focusNextWidget();
279 
280 
285  bool focusPreviousWidget();
286 
287 
291  void unfocusAllWidgets();
292 
293 
299  void moveWidgetToFront(const Widget::Ptr& widget);
300 
301 
307  void moveWidgetToBack(const Widget::Ptr& widget);
308 
309 
314  void uncheckRadioButtons();
315 
316 
323  void setOpacity(float opacity);
324 
325 
332  float getOpacity() const;
333 
334 
343  void setTextSize(unsigned int size);
344 
345 
351  unsigned int getTextSize() const;
352 
353 
360  void loadWidgetsFromFile(const String& filename, bool replaceExisting = true);
361 
362 
369  void saveWidgetsToFile(const String& filename);
370 
371 
378  void loadWidgetsFromStream(std::stringstream& stream, bool replaceExisting = true);
379 
380 
387  void loadWidgetsFromStream(std::stringstream&& stream, bool replaceExisting = true);
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(Duration 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  std::chrono::steady_clock::time_point m_lastUpdateTime;
420 
421  // The sfml render target to draw on
422  sf::RenderTarget* m_target;
423  bool m_windowFocused = true;
424 
425  #if SFML_VERSION_MAJOR == 2 && SFML_VERSION_MINOR < 5
426  // Does m_target contains a sf::RenderWindow?
427  bool m_accessToWindow;
428  #endif
429 
430  // Internal container to store all widgets
431  GuiContainer::Ptr m_container = std::make_shared<GuiContainer>();
432 
433  Widget::Ptr m_visibleToolTip = nullptr;
434  Duration m_tooltipTime;
435  bool m_tooltipPossible = false;
436  Vector2f m_lastMousePos;
437 
438  sf::View m_view{{0, 0, 1, 1}};
439 
440  bool m_TabKeyUsageEnabled = true;
441 
442 
444  };
445 
447 
448 }
449 
451 
452 #endif // TGUI_GUI_HPP
Definition: Font.hpp:42
Gui class.
Definition: Gui.hpp:43
T::Ptr get(const String &widgetName) const
Returns a pointer to an earlier created widget.
Definition: Gui.hpp:252
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:72
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:35
Wrapper for durations.
Definition: Duration.hpp:48
Wrapper class to store strings.
Definition: String.hpp:70