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