1//************************************ bs::framework - Copyright 2018 Marko Pintera **************************************//
2//*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********//
3#pragma once
4
5#include "BsPrerequisites.h"
6#include "Scene/BsComponent.h"
7#include "Math/BsRect2I.h"
8#include "GUI/BsGUIWidget.h"
9
10namespace bs
11{
12 /** @addtogroup GUI
13 * @{
14 */
15
16 /** Component wrapper for GUIWidget. */
17 class BS_EXPORT CGUIWidget : public Component
18 {
19 public:
20 virtual ~CGUIWidget() = default;
21
22 /** @copydoc GUIWidget::setSkin */
23 void setSkin(const HGUISkin& skin);
24
25 /** @copydoc GUIWidget::getSkin */
26 const GUISkin& getSkin() const;
27
28 /** @copydoc GUIWidget::getSkinResource */
29 const HGUISkin& getSkinResource() const;
30
31 /** @copydoc GUIWidget::getPanel */
32 GUIPanel* getPanel() const;
33
34 /** @copydoc GUIWidget::getDepth */
35 UINT8 getDepth() const;
36
37 /** @copydoc GUIWidget::setDepth */
38 void setDepth(UINT8 depth);
39
40 /** @copydoc GUIWidget::inBounds */
41 bool inBounds(const Vector2I& position) const;
42
43 /** @copydoc GUIWidget::getBounds */
44 const Rect2I& getBounds() const;
45
46 /** @copydoc GUIWidget::isDirty */
47 bool isDirty(bool cleanIfDirty);
48
49 /** @copydoc GUIWidget::getTarget */
50 Viewport* getTarget() const;
51
52 /** @copydoc GUIWidget::getCamera */
53 SPtr<Camera> getCamera() const;
54
55 /** @copydoc GUIWidget::getElements */
56 const Vector<GUIElement*>& getElements() const;
57
58 public: // ***** INTERNAL ******
59 /** @name Internal
60 * @{
61 */
62
63 /** Returns the internal GUIWidget that is wrapped by this component. */
64 GUIWidget* _getInternal() const { return mInternal.get(); };
65
66 /** @} */
67
68 protected:
69 friend class SceneObject;
70 friend class GUIElementBase;
71 friend class GUIManager;
72
73 /**
74 * Constructs a new GUI widget attached to the specified parent scene object. Widget elements will be rendered on
75 * the provided camera.
76 */
77 CGUIWidget(const HSceneObject& parent, const SPtr<Camera>& camera);
78
79 /**
80 * Constructs a new GUI widget attached to the specified parent scene object. Widget elements will be rendered on
81 * the provided camera.
82 */
83 CGUIWidget(const HSceneObject& parent, const HCamera& camera);
84
85 /** @copydoc Component::update */
86 void update() override;
87
88 /** @copydoc Component::onDestroyed */
89 void onDestroyed() override;
90
91 /** Called when the viewport size changes and widget elements need to be updated. */
92 virtual void ownerTargetResized() { }
93
94 /** Called when the parent window gained or lost focus. */
95 virtual void ownerWindowFocusChanged() { }
96
97 private:
98 CGUIWidget(CGUIWidget&&) = delete;
99 CGUIWidget(const CGUIWidget&) = delete;
100
101 SPtr<GUIWidget> mInternal;
102 HEvent mOwnerTargetResizedConn;
103 HEvent mOwnerWindowFocusChangedConn;
104
105 SPtr<Camera> mCamera;
106 UINT32 mParentHash;
107
108 /************************************************************************/
109 /* RTTI */
110 /************************************************************************/
111 public:
112 friend class CGUIWidgetRTTI;
113 static RTTITypeBase* getRTTIStatic();
114 RTTITypeBase* getRTTI() const override;
115
116 CGUIWidget(); // Serialization only
117 };
118
119 /** @} */
120}
121