1a3e0fd82Sopenharmony_ci/* 2a3e0fd82Sopenharmony_ci * Copyright (c) 2020-2021 Huawei Device Co., Ltd. 3a3e0fd82Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4a3e0fd82Sopenharmony_ci * you may not use this file except in compliance with the License. 5a3e0fd82Sopenharmony_ci * You may obtain a copy of the License at 6a3e0fd82Sopenharmony_ci * 7a3e0fd82Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8a3e0fd82Sopenharmony_ci * 9a3e0fd82Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10a3e0fd82Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11a3e0fd82Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12a3e0fd82Sopenharmony_ci * See the License for the specific language governing permissions and 13a3e0fd82Sopenharmony_ci * limitations under the License. 14a3e0fd82Sopenharmony_ci */ 15a3e0fd82Sopenharmony_ci 16a3e0fd82Sopenharmony_ci/** 17a3e0fd82Sopenharmony_ci * @addtogroup UI_Events 18a3e0fd82Sopenharmony_ci * @{ 19a3e0fd82Sopenharmony_ci * 20a3e0fd82Sopenharmony_ci * @brief Defines UI events, such as press, click and drag events. 21a3e0fd82Sopenharmony_ci * 22a3e0fd82Sopenharmony_ci * @since 1.0 23a3e0fd82Sopenharmony_ci * @version 1.0 24a3e0fd82Sopenharmony_ci */ 25a3e0fd82Sopenharmony_ci 26a3e0fd82Sopenharmony_ci/** 27a3e0fd82Sopenharmony_ci * @file drag_event.h 28a3e0fd82Sopenharmony_ci * 29a3e0fd82Sopenharmony_ci * @brief Declares a drag event, which indicates a certain movement (more than 10 pixels) after a view is pressed. 30a3e0fd82Sopenharmony_ci * 31a3e0fd82Sopenharmony_ci * @since 1.0 32a3e0fd82Sopenharmony_ci * @version 1.0 33a3e0fd82Sopenharmony_ci */ 34a3e0fd82Sopenharmony_ci 35a3e0fd82Sopenharmony_ci#ifndef GRAPHIC_LITE_DRAG_EVENT_H 36a3e0fd82Sopenharmony_ci#define GRAPHIC_LITE_DRAG_EVENT_H 37a3e0fd82Sopenharmony_ci 38a3e0fd82Sopenharmony_ci#include "event.h" 39a3e0fd82Sopenharmony_ci 40a3e0fd82Sopenharmony_cinamespace OHOS { 41a3e0fd82Sopenharmony_ci/** 42a3e0fd82Sopenharmony_ci * @brief Defines a drag event, which indicates a certain movement (more than 10 pixels) after a view is pressed. 43a3e0fd82Sopenharmony_ci * 44a3e0fd82Sopenharmony_ci * @since 1.0 45a3e0fd82Sopenharmony_ci * @version 1.0 46a3e0fd82Sopenharmony_ci */ 47a3e0fd82Sopenharmony_ciclass DragEvent : public Event { 48a3e0fd82Sopenharmony_cipublic: 49a3e0fd82Sopenharmony_ci /** 50a3e0fd82Sopenharmony_ci * @brief A constructor used to create a <b>DragEvent</b> instance. 51a3e0fd82Sopenharmony_ci * @param newPos Indicates the new position in the drag event. 52a3e0fd82Sopenharmony_ci * @param lastPos Indicates the last position in the drag event. 53a3e0fd82Sopenharmony_ci * @param totalLen Indicates the distance that the view has been dragged, including the movement on the x-axis 54a3e0fd82Sopenharmony_ci * and y-axis. 55a3e0fd82Sopenharmony_ci * @since 1.0 56a3e0fd82Sopenharmony_ci * @version 1.0 57a3e0fd82Sopenharmony_ci */ 58a3e0fd82Sopenharmony_ci DragEvent(const Point& newPos, const Point& lastPos, const Point& totalLen) : Event(newPos) 59a3e0fd82Sopenharmony_ci { 60a3e0fd82Sopenharmony_ci lastPos_ = lastPos; 61a3e0fd82Sopenharmony_ci startPos_.x = newPos.x - totalLen.x; 62a3e0fd82Sopenharmony_ci startPos_.y = newPos.y - totalLen.y; 63a3e0fd82Sopenharmony_ci preLastPos_ = lastPos; 64a3e0fd82Sopenharmony_ci deltaX_ = newPos.x - lastPos.x; 65a3e0fd82Sopenharmony_ci deltaY_ = newPos.y - lastPos.y; 66a3e0fd82Sopenharmony_ci } 67a3e0fd82Sopenharmony_ci 68a3e0fd82Sopenharmony_ci /** 69a3e0fd82Sopenharmony_ci * @brief A destructor used to delete the <b>DragEvent</b> instance. 70a3e0fd82Sopenharmony_ci * @since 1.0 71a3e0fd82Sopenharmony_ci * @version 1.0 72a3e0fd82Sopenharmony_ci */ 73a3e0fd82Sopenharmony_ci virtual ~DragEvent() {} 74a3e0fd82Sopenharmony_ci 75a3e0fd82Sopenharmony_ci /** 76a3e0fd82Sopenharmony_ci * @brief Obtains the coordinates of the last position in the drag event. 77a3e0fd82Sopenharmony_ci * @return Returns the coordinates of the last position. 78a3e0fd82Sopenharmony_ci * @since 1.0 79a3e0fd82Sopenharmony_ci * @version 1.0 80a3e0fd82Sopenharmony_ci */ 81a3e0fd82Sopenharmony_ci const Point& GetLastPoint() const 82a3e0fd82Sopenharmony_ci { 83a3e0fd82Sopenharmony_ci return lastPos_; 84a3e0fd82Sopenharmony_ci } 85a3e0fd82Sopenharmony_ci 86a3e0fd82Sopenharmony_ci /** 87a3e0fd82Sopenharmony_ci * @brief Obtains the start coordinates in the drag event. 88a3e0fd82Sopenharmony_ci * @return Returns the start coordinates. 89a3e0fd82Sopenharmony_ci * @since 1.0 90a3e0fd82Sopenharmony_ci * @version 1.0 91a3e0fd82Sopenharmony_ci */ 92a3e0fd82Sopenharmony_ci const Point& GetStartPoint() const 93a3e0fd82Sopenharmony_ci { 94a3e0fd82Sopenharmony_ci return startPos_; 95a3e0fd82Sopenharmony_ci } 96a3e0fd82Sopenharmony_ci 97a3e0fd82Sopenharmony_ci /** 98a3e0fd82Sopenharmony_ci * @brief Sets the coordinates of the stay position before the last position in the drag event. 99a3e0fd82Sopenharmony_ci * @param preLastPos Indicates the coordinates of the stay position to set. 100a3e0fd82Sopenharmony_ci * @since 1.0 101a3e0fd82Sopenharmony_ci * @version 1.0 102a3e0fd82Sopenharmony_ci */ 103a3e0fd82Sopenharmony_ci void SetPreLastPoint(const Point& preLastPos) 104a3e0fd82Sopenharmony_ci { 105a3e0fd82Sopenharmony_ci preLastPos_ = preLastPos; 106a3e0fd82Sopenharmony_ci } 107a3e0fd82Sopenharmony_ci 108a3e0fd82Sopenharmony_ci /** 109a3e0fd82Sopenharmony_ci * @brief Obtains the coordinates of the stay position before the last position in the drag event. 110a3e0fd82Sopenharmony_ci * @return Returns the coordinates of the stay position. 111a3e0fd82Sopenharmony_ci * @since 1.0 112a3e0fd82Sopenharmony_ci * @version 1.0 113a3e0fd82Sopenharmony_ci */ 114a3e0fd82Sopenharmony_ci const Point& GetPreLastPoint() const 115a3e0fd82Sopenharmony_ci { 116a3e0fd82Sopenharmony_ci return preLastPos_; 117a3e0fd82Sopenharmony_ci } 118a3e0fd82Sopenharmony_ci 119a3e0fd82Sopenharmony_ci /** 120a3e0fd82Sopenharmony_ci * @brief Obtains the direction in the drag event. 121a3e0fd82Sopenharmony_ci * @return Returns the direction. Available values are as follows: 122a3e0fd82Sopenharmony_ci * <b>0</b> indicates dragging from left to right. 123a3e0fd82Sopenharmony_ci * <b>1</b> indicates dragging from right to left. 124a3e0fd82Sopenharmony_ci * <b>2</b> indicates dragging from top to bottom. 125a3e0fd82Sopenharmony_ci * <b>3</b> indicates dragging from bottom to top. 126a3e0fd82Sopenharmony_ci * @since 1.0 127a3e0fd82Sopenharmony_ci * @version 1.0 128a3e0fd82Sopenharmony_ci */ 129a3e0fd82Sopenharmony_ci uint8_t GetDragDirection() const 130a3e0fd82Sopenharmony_ci { 131a3e0fd82Sopenharmony_ci if (MATH_ABS(curPos_.x - startPos_.x) >= MATH_ABS(curPos_.y - startPos_.y)) { 132a3e0fd82Sopenharmony_ci return (curPos_.x > startPos_.x) ? DIRECTION_LEFT_TO_RIGHT : DIRECTION_RIGHT_TO_LEFT; 133a3e0fd82Sopenharmony_ci } else { 134a3e0fd82Sopenharmony_ci return (curPos_.y > startPos_.y) ? DIRECTION_TOP_TO_BOTTOM : DIRECTION_BOTTOM_TO_TOP; 135a3e0fd82Sopenharmony_ci } 136a3e0fd82Sopenharmony_ci } 137a3e0fd82Sopenharmony_ci 138a3e0fd82Sopenharmony_ci /** 139a3e0fd82Sopenharmony_ci * @brief Obtains the difference between the current position and the last position of the view in the x-axis. 140a3e0fd82Sopenharmony_ci * @return Returns the different in the x-aix. 141a3e0fd82Sopenharmony_ci * @since 1.0 142a3e0fd82Sopenharmony_ci * @version 1.0 143a3e0fd82Sopenharmony_ci */ 144a3e0fd82Sopenharmony_ci int16_t GetDeltaX() const 145a3e0fd82Sopenharmony_ci { 146a3e0fd82Sopenharmony_ci return deltaX_; 147a3e0fd82Sopenharmony_ci } 148a3e0fd82Sopenharmony_ci 149a3e0fd82Sopenharmony_ci /** 150a3e0fd82Sopenharmony_ci * @brief Obtains the difference between the current position and the last position of the view in the y-axis. 151a3e0fd82Sopenharmony_ci * @return Returns the different in the y-aix. 152a3e0fd82Sopenharmony_ci * @since 1.0 153a3e0fd82Sopenharmony_ci * @version 1.0 154a3e0fd82Sopenharmony_ci */ 155a3e0fd82Sopenharmony_ci int16_t GetDeltaY() const 156a3e0fd82Sopenharmony_ci { 157a3e0fd82Sopenharmony_ci return deltaY_; 158a3e0fd82Sopenharmony_ci } 159a3e0fd82Sopenharmony_ci 160a3e0fd82Sopenharmony_ci static constexpr uint8_t DIRECTION_LEFT_TO_RIGHT = 0; 161a3e0fd82Sopenharmony_ci static constexpr uint8_t DIRECTION_RIGHT_TO_LEFT = 1; 162a3e0fd82Sopenharmony_ci static constexpr uint8_t DIRECTION_TOP_TO_BOTTOM = 2; 163a3e0fd82Sopenharmony_ci static constexpr uint8_t DIRECTION_BOTTOM_TO_TOP = 3; 164a3e0fd82Sopenharmony_ci 165a3e0fd82Sopenharmony_ciprivate: 166a3e0fd82Sopenharmony_ci Point lastPos_; 167a3e0fd82Sopenharmony_ci Point startPos_; 168a3e0fd82Sopenharmony_ci Point preLastPos_; 169a3e0fd82Sopenharmony_ci int16_t deltaX_; 170a3e0fd82Sopenharmony_ci int16_t deltaY_; 171a3e0fd82Sopenharmony_ci}; 172a3e0fd82Sopenharmony_ci} // namespace OHOS 173a3e0fd82Sopenharmony_ci#endif // GRAPHIC_LITE_DRAG_EVENT_H 174