TGUI  1.0-alpha
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
137
150 void setPosition(const Layout2d& position) override;
151 using Widget::setPosition;
152
153
162 void setSize(const Layout2d& size) override;
163 using Widget::setSize;
164
165
172 Vector2f getInnerSize() const override;
173
174
182 virtual void setClientSize(const Layout2d& size);
183
184
192 Vector2f getClientSize() const;
193
194
203 void setMaximumSize(Vector2f size);
204
205
213 Vector2f getMaximumSize() const;
214
215
224 void setMinimumSize(Vector2f size);
225
226
234 Vector2f getMinimumSize() const;
235
236
243 void setTitle(const String& title);
244
245
252 const String& getTitle() const;
253
254
260 void setTitleTextSize(unsigned int size);
261
262
267 unsigned int getTitleTextSize() const;
268
269
276 void setTitleAlignment(TitleAlignment alignment);
277
278
285 TitleAlignment getTitleAlignment() const;
286
287
300 void setTitleButtons(unsigned int buttons);
301
302
309 unsigned int getTitleButtons() const;
310
311
320 void close();
321
322
329 void destroy();
330
331
338 void setResizable(bool resizable = true);
339
340
347 bool isResizable() const;
348
349
356 void setPositionLocked(bool positionLocked = true);
357
358
363 bool isPositionLocked() const;
364
365
373 void setKeepInParent(bool enabled = true);
374
375
383 bool isKeptInParent() const;
384
385
393 Vector2f getChildWidgetsOffset() const override;
394
395
401 void setParent(Container* parent) override;
402
403
410 bool isMouseOnWidget(Vector2f pos) const override;
411
415 void leftMousePressed(Vector2f pos) override;
416
420 void leftMouseReleased(Vector2f pos) override;
421
425 void rightMousePressed(Vector2f pos) override;
426
430 void rightMouseReleased(Vector2f pos) override;
431
435 void mouseMoved(Vector2f pos) override;
436
440 void keyPressed(const Event::KeyEvent& event) override;
441
445 void mouseNoLongerOnWidget() override;
446
450 void leftMouseButtonNoLongerDown() override;
451
452
460 void draw(BackendRenderTarget& target, RenderStates states) const override;
461
462
464 protected:
465
467 // Updates the title bar texture, text and buttons after the title bar height has changed.
469 void updateTitleBarHeight();
470
471
473 // Updates the mouse cursor for resizable child windows
475 void updateResizeMouseCursor(Vector2f mousePos);
476
477
487 Signal& getSignal(String signalName) override;
488
489
496 void rendererChanged(const String& property) override;
497
498
502 std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
503
504
508 void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
509
510
514 void mouseEnteredWidget() override;
515
516
520 void mouseLeftWidget() override;
521
522
524 // Makes a copy of the widget
526 Widget::Ptr clone() const override;
527
528
530 public:
531
532 Signal onMousePress = {"MousePressed"};
533 SignalChildWindow onClose = {"Closed"};
534 SignalChildWindow onMinimize = {"Minimized"};
535 SignalChildWindow onMaximize = {"Maximized"};
536 SignalChildWindow onEscapeKeyPress = {"EscapeKeyPressed"};
537
542 SignalTyped<bool*> onClosing = {"Closing"};
543
544
546 protected:
547
548 enum ResizeDirection
549 {
550 ResizeNone = 0,
551 ResizeLeft = 1,
552 ResizeTop = 2,
553 ResizeRight = 4,
554 ResizeBottom = 8
555 };
556
557
559 protected:
560
561 Text m_titleText;
562 Vector2f m_draggingPosition;
563 Vector2f m_maximumSize = {std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity()};
564 Vector2f m_minimumSize = {0, 0};
565 Layout* m_decorationLayoutX = nullptr;
566 Layout* m_decorationLayoutY = nullptr;
567 TitleAlignment m_titleAlignment = TitleAlignment::Center;
568 unsigned int m_titleButtons = TitleButton::Close;
569 unsigned int m_titleTextSize = 0;
570 Cursor::Type m_currentChildWindowMouseCursor = Cursor::Type::Arrow;
571
572 CopiedSharedPtr<Button> m_closeButton;
573 CopiedSharedPtr<Button> m_minimizeButton;
574 CopiedSharedPtr<Button> m_maximizeButton;
575
576 bool m_mouseDownOnTitleBar = false;
577 bool m_keepInParent = false;
578
579 bool m_positionLocked = false;
580 bool m_resizable = false;
581 int m_resizeDirection = ResizeNone;
582
583 Sprite m_spriteTitleBar;
584 Sprite m_spriteBackground;
585
586 // Cached renderer properties
587 Borders m_bordersCached;
588 Color m_borderColorCached;
589 Color m_borderColorFocusedCached;
590 Color m_titleColorCached;
591 Color m_titleBarColorCached;
592 Color m_backgroundColorCached;
593 float m_titleBarHeightCached = 20;
594 float m_borderBelowTitleBarCached = 0;
595 float m_distanceToSideCached = 0;
596 float m_paddingBetweenButtonsCached = 0;
597 float m_minimumResizableBorderWidthCached = 10;
598 bool m_showTextOnTitleButtonsCached = false;
599
601 };
602
604}
605
607
608#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