TGUI  1.0-beta
Loading...
Searching...
No Matches
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 using Ptr = std::shared_ptr<ChildWindow>;
48 using ConstPtr = std::shared_ptr<const ChildWindow>;
49
50 static constexpr const char StaticWidgetType[] = "ChildWindow";
51
52
54 enum class TitleAlignment
55 {
56 Left,
57 Center,
58 Right
59 };
60
61
63 enum TitleButton : unsigned int
64 {
65 None = 0,
66 Close = 1 << 0,
67 Maximize = 1 << 1,
68 Minimize = 1 << 2
69 };
70
78 ChildWindow(const char* typeName = StaticWidgetType, bool initRenderer = true);
79
80
85
86
91
92
96 ChildWindow& operator= (const ChildWindow&);
97
98
102 ChildWindow& operator= (ChildWindow&&) noexcept;
103
104
111 static ChildWindow::Ptr create(const String& title = "", unsigned int titleButtons = TitleButton::Close);
112
113
122 static ChildWindow::Ptr copy(const ChildWindow::ConstPtr& childWindow);
123
124
129 ChildWindowRenderer* getSharedRenderer();
130 const ChildWindowRenderer* getSharedRenderer() const;
131
137 ChildWindowRenderer* getRenderer();
138
139
152 void setPosition(const Layout2d& position) override;
153 using Widget::setPosition;
154
155
164 void setSize(const Layout2d& size) override;
165 using Widget::setSize;
166
167
174 Vector2f getInnerSize() const override;
175
176
184 virtual void setClientSize(const Layout2d& size);
185
186
194 Vector2f getClientSize() const;
195
196
205 void setMaximumSize(Vector2f size);
206
207
215 Vector2f getMaximumSize() const;
216
217
226 void setMinimumSize(Vector2f size);
227
228
236 Vector2f getMinimumSize() const;
237
238
245 void setTitle(const String& title);
246
247
254 const String& getTitle() const;
255
256
262 void setTitleTextSize(unsigned int size);
263
264
269 unsigned int getTitleTextSize() const;
270
271
278 void setTitleAlignment(TitleAlignment alignment);
279
280
287 TitleAlignment getTitleAlignment() const;
288
289
302 void setTitleButtons(unsigned int buttons);
303
304
311 unsigned int getTitleButtons() const;
312
313
322 void close();
323
324
331 void destroy();
332
333
340 void setResizable(bool resizable = true);
341
342
349 bool isResizable() const;
350
351
358 void setPositionLocked(bool positionLocked = true);
359
360
365 bool isPositionLocked() const;
366
367
375 void setKeepInParent(bool enabled = true);
376
377
385 bool isKeptInParent() const;
386
387
395 Vector2f getChildWidgetsOffset() const override;
396
397
403 void setParent(Container* parent) override;
404
405
412 bool isMouseOnWidget(Vector2f pos) const override;
413
417 void leftMousePressed(Vector2f pos) override;
418
422 void leftMouseReleased(Vector2f pos) override;
423
427 void rightMousePressed(Vector2f pos) override;
428
432 void rightMouseReleased(Vector2f pos) override;
433
437 void mouseMoved(Vector2f pos) override;
438
442 void keyPressed(const Event::KeyEvent& event) override;
443
447 void mouseNoLongerOnWidget() override;
448
452 void leftMouseButtonNoLongerDown() override;
453
454
462 void draw(BackendRenderTarget& target, RenderStates states) const override;
463
464
466 protected:
467
469 // Updates the title bar texture, text and buttons after the title bar height has changed.
471 void updateTitleBarHeight();
472
473
475 // Updates the mouse cursor for resizable child windows
477 void updateResizeMouseCursor(Vector2f mousePos);
478
479
489 Signal& getSignal(String signalName) override;
490
491
498 void rendererChanged(const String& property) override;
499
500
504 std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
505
506
510 void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
511
512
516 void mouseEnteredWidget() override;
517
518
522 void mouseLeftWidget() override;
523
524
526 // Makes a copy of the widget
528 Widget::Ptr clone() const override;
529
530
532 private:
533
535 // Helper function to connect the title button callbacks from the various constuctors and assignment operators
537 void connectTitleButtonCallbacks();
538
539
541 public:
542
543 Signal onMousePress = {"MousePressed"};
544 SignalChildWindow onClose = {"Closed"};
545 SignalChildWindow onMinimize = {"Minimized"};
546 SignalChildWindow onMaximize = {"Maximized"};
547 SignalChildWindow onEscapeKeyPress = {"EscapeKeyPressed"};
548
553 SignalTyped<bool*> onClosing = {"Closing"};
554
555
557 protected:
558
559 enum ResizeDirection
560 {
561 ResizeNone = 0,
562 ResizeLeft = 1,
563 ResizeTop = 2,
564 ResizeRight = 4,
565 ResizeBottom = 8
566 };
567
568
570 protected:
571
572 Text m_titleText;
573 Vector2f m_draggingPosition;
574 Vector2f m_maximumSize = {std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity()};
575 Vector2f m_minimumSize = {0, 0};
576 Layout* m_decorationLayoutX = nullptr;
577 Layout* m_decorationLayoutY = nullptr;
578 TitleAlignment m_titleAlignment = TitleAlignment::Center;
579 unsigned int m_titleButtons = TitleButton::Close;
580 unsigned int m_titleTextSize = 0;
581 Cursor::Type m_currentChildWindowMouseCursor = Cursor::Type::Arrow;
582
583 CopiedSharedPtr<Button> m_closeButton;
584 CopiedSharedPtr<Button> m_minimizeButton;
585 CopiedSharedPtr<Button> m_maximizeButton;
586
587 bool m_mouseDownOnTitleBar = false;
588 bool m_keepInParent = false;
589
590 bool m_positionLocked = false;
591 bool m_resizable = false;
592 int m_resizeDirection = ResizeNone;
593
594 Sprite m_spriteTitleBar;
595 Sprite m_spriteBackground;
596
597 // Cached renderer properties
598 Borders m_bordersCached;
599 Color m_borderColorCached;
600 Color m_borderColorFocusedCached;
601 Color m_titleColorCached;
602 Color m_titleBarColorCached;
603 Color m_backgroundColorCached;
604 float m_titleBarHeightCached = 20;
605 float m_borderBelowTitleBarCached = 0;
606 float m_distanceToSideCached = 0;
607 float m_paddingBetweenButtonsCached = 0;
608 float m_minimumResizableBorderWidthCached = 10;
609 bool m_showTextOnTitleButtonsCached = false;
610
612 };
613
615}
616
618
619#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:55
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:64
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
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:466
Signal to which the user can subscribe to get callbacks from.
Definition: Signal.hpp:287
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