1 /* 2 * Copyright (c) 2023 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 GESTURE_HANDLER_H 17 #define GESTURE_HANDLER_H 18 19 #include <cmath> 20 #include <map> 21 #include <libinput.h> 22 23 #include "pointer_event.h" 24 #include "singleton.h" 25 26 namespace OHOS { 27 namespace MMI { 28 class GestureHandler { 29 DECLARE_DELAYED_SINGLETON(GestureHandler); 30 31 struct Position { 32 double x = 0.0; 33 double y = 0.0; 34 }; 35 public: 36 DISALLOW_COPY_AND_MOVE(GestureHandler); 37 int32_t GestureIdentify(int32_t originType, int32_t seatSlot, double logicalX, double logicalY); 38 double GetRotateAngle(); 39 40 private: 41 void InitRotateGesture(); 42 int32_t HandleTouchPadDownEvent(int32_t seatSlot, double logicalX, double logicalY); 43 int32_t HandleTouchPadMoveEvent(int32_t seatSlot, double logicalX, double logicalY); 44 int32_t HandleTouchPadUpEvent(int32_t seatSlot); 45 double CalculateAngle(std::map<int32_t, struct Position> fingerPosition); 46 double AdjustRotateAngle(double currentAngle); 47 48 private: 49 bool isReady_ { false }; 50 bool isStartRotate_ { false }; 51 std::map<int32_t, struct Position> fingerDownPosition_; 52 std::map<int32_t, struct Position> fingerCurrentPosition_; 53 double initialAngle_ = 0.0; 54 double lastAngle_ = 0.0; 55 double rotateAngle_ = 0.0; 56 }; 57 58 #define GESTURE_HANDLER ::OHOS::DelayedSingleton<GestureHandler>::GetInstance() 59 } // namespace MMI 60 } // namespace OHOS 61 #endif // GESTURE_HANDLER_H