--- --- TGUI: include/TGUI/Widgets/ChildWindow.hpp Source File
TGUI  1.x-dev
Loading...
Searching...
No Matches
ChildWindow.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2024 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#ifndef TGUI_CHILD_WINDOW_HPP
26#define TGUI_CHILD_WINDOW_HPP
27
28#include <TGUI/CopiedSharedPtr.hpp>
29#include <TGUI/Container.hpp>
30#include <TGUI/Widgets/Button.hpp>
31#include <TGUI/Renderers/ChildWindowRenderer.hpp>
32
33#if !TGUI_EXPERIMENTAL_USE_STD_MODULE
34 #include <limits>
35#endif
36
38
39TGUI_MODULE_EXPORT namespace tgui
40{
44 class TGUI_API ChildWindow : public Container
45 {
46 public:
47
48 using Ptr = std::shared_ptr<ChildWindow>;
49 using ConstPtr = std::shared_ptr<const ChildWindow>;
50
51 static constexpr const char StaticWidgetType[] = "ChildWindow";
52
54 using TitleAlignment TGUI_DEPRECATED("Use tgui::HorizontalAlignment instead") = HorizontalAlignment;
55
57 enum TitleButton : unsigned int
58 {
59 None = 0,
60 Close = 1 << 0,
61 Maximize = 1 << 1,
62 Minimize = 1 << 2
63 };
64
72 ChildWindow(const char* typeName = StaticWidgetType, bool initRenderer = true);
73
78
83
87 ChildWindow& operator= (const ChildWindow&);
88
92 ChildWindow& operator= (ChildWindow&&) noexcept;
93
100 TGUI_NODISCARD static ChildWindow::Ptr create(const String& title = "", unsigned int titleButtons = TitleButton::Close);
101
110 TGUI_NODISCARD static ChildWindow::Ptr copy(const ChildWindow::ConstPtr& childWindow);
111
116 TGUI_NODISCARD ChildWindowRenderer* getSharedRenderer() override;
117 TGUI_NODISCARD const ChildWindowRenderer* getSharedRenderer() const override;
118
124 TGUI_NODISCARD ChildWindowRenderer* getRenderer() override;
125
138 void setPosition(const Layout2d& position) override;
139 using Widget::setPosition;
140
149 void setSize(const Layout2d& size) override;
150 using Widget::setSize;
151
158 TGUI_NODISCARD Vector2f getInnerSize() const override;
159
167 virtual void setClientSize(const Layout2d& size);
168
176 TGUI_NODISCARD Vector2f getClientSize() const;
177
186 void setMaximumSize(Vector2f size);
187
195 TGUI_NODISCARD Vector2f getMaximumSize() const;
196
205 void setMinimumSize(Vector2f size);
206
214 TGUI_NODISCARD Vector2f getMinimumSize() const;
215
222 void setTitle(const String& title);
223
230 TGUI_NODISCARD const String& getTitle() const;
231
237 void setTitleTextSize(unsigned int size);
238
243 TGUI_NODISCARD unsigned int getTitleTextSize() const;
244
251 void setTitleAlignment(HorizontalAlignment alignment);
252
259 TGUI_NODISCARD HorizontalAlignment getTitleAlignment() const;
260
273 void setTitleButtons(unsigned int buttons);
274
281 TGUI_NODISCARD unsigned int getTitleButtons() const;
282
291 void close();
292
299 void destroy();
300
307 void setResizable(bool resizable = true);
308
315 TGUI_NODISCARD bool isResizable() const;
316
323 void setPositionLocked(bool positionLocked = true);
324
329 TGUI_NODISCARD bool isPositionLocked() const;
330
337 void setKeepInParent(bool enabled = true);
338
339#ifndef TGUI_REMOVE_DEPRECATED_CODE
346 TGUI_DEPRECATED("Use getKeepInParent instead") TGUI_NODISCARD bool isKeptInParent() const;
347#endif
348
357 TGUI_NODISCARD bool getKeepInParent() const;
358
366 TGUI_NODISCARD Vector2f getChildWidgetsOffset() const override;
367
373 void setParent(Container* parent) override;
374
381 TGUI_NODISCARD bool isMouseOnWidget(Vector2f pos) const override;
382
386 bool leftMousePressed(Vector2f pos) override;
387
391 void leftMouseReleased(Vector2f pos) override;
392
396 void rightMousePressed(Vector2f pos) override;
397
401 void rightMouseReleased(Vector2f pos) override;
402
406 void mouseMoved(Vector2f pos) override;
407
411 void keyPressed(const Event::KeyEvent& event) override;
412
422 bool canHandleKeyPress(const Event::KeyEvent& event) override;
423
427 void mouseNoLongerOnWidget() override;
428
432 void leftMouseButtonNoLongerDown() override;
433
441 void draw(BackendRenderTarget& target, RenderStates states) const override;
442
444 protected:
445
447 // Updates the title bar texture, text and buttons after the title bar height has changed.
449 void updateTitleBarHeight();
450
452 // Updates the mouse cursor for resizable child windows
454 void updateResizeMouseCursor(Vector2f mousePos);
455
465 TGUI_NODISCARD Signal& getSignal(String signalName) override;
466
473 void rendererChanged(const String& property) override;
474
478 TGUI_NODISCARD std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
479
483 void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
484
488 void mouseEnteredWidget() override;
489
493 void mouseLeftWidget() override;
494
496 // Makes a copy of the widget
498 TGUI_NODISCARD Widget::Ptr clone() const override;
499
501 private:
502
504 // Helper function to connect the title button callbacks from the various constuctors and assignment operators
506 void connectTitleButtonCallbacks();
507
509 public:
510
511 Signal onMousePress = {"MousePressed"};
512 SignalChildWindow onClose = {"Closed"};
513 SignalChildWindow onMinimize = {"Minimized"};
514 SignalChildWindow onMaximize = {"Maximized"};
515 SignalChildWindow onEscapeKeyPress = {"EscapeKeyPressed"};
516
521 SignalTyped<bool*> onClosing = {"Closing"};
522
524 protected:
525
526 enum ResizeDirection
527 {
528 ResizeNone = 0,
529 ResizeLeft = 1,
530 ResizeTop = 2,
531 ResizeRight = 4,
532 ResizeBottom = 8
533 };
534
536 protected:
537
538 Text m_titleText;
539 Vector2f m_draggingPosition;
540 Vector2f m_maximumSize = {std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity()};
541 Vector2f m_minimumSize = {0, 0};
542 Layout* m_decorationLayoutX = nullptr;
543 Layout* m_decorationLayoutY = nullptr;
544 HorizontalAlignment m_titleAlignment = HorizontalAlignment::Center;
545 unsigned int m_titleButtons = TitleButton::Close;
546 unsigned int m_titleTextSize = 0;
547 Cursor::Type m_currentChildWindowMouseCursor = Cursor::Type::Arrow;
548
549 CopiedSharedPtr<Button> m_closeButton;
550 CopiedSharedPtr<Button> m_minimizeButton;
551 CopiedSharedPtr<Button> m_maximizeButton;
552
553 bool m_mouseDownOnTitleBar = false;
554 bool m_keepInParent = false;
555
556 bool m_positionLocked = false;
557 bool m_resizable = false;
558 int m_resizeDirection = ResizeNone;
559
560 Sprite m_spriteTitleBar;
561 Sprite m_spriteBackground;
562
563 // Cached renderer properties
564 Borders m_bordersCached;
565 Color m_borderColorCached;
566 Color m_borderColorFocusedCached;
567 Color m_titleColorCached;
568 Color m_titleBarColorCached;
569 Color m_backgroundColorCached;
570 float m_titleBarHeightCached = 20;
571 float m_borderBelowTitleBarCached = 0;
572 float m_distanceToSideCached = 0;
573 float m_paddingBetweenButtonsCached = 0;
574 float m_minimumResizableBorderWidthCached = 10;
575 bool m_showTextOnTitleButtonsCached = false;
576
578 };
579
581}
582
584
585#endif // TGUI_CHILD_WINDOW_HPP
Base class for render targets.
Definition BackendRenderTarget.hpp:48
Child window widget.
Definition ChildWindow.hpp:45
TGUI_NODISCARD std::unique_ptr< DataIO::Node > save(SavingRenderersMap &renderers) const override
Saves the widget as a tree node in order to save it to a file.
ChildWindow(const ChildWindow &)
Copy constructor.
std::shared_ptr< ChildWindow > Ptr
Shared widget pointer.
Definition ChildWindow.hpp:48
void rendererChanged(const String &property) override
Function called when one of the properties of the renderer is changed.
void draw(BackendRenderTarget &target, RenderStates states) const override
Draw the widget to a render target.
void mouseLeftWidget() override
This function is called when the mouse leaves the widget.
TGUI_NODISCARD Vector2f getChildWidgetsOffset() const override
Returns the distance between the position of the container and a widget that would be drawn inside th...
TitleButton
Title buttons (use bitwise OR to combine)
Definition ChildWindow.hpp:58
bool canHandleKeyPress(const Event::KeyEvent &event) override
Called by the parent of the widget to check if keyPressed would process the event.
ChildWindow(ChildWindow &&) noexcept
Move constructor.
TGUI_NODISCARD bool isMouseOnWidget(Vector2f pos) const override
Returns whether the mouse position (which is relative to the parent widget) lies on top of the widget...
TGUI_NODISCARD Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
void load(const std::unique_ptr< DataIO::Node > &node, const LoadingRenderersMap &renderers) override
Loads the widget from a tree of nodes.
TGUI_NODISCARD Signal & getSignal(String signalName) override
Retrieves a signal based on its name.
bool leftMousePressed(Vector2f pos) override
Called by the parent when the left mouse button goes down on top of the widget.
void mouseEnteredWidget() override
This function is called when the mouse enters the widget.
TGUI_NODISCARD bool getKeepInParent() const
Returns whether the child window is kept inside its parent.
std::shared_ptr< const ChildWindow > ConstPtr
Shared constant widget pointer.
Definition ChildWindow.hpp:49
Definition ChildWindowRenderer.hpp:37
Container widget.
Definition Container.hpp:49
Class to store the position or size of a widget.
Definition Layout.hpp:328
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:470
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:62
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:291
Wrapper class to store strings.
Definition String.hpp:101
The parent class for every widget.
Definition Widget.hpp:84
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition Widget.hpp:87
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:39
HorizontalAlignment
The horizontal alignment.
Definition Layout.hpp:52
KeyPressed event parameters.
Definition Event.hpp:169
States used for drawing.
Definition RenderStates.hpp:39