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 {
59  class TGUI_API ChildWindow : public Container
60  {
61  public:
62 
63  typedef std::shared_ptr<ChildWindow> Ptr;
64  typedef std::shared_ptr<const ChildWindow> ConstPtr;
65 
66 
68  enum class TitleAlignment
69  {
70  Left,
71  Center,
72  Right
73  };
74 
75 
78  {
79  None = 0,
80  Close = 1 << 0,
81  Maximize = 1 << 1,
82  Minimize = 1 << 2
83  };
84 
86  // Default constructor
88  ChildWindow();
89 
90 
97  static ChildWindow::Ptr create();
98 
99 
108  static ChildWindow::Ptr copy(ChildWindow::ConstPtr childWindow);
109 
110 
118  {
119  return aurora::downcast<ChildWindowRenderer*>(m_renderer.get());
120  }
121 
122 
135  void setPosition(const Layout2d& position) override;
137 
138 
147  void setSize(const Layout2d& size) override;
149 
150 
159  virtual sf::Vector2f getFullSize() const override;
160 
161 
171  void setMaximumSize(sf::Vector2f size);
172 
173 
182  sf::Vector2f getMaximumSize() const;
183 
184 
194  void setMinimumSize(sf::Vector2f size);
195 
196 
205  sf::Vector2f getMinimumSize() const;
206 
207 
214  void setTitle(const sf::String& title);
215 
216 
223  const sf::String& getTitle() const;
224 
225 
232  void setTitleAlignment(TitleAlignment alignment);
233 
234 
241  TitleAlignment getTitleAlignment() const;
242 
243 
256  void setTitleButtons(unsigned int buttons);
257 
258 
265  unsigned int getTitleButtons() const;
266 
267 
277  void destroy();
278 
279 
286  void setResizable(bool resizable = true);
287 
288 
295  bool isResizable() const;
296 
297 
307  void keepInParent(bool enabled = true);
308 
309 
319  bool isKeptInParent() const;
320 
321 
329  virtual sf::Vector2f getChildWidgetsOffset() const override;
330 
331 
335  virtual bool mouseOnWidget(sf::Vector2f pos) const override;
336 
340  virtual void leftMousePressed(sf::Vector2f pos) override;
341 
345  virtual void leftMouseReleased(sf::Vector2f pos) override;
346 
350  virtual void mouseMoved(sf::Vector2f pos) override;
351 
355  virtual void mouseWheelScrolled(float delta, int x, int y) override;
356 
360  virtual void mouseNoLongerOnWidget() override;
361 
365  virtual void mouseNoLongerDown() override;
366 
367 
375  virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
376 
377 
379  protected:
380 
382  // Updates the title bar texture, text and buttons after the title bar height has changed.
384  void updateTitleBarHeight();
385 
386 
393  virtual void rendererChanged(const std::string& property) override;
394 
395 
397  // Makes a copy of the widget
399  virtual Widget::Ptr clone() const override
400  {
401  return std::make_shared<ChildWindow>(*this);
402  }
403 
404 
406  private:
407 
409  // Signal handler from the title buttons. This function propagates the signal to the user if needed.
411  void titleButtonPressed(const sf::String& signal);
412 
413 
415  protected:
416 
417  enum ResizeDirection
418  {
419  ResizeNone = 0,
420  ResizeLeft = 1,
421  ResizeTop = 2,
422  ResizeRight = 4,
423  ResizeBottom = 8
424  };
425 
427  protected:
428 
429  Text m_titleText;
430  sf::Vector2f m_draggingPosition;
431  sf::Vector2f m_maximumSize = {std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity()};
432  sf::Vector2f m_minimumSize = {0, 0};
433  TitleAlignment m_titleAlignment = TitleAlignment::Center;
434  unsigned int m_titleButtons = TitleButton::Close;
435 
436  std::shared_ptr<Button> m_closeButton;
437  std::shared_ptr<Button> m_minimizeButton;
438  std::shared_ptr<Button> m_maximizeButton;
439 
440  bool m_mouseDownOnTitleBar = false;
441  bool m_keepInParent = false;
442 
443  bool m_resizable = false;
444  int m_resizeDirection = ResizeNone;
445 
446  Sprite m_spriteTitleBar;
447 
448  // Cached renderer properties
449  Borders m_bordersCached;
450  Color m_borderColorCached;
451  Color m_titleColorCached;
452  Color m_titleBarColorCached;
453  Color m_backgroundColorCached;
454  float m_titleBarHeightCached = 20;
455  float m_distanceToSideCached = 0;
456  float m_paddingBetweenButtonsCached = 0;
457 
459  };
460 
462 }
463 
465 
466 #endif // TGUI_CHILD_WINDOW_HPP
Namespace that contains all TGUI functions and classes.
Definition: Animation.hpp:33
Definition: Sprite.hpp:40
Wrapper for colors.
Definition: Color.hpp:46
Child window widget.
Definition: ChildWindow.hpp:59
Class to store the position or size of a widget.
Definition: Layout.hpp:263
virtual Widget::Ptr clone() const override
Makes a copy of the widget if you don&#39;t know its exact type.
Definition: ChildWindow.hpp:399
virtual void setSize(const Layout2d &size)
Changes the size of the widget.
Definition: Text.hpp:41
virtual void setPosition(const Layout2d &position)
Sets the position of the widget.
TitleButton
Title buttons (use bitwise OR to combine)
Definition: ChildWindow.hpp:77
std::shared_ptr< ChildWindow > Ptr
Shared widget pointer.
Definition: ChildWindow.hpp:63
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:76
Container widget.
Definition: Container.hpp:47
ChildWindowRenderer * getRenderer() const
Returns the renderer, which gives access to functions that determine how the widget is displayed...
Definition: ChildWindow.hpp:117
Definition: Outline.hpp:37
Definition: ChildWindowRenderer.hpp:36
std::shared_ptr< const ChildWindow > ConstPtr
Shared constant widget pointer.
Definition: ChildWindow.hpp:64
TitleAlignment
Title alignments, possible options for the setTitleAlignment function.
Definition: ChildWindow.hpp:68