1 /* 2 * Copyright (c) 2024 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 FOUNDATION_ACE_FRAMEWORKS_CORE_EVENT_FOCUS_AXIS_EVENT_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_EVENT_FOCUS_AXIS_EVENT_H 18 19 #include "core/event/non_pointer_event.h" 20 #include "core/components_ng/event/event_constants.h" 21 22 namespace OHOS::Ace::NG { 23 24 struct FocusAxisEvent final : public NonPointerEvent { 25 int32_t id = 0; 26 AxisAction action = AxisAction::NONE; 27 SourceTool sourceTool = SourceTool::UNKNOWN; 28 std::shared_ptr<MMI::PointerEvent> pointerEvent; 29 int32_t touchEventId = 0; 30 std::vector<KeyCode> pressedCodes; 31 int32_t targetDisplayId = 0; 32 int32_t originalId = 0; 33 float absXValue = 0.0f; 34 float absYValue = 0.0f; 35 float absZValue = 0.0f; 36 float absRzValue = 0.0f; 37 float absHat0XValue = 0.0f; 38 float absHat0YValue = 0.0f; 39 float absBrakeValue = 0.0f; 40 float absGasValue = 0.0f; 41 ~FocusAxisEvent() = default; FocusAxisEventfinal42 FocusAxisEvent() 43 { 44 eventType = UIInputEventType::FOCUS_AXIS; 45 } 46 SetIdfinal47 FocusAxisEvent& SetId(int32_t id) 48 { 49 this->id = id; 50 return *this; 51 } 52 SetActionfinal53 FocusAxisEvent& SetAction(AxisAction action) 54 { 55 this->action = action; 56 return *this; 57 } 58 SetSourceToolfinal59 FocusAxisEvent& SetSourceTool(SourceTool sourceTool) 60 { 61 this->sourceTool = sourceTool; 62 return *this; 63 } 64 SetPointerEventfinal65 FocusAxisEvent& SetPointerEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) 66 { 67 this->pointerEvent = std::move(pointerEvent); 68 return *this; 69 } 70 SetTouchEventIdfinal71 FocusAxisEvent& SetTouchEventId(int32_t touchEventId) 72 { 73 this->touchEventId = touchEventId; 74 return *this; 75 } 76 SetPressedKeyCodesfinal77 FocusAxisEvent& SetPressedKeyCodes(const std::vector<KeyCode>& pressedCodes) 78 { 79 this->pressedCodes = pressedCodes; 80 return *this; 81 } 82 SetTargetDisplayIdfinal83 FocusAxisEvent& SetTargetDisplayId(int32_t targetDisplayId) 84 { 85 this->targetDisplayId = targetDisplayId; 86 return *this; 87 } 88 SetOriginalIdfinal89 FocusAxisEvent& SetOriginalId(int32_t originalId) 90 { 91 this->originalId = originalId; 92 return *this; 93 } 94 SetAbsXValuefinal95 FocusAxisEvent& SetAbsXValue(float absXValue) 96 { 97 this->absXValue = absXValue; 98 return *this; 99 } 100 SetAbsYValuefinal101 FocusAxisEvent& SetAbsYValue(float absYValue) 102 { 103 this->absYValue = absYValue; 104 return *this; 105 } 106 SetAbsZValuefinal107 FocusAxisEvent& SetAbsZValue(float absZValue) 108 { 109 this->absZValue = absZValue; 110 return *this; 111 } 112 SetAbsRzValuefinal113 FocusAxisEvent& SetAbsRzValue(float absRzValue) 114 { 115 this->absRzValue = absRzValue; 116 return *this; 117 } 118 SetAbsHat0XValuefinal119 FocusAxisEvent& SetAbsHat0XValue(float absHat0XValue) 120 { 121 this->absHat0XValue = absHat0XValue; 122 return *this; 123 } 124 SetAbsHat0YValuefinal125 FocusAxisEvent& SetAbsHat0YValue(float absHat0YValue) 126 { 127 this->absHat0YValue = absHat0YValue; 128 return *this; 129 } 130 SetAbsBrakeValuefinal131 FocusAxisEvent& SetAbsBrakeValue(float absBrakeValue) 132 { 133 this->absBrakeValue = absBrakeValue; 134 return *this; 135 } 136 SetAbsGasValuefinal137 FocusAxisEvent& SetAbsGasValue(float absGasValue) 138 { 139 this->absGasValue = absGasValue; 140 return *this; 141 } 142 }; 143 144 class ACE_EXPORT FocusAxisEventInfo : public BaseEventInfo { DECLARE_RELATIONSHIP_OF_CLASSES(FocusAxisEventInfo,BaseEventInfo)145 DECLARE_RELATIONSHIP_OF_CLASSES(FocusAxisEventInfo, BaseEventInfo) 146 147 public: 148 explicit FocusAxisEventInfo(const FocusAxisEvent& event) : BaseEventInfo("focusAxisEvent") 149 { 150 absXValue = event.absXValue; 151 absYValue = event.absYValue; 152 absZValue = event.absZValue; 153 absRzValue = event.absRzValue; 154 absHat0XValue = event.absHat0XValue; 155 absHat0YValue = event.absHat0YValue; 156 absBrakeValue = event.absBrakeValue; 157 absGasValue = event.absGasValue; 158 timeStamp_ = event.time; 159 sourceTool_ = event.sourceTool; 160 deviceType_ = event.sourceType; 161 deviceId_ = event.deviceId; 162 pressedKeyCodes_ = event.pressedCodes; 163 }; 164 ~FocusAxisEventInfo() override = default; 165 GetAbsXValue()166 float GetAbsXValue() const 167 { 168 return absXValue; 169 } 170 GetAbsYValue()171 float GetAbsYValue() const 172 { 173 return absYValue; 174 } 175 GetAbsZValue()176 float GetAbsZValue() const 177 { 178 return absZValue; 179 } 180 GetAbsRzValue()181 float GetAbsRzValue() const 182 { 183 return absRzValue; 184 } 185 GetAbsHat0XValue()186 float GetAbsHat0XValue() const 187 { 188 return absHat0XValue; 189 } 190 GetAbsHat0YValue()191 float GetAbsHat0YValue() const 192 { 193 return absHat0YValue; 194 } 195 GetAbsBrakeValue()196 float GetAbsBrakeValue() const 197 { 198 return absBrakeValue; 199 } 200 GetAbsGasValue()201 float GetAbsGasValue() const 202 { 203 return absGasValue; 204 } 205 206 private: 207 float absXValue = 0.0f; 208 float absYValue = 0.0f; 209 float absZValue = 0.0f; 210 float absRzValue = 0.0f; 211 float absHat0XValue = 0.0f; 212 float absHat0YValue = 0.0f; 213 float absBrakeValue = 0.0f; 214 float absGasValue = 0.0f; 215 }; 216 217 } // namespace OHOS::Ace::NG 218 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_EVENT_FOCUS_AXIS_EVENT_H 219