• 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_PINCH_RECOGNIZER_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_GESTURES_RECOGNIZERS_PINCH_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 PinchRecognizer : public MultiFingersRecognizer {
28     DECLARE_ACE_TYPE(PinchRecognizer, MultiFingersRecognizer);
29 
30 public:
31     PinchRecognizer(int32_t fingers, double distance);
32     ~PinchRecognizer() override = default;
33 
34     void OnAccepted() override;
35     void OnRejected() override;
36 
37 private:
38     void HandleTouchDownEvent(const TouchEvent& event) override;
39     void HandleTouchUpEvent(const TouchEvent& event) override;
40     void HandleTouchMoveEvent(const TouchEvent& event) override;
41     void HandleTouchCancelEvent(const TouchEvent& event) override;
42     void HandleTouchDownEvent(const AxisEvent& event) override;
43     void HandleTouchUpEvent(const AxisEvent& event) override;
44     void HandleTouchMoveEvent(const AxisEvent& event) override;
45     void HandleTouchCancelEvent(const AxisEvent& event) override;
46 
47     bool ReconcileFrom(const RefPtr<NGGestureRecognizer>& recognizer) override;
48     double ComputeAverageDeviation();
49 
50     void OnResetStatus() override;
51     void SendCallbackMsg(const std::unique_ptr<GestureEventFunc>& callback);
52     Offset ComputePinchCenter();
53 
54     bool IsCtrlBeingPressed();
55 
56     void OnFlushTouchEventsBegin() override;
57     void OnFlushTouchEventsEnd() override;
58 
59     double distance_ = 0.0;
60     double initialDev_ = 0.0;
61     double currentDev_ = 0.0;
62     double scale_ = 1.0;
63     Offset pinchCenter_;
64     TimeStamp time_;
65     TouchEvent lastTouchEvent_;
66     bool isFlushTouchEventsEnd_ = false;
67     bool isPinchEnd_ = false;
68 };
69 
70 } // namespace OHOS::Ace::NG
71 
72 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_GESTURES_RECOGNIZERS_PINCH_RECOGNIZER_H
73