1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef ARKUI_NATIVE_ANIMATE_IMPL_H 16 #define ARKUI_NATIVE_ANIMATE_IMPL_H 17 18 #include <cstdint> 19 #include <vector> 20 21 #include "native_animate.h" 22 #include "native_type.h" 23 24 #include "frameworks/core/interfaces/arkoala/arkoala_api.h" 25 26 #ifdef __cplusplus 27 extern "C" { 28 #endif 29 30 struct ArkUI_AnimateOption { 31 uint32_t duration; 32 float tempo; 33 ArkUI_AnimationCurve curve; 34 int32_t delay; 35 int32_t iterations; 36 ArkUI_AnimationPlayMode playMode; 37 ArkUI_ExpectedFrameRateRange* expectedFrameRateRange; 38 ArkUI_CurveHandle iCurve; 39 }; 40 41 typedef enum { 42 ARKUI_CURVE_TYPE_BASE = 0, 43 ARKUI_CURVE_TYPE_STEPS, 44 ARKUI_CURVE_TYPE_CUBIC_BEZIER, 45 ARKUI_CURVE_TYPE_SPRING, 46 ARKUI_CURVE_TYPE_SPRING_MOTION, 47 ARKUI_CURVE_TYPE_RESPONSIVE_SPRING_MOTION, 48 ARKUI_CURVE_TYPE_INTERPOLATING_SPRING, 49 ARKUI_CURVE_TYPE_CUSTOM, 50 } ArkUI_CurveType; 51 52 struct ArkUI_Curve { 53 ArkUI_CurveType type; 54 ArkUICurveHandle curve; 55 ArkUI_AnimationCurve baseCurveType; 56 }; 57 58 struct ArkUI_KeyframeState { 59 int32_t duration; 60 ArkUI_CurveHandle curve; 61 void (*event)(void* userData); 62 void* userData; 63 }; 64 65 struct ArkUI_KeyframeAnimateOption { 66 int32_t delay; 67 int32_t iterations; 68 void (*onFinish)(void* userData); 69 void* userData; 70 std::vector<ArkUI_KeyframeState> keyframes; 71 ArkUI_ExpectedFrameRateRange* expectedFrameRateRange; 72 }; 73 74 struct ArkUI_Keyframe { 75 float keyTime; 76 float keyValue; 77 ArkUI_CurveHandle curve; 78 }; 79 struct ArkUI_AnimatorOption { 80 int32_t duration; 81 int32_t delay; 82 int32_t iterations; 83 ArkUI_AnimationFillMode fill; 84 ArkUI_AnimationDirection direction; 85 float begin; 86 float end; 87 ArkUI_CurveHandle easing; 88 ArkUI_ExpectedFrameRateRange* expectedFrameRateRange; 89 std::vector<ArkUI_Keyframe> keyframes; 90 void (*onFrame)(ArkUI_AnimatorOnFrameEvent* event); 91 void* frameUserData; 92 void (*onFinish)(ArkUI_AnimatorEvent* event); 93 void* finishUserData; 94 void (*onCancel)(ArkUI_AnimatorEvent* event); 95 void* cancelUserData; 96 void (*onRepeat)(ArkUI_AnimatorEvent* event); 97 void* repeatUserData; 98 }; 99 100 struct ArkUI_Animator { 101 ArkUIAnimatorHandle animator; 102 ArkUI_AnimatorOption* option; 103 ArkUIAnimatorOption* animatorOption; 104 }; 105 #ifdef __cplusplus 106 }; 107 #endif 108 109 namespace OHOS::Ace::AnimateModel { 110 111 ArkUI_CurveHandle InitCurve(ArkUI_AnimationCurve animationCurve); 112 ArkUI_CurveHandle StepsCurve(int32_t count, bool end); 113 ArkUI_CurveHandle CubicBezierCurve(float x1, float y1, float x2, float y2); 114 ArkUI_CurveHandle SpringCurve(float velocity, float mass, float stiffness, float damping); 115 ArkUI_CurveHandle SpringMotion(float response, float dampingFraction, float overlapDuration); 116 ArkUI_CurveHandle ResponsiveSpringMotion(float response, float dampingFraction, float overlapDuration); 117 ArkUI_CurveHandle InterpolatingSpring(float velocity, float mass, float stiffness, float damping); 118 ArkUI_CurveHandle CustomCurve(void* userData, float (*interpolate)(float fraction, void* userdata)); 119 void DisposeCurve(ArkUI_CurveHandle curveHandle); 120 121 int32_t AnimateTo(ArkUI_ContextHandle context, ArkUI_AnimateOption* option, ArkUI_ContextCallback* update, 122 ArkUI_AnimateCompleteCallback* complete); 123 124 int32_t KeyframeAnimateTo(ArkUI_ContextHandle context, ArkUI_KeyframeAnimateOption* option); 125 126 ArkUI_AnimatorHandle CreateAnimator(ArkUI_ContextHandle context, ArkUI_AnimatorOption* option); 127 void DisposeAnimator(ArkUI_AnimatorHandle animatorHandle); 128 129 int32_t AnimatorReset(ArkUI_AnimatorHandle animatorHandle, ArkUI_AnimatorOption* option); 130 int32_t AnimatorPlay(ArkUI_AnimatorHandle animatorHandle); 131 int32_t AnimatorFinish(ArkUI_AnimatorHandle animatorHandle); 132 int32_t AnimatorPause(ArkUI_AnimatorHandle animatorHandle); 133 int32_t AnimatorCancel(ArkUI_AnimatorHandle animatorHandle); 134 int32_t AnimatorReverse(ArkUI_AnimatorHandle animatorHandle); 135 }; // namespace OHOS::Ace::AnimateModel 136 #endif