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