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/actor-attachments/light-attachment-impl.h>
22 #include <dali/public-api/common/dali-common.h>
23 #include <dali/internal/event/common/stage-impl.h>
24 #include <dali/internal/update/node-attachments/scene-graph-light-attachment.h>
32 LightAttachmentPtr LightAttachment::New( const SceneGraph::Node& parentNode )
34 StagePtr stage = Stage::GetCurrent();
36 LightAttachmentPtr attachment( new LightAttachment( *stage ) );
38 // Transfer object ownership of scene-object to message
39 SceneGraph::LightAttachment* sceneObject = SceneGraph::LightAttachment::New();
40 sceneObject->SetLight( attachment->mCachedLight );
41 AttachToNodeMessage( stage->GetUpdateManager(), parentNode, sceneObject );
43 // Keep raw pointer for message passing
44 attachment->mSceneObject = sceneObject;
49 LightAttachment::LightAttachment( Stage& stage )
50 : ActorAttachment( stage ),
53 mCachedLight = new Internal::Light( "Unnamed" );
56 LightAttachment::~LightAttachment()
60 void LightAttachment::SetLight( Internal::LightPtr light )
62 mCachedLight = new Internal::Light(*(light.Get()));
64 // sceneObject is being used in a separate thread; queue a message to set
65 SetLightMessage( mStage->GetUpdateInterface(), *mSceneObject, mCachedLight );
68 Internal::LightPtr LightAttachment::GetLight() const
70 return new Internal::Light(*(mCachedLight.Get()));
73 void LightAttachment::SetName( const std::string& name )
75 if ( mCachedLight->GetName() != name )
77 mCachedLight->SetName( name );
79 // sceneObject is being used in a separate thread; queue a message to set
80 SetNameMessage( mStage->GetUpdateInterface(), *mSceneObject, name );
84 const std::string& LightAttachment::GetName() const
86 return mCachedLight->GetName();
89 void LightAttachment::SetType( Dali::LightType type )
91 if ( mCachedLight->GetType() != type )
93 mCachedLight->SetType( type );
95 // sceneObject is being used in a separate thread; queue a message to set
96 SetTypeMessage( mStage->GetUpdateInterface(), *mSceneObject, type );
100 Dali::LightType LightAttachment::GetType() const
102 return mCachedLight->GetType();
105 void LightAttachment::SetFallOff( const Vector2& fallOff )
107 if ( mCachedLight->GetFallOff() != fallOff )
109 mCachedLight->SetFallOff( fallOff );
111 // sceneObject is being used in a separate thread; queue a message to set
112 SetFallOffMessage( mStage->GetUpdateInterface(), *mSceneObject, fallOff );
116 const Vector2& LightAttachment::GetFallOff() const
118 return mCachedLight->GetFallOff();
121 void LightAttachment::SetSpotAngle( const Vector2& angle )
123 if ( mCachedLight->GetSpotAngle() != angle )
125 mCachedLight->SetSpotAngle( angle );
127 // sceneObject is being used in a separate thread; queue a message to set
128 SetSpotAngleMessage( mStage->GetUpdateInterface(), *mSceneObject, angle );
132 const Vector2& LightAttachment::GetSpotAngle() const
134 return mCachedLight->GetSpotAngle();
137 void LightAttachment::SetAmbientColor( const Vector3& color )
139 if ( mCachedLight->GetAmbientColor() != color )
141 mCachedLight->SetAmbientColor( color );
143 // sceneObject is being used in a separate thread; queue a message to set
144 SetAmbientColorMessage( mStage->GetUpdateInterface(), *mSceneObject, color );
148 const Vector3& LightAttachment::GetAmbientColor() const
150 return mCachedLight->GetAmbientColor();
153 void LightAttachment::SetDiffuseColor( const Vector3& color )
155 if ( mCachedLight->GetDiffuseColor() != color )
157 mCachedLight->SetDiffuseColor( color );
159 // sceneObject is being used in a separate thread; queue a message to set
160 SetDiffuseColorMessage( mStage->GetUpdateInterface(), *mSceneObject, color );
164 const Vector3& LightAttachment::GetDiffuseColor() const
166 return mCachedLight->GetDiffuseColor();
169 void LightAttachment::SetSpecularColor( const Vector3& color )
171 if ( mCachedLight->GetSpecularColor() != color )
173 mCachedLight->SetSpecularColor( color );
175 // sceneObject is being used in a separate thread; queue a message to set
176 SetSpecularColorMessage( mStage->GetUpdateInterface(), *mSceneObject, color );
180 const Vector3& LightAttachment::GetSpecularColor() const
182 return mCachedLight->GetSpecularColor();
185 void LightAttachment::SetDirection( const Vector3& direction )
187 if ( mCachedLight->GetDirection() != direction )
189 mCachedLight->SetDirection( direction );
191 // sceneObject is being used in a separate thread; queue a message to set
192 SetDirectionMessage( mStage->GetUpdateInterface(), *mSceneObject, direction );
196 const Vector3& LightAttachment::GetDirection() const
198 return mCachedLight->GetDirection();
201 void LightAttachment::SetActive( bool active )
203 // sceneObject is being used in a separate thread; queue a message to set
204 SetActiveMessage( mStage->GetUpdateInterface(), *mSceneObject, active );
207 void LightAttachment::OnStageConnection()
212 void LightAttachment::OnStageDisconnection()
217 } // namespace Internal