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/actor-attachments/light-attachment-impl.h>
21 #include <dali/public-api/common/dali-common.h>
22 #include <dali/internal/event/common/stage-impl.h>
23 #include <dali/internal/update/node-attachments/scene-graph-light-attachment.h>
31 LightAttachmentPtr LightAttachment::New( const SceneGraph::Node& parentNode )
33 StagePtr stage = Stage::GetCurrent();
35 LightAttachmentPtr attachment( new LightAttachment( *stage ) );
37 // Transfer object ownership of scene-object to message
38 SceneGraph::LightAttachment* sceneObject = SceneGraph::LightAttachment::New();
39 sceneObject->SetLight( attachment->mCachedLight );
40 AttachToNodeMessage( stage->GetUpdateManager(), parentNode, sceneObject );
42 // Keep raw pointer for message passing
43 attachment->mSceneObject = sceneObject;
48 LightAttachment::LightAttachment( Stage& stage )
49 : ActorAttachment( stage )
51 mCachedLight = new Internal::Light( "Unnamed" );
54 LightAttachment::~LightAttachment()
58 void LightAttachment::SetLight( Internal::LightPtr light )
60 mCachedLight = new Internal::Light(*(light.Get()));
62 // sceneObject is being used in a separate thread; queue a message to set
63 SetLightMessage( mStage->GetUpdateInterface(), *mSceneObject, mCachedLight );
66 Internal::LightPtr LightAttachment::GetLight() const
68 return new Internal::Light(*(mCachedLight.Get()));
71 void LightAttachment::SetName( const std::string& name )
73 if ( mCachedLight->GetName() != name )
75 mCachedLight->SetName( name );
77 // sceneObject is being used in a separate thread; queue a message to set
78 SetNameMessage( mStage->GetUpdateInterface(), *mSceneObject, name );
82 const std::string& LightAttachment::GetName() const
84 return mCachedLight->GetName();
87 void LightAttachment::SetType( Dali::LightType type )
89 if ( mCachedLight->GetType() != type )
91 mCachedLight->SetType( type );
93 // sceneObject is being used in a separate thread; queue a message to set
94 SetTypeMessage( mStage->GetUpdateInterface(), *mSceneObject, type );
98 Dali::LightType LightAttachment::GetType() const
100 return mCachedLight->GetType();
103 void LightAttachment::SetFallOff( const Vector2& fallOff )
105 if ( mCachedLight->GetFallOff() != fallOff )
107 mCachedLight->SetFallOff( fallOff );
109 // sceneObject is being used in a separate thread; queue a message to set
110 SetFallOffMessage( mStage->GetUpdateInterface(), *mSceneObject, fallOff );
114 const Vector2& LightAttachment::GetFallOff() const
116 return mCachedLight->GetFallOff();
119 void LightAttachment::SetSpotAngle( const Vector2& angle )
121 if ( mCachedLight->GetSpotAngle() != angle )
123 mCachedLight->SetSpotAngle( angle );
125 // sceneObject is being used in a separate thread; queue a message to set
126 SetSpotAngleMessage( mStage->GetUpdateInterface(), *mSceneObject, angle );
130 const Vector2& LightAttachment::GetSpotAngle() const
132 return mCachedLight->GetSpotAngle();
135 void LightAttachment::SetAmbientColor( const Vector3& color )
137 if ( mCachedLight->GetAmbientColor() != color )
139 mCachedLight->SetAmbientColor( color );
141 // sceneObject is being used in a separate thread; queue a message to set
142 SetAmbientColorMessage( mStage->GetUpdateInterface(), *mSceneObject, color );
146 const Vector3& LightAttachment::GetAmbientColor() const
148 return mCachedLight->GetAmbientColor();
151 void LightAttachment::SetDiffuseColor( const Vector3& color )
153 if ( mCachedLight->GetDiffuseColor() != color )
155 mCachedLight->SetDiffuseColor( color );
157 // sceneObject is being used in a separate thread; queue a message to set
158 SetDiffuseColorMessage( mStage->GetUpdateInterface(), *mSceneObject, color );
162 const Vector3& LightAttachment::GetDiffuseColor() const
164 return mCachedLight->GetDiffuseColor();
167 void LightAttachment::SetSpecularColor( const Vector3& color )
169 if ( mCachedLight->GetSpecularColor() != color )
171 mCachedLight->SetSpecularColor( color );
173 // sceneObject is being used in a separate thread; queue a message to set
174 SetSpecularColorMessage( mStage->GetUpdateInterface(), *mSceneObject, color );
178 const Vector3& LightAttachment::GetSpecularColor() const
180 return mCachedLight->GetSpecularColor();
183 void LightAttachment::SetDirection( const Vector3& direction )
185 if ( mCachedLight->GetDirection() != direction )
187 mCachedLight->SetDirection( direction );
189 // sceneObject is being used in a separate thread; queue a message to set
190 SetDirectionMessage( mStage->GetUpdateInterface(), *mSceneObject, direction );
194 const Vector3& LightAttachment::GetDirection() const
196 return mCachedLight->GetDirection();
199 void LightAttachment::SetActive( bool active )
201 // sceneObject is being used in a separate thread; queue a message to set
202 SetActiveMessage( mStage->GetUpdateInterface(), *mSceneObject, active );
205 void LightAttachment::OnStageConnection()
210 void LightAttachment::OnStageDisconnection()
215 } // namespace Internal