• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_GESTURES_RECOGNIZERS_ROTATION_RECOGNIZER_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_GESTURES_RECOGNIZERS_ROTATION_RECOGNIZER_H
18 
19 #include <cmath>
20 #include <functional>
21 #include <map>
22 
23 #include "core/components_ng/gestures/recognizers/multi_fingers_recognizer.h"
24 
25 namespace OHOS::Ace::NG {
26 
27 class RotationRecognizer : public MultiFingersRecognizer {
28     DECLARE_ACE_TYPE(RotationRecognizer, MultiFingersRecognizer);
29 
30 public:
31     RotationRecognizer(int32_t fingers, double angle, bool isLimitFingerCount = false);
32     ~RotationRecognizer() override = default;
33 
34     void OnAccepted() override;
35     void OnRejected() override;
36 
37     virtual RefPtr<GestureSnapshot> Dump() const override;
38 
SetAngle(double angle)39     void SetAngle(double angle)
40     {
41         angle_ = angle;
42     }
43 
GetAngle()44     double GetAngle()
45     {
46         return angle_;
47     }
48 
49 private:
50     void HandleTouchDownEvent(const TouchEvent& event) override;
51     void HandleTouchUpEvent(const TouchEvent& event) override;
52     void HandleTouchMoveEvent(const TouchEvent& event) override;
53     void HandleTouchCancelEvent(const TouchEvent& event) override;
54     void HandleTouchDownEvent(const AxisEvent& event) override;
55     void HandleTouchUpEvent(const AxisEvent& event) override;
56     void HandleTouchMoveEvent(const AxisEvent& event) override;
57     void HandleTouchCancelEvent(const AxisEvent& event) override;
58 
59     bool ReconcileFrom(const RefPtr<NGGestureRecognizer>& recognizer) override;
60     double ComputeAngle();
61     void OnResetStatus() override;
62     void SendCallbackMsg(const std::unique_ptr<GestureEventFunc>& callback);
63     GestureJudgeResult TriggerGestureJudgeCallback();
64     static double ChangeValueRange(double value);
65 
66     double angle_ = 0.0;
67     double initialAngle_ = 0.0;
68     double currentAngle_ = 0.0;
69     double resultAngle_ = 0.0;
70     double lastAngle_ = 0.0;
71     bool angleSignChanged_ = false;
72     TimeStamp time_;
73     AxisEvent lastAxisEvent_;
74 };
75 
76 } // namespace OHOS::Ace::NG
77 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_GESTURES_RECOGNIZERS_ROTATION_RECOGNIZER_H