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 AXIS_EVENT_H 17 #define AXIS_EVENT_H 18 19 #include "input_event.h" 20 21 namespace OHOS { 22 namespace MMI { 23 class AxisEvent : public InputEvent { 24 public: 25 /** 26 * Unknown action for the axis input event. It is usually used as initial value. 27 * 28 * @since 9 29 */ 30 static constexpr int32_t AXIS_ACTION_UNKNOWN = 0; 31 32 /** 33 * Cancel action for the axis input event. 34 * 35 * @since 9 36 */ 37 static constexpr int32_t AXIS_ACTION_CANCEL = 1; 38 39 /** 40 * Start action for the axis input event. 41 * 42 * @since 9 43 */ 44 static constexpr int32_t AXIS_ACTION_START = 2; 45 46 /** 47 * Update action for the axis input event. 48 * 49 * @since 9 50 */ 51 static constexpr int32_t AXIS_ACTION_UPDATE = 3; 52 53 /** 54 * End action for the axis input event. 55 * 56 * @since 9 57 */ 58 static constexpr int32_t AXIS_ACTION_END = 4; 59 60 /** 61 * Unknown axis type. It is the initial value of axis type. 62 * 63 * @since 9 64 */ 65 static constexpr int32_t AXIS_TYPE_UNKNOWN = 0; 66 67 public: 68 static std::shared_ptr<AxisEvent> from(std::shared_ptr<InputEvent> inputEvent); 69 static std::shared_ptr<AxisEvent> Create(); 70 71 public: 72 DISALLOW_COPY_AND_MOVE(AxisEvent); 73 virtual ~AxisEvent(); 74 75 /** 76 * @brief Obtains the action for the axis input event. 77 * @return Returns the action for the axis input event. 78 * @since 9 79 */ 80 int32_t GetAxisAction(); 81 82 /** 83 * @brief Sets the action for the axis input event. 84 * @param axisAction Indicates the action for the axis input event. 85 * @return void 86 * @since 9 87 */ 88 void SetAxisAction(int32_t axisAction); 89 90 /** 91 * @brief Obtains the type of the axis input event. 92 * @return Returns the type of the axis input event. 93 * @since 9 94 */ 95 int32_t GetAxisType() const; 96 97 /** 98 * @brief Sets the type of the axis input event. 99 * @param axisType Indicates the type of the axis input event. 100 * @return void 101 * @since 9 102 */ 103 void SetAxisType(int32_t axisType); 104 105 /** 106 * @brief Obtains the value of the axis input event. 107 * @return Returns the value of the axis input event. 108 * @since 9 109 */ 110 int32_t GetAxisValue() const; 111 112 /** 113 * @brief Sets the value of the axis input event. 114 * @param axisValue Value of the axis input event. 115 * @return void 116 * @since 9 117 */ 118 void SetAxisValue(int32_t axisValue); 119 120 /** 121 * @brief Converts a Axis event action into a short string. 122 * @param Indicates the Axis event action. 123 * @return Returns the string converted from the Axis action. 124 * @since 12 125 */ 126 static std::string_view ActionToShortStr(int32_t action); 127 protected: 128 /** 129 * @brief Constructs an input event object by using the specified input event type. Generally, this method 130 * is used to construct a base class object when constructing a derived class object. 131 * @since 9 132 */ 133 explicit AxisEvent(int32_t eventType); 134 135 private: 136 int32_t axisAction_ { 0 }; 137 int32_t axisType_ { 0 }; 138 int32_t axisValue_ { 0 }; 139 }; 140 } // namespace MMI 141 } // namespace OHOS 142 #endif // AXIS_EVENT_H