Interpolator.h revision d41c4d8c732095ae99c955b6b82f7306633004b1
1/* 2 * Copyright (C) 2014 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#ifndef INTERPOLATOR_H 17#define INTERPOLATOR_H 18 19#include <stddef.h> 20#include <memory> 21 22#include <cutils/compiler.h> 23 24namespace android { 25namespace uirenderer { 26 27class Interpolator { 28public: 29 virtual ~Interpolator() {} 30 31 virtual float interpolate(float input) = 0; 32 33 static Interpolator* createDefaultInterpolator(); 34 35protected: 36 Interpolator() {} 37}; 38 39class ANDROID_API AccelerateDecelerateInterpolator : public Interpolator { 40public: 41 virtual float interpolate(float input) override; 42}; 43 44class ANDROID_API AccelerateInterpolator : public Interpolator { 45public: 46 AccelerateInterpolator(float factor) : mFactor(factor), mDoubleFactor(factor*2) {} 47 virtual float interpolate(float input) override; 48private: 49 const float mFactor; 50 const float mDoubleFactor; 51}; 52 53class ANDROID_API AnticipateInterpolator : public Interpolator { 54public: 55 AnticipateInterpolator(float tension) : mTension(tension) {} 56 virtual float interpolate(float input) override; 57private: 58 const float mTension; 59}; 60 61class ANDROID_API AnticipateOvershootInterpolator : public Interpolator { 62public: 63 AnticipateOvershootInterpolator(float tension) : mTension(tension) {} 64 virtual float interpolate(float input) override; 65private: 66 const float mTension; 67}; 68 69class ANDROID_API BounceInterpolator : public Interpolator { 70public: 71 virtual float interpolate(float input) override; 72}; 73 74class ANDROID_API CycleInterpolator : public Interpolator { 75public: 76 CycleInterpolator(float cycles) : mCycles(cycles) {} 77 virtual float interpolate(float input) override; 78private: 79 const float mCycles; 80}; 81 82class ANDROID_API DecelerateInterpolator : public Interpolator { 83public: 84 DecelerateInterpolator(float factor) : mFactor(factor) {} 85 virtual float interpolate(float input) override; 86private: 87 const float mFactor; 88}; 89 90class ANDROID_API LinearInterpolator : public Interpolator { 91public: 92 virtual float interpolate(float input) override { return input; } 93}; 94 95class ANDROID_API OvershootInterpolator : public Interpolator { 96public: 97 OvershootInterpolator(float tension) : mTension(tension) {} 98 virtual float interpolate(float input) override; 99private: 100 const float mTension; 101}; 102 103class ANDROID_API LUTInterpolator : public Interpolator { 104public: 105 LUTInterpolator(float* values, size_t size); 106 ~LUTInterpolator(); 107 108 virtual float interpolate(float input) override; 109 110private: 111 std::unique_ptr<float[]> mValues; 112 size_t mSize; 113}; 114 115} /* namespace uirenderer */ 116} /* namespace android */ 117 118#endif /* INTERPOLATOR_H */ 119