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 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 {
52   mCachedLight = new Internal::Light( "Unnamed" );
53 }
54
55 LightAttachment::~LightAttachment()
56 {
57 }
58
59 void LightAttachment::SetLight( Internal::LightPtr light )
60 {
61   mCachedLight = new Internal::Light(*(light.Get()));
62
63   // sceneObject is being used in a separate thread; queue a message to set
64   SetLightMessage( mStage->GetUpdateInterface(), *mSceneObject, mCachedLight );
65 }
66
67 Internal::LightPtr LightAttachment::GetLight() const
68 {
69   return new Internal::Light(*(mCachedLight.Get()));
70 }
71
72 void LightAttachment::SetName( const std::string& name )
73 {
74   if ( mCachedLight->GetName() != name )
75   {
76     mCachedLight->SetName( name );
77
78     // sceneObject is being used in a separate thread; queue a message to set
79     SetNameMessage( mStage->GetUpdateInterface(), *mSceneObject, name );
80   }
81 }
82
83 const std::string& LightAttachment::GetName() const
84 {
85   return mCachedLight->GetName();
86 }
87
88 void LightAttachment::SetType( Dali::LightType type )
89 {
90   if ( mCachedLight->GetType() != type )
91   {
92     mCachedLight->SetType( type );
93
94     // sceneObject is being used in a separate thread; queue a message to set
95     SetTypeMessage( mStage->GetUpdateInterface(), *mSceneObject, type );
96   }
97 }
98
99 Dali::LightType LightAttachment::GetType() const
100 {
101   return mCachedLight->GetType();
102 }
103
104 void LightAttachment::SetFallOff( const Vector2& fallOff )
105 {
106   if ( mCachedLight->GetFallOff() != fallOff )
107   {
108     mCachedLight->SetFallOff( fallOff );
109
110     // sceneObject is being used in a separate thread; queue a message to set
111     SetFallOffMessage( mStage->GetUpdateInterface(), *mSceneObject, fallOff );
112   }
113 }
114
115 const Vector2& LightAttachment::GetFallOff() const
116 {
117   return mCachedLight->GetFallOff();
118 }
119
120 void LightAttachment::SetSpotAngle( const Vector2& angle )
121 {
122   if ( mCachedLight->GetSpotAngle() != angle )
123   {
124     mCachedLight->SetSpotAngle( angle );
125
126     // sceneObject is being used in a separate thread; queue a message to set
127     SetSpotAngleMessage( mStage->GetUpdateInterface(), *mSceneObject, angle );
128   }
129 }
130
131 const Vector2& LightAttachment::GetSpotAngle() const
132 {
133   return mCachedLight->GetSpotAngle();
134 }
135
136 void LightAttachment::SetAmbientColor( const Vector3& color )
137 {
138   if ( mCachedLight->GetAmbientColor() != color )
139   {
140     mCachedLight->SetAmbientColor( color );
141
142     // sceneObject is being used in a separate thread; queue a message to set
143     SetAmbientColorMessage( mStage->GetUpdateInterface(), *mSceneObject, color );
144   }
145 }
146
147 const Vector3& LightAttachment::GetAmbientColor() const
148 {
149   return mCachedLight->GetAmbientColor();
150 }
151
152 void LightAttachment::SetDiffuseColor( const Vector3& color )
153 {
154   if ( mCachedLight->GetDiffuseColor() != color )
155   {
156     mCachedLight->SetDiffuseColor( color );
157
158     // sceneObject is being used in a separate thread; queue a message to set
159     SetDiffuseColorMessage( mStage->GetUpdateInterface(), *mSceneObject, color );
160   }
161 }
162
163 const Vector3& LightAttachment::GetDiffuseColor() const
164 {
165   return mCachedLight->GetDiffuseColor();
166 }
167
168 void LightAttachment::SetSpecularColor( const Vector3& color )
169 {
170   if ( mCachedLight->GetSpecularColor() != color )
171   {
172     mCachedLight->SetSpecularColor( color );
173
174     // sceneObject is being used in a separate thread; queue a message to set
175     SetSpecularColorMessage( mStage->GetUpdateInterface(), *mSceneObject, color );
176   }
177 }
178
179 const Vector3& LightAttachment::GetSpecularColor() const
180 {
181   return mCachedLight->GetSpecularColor();
182 }
183
184 void LightAttachment::SetDirection( const Vector3& direction )
185 {
186   if ( mCachedLight->GetDirection() != direction )
187   {
188     mCachedLight->SetDirection( direction );
189
190     // sceneObject is being used in a separate thread; queue a message to set
191     SetDirectionMessage( mStage->GetUpdateInterface(), *mSceneObject, direction );
192   }
193 }
194
195 const Vector3& LightAttachment::GetDirection() const
196 {
197   return mCachedLight->GetDirection();
198 }
199
200 void LightAttachment::SetActive( bool active )
201 {
202   // sceneObject is being used in a separate thread; queue a message to set
203   SetActiveMessage( mStage->GetUpdateInterface(), *mSceneObject, active );
204 }
205
206 void LightAttachment::OnStageConnection()
207 {
208   // do nothing
209 }
210
211 void LightAttachment::OnStageDisconnection()
212 {
213   // do nothing
214 }
215
216 } // namespace Internal
217
218 } // namespace Dali