TGUI  0.7.8
ChildWindow.hpp
1
2//
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
36namespace 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
90
91
99
100
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
257
258
266 {
267 return m_titleAlignment;
268 }
269
270
282 void setTitleButtons(unsigned int buttons);
283
284
291 unsigned int getTitleButtons() const
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
407
408
421 void setMinimizeButton(Button::Ptr minimizeButton);
422
423
433
434
447 void setMaximizeButton(Button::Ptr maximizeButton);
448
449
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 unsigned int 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
Definition: Borders.hpp:38
std::shared_ptr< Button > Ptr
Shared widget pointer.
Definition: Button.hpp:54
Definition: ChildWindow.hpp:587
std::shared_ptr< ButtonRenderer > getCloseButton() const
Returns the renderer of the close button.
void setPaddingBetweenButtons(float paddingBetweenButtons)
Changes the distance between the title buttons if multiple exist.
std::shared_ptr< ButtonRenderer > getMaximizeButton() const
Returns the renderer of the maximize button.
virtual ObjectConverter getProperty(std::string property) const override
Retrieve the value of a certain property.
virtual std::map< std::string, ObjectConverter > getPropertyValuePairs() const override
Get a map with all properties and their values.
void setTitleBarHeight(float height)
Change the height of the title bar.
void setTitleBarTexture(const Texture &texture)
Change the image of the title bar.
void setTitleColor(const Color &color)
Changes the color of the title that is displayed in the title bar of the child window.
std::shared_ptr< ButtonRenderer > getMinimizeButton() const
Returns the renderer of the minimize button.
void setTitleBarColor(const Color &color)
Changes the color of the title bar.
virtual void setBorders(const Borders &borders) override
Changes the size of the borders.
void setBorderColor(const Color &borderColor)
Set the border color.
ChildWindowRenderer(ChildWindow *childWindow)
Constructor.
Definition: ChildWindow.hpp:596
void setBackgroundColor(const Color &backgroundColor)
Changes the background color of the child window.
virtual void setProperty(std::string property, ObjectConverter &&value) override
Change a property of the renderer.
virtual void setProperty(std::string property, const std::string &value) override
Change a property of the renderer.
void setDistanceToSide(float distanceToSide)
Changes the distance between the title and the side of the title bar.
Child window widget.
Definition: ChildWindow.hpp:61
virtual void setFont(const Font &font) override
Changes the font of the text in the widget and its children.
void setMinimumSize(sf::Vector2f size)
Sets the minimum size of the child window.
TitleAlignment
Title alignments, possible options for the setTitleAlignment function.
Definition: ChildWindow.hpp:70
virtual void reload(const std::string &primary="", const std::string &secondary="", bool force=false) override
Reload the widget.
void setMaximumSize(sf::Vector2f size)
Sets the maximum size of the child window.
const sf::String & getTitle() const
Returns the title that is displayed in the title bar of the child window.
Definition: ChildWindow.hpp:244
virtual sf::Vector2f getChildWidgetsOffset() const override
Returns the distance between the position of the container and a widget that would be drawn inside th...
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
virtual Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
Definition: ChildWindow.hpp:528
void keepInParent(bool enabled=true)
Set the child window to be kept inside its parent.
void setPosition(const Layout2d &position) override
Set the position of the widget.
virtual void setOpacity(float opacity) override
Changes the opacity of the widget.
std::shared_ptr< ChildWindow > Ptr
Shared widget pointer.
Definition: ChildWindow.hpp:64
void setTitleButtons(unsigned int buttons)
Changes the title buttons.
void setTitleAlignment(TitleAlignment alignment)
Changes the title alignment.
sf::Vector2f getMaximumSize() const
Returns the maximum size of the child window.
TitleAlignment getTitleAlignment() const
Returns the title alignment.
Definition: ChildWindow.hpp:265
void setTitle(const sf::String &title)
Changes the title that is displayed in the title bar of the child window.
void setCloseButton(Button::Ptr closeButton)
Change the close button.
void destroy()
Destroys the window.
void setTitleButtonsText(const sf::String &closeText="x", const sf::String &minimizeText="-", const sf::String &maximizeText="+")
Changes the text within the title bar buttons.
void setIcon(const Texture &icon)
Changes the icon in the top left corner of the child window.
Button::Ptr getMinimizeButton() const
Returns the minimize button.
void setMaximizeButton(Button::Ptr maximizeButton)
Change the maximize button.
const Texture & getIcon()
Returns the icon in the top left corner of the child window.
static ChildWindow::Ptr create()
Creates a new child window widget.
Button::Ptr getCloseButton() const
Returns the close button.
std::shared_ptr< const ChildWindow > ConstPtr
Shared constant widget pointer.
Definition: ChildWindow.hpp:65
void setMinimizeButton(Button::Ptr minimizeButton)
Change the minimize button.
TitleButtons
Title buttons (bitwise OR to combine)
Definition: ChildWindow.hpp:79
sf::Vector2f getMinimumSize() const
Returns the minimum size of the child window.
unsigned int getTitleButtons() const
Returns the title bar buttons.
Definition: ChildWindow.hpp:291
bool isKeptInParent() const
Tells whether the child window is kept inside its parent.
Button::Ptr getMaximizeButton() const
Returns the maximize button.
void setResizable(bool resizable=true)
Changes whether the child window can be resized by dragging its borders or not.
bool isResizable() const
Check whether the child window can be resized by dragging its borders or not.
void setSize(const Layout2d &size) override
Changes the size of the child window.
static ChildWindow::Ptr copy(ChildWindow::ConstPtr childWindow)
Makes a copy of another child window.
virtual sf::Vector2f getFullSize() const override
Returns the size of the full child window.
Implicit converter for colors.
Definition: Color.hpp:40
Container widget.
Definition: Container.hpp:48
Definition: Font.hpp:38
Class to store the position or size of a widget.
Definition: Layout.hpp:255
Implicit converter for settable properties.
Definition: ObjectConverter.hpp:43
Definition: Texture.hpp:45
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:137
virtual void setBorders(const Borders &borders)
Changes the size of the borders.
Definition: Borders.hpp:149
Base class for all renderer classes.
Definition: Widget.hpp:683
The parent class for every widget.
Definition: Widget.hpp:72
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:75
Namespace that contains all TGUI functions and classes.
Definition: Animation.hpp:34