TGUI  0.8.1
MessageBox.hpp
1 //
3 // TGUI - Texus' Graphical User Interface
4 // Copyright (C) 2012-2018 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 
39 namespace 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 
79  MessageBox(MessageBox&& copy);
80 
81 
85  MessageBox& operator= (const MessageBox& right);
86 
87 
91  MessageBox& operator= (MessageBox&& right);
92 
93 
102  static MessageBox::Ptr copy(MessageBox::ConstPtr messageBox);
103 
104 
109  MessageBoxRenderer* getSharedRenderer();
110  const MessageBoxRenderer* getSharedRenderer() const;
111 
117  MessageBoxRenderer* getRenderer();
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);
151 
152 
159  unsigned int getTextSize() const;
160 
161 
171  void addButton(const sf::String& buttonCaption);
172 
173 
180  std::vector<sf::String> getButtons() const;
181 
182 
184  protected:
185 
187  // Makes sure all widgets lie within the window and places them on the correct position.
189  void rearrange();
190 
191 
201  Signal& getSignal(std::string signalName) override;
202 
203 
210  void rendererChanged(const std::string& property) override;
211 
212 
216  std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
217 
218 
222  void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
223 
224 
226  // Makes a copy of the widget
228  Widget::Ptr clone() const override
229  {
230  return std::make_shared<MessageBox>(*this);
231  }
232 
233 
235  private:
236 
238  // Figure out which widget is the label and which are the buttons after copying or loading
240  void identifyLabelAndButtons();
241 
242 
244  public:
245 
246  SignalString onButtonPress = {"ButtonPressed"};
247 
248 
250  protected:
251 
252  std::string m_loadedThemeFile;
253  std::string m_buttonClassName;
254 
255  std::vector<Button::Ptr> m_buttons;
256 
257  Label::Ptr m_label = Label::create();
258 
259  unsigned int m_textSize = 16;
260  };
261 
263 }
264 
266 
267 #endif // TGUI_MESSAGE_BOX_HPP
268 
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
Definition: MessageBoxRenderer.hpp:36
static Label::Ptr create(sf::String text="")
Creates a new label widget.
Child window widget.
Definition: ChildWindow.hpp:43
Widget::Ptr clone() const override
Makes a copy of the widget if you don&#39;t know its exact type.
Definition: MessageBox.hpp:228
std::shared_ptr< const MessageBox > ConstPtr
Shared constant widget pointer.
Definition: MessageBox.hpp:49
std::shared_ptr< Label > Ptr
Shared widget pointer.
Definition: Label.hpp:45
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:76
Signal to which the user can subscribe to get callbacks from.
Definition: Signal.hpp:59
std::shared_ptr< MessageBox > Ptr
Shared widget pointer.
Definition: MessageBox.hpp:48
Message box widget.
Definition: MessageBox.hpp:44