blob: b905faef104c80736b1c711d2ac7bc4d038afbbf [file] [log] [blame]
Doris Liu766431a2016-02-04 22:17:11 +00001/*
2 * Copyright (C) 2016 The Android Open Source Project
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#pragma once
18
19#include "VectorDrawable.h"
20
21#include <SkColor.h>
22
23namespace android {
24namespace uirenderer {
25
26/**
27 * PropertyValues holder contains data needed to change a property of a Vector Drawable object.
28 * When a fraction in [0f, 1f] is provided, the holder will calculate an interpolated value based
29 * on its start and end value, and set the new value on the VectorDrawble's corresponding property.
30 */
31class ANDROID_API PropertyValuesHolder {
32public:
33 virtual void setFraction(float fraction) = 0;
34 void setPropertyDataSource(float* dataSource, int length) {
35 mDataSource.insert(mDataSource.begin(), dataSource, dataSource + length);
36 }
37 float getValueFromData(float fraction);
38 virtual ~PropertyValuesHolder() {}
39protected:
40 std::vector<float> mDataSource;
41};
42
43class ANDROID_API GroupPropertyValuesHolder : public PropertyValuesHolder {
44public:
45 GroupPropertyValuesHolder(VectorDrawable::Group* ptr, int propertyId, float startValue,
46 float endValue)
47 : mGroup(ptr)
48 , mPropertyId(propertyId)
49 , mStartValue(startValue)
50 , mEndValue(endValue){
51 }
52 void setFraction(float fraction) override;
53private:
54 VectorDrawable::Group* mGroup;
55 int mPropertyId;
56 float mStartValue;
57 float mEndValue;
58};
59
60class ANDROID_API FullPathColorPropertyValuesHolder : public PropertyValuesHolder {
61public:
62 FullPathColorPropertyValuesHolder(VectorDrawable::FullPath* ptr, int propertyId, int32_t startValue,
63 int32_t endValue)
64 : mFullPath(ptr)
65 , mPropertyId(propertyId)
66 , mStartValue(startValue)
67 , mEndValue(endValue) {};
68 void setFraction(float fraction) override;
69 static SkColor interpolateColors(SkColor fromColor, SkColor toColor, float fraction);
70private:
71 VectorDrawable::FullPath* mFullPath;
72 int mPropertyId;
73 int32_t mStartValue;
74 int32_t mEndValue;
75};
76
77class ANDROID_API FullPathPropertyValuesHolder : public PropertyValuesHolder {
78public:
79 FullPathPropertyValuesHolder(VectorDrawable::FullPath* ptr, int propertyId, float startValue,
80 float endValue)
81 : mFullPath(ptr)
82 , mPropertyId(propertyId)
83 , mStartValue(startValue)
84 , mEndValue(endValue) {};
85 void setFraction(float fraction) override;
86private:
87 VectorDrawable::FullPath* mFullPath;
88 int mPropertyId;
89 float mStartValue;
90 float mEndValue;
91};
92
93class ANDROID_API PathDataPropertyValuesHolder : public PropertyValuesHolder {
94public:
95 PathDataPropertyValuesHolder(VectorDrawable::Path* ptr, PathData* startValue,
96 PathData* endValue)
97 : mPath(ptr)
98 , mStartValue(*startValue)
99 , mEndValue(*endValue) {};
100 void setFraction(float fraction) override;
101private:
102 VectorDrawable::Path* mPath;
103 PathData mPathData;
104 PathData mStartValue;
105 PathData mEndValue;
106};
107
108class ANDROID_API RootAlphaPropertyValuesHolder : public PropertyValuesHolder {
109public:
110 RootAlphaPropertyValuesHolder(VectorDrawable::Tree* tree, float startValue, float endValue)
111 : mTree(tree)
112 , mStartValue(startValue)
113 , mEndValue(endValue) {}
114 void setFraction(float fraction) override;
115private:
116 VectorDrawable::Tree* mTree;
117 float mStartValue;
118 float mEndValue;
119};
120}
121}