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); 32 ~RotationRecognizer() override = default; 33 34 void OnAccepted() override; 35 void OnRejected() override; 36 37 virtual RefPtr<GestureSnapshot> Dump() const override; 38 39 private: 40 void HandleTouchDownEvent(const TouchEvent& event) override; 41 void HandleTouchUpEvent(const TouchEvent& event) override; 42 void HandleTouchMoveEvent(const TouchEvent& event) override; 43 void HandleTouchCancelEvent(const TouchEvent& event) override; 44 void HandleTouchDownEvent(const AxisEvent& event) override; 45 void HandleTouchUpEvent(const AxisEvent& event) override; 46 void HandleTouchMoveEvent(const AxisEvent& event) override; 47 void HandleTouchCancelEvent(const AxisEvent& event) override; 48 49 bool ReconcileFrom(const RefPtr<NGGestureRecognizer>& recognizer) override; 50 double ComputeAngle(); 51 void OnResetStatus() override; 52 void SendCallbackMsg(const std::unique_ptr<GestureEventFunc>& callback); 53 GestureJudgeResult TriggerGestureJudgeCallback(); 54 static double ChangeValueRange(double value); 55 56 double angle_ = 0.0; 57 double initialAngle_ = 0.0; 58 double currentAngle_ = 0.0; 59 double resultAngle_ = 0.0; 60 double lastAngle_ = 0.0; 61 bool angleSignChanged_ = false; 62 TimeStamp time_; 63 AxisEvent lastAxisEvent_; 64 }; 65 66 } // namespace OHOS::Ace::NG 67 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_GESTURES_RECOGNIZERS_ROTATION_RECOGNIZER_H