TGUI  0.10-beta
ChildWindow.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2022 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#include <limits>
35
37
38namespace tgui
39{
43 class TGUI_API ChildWindow : public Container
44 {
45 public:
46
47 typedef std::shared_ptr<ChildWindow> Ptr;
48 typedef std::shared_ptr<const ChildWindow> ConstPtr;
49
50
52 enum class TitleAlignment
53 {
54 Left,
55 Center,
56 Right
57 };
58
59
62 {
63 None = 0,
64 Close = 1 << 0,
65 Maximize = 1 << 1,
66 Minimize = 1 << 2
67 };
68
76 ChildWindow(const char* typeName = "ChildWindow", bool initRenderer = true);
77
78
83
84
89
90
94 ChildWindow& operator= (const ChildWindow&);
95
96
100 ChildWindow& operator= (ChildWindow&&) noexcept;
101
102
109 static ChildWindow::Ptr create(const String& title = "", unsigned int titleButtons = TitleButton::Close);
110
111
120 static ChildWindow::Ptr copy(ChildWindow::ConstPtr childWindow);
121
122
127 ChildWindowRenderer* getSharedRenderer();
128 const ChildWindowRenderer* getSharedRenderer() const;
129
135 ChildWindowRenderer* getRenderer();
136 const ChildWindowRenderer* getRenderer() const;
137
138
151 void setPosition(const Layout2d& position) override;
152 using Widget::setPosition;
153
154
163 void setSize(const Layout2d& size) override;
164 using Widget::setSize;
165
166
173 Vector2f getInnerSize() const override;
174
175
183 void setClientSize(const Layout2d& size);
184
185
193 Vector2f getClientSize() const;
194
195
204 void setMaximumSize(Vector2f size);
205
206
214 Vector2f getMaximumSize() const;
215
216
225 void setMinimumSize(Vector2f size);
226
227
235 Vector2f getMinimumSize() const;
236
237
244 void setTitle(const String& title);
245
246
253 const String& getTitle() const;
254
255
261 void setTitleTextSize(unsigned int size);
262
263
268 unsigned int getTitleTextSize() const;
269
270
277 void setTitleAlignment(TitleAlignment alignment);
278
279
286 TitleAlignment getTitleAlignment() const;
287
288
301 void setTitleButtons(unsigned int buttons);
302
303
310 unsigned int getTitleButtons() const;
311
312
321 void close();
322
323
330 void destroy();
331
332
339 void setResizable(bool resizable = true);
340
341
348 bool isResizable() const;
349
350
357 void setPositionLocked(bool positionLocked = true);
358
359
364 bool isPositionLocked() const;
365
366
374 void setKeepInParent(bool enabled = true);
375
376
384 bool isKeptInParent() const;
385
386
394 Vector2f getChildWidgetsOffset() const override;
395
396
402 void setParent(Container* parent) override;
403
404
411 bool isMouseOnWidget(Vector2f pos) const override;
412
416 void leftMousePressed(Vector2f pos) override;
417
421 void leftMouseReleased(Vector2f pos) override;
422
426 void rightMousePressed(Vector2f pos) override;
427
431 void rightMouseReleased(Vector2f pos) override;
432
436 void mouseMoved(Vector2f pos) override;
437
441 void keyPressed(const Event::KeyEvent& event) override;
442
446 void mouseNoLongerOnWidget() override;
447
451 void leftMouseButtonNoLongerDown() override;
452
453
461 void draw(BackendRenderTarget& target, RenderStates states) const override;
462
463
465 protected:
466
468 // Updates the title bar texture, text and buttons after the title bar height has changed.
470 void updateTitleBarHeight();
471
472
474 // Updates the mouse cursor for resizable child windows
476 void updateResizeMouseCursor(Vector2f mousePos);
477
478
488 Signal& getSignal(String signalName) override;
489
490
497 void rendererChanged(const String& property) override;
498
499
503 std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
504
505
509 void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
510
511
515 void mouseEnteredWidget() override;
516
517
521 void mouseLeftWidget() override;
522
523
525 // Makes a copy of the widget
527 Widget::Ptr clone() const override;
528
529
531 public:
532
533 Signal onMousePress = {"MousePressed"};
534 SignalChildWindow onClose = {"Closed"};
535 SignalChildWindow onMinimize = {"Minimized"};
536 SignalChildWindow onMaximize = {"Maximized"};
537 SignalChildWindow onEscapeKeyPress = {"EscapeKeyPressed"};
538
543 SignalTyped<bool*> onClosing = {"Closing"};
544
545
547 protected:
548
549 enum ResizeDirection
550 {
551 ResizeNone = 0,
552 ResizeLeft = 1,
553 ResizeTop = 2,
554 ResizeRight = 4,
555 ResizeBottom = 8
556 };
557
558
560 protected:
561
562 Text m_titleText;
563 Vector2f m_draggingPosition;
564 Vector2f m_maximumSize = {std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity()};
565 Vector2f m_minimumSize = {0, 0};
566 Layout* m_decorationLayoutX = nullptr;
567 Layout* m_decorationLayoutY = nullptr;
568 TitleAlignment m_titleAlignment = TitleAlignment::Center;
569 unsigned int m_titleButtons = TitleButton::Close;
570 unsigned int m_titleTextSize = 0;
571 Cursor::Type m_currentChildWindowMouseCursor = Cursor::Type::Arrow;
572
573 CopiedSharedPtr<Button> m_closeButton;
574 CopiedSharedPtr<Button> m_minimizeButton;
575 CopiedSharedPtr<Button> m_maximizeButton;
576
577 bool m_mouseDownOnTitleBar = false;
578 bool m_keepInParent = false;
579
580 bool m_positionLocked = false;
581 bool m_resizable = false;
582 int m_resizeDirection = ResizeNone;
583
584 Sprite m_spriteTitleBar;
585 Sprite m_spriteBackground;
586
587 // Cached renderer properties
588 Borders m_bordersCached;
589 Color m_borderColorCached;
590 Color m_borderColorFocusedCached;
591 Color m_titleColorCached;
592 Color m_titleBarColorCached;
593 Color m_backgroundColorCached;
594 float m_titleBarHeightCached = 20;
595 float m_borderBelowTitleBarCached = 0;
596 float m_distanceToSideCached = 0;
597 float m_paddingBetweenButtonsCached = 0;
598 float m_minimumResizableBorderWidthCached = 10;
599 bool m_showTextOnTitleButtonsCached = false;
600
602 };
603
605}
606
608
609#endif // TGUI_CHILD_WINDOW_HPP
Base class for render targets.
Definition: BackendRenderTarget.hpp:48
Definition: ChildWindowRenderer.hpp:37
Child window widget.
Definition: ChildWindow.hpp:44
TitleAlignment
Title alignments, possible options for the setTitleAlignment function.
Definition: ChildWindow.hpp:53
ChildWindow(const ChildWindow &)
Copy constructor.
std::shared_ptr< ChildWindow > Ptr
Shared widget pointer.
Definition: ChildWindow.hpp:47
TitleButton
Title buttons (use bitwise OR to combine)
Definition: ChildWindow.hpp:62
ChildWindow(ChildWindow &&) noexcept
Move constructor.
std::shared_ptr< const ChildWindow > ConstPtr
Shared constant widget pointer.
Definition: ChildWindow.hpp:48
Container widget.
Definition: Container.hpp:47
std::shared_ptr< Container > Ptr
Shared widget pointer.
Definition: Container.hpp:50
std::shared_ptr< const Container > ConstPtr
Shared constant widget pointer.
Definition: Container.hpp:51
Type
List of available cursors.
Definition: Cursor.hpp:48
@ Arrow
Arrow cursor (default)
Class to store the position or size of a widget.
Definition: Layout.hpp:284
Signal to which the user can subscribe to get callbacks from.
Definition: Signal.hpp:467
Signal to which the user can subscribe to get callbacks from.
Definition: Signal.hpp:58
Wrapper class to store strings.
Definition: String.hpp:79
The parent class for every widget.
Definition: Widget.hpp:70
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
Definition: Event.hpp:37
States used for drawing.
Definition: RenderStates.hpp:39