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 16 #ifndef ARKUI_INPUT_RAW_INPUT_INJECTOR_RAW_INPUT_INJECTOR_UTILS_H 17 #define ARKUI_INPUT_RAW_INPUT_INJECTOR_RAW_INPUT_INJECTOR_UTILS_H 18 19 #include <cstdint> 20 #include <vector> 21 22 namespace OHOS { 23 namespace Ace { 24 25 // coordinate calculation function curve, used for point calculation of touch move 26 // [Note]: only LINEAR is supported for now 27 enum class CoordinateCurve : size_t { LINEAR = 0, EASE_IN_OUT, EASE_IN, EASE_OUT }; 28 29 enum class EaseAlgorithm : size_t { CUBIC = 0, QUART }; 30 31 struct Point { 32 double x = 0; // use double for high precision 33 double y = 0; 34 }; 35 36 class InjectorUtils final { 37 public: IsDebugOn()38 static bool IsDebugOn() 39 { 40 return debugEnabled_; 41 } 42 SetDebugEnabled(bool debug)43 static void SetDebugEnabled(bool debug) 44 { 45 debugEnabled_ = debug; 46 } 47 48 static int64_t GetSysClockTime(); 49 50 // calculate one point value in linear way 51 static int32_t CalculateNextPosValueWithLinear( 52 int32_t startPoint, int32_t targetPoint, int32_t currentIndex, int32_t totalCount); 53 static Point CalculateNextPosValueWithBezier( 54 std::vector<Point>& controlPoints, int32_t currentIndex, int32_t totalCount, CoordinateCurve curve); 55 56 private: 57 InjectorUtils() = default; 58 ~InjectorUtils() = default; 59 // bezier curve calculation 60 static Point BezierCurve(const std::vector<Point>& controlPoints, double t); 61 static int Combination(int n, int k); 62 static double EaseInOut(double t, EaseAlgorithm algorithm); 63 static bool debugEnabled_; 64 }; 65 } // namespace Ace 66 } // namespace OHOS 67 #endif // ARKUI_INPUT_RAW_INPUT_INJECTOR_RAW_INPUT_INJECTOR_H