Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / effects / runtime / FUiEffects_RuntimeUnitLight.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://floralicense.org/license/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 /**
18  * @file        FUiEffects_RuntimeUnitLight.cpp
19  * @brief       This file contains an implementation of UnitLight class methods
20  *
21  */
22
23 #include <FBaseSysLog.h>
24 #include <FUiEffects_EffectErrorMessages.h>
25 #include <FUiEffects_RuntimeUnitLight.h>
26
27 using namespace Tizen::Ui::Effects::_Utils;
28 using namespace std;
29
30 namespace Tizen { namespace Ui { namespace Effects { namespace _Runtime
31 {
32
33 UnitLight::ObjectsPool UnitLight::__objectsPool = UnitLight::ObjectsPool();
34
35 UnitLight::UnitLight(const string& name) :
36                         isEnabledChanged(false)
37                         , isColourChanged(false)
38                         , isIntensityChanged(false)
39                         , isSomethingChanged(false)
40                         , __enabled(true)
41                         , __name(name)
42                         , __colour(1.f, 0.f, 0.f)
43                         , __intensity(1.f)
44 {
45
46 }
47
48 UnitLight::UnitLight(bool enabled,
49                                         const string& name,
50                                         const Vec3f& colour,
51                                         float intensity) :
52                                                 isEnabledChanged(false)
53                                                 , isColourChanged(false)
54                                                 , isIntensityChanged(false)
55                                                 , isSomethingChanged(false)
56                                                 , __enabled(enabled)
57                                                 , __name(name)
58                                                 , __colour(colour)
59                                                 , __intensity(intensity)
60 {
61
62 }
63
64 UnitLight::~UnitLight(void)
65 {
66
67 }
68
69 bool
70 UnitLight::GetEnabled(void) const
71 {
72         return __enabled;
73 }
74
75 const Vec3f&
76 UnitLight::GetColour(void) const
77 {
78         return __colour;
79 }
80
81 float
82 UnitLight::GetIntensity(void) const
83 {
84         return __intensity;
85 }
86
87 const string&
88 UnitLight::GetName(void) const
89 {
90         return __name;
91 }
92
93 void
94 UnitLight::SetEnabled(bool enabled)
95 {
96         if (__enabled != enabled)
97         {
98                 __enabled = enabled;
99                 if (!isEnabledChanged)
100                 {
101                         isEnabledChanged = true;
102                         isSomethingChanged = true;
103                 }
104                 else
105                 {
106                         isEnabledChanged = false;
107                 }
108         }
109         return;
110 }
111
112 void
113 UnitLight::SetColour(const Vec3f& colour)
114 {
115         SetColour(colour.x, colour.y, colour.z);
116         return;
117 }
118
119 void
120 UnitLight::SetColour(float red, float green, float blue)
121 {
122         if (fabs(__colour.x - red) > EFFECT_EPSILONF
123                 || fabs(__colour.y - green) > EFFECT_EPSILONF
124                 || fabs(__colour.z - blue) > EFFECT_EPSILONF)
125         {
126                 __colour.x = red;
127                 __colour.y = green;
128                 __colour.z = blue;
129                 isColourChanged = true;
130                 isSomethingChanged = true;
131         }
132         return;
133 }
134
135 void
136 UnitLight::SetIntensity(float intensity)
137 {
138         if (fabs(__intensity - intensity) > EFFECT_EPSILONF)
139         {
140                 __intensity = intensity;
141                 isIntensityChanged = true;
142                 isSomethingChanged = true;
143         }
144 }
145
146 void
147 UnitLight::ResetSigns(void)
148 {
149         isEnabledChanged = false;
150         isColourChanged = false;
151         isIntensityChanged = false;
152         isSomethingChanged = false;
153 }
154
155 void
156 UnitLight::AddUnitLightToPool(UnitLight* unitLigth)
157 {
158         if (unitLigth == null)
159         {
160                 return;
161         }
162
163         SysAssertf(IsUnitLightInPool(*unitLigth).first == false, _UiEffectError::INTERNAL_ERROR);
164         __objectsPool.push_back(unitLigth);
165
166         return;
167 }
168
169 void
170 UnitLight::ReleaseObjectsPool(void)
171 {
172         ObjectsPool::iterator it = __objectsPool.begin();
173         for (; it != __objectsPool.end(); ++it)
174         {
175                 SysAssertf(*it != null, _UiEffectError::INTERNAL_ERROR);
176                 delete *it;
177         }
178         __objectsPool.clear();
179 }
180
181 UnitLight::DoesExistsInPool
182 UnitLight::IsUnitLightInPool(UnitLight& unitLight)
183 {
184         ObjectsPool::iterator it = __objectsPool.begin();
185         for (; it != __objectsPool.end(); ++it)
186         {
187                 if (&unitLight == *it)
188                 {
189                         return make_pair(true, it);
190                 }
191         }
192         return make_pair(false, __objectsPool.end());
193 }
194
195 void
196 UnitLight::RemoveUnitLightFromPool(ObjectsPool::iterator it)
197 {
198         __objectsPool.erase(it);
199 }
200
201 } } } } // Tizen::Ui::Effects::_Runtime