Fork for IVI: mesa fixing
[profile/ivi/uifw.git] / src / ui / effects / runtime / FUiEffects_RuntimeSpotLight.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_RuntimeSpotLight.cpp
19  * @brief       This file contains an implementation of SpotLight class methods
20  *
21  */
22
23 #include <FBaseSysLog.h>
24 #include <FBaseDataType.h>
25 #include <FUiEffects_RuntimeSpotLight.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 SpotLight::SpotLight(const std::string& name)
34                                 : PointLight(name)
35                                 , isTargetChanged(false)
36                                 , isAngleOpeningChanged(false)
37                                 , isAngleFadeOutChanged(false)
38                                 , __target(0.f, 0.f, -1.f)
39                                 , __angleOpening(30.f / 180.f * M_PI)
40                                 , __angleFadeOut(5.f / 180.f * M_PI)
41 {
42
43 }
44
45 SpotLight::SpotLight(bool isEnabled,
46                                         const string& name,
47                                         const Vec3f& colour,
48                                         float intensity,
49                                         const Vec3f& position,
50                                         const Vec3f& target,
51                                         float angleOpening,
52                                         float angleFadeOut)
53                                                 : PointLight(isEnabled, name, colour, intensity, position)
54                                                 , isTargetChanged(false)
55                                                 , isAngleOpeningChanged(false)
56                                                 , isAngleFadeOutChanged(false)
57                                                 , __target(target)
58                                                 , __angleOpening(angleOpening)
59                                                 , __angleFadeOut(angleFadeOut)
60 {
61
62 }
63
64 SpotLight::~SpotLight(void)
65 {
66
67 }
68
69 SpotLight*
70 SpotLight::CreateSpotLight(const std::string& name)
71 {
72         SpotLight* pSpotLight = new (std::nothrow) SpotLight(name);
73         AddUnitLightToPool(pSpotLight);
74         return pSpotLight;
75 }
76
77 SpotLight*
78 SpotLight::CreateSpotLight(bool isEnabled,
79                                                         const std::string& name,
80                                                         const Vec3f& colour,
81                                                         float intensity,
82                                                         const Vec3f& position,
83                                                         const Vec3f& target,
84                                                         float angleOpening,
85                                                         float angleFadeOut)
86 {
87         SpotLight* pSpotLight = new (std::nothrow) SpotLight(isEnabled,
88                                                                                                                 name,
89                                                                                                                 colour,
90                                                                                                                 intensity,
91                                                                                                                 position,
92                                                                                                                 target,
93                                                                                                                 angleOpening,
94                                                                                                                 angleFadeOut);
95         AddUnitLightToPool(pSpotLight);
96         return pSpotLight;
97 }
98
99 const Vec3f&
100 SpotLight::GetTarget(void) const
101 {
102         return __target;
103 }
104
105 float
106 SpotLight::GetAngleOpening(void) const
107 {
108         return __angleOpening;
109 }
110
111 float
112 SpotLight::GetAngleFadeOut(void) const
113 {
114         return __angleFadeOut;
115 }
116
117 void
118 SpotLight::SetTarget(const Vec3f& target)
119 {
120         SetTarget(target.x, target.y, target.z);
121         return;
122 }
123
124 void
125 SpotLight::SetTarget(float x, float y, float z)
126 {
127         if (fabs(__target.x - x) > EFFECT_EPSILONF
128                 || fabs(__target.y - y) > EFFECT_EPSILONF
129                 || fabs(__target.z - z) > EFFECT_EPSILONF)
130         {
131                 __target.x = x;
132                 __target.y = y;
133                 __target.z = z;
134                 isTargetChanged = true;
135                 isSomethingChanged = true;
136         }
137         return;
138 }
139
140 bool
141 SpotLight::SetAngleOpening(float angleOpening)
142 {
143         if (fabs(__angleOpening - angleOpening) > EFFECT_EPSILONF)
144         {
145                 if (angleOpening < 0 || angleOpening > 2 * M_PI)
146                 {
147                         return false;
148                 }
149                 __angleOpening = angleOpening;
150                 isAngleOpeningChanged = true;
151                 isSomethingChanged = true;
152         }
153         return true;
154 }
155
156 bool
157 SpotLight::SetAngleFadeOut(float angleFadeOut)
158 {
159         if (fabs(__angleFadeOut - angleFadeOut) > EFFECT_EPSILONF)
160         {
161                 if (angleFadeOut < 0 || angleFadeOut > M_PI - __angleOpening / 2.f)
162                 {
163                         return false;
164                 }
165                 __angleFadeOut = angleFadeOut;
166                 isAngleFadeOutChanged = true;
167                 isSomethingChanged = true;
168         }
169         return true;
170 }
171
172 TypeUnitLight
173 SpotLight::GetType(void) const
174 {
175         return TYPE_UNIT_LIGHT_SPOT;
176 }
177
178 void
179 SpotLight::ResetSigns(void)
180 {
181         PointLight::ResetSigns();
182         isTargetChanged = false;
183         isAngleOpeningChanged = false;
184         isAngleFadeOutChanged = false;
185 }
186
187 } } } } // Tizen::Ui::Effects::_Runtime