Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Graphic Ui
提交
46481088
G
Graphic Ui
项目概览
OpenHarmony
/
Graphic Ui
大约 1 年 前同步成功
通知
13
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
Graphic Ui
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
46481088
编写于
3月 18, 2021
作者:
W
wanngtiantian
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support checkbox software drawing
上级
bd270297
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
123 addition
and
36 deletion
+123
-36
frameworks/components/ui_checkbox.cpp
frameworks/components/ui_checkbox.cpp
+102
-16
frameworks/components/ui_radio_button.cpp
frameworks/components/ui_radio_button.cpp
+2
-4
frameworks/components/ui_toggle_button.cpp
frameworks/components/ui_toggle_button.cpp
+1
-2
interfaces/kits/components/ui_checkbox.h
interfaces/kits/components/ui_checkbox.h
+9
-0
interfaces/kits/components/ui_radio_button.h
interfaces/kits/components/ui_radio_button.h
+3
-6
interfaces/kits/components/ui_toggle_button.h
interfaces/kits/components/ui_toggle_button.h
+3
-6
test/uitest/test_button/ui_test_button.cpp
test/uitest/test_button/ui_test_button.cpp
+3
-2
未找到文件。
frameworks/components/ui_checkbox.cpp
浏览文件 @
46481088
...
@@ -16,13 +16,16 @@
...
@@ -16,13 +16,16 @@
#include "common/image.h"
#include "common/image.h"
#include "components/ui_checkbox.h"
#include "components/ui_checkbox.h"
#include "default_resource/check_box_res.h"
#include "default_resource/check_box_res.h"
#include "draw/draw_arc.h"
#include "draw/draw_image.h"
#include "draw/draw_image.h"
#include "draw/draw_line.h"
#include "draw/draw_rect.h"
#include "draw/draw_rect.h"
#include "imgdecode/cache_manager.h"
#include "imgdecode/cache_manager.h"
namespace
OHOS
{
namespace
OHOS
{
UICheckBox
::
UICheckBox
()
UICheckBox
::
UICheckBox
()
:
state_
(
UNSELECTED
),
onStateChangeListener_
(
nullptr
)
:
state_
(
UNSELECTED
),
onStateChangeListener_
(
nullptr
),
width_
(
DEFAULT_HOT_WIDTH
),
height_
(
DEFAULT_HOT_HEIGHT
),
borderWidth_
(
DEFAULT_BORDER_WIDTH
)
{
{
touchable_
=
true
;
touchable_
=
true
;
style_
=
&
(
StyleDefault
::
GetBackgroundTransparentStyle
());
style_
=
&
(
StyleDefault
::
GetBackgroundTransparentStyle
());
...
@@ -72,24 +75,107 @@ void UICheckBox::SetImages(const ImageInfo* selectedImageSrc, const ImageInfo* u
...
@@ -72,24 +75,107 @@ void UICheckBox::SetImages(const ImageInfo* selectedImageSrc, const ImageInfo* u
image_
[
UNSELECTED
].
SetSrc
(
unselectedImageSrc
);
image_
[
UNSELECTED
].
SetSrc
(
unselectedImageSrc
);
}
}
void
UICheckBox
::
OnDraw
(
const
Rect
&
invalidatedArea
)
void
UICheckBox
::
CalculateSize
()
{
int16_t
width
=
GetWidth
();
int16_t
height
=
GetHeight
();
if
((
width_
==
width
)
&&
(
height_
==
height
))
{
return
;
}
width_
=
width
;
height_
=
height
;
int16_t
minValue
=
(
width_
>
height_
)
?
height_
:
width_
;
borderWidth_
=
DEFAULT_BORDER_WIDTH
*
minValue
/
DEFAULT_HOT_WIDTH
;
}
void
UICheckBox
::
SelectedStateSoftwareDrawing
(
Rect
rect
,
Rect
trunc
,
int16_t
borderRadius
,
int16_t
rectLineWidth
)
{
{
ImageHeader
header
=
{
0
};
Style
styleSelect
=
StyleDefault
::
GetBackgroundTransparentStyle
();
image_
[
state_
].
GetHeader
(
header
);
styleSelect
.
borderRadius_
=
borderRadius
;
int16_t
imgWidth
=
header
.
width
;
styleSelect
.
bgColor_
=
Color
::
GetColorFromRGB
(
0x1F
,
0x71
,
0xFF
);
int16_t
imgHeight
=
header
.
height
;
styleSelect
.
bgOpa_
=
OPA_OPAQUE
;
Rect
coords
=
GetContentRect
();
Rect
contentRect
=
GetContentRect
();
coords
.
SetWidth
(
imgWidth
);
bool
isIntersect
=
trunc
.
Intersect
(
trunc
,
contentRect
);
coords
.
SetHeight
(
imgHeight
);
if
(
isIntersect
)
{
DrawRect
::
Draw
(
GetRect
(),
invalidatedArea
,
*
style_
,
opaScale_
);
DrawRect
::
Draw
(
rect
,
trunc
,
styleSelect
,
opaScale_
);
}
int16_t
dx
=
borderWidth_
*
0.22
;
// 0.22 : coefficient,
int16_t
dy
=
borderWidth_
*
0.5
;
// 0.5 : coefficient,
Point
start
=
{
static_cast
<
int16_t
>
(
rect
.
GetX
()
+
dx
),
static_cast
<
int16_t
>
(
rect
.
GetY
()
+
dy
)
};
dx
=
borderWidth_
*
0.2
;
// 0.2 : coefficient
Point
mid
=
{
static_cast
<
int16_t
>
(
start
.
x
+
dx
),
static_cast
<
int16_t
>
(
start
.
y
+
dx
)
};
dx
=
borderWidth_
*
0.38
;
// 0.38 : coefficient
Point
end
=
{
static_cast
<
int16_t
>
(
mid
.
x
+
dx
),
static_cast
<
int16_t
>
(
mid
.
y
-
dx
)
};
const
int16_t
half
=
2
;
// 2 :half
ArcInfo
arcInfoLeft
=
{
start
,
{
0
,
0
},
static_cast
<
uint16_t
>
(
rectLineWidth
),
SEMICIRCLE_IN_DEGREE
+
QUARTER_IN_DEGREE
/
half
,
QUARTER_IN_DEGREE
/
half
,
nullptr
};
ArcInfo
arcInfoMid
=
{
mid
,
{
0
,
0
},
static_cast
<
uint16_t
>
(
rectLineWidth
),
SEMICIRCLE_IN_DEGREE
-
QUARTER_IN_DEGREE
/
half
,
SEMICIRCLE_IN_DEGREE
+
QUARTER_IN_DEGREE
/
half
,
nullptr
};
ArcInfo
arcInfoRight
=
{
end
,
{
0
,
0
},
static_cast
<
uint16_t
>
(
rectLineWidth
),
CIRCLE_IN_DEGREE
-
QUARTER_IN_DEGREE
/
half
,
SEMICIRCLE_IN_DEGREE
-
QUARTER_IN_DEGREE
/
half
,
nullptr
};
styleSelect
.
lineColor_
=
Color
::
White
();
if
(
isIntersect
)
{
DrawArc
::
GetInstance
()
->
Draw
(
arcInfoLeft
,
trunc
,
styleSelect
,
OPA_OPAQUE
,
CapType
::
CAP_NONE
);
DrawLine
::
Draw
(
start
,
mid
,
trunc
,
rectLineWidth
*
2
,
Color
::
White
(),
opaScale_
);
// 2 : double
DrawArc
::
GetInstance
()
->
Draw
(
arcInfoMid
,
trunc
,
styleSelect
,
OPA_OPAQUE
,
CapType
::
CAP_NONE
);
DrawLine
::
Draw
(
mid
,
end
,
trunc
,
rectLineWidth
*
2
,
Color
::
White
(),
opaScale_
);
// 2 : double
DrawArc
::
GetInstance
()
->
Draw
(
arcInfoRight
,
trunc
,
styleSelect
,
OPA_OPAQUE
,
CapType
::
CAP_NONE
);
}
}
int16_t
offsetLeft
=
(
GetWidth
()
-
imgWidth
)
/
2
;
// 2 : half
void
UICheckBox
::
OnDraw
(
const
Rect
&
invalidatedArea
)
int16_t
offsetTop
=
(
GetHeight
()
-
imgHeight
)
/
2
;
// 2 : half
{
coords
.
SetX
(
coords
.
GetX
()
+
offsetLeft
);
coords
.
SetY
(
coords
.
GetY
()
+
offsetTop
);
Rect
trunc
=
invalidatedArea
;
Rect
trunc
=
invalidatedArea
;
if
(
trunc
.
Intersect
(
trunc
,
coords
))
{
if
((
image_
[
SELECTED
].
GetSrcType
()
!=
IMG_SRC_UNKNOWN
)
&&
(
image_
[
UNSELECTED
].
GetSrcType
()
!=
IMG_SRC_UNKNOWN
))
{
image_
[
state_
].
DrawImage
(
coords
,
trunc
,
*
style_
,
opaScale_
);
ImageHeader
header
=
{
0
};
image_
[
state_
].
GetHeader
(
header
);
int16_t
imgWidth
=
header
.
width
;
int16_t
imgHeight
=
header
.
height
;
Rect
coords
=
GetContentRect
();
coords
.
SetWidth
(
imgWidth
);
coords
.
SetHeight
(
imgHeight
);
DrawRect
::
Draw
(
GetRect
(),
invalidatedArea
,
*
style_
,
opaScale_
);
int16_t
offsetLeft
=
(
GetWidth
()
-
imgWidth
)
/
2
;
// 2 : half
int16_t
offsetTop
=
(
GetHeight
()
-
imgHeight
)
/
2
;
// 2 : half
coords
.
SetX
(
coords
.
GetX
()
+
offsetLeft
);
coords
.
SetY
(
coords
.
GetY
()
+
offsetTop
);
if
(
trunc
.
Intersect
(
trunc
,
coords
))
{
image_
[
state_
].
DrawImage
(
coords
,
trunc
,
*
style_
,
opaScale_
);
}
}
else
{
CalculateSize
();
int16_t
rectLineWidth
=
borderWidth_
/
DEFAULT_BORDER_WIDTH
;
int16_t
borderRadius
=
rectLineWidth
*
4
;
// 4 : coefficient
DrawRect
::
Draw
(
GetRect
(),
invalidatedArea
,
*
style_
,
opaScale_
);
Rect
contentRect
=
GetContentRect
();
int16_t
x
=
contentRect
.
GetX
()
+
(
width_
-
borderWidth_
)
/
2
;
// 2: half
int16_t
y
=
contentRect
.
GetY
()
+
(
height_
-
borderWidth_
)
/
2
;
// 2: half
Rect
rect
(
x
,
y
,
x
+
borderWidth_
,
y
+
borderWidth_
);
switch
(
state_
)
{
case
SELECTED
:
{
SelectedStateSoftwareDrawing
(
rect
,
trunc
,
borderRadius
,
rectLineWidth
);
break
;
}
case
UNSELECTED
:
{
Style
styleUnSelect
=
StyleDefault
::
GetBackgroundTransparentStyle
();
styleUnSelect
.
borderWidth_
=
rectLineWidth
;
styleUnSelect
.
borderRadius_
=
borderRadius
;
styleUnSelect
.
borderColor_
=
Color
::
White
();
styleUnSelect
.
borderOpa_
=
0xa8
;
// 0xa8: opacity
if
(
trunc
.
Intersect
(
trunc
,
contentRect
))
{
DrawRect
::
Draw
(
rect
,
trunc
,
styleUnSelect
,
opaScale_
);
}
break
;
}
default:
break
;
}
}
}
}
}
}
// namespace OHOS
}
// namespace OHOS
frameworks/components/ui_radio_button.cpp
浏览文件 @
46481088
...
@@ -25,8 +25,7 @@
...
@@ -25,8 +25,7 @@
#include "securec.h"
#include "securec.h"
namespace
OHOS
{
namespace
OHOS
{
UIRadioButton
::
UIRadioButton
()
:
name_
(
nullptr
),
width_
(
DEFAULT_HOT_WIDTH
),
height_
(
DEFAULT_HOT_HEIGHT
),
UIRadioButton
::
UIRadioButton
()
:
name_
(
nullptr
),
radiusBig_
(
DEFAULT_RADIUS_BIG
),
radiusSmall_
(
DEFAULT_RADIUS_SMALL
),
radiusBig_
(
DEFAULT_RADIUS_BIG
),
radiusSmall_
(
DEFAULT_RADIUS_SMALL
),
lineWidth_
(
DEFAULT_LINE_WIDTH
)
lineWidth_
(
DEFAULT_LINE_WIDTH
)
{
{
image_
[
UNSELECTED
].
SetSrc
(
""
);
image_
[
UNSELECTED
].
SetSrc
(
""
);
...
@@ -34,8 +33,7 @@ UIRadioButton::UIRadioButton() : name_(nullptr), width_(DEFAULT_HOT_WIDTH), heig
...
@@ -34,8 +33,7 @@ UIRadioButton::UIRadioButton() : name_(nullptr), width_(DEFAULT_HOT_WIDTH), heig
Resize
(
width_
,
height_
);
Resize
(
width_
,
height_
);
}
}
UIRadioButton
::
UIRadioButton
(
const
char
*
name
)
:
name_
(
nullptr
),
width_
(
DEFAULT_HOT_WIDTH
),
UIRadioButton
::
UIRadioButton
(
const
char
*
name
)
:
name_
(
nullptr
),
radiusBig_
(
DEFAULT_RADIUS_BIG
),
height_
(
DEFAULT_HOT_HEIGHT
),
radiusBig_
(
DEFAULT_RADIUS_BIG
),
radiusSmall_
(
DEFAULT_RADIUS_SMALL
),
lineWidth_
(
DEFAULT_LINE_WIDTH
)
radiusSmall_
(
DEFAULT_RADIUS_SMALL
),
lineWidth_
(
DEFAULT_LINE_WIDTH
)
{
{
SetName
(
name
);
SetName
(
name
);
...
...
frameworks/components/ui_toggle_button.cpp
浏览文件 @
46481088
...
@@ -20,8 +20,7 @@
...
@@ -20,8 +20,7 @@
#include "imgdecode/cache_manager.h"
#include "imgdecode/cache_manager.h"
namespace
OHOS
{
namespace
OHOS
{
UIToggleButton
::
UIToggleButton
()
:
width_
(
DEFAULT_HOT_WIDTH
),
height_
(
DEFAULT_HOT_WIDTH
),
UIToggleButton
::
UIToggleButton
()
:
corner_
(
DEFAULT_CORNER_RADIUS
),
radius_
(
DEFAULT_CORNER_RADIUS
-
DEAFULT_RADIUS_DIFF
),
corner_
(
DEFAULT_CORNER_RADIUS
),
radius_
(
DEFAULT_CORNER_RADIUS
-
DEAFULT_RADIUS_DIFF
),
rectWidth_
(
DEFAULT_WIDTH
)
rectWidth_
(
DEFAULT_WIDTH
)
{
{
image_
[
UNSELECTED
].
SetSrc
(
""
);
image_
[
UNSELECTED
].
SetSrc
(
""
);
...
...
interfaces/kits/components/ui_checkbox.h
浏览文件 @
46481088
...
@@ -217,8 +217,17 @@ public:
...
@@ -217,8 +217,17 @@ public:
protected:
protected:
virtual
void
ReverseState
();
virtual
void
ReverseState
();
virtual
void
CalculateSize
();
void
SelectedStateSoftwareDrawing
(
Rect
rect
,
Rect
trunc
,
int16_t
borderRadius
,
int16_t
rectLineWidth
);
static
constexpr
int16_t
DEFAULT_HOT_WIDTH
=
46
;
static
constexpr
int16_t
DEFAULT_HOT_HEIGHT
=
46
;
static
constexpr
int16_t
DEFAULT_BORDER_WIDTH
=
22
;
UICheckBoxState
state_
;
UICheckBoxState
state_
;
OnChangeListener
*
onStateChangeListener_
;
OnChangeListener
*
onStateChangeListener_
;
int16_t
width_
;
int16_t
height_
;
int16_t
borderWidth_
;
Image
image_
[
MAX_STATUS_NUM
];
Image
image_
[
MAX_STATUS_NUM
];
};
};
}
// namespace OHOS
}
// namespace OHOS
...
...
interfaces/kits/components/ui_radio_button.h
浏览文件 @
46481088
...
@@ -132,22 +132,19 @@ public:
...
@@ -132,22 +132,19 @@ public:
return
name_
;
return
name_
;
}
}
protected:
void
CalculateSize
()
override
;
private:
private:
void
FindRadioButtonAndChangeState
(
UIView
*
view
);
void
FindRadioButtonAndChangeState
(
UIView
*
view
);
static
constexpr
int16_t
DEFAULT_HOT_WIDTH
=
46
;
static
constexpr
int16_t
DEFAULT_HOT_HEIGHT
=
46
;
static
constexpr
int16_t
DEFAULT_RADIUS_BIG
=
11
;
static
constexpr
int16_t
DEFAULT_RADIUS_BIG
=
11
;
static
constexpr
int16_t
DEFAULT_RADIUS_SMALL
=
6
;
static
constexpr
int16_t
DEFAULT_RADIUS_SMALL
=
6
;
static
constexpr
int16_t
DEFAULT_LINE_WIDTH
=
1
;
static
constexpr
int16_t
DEFAULT_LINE_WIDTH
=
1
;
char
*
name_
;
char
*
name_
;
int16_t
width_
;
int16_t
height_
;
uint16_t
radiusBig_
;
uint16_t
radiusBig_
;
uint16_t
radiusSmall_
;
uint16_t
radiusSmall_
;
int16_t
lineWidth_
;
int16_t
lineWidth_
;
void
CalculateSize
();
};
};
}
// namespace OHOS
}
// namespace OHOS
#endif // GRAPHIC_LITE_UI_RADIO_BUTTON_H
#endif // GRAPHIC_LITE_UI_RADIO_BUTTON_H
interfaces/kits/components/ui_toggle_button.h
浏览文件 @
46481088
...
@@ -105,9 +105,10 @@ public:
...
@@ -105,9 +105,10 @@ public:
return
(
state_
!=
UNSELECTED
);
return
(
state_
!=
UNSELECTED
);
}
}
protected:
void
CalculateSize
()
override
;
private:
private:
static
constexpr
int16_t
DEFAULT_HOT_WIDTH
=
46
;
static
constexpr
int16_t
DEFAULT_HOT_HEIGHT
=
46
;
static
constexpr
int16_t
DEFAULT_WIDTH
=
32
;
static
constexpr
int16_t
DEFAULT_WIDTH
=
32
;
static
constexpr
int16_t
DEFAULT_CORNER_RADIUS
=
11
;
static
constexpr
int16_t
DEFAULT_CORNER_RADIUS
=
11
;
static
constexpr
int16_t
DEAFULT_RADIUS_DIFF
=
2
;
static
constexpr
int16_t
DEAFULT_RADIUS_DIFF
=
2
;
...
@@ -116,13 +117,9 @@ private:
...
@@ -116,13 +117,9 @@ private:
static
constexpr
uint8_t
DEFAULT_BG_GREEN
=
113
;
static
constexpr
uint8_t
DEFAULT_BG_GREEN
=
113
;
static
constexpr
uint8_t
DEFAULT_BG_BLUE
=
255
;
static
constexpr
uint8_t
DEFAULT_BG_BLUE
=
255
;
int16_t
width_
;
int16_t
height_
;
uint16_t
corner_
;
uint16_t
corner_
;
uint16_t
radius_
;
uint16_t
radius_
;
int16_t
rectWidth_
;
int16_t
rectWidth_
;
void
CalculateSize
();
};
// class UIToggleButton
};
// class UIToggleButton
}
// namespace OHOS
}
// namespace OHOS
#endif // GRAPHIC_LITE_UI_TOGGLE_BUTTON_H
#endif // GRAPHIC_LITE_UI_TOGGLE_BUTTON_H
test/uitest/test_button/ui_test_button.cpp
浏览文件 @
46481088
...
@@ -70,7 +70,8 @@ void UITestBUTTON::UIKit_Check_Box_Test_001() const
...
@@ -70,7 +70,8 @@ void UITestBUTTON::UIKit_Check_Box_Test_001() const
checkbox2
->
SetPosition
(
100
,
30
);
// 100: x-coordinate, 30: y-coordinate
checkbox2
->
SetPosition
(
100
,
30
);
// 100: x-coordinate, 30: y-coordinate
UICheckBox
*
checkbox3
=
new
UICheckBox
();
UICheckBox
*
checkbox3
=
new
UICheckBox
();
checkbox3
->
SetPosition
(
170
,
30
);
// 170: x-coordinate, 30: y-coordinate
checkbox3
->
SetImages
(
""
,
""
);
checkbox3
->
SetPosition
(
170
,
30
,
100
,
100
);
// 170: x-coordinate, 30: y-coordinate, 100 : width, 100 : height
container_
->
Add
(
checkbox
);
container_
->
Add
(
checkbox
);
container_
->
Add
(
checkbox2
);
container_
->
Add
(
checkbox2
);
...
@@ -668,4 +669,4 @@ void UITestBUTTON::UIKit_Button_Test_001() const
...
@@ -668,4 +669,4 @@ void UITestBUTTON::UIKit_Button_Test_001() const
UIKit_BUTTON_TEST_002
(
container_
,
button
);
UIKit_BUTTON_TEST_002
(
container_
,
button
);
}
}
}
}
}
// namespace OHOS
}
// namespace OHOS
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录