TGUI  v0.7.5
ChildWindow.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_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/Widgets/Label.hpp>
33 
35 
36 namespace tgui
37 {
38  class ChildWindowRenderer;
39 
60  class TGUI_API ChildWindow : public Container
61  {
62  public:
63 
64  typedef std::shared_ptr<ChildWindow> Ptr;
65  typedef std::shared_ptr<const ChildWindow> ConstPtr;
66 
67 
69  enum class TitleAlignment
70  {
71  Left,
72  Center,
73  Right
74  };
75 
76 
79  {
80  None = 0,
81  Close = 1 << 0,
82  Minimize = 1 << 1,
83  Maximize = 1 << 2
84  };
85 
87  // Default constructor
89  ChildWindow();
90 
91 
98  static ChildWindow::Ptr create();
99 
100 
109  static ChildWindow::Ptr copy(ChildWindow::ConstPtr childWindow);
110 
111 
118  std::shared_ptr<ChildWindowRenderer> getRenderer() const
119  {
120  return std::static_pointer_cast<ChildWindowRenderer>(m_renderer);
121  }
122 
123 
136  void setPosition(const Layout2d& position) override;
138 
139 
148  void setSize(const Layout2d& size) override;
150 
151 
160  virtual sf::Vector2f getFullSize() const override;
161 
162 
172  void setMaximumSize(sf::Vector2f size);
173 
174 
183  sf::Vector2f getMaximumSize() const;
184 
185 
195  void setMinimumSize(sf::Vector2f size);
196 
197 
206  sf::Vector2f getMinimumSize() const;
207 
208 
217  virtual void setFont(const Font& font) override;
218 
219 
226  virtual void setOpacity(float opacity) override;
227 
228 
235  void setTitle(const sf::String& title);
236 
237 
244  const sf::String& getTitle() const
245  {
246  return m_titleText.getText();
247  }
248 
249 
256  void setTitleAlignment(TitleAlignment alignment);
257 
258 
266  {
267  return m_titleAlignment;
268  }
269 
270 
282  void setTitleButtons(TitleButtons buttons);
283 
284 
292  {
293  return m_titleButtons;
294  }
295 
296 
305  void setTitleButtonsText(const sf::String& closeText = "x", const sf::String& minimizeText = "-", const sf::String& maximizeText = "+");
306 
307 
317  void setIcon(const Texture& icon);
318 
319 
326  const Texture& getIcon();
327 
328 
338  void destroy();
339 
340 
347  void setResizable(bool resizable = true);
348 
349 
356  bool isResizable() const;
357 
358 
368  void keepInParent(bool enabled = true);
369 
370 
380  bool isKeptInParent() const;
381 
382 
395  void setCloseButton(Button::Ptr closeButton);
396 
397 
406  Button::Ptr getCloseButton() const;
407 
408 
421  void setMinimizeButton(Button::Ptr minimizeButton);
422 
423 
432  Button::Ptr getMinimizeButton() const;
433 
434 
447  void setMaximizeButton(Button::Ptr maximizeButton);
448 
449 
458  Button::Ptr getMaximizeButton() const;
459 
460 
468  virtual sf::Vector2f getChildWidgetsOffset() const override;
469 
470 
474  virtual bool mouseOnWidget(float x, float y) const override;
475 
479  virtual void leftMousePressed(float x, float y) override;
480 
484  virtual void leftMouseReleased(float x, float y) override;
485 
489  virtual void mouseMoved(float x, float y) override;
490 
494  virtual void mouseWheelMoved(int delta, int x, int y) override;
495 
499  virtual void mouseNoLongerOnWidget() override;
500 
504  virtual void mouseNoLongerDown() override;
505 
506 
508  protected:
509 
522  virtual void reload(const std::string& primary = "", const std::string& secondary = "", bool force = false) override;
523 
524 
526  // Makes a copy of the widget
528  virtual Widget::Ptr clone() const override
529  {
530  return std::make_shared<ChildWindow>(*this);
531  }
532 
533 
536  // Draws the widget on the render target.
538  virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
539 
540 
542  protected:
543 
544  enum ResizeDirection
545  {
546  ResizeNone = 0,
547  ResizeLeft = 1,
548  ResizeTop = 2,
549  ResizeRight = 4,
550  ResizeBottom = 8
551  };
552 
554  protected:
555 
556  Texture m_iconTexture;
557 
558  Label m_titleText;
559  sf::Vector2f m_draggingPosition;
560  sf::Vector2f m_maximumSize;
561  sf::Vector2f m_minimumSize;
562  TitleAlignment m_titleAlignment = TitleAlignment::Center;
563  TitleButtons m_titleButtons = TitleButtons::Close;
564  sf::String m_closeButtonText = "x";
565  sf::String m_minimizeButtonText = "-";
566  sf::String m_maximizeButtonText = "+";
567 
568  std::shared_ptr<Button> m_closeButton = std::make_shared<Button>();
569  std::shared_ptr<Button> m_minimizeButton = std::make_shared<Button>();
570  std::shared_ptr<Button> m_maximizeButton = std::make_shared<Button>();
571 
572  bool m_mouseDownOnTitleBar = false;
573  bool m_keepInParent = false;
574 
575  bool m_resizable = false;
576  int m_resizeDirection = ResizeNone;
577 
578  friend class ChildWindowRenderer;
579 
581  };
582 
583 
585 
586  class TGUI_API ChildWindowRenderer : public WidgetRenderer, public WidgetBorders
587  {
588  public:
589 
596  ChildWindowRenderer(ChildWindow* childWindow) : m_childWindow{childWindow} {}
597 
598 
609  virtual void setProperty(std::string property, const std::string& value) override;
610 
611 
623  virtual void setProperty(std::string property, ObjectConverter&& value) override;
624 
625 
635  virtual ObjectConverter getProperty(std::string property) const override;
636 
637 
644  virtual std::map<std::string, ObjectConverter> getPropertyValuePairs() const override;
645 
646 
655  void setTitleBarColor(const Color& color);
656 
657 
664  void setTitleBarHeight(float height);
665 
666 
673  void setTitleColor(const Color& color);
674 
675 
682  void setBorderColor(const Color& borderColor);
683 
684 
691  virtual void setBorders(const Borders& borders) override;
693 
694 
701  void setDistanceToSide(float distanceToSide);
702 
709  void setPaddingBetweenButtons(float paddingBetweenButtons);
710 
717  void setBackgroundColor(const Color& backgroundColor);
718 
719 
729  void setTitleBarTexture(const Texture& texture);
730 
731 
738  std::shared_ptr<ButtonRenderer> getCloseButton() const;
739 
746  std::shared_ptr<ButtonRenderer> getMinimizeButton() const;
747 
754  std::shared_ptr<ButtonRenderer> getMaximizeButton() const;
755 
757  // Draws the widget on the render target.
759  void draw(sf::RenderTarget& target, sf::RenderStates states) const;
760 
761 
763  protected:
764 
766  // Makes a copy of the renderer
768  virtual std::shared_ptr<WidgetRenderer> clone(Widget* widget) override;
769 
770 
772  protected:
773 
774  ChildWindow* m_childWindow;
775 
776  float m_titleBarHeight = 0;
777  float m_distanceToSide = 0;
778  float m_paddingBetweenButtons = 3; // Pixels between buttons
779 
780  Texture m_textureTitleBar;
781 
782  sf::Color m_titleColor;
783  sf::Color m_titleBarColor;
784 
785  sf::Color m_backgroundColor;
786  sf::Color m_borderColor;
787 
788  sf::String m_closeButtonClassName = "";
789  sf::String m_minimizeButtonClassName = "";
790  sf::String m_maximizeButtonClassName = "";
791 
792  friend class ChildWindow;
793 
795  };
796 
798 }
799 
801 
802 #endif // TGUI_CHILD_WINDOW_HPP
Namespace that contains all TGUI functions and classes.
Definition: Animation.hpp:33
virtual void setBorders(const Borders &borders)
Changes the size of the borders.
Definition: Borders.hpp:149
Implicit converter for colors.
Definition: Color.hpp:39
Child window widget.
Definition: ChildWindow.hpp:60
Definition: Font.hpp:37
Class to store the position or size of a widget.
Definition: Layout.hpp:262
Label widget.
Definition: Label.hpp:49
The parent class for every widget.
Definition: Widget.hpp:71
virtual Widget::Ptr clone() const override
Makes a copy of the widget if you don&#39;t know its exact type.
Definition: ChildWindow.hpp:528
ChildWindowRenderer(ChildWindow *childWindow)
Constructor.
Definition: ChildWindow.hpp:596
TitleAlignment getTitleAlignment() const
Returns the title alignment.
Definition: ChildWindow.hpp:265
virtual void setSize(const Layout2d &size)
Changes the size of the widget.
virtual void setPosition(const Layout2d &position)
set the position of the widget
Parent class for every widget that has borders.
Definition: Borders.hpp:136
Implicit converter for settable properties.
Definition: ObjectConverter.hpp:42
const sf::String & getTitle() const
Returns the title that is displayed in the title bar of the child window.
Definition: ChildWindow.hpp:244
std::shared_ptr< ChildWindow > Ptr
Shared widget pointer.
Definition: ChildWindow.hpp:64
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:75
Container widget.
Definition: Container.hpp:47
Definition: Texture.hpp:44
Definition: Borders.hpp:37
Definition: ChildWindow.hpp:586
std::shared_ptr< const ChildWindow > ConstPtr
Shared constant widget pointer.
Definition: ChildWindow.hpp:65
TitleButtons
Title buttons (bitwise OR to combine)
Definition: ChildWindow.hpp:78
TitleButtons getTitleButtons() const
Returns the title bar buttons.
Definition: ChildWindow.hpp:291
std::shared_ptr< Button > Ptr
Shared widget pointer.
Definition: Button.hpp:54
TitleAlignment
Title alignments, possible options for the setTitleAlignment function.
Definition: ChildWindow.hpp:69
std::shared_ptr< ChildWindowRenderer > getRenderer() const
Returns the renderer, which gives access to functions that determine how the widget is displayed...
Definition: ChildWindow.hpp:118
Base class for all renderer classes.
Definition: Widget.hpp:682