• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     void InitRotateGesture();
40     bool GetRotateStatus();
41 
42 private:
43     int32_t HandleTouchPadDownEvent(int32_t seatSlot, double logicalX, double logicalY);
44     int32_t HandleTouchPadMoveEvent(int32_t seatSlot, double logicalX, double logicalY);
45     int32_t HandleTouchPadUpEvent(int32_t seatSlot);
46     double CalculateAngle(std::map<int32_t, struct Position> fingerPosition);
47     double AdjustRotateAngle(double currentAngle);
48 
49 private:
50     bool isReady_ { false };
51     bool isStartRotate_ { false };
52     std::map<int32_t, struct Position> fingerDownPosition_;
53     std::map<int32_t, struct Position> fingerCurrentPosition_;
54     double initialAngle_ { 0.0 };
55     double lastAngle_ { 0.0 };
56     double rotateAngle_ { 0.0 };
57     int32_t numberOfTouchPadFingerDown_ {-1};
58 };
59 
60 #define GESTURE_HANDLER ::OHOS::DelayedSingleton<GestureHandler>::GetInstance()
61 } // namespace MMI
62 } // namespace OHOS
63 #endif // GESTURE_HANDLER_H