2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.
18 #include <dali/internal/event/actors/light-actor-impl.h>
21 #include <dali/public-api/object/type-registry.h>
22 #include <dali/integration-api/debug.h>
23 #include <dali/internal/event/common/property-index-ranges.h>
28 const Property::Index LightActor::LIGHT_TYPE = Internal::DEFAULT_ACTOR_PROPERTY_MAX_COUNT;
29 const Property::Index LightActor::ENABLE = Internal::DEFAULT_ACTOR_PROPERTY_MAX_COUNT + 1;
30 const Property::Index LightActor::FALL_OFF = Internal::DEFAULT_ACTOR_PROPERTY_MAX_COUNT + 2;
31 const Property::Index LightActor::SPOT_ANGLE = Internal::DEFAULT_ACTOR_PROPERTY_MAX_COUNT + 3;
32 const Property::Index LightActor::AMBIENT_COLOR = Internal::DEFAULT_ACTOR_PROPERTY_MAX_COUNT + 4;
33 const Property::Index LightActor::DIFFUSE_COLOR = Internal::DEFAULT_ACTOR_PROPERTY_MAX_COUNT + 5;
34 const Property::Index LightActor::SPECULAR_COLOR = Internal::DEFAULT_ACTOR_PROPERTY_MAX_COUNT + 6;
35 const Property::Index LightActor::DIRECTION = Internal::DEFAULT_ACTOR_PROPERTY_MAX_COUNT + 7;
39 bool LightActor::mFirstInstance = true ;
40 Actor::DefaultPropertyLookup* LightActor::mDefaultLightActorPropertyLookup = NULL;
47 return Dali::LightActor::New();
50 TypeRegistration mType( typeid(Dali::LightActor), typeid(Dali::Actor), Create );
52 const std::string DEFAULT_LIGHT_ACTOR_PROPERTY_NAMES[] =
63 const int DEFAULT_LIGHT_ACTOR_PROPERTY_COUNT = sizeof( DEFAULT_LIGHT_ACTOR_PROPERTY_NAMES ) / sizeof( std::string );
65 const Property::Type DEFAULT_LIGHT_ACTOR_PROPERTY_TYPES[DEFAULT_LIGHT_ACTOR_PROPERTY_COUNT] =
67 Property::STRING, // "light-type",
68 Property::VECTOR2, // "enable",
69 Property::VECTOR2, // "fall-off",
70 Property::VECTOR2, // "spot-angle",
71 Property::VECTOR3, // "ambient-color",
72 Property::VECTOR3, // "diffuse-color",
73 Property::VECTOR3, // "specular-color",
74 Property::VECTOR3, // "direction",
78 LightType LightTypeEnum(const std::string &stringValue)
80 LightType ret(AMBIENT);
82 if(stringValue == "AMBIENT")
86 else if(stringValue == "DIRECTIONAL")
90 else if(stringValue == "SPOT")
94 else if(stringValue == "POINT")
100 DALI_LOG_WARNING("Unknown Light Type:%s\n", stringValue.c_str());
106 std::string LightTypeString(const LightType type)
108 std::string ret("AMBIENT");
141 LightActorPtr LightActor::New()
143 LightActorPtr actor(new LightActor());
145 // Second-phase construction
149 // Create the attachment
150 actor->mLightAttachment = LightAttachment::New( *actor->mNode );
151 actor->Attach(*actor->mLightAttachment);
152 actor->mLightAttachment->SetName(actor->GetName());
158 void LightActor::OnInitialize()
160 if(LightActor::mFirstInstance)
162 mDefaultLightActorPropertyLookup = new DefaultPropertyLookup();
163 const int start = DEFAULT_ACTOR_PROPERTY_MAX_COUNT;
164 for ( int i = 0; i < DEFAULT_LIGHT_ACTOR_PROPERTY_COUNT; ++i )
166 (*mDefaultLightActorPropertyLookup)[DEFAULT_LIGHT_ACTOR_PROPERTY_NAMES[i]] = i + start;
168 LightActor::mFirstInstance = false ;
172 LightActor::LightActor()
173 : Actor( Actor::BASIC ),
178 LightActor::~LightActor()
182 void LightActor::SetLight(Dali::Light light)
184 Internal::LightPtr lightPtr(&GetImplementation(light));
185 mLightAttachment->SetLight(lightPtr);
186 mLightAttachment->SetActive(true);
189 Dali::Light LightActor::GetLight() const
191 Internal::LightPtr lightPtr(mLightAttachment->GetLight());
192 return Dali::Light(lightPtr.Get());
195 void LightActor::SetActive(bool active)
197 mLightAttachment->SetActive(active);
201 bool LightActor::GetActive()
206 unsigned int LightActor::GetDefaultPropertyCount() const
208 return Actor::GetDefaultPropertyCount() + DEFAULT_LIGHT_ACTOR_PROPERTY_COUNT;
211 void LightActor::GetDefaultPropertyIndices( Property::IndexContainer& indices ) const
213 Actor::GetDefaultPropertyIndices( indices ); // Actor class properties
215 indices.reserve( indices.size() + DEFAULT_LIGHT_ACTOR_PROPERTY_COUNT );
217 int index = DEFAULT_ACTOR_PROPERTY_MAX_COUNT;
218 for ( int i = 0; i < DEFAULT_LIGHT_ACTOR_PROPERTY_COUNT; ++i, ++index )
220 indices.push_back( index );
224 bool LightActor::IsDefaultPropertyWritable( Property::Index index ) const
226 if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT)
228 return Actor::IsDefaultPropertyWritable(index) ;
236 bool LightActor::IsDefaultPropertyAnimatable( Property::Index index ) const
238 if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT)
240 return Actor::IsDefaultPropertyAnimatable(index) ;
248 bool LightActor::IsDefaultPropertyAConstraintInput( Property::Index index ) const
250 if( index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT )
252 return Actor::IsDefaultPropertyAConstraintInput(index);
254 return true; // Our properties can be used as input to constraints.
257 Property::Type LightActor::GetDefaultPropertyType( Property::Index index ) const
259 if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT)
261 return Actor::GetDefaultPropertyType(index) ;
265 index -= DEFAULT_ACTOR_PROPERTY_MAX_COUNT;
267 if ( ( index >= 0 ) && ( index < DEFAULT_LIGHT_ACTOR_PROPERTY_COUNT ) )
269 return DEFAULT_LIGHT_ACTOR_PROPERTY_TYPES[index];
273 // index out-of-bounds
274 return Property::NONE;
279 const std::string& LightActor::GetDefaultPropertyName( Property::Index index ) const
281 if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT)
283 return Actor::GetDefaultPropertyName(index) ;
287 index -= DEFAULT_ACTOR_PROPERTY_MAX_COUNT;
289 if ( ( index >= 0 ) && ( index < DEFAULT_LIGHT_ACTOR_PROPERTY_COUNT ) )
291 return DEFAULT_LIGHT_ACTOR_PROPERTY_NAMES[index];
295 // index out-of-bounds
296 static const std::string INVALID_PROPERTY_NAME;
297 return INVALID_PROPERTY_NAME;
302 Property::Index LightActor::GetDefaultPropertyIndex(const std::string& name) const
304 Property::Index index = Property::INVALID_INDEX;
306 DALI_ASSERT_DEBUG( NULL != mDefaultLightActorPropertyLookup );
308 // Look for name in current class' default properties
309 DefaultPropertyLookup::const_iterator result = mDefaultLightActorPropertyLookup->find( name );
310 if ( mDefaultLightActorPropertyLookup->end() != result )
312 index = result->second;
316 // If not found, check in base class
317 index = Actor::GetDefaultPropertyIndex( name );
323 void LightActor::SetDefaultProperty( Property::Index index, const Property::Value& propertyValue )
325 if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT)
327 Actor::SetDefaultProperty(index, propertyValue) ;
333 case Dali::LightActor::LIGHT_TYPE:
335 mLightAttachment->SetType(LightTypeEnum(propertyValue.Get<std::string>()));
338 case Dali::LightActor::ENABLE:
340 SetActive(propertyValue.Get<bool>());
343 case Dali::LightActor::FALL_OFF:
345 mLightAttachment->SetFallOff(propertyValue.Get<Vector2>());
348 case Dali::LightActor::SPOT_ANGLE:
350 mLightAttachment->SetSpotAngle(propertyValue.Get<Vector2>());
353 case Dali::LightActor::AMBIENT_COLOR:
355 mLightAttachment->SetAmbientColor(propertyValue.Get<Vector3>());
358 case Dali::LightActor::DIFFUSE_COLOR:
360 mLightAttachment->SetDiffuseColor(propertyValue.Get<Vector3>());
363 case Dali::LightActor::SPECULAR_COLOR:
365 mLightAttachment->SetSpecularColor(propertyValue.Get<Vector3>());
368 case Dali::LightActor::DIRECTION:
370 mLightAttachment->SetDirection(propertyValue.Get<Vector3>());
375 DALI_LOG_WARNING("Unknown property (%d)\n", index);
383 Property::Value LightActor::GetDefaultProperty( Property::Index index ) const
385 Property::Value ret ;
386 if(index < DEFAULT_ACTOR_PROPERTY_MAX_COUNT)
388 ret = Actor::GetDefaultProperty(index) ;
394 case Dali::LightActor::LIGHT_TYPE:
396 ret = LightTypeString(mLightAttachment->GetType());
399 case Dali::LightActor::ENABLE:
404 case Dali::LightActor::FALL_OFF:
406 ret = mLightAttachment->GetFallOff();
409 case Dali::LightActor::SPOT_ANGLE:
411 ret = mLightAttachment->GetSpotAngle();
414 case Dali::LightActor::AMBIENT_COLOR:
416 ret = mLightAttachment->GetAmbientColor();
419 case Dali::LightActor::DIFFUSE_COLOR:
421 ret = mLightAttachment->GetDiffuseColor();
424 case Dali::LightActor::SPECULAR_COLOR:
426 ret = mLightAttachment->GetSpecularColor();
429 case Dali::LightActor::DIRECTION:
431 ret = mLightAttachment->GetDirection();
436 DALI_LOG_WARNING("Unknown property (%d)\n", index);
446 } // namespace Internal