Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
1d1ad942
D
Docs
项目概览
OpenHarmony
/
Docs
接近 2 年 前同步成功
通知
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看板
未验证
提交
1d1ad942
编写于
9月 29, 2022
作者:
L
luoying_ace
提交者:
Gitee
9月 29, 2022
1
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-shape.md.
Signed-off-by:
N
luoying_ace
<
luoying19@huawei.com
>
上级
28f05f8b
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
138 addition
and
30 deletion
+138
-30
zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-shape.md
...ion-dev/reference/arkui-ts/ts-drawing-components-shape.md
+138
-30
未找到文件。
zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-shape.md
浏览文件 @
1d1ad942
...
...
@@ -48,7 +48,7 @@ Shape(value?: PixelMap)
| antiAlias | boolean | true | 否 | 是否开启抗锯齿效果。 |
| mesh
<sup>
8+
</sup>
| Array
<
number
>
,number,number | [],0,0 | 否 | 设置mesh效果。第一个参数为长度(column + 1)
* (row + 1)*
2的数组,它记录了扭曲后的位图各个顶点位置,第二个参数为mesh矩阵列数column,第三个参数为mesh矩阵行数row。 |
## 示例
## 示例
1
```
ts
// xxx.ets
...
...
@@ -56,61 +56,169 @@ Shape(value?: PixelMap)
@
Component
struct
ShapeExample
{
build
()
{
Column
({
space
:
5
})
{
Text
(
'
basic
'
).
fontSize
(
30
).
fontColor
(
0xCCCCCC
).
width
(
320
)
// 在Shape的(-2, -2)点绘制一个 300 * 50 带边框的矩形,颜色0x317A
f7,边框颜色黑色,边框宽度4,边框间隙20,向左偏移10,尖端样式圆角
,拐角样式圆角,抗锯齿(默认开启)
// 在Shape的(-2, 58)点绘制一个 300 * 50 带边框的椭圆,颜色0x317A
f7,边框颜色黑色,边框宽度4,边框间隙20,向左偏移10,尖端样式圆角
,拐角样式圆角,抗锯齿(默认开启)
// 在Shape的(-2, 118)点绘制一个 300 * 10
线段,颜色0x317Af7,边框颜色黑色,宽度4,间隙20,向左偏移10,尖端样式圆角
,拐角样式圆角,抗锯齿(默认开启)
Column
({
space
:
10
})
{
Text
(
'
basic
'
).
fontSize
(
11
).
fontColor
(
0xCCCCCC
).
width
(
320
)
// 在Shape的(-2, -2)点绘制一个 300 * 50 带边框的矩形,颜色0x317A
F7,边框颜色黑色,边框宽度4,边框间隙20,向左偏移10,线条两端样式为半圆
,拐角样式圆角,抗锯齿(默认开启)
// 在Shape的(-2, 58)点绘制一个 300 * 50 带边框的椭圆,颜色0x317A
F7,边框颜色黑色,边框宽度4,边框间隙20,向左偏移10,线条两端样式为半圆
,拐角样式圆角,抗锯齿(默认开启)
// 在Shape的(-2, 118)点绘制一个 300 * 10
直线路径,颜色0x317AF7,边框颜色黑色,宽度4,间隙20,向左偏移10,线条两端样式为半圆
,拐角样式圆角,抗锯齿(默认开启)
Shape
()
{
Rect
().
width
(
300
).
height
(
50
)
Ellipse
().
width
(
300
).
height
(
50
).
offset
({
x
:
0
,
y
:
60
})
Path
().
width
(
300
).
height
(
10
).
commands
(
'
M0 0 L900 0
'
).
offset
({
x
:
0
,
y
:
120
})
}
.
viewPort
({
x
:
-
2
,
y
:
-
2
,
width
:
304
,
height
:
130
})
.
fill
(
0x317Af7
).
stroke
(
Color
.
Black
).
strokeWidth
(
4
)
.
strokeDashArray
([
20
]).
strokeDashOffset
(
10
).
strokeLineCap
(
LineCapStyle
.
Round
)
.
strokeLineJoin
(
LineJoinStyle
.
Round
).
antiAlias
(
true
)
// 在Shape的(-1, -1)点绘制一个 300 * 50 带边框的矩形,颜色0x317Af7,边框颜色黑色,边框宽度2
.
fill
(
0x317AF7
)
.
stroke
(
Color
.
Black
)
.
strokeWidth
(
4
)
.
strokeDashArray
([
20
])
.
strokeDashOffset
(
10
)
.
strokeLineCap
(
LineCapStyle
.
Round
)
.
strokeLineJoin
(
LineJoinStyle
.
Round
)
.
antiAlias
(
true
)
// 分别在Shape的(0, 0)、(-5, -5)点绘制一个 300 * 50 带边框的矩形,可以看出之所以将视口的起始位置坐标设为负值是因为绘制的起点默认为线宽的中点位置,因此要让边框完全显示则需要让视口偏移半个线宽
Shape
()
{
Rect
().
width
(
300
).
height
(
50
)
}.
viewPort
({
x
:
-
1
,
y
:
-
1
,
width
:
302
,
height
:
52
}).
fill
(
0x317Af7
).
stroke
(
Color
.
Black
).
strokeWidth
(
2
)
}
.
viewPort
({
x
:
0
,
y
:
0
,
width
:
320
,
height
:
70
})
.
fill
(
0x317AF7
)
.
stroke
(
Color
.
Black
)
.
strokeWidth
(
10
)
Text
(
'
border
'
).
fontSize
(
30
).
fontColor
(
0xCCCCCC
).
width
(
320
).
margin
({
top
:
30
})
// 在Shape的(0, -5)点绘制一个 300 * 10 直线,颜色0xEE8443,边框宽度10,边框间隙20
Shape
()
{
Path
().
width
(
300
).
height
(
10
).
commands
(
'
M0 0 L900 0
'
)
}.
viewPort
({
x
:
0
,
y
:
-
5
,
width
:
300
,
height
:
20
}).
stroke
(
0xEE8443
).
strokeWidth
(
10
).
strokeDashArray
([
20
])
// 在Shape的(0, -5)点绘制一个 300 * 10 直线,颜色0xEE8443,边框宽度10,边框间隙20,向左偏移10
Rect
().
width
(
300
).
height
(
50
)
}
.
viewPort
({
x
:
-
5
,
y
:
-
5
,
width
:
320
,
height
:
70
})
.
fill
(
0x317AF7
)
.
stroke
(
Color
.
Black
)
.
strokeWidth
(
10
)
Text
(
'
path
'
).
fontSize
(
11
).
fontColor
(
0xCCCCCC
).
width
(
320
)
// 在Shape的(0, -5)点绘制一条直线路径,颜色0xEE8443,线条宽度10,线条间隙20
Shape
()
{
Path
().
width
(
300
).
height
(
10
).
commands
(
'
M0 0 L900 0
'
)
}
.
viewPort
({
x
:
0
,
y
:
-
5
,
width
:
300
,
height
:
20
})
.
stroke
(
0xEE8443
).
strokeWidth
(
10
).
strokeDashArray
([
20
]).
strokeDashOffset
(
10
)
// 在Shape的(0, -5)点绘制一个 300 * 10 直线,颜色0xEE8443,边框宽度10,透明度0.5
.
stroke
(
0xEE8443
)
.
strokeWidth
(
10
)
.
strokeDashArray
([
20
])
// 在Shape的(0, -5)点绘制一条直线路径,颜色0xEE8443,线条宽度10,线条间隙20,向左偏移10
Shape
()
{
Path
().
width
(
300
).
height
(
10
).
commands
(
'
M0 0 L900 0
'
)
}.
viewPort
({
x
:
0
,
y
:
-
5
,
width
:
300
,
height
:
20
}).
stroke
(
0xEE8443
).
strokeWidth
(
10
).
strokeOpacity
(
0.5
)
// 在Shape的(0, -5)点绘制一个 300 * 10 直线,颜色0xEE8443,边框宽度10,边框间隙20,向左偏移10,尖端样式圆角
}
.
viewPort
({
x
:
0
,
y
:
-
5
,
width
:
300
,
height
:
20
})
.
stroke
(
0xEE8443
)
.
strokeWidth
(
10
)
.
strokeDashArray
([
20
])
.
strokeDashOffset
(
10
)
// 在Shape的(0, -5)点绘制一条直线路径,颜色0xEE8443,线条宽度10,透明度0.5
Shape
()
{
Path
().
width
(
300
).
height
(
10
).
commands
(
'
M0 0 L900 0
'
)
}
.
viewPort
({
x
:
0
,
y
:
-
5
,
width
:
300
,
height
:
20
})
.
stroke
(
0xEE8443
).
strokeWidth
(
10
).
strokeDashArray
([
20
]).
strokeLineCap
(
LineCapStyle
.
Round
)
// 在Shape的(-5, -5)点绘制一个 300 * 50 带边框的矩形,颜色0x317Af7,边框宽度10,边框颜色0xEE8443,拐角样式圆角
.
stroke
(
0xEE8443
)
.
strokeWidth
(
10
)
.
strokeOpacity
(
0.5
)
// 在Shape的(0, -5)点绘制一条直线路径,颜色0xEE8443,线条宽度10,线条间隙20,线条两端样式为半圆
Shape
()
{
Rect
().
width
(
300
).
height
(
100
)
Path
().
width
(
300
).
height
(
10
).
commands
(
'
M0 0 L900 0
'
)
}
.
viewPort
({
x
:
-
5
,
y
:
-
5
,
width
:
310
,
height
:
120
})
.
fill
(
0x317Af7
).
stroke
(
0xEE8443
).
strokeWidth
(
10
).
strokeLineJoin
(
LineJoinStyle
.
Round
)
.
viewPort
({
x
:
0
,
y
:
-
5
,
width
:
300
,
height
:
20
})
.
stroke
(
0xEE8443
)
.
strokeWidth
(
10
)
.
strokeDashArray
([
20
])
.
strokeLineCap
(
LineCapStyle
.
Round
)
// 在Shape的(-80, -5)点绘制一个封闭路径,颜色0x317AF7,线条宽度10,边框颜色0xEE8443,拐角样式锐角(默认值)
Shape
()
{
Path
().
width
(
300
).
height
(
60
).
commands
(
'
M0 0 L400 0 L400 20
0 Z
'
)
Path
().
width
(
200
).
height
(
60
).
commands
(
'
M0 0 L400 0 L400 15
0 Z
'
)
}
.
viewPort
({
x
:
-
80
,
y
:
-
5
,
width
:
310
,
height
:
100
})
.
fill
(
0x317Af7
).
stroke
(
0xEE8443
).
strokeWidth
(
10
)
.
strokeLineJoin
(
LineJoinStyle
.
Miter
).
strokeMiterLimit
(
5
)
.
viewPort
({
x
:
-
80
,
y
:
-
5
,
width
:
310
,
height
:
90
})
.
fill
(
0x317AF7
)
.
stroke
(
0xEE8443
)
.
strokeWidth
(
10
)
.
strokeLineJoin
(
LineJoinStyle
.
Miter
)
.
strokeMiterLimit
(
5
)
}.
width
(
'
100%
'
).
margin
({
top
:
15
})
}
}
```

## 示例2
```
ts
// xxx.ets
@
Entry
@
Component
struct
ShapeMeshExample
{
@
State
columnVal
:
number
=
0
;
@
State
rowVal
:
number
=
0
;
@
State
count
:
number
=
0
;
@
State
verts
:
Array
<
number
>
=
[];
@
State
shapeWidth
:
number
=
600
;
@
State
shapeHeight
:
number
=
600
;
build
()
{
Column
()
{
Shape
()
{
Rect
()
.
width
(
'
250px
'
)
.
height
(
'
250px
'
)
.
radiusWidth
(
'
10px
'
)
.
radiusHeight
(
'
10px
'
)
.
stroke
(
'
10px
'
)
.
margin
({
left
:
'
10px
'
,
top
:
'
10px
'
})
.
strokeWidth
(
'
10px
'
)
.
fill
(
Color
.
Blue
)
Rect
()
.
width
(
'
250px
'
)
.
height
(
'
250px
'
)
.
radiusWidth
(
'
10px
'
)
.
radiusHeight
(
'
10px
'
)
.
stroke
(
'
10px
'
)
.
margin
({
left
:
'
270px
'
,
top
:
'
10px
'
})
.
strokeWidth
(
'
10px
'
)
.
fill
(
Color
.
Red
)
}
.
mesh
(
this
.
verts
,
this
.
columnVal
,
this
.
rowVal
)
.
width
(
this
.
shapeWidth
+
'
px
'
)
.
height
(
this
.
shapeHeight
+
'
px
'
)
// 手指触摸Shape组件时会显示mesh扭曲效果
.
onTouch
((
event
:
TouchEvent
)
=>
{
var
touchX
=
event
.
touches
[
0
].
x
*
2
;
var
touchY
=
event
.
touches
[
0
].
y
*
2
;
this
.
columnVal
=
20
;
this
.
rowVal
=
20
;
this
.
count
=
(
this
.
columnVal
+
1
)
*
(
this
.
rowVal
+
1
);
var
orig
=
[
this
.
count
*
2
];
var
index
=
0
;
for
(
var
i
=
0
;
i
<=
this
.
rowVal
;
i
++
)
{
var
fy
=
this
.
shapeWidth
*
i
/
this
.
rowVal
;
for
(
var
j
=
0
;
j
<=
this
.
columnVal
;
j
++
)
{
var
fx
=
this
.
shapeWidth
*
j
/
this
.
columnVal
;
orig
[
index
*
2
+
0
]
=
this
.
verts
[
index
*
2
+
0
]
=
fx
;
orig
[
index
*
2
+
1
]
=
this
.
verts
[
index
*
2
+
1
]
=
fy
;
index
++
;
}
}
for
(
var
k
=
0
;
k
<
this
.
count
*
2
;
k
+=
2
)
{
var
dx
=
touchX
-
orig
[
k
+
0
];
var
dy
=
touchY
-
orig
[
k
+
1
];
var
dd
=
dx
*
dx
+
dy
*
dy
;
var
d
=
Math
.
sqrt
(
dd
);
var
pull
=
80000
/
(
dd
*
d
);
if
(
pull
>=
1
)
{
this
.
verts
[
k
+
0
]
=
touchX
;
this
.
verts
[
k
+
1
]
=
touchY
;
}
else
{
this
.
verts
[
k
+
0
]
=
orig
[
k
+
0
]
+
dx
*
pull
;
this
.
verts
[
k
+
1
]
=
orig
[
k
+
1
]
+
dy
*
pull
;
}
}
})
}
.
width
(
'
600px
'
)
.
height
(
'
600px
'
)
.
border
({
width
:
3
,
color
:
Color
.
Black
})
}
}
```
Miykael_xxm
🚴
@xiongjiamu
mentioned in commit
6de162ca
·
9月 30, 2022
mentioned in commit
6de162ca
mentioned in commit 6de162ca85faed410be302d8e7b3dd9e1eb93e95
开关提交列表
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录