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 #include "core/components_ng/event/event_constants.h" 25 26 namespace OHOS::Ace::NG { 27 28 class RotationRecognizer : public MultiFingersRecognizer { 29 DECLARE_ACE_TYPE(RotationRecognizer, MultiFingersRecognizer); 30 31 public: 32 RotationRecognizer(int32_t fingers, double angle, bool isLimitFingerCount = false); 33 ~RotationRecognizer() override = default; 34 35 void OnAccepted() override; 36 void OnRejected() override; 37 38 virtual RefPtr<GestureSnapshot> Dump() const override; 39 SetAngle(double angle)40 void SetAngle(double angle) 41 { 42 angle_ = angle; 43 } 44 GetAngle()45 double GetAngle() 46 { 47 return angle_; 48 } 49 50 private: 51 void HandleTouchDownEvent(const TouchEvent& event) override; 52 void HandleTouchUpEvent(const TouchEvent& event) override; 53 void HandleTouchMoveEvent(const TouchEvent& event) override; 54 void HandleTouchCancelEvent(const TouchEvent& event) override; 55 void HandleTouchDownEvent(const AxisEvent& event) override; 56 void HandleTouchUpEvent(const AxisEvent& event) override; 57 void HandleTouchMoveEvent(const AxisEvent& event) override; 58 void HandleTouchCancelEvent(const AxisEvent& event) override; 59 60 bool ReconcileFrom(const RefPtr<NGGestureRecognizer>& recognizer) override; 61 double ComputeAngle(); 62 void OnResetStatus() override; 63 void SendCallbackMsg(const std::unique_ptr<GestureEventFunc>& callback, GestureCallbackType type); 64 void GetGestureEventInfo(GestureEvent& info); 65 void HandleReports(const GestureEvent& info, GestureCallbackType type) override; 66 GestureJudgeResult TriggerGestureJudgeCallback(); 67 static double ChangeValueRange(double value); 68 69 double angle_ = 0.0; 70 double initialAngle_ = 0.0; 71 double currentAngle_ = 0.0; 72 double resultAngle_ = 0.0; 73 double lastAngle_ = 0.0; 74 bool angleSignChanged_ = false; 75 TimeStamp time_; 76 AxisEvent lastAxisEvent_; 77 }; 78 79 } // namespace OHOS::Ace::NG 80 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_GESTURES_RECOGNIZERS_ROTATION_RECOGNIZER_H