2 * Copyright (c) 2014 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/internal/event/actors/light-actor-impl.h>
22 #include <dali/public-api/object/type-registry.h>
23 #include <dali/integration-api/debug.h>
24 #include <dali/internal/event/common/property-index-ranges.h>
29 const Property::Index LightActor::LIGHT_TYPE = Internal::DEFAULT_ACTOR_PROPERTY_MAX_COUNT;
30 const Property::Index LightActor::ENABLE = Internal::DEFAULT_ACTOR_PROPERTY_MAX_COUNT + 1;
31 const Property::Index LightActor::FALL_OFF = Internal::DEFAULT_ACTOR_PROPERTY_MAX_COUNT + 2;
32 const Property::Index LightActor::SPOT_ANGLE = Internal::DEFAULT_ACTOR_PROPERTY_MAX_COUNT + 3;
33 const Property::Index LightActor::AMBIENT_COLOR = Internal::DEFAULT_ACTOR_PROPERTY_MAX_COUNT + 4;
34 const Property::Index LightActor::DIFFUSE_COLOR = Internal::DEFAULT_ACTOR_PROPERTY_MAX_COUNT + 5;
35 const Property::Index LightActor::SPECULAR_COLOR = Internal::DEFAULT_ACTOR_PROPERTY_MAX_COUNT + 6;
36 const Property::Index LightActor::DIRECTION = Internal::DEFAULT_ACTOR_PROPERTY_MAX_COUNT + 7;
46 return Dali::LightActor::New();
49 TypeRegistration mType( typeid(Dali::LightActor), typeid(Dali::Actor), Create );
51 const Internal::PropertyDetails DEFAULT_LIGHT_ACTOR_PROPERTY_DETAILS[] =
53 // Name Type writable animatable constraint-input
54 { "light-type", Property::STRING, true, false, true }, // LIGHT_TYPE
55 { "enable", Property::BOOLEAN, true, false, true }, // ENABLE
56 { "fall-off", Property::VECTOR2, true, false, true }, // FALL_OFF
57 { "spot-angle", Property::VECTOR2, true, false, true }, // SPOT_ANGLE
58 { "ambient-color", Property::VECTOR3, true, false, true }, // AMBIENT_COLOR
59 { "diffuse-color", Property::VECTOR3, true, false, true }, // DIFFUSE_COLOR
60 { "specular-color", Property::VECTOR3, true, false, true }, // SPECULAR_COLOR
61 { "direction", Property::VECTOR3, true, false, true }, // DIRECTION
63 const int DEFAULT_LIGHT_ACTOR_PROPERTY_COUNT = sizeof( DEFAULT_LIGHT_ACTOR_PROPERTY_DETAILS ) / sizeof( Internal::PropertyDetails );
65 LightType LightTypeEnum(const std::string &stringValue)
67 LightType ret(AMBIENT);
69 if(stringValue == "AMBIENT")
73 else if(stringValue == "DIRECTIONAL")
77 else if(stringValue == "SPOT")
81 else if(stringValue == "POINT")
87 DALI_LOG_WARNING("Unknown Light Type:%s\n", stringValue.c_str());
93 std::string LightTypeString(const LightType type)
95 std::string ret("AMBIENT");
128 LightActorPtr LightActor::New()
130 LightActorPtr actor(new LightActor());
132 // Second-phase construction
136 // Create the attachment
137 actor->mLightAttachment = LightAttachment::New( *actor->mNode );
138 actor->Attach(*actor->mLightAttachment);
139 actor->mLightAttachment->SetName(actor->GetName());
145 void LightActor::OnInitialize()
149 LightActor::LightActor()
150 : Actor( Actor::BASIC ),
155 LightActor::~LightActor()
159 void LightActor::SetLight(Dali::Light light)
161 Internal::LightPtr lightPtr(&GetImplementation(light));
162 mLightAttachment->SetLight(lightPtr);
163 mLightAttachment->SetActive(true);
166 Dali::Light LightActor::GetLight() const
168 Internal::LightPtr lightPtr(mLightAttachment->GetLight());
169 return Dali::Light(lightPtr.Get());
172 void LightActor::SetActive(bool active)
174 mLightAttachment->SetActive(active);
178 bool LightActor::GetActive()
183 unsigned int LightActor::GetDefaultPropertyCount() const
185 return Actor::GetDefaultPropertyCount() + DEFAULT_LIGHT_ACTOR_PROPERTY_COUNT;
188 void LightActor::GetDefaultPropertyIndices( Property::IndexContainer& indices ) const
190 Actor::GetDefaultPropertyIndices( indices ); // Actor class properties
192 indices.reserve( indices.size() + DEFAULT_LIGHT_ACTOR_PROPERTY_COUNT );
194 int index = DEFAULT_ACTOR_PROPERTY_MAX_COUNT;
195 for ( int i = 0; i < DEFAULT_LIGHT_ACTOR_PROPERTY_COUNT; ++i, ++index )
197 indices.push_back( index );
201 bool LightActor::IsDefaultPropertyWritable( Property::Index index ) const
203 if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT)
205 return Actor::IsDefaultPropertyWritable(index) ;
209 return true; // all properties are writable
213 bool LightActor::IsDefaultPropertyAnimatable( Property::Index index ) const
215 if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT)
217 return Actor::IsDefaultPropertyAnimatable(index) ;
221 return false; // all properties are non animateable
225 bool LightActor::IsDefaultPropertyAConstraintInput( Property::Index index ) const
227 if( index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT )
229 return Actor::IsDefaultPropertyAConstraintInput(index);
231 return true; // Our properties can be used as input to constraints.
234 Property::Type LightActor::GetDefaultPropertyType( Property::Index index ) const
236 if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT)
238 return Actor::GetDefaultPropertyType(index) ;
242 index -= DEFAULT_ACTOR_PROPERTY_MAX_COUNT;
244 if ( ( index >= 0 ) && ( index < DEFAULT_LIGHT_ACTOR_PROPERTY_COUNT ) )
246 return DEFAULT_LIGHT_ACTOR_PROPERTY_DETAILS[index].type;
250 // index out-of-bounds
251 return Property::NONE;
256 const char* LightActor::GetDefaultPropertyName( Property::Index index ) const
258 if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT)
260 return Actor::GetDefaultPropertyName(index) ;
264 index -= DEFAULT_ACTOR_PROPERTY_MAX_COUNT;
266 if ( ( index >= 0 ) && ( index < DEFAULT_LIGHT_ACTOR_PROPERTY_COUNT ) )
268 return DEFAULT_LIGHT_ACTOR_PROPERTY_DETAILS[index].name;
277 Property::Index LightActor::GetDefaultPropertyIndex(const std::string& name) const
279 Property::Index index = Property::INVALID_INDEX;
281 // Look for name in current class' default properties
282 for( int i = 0; i < DEFAULT_LIGHT_ACTOR_PROPERTY_COUNT; ++i )
284 const Internal::PropertyDetails* property = &DEFAULT_LIGHT_ACTOR_PROPERTY_DETAILS[ i ];
285 if( 0 == strcmp( name.c_str(), property->name ) ) // dont want to convert rhs to string
287 index = i + DEFAULT_ACTOR_PROPERTY_MAX_COUNT;
292 // If not found, check in base class
293 if( Property::INVALID_INDEX == index )
295 index = Actor::GetDefaultPropertyIndex( name );
301 void LightActor::SetDefaultProperty( Property::Index index, const Property::Value& propertyValue )
303 if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT)
305 Actor::SetDefaultProperty(index, propertyValue) ;
311 case Dali::LightActor::LIGHT_TYPE:
313 mLightAttachment->SetType(LightTypeEnum(propertyValue.Get<std::string>()));
316 case Dali::LightActor::ENABLE:
318 SetActive(propertyValue.Get<bool>());
321 case Dali::LightActor::FALL_OFF:
323 mLightAttachment->SetFallOff(propertyValue.Get<Vector2>());
326 case Dali::LightActor::SPOT_ANGLE:
328 mLightAttachment->SetSpotAngle(propertyValue.Get<Vector2>());
331 case Dali::LightActor::AMBIENT_COLOR:
333 mLightAttachment->SetAmbientColor(propertyValue.Get<Vector3>());
336 case Dali::LightActor::DIFFUSE_COLOR:
338 mLightAttachment->SetDiffuseColor(propertyValue.Get<Vector3>());
341 case Dali::LightActor::SPECULAR_COLOR:
343 mLightAttachment->SetSpecularColor(propertyValue.Get<Vector3>());
346 case Dali::LightActor::DIRECTION:
348 mLightAttachment->SetDirection(propertyValue.Get<Vector3>());
353 DALI_LOG_WARNING("Unknown property (%d)\n", index);
361 Property::Value LightActor::GetDefaultProperty( Property::Index index ) const
363 Property::Value ret ;
364 if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT)
366 ret = Actor::GetDefaultProperty(index) ;
372 case Dali::LightActor::LIGHT_TYPE:
374 ret = LightTypeString(mLightAttachment->GetType());
377 case Dali::LightActor::ENABLE:
382 case Dali::LightActor::FALL_OFF:
384 ret = mLightAttachment->GetFallOff();
387 case Dali::LightActor::SPOT_ANGLE:
389 ret = mLightAttachment->GetSpotAngle();
392 case Dali::LightActor::AMBIENT_COLOR:
394 ret = mLightAttachment->GetAmbientColor();
397 case Dali::LightActor::DIFFUSE_COLOR:
399 ret = mLightAttachment->GetDiffuseColor();
402 case Dali::LightActor::SPECULAR_COLOR:
404 ret = mLightAttachment->GetSpecularColor();
407 case Dali::LightActor::DIRECTION:
409 ret = mLightAttachment->GetDirection();
414 DALI_LOG_WARNING("Unknown property (%d)\n", index);
424 } // namespace Internal