TGUI  0.7.4
MessageBox.hpp
1 //
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_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 
35 
36 namespace tgui
37 {
38  class MessageBoxRenderer;
39 
51  class TGUI_API MessageBox : public ChildWindow
52  {
53  public:
54 
55  typedef std::shared_ptr<MessageBox> Ptr;
56  typedef std::shared_ptr<const MessageBox> ConstPtr;
57 
58 
60  // Default constructor
62  MessageBox();
63 
64 
71  MessageBox(const MessageBox& copy);
72 
73 
82  MessageBox& operator= (const MessageBox& right);
83 
84 
91  static MessageBox::Ptr create();
92 
93 
102  static MessageBox::Ptr copy(MessageBox::ConstPtr messageBox);
103 
104 
111  std::shared_ptr<MessageBoxRenderer> getRenderer() const
112  {
113  return std::static_pointer_cast<MessageBoxRenderer>(m_renderer);
114  }
115 
116 
125  virtual void setFont(const Font& font) override;
126 
127 
137  void setText(const sf::String& text);
138 
139 
146  sf::String getText() const
147  {
148  return m_label->getText();
149  }
150 
151 
160  void setTextSize(unsigned int size);
161 
162 
169  unsigned int getTextSize() const
170  {
171  return m_textSize;
172  }
173 
174 
184  void addButton(const sf::String& buttonCaption);
185 
186 
188  protected:
189 
191  // Makes sure all widgets lie within the window and places them on the correct position.
193  void rearrange();
194 
195 
208  virtual void reload(const std::string& primary = "", const std::string& secondary = "", bool force = false) override;
209 
210 
212  // Makes a copy of the widget
214  virtual Widget::Ptr clone() const override
215  {
216  return std::make_shared<MessageBox>(*this);
217  }
218 
219 
221  protected:
222 
223  std::string m_loadedThemeFile;
224  std::string m_buttonClassName;
225 
226  std::vector<Button::Ptr> m_buttons;
227 
228  Label::Ptr m_label = std::make_shared<Label>();
229 
230  unsigned int m_textSize = 16;
231 
232  friend class MessageBoxRenderer;
233  };
234 
235 
237 
238  class TGUI_API MessageBoxRenderer : public ChildWindowRenderer
239  {
240  public:
241 
248  MessageBoxRenderer(MessageBox* messageBox) : ChildWindowRenderer{messageBox}, m_messageBox{messageBox} {}
249 
250 
261  virtual void setProperty(std::string property, const std::string& value) override;
262 
263 
275  virtual void setProperty(std::string property, ObjectConverter&& value) override;
276 
277 
287  virtual ObjectConverter getProperty(std::string property) const override;
288 
289 
296  virtual std::map<std::string, ObjectConverter> getPropertyValuePairs() const override;
297 
298 
305  void setTextColor(const Color& color);
306 
307 
309  private:
310 
312  // Makes a copy of the renderer
314  virtual std::shared_ptr<WidgetRenderer> clone(Widget* widget) override;
315 
316 
318  protected:
319 
320  MessageBox* m_messageBox;
321 
322  friend class MessageBox;
323 
325  };
326 
328 }
329 
331 
332 #endif // TGUI_MESSAGE_BOX_HPP
333 
Namespace that contains all TGUI functions and classes.
Definition: Animation.hpp:33
Definition: MessageBox.hpp:238
Implicit converter for colors.
Definition: Color.hpp:39
Child window widget.
Definition: ChildWindow.hpp:60
virtual Widget::Ptr clone() const override
Makes a copy of the widget if you don&#39;t know its exact type.
Definition: MessageBox.hpp:214
std::shared_ptr< const MessageBox > ConstPtr
Shared constant widget pointer.
Definition: MessageBox.hpp:56
Definition: Font.hpp:37
The parent class for every widget.
Definition: Widget.hpp:71
std::shared_ptr< Label > Ptr
Shared widget pointer.
Definition: Label.hpp:53
sf::String getText() const
Return the text of the message box.
Definition: MessageBox.hpp:146
unsigned int getTextSize() const
Returns the size of the text.
Definition: MessageBox.hpp:169
Implicit converter for settable properties.
Definition: ObjectConverter.hpp:42
std::shared_ptr< MessageBoxRenderer > getRenderer() const
Returns the renderer, which gives access to functions that determine how the widget is displayed...
Definition: MessageBox.hpp:111
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:75
MessageBoxRenderer(MessageBox *messageBox)
Constructor.
Definition: MessageBox.hpp:248
std::shared_ptr< MessageBox > Ptr
Shared widget pointer.
Definition: MessageBox.hpp:55
Definition: ChildWindow.hpp:586
Message box widget.
Definition: MessageBox.hpp:51