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#include "GUI/BsCGUIWidget.h"
4#include "Private/RTTI/BsCGUIWidgetRTTI.h"
5#include "GUI/BsGUIWidget.h"
6#include "Scene/BsSceneObject.h"
7#include "Components/BsCCamera.h"
8
9namespace bs
10{
11 CGUIWidget::CGUIWidget()
12 {
13 setFlag(ComponentFlag::AlwaysRun, true);
14 }
15
16 CGUIWidget::CGUIWidget(const HSceneObject& parent, const SPtr<Camera>& camera)
17 :Component(parent), mCamera(camera), mParentHash((UINT32)-1)
18 {
19 setFlag(ComponentFlag::AlwaysRun, true);
20
21 mInternal = GUIWidget::create(camera);
22 mOwnerTargetResizedConn = mInternal->onOwnerTargetResized.connect(
23 std::bind(&CGUIWidget::ownerTargetResized, this));
24 mOwnerWindowFocusChangedConn = mInternal->onOwnerWindowFocusChanged.connect(
25 std::bind(&CGUIWidget::ownerWindowFocusChanged, this));
26 }
27
28 CGUIWidget::CGUIWidget(const HSceneObject& parent, const HCamera& camera)
29 :CGUIWidget(parent, camera->_getCamera())
30 { }
31
32 void CGUIWidget::setSkin(const HGUISkin& skin)
33 {
34 mInternal->setSkin(skin);
35 }
36
37 const GUISkin& CGUIWidget::getSkin() const
38 {
39 return mInternal->getSkin();
40 }
41
42 const HGUISkin& CGUIWidget::getSkinResource() const
43 {
44 return mInternal->getSkinResource();
45 }
46
47 GUIPanel* CGUIWidget::getPanel() const
48 {
49 return mInternal->getPanel();
50 }
51
52 UINT8 CGUIWidget::getDepth() const
53 {
54 return mInternal->getDepth();
55 }
56
57 void CGUIWidget::setDepth(UINT8 depth)
58 {
59 mInternal->setDepth(depth);
60 }
61
62 bool CGUIWidget::inBounds(const Vector2I& position) const
63 {
64 return mInternal->inBounds(position);
65 }
66
67 const Rect2I& CGUIWidget::getBounds() const
68 {
69 return mInternal->getBounds();
70 }
71
72 bool CGUIWidget::isDirty(bool cleanIfDirty)
73 {
74 return mInternal->isDirty(cleanIfDirty);
75 }
76
77 Viewport* CGUIWidget::getTarget() const
78 {
79 return mInternal->getTarget();
80 }
81
82 SPtr<Camera> CGUIWidget::getCamera() const
83 {
84 return mInternal->getCamera();
85 }
86
87 const Vector<GUIElement*>& CGUIWidget::getElements() const
88 {
89 return mInternal->getElements();
90 }
91
92 void CGUIWidget::update()
93 {
94 HSceneObject parent = SO();
95
96 UINT32 curHash = parent->getTransformHash();
97 if (curHash != mParentHash)
98 {
99 mInternal->_updateTransform(parent);
100 mParentHash = curHash;
101 }
102
103 if (parent->getActive() != mInternal->getIsActive())
104 mInternal->setIsActive(parent->getActive());
105
106 mInternal->_updateRT();
107 }
108
109 void CGUIWidget::onDestroyed()
110 {
111 mOwnerTargetResizedConn.disconnect();
112 mOwnerWindowFocusChangedConn.disconnect();
113 mInternal = nullptr;
114 }
115
116 RTTITypeBase* CGUIWidget::getRTTIStatic()
117 {
118 return CGUIWidgetRTTI::instance();
119 }
120
121 RTTITypeBase* CGUIWidget::getRTTI() const
122 {
123 return CGUIWidget::getRTTIStatic();
124 }
125}