TGUI  0.8.9
MessageBox.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_MESSAGE_BOX_HPP
27#define TGUI_MESSAGE_BOX_HPP
28
29
30#include <TGUI/Widgets/Label.hpp>
31#include <TGUI/Widgets/Button.hpp>
32#include <TGUI/Widgets/ChildWindow.hpp>
33#include <TGUI/Renderers/MessageBoxRenderer.hpp>
34
35#undef MessageBox // windows.h defines MessageBox when NOMB isn't defined before including windows.h
36
38
39namespace tgui
40{
44 class TGUI_API MessageBox : public ChildWindow
45 {
46 public:
47
48 typedef std::shared_ptr<MessageBox> Ptr;
49 typedef std::shared_ptr<const MessageBox> ConstPtr;
50
51
53 // Default constructor
55 MessageBox();
56
57
67 static MessageBox::Ptr create(sf::String title = "", sf::String text = "", std::vector<sf::String> buttons = {});
68
69
73 MessageBox(const MessageBox& copy);
74
75
80
81
85 MessageBox& operator= (const MessageBox& right);
86
87
91 MessageBox& operator= (MessageBox&& right);
92
93
103
104
110 const MessageBoxRenderer* getSharedRenderer() const;
111
118 const MessageBoxRenderer* getRenderer() const;
119
120
130 void setText(const sf::String& text);
131
132
139 const sf::String& getText() const;
140
141
150 void setTextSize(unsigned int size) override;
151
152
162 void addButton(const sf::String& buttonCaption);
163
164
171 std::vector<sf::String> getButtons() const;
172
173
175 protected:
176
178 // Makes sure all widgets lie within the window and places them on the correct position.
180 void rearrange();
181
182
192 Signal& getSignal(std::string signalName) override;
193
194
201 void rendererChanged(const std::string& property) override;
202
203
207 std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
208
209
213 void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
214
215
217 // Makes a copy of the widget
219 Widget::Ptr clone() const override
220 {
221 return std::make_shared<MessageBox>(*this);
222 }
223
224
226 private:
227
229 // Figure out which widget is the label and which are the buttons after copying or loading
231 void identifyLabelAndButtons();
232
233
235 public:
236
237 SignalString onButtonPress = {"ButtonPressed"};
238
239
241 protected:
242
243 std::string m_loadedThemeFile;
244 std::string m_buttonClassName;
245
246 std::vector<Button::Ptr> m_buttons;
247
248 Label::Ptr m_label = Label::create();
249 };
250
252}
253
255
256#endif // TGUI_MESSAGE_BOX_HPP
Child window widget.
Definition: ChildWindow.hpp:44
std::shared_ptr< Label > Ptr
Shared widget pointer.
Definition: Label.hpp:47
static Label::Ptr create(sf::String text="")
Creates a new label widget.
Definition: MessageBoxRenderer.hpp:37
Message box widget.
Definition: MessageBox.hpp:45
void load(const std::unique_ptr< DataIO::Node > &node, const LoadingRenderersMap &renderers) override
Loads the widget from a tree of nodes.
std::vector< sf::String > getButtons() const
Returns the caption of the buttons.
const sf::String & getText() const
Returns the text of the message box.
void setTextSize(unsigned int size) override
Changes the character size of the text.
Signal & getSignal(std::string signalName) override
Retrieves a signal based on its name.
std::unique_ptr< DataIO::Node > save(SavingRenderersMap &renderers) const override
Saves the widget as a tree node in order to save it to a file.
MessageBox(MessageBox &&copy)
Move constructor.
MessageBox(const MessageBox &copy)
Copy constructor.
void setText(const sf::String &text)
Changes the text of the message box.
MessageBoxRenderer * getRenderer()
Returns the renderer, which gives access to functions that determine how the widget is displayed.
static MessageBox::Ptr create(sf::String title="", sf::String text="", std::vector< sf::String > buttons={})
Creates a new message box widget.
MessageBoxRenderer * getSharedRenderer()
Returns the renderer, which gives access to functions that determine how the widget is displayed.
std::shared_ptr< MessageBox > Ptr
Shared widget pointer.
Definition: MessageBox.hpp:48
std::shared_ptr< const MessageBox > ConstPtr
Shared constant widget pointer.
Definition: MessageBox.hpp:49
Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
Definition: MessageBox.hpp:219
void addButton(const sf::String &buttonCaption)
Adds a button to the message box.
static MessageBox::Ptr copy(MessageBox::ConstPtr messageBox)
Makes a copy of another message box.
void rendererChanged(const std::string &property) override
Function called when one of the properties of the renderer is changed.
Signal to which the user can subscribe to get callbacks from.
Definition: Signal.hpp:231
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:77
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:37