soui 5.0.0.1
Soui5 Doc
 
Loading...
Searching...
No Matches
ScaleAnimation.cpp
1
2#include <souistd.h>
3#include <animation/ScaleAnimation.h>
4
5SNSBEGIN
6
7void SScaleAnimation::initialize(int width, int height, int parentWidth, int parentHeight, int nScale)
8{
9 mPivotX = (float)resolveSize(mPivotXDesc, width, parentWidth, nScale);
10 mPivotY = (float)resolveSize(mPivotYDesc, height, parentHeight, nScale);
11}
12
13void SScaleAnimation::applyTransformation(float interpolatedTime, ITransformation *t)
14{
15 float sx = 1.0f;
16 float sy = 1.0f;
17 float scale = getScaleFactor();
18
19 if (mFromX != 1.0f || mToX != 1.0f)
20 {
21 sx = mFromX + ((mToX - mFromX) * interpolatedTime);
22 }
23 if (mFromY != 1.0f || mToY != 1.0f)
24 {
25 sy = mFromY + ((mToY - mFromY) * interpolatedTime);
26 }
27
28 if (mPivotX == 0 && mPivotY == 0)
29 {
30 t->GetMatrix()->setScale(sx, sy);
31 }
32 else
33 {
34 t->GetMatrix()->setScale2(sx, sy, scale * mPivotX, scale * mPivotY);
35 }
36 t->SetTransformationType(TYPE_MATRIX);
37}
38
39void SScaleAnimation::copy(const IAnimation *src)
40{
41 const SScaleAnimation *src2 = sobj_cast<const SScaleAnimation>(src);
42 if (!src2)
43 return;
45 mFromX = src2->mFromX;
46 mToX = src2->mToX;
47 mFromY = src2->mFromY;
48 mToY = src2->mToY;
49
50 mPivotXDesc = src2->mPivotXDesc;
51 mPivotYDesc = src2->mPivotYDesc;
52}
53
54void SScaleAnimation::init(float fromX, float toX, float fromY, float toY, const SValueDescription &pivotX, const SValueDescription &pivotY)
55{
56 mFromX = fromX;
57 mToX = toX;
58 mFromY = fromY;
59 mToY = toY;
60
61 mPivotXDesc = pivotX;
62 mPivotYDesc = pivotY;
63}
64
66{
67 init(1.0f, 1.0f, 1.0f, 1.0f, SValueDescription(RELATIVE_TO_SELF, 0.5f), SValueDescription(RELATIVE_TO_SELF, 0.5f));
68}
69
70SNSEND
int resolveSize(const SValueDescription &value, int size, int parentSize, int nScale)
Converts the information in the description of a size to an actual dimension.
void copy(const IAnimation *src) OVERRIDE
Copies the properties of another animation to this animation.
float getScaleFactor()
Gets the scale factor that should be applied to pre-scaled values in an Animation....
SScaleAnimation()
Default constructor for SScaleAnimation.
void copy(const IAnimation *src) OVERRIDE
Copies the properties of another animation to this animation.
void applyTransformation(float interpolatedTime, ITransformation *t) OVERRIDE
Applies the transformation at a specific interpolated time.
void initialize(int width, int height, int parentWidth, int parentHeight, int nScale) OVERRIDE
Initializes the animation with the dimensions of the object and its parent.
void init(float fromX, float toX, float fromY, float toY, const SValueDescription &pivotX, const SValueDescription &pivotY)
Constructor to use when building a ScaleAnimation from code.
Utility class to parse a string description of a size.
Definition SAnimation.h:24