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 )
52 mCachedLight = new Internal::Light( "Unnamed" );
55 LightAttachment::~LightAttachment()
59 void LightAttachment::SetLight( Internal::LightPtr light )
61 mCachedLight = new Internal::Light(*(light.Get()));
63 // sceneObject is being used in a separate thread; queue a message to set
64 SetLightMessage( mStage->GetUpdateInterface(), *mSceneObject, mCachedLight );
67 Internal::LightPtr LightAttachment::GetLight() const
69 return new Internal::Light(*(mCachedLight.Get()));
72 void LightAttachment::SetName( const std::string& name )
74 if ( mCachedLight->GetName() != name )
76 mCachedLight->SetName( name );
78 // sceneObject is being used in a separate thread; queue a message to set
79 SetNameMessage( mStage->GetUpdateInterface(), *mSceneObject, name );
83 const std::string& LightAttachment::GetName() const
85 return mCachedLight->GetName();
88 void LightAttachment::SetType( Dali::LightType type )
90 if ( mCachedLight->GetType() != type )
92 mCachedLight->SetType( type );
94 // sceneObject is being used in a separate thread; queue a message to set
95 SetTypeMessage( mStage->GetUpdateInterface(), *mSceneObject, type );
99 Dali::LightType LightAttachment::GetType() const
101 return mCachedLight->GetType();
104 void LightAttachment::SetFallOff( const Vector2& fallOff )
106 if ( mCachedLight->GetFallOff() != fallOff )
108 mCachedLight->SetFallOff( fallOff );
110 // sceneObject is being used in a separate thread; queue a message to set
111 SetFallOffMessage( mStage->GetUpdateInterface(), *mSceneObject, fallOff );
115 const Vector2& LightAttachment::GetFallOff() const
117 return mCachedLight->GetFallOff();
120 void LightAttachment::SetSpotAngle( const Vector2& angle )
122 if ( mCachedLight->GetSpotAngle() != angle )
124 mCachedLight->SetSpotAngle( angle );
126 // sceneObject is being used in a separate thread; queue a message to set
127 SetSpotAngleMessage( mStage->GetUpdateInterface(), *mSceneObject, angle );
131 const Vector2& LightAttachment::GetSpotAngle() const
133 return mCachedLight->GetSpotAngle();
136 void LightAttachment::SetAmbientColor( const Vector3& color )
138 if ( mCachedLight->GetAmbientColor() != color )
140 mCachedLight->SetAmbientColor( color );
142 // sceneObject is being used in a separate thread; queue a message to set
143 SetAmbientColorMessage( mStage->GetUpdateInterface(), *mSceneObject, color );
147 const Vector3& LightAttachment::GetAmbientColor() const
149 return mCachedLight->GetAmbientColor();
152 void LightAttachment::SetDiffuseColor( const Vector3& color )
154 if ( mCachedLight->GetDiffuseColor() != color )
156 mCachedLight->SetDiffuseColor( color );
158 // sceneObject is being used in a separate thread; queue a message to set
159 SetDiffuseColorMessage( mStage->GetUpdateInterface(), *mSceneObject, color );
163 const Vector3& LightAttachment::GetDiffuseColor() const
165 return mCachedLight->GetDiffuseColor();
168 void LightAttachment::SetSpecularColor( const Vector3& color )
170 if ( mCachedLight->GetSpecularColor() != color )
172 mCachedLight->SetSpecularColor( color );
174 // sceneObject is being used in a separate thread; queue a message to set
175 SetSpecularColorMessage( mStage->GetUpdateInterface(), *mSceneObject, color );
179 const Vector3& LightAttachment::GetSpecularColor() const
181 return mCachedLight->GetSpecularColor();
184 void LightAttachment::SetDirection( const Vector3& direction )
186 if ( mCachedLight->GetDirection() != direction )
188 mCachedLight->SetDirection( direction );
190 // sceneObject is being used in a separate thread; queue a message to set
191 SetDirectionMessage( mStage->GetUpdateInterface(), *mSceneObject, direction );
195 const Vector3& LightAttachment::GetDirection() const
197 return mCachedLight->GetDirection();
200 void LightAttachment::SetActive( bool active )
202 // sceneObject is being used in a separate thread; queue a message to set
203 SetActiveMessage( mStage->GetUpdateInterface(), *mSceneObject, active );
206 void LightAttachment::OnStageConnection()
211 void LightAttachment::OnStageDisconnection()
216 } // namespace Internal