2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
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
9 // http://floralicense.org/license/
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.
19 * @file FUiAnim_VisualElementAnimationVariantInterpolator.cpp
20 * @brief This file contains implementation of _VisualElementAnimationVariantInterpolator class
22 * This file contains implementation _VisualElementAnimationVariantInterpolator class.
25 #include <FBaseSysLog.h>
26 #include <FBaseErrors.h>
28 #include <FGrpFloatMatrix4.h>
29 #include <FGrpRectangle.h>
30 #include <FGrpDimension.h>
31 #include <FGrpPoint.h>
32 #include <FGrpColor.h>
33 #include <FGrpFloatPoint.h>
34 #include <FGrpFloatRectangle.h>
35 #include <FGrpFloatDimension.h>
37 #include "FUiAnim_VariantEx.h"
38 #include "FUiAnim_VisualElementAnimationVariantInterpolator.h"
40 using namespace Tizen;
41 using namespace Tizen::Graphics;
43 namespace Tizen { namespace Ui { namespace Animations
46 _VisualElementAnimationVariantInterpolator::_VisualElementAnimationVariantInterpolator(void)
50 _VisualElementAnimationVariantInterpolator::~_VisualElementAnimationVariantInterpolator(void)
56 _VisualElementAnimationVariantInterpolator::Interpolate(float progress, const Tizen::Ui::Variant& startValue, const Tizen::Ui::Variant& endValue, Tizen::Ui::Variant& value) const
58 SysTryReturnResult(NID_UI_ANIM, startValue.GetType() == endValue.GetType(), E_INVALID_ARG, "Invalid argument(s) is used. Variant types are not matched.");
60 const _VariantEx* pStartValueEx = dynamic_cast< const _VariantEx* >(&startValue);
61 const _VariantEx* pEndValueEx = dynamic_cast< const _VariantEx* >(&endValue);
63 if (pStartValueEx && pEndValueEx)
65 if (pStartValueEx->IsValidTransformMatrix() && pEndValueEx->IsValidTransformMatrix())
67 value = pEndValueEx->GetTransformMatrix().Interpolate(
68 pStartValueEx->GetTransformMatrix(),
75 switch (startValue.GetType())
77 case VARIANT_TYPE_INT:
79 int start = startValue.ToInt();
80 int end = endValue.ToInt();
82 value = static_cast< int >(static_cast< float >(start) * (1.0f - progress) + static_cast< float >(end) * progress);
86 case VARIANT_TYPE_LONG:
88 long start = startValue.ToLong();
89 long end = endValue.ToLong();
92 value = static_cast< long >(static_cast< float >(start) * (1.0f - progress) + static_cast< float >(end) * progress);
96 case VARIANT_TYPE_LONGLONG:
98 long long start = startValue.ToLongLong();
99 long long end = endValue.ToLongLong();
101 value = static_cast< long long >(static_cast< float >(start) * (1.0f - progress) + static_cast< float >(end) * progress);
105 case VARIANT_TYPE_FLOAT:
107 float start = startValue.ToFloat();
108 float end = endValue.ToFloat();
110 value = start * (1.0f - progress) + end * progress;
114 case VARIANT_TYPE_DOUBLE:
116 double start = startValue.ToDouble();
117 double end = endValue.ToDouble();
119 value = static_cast< double >(static_cast< double >(start) * (1.0 - static_cast< double >(progress)) + static_cast< double >(end) * static_cast< double >(progress));
123 case VARIANT_TYPE_RECTANGLE:
125 const Tizen::Graphics::Rectangle& start = startValue.ToRectangle();
126 const Tizen::Graphics::Rectangle& end = endValue.ToRectangle();
127 Tizen::Graphics::Rectangle rect;
129 rect.x = static_cast< int >(static_cast< float >(start.x) * (1.0f - progress) + static_cast< float >(end.x) * progress);
130 rect.y = static_cast< int >(static_cast< float >(start.y) * (1.0f - progress) + static_cast< float >(end.y) * progress);
131 rect.width = static_cast< int >(static_cast< float >(start.width) * (1.0f - progress) + static_cast< float >(end.width) * progress);
132 rect.height = static_cast< int >(static_cast< float >(start.height) * (1.0f - progress) + static_cast< float >(end.height) * progress);
138 case VARIANT_TYPE_FLOAT_RECTANGLE:
140 const Tizen::Graphics::FloatRectangle& start = startValue.ToFloatRectangle();
141 const Tizen::Graphics::FloatRectangle& end = endValue.ToFloatRectangle();
143 float left = start.x * (1.0f - progress) + end.x * progress;
144 float top = start.y * (1.0f - progress) + end.y * progress;
145 float width = start.width * (1.0f - progress) + end.width * progress;
146 float height = start.height * (1.0f - progress) + end.height * progress;
148 value = Variant(Tizen::Graphics::FloatRectangle(left, top, width, height));
152 case VARIANT_TYPE_POINT:
154 const Tizen::Graphics::Point& start = startValue.ToPoint();
155 const Tizen::Graphics::Point& end = endValue.ToPoint();
156 Tizen::Graphics::Point point;
158 point.x = static_cast< int >(static_cast< float >(start.x) * (1.0f - progress) + static_cast< float >(end.x) * progress);
159 point.y = static_cast< int >(static_cast< float >(start.y) * (1.0f - progress) + static_cast< float >(end.y) * progress);
165 case VARIANT_TYPE_FLOAT_POINT:
167 const Tizen::Graphics::FloatPoint& start = startValue.ToFloatPoint();
168 const Tizen::Graphics::FloatPoint& end = endValue.ToFloatPoint();
170 float x = start.x * (1.0f - progress) + end.x * progress;
171 float y = start.y * (1.0f - progress) + end.y * progress;
173 value = Variant(Tizen::Graphics::FloatPoint(x, y));
177 case VARIANT_TYPE_DIMENSION:
179 const Tizen::Graphics::Dimension& start = startValue.ToDimension();
180 const Tizen::Graphics::Dimension& end = endValue.ToDimension();
181 Tizen::Graphics::Dimension size;
183 size.width = static_cast< int >(static_cast< float >(start.width) * (1.0f - progress) + static_cast< float >(end.width) * progress);
184 size.height = static_cast< int >(static_cast< float >(start.height) * (1.0f - progress) + static_cast< float >(end.height) * progress);
190 case VARIANT_TYPE_FLOAT_DIMENSION:
192 const Tizen::Graphics::FloatDimension& start = startValue.ToFloatDimension();
193 const Tizen::Graphics::FloatDimension& end = endValue.ToFloatDimension();
194 Tizen::Graphics::FloatDimension size;
196 size.width = start.width * (1.0f - progress) + end.width * progress;
197 size.height = start.height * (1.0f - progress) + end.height * progress;
203 case VARIANT_TYPE_COLOR:
205 const Tizen::Graphics::Color& start = startValue.ToColor();
206 const Tizen::Graphics::Color& end = endValue.ToColor();
208 byte r = static_cast< byte >(static_cast< float >(start.GetRed()) * (1.0f - progress) + static_cast< float >(end.GetRed()) * progress);
209 byte g = static_cast< byte >(static_cast< float >(start.GetGreen()) * (1.0f - progress) + static_cast< float >(end.GetGreen()) * progress);
210 byte b = static_cast< byte >(static_cast< float >(start.GetBlue()) * (1.0f - progress) + static_cast< float >(end.GetBlue()) * progress);
211 byte a = static_cast< byte >(static_cast< float >(start.GetAlpha()) * (1.0f - progress) + static_cast< float >(end.GetAlpha()) * progress);
213 value = Variant(Tizen::Graphics::Color(r, g, b, a));
218 case VARIANT_TYPE_COLORF:
220 const _Colorf& startValue = start.ToColorf();
221 const _Colorf& endValue = end.ToColorf();
223 float r = startValue.Red() * (1.0f - progress) + endValue.Red() * progress;
224 float g = startValue.Green() * (1.0f - progress) + endValue.Green() * progress;
225 float b = startValue.Blue() * (1.0f - progress) + endValue.Blue() * progress;
226 float a = startValue.Alpha() * (1.0f - progress) + endValue.Alpha() * progress;
228 value = Variant(_Colorf(r, g, b, a));
233 case VARIANT_TYPE_FLOAT_MATRIX4:
235 const Tizen::Graphics::FloatMatrix4& start = startValue.ToFloatMatrix4();
236 const Tizen::Graphics::FloatMatrix4& end = endValue.ToFloatMatrix4();
237 float m[4][4] = {{0.0f}, };
239 for (int i = 0; i < 4; i++)
241 for (int j = 0; j < 4; j++)
243 // m[j][i] = start(i, j) * (1.0f - progress) + end(i, j) * progress;
244 m[j][i] = start.matrix[j][i] * (1.0f - progress) + end.matrix[j][i] * progress;
248 value = Variant(Tizen::Graphics::FloatMatrix4(m));
252 case VARIANT_TYPE_BOOL:
254 bool start = startValue.ToBool();
255 bool end = endValue.ToBool();
268 case VARIANT_TYPE_NONE:
269 case VARIANT_TYPE_STRING:
271 SysLogException(NID_UI_ANIM, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument(s) is used. Variant type is invalid.");
272 return E_INVALID_ARG;
278 }}} //Tizen::Ui::Animations