Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
91bf9827
D
Docs
项目概览
OpenHarmony
/
Docs
11 个月 前同步成功
通知
159
Star
292
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
91bf9827
编写于
7月 19, 2023
作者:
O
openharmony_ci
提交者:
Gitee
7月 19, 2023
浏览文件
操作
浏览文件
下载
差异文件
!20875 XComponent开发指导文档补充接口内容的使用方法
Merge pull request !20875 from WangJiazhen/master
上级
7960b309
0b26ad6f
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
269 addition
and
181 deletion
+269
-181
zh-cn/application-dev/napi/xcomponent-guidelines.md
zh-cn/application-dev/napi/xcomponent-guidelines.md
+269
-181
未找到文件。
zh-cn/application-dev/napi/xcomponent-guidelines.md
浏览文件 @
91bf9827
...
...
@@ -321,6 +321,94 @@ XComponent({ id: 'xcomponentId1', type: 'surface', libraryname: 'nativerender' }
render
->
OnKeyEvent
(
component
,
window
);
}
}
// 定义一个OnSurfaceChanged()方法
void
PluginRender
::
OnSurfaceChanged
(
OH_NativeXComponent
*
component
,
void
*
window
)
{
// ...
std
::
string
id
(
idStr
);
PluginRender
*
render
=
PluginRender
::
GetInstance
(
id
);
double
offsetX
;
double
offsetY
;
// 获取XComponent持有的surface相对窗口左上角的偏移量
OH_NativeXComponent_GetXComponentOffset
(
component
,
window
,
&
offsetX
,
&
offsetY
);
OH_LOG_Print
(
LOG_APP
,
LOG_INFO
,
LOG_PRINT_DOMAIN
,
"OH_NativeXComponent_GetXComponentOffset"
,
"offsetX = %{public}lf, offsetY = %{public}lf"
,
offsetX
,
offsetY
);
uint64_t
width
;
uint64_t
height
;
OH_NativeXComponent_GetXComponentSize
(
component
,
window
,
&
width
,
&
height
);
if
(
render
!=
nullptr
)
{
render
->
eglCore_
->
UpdateSize
(
width
,
height
);
}
}
// 定义一个OnTouchEvent()方法
void
PluginRender
::
OnTouchEvent
(
OH_NativeXComponent
*
component
,
void
*
window
)
{
// ...
OH_NativeXComponent_TouchEvent
touchEvent
;
// 获取由XComponent触发的触摸事件
OH_NativeXComponent_GetTouchEvent
(
component
,
window
,
&
touchEvent
);
std
::
string
id
(
idStr
);
PluginRender
*
render
=
PluginRender
::
GetInstance
(
id
);
if
(
render
!=
nullptr
&&
touchEvent
.
type
==
OH_NativeXComponent_TouchEventType
::
OH_NATIVEXCOMPONENT_UP
)
{
render
->
eglCore_
->
ChangeColor
();
hasChangeColor_
=
1
;
}
float
tiltX
=
0.0
f
;
float
tiltY
=
0.0
f
;
OH_NativeXComponent_TouchPointToolType
toolType
=
OH_NativeXComponent_TouchPointToolType
::
OH_NATIVEXCOMPONENT_TOOL_TYPE_UNKNOWN
;
// 获取XComponent触摸点的工具类型
OH_NativeXComponent_GetTouchPointToolType
(
component
,
0
,
&
toolType
);
// 获取XComponent触摸点处相对X轴的倾斜角度
OH_NativeXComponent_GetTouchPointTiltX
(
component
,
0
,
&
tiltX
);
// 获取XComponent触摸点处相对Y轴的倾斜角度
OH_NativeXComponent_GetTouchPointTiltY
(
component
,
0
,
&
tiltY
);
OH_LOG_Print
(
LOG_APP
,
LOG_INFO
,
LOG_PRINT_DOMAIN
,
"OnTouchEvent"
,
"touch info: toolType = %{public}d, tiltX = %{public}lf, tiltY = %{public}lf"
,
toolType
,
tiltX
,
tiltY
);
}
// 定义一个OnMouseEvent()方法
void
PluginRender
::
OnMouseEvent
(
OH_NativeXComponent
*
component
,
void
*
window
)
{
OH_LOG_Print
(
LOG_APP
,
LOG_INFO
,
LOG_PRINT_DOMAIN
,
"PluginRender"
,
"OnMouseEvent"
);
OH_NativeXComponent_MouseEvent
mouseEvent
;
// 获取由XComponent触发的鼠标事件
int32_t
ret
=
OH_NativeXComponent_GetMouseEvent
(
component
,
window
,
&
mouseEvent
);
if
(
ret
==
OH_NATIVEXCOMPONENT_RESULT_SUCCESS
)
{
OH_LOG_Print
(
LOG_APP
,
LOG_INFO
,
LOG_PRINT_DOMAIN
,
"PluginRender"
,
"MouseEvent Info: x = %{public}f, y = %{public}f, action = %{public}d, button = %{public}d"
,
mouseEvent
.
x
,
mouseEvent
.
y
,
mouseEvent
.
action
,
mouseEvent
.
button
);
}
else
{
OH_LOG_Print
(
LOG_APP
,
LOG_ERROR
,
LOG_PRINT_DOMAIN
,
"PluginRender"
,
"GetMouseEvent error"
);
}
}
// 定义一个OnMouseEvent()方法
void
PluginRender
::
OnKeyEvent
(
OH_NativeXComponent
*
component
,
void
*
window
)
{
OH_LOG_Print
(
LOG_APP
,
LOG_INFO
,
LOG_PRINT_DOMAIN
,
"PluginRender"
,
"OnKeyEvent"
);
OH_NativeXComponent_KeyEvent
*
keyEvent
=
nullptr
;
// 获取由XComponent触发的按键事件。
if
(
OH_NativeXComponent_GetKeyEvent
(
component
,
&
keyEvent
)
>=
0
)
{
OH_NativeXComponent_KeyAction
action
;
// 获取按键事件的动作
OH_NativeXComponent_GetKeyEventAction
(
keyEvent
,
&
action
);
OH_NativeXComponent_KeyCode
code
;
// 获取按键事件的键码值
OH_NativeXComponent_GetKeyEventCode
(
keyEvent
,
&
code
);
OH_NativeXComponent_EventSourceType
sourceType
;
// 获取按键事件的输入源类型
OH_NativeXComponent_GetKeyEventSourceType
(
keyEvent
,
&
sourceType
);
int64_t
deviceId
;
// 获取按键事件的设备ID
OH_NativeXComponent_GetKeyEventDeviceId
(
keyEvent
,
&
deviceId
);
int64_t
timeStamp
;
// 获取按键事件的时间戳
OH_NativeXComponent_GetKeyEventTimestamp
(
keyEvent
,
&
timeStamp
);
OH_LOG_Print
(
LOG_APP
,
LOG_INFO
,
LOG_PRINT_DOMAIN
,
"PluginRender"
,
"KeyEvent Info: action=%{public}d, code=%{public}d, sourceType=%{public}d, deviceId=%{public}ld, timeStamp=%{public}ld"
,
action
,
code
,
sourceType
,
deviceId
,
timeStamp
);
}
else
{
OH_LOG_Print
(
LOG_APP
,
LOG_ERROR
,
LOG_PRINT_DOMAIN
,
"PluginRender"
,
"GetKeyEvent error"
);
}
}
```
(2) 注册XComponent事件回调函数,在XComponent事件触发时调用3.1步骤中定义的方法。
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录