TGUI  1.0.0
Loading...
Searching...
No Matches
ChildWindow.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2023 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
450 void mouseNoLongerOnWidget() override;
451
455 void leftMouseButtonNoLongerDown() override;
456
457
465 void draw(BackendRenderTarget& target, RenderStates states) const override;
466
467
469 protected:
470
472 // Updates the title bar texture, text and buttons after the title bar height has changed.
474 void updateTitleBarHeight();
475
476
478 // Updates the mouse cursor for resizable child windows
480 void updateResizeMouseCursor(Vector2f mousePos);
481
482
492 TGUI_NODISCARD Signal& getSignal(String signalName) override;
493
494
501 void rendererChanged(const String& property) override;
502
503
507 TGUI_NODISCARD std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
508
509
513 void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
514
515
519 void mouseEnteredWidget() override;
520
521
525 void mouseLeftWidget() override;
526
527
529 // Makes a copy of the widget
531 TGUI_NODISCARD Widget::Ptr clone() const override;
532
533
535 private:
536
538 // Helper function to connect the title button callbacks from the various constuctors and assignment operators
540 void connectTitleButtonCallbacks();
541
542
544 public:
545
546 Signal onMousePress = {"MousePressed"};
547 SignalChildWindow onClose = {"Closed"};
548 SignalChildWindow onMinimize = {"Minimized"};
549 SignalChildWindow onMaximize = {"Maximized"};
550 SignalChildWindow onEscapeKeyPress = {"EscapeKeyPressed"};
551
556 SignalTyped<bool*> onClosing = {"Closing"};
557
558
560 protected:
561
562 enum ResizeDirection
563 {
564 ResizeNone = 0,
565 ResizeLeft = 1,
566 ResizeTop = 2,
567 ResizeRight = 4,
568 ResizeBottom = 8
569 };
570
571
573 protected:
574
575 Text m_titleText;
576 Vector2f m_draggingPosition;
577 Vector2f m_maximumSize = {std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity()};
578 Vector2f m_minimumSize = {0, 0};
579 Layout* m_decorationLayoutX = nullptr;
580 Layout* m_decorationLayoutY = nullptr;
581 TitleAlignment m_titleAlignment = TitleAlignment::Center;
582 unsigned int m_titleButtons = TitleButton::Close;
583 unsigned int m_titleTextSize = 0;
584 Cursor::Type m_currentChildWindowMouseCursor = Cursor::Type::Arrow;
585
586 CopiedSharedPtr<Button> m_closeButton;
587 CopiedSharedPtr<Button> m_minimizeButton;
588 CopiedSharedPtr<Button> m_maximizeButton;
589
590 bool m_mouseDownOnTitleBar = false;
591 bool m_keepInParent = false;
592
593 bool m_positionLocked = false;
594 bool m_resizable = false;
595 int m_resizeDirection = ResizeNone;
596
597 Sprite m_spriteTitleBar;
598 Sprite m_spriteBackground;
599
600 // Cached renderer properties
601 Borders m_bordersCached;
602 Color m_borderColorCached;
603 Color m_borderColorFocusedCached;
604 Color m_titleColorCached;
605 Color m_titleBarColorCached;
606 Color m_backgroundColorCached;
607 float m_titleBarHeightCached = 20;
608 float m_borderBelowTitleBarCached = 0;
609 float m_distanceToSideCached = 0;
610 float m_paddingBetweenButtonsCached = 0;
611 float m_minimumResizableBorderWidthCached = 10;
612 bool m_showTextOnTitleButtonsCached = false;
613
615 };
616
618}
619
621
622#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:289
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