TGUI  0.8.9
Gui.hpp
1
2//
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 <queue>
33
35
36namespace tgui
37{
42 class TGUI_API Gui
43 {
44 public:
45
52 Gui();
53
54#if SFML_VERSION_MAJOR == 2 && SFML_VERSION_MINOR < 5
63 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
95 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
152 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
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#ifndef TGUI_REMOVE_DEPRECATED_CODE
227 TGUI_DEPRECATED("Use getWidgets() and Widget::getWidgetName instead") const std::vector<sf::String> getWidgetNames() const;
228#endif
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
293
294
304
305
315
316
326 Widget::Ptr getWidgetAtPosition(sf::Vector2f pos) const;
327
328
338 Widget::Ptr getWidgetBelowMouseCursor(sf::Vector2i mousePos) const;
339
340
341#ifndef TGUI_REMOVE_DEPRECATED_CODE
351 TGUI_DEPRECATED("Use Widget::setWidgetName instead") bool setWidgetName(const Widget::Ptr& widget, const std::string& name);
352
353
362 TGUI_DEPRECATED("Use Widget::getWidgetName instead") std::string getWidgetName(const Widget::Ptr& widget) const;
363#endif
364
373 bool focusNextWidget(bool recursive = true);
374
375
384 bool focusPreviousWidget(bool recursive = true);
385
386
391
392
398 void moveWidgetToFront(const Widget::Ptr& widget);
399
400
406 void moveWidgetToBack(const Widget::Ptr& widget);
407
408
419 std::size_t moveWidgetForward(const Widget::Ptr& widget);
420
421
432 std::size_t moveWidgetBackward(const Widget::Ptr& widget);
433
434
440
441
448 void setOpacity(float opacity);
449
450
457 float getOpacity() const;
458
459
468 void setTextSize(unsigned int size);
469
470
476 unsigned int getTextSize() const;
477
478
485 void loadWidgetsFromFile(const std::string& filename, bool replaceExisting = true);
486
487
494 void saveWidgetsToFile(const std::string& filename);
495
496
503 void loadWidgetsFromStream(std::stringstream& stream, bool replaceExisting = true);
504
505
512 void loadWidgetsFromStream(std::stringstream&& stream, bool replaceExisting = true);
513
514
521 void saveWidgetsToStream(std::stringstream& stream) const;
522
523
529 void setDrawingUpdatesTime(bool drawUpdatesTime);
530
531
540
541
544 // Updates the internal clock to make animation possible. This function is called automatically by the draw function.
545 // You will thus only need to call it yourself when you are drawing everything manually.
547 bool updateTime(const sf::Time& elapsedTime);
548
549
551 private:
552
554 // Code that has to be run in each constructor
556 void init();
557
558
560 protected:
561
562 // The internal clock which is used for animation of widgets
563 sf::Clock m_clock;
564
565 // The sfml render target to draw on
566 sf::RenderTarget* m_target;
567 bool m_windowFocused = true;
568
569 #if SFML_VERSION_MAJOR == 2 && SFML_VERSION_MINOR < 5
570 // Does m_target contains a sf::RenderWindow?
571 bool m_accessToWindow;
572 #endif
573
574 // Internal container to store all widgets
575 GuiContainer::Ptr m_container = std::make_shared<GuiContainer>();
576
577 Widget::Ptr m_visibleToolTip = nullptr;
578 sf::Time m_tooltipTime;
579 bool m_tooltipPossible = false;
580 Vector2f m_lastMousePos;
581
582 sf::View m_view{{0, 0, 1, 1}};
583
584 bool m_drawUpdatesTime = true;
585 bool m_TabKeyUsageEnabled = true;
586
587
589 };
590
592
593}
594
596
597#endif // TGUI_GUI_HPP
Definition: Font.hpp:43
Gui class.
Definition: Gui.hpp:43
Widget::Ptr get(const sf::String &widgetName) const
Returns a pointer to an earlier created widget.
std::size_t moveWidgetForward(const Widget::Ptr &widget)
Places a widget one step forward in the z-order.
unsigned int getTextSize() const
Returns the character size for future child widgets (and for existing widgets where the size wasn't c...
std::size_t moveWidgetBackward(const Widget::Ptr &widget)
Places a widget one step backward in the z-order.
void draw()
Draws all the widgets that were added to the gui.
void moveWidgetToFront(const Widget::Ptr &widget)
Places a widget before all other widgets, to the front of the z-order.
GuiContainer::Ptr getContainer() const
Returns the internal container of the Gui.
void setTextSize(unsigned int size)
Changes the character size of all existing and future child widgets.
Widget::Ptr getFocusedChild() const
Returns the child widget that is focused inside this container.
bool focusNextWidget(bool recursive=true)
Focuses the next widget in the gui.
Widget::Ptr getWidgetBelowMouseCursor(sf::Vector2i mousePos) const
Returns the leaf child widget below the mouse.
void setTabKeyUsageEnabled(bool enabled)
When the tab key usage is enabled, pressing tab will focus another widget.
void moveWidgetToBack(const Widget::Ptr &widget)
Places a widget behind all other widgets, to the back of the z-order.
void setFont(const Font &font)
Changes the global font.
const sf::View & getView() const
Returns the view that is currently used by the gui.
Gui()
Default constructor.
void loadWidgetsFromFile(const std::string &filename, bool replaceExisting=true)
Loads the child widgets from a text file.
bool handleEvent(sf::Event event)
Passes the event to the widgets.
void setOpacity(float opacity)
Changes the opacity of all widgets.
T::Ptr get(const sf::String &widgetName) const
Returns a pointer to an earlier created widget.
Definition: Gui.hpp:273
float getOpacity() const
Returns the opacity of all the widgets.
void saveWidgetsToFile(const std::string &filename)
Saves the child widgets to a text file.
bool focusPreviousWidget(bool recursive=true)
Focuses the previous widget in the gui.
bool updateTime()
Updates the internal clock (for animations and blinking edit cursors)
Widget::Ptr getWidgetAtPosition(sf::Vector2f pos) const
Returns the leaf child widget that is located at the given position.
void unfocusAllWidgets()
Unfocus all the widgets.
bool isTabKeyUsageEnabled() const
Returns whether the tab key usage is enabled (if so, pressing tab will focus another widget)
void add(const Widget::Ptr &widgetPtr, const sf::String &widgetName="")
Adds a widget to the container.
Gui(sf::RenderTarget &target)
Constructs the gui and set the target on which the gui should be drawn.
Widget::Ptr getFocusedLeaf() const
Returns the leaf child widget that is focused inside this container.
std::shared_ptr< sf::Font > getFont() const
Returns the global font.
void setView(const sf::View &view)
Changes the view that is used by the gui.
void uncheckRadioButtons()
Unchecks all the radio buttons.
void saveWidgetsToStream(std::stringstream &stream) const
Saves this the child widgets to a text file.
sf::RenderTarget * getTarget() const
Returns the render target on which the gui is being drawn.
void loadWidgetsFromStream(std::stringstream &stream, bool replaceExisting=true)
Loads the child widgets from a string stream.
void loadWidgetsFromStream(std::stringstream &&stream, bool replaceExisting=true)
Loads the child widgets from a string stream.
bool remove(const Widget::Ptr &widget)
Removes a single widget that was added to the container.
void setTarget(sf::RenderTarget &target)
Sets the target on which the gui should be drawn.
void setDrawingUpdatesTime(bool drawUpdatesTime)
Sets whether drawing the gui will automatically update the internal clock or whether the user does it...
const std::vector< Widget::Ptr > & getWidgets() const
Returns a list of all the widgets.
void removeAllWidgets()
Removes all widgets that were added to the container.
Wrapper class to store strings.
Definition: String.hpp:119
Definition: Vector2f.hpp:39
The parent class for every widget.
Definition: Widget.hpp:74
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:77
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:37