TGUI  1.2.0
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
26#ifndef TGUI_CHILD_WINDOW_HPP
27#define TGUI_CHILD_WINDOW_HPP
28
29
30#include <TGUI/CopiedSharedPtr.hpp>
31#include <TGUI/Container.hpp>
32#include <TGUI/Widgets/Button.hpp>
33#include <TGUI/Renderers/ChildWindowRenderer.hpp>
34
35#if !TGUI_EXPERIMENTAL_USE_STD_MODULE
36 #include <limits>
37#endif
38
40
41TGUI_MODULE_EXPORT namespace tgui
42{
46 class TGUI_API ChildWindow : public Container
47 {
48 public:
49
50 using Ptr = std::shared_ptr<ChildWindow>;
51 using ConstPtr = std::shared_ptr<const ChildWindow>;
52
53 static constexpr const char StaticWidgetType[] = "ChildWindow";
54
55
57 enum class TitleAlignment
58 {
59 Left,
60 Center,
61 Right
62 };
63
64
66 enum TitleButton : unsigned int
67 {
68 None = 0,
69 Close = 1 << 0,
70 Maximize = 1 << 1,
71 Minimize = 1 << 2
72 };
73
81 ChildWindow(const char* typeName = StaticWidgetType, bool initRenderer = true);
82
83
88
89
94
95
99 ChildWindow& operator= (const ChildWindow&);
100
101
105 ChildWindow& operator= (ChildWindow&&) noexcept;
106
107
114 TGUI_NODISCARD static ChildWindow::Ptr create(const String& title = "", unsigned int titleButtons = TitleButton::Close);
115
116
125 TGUI_NODISCARD static ChildWindow::Ptr copy(const ChildWindow::ConstPtr& childWindow);
126
127
132 TGUI_NODISCARD ChildWindowRenderer* getSharedRenderer() override;
133 TGUI_NODISCARD const ChildWindowRenderer* getSharedRenderer() const override;
134
140 TGUI_NODISCARD ChildWindowRenderer* getRenderer() override;
141
142
155 void setPosition(const Layout2d& position) override;
156 using Widget::setPosition;
157
158
167 void setSize(const Layout2d& size) override;
168 using Widget::setSize;
169
170
177 TGUI_NODISCARD Vector2f getInnerSize() const override;
178
179
187 virtual void setClientSize(const Layout2d& size);
188
189
197 TGUI_NODISCARD Vector2f getClientSize() const;
198
199
208 void setMaximumSize(Vector2f size);
209
210
218 TGUI_NODISCARD Vector2f getMaximumSize() const;
219
220
229 void setMinimumSize(Vector2f size);
230
231
239 TGUI_NODISCARD Vector2f getMinimumSize() const;
240
241
248 void setTitle(const String& title);
249
250
257 TGUI_NODISCARD const String& getTitle() const;
258
259
265 void setTitleTextSize(unsigned int size);
266
267
272 TGUI_NODISCARD unsigned int getTitleTextSize() const;
273
274
281 void setTitleAlignment(TitleAlignment alignment);
282
283
290 TGUI_NODISCARD TitleAlignment getTitleAlignment() const;
291
292
305 void setTitleButtons(unsigned int buttons);
306
307
314 TGUI_NODISCARD unsigned int getTitleButtons() const;
315
316
325 void close();
326
327
334 void destroy();
335
336
343 void setResizable(bool resizable = true);
344
345
352 TGUI_NODISCARD bool isResizable() const;
353
354
361 void setPositionLocked(bool positionLocked = true);
362
363
368 TGUI_NODISCARD bool isPositionLocked() const;
369
370
378 void setKeepInParent(bool enabled = true);
379
380
388 TGUI_NODISCARD bool isKeptInParent() const;
389
390
398 TGUI_NODISCARD Vector2f getChildWidgetsOffset() const override;
399
400
406 void setParent(Container* parent) override;
407
408
415 TGUI_NODISCARD bool isMouseOnWidget(Vector2f pos) const override;
416
420 bool leftMousePressed(Vector2f pos) override;
421
425 void leftMouseReleased(Vector2f pos) override;
426
430 void rightMousePressed(Vector2f pos) override;
431
435 void rightMouseReleased(Vector2f pos) override;
436
440 void mouseMoved(Vector2f pos) override;
441
445 void keyPressed(const Event::KeyEvent& event) override;
446
456 bool canHandleKeyPress(const Event::KeyEvent& event) override;
457
461 void mouseNoLongerOnWidget() override;
462
466 void leftMouseButtonNoLongerDown() override;
467
468
476 void draw(BackendRenderTarget& target, RenderStates states) const override;
477
478
480 protected:
481
483 // Updates the title bar texture, text and buttons after the title bar height has changed.
485 void updateTitleBarHeight();
486
487
489 // Updates the mouse cursor for resizable child windows
491 void updateResizeMouseCursor(Vector2f mousePos);
492
493
503 TGUI_NODISCARD Signal& getSignal(String signalName) override;
504
505
512 void rendererChanged(const String& property) override;
513
514
518 TGUI_NODISCARD std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
519
520
524 void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
525
526
530 void mouseEnteredWidget() override;
531
532
536 void mouseLeftWidget() override;
537
538
540 // Makes a copy of the widget
542 TGUI_NODISCARD Widget::Ptr clone() const override;
543
544
546 private:
547
549 // Helper function to connect the title button callbacks from the various constuctors and assignment operators
551 void connectTitleButtonCallbacks();
552
553
555 public:
556
557 Signal onMousePress = {"MousePressed"};
558 SignalChildWindow onClose = {"Closed"};
559 SignalChildWindow onMinimize = {"Minimized"};
560 SignalChildWindow onMaximize = {"Maximized"};
561 SignalChildWindow onEscapeKeyPress = {"EscapeKeyPressed"};
562
567 SignalTyped<bool*> onClosing = {"Closing"};
568
569
571 protected:
572
573 enum ResizeDirection
574 {
575 ResizeNone = 0,
576 ResizeLeft = 1,
577 ResizeTop = 2,
578 ResizeRight = 4,
579 ResizeBottom = 8
580 };
581
582
584 protected:
585
586 Text m_titleText;
587 Vector2f m_draggingPosition;
588 Vector2f m_maximumSize = {std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity()};
589 Vector2f m_minimumSize = {0, 0};
590 Layout* m_decorationLayoutX = nullptr;
591 Layout* m_decorationLayoutY = nullptr;
592 TitleAlignment m_titleAlignment = TitleAlignment::Center;
593 unsigned int m_titleButtons = TitleButton::Close;
594 unsigned int m_titleTextSize = 0;
595 Cursor::Type m_currentChildWindowMouseCursor = Cursor::Type::Arrow;
596
597 CopiedSharedPtr<Button> m_closeButton;
598 CopiedSharedPtr<Button> m_minimizeButton;
599 CopiedSharedPtr<Button> m_maximizeButton;
600
601 bool m_mouseDownOnTitleBar = false;
602 bool m_keepInParent = false;
603
604 bool m_positionLocked = false;
605 bool m_resizable = false;
606 int m_resizeDirection = ResizeNone;
607
608 Sprite m_spriteTitleBar;
609 Sprite m_spriteBackground;
610
611 // Cached renderer properties
612 Borders m_bordersCached;
613 Color m_borderColorCached;
614 Color m_borderColorFocusedCached;
615 Color m_titleColorCached;
616 Color m_titleBarColorCached;
617 Color m_backgroundColorCached;
618 float m_titleBarHeightCached = 20;
619 float m_borderBelowTitleBarCached = 0;
620 float m_distanceToSideCached = 0;
621 float m_paddingBetweenButtonsCached = 0;
622 float m_minimumResizableBorderWidthCached = 10;
623 bool m_showTextOnTitleButtonsCached = false;
624
626 };
627
629}
630
632
633#endif // TGUI_CHILD_WINDOW_HPP
Base class for render targets.
Definition BackendRenderTarget.hpp:48
Definition ChildWindowRenderer.hpp:37
Child window widget.
Definition ChildWindow.hpp:47
TitleAlignment
Title alignments, possible options for the setTitleAlignment function.
Definition ChildWindow.hpp:58
ChildWindow(const ChildWindow &)
Copy constructor.
std::shared_ptr< ChildWindow > Ptr
Shared widget pointer.
Definition ChildWindow.hpp:50
TitleButton
Title buttons (use bitwise OR to combine)
Definition ChildWindow.hpp:67
ChildWindow(ChildWindow &&) noexcept
Move constructor.
std::shared_ptr< const ChildWindow > ConstPtr
Shared constant widget pointer.
Definition ChildWindow.hpp:51
Container widget.
Definition Container.hpp:49
Class to store the position or size of a widget.
Definition Layout.hpp:305
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:291
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:62
Wrapper class to store strings.
Definition String.hpp:101
The parent class for every widget.
Definition Widget.hpp:84
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:39
Definition Event.hpp:39
States used for drawing.
Definition RenderStates.hpp:39