diff --git a/zh-cn/native_sdk/ace/native_interface_xcomponent.h b/zh-cn/native_sdk/ace/native_interface_xcomponent.h new file mode 100644 index 0000000000000000000000000000000000000000..8a215d2d027d405949346f6e3ce0b021b7bafe35 --- /dev/null +++ b/zh-cn/native_sdk/ace/native_interface_xcomponent.h @@ -0,0 +1,218 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @addtogroup ACE + * @{ + * + * @brief 提供设置和获取组件的数据与回调的功能 + * @since 8 + * @version 1.0 + */ + +/** + * @file native_interface_xcomponent.h + * + * @brief 声明APIs以此获得原生xcomponent的数据 + * + * @since 8 + * @version 1.0 + */ + +#ifndef _NATIVE_INTERFACE_XCOMPONENT_H_ +#define _NATIVE_INTERFACE_XCOMPONENT_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief 枚举返回值类型 + * + * @since 8 + * @version 1.0 + */ +enum { + /* 成功结果 */ + OH_NATIVEXCOMPONENT_RESULT_SUCCESS = 0, + /* 失败的结果 */ + OH_NATIVEXCOMPONENT_RESULT_FAILED = -1, + /* 无效参数 */ + OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER = -2, +}; + +enum OH_NativeXComponent_TouchEventType { + OH_NATIVEXCOMPONENT_DOWN = 0, + OH_NATIVEXCOMPONENT_UP, + OH_NATIVEXCOMPONENT_MOVE, + OH_NATIVEXCOMPONENT_CANCEL, + OH_NATIVEXCOMPONENT_UNKNOWN, +}; + +#define OH_NATIVE_XCOMPONENT_OBJ ("__NATIVE_XCOMPONENT_OBJ__") +const uint32_t OH_XCOMPONENT_ID_LEN_MAX = 128; +const uint32_t OH_MAX_TOUCH_POINTS_NUMBER = 10; + +struct OH_NativeXComponent_TouchPoint { + // 手指与屏幕间的接触点ID + int32_t id = 0; + // 触摸点相对于屏幕左上角的水平距离 + float screenX = 0.0; + // 触摸点相对于屏幕左上角的垂直距离 + float screenY = 0.0; + // 触摸点相对于被触摸的元素左上角的水平距离 + float x = 0.0; + // 触摸点相对于被触摸的元素左上角的垂直距离 + float y = 0.0; + // 触摸事件的触摸类型 + OH_NativeXComponent_TouchEventType type = OH_NativeXComponent_TouchEventType::OH_NATIVEXCOMPONENT_UNKNOWN; + // 环绕用户与触摸屏的接触面尺寸 + double size = 0.0; + // 手指按压触摸屏的压力 + float force = 0.0; + // 触摸事件的时间戳 + long long timeStamp = 0; + // 点是否被按下 + bool isPressed = false; +}; + +// 活动改变点信息 +struct OH_NativeXComponent_TouchEvent { + // 手指与屏幕间的接触点ID + int32_t id = 0; + // 触摸点相对于屏幕左上角的水平距离 + float screenX = 0.0; + // 触摸点相对于屏幕左上角的垂直距离 + float screenY = 0.0; + // 触摸点相对于被触摸的元素左上角的水平距离 + float x = 0.0; + // 触摸点相对于被触摸的元素左上角的垂直距离 + float y = 0.0; + // 触摸事件的触摸类型 + OH_NativeXComponent_TouchEventType type = OH_NativeXComponent_TouchEventType::OH_NATIVEXCOMPONENT_UNKNOWN; + // 环绕用户与触摸屏的接触面尺寸 + double size = 0.0; + // 手指按压触摸屏的压力 + float force = 0.0; + // 设备编号 + int64_t deviceId = 0; + // 触摸事件的时间戳 + long long timeStamp = 0; + // 触摸屏上所有的点 + OH_NativeXComponent_TouchPoint touchPoints[OH_MAX_TOUCH_POINTS_NUMBER]; + // 触摸指针的数量 + uint32_t numPoints = 0; +}; + +/** + * @brief 定义NativeXComponent对象,通常通过指针访问 + * + * @since 8 + * @version 1.0 + */ +typedef struct OH_NativeXComponent OH_NativeXComponent; + +/** + * @brief 定义NativeXComponentCallback结构体, 保持表面生命周期的回调 + * + * @since 8 + * @version 1.0 + */ +typedef struct OH_NativeXComponent_Callback { + /* 在创建或重新创建原生surface时调用 */ + void (*OnSurfaceCreated)(OH_NativeXComponent* component, void* window); + /* 在原生surface改变时调用 */ + void (*OnSurfaceChanged)(OH_NativeXComponent* component, void* window); + /* 在原生surface被破坏时调用 */ + void (*OnSurfaceDestroyed)(OH_NativeXComponent* component, void* window); + /* 在触摸事件触发时调用 */ + void (*DispatchTouchEvent)(OH_NativeXComponent* component, void* window); +} OH_NativeXComponent_Callback; + +/** + * @brief 获取xcomponent的id. + * + * @param component 表示指向NativeXComponent实例的指针 + * @param id 表示保存xcomponent ID的字符缓冲区 + * 请注意,空终止符将附加到字符缓冲区,因此字符缓冲区的大小应至少与真实id长度的大小加1一样大 + * 字符缓冲区的大小建议为[OH_XCOMPONENT_ID_LEN_MAX + 1] + * @param size 是一个输入输出参数 + * [in] 表示id字符缓冲区的长度(包括空终止符) + * size的引用值应在(0, OH_XCOMPONENT_ID_LEN_MAX + 1]范围内 + * [out] 接收id的长度(不包括空终止符) + * @return 返回执行结果 + * @since 8 + * @version 1.0 + */ +int32_t OH_NativeXComponent_GetXComponentId(OH_NativeXComponent* component, char* id, uint64_t* size); + +/** + * @brief 获取xcomponent的大小 + * + * @param component 表示指向NativeXComponent实例的指针 + * @param window 表示本机窗口处理程序 + * @param width 表示指向xcomponent宽度的指针. + * @param height 表示指向xcomponent高度的指针. + * @return 返回执行结果 + * @since 8 + * @version 1.0 + */ +int32_t OH_NativeXComponent_GetXComponentSize( + OH_NativeXComponent* component, const void* window, uint64_t* width, uint64_t* height); + +/** + * @brief 获取xcomponent的偏移量 + * + * @param component 表示指向NativeXComponent实例的指针 + * @param window 表示本机窗口处理程序 + * @param x 表示指向xcomponent相对于屏幕左上角的水平坐标的指针 + * @param y 表示指向xcomponent相对于屏幕左上角的纵坐标的指针 + * @return 返回执行结果 + * @since 8 + * @version 1.0 + */ +int32_t OH_NativeXComponent_GetXComponentOffset( + OH_NativeXComponent* component, const void* window, double* x, double* y); + +/** + * @brief 获取触摸事件的信息 + * + * @param component 表示指向NativeXComponent实例的指针 + * @param window 表示本机窗口处理程序 + * @param touchInfo 表示指向当前触摸信息的指针 + * @return 返回执行结果 + * @since 8 + * @version 1.0 + */ +int32_t OH_NativeXComponent_GetTouchEvent( + OH_NativeXComponent* component, const void* window, OH_NativeXComponent_TouchEvent* touchEvent); + +/** + * @brief 设置xcomponent的回调 + * + * @param component 表示指向NativeXComponent实例的指针 + * @param callback 表示本机表面生命周期的回调 + * @return 返回执行结果 + * @since 8 + * @version 1.0 + */ +int32_t OH_NativeXComponent_RegisterCallback(OH_NativeXComponent* component, OH_NativeXComponent_Callback* callback); + +#ifdef __cplusplus +}; +#endif +#endif // _NATIVE_INTERFACE_XCOMPONENT_H_ \ No newline at end of file