Adding chipmunk implementation for physics adaptor
[platform/core/uifw/dali-toolkit.git] / dali-scene3d / internal / light / light-impl.cpp
1 /*
2  * Copyright (c) 2023 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali-scene3d/internal/light/light-impl.h>
20
21 // EXTERNAL INCLUDES
22 #include <dali/integration-api/debug.h>
23 #include <dali/public-api/object/type-registry-helper.h>
24 #include <dali/public-api/object/type-registry.h>
25
26 // INTERNAL INCLUDES
27 #include <dali-scene3d/internal/controls/scene-view/scene-view-impl.h>
28
29 namespace Dali
30 {
31 namespace Scene3D
32 {
33 namespace Internal
34 {
35 namespace
36 {
37 static constexpr uint32_t         MAX_NUMBER_OF_LIGHT = 5;
38 static constexpr std::string_view LIGHT_COUNT_STRING("uLightCount");
39 static constexpr std::string_view LIGHT_DIRECTION_STRING("uLightDirection");
40 static constexpr std::string_view LIGHT_COLOR_STRING("uLightColor");
41
42 /**
43  * Creates control through type registry
44  */
45 BaseHandle Create()
46 {
47   return Scene3D::Light::New();
48 }
49
50 // Setup properties, signals and actions using the type-registry.
51 DALI_TYPE_REGISTRATION_BEGIN(Scene3D::Light, Dali::CustomActor, Create);
52 DALI_TYPE_REGISTRATION_END()
53 } // unnamed namespace
54
55 Dali::Scene3D::Light Light::New()
56 {
57   // Create the implementation, temporarily owned on stack
58   IntrusivePtr<Light> nodeImpl = new Light();
59
60   // Pass ownership to handle
61   Scene3D::Light handle(*nodeImpl);
62
63   // Second-phase init of the implementation
64   // This can only be done after the CustomActor connection has been made...
65   nodeImpl->Initialize();
66
67   return handle;
68 }
69
70 Light::Light()
71 : CustomActorImpl(ActorFlags::DISABLE_SIZE_NEGOTIATION)
72 {
73 }
74
75 Light::~Light()
76 {
77 }
78
79 void Light::Initialize()
80 {
81   Self().SetProperty(Dali::Actor::Property::COLOR, Color::WHITE);
82 }
83
84 void Light::Enable(bool enable)
85 {
86   if(enable == mIsEnabled)
87   {
88     return;
89   }
90   mIsEnabled = enable;
91
92   Scene3D::SceneView sceneView = mParentSceneView.GetHandle();
93   if(!sceneView)
94   {
95     return;
96   }
97
98   if(mIsEnabled)
99   {
100     GetImpl(sceneView).AddLight(Scene3D::Light::DownCast(Self()));
101   }
102   else
103   {
104     GetImpl(sceneView).RemoveLight(Scene3D::Light::DownCast(Self()));
105   }
106 }
107
108 bool Light::IsEnabled() const
109 {
110   return mIsEnabled;
111 }
112
113 void Light::OnSceneConnection(int depth)
114 {
115   Actor parent = Self().GetParent();
116   while(parent)
117   {
118     Scene3D::SceneView sceneView = Scene3D::SceneView::DownCast(parent);
119     if(sceneView)
120     {
121       mParentSceneView = sceneView;
122       if(mIsEnabled)
123       {
124         GetImpl(sceneView).AddLight(Scene3D::Light::DownCast(Self()));
125       }
126       break;
127     }
128     parent = parent.GetParent();
129   }
130 }
131
132 void Light::OnSceneDisconnection()
133 {
134   Scene3D::SceneView sceneView = mParentSceneView.GetHandle();
135   if(sceneView)
136   {
137     mParentSceneView.Reset();
138     GetImpl(sceneView).RemoveLight(Scene3D::Light::DownCast(Self()));
139   }
140 }
141
142 void Light::OnChildAdd(Actor& child)
143 {
144 }
145
146 void Light::OnChildRemove(Actor& child)
147 {
148 }
149
150 void Light::OnSizeSet(const Vector3& targetSize)
151 {
152 }
153
154 void Light::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
155 {
156   // @todo size negotiate background to new size, animate as well?
157 }
158
159 void Light::OnRelayout(const Vector2& size, RelayoutContainer& container)
160 {
161 }
162
163 void Light::OnSetResizePolicy(ResizePolicy::Type policy, Dimension::Type dimension)
164 {
165 }
166
167 Vector3 Light::GetNaturalSize()
168 {
169   return Vector3::ZERO;
170 }
171
172 float Light::CalculateChildSize(const Dali::Actor& child, Dimension::Type dimension)
173 {
174   return 0.0f;
175 }
176
177 float Light::GetHeightForWidth(float width)
178 {
179   return 0.0f;
180 }
181
182 float Light::GetWidthForHeight(float height)
183 {
184   return 0.0f;
185 }
186
187 bool Light::RelayoutDependentOnChildren(Dimension::Type dimension)
188 {
189   return false;
190 }
191
192 void Light::OnCalculateRelayoutSize(Dimension::Type dimension)
193 {
194 }
195
196 void Light::OnLayoutNegotiated(float size, Dimension::Type dimension)
197 {
198 }
199
200 Light& GetImplementation(Dali::Scene3D::Light& handle)
201 {
202   CustomActorImpl& customInterface = handle.GetImplementation();
203   Light&           impl            = dynamic_cast<Internal::Light&>(customInterface);
204   return impl;
205 }
206
207 const Light& GetImplementation(const Dali::Scene3D::Light& handle)
208 {
209   const CustomActorImpl& customInterface = handle.GetImplementation();
210   // downcast to control
211   const Light& impl = dynamic_cast<const Internal::Light&>(customInterface);
212   return impl;
213 }
214
215 // Public Method
216
217 uint32_t Light::GetMaximumEnabledLightCount()
218 {
219   return MAX_NUMBER_OF_LIGHT;
220 }
221
222 std::string_view Light::GetLightCountUniformName()
223 {
224   return LIGHT_COUNT_STRING;
225 }
226
227 std::string_view Light::GetLightDirectionUniformName()
228 {
229   return LIGHT_DIRECTION_STRING;
230 }
231
232 std::string_view Light::GetLightColorUniformName()
233 {
234   return LIGHT_COLOR_STRING;
235 }
236
237 } // namespace Internal
238
239 } // namespace Scene3D
240
241 } // namespace Dali