TGUI  0.8-dev
ChildWindow.hpp
1 //
3 // TGUI - Texus' 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_CHILD_WINDOW_HPP
27 #define TGUI_CHILD_WINDOW_HPP
28 
29 
30 #include <TGUI/Container.hpp>
31 #include <TGUI/Widgets/Button.hpp>
32 #include <TGUI/Renderers/ChildWindowRenderer.hpp>
33 #include <limits>
34 
36 
37 namespace tgui
38 {
42  class TGUI_API ChildWindow : public Container
43  {
44  public:
45 
46  typedef std::shared_ptr<ChildWindow> Ptr;
47  typedef std::shared_ptr<const ChildWindow> ConstPtr;
48 
49 
51  enum class TitleAlignment
52  {
53  Left,
54  Center,
55  Right
56  };
57 
58 
61  {
62  None = 0,
63  Close = 1 << 0,
64  Maximize = 1 << 1,
65  Minimize = 1 << 2
66  };
67 
69  // Default constructor
71  ChildWindow(const sf::String& title = "", unsigned int titleButtons = TitleButton::Close);
72 
73 
80  static ChildWindow::Ptr create(const sf::String& title = "", unsigned int titleButtons = TitleButton::Close);
81 
82 
91  static ChildWindow::Ptr copy(ChildWindow::ConstPtr childWindow);
92 
93 
98  ChildWindowRenderer* getSharedRenderer();
99  const ChildWindowRenderer* getSharedRenderer() const;
100 
106  ChildWindowRenderer* getRenderer();
107  const ChildWindowRenderer* getRenderer() const;
108 
109 
122  void setPosition(const Layout2d& position) override;
123  using Widget::setPosition;
124 
125 
134  void setSize(const Layout2d& size) override;
135  using Widget::setSize;
136 
137 
146  sf::Vector2f getFullSize() const override;
147 
148 
158  void setMaximumSize(sf::Vector2f size);
159 
160 
169  sf::Vector2f getMaximumSize() const;
170 
171 
181  void setMinimumSize(sf::Vector2f size);
182 
183 
192  sf::Vector2f getMinimumSize() const;
193 
194 
201  void setTitle(const sf::String& title);
202 
203 
210  const sf::String& getTitle() const;
211 
212 
219  void setTitleAlignment(TitleAlignment alignment);
220 
221 
228  TitleAlignment getTitleAlignment() const;
229 
230 
243  void setTitleButtons(unsigned int buttons);
244 
245 
252  unsigned int getTitleButtons() const;
253 
254 
264  void destroy();
265 
266 
273  void setResizable(bool resizable = true);
274 
275 
282  bool isResizable() const;
283 
284 
294  void keepInParent(bool enabled = true);
295 
296 
306  bool isKeptInParent() const;
307 
308 
316  sf::Vector2f getChildWidgetsOffset() const override;
317 
318 
324  void setParent(Container* parent) override;
325 
326 
333  bool mouseOnWidget(sf::Vector2f pos) const override;
334 
338  void leftMousePressed(sf::Vector2f pos) override;
339 
343  void leftMouseReleased(sf::Vector2f pos) override;
344 
348  void mouseMoved(sf::Vector2f pos) override;
349 
353  void mouseNoLongerOnWidget() override;
354 
358  void mouseNoLongerDown() override;
359 
360 
368  void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
369 
370 
372  protected:
373 
375  // Updates the title bar texture, text and buttons after the title bar height has changed.
377  void updateTitleBarHeight();
378 
379 
389  Signal& getSignal(std::string signalName) override;
390 
391 
398  void rendererChanged(const std::string& property) override;
399 
400 
402  // Makes a copy of the widget
404  Widget::Ptr clone() const override
405  {
406  return std::make_shared<ChildWindow>(*this);
407  }
408 
409 
411  public:
412 
413  Signal onMousePress = {"MousePressed"};
414  SignalChildWindow onClose = {"Closed"};
415  SignalChildWindow onMinimize = {"Minimized"};
416  SignalChildWindow onMaximize = {"Maximized"};
417 
418 
420  protected:
421 
422  enum ResizeDirection
423  {
424  ResizeNone = 0,
425  ResizeLeft = 1,
426  ResizeTop = 2,
427  ResizeRight = 4,
428  ResizeBottom = 8
429  };
430 
431 
433  protected:
434 
435  Text m_titleText;
436  sf::Vector2f m_draggingPosition;
437  sf::Vector2f m_maximumSize = {std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity()};
438  sf::Vector2f m_minimumSize = {0, 0};
439  TitleAlignment m_titleAlignment = TitleAlignment::Center;
440  unsigned int m_titleButtons = TitleButton::Close;
441 
442  Button::Ptr m_closeButton;
443  Button::Ptr m_minimizeButton;
444  Button::Ptr m_maximizeButton;
445 
446  bool m_mouseDownOnTitleBar = false;
447  bool m_keepInParent = false;
448 
449  bool m_resizable = false;
450  int m_resizeDirection = ResizeNone;
451 
452  Sprite m_spriteTitleBar;
453 
454  // Cached renderer properties
455  Borders m_bordersCached;
456  Color m_borderColorCached;
457  Color m_titleColorCached;
458  Color m_titleBarColorCached;
459  Color m_backgroundColorCached;
460  float m_titleBarHeightCached = 20;
461  float m_distanceToSideCached = 0;
462  float m_paddingBetweenButtonsCached = 0;
463 
465  };
466 
468 }
469 
471 
472 #endif // TGUI_CHILD_WINDOW_HPP
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
Definition: Sprite.hpp:40
Widget::Ptr clone() const override
Makes a copy of the widget if you don&#39;t know its exact type.
Definition: ChildWindow.hpp:404
Wrapper for colors.
Definition: Color.hpp:46
Child window widget.
Definition: ChildWindow.hpp:42
Class to store the position or size of a widget.
Definition: Layout.hpp:243
virtual void setPosition(const Layout2d &position)
sets the position of the widget
Definition: Text.hpp:41
TitleButton
Title buttons (use bitwise OR to combine)
Definition: ChildWindow.hpp:60
virtual void setSize(const Layout2d &size)
Changes the size of the widget.
std::shared_ptr< ChildWindow > Ptr
Shared widget pointer.
Definition: ChildWindow.hpp:46
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:66
Container widget.
Definition: Container.hpp:47
Signal to which the user can subscribe to get callbacks from.
Definition: Signal.hpp:59
Signal to which the user can subscribe to get callbacks from.
Definition: Signal.hpp:333
Definition: Outline.hpp:38
Definition: ChildWindowRenderer.hpp:36
std::shared_ptr< const ChildWindow > ConstPtr
Shared constant widget pointer.
Definition: ChildWindow.hpp:47
std::shared_ptr< Button > Ptr
Shared widget pointer.
Definition: Button.hpp:45
TitleAlignment
Title alignments, possible options for the setTitleAlignment function.
Definition: ChildWindow.hpp:51