TGUI  0.7.8
Gui.hpp
1
2//
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
36namespace 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
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
367
368
377
378
384
385
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
Definition: Font.hpp:38
Gui class.
Definition: Gui.hpp:43
const std::vector< sf::String > & getWidgetNames()
Returns a list of the names of all the widgets.
Definition: Gui.hpp:231
void draw()
Draws all the widgets that were added to the gui.
void setWindow(sf::RenderTarget &window)
Set the target on which the gui should be drawn.
void setWindow(sf::RenderWindow &window)
Set the window on which the gui should be drawn.
GuiContainer::Ptr getContainer() const
Returns the internal container of the Gui.
Definition: Gui.hpp:183
std::string getWidgetName(const Widget::Ptr &widget) const
Returns the name of a widget.
void setFont(const Font &font)
Changes the global font.
Definition: Gui.hpp:195
const sf::View & getView() const
Return the view that is currently used by the gui.
Definition: Gui.hpp:134
Gui()
Default constructor.
bool handleEvent(sf::Event event)
Passes the event to the widgets.
void saveWidgetsToStream(std::stringstream &stream)
Save this the child widgets to a text file.
const std::vector< Widget::Ptr > & getWidgets()
Returns a list of all the widgets.
Definition: Gui.hpp:219
void setOpacity(float opacity)
Changes the opacity of all widgets.
float getOpacity() const
Returns the opacity of all the widgets.
void saveWidgetsToFile(const std::string &filename)
Save the child widgets to a text file.
void focusWidget(const Widget::Ptr &widget)
Focuses a widget.
bool setWidgetName(const Widget::Ptr &widget, const std::string &name)
Changes the name of a widget.
Widget::Ptr get(const sf::String &widgetName, bool recursive=false) const
Returns a pointer to an earlier created widget.
void loadWidgetsFromStream(std::stringstream &stream)
Load the child widgets from a string stream.
void unfocusWidgets()
Unfocus all the widgets.
T::Ptr get(const sf::String &widgetName, bool recursive=false) const
Returns a pointer to an earlier created widget.
Definition: Gui.hpp:295
void add(const Widget::Ptr &widgetPtr, const sf::String &widgetName="")
Adds a widget to the container.
Gui(sf::RenderTarget &window)
Construct the gui and set the target on which the gui should be drawn.
void focusNextWidget()
Focuses the next widget.
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
Gui(sf::RenderWindow &window)
Construct the gui and set the window on which the gui should be drawn.
void loadWidgetsFromFile(const std::string &filename)
Load the child widgets from a text file.
void setView(const sf::View &view)
Change the view that is used by the gui.
void focusPreviousWidget()
Focuses the previous widget.
void uncheckRadioButtons()
Uncheck all the radio buttons.
sf::Vector2f getSize() const
Returns the size of the container.
bool remove(const Widget::Ptr &widget)
Removes a single widget that was added to the container.
void removeAllWidgets()
Removes all widgets that were added to the container.
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:75
Namespace that contains all TGUI functions and classes.
Definition: Animation.hpp:34