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::MMI { 21 class PointerEvent; 22 } // namespace OHOS::MMI 23 24 namespace OHOS::Ace { 25 26 class ACE_EXPORT BaseGestureEvent : public BaseEventInfo { 27 DECLARE_RELATIONSHIP_OF_CLASSES(BaseGestureEvent, BaseEventInfo); 28 29 public: BaseGestureEvent()30 BaseGestureEvent() : BaseEventInfo("baseGesture") {} 31 ~BaseGestureEvent() override = default; 32 GetFingerList()33 const std::list<FingerInfo>& GetFingerList() const 34 { 35 return fingerList_; 36 } 37 SetFingerList(const std::list<FingerInfo> & fingerList)38 void SetFingerList(const std::list<FingerInfo>& fingerList) 39 { 40 fingerList_ = fingerList; 41 } 42 GetRawInputEventType()43 InputEventType GetRawInputEventType() const 44 { 45 return rawInputEventType_; 46 } 47 SetRawInputEventType(InputEventType type)48 void SetRawInputEventType(InputEventType type) 49 { 50 rawInputEventType_ = type; 51 } 52 GetRawInputEvent()53 std::shared_ptr<MMI::PointerEvent> GetRawInputEvent() const 54 { 55 return rawInputEvent_; 56 } 57 SetRawInputEvent(std::shared_ptr<MMI::PointerEvent> rawInputEvent)58 void SetRawInputEvent(std::shared_ptr<MMI::PointerEvent> rawInputEvent) 59 { 60 rawInputEvent_ = rawInputEvent; 61 } 62 GetRawInputDeviceId()63 int64_t GetRawInputDeviceId() const 64 { 65 return rawInputDeviceId_; 66 } 67 SetRawInputDeviceId(int64_t rawInputDeviceId)68 void SetRawInputDeviceId(int64_t rawInputDeviceId) 69 { 70 rawInputDeviceId_ = rawInputDeviceId; 71 } 72 SetLastAction(int32_t action)73 void SetLastAction(int32_t action) 74 { 75 lastAction_.emplace(action); 76 } 77 GetLastAction()78 std::optional<int32_t> GetLastAction() const 79 { 80 return lastAction_; 81 } 82 83 protected: 84 std::list<FingerInfo> fingerList_; 85 InputEventType rawInputEventType_ = InputEventType::TOUCH_SCREEN; 86 std::shared_ptr<MMI::PointerEvent> rawInputEvent_; 87 int64_t rawInputDeviceId_ = 0; 88 std::optional<int32_t> lastAction_; 89 }; 90 91 class ACE_EXPORT TapGestureEvent : public BaseGestureEvent { 92 DECLARE_RELATIONSHIP_OF_CLASSES(TapGestureEvent, BaseGestureEvent); 93 94 public: 95 TapGestureEvent() = default; 96 ~TapGestureEvent() override = default; 97 }; 98 99 class ACE_EXPORT LongPressGestureEvent : public BaseGestureEvent { 100 DECLARE_RELATIONSHIP_OF_CLASSES(LongPressGestureEvent, BaseGestureEvent); 101 102 public: 103 LongPressGestureEvent() = default; 104 ~LongPressGestureEvent() override = default; 105 SetRepeat(bool repeat)106 void SetRepeat(bool repeat) 107 { 108 repeat_ = repeat; 109 } 110 GetRepeat()111 bool GetRepeat() const 112 { 113 return repeat_; 114 } 115 116 private: 117 bool repeat_ = false; 118 }; 119 120 class ACE_EXPORT PanGestureEvent : public BaseGestureEvent { 121 DECLARE_RELATIONSHIP_OF_CLASSES(PanGestureEvent, BaseGestureEvent); 122 123 public: 124 PanGestureEvent() = default; 125 ~PanGestureEvent() override = default; 126 SetOffsetX(double offsetX)127 void SetOffsetX(double offsetX) 128 { 129 offsetX_ = offsetX; 130 } 131 GetOffsetX()132 double GetOffsetX() const 133 { 134 return offsetX_; 135 } 136 SetOffsetY(double offsetY)137 void SetOffsetY(double offsetY) 138 { 139 offsetY_ = offsetY; 140 } 141 GetOffsetY()142 double GetOffsetY() const 143 { 144 return offsetY_; 145 } 146 SetVelocity(const Velocity & velocity)147 void SetVelocity(const Velocity& velocity) 148 { 149 velocity_ = velocity; 150 } 151 GetVelocity()152 const Velocity& GetVelocity() const 153 { 154 return velocity_; 155 } 156 SetMainVelocity(double mainVelocity)157 void SetMainVelocity(double mainVelocity) 158 { 159 mainVelocity_ = mainVelocity; 160 } 161 GetMainVelocity()162 double GetMainVelocity() const 163 { 164 return mainVelocity_; 165 } 166 167 private: 168 double offsetX_ = 0.0; 169 double offsetY_ = 0.0; 170 Velocity velocity_; 171 double mainVelocity_ = 0.0; 172 }; 173 174 class ACE_EXPORT PinchGestureEvent : public BaseGestureEvent { 175 DECLARE_RELATIONSHIP_OF_CLASSES(PinchGestureEvent, BaseGestureEvent); 176 177 public: 178 PinchGestureEvent() = default; 179 ~PinchGestureEvent() override = default; 180 SetScale(double scale)181 void SetScale(double scale) 182 { 183 scale_ = scale; 184 } 185 GetScale()186 double GetScale() const 187 { 188 return scale_; 189 } 190 GetPinchCenter()191 const Offset& GetPinchCenter() const 192 { 193 return pinchCenter_; 194 } 195 SetPinchCenter(const Offset & pinchCenter)196 PinchGestureEvent& SetPinchCenter(const Offset& pinchCenter) 197 { 198 pinchCenter_ = pinchCenter; 199 return *this; 200 } 201 202 private: 203 double scale_ = 1.0; 204 Offset pinchCenter_; 205 }; 206 207 class ACE_EXPORT RotationGestureEvent : public BaseGestureEvent { 208 DECLARE_RELATIONSHIP_OF_CLASSES(RotationGestureEvent, BaseGestureEvent); 209 210 public: 211 RotationGestureEvent() = default; 212 ~RotationGestureEvent() override = default; 213 SetAngle(double angle)214 void SetAngle(double angle) 215 { 216 angle_ = angle; 217 } 218 GetAngle()219 double GetAngle() const 220 { 221 return angle_; 222 } 223 224 private: 225 double angle_ = 0.0; 226 }; 227 228 class ACE_EXPORT SwipeGestureEvent : public BaseGestureEvent { 229 DECLARE_RELATIONSHIP_OF_CLASSES(SwipeGestureEvent, BaseGestureEvent); 230 231 public: 232 SwipeGestureEvent() = default; 233 ~SwipeGestureEvent() override = default; 234 SetAngle(double angle)235 void SetAngle(double angle) 236 { 237 angle_ = angle; 238 } 239 GetAngle()240 double GetAngle() const 241 { 242 return angle_; 243 } 244 SetSpeed(double speed)245 void SetSpeed(double speed) 246 { 247 speed_ = speed; 248 } 249 GetSpeed()250 double GetSpeed() const 251 { 252 return speed_; 253 } 254 255 private: 256 double angle_ = 0.0; 257 double speed_ = 0.0; 258 }; 259 } // namespace OHOS::Ace 260 261 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_GESTURES_BASE_GESTURE_EVENT_H