Merge "Klockwork fixes: Distance field iteration Checking for null...
[platform/core/uifw/dali-core.git] / dali / internal / event / actor-attachments / light-attachment-impl.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/event/actor-attachments/light-attachment-impl.h>
20
21 // INTERNAL INCLUDES
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>
25
26 namespace Dali
27 {
28
29 namespace Internal
30 {
31
32 LightAttachmentPtr LightAttachment::New( const SceneGraph::Node& parentNode )
33 {
34   StagePtr stage = Stage::GetCurrent();
35
36   LightAttachmentPtr attachment( new LightAttachment( *stage ) );
37
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 );
42
43   // Keep raw pointer for message passing
44   attachment->mSceneObject = sceneObject;
45
46   return attachment;
47 }
48
49 LightAttachment::LightAttachment( Stage& stage )
50 : ActorAttachment( stage ),
51   mSceneObject( NULL )
52 {
53   mCachedLight = new Internal::Light( "Unnamed" );
54 }
55
56 LightAttachment::~LightAttachment()
57 {
58 }
59
60 void LightAttachment::SetLight( Internal::LightPtr light )
61 {
62   mCachedLight = new Internal::Light(*(light.Get()));
63
64   // sceneObject is being used in a separate thread; queue a message to set
65   SetLightMessage( mStage->GetUpdateInterface(), *mSceneObject, mCachedLight );
66 }
67
68 Internal::LightPtr LightAttachment::GetLight() const
69 {
70   return new Internal::Light(*(mCachedLight.Get()));
71 }
72
73 void LightAttachment::SetName( const std::string& name )
74 {
75   if ( mCachedLight->GetName() != name )
76   {
77     mCachedLight->SetName( name );
78
79     // sceneObject is being used in a separate thread; queue a message to set
80     SetNameMessage( mStage->GetUpdateInterface(), *mSceneObject, name );
81   }
82 }
83
84 const std::string& LightAttachment::GetName() const
85 {
86   return mCachedLight->GetName();
87 }
88
89 void LightAttachment::SetType( Dali::LightType type )
90 {
91   if ( mCachedLight->GetType() != type )
92   {
93     mCachedLight->SetType( type );
94
95     // sceneObject is being used in a separate thread; queue a message to set
96     SetTypeMessage( mStage->GetUpdateInterface(), *mSceneObject, type );
97   }
98 }
99
100 Dali::LightType LightAttachment::GetType() const
101 {
102   return mCachedLight->GetType();
103 }
104
105 void LightAttachment::SetFallOff( const Vector2& fallOff )
106 {
107   if ( mCachedLight->GetFallOff() != fallOff )
108   {
109     mCachedLight->SetFallOff( fallOff );
110
111     // sceneObject is being used in a separate thread; queue a message to set
112     SetFallOffMessage( mStage->GetUpdateInterface(), *mSceneObject, fallOff );
113   }
114 }
115
116 const Vector2& LightAttachment::GetFallOff() const
117 {
118   return mCachedLight->GetFallOff();
119 }
120
121 void LightAttachment::SetSpotAngle( const Vector2& angle )
122 {
123   if ( mCachedLight->GetSpotAngle() != angle )
124   {
125     mCachedLight->SetSpotAngle( angle );
126
127     // sceneObject is being used in a separate thread; queue a message to set
128     SetSpotAngleMessage( mStage->GetUpdateInterface(), *mSceneObject, angle );
129   }
130 }
131
132 const Vector2& LightAttachment::GetSpotAngle() const
133 {
134   return mCachedLight->GetSpotAngle();
135 }
136
137 void LightAttachment::SetAmbientColor( const Vector3& color )
138 {
139   if ( mCachedLight->GetAmbientColor() != color )
140   {
141     mCachedLight->SetAmbientColor( color );
142
143     // sceneObject is being used in a separate thread; queue a message to set
144     SetAmbientColorMessage( mStage->GetUpdateInterface(), *mSceneObject, color );
145   }
146 }
147
148 const Vector3& LightAttachment::GetAmbientColor() const
149 {
150   return mCachedLight->GetAmbientColor();
151 }
152
153 void LightAttachment::SetDiffuseColor( const Vector3& color )
154 {
155   if ( mCachedLight->GetDiffuseColor() != color )
156   {
157     mCachedLight->SetDiffuseColor( color );
158
159     // sceneObject is being used in a separate thread; queue a message to set
160     SetDiffuseColorMessage( mStage->GetUpdateInterface(), *mSceneObject, color );
161   }
162 }
163
164 const Vector3& LightAttachment::GetDiffuseColor() const
165 {
166   return mCachedLight->GetDiffuseColor();
167 }
168
169 void LightAttachment::SetSpecularColor( const Vector3& color )
170 {
171   if ( mCachedLight->GetSpecularColor() != color )
172   {
173     mCachedLight->SetSpecularColor( color );
174
175     // sceneObject is being used in a separate thread; queue a message to set
176     SetSpecularColorMessage( mStage->GetUpdateInterface(), *mSceneObject, color );
177   }
178 }
179
180 const Vector3& LightAttachment::GetSpecularColor() const
181 {
182   return mCachedLight->GetSpecularColor();
183 }
184
185 void LightAttachment::SetDirection( const Vector3& direction )
186 {
187   if ( mCachedLight->GetDirection() != direction )
188   {
189     mCachedLight->SetDirection( direction );
190
191     // sceneObject is being used in a separate thread; queue a message to set
192     SetDirectionMessage( mStage->GetUpdateInterface(), *mSceneObject, direction );
193   }
194 }
195
196 const Vector3& LightAttachment::GetDirection() const
197 {
198   return mCachedLight->GetDirection();
199 }
200
201 void LightAttachment::SetActive( bool active )
202 {
203   // sceneObject is being used in a separate thread; queue a message to set
204   SetActiveMessage( mStage->GetUpdateInterface(), *mSceneObject, active );
205 }
206
207 void LightAttachment::OnStageConnection()
208 {
209   // do nothing
210 }
211
212 void LightAttachment::OnStageDisconnection()
213 {
214   // do nothing
215 }
216
217 } // namespace Internal
218
219 } // namespace Dali