1  /*
2   * Copyright (c) 2020-2021 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  /**
17   * @addtogroup UI_Events
18   * @{
19   *
20   * @brief Defines UI events, such as press, click and drag events.
21   *
22   * @since 1.0
23   * @version 1.0
24   */
25  
26  /**
27   * @file event.h
28   *
29   * @brief Declares the base class of a user input event and provides functions to record information such as
30   *        the event position and timestamp.
31   *
32   * @since 1.0
33   * @version 1.0
34   */
35  
36  #ifndef GRAPHIC_LITE_EVENT_H
37  #define GRAPHIC_LITE_EVENT_H
38  
39  #include "gfx_utils/geometry2d.h"
40  #include "gfx_utils/graphic_types.h"
41  
42  namespace OHOS {
43  class UIView;
44  /**
45   * @brief Defines the base class of a user input event and provides functions to record information such as
46   *        the event position and timestamp.
47   *
48   * @since 1.0
49   * @version 1.0
50   */
51  class Event : public HeapBase {
52  public:
53      /**
54       * @brief A default constructor used to create an <b>Event</b> instance.
55       * @since 1.0
56       * @version 1.0
57       */
58      Event();
59  
60      /**
61       * @brief A constructor used to create an <b>Event</b> instance.
62       * @param pos Indicates the position where the event occurs.
63       * @since 1.0
64       * @version 1.0
65       */
66      Event(const Point& curPos);
67  
68      /**
69       * @brief A destructor used to delete the <b>Event</b> instance.
70       * @since 1.0
71       * @version 1.0
72       */
~Event()73      virtual ~Event() {}
74  
75      /**
76       * @brief Obtains the position where an event occurs.
77       * @return Returns the position.
78       * @since 1.0
79       * @version 1.0
80       */
GetCurrentPos()81      const Point& GetCurrentPos() const
82      {
83          return curPos_;
84      }
85  
86      /**
87      * @brief Obtains the timestamp when an event occurs.
88      * @return Returns the timestamp.
89      * @since 1.0
90      * @version 1.0
91      */
GetTimeStamp()92      const TimeType& GetTimeStamp() const
93      {
94          return timeStamp_;
95      }
96  
97      /**
98       * @brief Sets the timestamp when an event occurs.
99       * @param timeStamp Indicates the timestamp of the event to set.
100       * @since 1.0
101       * @version 1.0
102       */
SetTimeStamp(const TimeType & timeStamp)103      void SetTimeStamp(const TimeType& timeStamp)
104      {
105          timeStamp_ = timeStamp;
106      }
107  
108  protected:
109      TimeType timeStamp_;
110      Point curPos_;
111      UIView* targetView_ = nullptr;
112      UIView* currentView_ = nullptr;
113  };
114  } // namespace OHOS
115  #endif // GRAPHIC_LITE_EVENT_H
116