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 /** 17 * @addtogroup ArkUI_NativeModule 18 * @{ 19 * 20 * @brief 提供ArkUI在Native侧的UI能力,如UI组件创建销毁、树节点操作,属性设置,事件监听等。 21 * 22 * @since 12 23 */ 24 25 /** 26 * @file native_event.h 27 * 28 * @brief 提供ArkUI在Native侧的事件类型定义集合。 29 * 30 * @library libace_ndk.z.so 31 * @syscap SystemCapability.ArkUI.ArkUI.Full 32 * @since 12 33 */ 34 35 #ifndef ARKUI_NATIVE_EVENT 36 #define ARKUI_NATIVE_EVENT 37 38 #include <stdbool.h> 39 #include <stdint.h> 40 41 #ifdef __cplusplus 42 extern "C" { 43 #endif 44 45 /** 46 * @brief Touch事件的工具类型定义。 47 * 48 * @since 12 49 */ 50 typedef enum { 51 /** 不支持的工具类型。 */ 52 NODE_TOOL_TYPE_UNKNOWN = -1, 53 54 /** 手指。 */ 55 NODE_TOOL_TYPE_FINGER = 0, 56 57 /** 笔。 */ 58 NODE_TOOL_TYPE_PEN = 1, 59 } ArkUI_NodeToolType; 60 61 /** 62 * @brief 产生Touch事件的来源类型定义。 63 * 64 * @since 12 65 */ 66 typedef enum { 67 /** 不支持的来源类型。 */ 68 NODE_SOURCE_TYPE_UNKNOWN = -1, 69 /** 触摸屏。 */ 70 NODE_SOURCE_TYPE_TOUCH_SCREEN = 0, 71 /** 手写笔。 */ 72 NODE_SOURCE_TYPE_PEN = 1, 73 /** 触控板。 */ 74 NODE_SOURCE_TYPE_TOUCH_PAD = 2, 75 } ArkUI_NodeSourceType; 76 77 /** 78 * @brief 定义Touch事件触控点信息的数据结构。 79 * 80 * @since 12 81 */ 82 typedef struct { 83 /** 触控事件标识。 */ 84 int32_t id; 85 86 /** 手指按下的时间戳,单位为微秒(us)。*/ 87 int64_t pressedTime; 88 89 /** 触摸位置所属的屏幕X坐标。 */ 90 int32_t screenX; 91 92 /** 触摸位置所属的屏幕Y坐标。 */ 93 int32_t screenY; 94 95 /** 触摸位置在窗口中的X坐标。 */ 96 int32_t windowX; 97 98 /** 触摸位置在窗口中的Y坐标。 */ 99 int32_t windowY; 100 101 /** 触摸位置在当前触发事件组件中的X坐标。 */ 102 int32_t nodeX; 103 104 /** 触摸位置在当前触发事件组件中的Y坐标。 */ 105 int32_t nodeY; 106 107 /** 压力值,取值范围是[0.0, 1.0],0.0表示不支持。 */ 108 double pressure; 109 110 /** 触摸区域的宽度。 */ 111 int32_t contactAreaWidth; 112 113 /** 触摸区域的高度。 */ 114 int32_t contactAreaHeight; 115 116 /** 相对YZ平面的角度,取值范围是[-90, 90],其中正值是向右倾斜。 */ 117 double tiltX; 118 119 /** 相对XZ平面的角度,取值范围是[-90, 90],其中正值是向下倾斜。 */ 120 double tiltY; 121 122 /** 工具区域的中心点X坐标。 */ 123 int32_t toolX; 124 125 /** 工具区域的中心点Y坐标。 */ 126 int32_t toolY; 127 128 /** 工具接触区域的宽度。 */ 129 int32_t toolWidth; 130 131 /** 工具接触区域的高度。 */ 132 int32_t toolHeight; 133 134 /** 输入设备上的X坐标。 */ 135 int32_t rawX; 136 137 /** 输入设备上的Y坐标。 */ 138 int32_t rawY; 139 140 /** 工具类型。 */ 141 ArkUI_NodeToolType toolType; 142 } ArkUI_NodeTouchPoint; 143 144 /** 145 * @brief 定义触屏事件类型的枚举值。 146 * 147 * @since 12 148 */ 149 typedef enum { 150 /** 触摸取消。 */ 151 NODE_ACTION_CANCEL = 0, 152 /** 触摸按下。 */ 153 NODE_ACTION_DOWN = 1, 154 /** 触摸移动。 */ 155 NODE_ACTION_MOVE = 2, 156 /** 触摸抬起。 */ 157 NODE_ACTION_UP = 3, 158 } ArkUI_NodeTouchEventAction; 159 160 /** 161 * @brief 定义历史点信息的结构类型。 162 * 163 * @since 12 164 */ 165 typedef struct { 166 /** 触屏事件类型。*/ 167 ArkUI_NodeTouchEventAction action; 168 /** 触屏历史事件时间戳,单位为微秒(us)。*/ 169 int64_t timeStamp; 170 /** 历史触摸事件来源类型。*/ 171 ArkUI_NodeTouchPoint actionTouch; 172 /** 历史触摸事件来源类型。*/ 173 ArkUI_NodeSourceType sourceType; 174 } ArkUI_NodeHistoricalTouchPoint; 175 176 /** 177 * @brief 定义Touch事件的结构类型。 178 * 179 * @since 12 180 */ 181 typedef struct { 182 /** 触屏事件的类型。*/ 183 ArkUI_NodeTouchEventAction action; 184 185 /** 触屏事件时间戳,单位为微秒(us)。 */ 186 int64_t timeStamp; 187 188 /** 当前触屏事件的触控点信息。*/ 189 ArkUI_NodeTouchPoint actionTouch; 190 191 /** 192 * @brief 返回此事件发生时所有屏幕接触点信息。 193 * @param points 用来接受数据的指针对象。 194 * @return 屏幕接触点数据数组元素数量。 195 * @note 196 * ArkUI会在该函数调用时创建触控点信息数组的堆内存对象并返回指针,开发者需要在使用完成后调用delete[]手动释放内存。 197 */ 198 int32_t (*getTouches)(ArkUI_NodeTouchPoint** points); 199 200 /** 201 * @brief 返回此事件中的历史点信息。这些是在此事件和上一个事件之间发生的运动。 202 * @param points 用来接受数据的指针对象。 203 * @return 历史点数据数组元素数量。 204 * @note 205 * 框架会在该函数调用时创建历史点数据数组的堆内存对象并返回指针,开发者需要在使用完成后调用delete[]手动释放内存。 206 */ 207 int32_t (*getHistoricalPoints)(ArkUI_NodeHistoricalTouchPoint** historicalPoints); 208 209 /** 触发事件来源的类型。*/ 210 ArkUI_NodeSourceType sourceType; 211 212 /** 阻止事件进一步向父节点冒泡处理。*/ 213 bool stopPropagation; 214 215 /** 阻止当前节点的默认事件处理行为,允许事件进一步向上冒泡。*/ 216 bool preventDefault; 217 } ArkUI_NodeTouchEvent; 218 219 #ifdef __cplusplus 220 }; 221 #endif 222 223 #endif // ARKUI_NATIVE_EVENT 224 /** @} */ 225