2 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali-scene3d/internal/light/light-impl.h>
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>
27 #include <dali-scene3d/internal/controls/scene-view/scene-view-impl.h>
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");
43 * Creates control through type registry
47 return Scene3D::Light::New();
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
55 Dali::Scene3D::Light Light::New()
57 // Create the implementation, temporarily owned on stack
58 IntrusivePtr<Light> nodeImpl = new Light();
60 // Pass ownership to handle
61 Scene3D::Light handle(*nodeImpl);
63 // Second-phase init of the implementation
64 // This can only be done after the CustomActor connection has been made...
65 nodeImpl->Initialize();
71 : CustomActorImpl(ActorFlags::DISABLE_SIZE_NEGOTIATION)
79 void Light::Initialize()
81 Self().SetProperty(Dali::Actor::Property::COLOR, Color::WHITE);
84 void Light::Enable(bool enable)
86 if(enable == mIsEnabled)
92 Scene3D::SceneView sceneView = mParentSceneView.GetHandle();
100 GetImpl(sceneView).AddLight(Scene3D::Light::DownCast(Self()));
104 GetImpl(sceneView).RemoveLight(Scene3D::Light::DownCast(Self()));
108 bool Light::IsEnabled() const
113 void Light::OnSceneConnection(int depth)
115 Actor parent = Self().GetParent();
118 Scene3D::SceneView sceneView = Scene3D::SceneView::DownCast(parent);
121 mParentSceneView = sceneView;
124 GetImpl(sceneView).AddLight(Scene3D::Light::DownCast(Self()));
128 parent = parent.GetParent();
132 void Light::OnSceneDisconnection()
134 Scene3D::SceneView sceneView = mParentSceneView.GetHandle();
137 mParentSceneView.Reset();
138 GetImpl(sceneView).RemoveLight(Scene3D::Light::DownCast(Self()));
142 void Light::OnChildAdd(Actor& child)
146 void Light::OnChildRemove(Actor& child)
150 void Light::OnSizeSet(const Vector3& targetSize)
154 void Light::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
156 // @todo size negotiate background to new size, animate as well?
159 void Light::OnRelayout(const Vector2& size, RelayoutContainer& container)
163 void Light::OnSetResizePolicy(ResizePolicy::Type policy, Dimension::Type dimension)
167 Vector3 Light::GetNaturalSize()
169 return Vector3::ZERO;
172 float Light::CalculateChildSize(const Dali::Actor& child, Dimension::Type dimension)
177 float Light::GetHeightForWidth(float width)
182 float Light::GetWidthForHeight(float height)
187 bool Light::RelayoutDependentOnChildren(Dimension::Type dimension)
192 void Light::OnCalculateRelayoutSize(Dimension::Type dimension)
196 void Light::OnLayoutNegotiated(float size, Dimension::Type dimension)
200 Light& GetImplementation(Dali::Scene3D::Light& handle)
202 CustomActorImpl& customInterface = handle.GetImplementation();
203 Light& impl = dynamic_cast<Internal::Light&>(customInterface);
207 const Light& GetImplementation(const Dali::Scene3D::Light& handle)
209 const CustomActorImpl& customInterface = handle.GetImplementation();
210 // downcast to control
211 const Light& impl = dynamic_cast<const Internal::Light&>(customInterface);
217 uint32_t Light::GetMaximumEnabledLightCount()
219 return MAX_NUMBER_OF_LIGHT;
222 std::string_view Light::GetLightCountUniformName()
224 return LIGHT_COUNT_STRING;
227 std::string_view Light::GetLightDirectionUniformName()
229 return LIGHT_DIRECTION_STRING;
232 std::string_view Light::GetLightColorUniformName()
234 return LIGHT_COLOR_STRING;
237 } // namespace Internal
239 } // namespace Scene3D