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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_GESTURES_BASE_GESTURE_EVENT_H 16 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_GESTURES_BASE_GESTURE_EVENT_H 17 18 #include "core/gestures/gesture_info.h" 19 20 namespace OHOS::Ace { 21 22 class ACE_EXPORT BaseGestureEvent : public BaseEventInfo { 23 DECLARE_RELATIONSHIP_OF_CLASSES(BaseGestureEvent, BaseEventInfo); 24 25 public: BaseGestureEvent()26 BaseGestureEvent() : BaseEventInfo("baseGesture") {} 27 ~BaseGestureEvent() override = default; 28 GetFingerList()29 const std::list<FingerInfo>& GetFingerList() const 30 { 31 return fingerList_; 32 } 33 SetFingerList(const std::list<FingerInfo> & fingerList)34 void SetFingerList(const std::list<FingerInfo>& fingerList) 35 { 36 fingerList_ = fingerList; 37 } 38 39 protected: 40 std::list<FingerInfo> fingerList_; 41 }; 42 43 class ACE_EXPORT TapGestureEvent : public BaseGestureEvent { 44 DECLARE_RELATIONSHIP_OF_CLASSES(TapGestureEvent, BaseGestureEvent); 45 46 public: 47 TapGestureEvent() = default; 48 ~TapGestureEvent() override = default; 49 }; 50 51 class ACE_EXPORT LongPressGestureEvent : public BaseGestureEvent { 52 DECLARE_RELATIONSHIP_OF_CLASSES(LongPressGestureEvent, BaseGestureEvent); 53 54 public: 55 LongPressGestureEvent() = default; 56 ~LongPressGestureEvent() override = default; 57 SetRepeat(bool repeat)58 void SetRepeat(bool repeat) 59 { 60 repeat_ = repeat; 61 } 62 GetRepeat()63 bool GetRepeat() const 64 { 65 return repeat_; 66 } 67 68 private: 69 bool repeat_ = false; 70 }; 71 72 class ACE_EXPORT PanGestureEvent : public BaseGestureEvent { 73 DECLARE_RELATIONSHIP_OF_CLASSES(PanGestureEvent, BaseGestureEvent); 74 75 public: 76 PanGestureEvent() = default; 77 ~PanGestureEvent() override = default; 78 SetOffsetX(double offsetX)79 void SetOffsetX(double offsetX) 80 { 81 offsetX_ = offsetX; 82 } 83 GetOffsetX()84 double GetOffsetX() const 85 { 86 return offsetX_; 87 } 88 SetOffsetY(double offsetY)89 void SetOffsetY(double offsetY) 90 { 91 offsetY_ = offsetY; 92 } 93 GetOffsetY()94 double GetOffsetY() const 95 { 96 return offsetY_; 97 } 98 SetVelocity(const Velocity & velocity)99 void SetVelocity(const Velocity& velocity) 100 { 101 velocity_ = velocity; 102 } 103 GetVelocity()104 const Velocity& GetVelocity() const 105 { 106 return velocity_; 107 } 108 SetMainVelocity(double mainVelocity)109 void SetMainVelocity(double mainVelocity) 110 { 111 mainVelocity_ = mainVelocity; 112 } 113 GetMainVelocity()114 double GetMainVelocity() const 115 { 116 return mainVelocity_; 117 } 118 119 private: 120 double offsetX_ = 0.0; 121 double offsetY_ = 0.0; 122 Velocity velocity_; 123 double mainVelocity_ = 0.0; 124 }; 125 126 class ACE_EXPORT PinchGestureEvent : public BaseGestureEvent { 127 DECLARE_RELATIONSHIP_OF_CLASSES(PinchGestureEvent, BaseGestureEvent); 128 129 public: 130 PinchGestureEvent() = default; 131 ~PinchGestureEvent() override = default; 132 SetScale(double scale)133 void SetScale(double scale) 134 { 135 scale_ = scale; 136 } 137 GetScale()138 double GetScale() const 139 { 140 return scale_; 141 } 142 GetPinchCenter()143 const Offset& GetPinchCenter() const 144 { 145 return pinchCenter_; 146 } 147 SetPinchCenter(const Offset & pinchCenter)148 PinchGestureEvent& SetPinchCenter(const Offset& pinchCenter) 149 { 150 pinchCenter_ = pinchCenter; 151 return *this; 152 } 153 154 private: 155 double scale_ = 1.0; 156 Offset pinchCenter_; 157 }; 158 159 class ACE_EXPORT RotationGestureEvent : public BaseGestureEvent { 160 DECLARE_RELATIONSHIP_OF_CLASSES(RotationGestureEvent, BaseGestureEvent); 161 162 public: 163 RotationGestureEvent() = default; 164 ~RotationGestureEvent() override = default; 165 SetAngle(double angle)166 void SetAngle(double angle) 167 { 168 angle_ = angle; 169 } 170 GetAngle()171 double GetAngle() const 172 { 173 return angle_; 174 } 175 176 private: 177 double angle_ = 0.0; 178 }; 179 180 class ACE_EXPORT SwipeGestureEvent : public BaseGestureEvent { 181 DECLARE_RELATIONSHIP_OF_CLASSES(SwipeGestureEvent, BaseGestureEvent); 182 183 public: 184 SwipeGestureEvent() = default; 185 ~SwipeGestureEvent() override = default; 186 SetAngle(double angle)187 void SetAngle(double angle) 188 { 189 angle_ = angle; 190 } 191 GetAngle()192 double GetAngle() const 193 { 194 return angle_; 195 } 196 SetSpeed(double speed)197 void SetSpeed(double speed) 198 { 199 speed_ = speed; 200 } 201 GetSpeed()202 double GetSpeed() const 203 { 204 return speed_; 205 } 206 207 private: 208 double angle_ = 0.0; 209 double speed_ = 0.0; 210 }; 211 } // namespace OHOS::Ace 212 213 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_GESTURES_BASE_GESTURE_EVENT_H