diff --git a/.clang-format b/.clang-format
old mode 100755
new mode 100644
index d4026b8..57356be
--- a/.clang-format
+++ b/.clang-format
@@ -1,160 +1,160 @@
-Language: Cpp
-# BasedOnStyle: LLVM
-# 访问说明符(public、private等)的偏移
-AccessModifierOffset: -4
-# 开括号(开圆括号、开尖括号、开方括号)后的对齐
-AlignAfterOpenBracket: Align
-# 连续赋值时,等号对齐
-AlignConsecutiveAssignments: false
-# 连续赋值时,变量名对齐
-AlignConsecutiveDeclarations: false
-# 左对齐逃脱换行(使用反斜杠换行)的反斜杠
-AlignEscapedNewlinesLeft: true
-# 水平对齐二元和三元表达式的操作数
-AlignOperands: true
-# 对齐连续的尾随的注释
-AlignTrailingComments: true
-# 允许函数声明的所有参数在放在下一行
-AllowAllParametersOfDeclarationOnNextLine: false
-# 允许短的块放在同一行
-AllowShortBlocksOnASingleLine: false
-# 允许短的case标签放在同一行
-AllowShortCaseLabelsOnASingleLine: false
-# 允许短的函数放在同一行: None, InlineOnly(定义在类中), Empty(空函数), Inline(定义在类中,空函数), All
-AllowShortFunctionsOnASingleLine: Empty
-# 允许短的if语句保持在同一行
-AllowShortIfStatementsOnASingleLine: false
-# 允许短的循环保持在同一行
-AllowShortLoopsOnASingleLine: false
-# 总是在定义返回类型后换行(deprecated)
-AlwaysBreakAfterDefinitionReturnType: None
-# 总是在返回类型后换行: None, All, TopLevel(顶级函数,不包括在类中的函数),
-# AllDefinitions(所有的定义,不包括声明), TopLevelDefinitions(所有的顶级函数的定义)
-AlwaysBreakAfterReturnType: None
-# 总是在多行string字面量前换行
-AlwaysBreakBeforeMultilineStrings: true
-# 总是在template声明后换行
-AlwaysBreakTemplateDeclarations: false
-# false表示函数实参要么都在同一行,要么都各自一行
-BinPackArguments: true
-# false表示所有形参要么都在同一行,要么都各自一行
-BinPackParameters: false
-# 大括号换行,只有当BreakBeforeBraces设置为Custom时才有效
-BraceWrapping:
- AfterClass: false
- AfterControlStatement: false
- AfterEnum: false
- AfterFunction: true
- AfterNamespace: false
- AfterObjCDeclaration: false
- AfterStruct: false
- AfterUnion: false
- BeforeCatch: false
- BeforeElse: false
- IndentBraces: false
-# 在二元运算符前换行: None(在操作符后换行), NonAssignment(在非赋值的操作符前换行), All(在操作符前换行)
-BreakBeforeBinaryOperators: None
-# 在大括号前换行: Attach(始终将大括号附加到周围的上下文), Linux(除函数、命名空间和类定义,与Attach类似),
-# Mozilla(除枚举、函数、记录定义,与Attach类似), Stroustrup(除函数定义、catch、else,与Attach类似),
-# Allman(总是在大括号前换行), GNU(总是在大括号前换行,并对于控制语句的大括号增加额外的缩进), WebKit(在函数前换行), Custom
-# 注:这里认为语句块也属于函数
-BreakBeforeBraces: Custom
-# 在三元运算符前换行
-BreakBeforeTernaryOperators: true
-# 在构造函数的初始化列表的逗号前换行
-BreakConstructorInitializersBeforeComma: false
-# 每行字符的限制,0表示没有限制
-ColumnLimit: 120
-# 描述具有特殊意义的注释的正则表达式,它不应该被分割为多行或以其它方式改变
-CommentPragmas: "^ IWYU pragma:"
-# 构造函数的初始化列表要么都在同一行,要么都各自一行
-ConstructorInitializerAllOnOneLineOrOnePerLine: true
-# 构造函数的初始化列表的缩进宽度
-ConstructorInitializerIndentWidth: 4
-# 延续的行的缩进宽度
-ContinuationIndentWidth: 4
-# 去除C++11的列表初始化的大括号{后和}前的空格
-Cpp11BracedListStyle: true
-# 继承最常用的指针和引用的对齐方式
-DerivePointerAlignment: false
-# 关闭格式化
-DisableFormat: false
-# 自动检测函数的调用和定义是否被格式为每行一个参数(Experimental)
-ExperimentalAutoDetectBinPacking: false
-# 需要被解读为foreach循环而不是函数调用的宏
-ForEachMacros: [foreach, Q_FOREACH, BOOST_FOREACH]
-# 对#include进行排序,匹配了某正则表达式的#include拥有对应的优先级,匹配不到的则默认优先级为INT_MAX(优先级越小排序越靠前),
-# 可以定义负数优先级从而保证某些#include永远在最前面
-IncludeCategories:
- - Regex: '^"(llvm|llvm-c|clang|clang-c)/'
- Priority: 2
- - Regex: '^(<|"(gtest|isl|json)/)'
- Priority: 3
- - Regex: ".*"
- Priority: 1
-# 缩进case标签
-IndentCaseLabels: true
-# 缩进宽度
-IndentWidth: 4
-# 函数返回类型换行时,缩进函数声明或函数定义的函数名
-IndentWrappedFunctionNames: true
-# 保留在块开始处的空行
-KeepEmptyLinesAtTheStartOfBlocks: true
-# 开始一个块的宏的正则表达式
-MacroBlockBegin: ""
-# 结束一个块的宏的正则表达式
-MacroBlockEnd: ""
-# 连续空行的最大数量
-MaxEmptyLinesToKeep: 1
-# 命名空间的缩进: None, Inner(缩进嵌套的命名空间中的内容), All
-NamespaceIndentation: None
-# 使用ObjC块时缩进宽度
-ObjCBlockIndentWidth: 4
-# 在ObjC的@property后添加一个空格
-ObjCSpaceAfterProperty: false
-# 在ObjC的protocol列表前添加一个空格
-ObjCSpaceBeforeProtocolList: true
-# 在call(后对函数调用换行的penalty
-PenaltyBreakBeforeFirstCallParameter: 19
-# 在一个注释中引入换行的penalty
-PenaltyBreakComment: 300
-# 第一次在<<前换行的penalty
-PenaltyBreakFirstLessLess: 120
-# 在一个字符串字面量中引入换行的penalty
-PenaltyBreakString: 1000
-# 对于每个在行字符数限制之外的字符的penalt
-PenaltyExcessCharacter: 1000000
-# 将函数的返回类型放到它自己的行的penalty
-PenaltyReturnTypeOnItsOwnLine: 60
-# 指针和引用的对齐: Left, Right, Middle
-PointerAlignment: Left
-# 允许重新排版注释
-ReflowComments: true
-# 允许排序#include
-SortIncludes: true
-# 在C风格类型转换后添加空格
-SpaceAfterCStyleCast: false
-# 在赋值运算符之前添加空格
-SpaceBeforeAssignmentOperators: true
-# 开圆括号之前添加一个空格: Never, ControlStatements, Always
-SpaceBeforeParens: ControlStatements
-# 在空的圆括号中添加空格
-SpaceInEmptyParentheses: false
-# 在尾随的评论前添加的空格数(只适用于//)
-SpacesBeforeTrailingComments: 1
-# 在尖括号的<后和>前添加空格
-SpacesInAngles: false
-# 在容器(ObjC和JavaScript的数组和字典等)字面量中添加空格
-SpacesInContainerLiterals: true
-# 在C风格类型转换的括号中添加空格
-SpacesInCStyleCastParentheses: false
-# 在圆括号的(后和)前添加空格
-SpacesInParentheses: false
-# 在方括号的[后和]前添加空格,lamda表达式和未指明大小的数组的声明不受影响
-SpacesInSquareBrackets: false
-# 标准: Cpp03, Cpp11, Auto
-Standard: Cpp11
-# tab宽度
-TabWidth: 4
-# 使用tab字符: Never, ForIndentation, ForContinuationAndIndentation, Always
-UseTab: Never
+Language: Cpp
+# BasedOnStyle: LLVM
+# 访问说明符(public、private等)的偏移
+AccessModifierOffset: -4
+# 开括号(开圆括号、开尖括号、开方括号)后的对齐
+AlignAfterOpenBracket: Align
+# 连续赋值时,等号对齐
+AlignConsecutiveAssignments: false
+# 连续赋值时,变量名对齐
+AlignConsecutiveDeclarations: false
+# 左对齐逃脱换行(使用反斜杠换行)的反斜杠
+AlignEscapedNewlinesLeft: true
+# 水平对齐二元和三元表达式的操作数
+AlignOperands: true
+# 对齐连续的尾随的注释
+AlignTrailingComments: true
+# 允许函数声明的所有参数在放在下一行
+AllowAllParametersOfDeclarationOnNextLine: false
+# 允许短的块放在同一行
+AllowShortBlocksOnASingleLine: false
+# 允许短的case标签放在同一行
+AllowShortCaseLabelsOnASingleLine: false
+# 允许短的函数放在同一行: None, InlineOnly(定义在类中), Empty(空函数), Inline(定义在类中,空函数), All
+AllowShortFunctionsOnASingleLine: Empty
+# 允许短的if语句保持在同一行
+AllowShortIfStatementsOnASingleLine: false
+# 允许短的循环保持在同一行
+AllowShortLoopsOnASingleLine: false
+# 总是在定义返回类型后换行(deprecated)
+AlwaysBreakAfterDefinitionReturnType: None
+# 总是在返回类型后换行: None, All, TopLevel(顶级函数,不包括在类中的函数),
+# AllDefinitions(所有的定义,不包括声明), TopLevelDefinitions(所有的顶级函数的定义)
+AlwaysBreakAfterReturnType: None
+# 总是在多行string字面量前换行
+AlwaysBreakBeforeMultilineStrings: true
+# 总是在template声明后换行
+AlwaysBreakTemplateDeclarations: false
+# false表示函数实参要么都在同一行,要么都各自一行
+BinPackArguments: true
+# false表示所有形参要么都在同一行,要么都各自一行
+BinPackParameters: false
+# 大括号换行,只有当BreakBeforeBraces设置为Custom时才有效
+BraceWrapping:
+ AfterClass: false
+ AfterControlStatement: false
+ AfterEnum: false
+ AfterFunction: true
+ AfterNamespace: false
+ AfterObjCDeclaration: false
+ AfterStruct: false
+ AfterUnion: false
+ BeforeCatch: false
+ BeforeElse: false
+ IndentBraces: false
+# 在二元运算符前换行: None(在操作符后换行), NonAssignment(在非赋值的操作符前换行), All(在操作符前换行)
+BreakBeforeBinaryOperators: None
+# 在大括号前换行: Attach(始终将大括号附加到周围的上下文), Linux(除函数、命名空间和类定义,与Attach类似),
+# Mozilla(除枚举、函数、记录定义,与Attach类似), Stroustrup(除函数定义、catch、else,与Attach类似),
+# Allman(总是在大括号前换行), GNU(总是在大括号前换行,并对于控制语句的大括号增加额外的缩进), WebKit(在函数前换行), Custom
+# 注:这里认为语句块也属于函数
+BreakBeforeBraces: Custom
+# 在三元运算符前换行
+BreakBeforeTernaryOperators: true
+# 在构造函数的初始化列表的逗号前换行
+BreakConstructorInitializersBeforeComma: false
+# 每行字符的限制,0表示没有限制
+ColumnLimit: 120
+# 描述具有特殊意义的注释的正则表达式,它不应该被分割为多行或以其它方式改变
+CommentPragmas: "^ IWYU pragma:"
+# 构造函数的初始化列表要么都在同一行,要么都各自一行
+ConstructorInitializerAllOnOneLineOrOnePerLine: true
+# 构造函数的初始化列表的缩进宽度
+ConstructorInitializerIndentWidth: 4
+# 延续的行的缩进宽度
+ContinuationIndentWidth: 4
+# 去除C++11的列表初始化的大括号{后和}前的空格
+Cpp11BracedListStyle: true
+# 继承最常用的指针和引用的对齐方式
+DerivePointerAlignment: false
+# 关闭格式化
+DisableFormat: false
+# 自动检测函数的调用和定义是否被格式为每行一个参数(Experimental)
+ExperimentalAutoDetectBinPacking: false
+# 需要被解读为foreach循环而不是函数调用的宏
+ForEachMacros: [foreach, Q_FOREACH, BOOST_FOREACH]
+# 对#include进行排序,匹配了某正则表达式的#include拥有对应的优先级,匹配不到的则默认优先级为INT_MAX(优先级越小排序越靠前),
+# 可以定义负数优先级从而保证某些#include永远在最前面
+IncludeCategories:
+ - Regex: '^"(llvm|llvm-c|clang|clang-c)/'
+ Priority: 2
+ - Regex: '^(<|"(gtest|isl|json)/)'
+ Priority: 3
+ - Regex: ".*"
+ Priority: 1
+# 缩进case标签
+IndentCaseLabels: true
+# 缩进宽度
+IndentWidth: 4
+# 函数返回类型换行时,缩进函数声明或函数定义的函数名
+IndentWrappedFunctionNames: true
+# 保留在块开始处的空行
+KeepEmptyLinesAtTheStartOfBlocks: true
+# 开始一个块的宏的正则表达式
+MacroBlockBegin: ""
+# 结束一个块的宏的正则表达式
+MacroBlockEnd: ""
+# 连续空行的最大数量
+MaxEmptyLinesToKeep: 1
+# 命名空间的缩进: None, Inner(缩进嵌套的命名空间中的内容), All
+NamespaceIndentation: None
+# 使用ObjC块时缩进宽度
+ObjCBlockIndentWidth: 4
+# 在ObjC的@property后添加一个空格
+ObjCSpaceAfterProperty: false
+# 在ObjC的protocol列表前添加一个空格
+ObjCSpaceBeforeProtocolList: true
+# 在call(后对函数调用换行的penalty
+PenaltyBreakBeforeFirstCallParameter: 19
+# 在一个注释中引入换行的penalty
+PenaltyBreakComment: 300
+# 第一次在<<前换行的penalty
+PenaltyBreakFirstLessLess: 120
+# 在一个字符串字面量中引入换行的penalty
+PenaltyBreakString: 1000
+# 对于每个在行字符数限制之外的字符的penalt
+PenaltyExcessCharacter: 1000000
+# 将函数的返回类型放到它自己的行的penalty
+PenaltyReturnTypeOnItsOwnLine: 60
+# 指针和引用的对齐: Left, Right, Middle
+PointerAlignment: Left
+# 允许重新排版注释
+ReflowComments: true
+# 允许排序#include
+SortIncludes: true
+# 在C风格类型转换后添加空格
+SpaceAfterCStyleCast: false
+# 在赋值运算符之前添加空格
+SpaceBeforeAssignmentOperators: true
+# 开圆括号之前添加一个空格: Never, ControlStatements, Always
+SpaceBeforeParens: ControlStatements
+# 在空的圆括号中添加空格
+SpaceInEmptyParentheses: false
+# 在尾随的评论前添加的空格数(只适用于//)
+SpacesBeforeTrailingComments: 1
+# 在尖括号的<后和>前添加空格
+SpacesInAngles: false
+# 在容器(ObjC和JavaScript的数组和字典等)字面量中添加空格
+SpacesInContainerLiterals: true
+# 在C风格类型转换的括号中添加空格
+SpacesInCStyleCastParentheses: false
+# 在圆括号的(后和)前添加空格
+SpacesInParentheses: false
+# 在方括号的[后和]前添加空格,lamda表达式和未指明大小的数组的声明不受影响
+SpacesInSquareBrackets: false
+# 标准: Cpp03, Cpp11, Auto
+Standard: Cpp11
+# tab宽度
+TabWidth: 4
+# 使用tab字符: Never, ForIndentation, ForContinuationAndIndentation, Always
+UseTab: Never
diff --git a/.gitee/ISSUE_TEMPLATE.zh-CN.md b/.gitee/ISSUE_TEMPLATE.zh-CN.md
deleted file mode 100755
index f09d98d..0000000
--- a/.gitee/ISSUE_TEMPLATE.zh-CN.md
+++ /dev/null
@@ -1,13 +0,0 @@
-### 该问题是怎么引起的?
-
-
-
-### 重现步骤
-
-
-
-### 报错信息
-
-
-
-
diff --git a/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md b/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md
deleted file mode 100755
index 33948fd..0000000
--- a/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md
+++ /dev/null
@@ -1,15 +0,0 @@
-### 相关的Issue
-
-
-### 原因(目的、解决的问题等)
-
-
-### 描述(做了什么,变更了什么)
-
-
-### 测试用例(新增、改动、可能影响的功能)
-
-
-
-
-
diff --git a/.gitignore b/.gitignore
deleted file mode 100755
index 5167ed4..0000000
--- a/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-/huawei_proprietary
-/test
diff --git a/BUILD.gn b/BUILD.gn
old mode 100755
new mode 100644
index 92ed549..b9ae35d
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -1,4 +1,4 @@
-# Copyright (c) 2020 Huawei Device Co., Ltd.
+# Copyright (c) 2020-2021 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
@@ -9,46 +9,56 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+import("//build/lite/config/component/lite_component.gni")
import("//build/lite/ndk/ndk.gni")
-group("ndk_build") {
- deps = [
- ":ui",
- ":surface",
- ":graphic_utils"
- ]
+lite_component("lite_surface") {
+ features = [ ":surface" ]
+ public_deps = features
}
-ndk_lib("surface") {
- lib_extension = ".so"
- deps = [
- "//foundation/graphic/lite/frameworks/surface:surface"
- ]
-
- head_files = [
- "//foundation/graphic/lite/interfaces/kits/surface"
- ]
+ndk_lib("lite_surface_ndk") {
+ lib_extension = ".so"
+ deps = [ ":surface" ]
+ head_files = [ "interfaces/kits" ]
}
-ndk_lib("ui") {
- lib_extension = ".so"
- deps = [
- "//foundation/graphic/lite/frameworks/ui:ui"
- ]
-
- head_files = [
- "//foundation/graphic/lite/interfaces/kits/ui",
- "//foundation/graphic/lite/interfaces/kits/config"
- ]
+shared_library("surface") {
+ sources = [
+ "frameworks/buffer_client_producer.cpp",
+ "frameworks/buffer_manager.cpp",
+ "frameworks/buffer_queue.cpp",
+ "frameworks/buffer_queue_consumer.cpp",
+ "frameworks/buffer_queue_producer.cpp",
+ "frameworks/surface.cpp",
+ "frameworks/surface_buffer_impl.cpp",
+ "frameworks/surface_impl.cpp",
+ ]
+ include_dirs = [
+ "frameworks",
+ "//drivers/peripheral/display/interfaces/include",
+ ]
+ public_configs = [ ":surface_public_config" ]
+ public_deps = [ "//foundation/graphic/utils:lite_graphic_utils" ]
+ deps = [
+ "//drivers/peripheral/display/hal:hdi_display",
+ "//foundation/communication/ipc_lite:liteipc_adapter",
+ "//third_party/bounds_checking_function:libsec_shared",
+ ]
+ ldflags = [
+ "-ldisplay_gfx",
+ "-ldisplay_gralloc",
+ "-ldisplay_layer",
+ ]
+ cflags = [ "-fPIC" ]
+ cflags += [ "-Wall" ]
+ cflags_cc = cflags
}
-ndk_lib("graphic_utils") {
- lib_extension = ".so"
- deps = [
- "//foundation/graphic/lite/utils:graphic_utils"
- ]
-
- head_files = [
- "//foundation/graphic/lite/interfaces/kits/utils"
- ]
-}
\ No newline at end of file
+config("surface_public_config") {
+ include_dirs = [
+ "interfaces/innerkits",
+ "interfaces/kits",
+ "//foundation/graphic/utils/interfaces/kits",
+ ]
+}
diff --git a/CMakeLists.txt b/CMakeLists.txt
deleted file mode 100755
index cbe3609..0000000
--- a/CMakeLists.txt
+++ /dev/null
@@ -1,160 +0,0 @@
-cmake_minimum_required(VERSION 3.16.5)
-
-add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/zlib zlib.out)
-add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/libpng libpng.out)
-add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/libjpeg libjpeg.out)
-add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/freetype freetype.out)
-
-set(UI_DIR "${PROJECT_SOURCE_DIR}/foundation/graphic/lite/frameworks/ui")
-
-include_directories(${PROJECT_SOURCE_DIR}/third_party/bounds_checking_function/include)
-include_directories(${PROJECT_SOURCE_DIR}/third_party/cJSON)
-include_directories(${PROJECT_SOURCE_DIR}/third_party/libjpeg)
-include_directories(${PROJECT_SOURCE_DIR}/third_party/libpng)
-include_directories(${PROJECT_SOURCE_DIR}/third_party/freetype/include)
-include_directories(${PROJECT_SOURCE_DIR}/foundation/graphic/lite/huawei_proprietary/include)
-include_directories(${PROJECT_SOURCE_DIR}/foundation/graphic/lite/huawei_proprietary/include/appfwk)
-include_directories(${PROJECT_SOURCE_DIR}/foundation/graphic/lite/huawei_proprietary/include/components)
-include_directories(${PROJECT_SOURCE_DIR}/foundation/graphic/lite/huawei_proprietary/include/common-x)
-include_directories(${PROJECT_SOURCE_DIR}/foundation/graphic/lite/huawei_proprietary/include/font)
-
-file(GLOB SECUREC "${PROJECT_SOURCE_DIR}/third_party/bounds_checking_function/src/*.c")
-
-add_library(ui STATIC
- "${PROJECT_SOURCE_DIR}/third_party/bounds_checking_function/src/memset_s.c"
- "${PROJECT_SOURCE_DIR}/third_party/cJSON/cJSON.c"
- "${UI_DIR}/src/animator/animator.cpp"
- "${UI_DIR}/src/animator/easing_equation.cpp"
- "${UI_DIR}/src/animator/interpolation.cpp"
- "${UI_DIR}/src/common/graphic_startup.cpp"
- "${UI_DIR}/src/common/image.cpp"
- "${UI_DIR}/src/common/input_device_manager.cpp"
- "${UI_DIR}/src/common/screen.cpp"
- "${UI_DIR}/src/common/screen_device_proxy.cpp"
- "${UI_DIR}/src/common/task.cpp"
- "${UI_DIR}/src/common/text.cpp"
- "${UI_DIR}/src/common/typed_text.cpp"
- "${UI_DIR}/src/common/ui_text_language.cpp"
- "${UI_DIR}/src/components/root_view.cpp"
- "${UI_DIR}/src/components/ui_button.cpp"
- "${UI_DIR}/src/components/ui_checkbox.cpp"
- "${UI_DIR}/src/components/ui_label_button.cpp"
- "${UI_DIR}/src/components/ui_radio_button.cpp"
- "${UI_DIR}/src/components/ui_repeat_button.cpp"
- "${UI_DIR}/src/components/ui_toggle_button.cpp"
- "${UI_DIR}/src/components/ui_canvas.cpp"
- "${UI_DIR}/src/components/ui_axis.cpp"
- "${UI_DIR}/src/components/ui_chart.cpp"
- "${UI_DIR}/src/components/ui_abstract_clock.cpp"
- "${UI_DIR}/src/components/ui_analog_clock.cpp"
- "${UI_DIR}/src/components/ui_digital_clock.cpp"
- "${UI_DIR}/src/components/ui_abstract_scroll.cpp"
- "${UI_DIR}/src/components/ui_view.cpp"
- "${UI_DIR}/src/components/ui_view_group.cpp"
- "${UI_DIR}/src/components/ui_image_animator.cpp"
- "${UI_DIR}/src/components/ui_image_view.cpp"
- "${UI_DIR}/src/components/ui_arc_label.cpp"
- "${UI_DIR}/src/components/ui_label.cpp"
- "${UI_DIR}/src/components/text_adapter.cpp"
- "${UI_DIR}/src/components/ui_list.cpp"
- "${UI_DIR}/src/components/ui_picker.cpp"
- "${UI_DIR}/src/components/ui_time_picker.cpp"
- "${UI_DIR}/src/components/ui_abstract_progress.cpp"
- "${UI_DIR}/src/components/ui_box_progress.cpp"
- "${UI_DIR}/src/components/ui_circle_progress.cpp"
- "${UI_DIR}/src/components/ui_scroll_view.cpp"
- "${UI_DIR}/src/components/ui_slider.cpp"
- "${UI_DIR}/src/components/ui_swipe_view.cpp"
- "${UI_DIR}/src/components/ui_texture_mapper.cpp"
- "${UI_DIR}/src/core/render_manager.cpp"
- "${UI_DIR}/src/core/measure_manager.cpp"
- "${UI_DIR}/src/core/task_manager.cpp"
- "${UI_DIR}/src/default_resource/check_box_res.cpp"
- "${UI_DIR}/src/default_resource/radio_button_res.cpp"
- "${UI_DIR}/src/default_resource/toggle_button_res.cpp"
- "${UI_DIR}/src/dfx/ui_dump_dom_tree.cpp"
- "${UI_DIR}/src/dfx/point_event_injector.cpp"
- "${UI_DIR}/src/dfx/event_injector.cpp"
- "${UI_DIR}/src/dock/input_device.cpp"
- "${UI_DIR}/src/dock/key_input_device.cpp"
- "${UI_DIR}/src/dock/pointer_input_device.cpp"
- "${UI_DIR}/src/dock/input_device.cpp"
- "${UI_DIR}/src/events/event.cpp"
- "${UI_DIR}/src/font/ui_dynamic_font.cpp"
- "${UI_DIR}/src/font/ui_font_allocator.cpp"
- "${UI_DIR}/src/font/ui_font_cache.cpp"
- "${UI_DIR}/src/font/ui_font.cpp"
- "${UI_DIR}/src/font/ui_base_font.cpp"
- "${UI_DIR}/src/font/ui_font_vector.cpp"
- "${UI_DIR}/src/imgdecode/cache_manager.cpp"
- "${UI_DIR}/src/imgdecode/file_img_decoder.cpp"
- "${UI_DIR}/src/layout/flex_layout.cpp"
- "${UI_DIR}/src/layout/grid_layout.cpp"
- "${UI_DIR}/src/layout/list_layout.cpp"
- "${UI_DIR}/src/themes/theme.cpp"
- "${UI_DIR}/src/themes/theme_manager.cpp"
- "${UI_DIR}/src/draw/draw_arc.cpp"
- "${UI_DIR}/src/draw/draw_curve.cpp"
- "${UI_DIR}/src/draw/draw_image.cpp"
- "${UI_DIR}/src/draw/draw_label.cpp"
- "${UI_DIR}/src/draw/draw_line.cpp"
- "${UI_DIR}/src/draw/draw_rect.cpp"
- "${UI_DIR}/src/draw/draw_triangle.cpp"
- "${UI_DIR}/src/draw/draw_utils.cpp"
- "${UI_DIR}/../../hals/src/hal_tick.cpp"
- "${UI_DIR}/../../utils/src/win_file.c"
- "${UI_DIR}/../../utils/src/mc_file.c"
- "${UI_DIR}/../../utils/src/linux_file.c"
- "${UI_DIR}/../../utils/src/color.cpp"
- "${UI_DIR}/../../utils/src/file.c"
- "${UI_DIR}/../../utils/src/geometry2d.cpp"
- "${UI_DIR}/../../utils/src/graphic_math.cpp"
- "${UI_DIR}/../../utils/src/mem_api.cpp"
- "${UI_DIR}/../../utils/src/style.cpp"
- "${UI_DIR}/../../utils/src/sys_info.cpp"
- "${UI_DIR}/../../utils/src/transform.cpp"
- "${UI_DIR}/../../utils/src/version.cpp"
-)
-
-target_include_directories(ui PUBLIC
- ${PROJECT_SOURCE_DIR}/foundation/graphic/lite/frameworks/surface/include
- ${PROJECT_SOURCE_DIR}/foundation/graphic/lite/frameworks/ui/include
- ${PROJECT_SOURCE_DIR}/foundation/graphic/lite/frameworks/ui/include/common
- ${PROJECT_SOURCE_DIR}/foundation/graphic/lite/frameworks/ui/include/core
- ${PROJECT_SOURCE_DIR}/foundation/graphic/lite/frameworks/ui/include/default_resource
- ${PROJECT_SOURCE_DIR}/foundation/graphic/lite/frameworks/ui/include/dfx
- ${PROJECT_SOURCE_DIR}/foundation/graphic/lite/frameworks/ui/include/dock
- ${PROJECT_SOURCE_DIR}/foundation/graphic/lite/frameworks/ui/include/draw
- ${PROJECT_SOURCE_DIR}/foundation/graphic/lite/frameworks/ui/include/font
- ${PROJECT_SOURCE_DIR}/foundation/graphic/lite/frameworks/ui/include/imgdecode
- ${PROJECT_SOURCE_DIR}/foundation/graphic/lite/frameworks/ui/include/window
- ${PROJECT_SOURCE_DIR}/foundation/graphic/lite/frameworks/ui/src
- ${PROJECT_SOURCE_DIR}/foundation/graphic/lite/hals/include
- ${PROJECT_SOURCE_DIR}/foundation/graphic/lite/interfaces/
- ${PROJECT_SOURCE_DIR}/foundation/graphic/lite/interfaces/innerkits
- ${PROJECT_SOURCE_DIR}/foundation/graphic/lite/interfaces/innerkits/ui
- ${PROJECT_SOURCE_DIR}/foundation/graphic/lite/interfaces/innerkits/ui/common
- ${PROJECT_SOURCE_DIR}/foundation/graphic/lite/interfaces/innerkits/ui/dock
- ${PROJECT_SOURCE_DIR}/foundation/graphic/lite/interfaces/innerkits/wms/common
- ${PROJECT_SOURCE_DIR}/foundation/graphic/lite/interfaces/kits
- ${PROJECT_SOURCE_DIR}/foundation/graphic/lite/interfaces/kits/config
- ${PROJECT_SOURCE_DIR}/foundation/graphic/lite/interfaces/kits/surface
- ${PROJECT_SOURCE_DIR}/foundation/graphic/lite/interfaces/kits/ui
- ${PROJECT_SOURCE_DIR}/foundation/graphic/lite/interfaces/kits/ui/animator
- ${PROJECT_SOURCE_DIR}/foundation/graphic/lite/interfaces/kits/ui/common
- ${PROJECT_SOURCE_DIR}/foundation/graphic/lite/interfaces/kits/ui/components
- ${PROJECT_SOURCE_DIR}/foundation/graphic/lite/interfaces/kits/ui/dfx
- ${PROJECT_SOURCE_DIR}/foundation/graphic/lite/interfaces/kits/ui/events
- ${PROJECT_SOURCE_DIR}/foundation/graphic/lite/interfaces/kits/ui/font
- ${PROJECT_SOURCE_DIR}/foundation/graphic/lite/interfaces/kits/ui/layout
- ${PROJECT_SOURCE_DIR}/foundation/graphic/lite/interfaces/kits/ui/themes
- ${PROJECT_SOURCE_DIR}/foundation/graphic/lite/interfaces/kits/ui/window
- ${PROJECT_SOURCE_DIR}/foundation/graphic/lite/interfaces/kits/utils
- ${PROJECT_SOURCE_DIR}/foundation/graphic/lite/services/ims/include
- ${PROJECT_SOURCE_DIR}/foundation/graphic/lite/services/wms/include
- ${PROJECT_SOURCE_DIR}/foundation/graphic/lite/utils/include
- )
-
-target_link_libraries(ui PUBLIC libjpeg)
-target_link_libraries(ui PUBLIC libpng)
-target_link_libraries(ui PUBLIC freetype)
\ No newline at end of file
diff --git a/LICENSE b/LICENSE
old mode 100755
new mode 100644
index 4a45986..4947287
--- a/LICENSE
+++ b/LICENSE
@@ -1,177 +1,177 @@
-
- Apache License
- Version 2.0, January 2004
- http://www.apache.org/licenses/
-
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
- 1. Definitions.
-
- "License" shall mean the terms and conditions for use, reproduction,
- and distribution as defined by Sections 1 through 9 of this document.
-
- "Licensor" shall mean the copyright owner or entity authorized by
- the copyright owner that is granting the License.
-
- "Legal Entity" shall mean the union of the acting entity and all
- other entities that control, are controlled by, or are under common
- control with that entity. For the purposes of this definition,
- "control" means (i) the power, direct or indirect, to cause the
- direction or management of such entity, whether by contract or
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
- outstanding shares, or (iii) beneficial ownership of such entity.
-
- "You" (or "Your") shall mean an individual or Legal Entity
- exercising permissions granted by this License.
-
- "Source" form shall mean the preferred form for making modifications,
- including but not limited to software source code, documentation
- source, and configuration files.
-
- "Object" form shall mean any form resulting from mechanical
- transformation or translation of a Source form, including but
- not limited to compiled object code, generated documentation,
- and conversions to other media types.
-
- "Work" shall mean the work of authorship, whether in Source or
- Object form, made available under the License, as indicated by a
- copyright notice that is included in or attached to the work
- (an example is provided in the Appendix below).
-
- "Derivative Works" shall mean any work, whether in Source or Object
- form, that is based on (or derived from) the Work and for which the
- editorial revisions, annotations, elaborations, or other modifications
- represent, as a whole, an original work of authorship. For the purposes
- of this License, Derivative Works shall not include works that remain
- separable from, or merely link (or bind by name) to the interfaces of,
- the Work and Derivative Works thereof.
-
- "Contribution" shall mean any work of authorship, including
- the original version of the Work and any modifications or additions
- to that Work or Derivative Works thereof, that is intentionally
- submitted to Licensor for inclusion in the Work by the copyright owner
- or by an individual or Legal Entity authorized to submit on behalf of
- the copyright owner. For the purposes of this definition, "submitted"
- means any form of electronic, verbal, or written communication sent
- to the Licensor or its representatives, including but not limited to
- communication on electronic mailing lists, source code control systems,
- and issue tracking systems that are managed by, or on behalf of, the
- Licensor for the purpose of discussing and improving the Work, but
- excluding communication that is conspicuously marked or otherwise
- designated in writing by the copyright owner as "Not a Contribution."
-
- "Contributor" shall mean Licensor and any individual or Legal Entity
- on behalf of whom a Contribution has been received by Licensor and
- subsequently incorporated within the Work.
-
- 2. Grant of Copyright License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- copyright license to reproduce, prepare Derivative Works of,
- publicly display, publicly perform, sublicense, and distribute the
- Work and such Derivative Works in Source or Object form.
-
- 3. Grant of Patent License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- (except as stated in this section) patent license to make, have made,
- use, offer to sell, sell, import, and otherwise transfer the Work,
- where such license applies only to those patent claims licensable
- by such Contributor that are necessarily infringed by their
- Contribution(s) alone or by combination of their Contribution(s)
- with the Work to which such Contribution(s) was submitted. If You
- institute patent litigation against any entity (including a
- cross-claim or counterclaim in a lawsuit) alleging that the Work
- or a Contribution incorporated within the Work constitutes direct
- or contributory patent infringement, then any patent licenses
- granted to You under this License for that Work shall terminate
- as of the date such litigation is filed.
-
- 4. Redistribution. You may reproduce and distribute copies of the
- Work or Derivative Works thereof in any medium, with or without
- modifications, and in Source or Object form, provided that You
- meet the following conditions:
-
- (a) You must give any other recipients of the Work or
- Derivative Works a copy of this License; and
-
- (b) You must cause any modified files to carry prominent notices
- stating that You changed the files; and
-
- (c) You must retain, in the Source form of any Derivative Works
- that You distribute, all copyright, patent, trademark, and
- attribution notices from the Source form of the Work,
- excluding those notices that do not pertain to any part of
- the Derivative Works; and
-
- (d) If the Work includes a "NOTICE" text file as part of its
- distribution, then any Derivative Works that You distribute must
- include a readable copy of the attribution notices contained
- within such NOTICE file, excluding those notices that do not
- pertain to any part of the Derivative Works, in at least one
- of the following places: within a NOTICE text file distributed
- as part of the Derivative Works; within the Source form or
- documentation, if provided along with the Derivative Works; or,
- within a display generated by the Derivative Works, if and
- wherever such third-party notices normally appear. The contents
- of the NOTICE file are for informational purposes only and
- do not modify the License. You may add Your own attribution
- notices within Derivative Works that You distribute, alongside
- or as an addendum to the NOTICE text from the Work, provided
- that such additional attribution notices cannot be construed
- as modifying the License.
-
- You may add Your own copyright statement to Your modifications and
- may provide additional or different license terms and conditions
- for use, reproduction, or distribution of Your modifications, or
- for any such Derivative Works as a whole, provided Your use,
- reproduction, and distribution of the Work otherwise complies with
- the conditions stated in this License.
-
- 5. Submission of Contributions. Unless You explicitly state otherwise,
- any Contribution intentionally submitted for inclusion in the Work
- by You to the Licensor shall be under the terms and conditions of
- this License, without any additional terms or conditions.
- Notwithstanding the above, nothing herein shall supersede or modify
- the terms of any separate license agreement you may have executed
- with Licensor regarding such Contributions.
-
- 6. Trademarks. This License does not grant permission to use the trade
- names, trademarks, service marks, or product names of the Licensor,
- except as required for reasonable and customary use in describing the
- origin of the Work and reproducing the content of the NOTICE file.
-
- 7. Disclaimer of Warranty. Unless required by applicable law or
- agreed to in writing, Licensor provides the Work (and each
- Contributor provides its Contributions) on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied, including, without limitation, any warranties or conditions
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
- PARTICULAR PURPOSE. You are solely responsible for determining the
- appropriateness of using or redistributing the Work and assume any
- risks associated with Your exercise of permissions under this License.
-
- 8. Limitation of Liability. In no event and under no legal theory,
- whether in tort (including negligence), contract, or otherwise,
- unless required by applicable law (such as deliberate and grossly
- negligent acts) or agreed to in writing, shall any Contributor be
- liable to You for damages, including any direct, indirect, special,
- incidental, or consequential damages of any character arising as a
- result of this License or out of the use or inability to use the
- Work (including but not limited to damages for loss of goodwill,
- work stoppage, computer failure or malfunction, or any and all
- other commercial damages or losses), even if such Contributor
- has been advised of the possibility of such damages.
-
- 9. Accepting Warranty or Additional Liability. While redistributing
- the Work or Derivative Works thereof, You may choose to offer,
- and charge a fee for, acceptance of support, warranty, indemnity,
- or other liability obligations and/or rights consistent with this
- License. However, in accepting such obligations, You may act only
- on Your own behalf and on Your sole responsibility, not on behalf
- of any other Contributor, and only if You agree to indemnify,
- defend, and hold each Contributor harmless for any liability
- incurred by, or claims asserted against, such Contributor by reason
- of your accepting any such warranty or additional liability.
-
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
END OF TERMS AND CONDITIONS
\ No newline at end of file
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..301d3bb
--- /dev/null
+++ b/README.md
@@ -0,0 +1,69 @@
+# Surface
+
+- [Introduction](#section11660541593)
+- [Directory Structure](#section161941989596)
+- [Compilation and Building](#section137768191623)
+- [Description](#section1312121216216)
+ - [Process Description](#section1551164914237)
+ - [Usage](#section129654513264)
+
+- [Repositories Involved](#section1371113476307)
+
+## Introduction
+
+A surface is used to manage and transfer the shared memory of graphics and media. Specific use cases include graphics display and composition, and media playback and recording.
+
+A surface transfers data across processes through control structures such as Inter-Process Communication \(IPC\) handles \(with copies\), and transfers graphics and media data \(zero-copy\) through shared memory. The following figure shows the position where a surface works in the system architecture. The elements in green blocks are surface buffers.
+
+**Figure 1** Position of a surface in the system architecture
+
+
+## Directory Structure
+
+```
+/foundation/graphic/surface
+├── frameworks # Framework code
+├── interfaces # APIs
+│ ├── innerkits # APIs between modules
+│ └── kits # External APIs
+└── test # Test code
+ ├── fuzztest # Fuzzing
+ └── unittest # Unit testing
+```
+
+## Compilation and Building
+
+```
+# Generate the libsurface.so file in the out directory of the product folder through GN compilation.
+hb build lite_surface
+```
+
+## Description
+
+### Process Description
+
+Take the interaction between Window Manager Service \(WMS\) and UI as an example. UI works as a producer, and WMS works as a consumer.
+
+The producer obtains a buffer from the free queue, draws the UI content into the buffer, and places the buffer in the dirty queue.
+
+The consumer obtains the buffer from the dirty queue, synthesizes graphics data, and places the buffer in the free queue again.
+
+**Figure 2** Surface rotation process
+
+
+> **NOTICE:**
+>1. A shared memory is used for data transfer, and the task of managing the shared memory runs in the process of creating a surface for the first time. If the process is abnormal and is not recycled, severe memory leakage occurs. Therefore, pay special attention to the process.
+>2. Surfaces are generally used for cross-process transfers of large memory blocks \(such as display data\) in graphics or media. Especially, when continuous physical memory is used, the transfer rate can be greatly improved. It is not recommended that surfaces be used in small-memory transfer scenarios. Otherwise, memory fragmentation may occur, which affects the performance in typical scenarios.
+
+### Usage
+
+For details, see [WMS](en-us_topic_0000001122925147.md).
+
+## Repositories Involved
+
+/hmf/graphic/wms
+
+/hmf/graphic/ui
+
+/hmf/graphic/utils
+
diff --git a/README_zh.md b/README_zh.md
new file mode 100644
index 0000000..2fc13ec
--- /dev/null
+++ b/README_zh.md
@@ -0,0 +1,69 @@
+# 图形SURFACE组件
+
+- [简介](#section11660541593)
+- [目录](#section161941989596)
+- [编译构建](#section137768191623)
+- [说明](#section1312121216216)
+ - [流程说明](#section1551164914237)
+ - [使用说明](#section129654513264)
+
+- [相关仓](#section1371113476307)
+
+## 简介
+
+Surface组件用于管理和传递图形和媒体的共享内存。具体场景包括了图形的送显、合成,媒体的播放、录制等。
+
+Surface的跨进程传输使用IPC传输句柄等控制结构(有拷贝),使用共享内存传递图形/媒体数据(零拷贝)。
+
+**图 1** surface在系统架构中的位置(绿色部分为surface buffer)
+.png "surface在系统架构中的位置(绿色部分为surface-buffer)")
+
+## 目录
+
+```
+/foundation/graphic/surface
+├── frameworks # 框架代码
+├── interfaces # 接口
+│ ├── innerkits # 模块间接口
+│ └── kits # 对外接口
+└── test # 测试代码
+ ├── fuzztest # fuzz测试
+ └── unittest # 单元测试
+```
+
+## 编译构建
+
+```
+# 通过gn编译,在out目录下对应产品的文件夹中生成libsurface.so
+hb build lite_surface
+```
+
+## 说明
+
+### 流程说明
+
+以WMS组件和UI组件交互为例,UI为生产者,WMS为消费者。
+
+生产者:从Free队列中获取Buffer,将UI内容绘制到Buffer中,然后将Buffer放到Dirty队列;
+
+消费者:从Dirty队列中获取Buffer并进行合成,然后将Buffer重新放到Free队列中。
+
+**图 2** Surface轮转流程
+
+
+> **须知:**
+>1. 由于使用了共享内存,而共享内存的管理任务在首次创建Surface的进程中,因此需要对该进程格外关注,如果发生进程异常且没有回收处理会发生严重的内存泄漏;
+>2. Surface一般用作图形/媒体中大块内存的跨进程传输(如显示数据),尤其在使用了连续物理内存的情况下,可以大幅提高传输速率。不建议用在小内存传输的场景,容易造成内存碎片化影响典型场景的性能。
+
+### 使用说明
+
+可参考图形[图形WMS组件](zh-cn_topic_0000001122925147.md)。
+
+## 相关仓
+
+/hmf/graphic/wms
+
+/hmf/graphic/ui
+
+/hmf/graphic/utils
+
diff --git a/figures/Surface轮转流程.png b/figures/Surface轮转流程.png
new file mode 100644
index 0000000..35f7c1d
Binary files /dev/null and b/figures/Surface轮转流程.png differ
diff --git a/figures/position-of-a-surface-in-the-system-architecture.png b/figures/position-of-a-surface-in-the-system-architecture.png
new file mode 100644
index 0000000..60de5b6
Binary files /dev/null and b/figures/position-of-a-surface-in-the-system-architecture.png differ
diff --git a/figures/surface-rotation-process.png b/figures/surface-rotation-process.png
new file mode 100644
index 0000000..fa9b771
Binary files /dev/null and b/figures/surface-rotation-process.png differ
diff --git a/figures/surface在系统架构中的位置(绿色部分为surface-buffer).png b/figures/surface在系统架构中的位置(绿色部分为surface-buffer).png
new file mode 100644
index 0000000..60de5b6
Binary files /dev/null and b/figures/surface在系统架构中的位置(绿色部分为surface-buffer).png differ
diff --git a/frameworks/surface/src/buffer_client_producer.cpp b/frameworks/buffer_client_producer.cpp
similarity index 83%
rename from frameworks/surface/src/buffer_client_producer.cpp
rename to frameworks/buffer_client_producer.cpp
index ad8afbf..71159d4 100755
--- a/frameworks/surface/src/buffer_client_producer.cpp
+++ b/frameworks/buffer_client_producer.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020 Huawei Device Co., Ltd.
+ * Copyright (c) 2020-2021 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
@@ -25,7 +25,7 @@
#include "surface_buffer_impl.h"
namespace OHOS {
-const int32_t DEFAULT_IPC_SIZE = 100;
+const int32_t DEFAULT_IPC_SIZE = 200;
BufferClientProducer::BufferClientProducer(const SvcIdentity& sid) : sid_(sid)
{
}
@@ -98,11 +98,11 @@ int32_t BufferClientProducer::FlushBuffer(SurfaceBufferImpl* buffer)
return ret;
}
ret = IpcIoPopInt32(&reply);
+ FreeBuffer(nullptr, reinterpret_cast(ptr));
if (ret != SURFACE_ERROR_OK) {
GRAPHIC_LOGW("FlushBuffer failed code=%d", ret);
- ret = -1;
+ return -1;
}
- FreeBuffer(nullptr, reinterpret_cast(ptr));
manager->UnmapBuffer(*buffer);
delete buffer;
return ret;
@@ -110,6 +110,9 @@ int32_t BufferClientProducer::FlushBuffer(SurfaceBufferImpl* buffer)
void BufferClientProducer::Cancel(SurfaceBufferImpl* buffer)
{
+ if (buffer == nullptr) {
+ return;
+ }
IpcIo requestIo;
uint8_t requestIoData[DEFAULT_IPC_SIZE];
IpcIoInit(&requestIo, requestIoData, DEFAULT_IPC_SIZE, 0);
@@ -240,6 +243,48 @@ uint32_t BufferClientProducer::GetUsage()
return usage;
}
+void BufferClientProducer::SetUserData(const std::string& key, const std::string& value)
+{
+ IpcIo requestIo;
+ uint8_t requestIoData[DEFAULT_IPC_SIZE];
+ IpcIoInit(&requestIo, requestIoData, DEFAULT_IPC_SIZE, 0);
+ IpcIoPushString(&requestIo, key.c_str());
+ IpcIoPushString(&requestIo, value.c_str());
+ IpcIo reply;
+ uintptr_t ptr;
+ int32_t ret = Transact(nullptr, sid_, SET_USER_DATA, &requestIo, &reply, LITEIPC_FLAG_DEFAULT, &ptr);
+ if (ret != SURFACE_ERROR_OK) {
+ GRAPHIC_LOGW("Get user data(%s) failed", key.c_str());
+ } else {
+ FreeBuffer(nullptr, reinterpret_cast(ptr));
+ }
+}
+
+std::string BufferClientProducer::GetUserData(const std::string& key)
+{
+ std::string sValue = std::string();
+ IpcIo requestIo;
+ uint8_t requestIoData[DEFAULT_IPC_SIZE];
+ IpcIoInit(&requestIo, requestIoData, DEFAULT_IPC_SIZE, 0);
+ IpcIoPushString(&requestIo, key.c_str());
+ IpcIo reply;
+ uintptr_t ptr;
+ int32_t ret = Transact(nullptr, sid_, GET_USER_DATA, &requestIo, &reply, LITEIPC_FLAG_DEFAULT, &ptr);
+ if (ret != SURFACE_ERROR_OK) {
+ return sValue;
+ } else {
+ size_t len = 0;
+ const char* value = reinterpret_cast(IpcIoPopString(&reply, &len));
+ if (value == nullptr || len == 0) {
+ GRAPHIC_LOGW("Get user data failed");
+ } else {
+ sValue = value;
+ }
+ FreeBuffer(nullptr, reinterpret_cast(ptr));
+ return sValue;
+ }
+}
+
void BufferClientProducer::SetAttr(uint32_t code, uint32_t value)
{
IpcIo requestIo;
diff --git a/frameworks/surface/include/buffer_client_producer.h b/frameworks/buffer_client_producer.h
similarity index 91%
rename from frameworks/surface/include/buffer_client_producer.h
rename to frameworks/buffer_client_producer.h
index 6b07bb1..9c0a918 100755
--- a/frameworks/surface/include/buffer_client_producer.h
+++ b/frameworks/buffer_client_producer.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020 Huawei Device Co., Ltd.
+ * Copyright (c) 2020-2021 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
@@ -13,18 +13,15 @@
* limitations under the License.
*/
-#ifndef GRAPHIC_LITE_BUFFER_SLAVE_PRODUCER_H
-#define GRAPHIC_LITE_BUFFER_SLAVE_PRODUCER_H
+#ifndef GRAPHIC_LITE_BUFFER_CLIENT_PRODUCER_H
+#define GRAPHIC_LITE_BUFFER_CLIENT_PRODUCER_H
#include "buffer_producer.h"
-#include "surface_buffer.h"
#include "buffer_queue.h"
-#ifndef _SURFACE_LINUX_
-#include "serializer.h"
#include "liteipc_adapter.h"
-#endif
+#include "serializer.h"
+#include "surface_buffer.h"
namespace OHOS {
-#ifndef _SURFACE_LINUX_
/**
* @brief Surface producer client class in multi process. Surface Client invoke these method to send ipc
* request to BufferQueueProducer for request buffer, flush buffer, cancel buffer and set buffer attr.
@@ -35,7 +32,7 @@ public:
* @brief Surface Buffer Client Producer Constructor.
* @param [in] SvcIdentity sid, Surface consumer sid, for sending ipc request.
*/
- BufferClientProducer(const SvcIdentity& sid);
+ explicit BufferClientProducer(const SvcIdentity& sid);
/**
* @brief Surface Buffer Client Producer Destructor.
@@ -163,12 +160,24 @@ public:
* @returns The buffer usage.
*/
uint32_t GetUsage() override;
+
+ /**
+ * @brief Set user data. Construct a local map to store all the user-data.
+ * @param [in] key.
+ * @param [in] value.
+ */
+ void SetUserData(const std::string& key, const std::string& value) override;
+
+ /**
+ * @brief Get user data. Get the value from local map.
+ * @returns value refers to the key.
+ */
+ std::string GetUserData(const std::string& key) override;
private:
uint32_t GetAttr(uint32_t code);
void SetAttr(uint32_t code, uint32_t value);
SvcIdentity sid_;
};
-#endif
} // end namespace
#endif
diff --git a/frameworks/surface/src/buffer_manager.cpp b/frameworks/buffer_manager.cpp
similarity index 94%
rename from frameworks/surface/src/buffer_manager.cpp
rename to frameworks/buffer_manager.cpp
index a2c3fbf..340f260 100755
--- a/frameworks/surface/src/buffer_manager.cpp
+++ b/frameworks/buffer_manager.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020 Huawei Device Co., Ltd.
+ * Copyright (c) 2020-2021 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
@@ -16,13 +16,14 @@
#include "buffer_manager.h"
#include "buffer_common.h"
+#include "securec.h"
#include "surface_buffer.h"
namespace OHOS {
BufferManager* BufferManager::GetInstance()
{
- static BufferManager BufferManager;
- return &BufferManager;
+ static BufferManager instance;
+ return &instance;
}
bool BufferManager::Init()
@@ -97,13 +98,16 @@ SurfaceBufferImpl* BufferManager::AllocBuffer(uint32_t size, uint32_t usage)
buffer->SetShmid(grallocBuffer.hdl.shmid);
buffer->SetPhyAddr(grallocBuffer.hdl.phyAddr);
GRAPHIC_LOGI("Alloc buffer succeed to shared memory segment.");
+ if (memset_s(grallocBuffer.virAddr, grallocBuffer.size, 0, grallocBuffer.size) != EOK) {
+ GRAPHIC_LOGW("Clear buffer failed.");
+ }
} else {
GRAPHIC_LOGW("Alloc buffer failed to shared memory segment.");
}
return buffer;
}
-void BufferManager::FreeBuffer(SurfaceBufferImpl* buffer)
+void BufferManager::FreeBuffer(const SurfaceBufferImpl* buffer)
{
RETURN_IF_FAIL((grallocFucs_ != nullptr));
if (buffer == nullptr) {
diff --git a/frameworks/surface/include/buffer_manager.h b/frameworks/buffer_manager.h
similarity index 96%
rename from frameworks/surface/include/buffer_manager.h
rename to frameworks/buffer_manager.h
index 092cd0d..14f9a17 100755
--- a/frameworks/surface/include/buffer_manager.h
+++ b/frameworks/buffer_manager.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020 Huawei Device Co., Ltd.
+ * Copyright (c) 2020-2021 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
@@ -52,7 +52,7 @@ public:
* @brief Free the buffer.
* @param [in] SurfaceBufferImpl pointer, free the buffer size.
*/
- void FreeBuffer(SurfaceBufferImpl* buffer);
+ void FreeBuffer(const SurfaceBufferImpl* buffer);
/**
* @brief Flush the buffer.
diff --git a/frameworks/surface/src/buffer_queue.cpp b/frameworks/buffer_queue.cpp
similarity index 99%
rename from frameworks/surface/src/buffer_queue.cpp
rename to frameworks/buffer_queue.cpp
index 460ee31..dc3f0a4 100755
--- a/frameworks/surface/src/buffer_queue.cpp
+++ b/frameworks/buffer_queue.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020 Huawei Device Co., Ltd.
+ * Copyright (c) 2020-2021 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
diff --git a/frameworks/surface/src/buffer_queue_consumer.cpp b/frameworks/buffer_queue_consumer.cpp
similarity index 95%
rename from frameworks/surface/src/buffer_queue_consumer.cpp
rename to frameworks/buffer_queue_consumer.cpp
index 91d2f97..17b04cd 100755
--- a/frameworks/surface/src/buffer_queue_consumer.cpp
+++ b/frameworks/buffer_queue_consumer.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020 Huawei Device Co., Ltd.
+ * Copyright (c) 2020-2021 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
diff --git a/frameworks/surface/src/buffer_queue_producer.cpp b/frameworks/buffer_queue_producer.cpp
similarity index 87%
rename from frameworks/surface/src/buffer_queue_producer.cpp
rename to frameworks/buffer_queue_producer.cpp
index 8ea9709..10dd02f 100755
--- a/frameworks/surface/src/buffer_queue_producer.cpp
+++ b/frameworks/buffer_queue_producer.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020 Huawei Device Co., Ltd.
+ * Copyright (c) 2020-2021 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
@@ -23,7 +23,6 @@
namespace OHOS {
const int32_t DEFAULT_IPC_SIZE = 100;
-#ifndef _SURFACE_LINUX_
extern "C" {
typedef int32_t (*IpcMsgHandle)(BufferQueueProducer* product, void *ipcMsg, IpcIo *io);
};
@@ -178,6 +177,44 @@ static int32_t OnGetUsage(BufferQueueProducer* product, void *ipcMsg, IpcIo *io)
return OnGetAttr(product->GetUsage(), ipcMsg, io);
}
+static int32_t OnSetUserData(BufferQueueProducer* product, void *ipcMsg, IpcIo *io)
+{
+ size_t len = 0;
+ const char* key = reinterpret_cast(IpcIoPopString(io, &len));
+ if (key == nullptr || len == 0) {
+ GRAPHIC_LOGW("Get user data key failed");
+ return -1;
+ }
+ const char* value = reinterpret_cast(IpcIoPopString(io, &len));
+ if (value == nullptr || len == 0) {
+ GRAPHIC_LOGW("Get user data value failed");
+ return -1;
+ }
+ std::string sKey = key;
+ std::string sValue = value;
+ product->SetUserData(sKey, sValue);
+ OnSendReply(ipcMsg, io);
+ return 0;
+}
+
+static int32_t OnGetUserData(BufferQueueProducer* product, void *ipcMsg, IpcIo *io)
+{
+ size_t len = 0;
+ const char* key = reinterpret_cast(IpcIoPopString(io, &len));
+ if (key == nullptr || len == 0) {
+ GRAPHIC_LOGW("Get user data key failed");
+ return -1;
+ }
+ std::string sKey = key;
+ std::string value = product->GetUserData(sKey);
+ IpcIo reply;
+ uint8_t tmpData[DEFAULT_IPC_SIZE];
+ IpcIoInit(&reply, tmpData, DEFAULT_IPC_SIZE, 0);
+ IpcIoPushString(&reply, value.c_str());
+ SendReply(nullptr, ipcMsg, &reply);
+ return 0;
+}
+
static IpcMsgHandle g_ipcMsgHandleList[] = {
OnRequestBuffer, // REQUEST_BUFFER
OnFlushBuffer, // FLUSH_BUFFER
@@ -196,8 +233,9 @@ static IpcMsgHandle g_ipcMsgHandleList[] = {
OnGetSize, // GET_SIZE
OnSetUsage, // SET_USAGE
OnGetUsage, // GET_USAGE
+ OnSetUserData, // SET_USER_DATA
+ OnGetUserData, // GET_USER_DATA
};
-#endif
BufferQueueProducer::BufferQueueProducer(BufferQueue* bufferQueue)
: bufferQueue_(bufferQueue),
@@ -206,9 +244,7 @@ BufferQueueProducer::BufferQueueProducer(BufferQueue* bufferQueue)
}
BufferQueueProducer::~BufferQueueProducer()
{
- if (consumerListener_ != nullptr) {
- consumerListener_ = nullptr;
- }
+ consumerListener_ = nullptr;
if (bufferQueue_ != nullptr) {
delete bufferQueue_;
bufferQueue_ = nullptr;
@@ -236,6 +272,7 @@ int32_t BufferQueueProducer::EnqueueBuffer(SurfaceBufferImpl& buffer)
int32_t BufferQueueProducer::FlushBuffer(SurfaceBufferImpl* buffer)
{
+ RETURN_VAL_IF_FAIL(buffer, SURFACE_ERROR_INVAILD_PARAM);
RETURN_VAL_IF_FAIL(bufferQueue_, SURFACE_ERROR_INVAILD_PARAM);
BufferManager* manager = BufferManager::GetInstance();
RETURN_VAL_IF_FAIL(manager, SURFACE_ERROR_NOT_READY);
@@ -349,7 +386,6 @@ void BufferQueueProducer::UnregisterConsumerListener()
consumerListener_ = nullptr;
}
-#ifndef _SURFACE_LINUX_
int32_t BufferQueueProducer::OnIpcMsg(void *ipcMsg, IpcIo *io)
{
if (ipcMsg == NULL || io == NULL) {
@@ -365,7 +401,6 @@ int32_t BufferQueueProducer::OnIpcMsg(void *ipcMsg, IpcIo *io)
}
return g_ipcMsgHandleList[code](this, ipcMsg, io);
}
-#endif
void BufferQueueProducer::SetUserData(const std::string& key, const std::string& value)
{
diff --git a/frameworks/surface/include/buffer_queue_producer.h b/frameworks/buffer_queue_producer.h
similarity index 98%
rename from frameworks/surface/include/buffer_queue_producer.h
rename to frameworks/buffer_queue_producer.h
index b81a16f..f45a303 100755
--- a/frameworks/surface/include/buffer_queue_producer.h
+++ b/frameworks/buffer_queue_producer.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020 Huawei Device Co., Ltd.
+ * Copyright (c) 2020-2021 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
@@ -34,7 +34,7 @@ public:
* @param [in] BufferQueue bufferQueue, to request buffer, flush buffer,
* cancel buffer and set buffer attr.
*/
- BufferQueueProducer(BufferQueue* bufferQueue);
+ explicit BufferQueueProducer(BufferQueue* bufferQueue);
/**
* @brief Surface Buffer Producer Destructor.
@@ -191,7 +191,7 @@ public:
* there will have no listener.
*/
void UnregisterConsumerListener();
-#ifndef _SURFACE_LINUX_
+
/**
* @brief Deal with the ipc msg from BufferClientProducer.
* @param [in] ipcMsg, ipc msg, constains request code...
@@ -199,7 +199,6 @@ public:
* @returns 0 is succeed; other is failed.
*/
int32_t OnIpcMsg(void *ipcMsg, IpcIo *io);
-#endif
private:
BufferQueue* bufferQueue_;
IBufferConsumerListener* consumerListener_;
diff --git a/frameworks/surface/src/surface.cpp b/frameworks/surface.cpp
similarity index 95%
rename from frameworks/surface/src/surface.cpp
rename to frameworks/surface.cpp
index 0d51bd9..9a61859 100755
--- a/frameworks/surface/src/surface.cpp
+++ b/frameworks/surface.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020 Huawei Device Co., Ltd.
+ * Copyright (c) 2020-2021 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
diff --git a/frameworks/surface/BUILD.gn b/frameworks/surface/BUILD.gn
deleted file mode 100755
index 5e1a6c1..0000000
--- a/frameworks/surface/BUILD.gn
+++ /dev/null
@@ -1,69 +0,0 @@
-# Copyright (c) 2020 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.
-
-import("//build/lite/config/component/lite_component.gni")
-
-generate_notice_file("surface_lite_notice_file") {
- module_name = "surface_lite"
- module_source_dir_list = [ "//third_party/bounds_checking_function" ]
-}
-
-shared_library("surface") {
- sources = [
- "src/buffer_manager.cpp",
- "src/buffer_queue.cpp",
- "src/buffer_queue_consumer.cpp",
- "src/buffer_queue_producer.cpp",
- "src/surface.cpp",
- "src/surface_buffer_impl.cpp",
- "src/surface_impl.cpp",
- ]
- public_configs = [ ":surface_external_library_config" ]
- include_dirs = [
- "//kernel/liteos_a/kernel/include/",
- "//kernel/liteos_a/kernel/common",
- "//third_party/bounds_checking_function/include",
- "//drivers/hdf/lite/hdi/display/include",
- "//foundation/graphic/lite/interfaces/kits/utils",
- "//foundation/graphic/lite/interfaces/kits/config",
- ]
- cflags = [ "-fPIC" ]
- cflags += [ "-Wall" ]
- public_deps = [
- "//base/hiviewdfx/frameworks/hilog_lite/featured:hilog_shared",
- "//vendor/huawei/hdf/display/hdi:hdi_display",
- ]
- if (ohos_kernel_type == "liteos_a") {
- sources += [ "src/buffer_client_producer.cpp" ]
- cflags += [ "-D _SURFACE_LITEOS_A_" ]
- public_deps +=
- [ "//foundation/communication/frameworks/ipc_lite:liteipc_adapter" ]
- } else if (ohos_kernel_type == "linux") {
- cflags += [ "-D _SURFACE_LINUX_" ]
- }
- cflags_cc = cflags
- ldflags = [ "-ldisplay_gralloc" ]
- deps = [
- "//third_party/bounds_checking_function:libsec_shared",
- ]
-}
-
-config("surface_external_library_config") {
- include_dirs = [
- "//foundation/graphic/lite/interfaces/kits/surface",
- "include",
- "//drivers/hdf/lite/hdi/display/include",
- ]
-}
-
-lite_component("litesurface") {
- features = [ ":surface" ]
-}
diff --git a/frameworks/surface/Readme.md b/frameworks/surface/Readme.md
deleted file mode 100755
index 5824475..0000000
--- a/frameworks/surface/Readme.md
+++ /dev/null
@@ -1,187 +0,0 @@
-
-### Surface Sequence Diagram
-```plantuml
-
-actor Producer
-participant "Surface" as SurfaceClient <>
-control BufferClientProducer
-collections BufferQueue
-control BufferManager
-control BufferQueueProducer
-
-Producer -> SurfaceClient ++: RequestBuffer
-SurfaceClient -> BufferClientProducer ++: RequestBuffer
-BufferClientProducer -> BufferQueueProducer++ : <>
-BufferQueueProducer -> BufferQueue ++: Dequeue
-opt free list is empty
-BufferQueue -> BufferManager ++: AllocBuffer
-create entity Buffer
-BufferManager -> Buffer : new Buffer
-note right : allocate buffer with virtural or phiscal memory.
-return buffer
-BufferQueue -> BufferQueue : push to free list
-end
-BufferQueue -> BufferQueue : pop from free list
-return buffer
-return buffer
-BufferClientProducer -> BufferManager++ : MapBuffer
-return success
-return buffer
-return buffer
-
-Producer -> Producer : write data to buffer
-
-Producer -> SurfaceClient ++: FlushBuffer
-SurfaceClient -> BufferClientProducer ++: FlushBuffer
-BufferClientProducer -> BufferQueueProducer++ : <>
-BufferQueueProducer -> BufferQueue ++: Enqueue
-BufferQueue -> BufferQueue : push to dirty list
-return success
-return success
-BufferClientProducer -> BufferManager++ : UnmapBuffer
-return success
-return success
-return success
-
-control BufferQueueConsumer
-participant "Surface" as SurfaceServer <>
-actor Consumer
-Consumer -> SurfaceServer ++: AcquireBuffer
-SurfaceServer -> BufferQueueConsumer ++: AcquireBuffer
-BufferQueueConsumer -> BufferQueue ++: Acquire
-BufferQueue -> BufferQueue : pop from dirty list
-return buffer
-return buffer
-return buffer
-
-Consumer -> Consumer : read data from buffer
-
-Consumer -> SurfaceServer ++: ReleaseBuffer
-SurfaceServer -> BufferQueueConsumer ++: ReleaseBuffer
-BufferQueueConsumer -> BufferQueue ++: Release
-BufferQueue -> BufferQueue: push to free list
-return success
-return success
-return success
-```
-
-###Surface State Diagram
-
-```plantuml
-[*] --> NONE : Allocate Buffer
-NONE --> DEQUEUE : Dequeue Buffer
-DEQUEUE --> ENQUEUE : Enqueue Buffer
-DEQUEUE --> FREE : Cancel Buffer
-ENQUEUE --> ACQUIRE : Acquire Buffer
-ACQUIRE --> FREE : Release Buffer
-FREE -->DEQUEUE : Dequeue Buffer
-
-FREE --> [*] : Free Buffer
-```
-
-###Surface Class Diagram
-```plantuml
-namespace OHOS {
- class Surface {
- __Methods__
- +{static}GenericSurfaceByIpcIo(IpcIo& io):Surface*
- +Surface()
- +RequestBuffer(uint8_t):SurfaceBuffer*
- +FlushBuffer(SurfaceBuffer*):bool
- +AcquireBuffer():SurfaceBuffer*
- +CancelBuffer(SurfaceBuffer*)
- +ReleaseBuffer(const SurfaceBuffer& buffer):bool
- +RegisterConsumerListener(IBufferConsumerListener& listener)
- +UnregisterConsumerListener()
- +WriteIoIpcIo(IpcIo& io)
- __Attributes__
- -BufferProducer producer_
- -BufferQueueConsumer consumer_
- }
- abstract class BufferProducer {
- __Methods__
- +{abstract} RequestBuffer(uint8_t):SurfaceBuffer*
- +{abstract} FlushBuffer(SurfaceBuffer*):bool
- +{abstract} CancelBuffer(SurfaceBuffer*)
- }
- class BufferClientProducer {
- __Methods__
- +RequestBuffer(uint8_t):SurfaceBuffer*
- +FlushBuffer(SurfaceBuffer*):bool
- +CancelBuffer(SurfaceBuffer*)
- }
- class BufferQueueProducer {
- __Methods__
- +RequestBuffer(uint8_t):SurfaceBuffer*
- +FlushBuffer(SurfaceBuffer*):bool
- +CancelBuffer(SurfaceBuffer*)
- __Attributes__
- -BufferQueue queue_
- }
- class BufferQueueConsumer {
- __Methods__
- +AcquireBuffer():SurfaceBuffer*
- +ReleaseBuffer(const SurfaceBuffer&):bool
- __Attributes__
- -BufferQueue queue_
- }
- class BufferQueue {
- __Methods__
- +Dequeue(uint8_t):SurfaceBuffer*
- +Enqueue(SurfaceBuffer& buffer):int32_t
- +Acquire():SurfaceBuffer*
- +Release(const SurfaceBuffer&):bool
- +Cancel(const SurfaceBuffer&):int32_t
- __Attributes__
- -List allBuffers
- -List freeLists
- -List dirtyLists
- }
- abstract class BufferManager {
- +{abstract} AllocBuffer(uint32_t, uint32_t) : SurfaceBuffer*
- +{abstract} FreeBuffer(SurfaceBuffer*)
- +{abstract} FlushCache(const SurfaceBuffer& buffer) : int32_t
- +{abstract} MapBuffer(SurfaceBuffer&)
- +{abstract} UnmapBuffer(SurfaceBuffer&)
- }
- class BufferManagerDumb {
- +AllocBuffer(uint32_t, uint32_t) : SurfaceBuffer*
- +FreeBuffer(SurfaceBuffer*)
- +FlushCache(const SurfaceBuffer& buffer) : int32_t
- +MapBuffer(SurfaceBuffer&)
- +UnmapBuffer(SurfaceBuffer&)
- }
- class BufferManagerShm {
- +AllocBuffer(uint32_t, uint32_t) : SurfaceBuffer*
- +FreeBuffer(SurfaceBuffer*)
- +FlushCache(const SurfaceBuffer& buffer) : int32_t
- +MapBuffer(SurfaceBuffer&)
- +UnmapBuffer(SurfaceBuffer&)
- }
- class SurfaceBuffer {
- __Methods__
- +GetVirAddr() : void*
- +SetInt32(uint32_t, int32_t) : int32_t
- +GetInt32(uint32_t, int32_t&) : int32_t
- +SetInt64(uint32_t, int64_t) : int32_t
- +GetInt64(uint32_t, int64_t&) : int32_t
- +ReadFromIpcIo(IpcIo&)
- +WriteToIpcIo(IpcIo&)
- +CopyExtraData(SurfaceBuffer&)
- +ClearExtraData()
- }
-
- BufferProducer <|-- BufferClientProducer
- BufferProducer <|-- BufferQueueProducer
- BufferManager <|-- BufferManagerDumb
- BufferManager <|-- BufferManagerShm
- BufferQueue *- SurfaceBuffer : have more >
- BufferManagerDumb ..> SurfaceBuffer
- BufferManagerShm ..> SurfaceBuffer
- Surface o-- BufferProducer
- Surface o-- BufferQueueConsumer
- BufferQueueConsumer *-- BufferQueue
- BufferQueueProducer *-- BufferQueue
- BufferManager .. BufferQueue
-}
-```
diff --git a/frameworks/surface/src/surface_buffer_impl.cpp b/frameworks/surface_buffer_impl.cpp
similarity index 94%
rename from frameworks/surface/src/surface_buffer_impl.cpp
rename to frameworks/surface_buffer_impl.cpp
index f26abbd..d7f9412 100755
--- a/frameworks/surface/src/surface_buffer_impl.cpp
+++ b/frameworks/surface_buffer_impl.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020 Huawei Device Co., Ltd.
+ * Copyright (c) 2020-2021 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
@@ -108,6 +108,10 @@ int32_t SurfaceBufferImpl::SetData(uint32_t key, uint8_t type, const void* data,
int32_t SurfaceBufferImpl::GetData(uint32_t key, uint8_t* type, void** data, uint8_t* size)
{
+ if ((type == nullptr) || (data == nullptr) || (size == nullptr)) {
+ return SURFACE_ERROR_INVAILD_PARAM;
+ }
+
std::map::iterator iter = extDatas_.find(key);
if (iter == extDatas_.end()) {
return SURFACE_ERROR_INVAILD_PARAM;
@@ -119,13 +123,13 @@ int32_t SurfaceBufferImpl::GetData(uint32_t key, uint8_t* type, void** data, uin
return SURFACE_ERROR_OK;
}
-#ifndef _SURFACE_LINUX_
void SurfaceBufferImpl::ReadFromIpcIo(IpcIo& io)
{
- bufferData_.handle.key = IpcIoPopUint32(&io);
+ bufferData_.handle.key = IpcIoPopInt32(&io);
bufferData_.handle.phyAddr = IpcIoPopUint64(&io);
bufferData_.size = IpcIoPopUint32(&io);
bufferData_.usage = IpcIoPopUint32(&io);
+ len_ = IpcIoPopUint32(&io);
uint32_t extDataSize = IpcIoPopUint32(&io);
if (extDataSize > 0 && extDataSize < MAX_USER_DATA_COUNT) {
for (uint32_t i = 0; i < extDataSize; i++) {
@@ -150,14 +154,15 @@ void SurfaceBufferImpl::ReadFromIpcIo(IpcIo& io)
}
void SurfaceBufferImpl::WriteToIpcIo(IpcIo& io)
{
- IpcIoPushUint32(&io, bufferData_.handle.key);
+ IpcIoPushInt32(&io, bufferData_.handle.key);
IpcIoPushUint64(&io, bufferData_.handle.phyAddr);
IpcIoPushUint32(&io, bufferData_.size);
IpcIoPushUint32(&io, bufferData_.usage);
+ IpcIoPushUint32(&io, len_);
IpcIoPushUint32(&io, extDatas_.size());
if (!extDatas_.empty()) {
std::map::iterator iter;
- for (iter = extDatas_.begin(); iter != extDatas_.end(); iter++) {
+ for (iter = extDatas_.begin(); iter != extDatas_.end(); ++iter) {
uint32_t key = iter->first;
ExtraData value = iter->second;
IpcIoPushUint32(&io, key);
@@ -175,10 +180,10 @@ void SurfaceBufferImpl::WriteToIpcIo(IpcIo& io)
}
}
}
-#endif
void SurfaceBufferImpl::CopyExtraData(SurfaceBufferImpl& buffer)
{
+ len_ = buffer.len_;
extDatas_ = buffer.extDatas_;
buffer.extDatas_.clear();
}
@@ -187,7 +192,7 @@ void SurfaceBufferImpl::ClearExtraData()
{
if (!extDatas_.empty()) {
std::map::iterator iter;
- for (iter = extDatas_.begin(); iter != extDatas_.end(); iter++) {
+ for (iter = extDatas_.begin(); iter != extDatas_.end(); ++iter) {
ExtraData value = iter->second;
free(value.value);
value.value = NULL;
@@ -202,4 +207,4 @@ SurfaceBufferImpl::~SurfaceBufferImpl()
struct SurfaceBufferData bufferData = {{0}, 0, 0, 0, BUFFER_STATE_NONE, NULL};
bufferData_ = bufferData;
}
-}
\ No newline at end of file
+}
diff --git a/frameworks/surface/src/surface_impl.cpp b/frameworks/surface_impl.cpp
similarity index 88%
rename from frameworks/surface/src/surface_impl.cpp
rename to frameworks/surface_impl.cpp
index 5e0b58b..b4d8424 100755
--- a/frameworks/surface/src/surface_impl.cpp
+++ b/frameworks/surface_impl.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020 Huawei Device Co., Ltd.
+ * Copyright (c) 2020-2021 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
@@ -25,20 +25,16 @@ namespace OHOS {
SurfaceImpl::SurfaceImpl()
: consumer_(nullptr), producer_(nullptr), IsConsumer_(true)
{
-#ifndef _SURFACE_LINUX_
sid_ = {
.handle = 0,
.token = 0
};
-#endif
}
-#ifndef _SURFACE_LINUX_
SurfaceImpl::SurfaceImpl(const SvcIdentity& sid)
: sid_(sid), consumer_(nullptr), producer_(nullptr), IsConsumer_(false)
{
}
-#endif
SurfaceImpl::~SurfaceImpl()
{
@@ -50,6 +46,11 @@ SurfaceImpl::~SurfaceImpl()
delete producer_;
producer_ = nullptr;
}
+#ifdef __LINUX__
+ if (sid_.handle != 0) {
+ BinderRelease(sid_.ipcContext, sid_.handle);
+ }
+#endif
}
bool SurfaceImpl::Init()
@@ -73,7 +74,7 @@ bool SurfaceImpl::Init()
producer_ = new BufferQueueProducer(bufferQueue);
if (producer_ == nullptr) {
- GRAPHIC_LOGE("Surface consumer(consumer) init failed.");
+ GRAPHIC_LOGE("Surface consumer(producer) init failed.");
delete bufferQueue;
return false;
}
@@ -84,14 +85,23 @@ bool SurfaceImpl::Init()
producer_ = nullptr;
return false;
}
-#ifndef _SURFACE_LINUX_
+ SvcIdentity svc;
+ int32_t ret = RegisterIpcCallback(IpcRequestHandler, 0, IPC_WAIT_FOREVER, &svc, producer_);
+ if (ret != LITEIPC_OK) {
+ GRAPHIC_LOGE("Surface RegisterIpcCallback failed.");
+ delete consumer_;
+ consumer_ = nullptr;
+ delete producer_;
+ producer_ = nullptr;
+ return false;
+ }
+ sid_ = svc;
} else {
producer_ = new BufferClientProducer(sid_);
if (producer_ == nullptr) {
GRAPHIC_LOGE("Surface producer init failed.");
return false;
}
-#endif
}
return true;
}
@@ -247,12 +257,18 @@ void SurfaceImpl::UnregisterConsumerListener()
BufferQueueProducer* bufferQueueProducer = reinterpret_cast(producer_);
bufferQueueProducer->UnregisterConsumerListener();
}
-#ifndef _SURFACE_LINUX_
+
void SurfaceImpl::WriteIoIpcIo(IpcIo& io)
{
IpcIoPushSvc(&io, &sid_);
}
+int32_t SurfaceImpl::IpcRequestHandler(const IpcContext* context, void* ipcMsg, IpcIo* io, void* arg)
+{
+ BufferQueueProducer* product = (BufferQueueProducer*) arg;
+ return product->OnIpcMsg(ipcMsg, io);
+}
+
int32_t SurfaceImpl::DoIpcMsg(void* ipcMsg, IpcIo* io)
{
RETURN_VAL_IF_FAIL(producer_, SURFACE_ERROR_INVAILD_PARAM);
@@ -267,6 +283,11 @@ Surface* SurfaceImpl::GenericSurfaceByIpcIo(IpcIo& io)
SvcIdentity* sid = IpcIoPopSvc(&io);
if (sid != NULL) {
SurfaceImpl* surface = new SurfaceImpl(*sid);
+#ifdef __LINUX__
+ BinderAcquire(sid->ipcContext, sid->handle);
+ free(sid);
+ sid = nullptr;
+#endif
if (surface != nullptr) {
if (surface->Init()) {
return surface;
@@ -278,5 +299,4 @@ Surface* SurfaceImpl::GenericSurfaceByIpcIo(IpcIo& io)
}
return nullptr;
}
-#endif
} // namespace OHOS
diff --git a/frameworks/ui/BUILD.gn b/frameworks/ui/BUILD.gn
deleted file mode 100755
index c5a7ef0..0000000
--- a/frameworks/ui/BUILD.gn
+++ /dev/null
@@ -1,163 +0,0 @@
-# Copyright (c) 2020 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.
-
-import("//build/lite/config/component/lite_component.gni")
-
-generate_notice_file("ui_lite_notice_file") {
- module_name = "ui_lite"
- module_source_dir_list = [
- "//third_party/bounds_checking_function",
- "//third_party/cJSON",
- "//third_party/libjpeg",
- "//third_party/libpng",
- "//third_party/freetype"
- ]
-}
-
-config("vector_font_config") {
- include_dirs = [
- "//third_party/freetype/include",
- ]
-}
-
-shared_library("ui") {
- sources = [
- "src/animator/animator.cpp",
- "src/animator/easing_equation.cpp",
- "src/animator/interpolation.cpp",
- "src/common/image.cpp",
- "src/common/text.cpp",
- "src/common/screen.cpp",
- "src/common/task.cpp",
- "src/common/typed_text.cpp",
- "src/common/ui_text_language.cpp",
- "src/common/screen_device_proxy.cpp",
- "src/components/ui_button.cpp",
- "src/common/input_device_manager.cpp",
- "src/common/graphic_startup.cpp",
- "src/components/ui_checkbox.cpp",
- "src/components/ui_label_button.cpp",
- "src/components/ui_radio_button.cpp",
- "src/components/ui_repeat_button.cpp",
- "src/components/ui_toggle_button.cpp",
- "src/components/ui_canvas.cpp",
- "src/components/ui_axis.cpp",
- "src/components/ui_chart.cpp",
- "src/components/ui_abstract_clock.cpp",
- "src/components/ui_analog_clock.cpp",
- "src/components/ui_digital_clock.cpp",
- "src/components/root_view.cpp",
- "src/components/ui_abstract_scroll.cpp",
- "src/components/ui_view.cpp",
- "src/components/ui_view_group.cpp",
- "src/components/ui_image_animator.cpp",
- "src/components/ui_image_view.cpp",
- "src/components/ui_arc_label.cpp",
- "src/components/ui_label.cpp",
- "src/components/text_adapter.cpp",
- "src/components/ui_list.cpp",
- "src/components/ui_picker.cpp",
- "src/components/ui_time_picker.cpp",
- "src/components/ui_abstract_progress.cpp",
- "src/components/ui_box_progress.cpp",
- "src/components/ui_circle_progress.cpp",
- "src/components/ui_scroll_view.cpp",
- "src/components/ui_slider.cpp",
- "src/components/ui_surface_view.cpp",
- "src/components/ui_swipe_view.cpp",
- "src/components/ui_texture_mapper.cpp",
- "src/components/ui_dialog.cpp",
- "src/core/render_manager.cpp",
- "src/core/measure_manager.cpp",
- "src/core/task_manager.cpp",
- "src/default_resource/check_box_res.cpp",
- "src/default_resource/radio_button_res.cpp",
- "src/default_resource/toggle_button_res.cpp",
- "src/dfx/ui_dump_dom_tree.cpp",
- "src/dfx/event_injector.cpp",
- "src/dfx/point_event_injector.cpp",
- "src/dfx/ui_screenshot.cpp",
- "src/dock/input_device.cpp",
- "src/dock/ohos/ohos_input_device.cpp",
- "src/dock/key_input_device.cpp",
- "src/dock/pointer_input_device.cpp",
- "src/dock/virtual_input_device.cpp",
- "src/events/event.cpp",
- "src/font/ui_dynamic_font.cpp",
- "src/font/ui_font_allocator.cpp",
- "src/font/ui_font_cache.cpp",
- "src/font/ui_font.cpp",
- "src/font/ui_base_font.cpp",
- "src/font/ui_font_vector.cpp",
- "src/imgdecode/cache_manager.cpp",
- "src/imgdecode/file_img_decoder.cpp",
- "src/layout/flex_layout.cpp",
- "src/layout/grid_layout.cpp",
- "src/layout/list_layout.cpp",
- "src/themes/theme.cpp",
- "src/themes/theme_manager.cpp",
- "src/window/window.cpp",
- "src/window/window_impl.cpp",
- "src/draw/draw_arc.cpp",
- "src/draw/draw_curve.cpp",
- "src/draw/draw_image.cpp",
- "src/draw/draw_label.cpp",
- "src/draw/draw_line.cpp",
- "src/draw/draw_rect.cpp",
- "src/draw/draw_triangle.cpp",
- "src/draw/draw_utils.cpp",
- ]
- include_dirs = [
- "//foundation/graphic/lite",
- "//foundation/graphic/lite/hals/include",
- "//foundation/graphic/lite/frameworks/ui/include",
- "//foundation/graphic/lite/frameworks/ui/src",
- "//foundation/graphic/lite/interfaces",
- "//foundation/graphic/lite/interfaces/kits/surface",
- "//foundation/graphic/lite/interfaces/kits/ui",
- "//foundation/graphic/lite/interfaces/kits/utils",
- "//foundation/graphic/lite/utils/include",
- "//foundation/graphic/lite/interfaces/kits/config",
- "//foundation/graphic/lite/interfaces/innerkits/ui",
- "//foundation/graphic/lite/interfaces/innerkits/wms",
- "//foundation/graphic/lite/frameworks",
- "//foundation/graphic/lite/services/wms/include",
- "//foundation/graphic/lite/services/ims/include",
- "//foundation/graphic/lite/tools",
- "//kernel/liteos_a/kernel/include/",
- "//kernel/liteos_a/kernel/common",
- "//third_party/bounds_checking_function/include",
- "//third_party/cJSON",
- "//third_party/libpng",
- "//third_party/libjpeg",
- ]
- public_configs = [ ":vector_font_config" ]
- public_deps = [
- "//third_party/bounds_checking_function:libsec_shared",
- "//third_party/freetype:freetype_shared",
- "//base/hiviewdfx/frameworks/hilog_lite/featured:hilog_shared",
- "//third_party/cJSON:cjson_shared",
- "//foundation/graphic/lite/utils:litegraphicutils",
- "//foundation/graphic/lite/hals:graphic_hals",
- "//foundation/graphic/lite/services/ims:ims",
- "//foundation/graphic/lite/services/wms:wms_client",
- "//third_party/libjpeg:libjpeg",
- "//third_party/libpng:libpng",
- ]
- cflags = ["-Wall"]
- cflags_cc = cflags
-}
-
-lite_component("liteui") {
- features = [
- ":ui",
- ]
-}
diff --git a/frameworks/ui/include/common/typed_text.h b/frameworks/ui/include/common/typed_text.h
deleted file mode 100755
index ca13509..0000000
--- a/frameworks/ui/include/common/typed_text.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#ifndef GRAPHIC_LITE_TYPE_TEXT_H
-#define GRAPHIC_LITE_TYPE_TEXT_H
-
-#include "color.h"
-#include "components/ui_arc_label.h"
-#include "font/ui_font_header.h"
-#include "geometry2d.h"
-#include "graphic_config.h"
-
-namespace OHOS {
-/**
- * @brief typed text, support UTF-8
- */
-class TypedText : public HeapBase {
-public:
- static Point GetTextSize(const char* text, int16_t letterSpace, int16_t lineSpace, int16_t maxWidth);
-
- static uint32_t GetNextLine(const char* text, int16_t letterSpace, int16_t maxWidth);
-
- static uint16_t GetTextWidth(const char* text, uint32_t length, int16_t letterSpace);
-
- static void GetArcTextRect(Rect& rect,
- const char* text,
- const Point& arcCenter,
- int16_t letterSpace,
- UIArcLabel::TextOrientation orientation,
- const UIArcLabel::ArcTextInfo arcTextInfo);
-
- static uint32_t GetUTF8Next(const char* text, uint32_t i, uint32_t& j);
-
- static uint8_t GetUTF8OneCharacterSize(const char* str);
-
- static uint32_t GetByteIndexFromUTF8Id(const char* text, uint32_t utf8Id);
-
- static uint32_t GetUTF8CharacterSize(const char* text, uint32_t byteIndex = UINT32_MAX);
-
-private:
- static constexpr uint8_t UTF8_TO_UNICODE_SHIFT1 = 6;
- static constexpr uint8_t UTF8_TO_UNICODE_SHIFT2 = 12;
- static constexpr uint8_t UTF8_TO_UNICODE_SHIFT3 = 18;
- static constexpr uint8_t DRAW_ARC_QUADRANT_NUM = 4;
- static bool GetWrapPoint(const char* text, uint32_t& breakPoint);
-};
-} // namespace OHOS
-#endif // GRAPHIC_LITE_TYPE_TEXT_H
diff --git a/frameworks/ui/include/core/measure_manager.h b/frameworks/ui/include/core/measure_manager.h
deleted file mode 100755
index 9e3a267..0000000
--- a/frameworks/ui/include/core/measure_manager.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#ifndef GRAPHIC_LITE_MEASURE_MANAGER_H
-#define GRAPHIC_LITE_MEASURE_MANAGER_H
-
-#include "list.h"
-#include "components/ui_view.h"
-
-namespace OHOS {
-class MeasureManager : public HeapBase {
-public:
- static MeasureManager& GetInstance()
- {
- static MeasureManager instance;
- return instance;
- }
-
- void AddMeasureView(UIView* view);
-
- void DeleteMeasureView(UIView* view);
-
- void ReMeasureRect();
-
-private:
- MeasureManager() {}
-
- ~MeasureManager()
- {
- measureView_.Clear();
- }
-
- List measureView_;
-};
-} // namespace OHOS
-#endif // GRAPHIC_LITE_MEASURE_MANAGER_H
diff --git a/frameworks/ui/include/core/render_manager.h b/frameworks/ui/include/core/render_manager.h
deleted file mode 100755
index 51ac8ac..0000000
--- a/frameworks/ui/include/core/render_manager.h
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#ifndef GRAPHIC_LITE_RENDER_MANAGER_H
-#define GRAPHIC_LITE_RENDER_MANAGER_H
-
-#include "components/ui_view.h"
-#include "components/root_view.h"
-#include "common/task_manager.h"
-#include "geometry2d.h"
-#include "list.h"
-#include "sys_info.h"
-#if ENABLE_WINDOW
-#include "window/window.h"
-#endif
-
-namespace OHOS {
-static constexpr float MAX_FPS = 60.f;
-
-static constexpr int16_t SAMPLE_NUMBER = 100;
-
-static constexpr uint16_t MILLISECONDS_PER_SECOND = 1000;
-
-class RenderManager : public Task {
-public:
- static RenderManager& GetInstance()
- {
- static RenderManager instance;
- return instance;
- }
-
- virtual void Init() override;
-
-#if ENABLE_WINDOW
- Window* GetWindowById(int32_t id)
- {
- auto node = winList_.Begin();
- while (node != winList_.End()) {
- if (node->data_->GetWindowId() == id) {
- return node->data_;
- }
- node = node->next_;
- }
- return nullptr;
- }
-#endif
-
- virtual void Callback() override
- {
- RenderTask();
- }
-
- float GetFPS() const
- {
- return fps_;
- }
-
- void RegisterFPSChangedListener(SysInfo::OnFPSChangedListener* onFPSChangedListener)
- {
- onFPSChangedListener_ = onFPSChangedListener;
- needResetFPS_ = true;
- }
-
-#if ENABLE_WINDOW
- void AddToDisplay(Window* window);
-
- void RemoveFromDisplay(Window* window);
-#endif
-
-private:
- friend class RootView;
-
- RenderManager();
-
- ~RenderManager();
-
- void RenderTask();
-
- static void RenderRect(const Rect& rect, RootView* rootView);
-
-#if ENABLE_FPS_SUPPORT
- void UpdateFPS();
-
- void UpdateFPSByFixedTimeMethod();
-
- void UpdateFPSByAverageSamplingMethod();
-
- void UpdateFPSByPreciseSamplingMethod();
-
- void OnFPSChanged(float newFPS)
- {
- if (onFPSChangedListener_) {
- onFPSChangedListener_->OnFPSChanged(newFPS);
- }
- }
-#endif
-
- float fps_;
-
- bool needResetFPS_;
-
- SysInfo::OnFPSChangedListener* onFPSChangedListener_;
-
-#if ENABLE_WINDOW
- List winList_;
-#endif
-};
-} // namespace OHOS
-#endif // GRAPHIC_LITE_RENDER_MANAGER_H
diff --git a/frameworks/ui/include/default_resource/check_box_res.h b/frameworks/ui/include/default_resource/check_box_res.h
deleted file mode 100755
index ce38d36..0000000
--- a/frameworks/ui/include/default_resource/check_box_res.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#ifndef GRAPHIC_LITE_CHECK_BOX_RES_H
-#define GRAPHIC_LITE_CHECK_BOX_RES_H
-
-#include "image_info.h"
-#include "graphic_types.h"
-namespace OHOS {
-ImageInfo* GetCheckBoxOnInfo();
-ImageInfo* GetCheckBoxOffInfo();
-} // namespace OHOS
-#endif // GRAPHIC_LITE_CHECK_BOX_RES_H
diff --git a/frameworks/ui/include/default_resource/radio_button_res.h b/frameworks/ui/include/default_resource/radio_button_res.h
deleted file mode 100755
index 962e413..0000000
--- a/frameworks/ui/include/default_resource/radio_button_res.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#ifndef GRAPHIC_LITE_RADIO_BUTTON_RES_H
-#define GRAPHIC_LITE_RADIO_BUTTON_RES_H
-
-#include "image_info.h"
-#include "graphic_types.h"
-namespace OHOS {
-ImageInfo* GetRadioButtonOnInfo();
-ImageInfo* GetRadioButtonOffInfo();
-} // namespace OHOS
-#endif // GRAPHIC_LITE_RADIO_BUTTON_RES_H
\ No newline at end of file
diff --git a/frameworks/ui/include/default_resource/toggle_button_res.h b/frameworks/ui/include/default_resource/toggle_button_res.h
deleted file mode 100755
index 22a7bea..0000000
--- a/frameworks/ui/include/default_resource/toggle_button_res.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#ifndef GRAPHIC_LITE_TOGGLE_BUTTON_RES_H
-#define GRAPHIC_LITE_TOGGLE_BUTTON_RES_H
-
-#include "image_info.h"
-#include "graphic_types.h"
-namespace OHOS {
-ImageInfo* GetToggleButtonOnInfo();
-ImageInfo* GetToggleButtonOffInfo();
-} // namespace OHOS
-#endif // GRAPHIC_LITE_TOGGLE_BUTTON_RES_H
\ No newline at end of file
diff --git a/frameworks/ui/include/dfx/point_event_injector.h b/frameworks/ui/include/dfx/point_event_injector.h
deleted file mode 100755
index a4fa2d6..0000000
--- a/frameworks/ui/include/dfx/point_event_injector.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#ifndef GRAPHIC_LITE_POINT_EVENT_INJECTOR_H
-#define GRAPHIC_LITE_POINT_EVENT_INJECTOR_H
-
-#include "graphic_config.h"
-#include "list.h"
-
-#if ENABLE_DEBUG
-#include "dock/pointer_input_device.h"
-namespace OHOS {
-class PointEventInjector : public PointerInputDevice {
-public:
- PointEventInjector() : lastX_(0), lastY_(0), lastState_(0) {}
-
- ~PointEventInjector();
-
- bool SetPointEvent(const DeviceData& data);
-
- bool Read(DeviceData& data) override;
-private:
- List dataList_;
- int16_t lastX_;
- int16_t lastY_;
- uint16_t lastState_;
-
- constexpr static uint8_t MAX_LIST_LENGTH = 40;
-};
-}
-#endif // ENABLE_DEBUG
-#endif // GRAPHIC_LITE_POINT_EVENT_INJECTOR_H
-
diff --git a/frameworks/ui/include/dock/ohos/ohos_input_device.h b/frameworks/ui/include/dock/ohos/ohos_input_device.h
deleted file mode 100755
index 9c55867..0000000
--- a/frameworks/ui/include/dock/ohos/ohos_input_device.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#ifndef GRAPHIC_LITE_OHOS_INPUT_DEVICE_H
-#define GRAPHIC_LITE_OHOS_INPUT_DEVICE_H
-
-#include "dock/pointer_input_device.h"
-
-namespace OHOS {
-class OHOSInputDevice : public PointerInputDevice {
-public:
- OHOSInputDevice() {}
-
- virtual ~OHOSInputDevice() {}
-
- bool Read(DeviceData& data) override;
-};
-}
-#endif
diff --git a/frameworks/ui/include/draw/draw_arc.h b/frameworks/ui/include/draw/draw_arc.h
deleted file mode 100755
index f05f07d..0000000
--- a/frameworks/ui/include/draw/draw_arc.h
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#ifndef GRAPHIC_LITE_DRAW_ARC_H
-#define GRAPHIC_LITE_DRAW_ARC_H
-#include "common/image.h"
-#include "draw_image.h"
-#include "draw_utils.h"
-#include "graphic_math.h"
-#include "heap_base.h"
-#include "imgdecode/cache_manager.h"
-#include "style.h"
-
-namespace OHOS {
-struct ArcInfo {
- Point center;
- Point imgPos;
- uint16_t radius;
- int16_t startAngle;
- int16_t endAngle;
- const Image* imgSrc;
-};
-
-class DrawArc : public HeapBase {
-public:
- static DrawArc* GetInstance()
- {
- static DrawArc drawArc;
- return &drawArc;
- }
-
- void GetDrawRange(int16_t& start, int16_t& end);
-
- void Draw(ArcInfo& arcInfo, const Rect& mask, const Style& style, uint8_t opaScale, uint8_t cap);
-
-private:
- static constexpr uint8_t DRAW_ARC_QUADRANT_NUM = 4;
- static constexpr uint8_t ARC_QUADRANT_ONE = 0;
- static constexpr uint8_t ARC_QUADRANT_TWO = 1;
- static constexpr uint8_t ARC_QUADRANT_THREE = 2;
- static constexpr uint8_t ARC_QUADRANT_FOUR = 3;
- static constexpr int16_t IN_DEGREE_RANG = 0;
- static constexpr int16_t OUT_DEGREE_RANG = 1;
- static constexpr int16_t INTERSECT = 2;
- static constexpr int16_t DOUBLE_INTERSECT = 3;
-
- int16_t lineStart_;
- int16_t lineEnd_;
- int16_t outAntiStart_;
- int16_t outAntiEnd_;
- int16_t inAntiStart_;
- int16_t inAntiEnd_;
- int16_t y_;
- int16_t outRadius_;
- int16_t inRadius_;
- uint32_t ySqr_;
- uint32_t outRadiusSqr_;
- uint32_t inRadiusSqr_;
- bool isCircle_;
- uint32_t antiOutRadiusSqr_;
- uint32_t antiInRadiusSqr_;
-
- DrawArc()
- : lineStart_(0),
- lineEnd_(0),
- outAntiStart_(0),
- outAntiEnd_(0),
- inAntiStart_(0),
- inAntiEnd_(0),
- y_(0),
- outRadius_(0),
- inRadius_(0),
- ySqr_(0),
- outRadiusSqr_(0),
- inRadiusSqr_(0),
- isCircle_(false),
- antiOutRadiusSqr_(0),
- antiInRadiusSqr_(0)
- {
- }
- ~DrawArc() {}
- void DrawVerLine(const Point& begin,
- const Point& imgPos,
- const Rect& mask,
- int16_t len,
- const Style& style,
- uint8_t opaScale,
- const Image* imgSrc);
-
- void DrawHorLine(const Point& begin,
- const Point& imgPos,
- const Rect& mask,
- int16_t len,
- const Style& style,
- uint8_t opaScale,
- const Image* imgSrc);
-
- void DrawImg(const Point& imgPos,
- Rect& area,
- const Rect& invalidatedArea,
- const Style& style,
- uint8_t opaScale,
- const Image* imgSrc);
-
- int16_t GetDegreeRangeIntersectState(uint16_t degreeStart, uint16_t degreeEnd, uint16_t start, uint16_t end);
- uint16_t CalculateTanDegree(uint16_t x, uint16_t y);
- int16_t GetDrawAngle(int16_t angle);
- void DrawCircleNoEndpoint(ArcInfo& arcInfo, const Rect& mask, const Style& style, uint8_t opa, bool anti);
- void DrawAxisLine(ArcInfo& arcInfo, const Rect& mask, const Style& style, uint8_t opa);
- void DrawLineWithDegree(ArcInfo& arcInfo,
- int16_t start,
- int16_t end,
- int16_t y,
- const Rect& mask,
- const Style& style,
- uint8_t opaScale,
- uint8_t quadrant);
- int16_t DrawLineWithDegreeInner(ArcInfo& arcInfo,
- int16_t start,
- int16_t end,
- int16_t y,
- const Rect& mask,
- const Style& style,
- uint8_t opaScale,
- uint8_t quadrant);
-#if ENABLE_ANTIALIAS
- void DrawLineAnti(ArcInfo& arcInfo, const Rect& mask, const Style& style, uint8_t opa);
- void DrawPointAnti(ArcInfo& arcInfo, int16_t x, const Rect& mask, const Style& style, uint8_t antiOpa);
-#endif
- uint16_t GetDegreeInQuadrant(uint16_t degree, uint8_t quadrant);
- void SetArcInfo(ArcInfo& arcInfo, const Style& style);
-};
-} // namespace OHOS
-#endif // GRAPHIC_LITE_DRAW_ARC_H
diff --git a/frameworks/ui/include/draw/draw_curve.h b/frameworks/ui/include/draw/draw_curve.h
deleted file mode 100755
index e379456..0000000
--- a/frameworks/ui/include/draw/draw_curve.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#ifndef GRAPHIC_LITE_DRAW_CURVE_H
-#define GRAPHIC_LITE_DRAW_CURVE_H
-
-#include "color.h"
-#include "geometry2d.h"
-
-namespace OHOS {
-class DrawCurve : public HeapBase {
-public:
- static void DrawCubicBezier(const Point& start, const Point& control1, const Point& control2, const Point& end,
- const Rect& mask, int16_t width, const ColorType& color, OpacityType opacity);
-private:
- static constexpr uint16_t INTERPOLATION_RANGE = 1024;
-};
-} // namespace OHOS
-#endif // GRAPHIC_LITE_DRAW_CURVE_H
\ No newline at end of file
diff --git a/frameworks/ui/include/draw/draw_image.h b/frameworks/ui/include/draw/draw_image.h
deleted file mode 100755
index 5aa8264..0000000
--- a/frameworks/ui/include/draw/draw_image.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#ifndef GRAPHIC_LITE_DRAW_IMAGE_H
-#define GRAPHIC_LITE_DRAW_IMAGE_H
-
-#include
-#include
-#include "components/ui_view.h"
-#include "draw_utils.h"
-#include "geometry2d.h"
-
-namespace OHOS {
-class CacheEntry;
-
-class DrawImage : public HeapBase {
-public:
- DrawImage() {}
- ~DrawImage() {}
-
- static void DrawCommon(const Rect& coords, const Rect& mask,
- const ImageInfo* img, const Style& style, uint8_t opaScale);
-
- static void DrawCommon(const Rect& coords, const Rect& mask,
- const char* path, const Style& style, uint8_t opaScale);
-};
-} // namespace OHOS
-
-#endif // GRAPHIC_LITE_DRAW_IMAGE_H
diff --git a/frameworks/ui/include/draw/draw_label.h b/frameworks/ui/include/draw/draw_label.h
deleted file mode 100755
index cf67b08..0000000
--- a/frameworks/ui/include/draw/draw_label.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#ifndef GRAPHIC_LITE_DRAW_LABEL_H
-#define GRAPHIC_LITE_DRAW_LABEL_H
-
-#include "common/typed_text.h"
-#include "draw/draw_utils.h"
-#include "geometry2d.h"
-#include "heap_base.h"
-#include "style.h"
-
-namespace OHOS {
-class DrawLabel : public HeapBase {
-public:
- static void DrawTextOneLine(const LabelLineInfo& labelLine);
-
- static void DrawArcText(const Rect& mask, const char* text, const Point& arcCenter, uint8_t fontId,
- const UIArcLabel::ArcTextInfo arcTextInfo, UIArcLabel::TextOrientation orientation, const Style& style,
- uint8_t opaScale);
-
- static void DrawLetterWithRotate(const Rect& mask, uint8_t fontId, uint32_t letter, const Point& pos,
- int16_t rotateAngle, const ColorType& color, uint8_t opa);
-};
-} // namespace OHOS
-#endif // GRAPHIC_LITE_DRAW_LABEL_H
diff --git a/frameworks/ui/include/draw/draw_line.h b/frameworks/ui/include/draw/draw_line.h
deleted file mode 100755
index 5ebf38c..0000000
--- a/frameworks/ui/include/draw/draw_line.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#ifndef GRAPHIC_LITE_DRAW_LINE_H
-#define GRAPHIC_LITE_DRAW_LINE_H
-
-#include "color.h"
-#include "geometry2d.h"
-
-namespace OHOS {
-struct LineInfo {
- Point start;
- Point end;
- Point act;
- int16_t dx;
- int16_t sx;
- int16_t dy;
- int16_t sy;
- int16_t twoDx;
- int16_t twoDy;
- int16_t p;
- bool hor;
-};
-
-class DrawLine : public HeapBase {
-public:
- static void Draw(const Point& start, const Point& end, const Rect& mask,
- int16_t width, const ColorType& color, OpacityType opacity);
-
-private:
- static void DrawVerticalLine(const Point& start, const Point& end, const Rect& mask,
- int16_t width, const ColorType& color, OpacityType opacity);
- static void DrawHorizontalLine(const Point& start, const Point& end, const Rect& mask,
- int16_t width, const ColorType& color, OpacityType opacity);
- static void DrawObliqueLine(const Point& start, const Point& end, const Rect& mask,
- int16_t width, const ColorType& color, OpacityType opacity);
- static void DrawBresenhamLine(LineInfo& line, const Point& translate, bool fillGaps,
- const Rect& mask, const ColorType& color, OpacityType opacity);
- static void GenerateNormalVector(LineInfo& mainLine, int16_t& lineWidth, Point* pattern, int16_t maxLen);
- static void LineInit(LineInfo& line, const Point& start, const Point& end);
- static void GetNextPoint(LineInfo& line);
-};
-} // namespace OHOS
-#endif // GRAPHIC_LITE_DRAW_LINE_H
diff --git a/frameworks/ui/include/draw/draw_rect.h b/frameworks/ui/include/draw/draw_rect.h
deleted file mode 100755
index 5960246..0000000
--- a/frameworks/ui/include/draw/draw_rect.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#ifndef GRAPHIC_LITE_DRAW_RECT_H
-#define GRAPHIC_LITE_DRAW_RECT_H
-
-#include "components/ui_view.h"
-
-namespace OHOS {
-/** @brief Class for drawing rectangle. */
-class DrawRect : public HeapBase {
-public:
- DrawRect() {};
- ~DrawRect() {};
-
- static void Draw(const Rect& rect, const Rect& dirtyRect, const Style& style);
-
-private:
- static void DrawRectRadiusWithoutBorder(const Rect& rect, const Rect& dirtyRect, const Style& style);
- static void DrawRectBorderWithoutRadius(const Rect& rect, const Rect& dirtyRect, const Style& style);
- static void DrawRectRadiusEqualBorder(const Rect& rect, const Rect& dirtyRect, const Style& style);
- static void DrawRectRadiusSmallThanBorder(const Rect& rect, const Rect& dirtyRect, const Style& style);
- static void DrawRectRadiusBiggerThanBorder(const Rect& rect, const Rect& dirtyRect, const Style& style);
-
- static void DrawRectRadiusWithoutBorderCon1(const Rect& rect, const Rect& dirtyRect, const Style& style);
- static void DrawRectRadiusWithoutBorderCon2(const Rect& rect, const Rect& dirtyRect, const Style& style);
- static void DrawRectRadiusWithoutBorderCon3(const Rect& rect, const Rect& dirtyRect, const Style& style);
- static void DrawRectRadiusWithoutBorderCon4(const Rect& rect, const Rect& dirtyRect, const Style& style);
-
- static void DrawRectRadiusBiggerThanBorderCon1(const Rect& rect, const Rect& dirtyRect, const Style& style);
- static void DrawRectRadiusBiggerThanBorderCon2(const Rect& rect, const Rect& dirtyRect, const Style& style);
- static void DrawRectRadiusBiggerThanBorderCon3(const Rect& rect, const Rect& dirtyRect, const Style& style);
- static void DrawRectRadiusBiggerThanBorderCon4(const Rect& rect, const Rect& dirtyRect, const Style& style);
-};
-} // namespace OHOS
-#endif // GRAPHIC_LITE_DRAW_RECT_H
diff --git a/frameworks/ui/include/draw/draw_triangle.h b/frameworks/ui/include/draw/draw_triangle.h
deleted file mode 100755
index 1976733..0000000
--- a/frameworks/ui/include/draw/draw_triangle.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#ifndef GRAPHIC_LITE_DRAW_TRIANGLE_H
-#define GRAPHIC_LITE_DRAW_TRIANGLE_H
-
-#include "color.h"
-#include "geometry2d.h"
-
-namespace OHOS {
-class DrawTriangle : public HeapBase {
-public:
- static void Draw(const Point* points, uint8_t count, const Rect& mask, const ColorType& color, OpacityType opa);
-
- struct Edge {
- Point curPoint;
- Point dPoint;
- Point uPoint;
- int16_t eps;
- };
-
- static void SortVertexs(Point& p1, Point& p2, Point& p3);
-
- static void SortPoint(Point& p1, Point& p2);
-
- static void StepToNextPointOnEdge(Edge& edge);
-
- static Edge InitEdge(const Point& startP, const Point& endP);
-private:
- static constexpr uint8_t VERTEX_NUM = 3;
-};
-} // namespace OHOS
-#endif // GRAPHIC_LITE_DRAW_TRIANGLE_H
diff --git a/frameworks/ui/include/draw/draw_utils.h b/frameworks/ui/include/draw/draw_utils.h
deleted file mode 100755
index 0737f0b..0000000
--- a/frameworks/ui/include/draw/draw_utils.h
+++ /dev/null
@@ -1,225 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#ifndef GRAPHIC_LITE_DRAW_UTILS_H
-#define GRAPHIC_LITE_DRAW_UTILS_H
-
-#include "color.h"
-#include "common/text.h"
-#include "graphic_types.h"
-#include "common/screen_device_proxy.h"
-#include "geometry2d.h"
-#include "style.h"
-#include "transform.h"
-
-namespace OHOS {
-struct EdgeSides {
- int16_t left;
- int16_t right;
- int16_t top;
- int16_t bottom;
-};
-
-struct LabelLineInfo {
- Point& pos;
- Point& offset;
- const Rect& mask;
- const LabelRotation& rotate;
- int16_t lineHeight;
- uint16_t lineLength;
- uint8_t shapingId;
- uint8_t opaScale;
- const Style& style;
-
- const char* text;
- uint16_t length;
- uint16_t start;
- uint8_t fontId;
- UITextLanguageDirect direct;
- uint32_t* codePoints;
-};
-
-struct LabelLetterInfo {
- const Point& pos;
- Rect mask;
- const LabelRotation& rotate;
-
- const ColorType& color;
- OpacityType opa;
-
- const uint32_t& letter;
- UITextLanguageDirect direct;
- uint8_t fontId;
- uint8_t shapingId;
-};
-
-struct TransformInitState {
- float verticalU;
- float verticalV;
- float duHorizon;
- float dvHorizon;
- float duVertical;
- float dvVertical;
-};
-
-struct TriangleEdge {
- TriangleEdge() {}
- TriangleEdge(int16_t x1, int16_t y1, int16_t duInt, int16_t dvInt);
- ~TriangleEdge();
- float curX = 0.0f;
- float curY = 0.0f;
- float du = 0.0f;
- float dv = 0.0f;
-};
-struct TransformDataInfo {
- ImageHeader header;
- const uint8_t* data;
- uint8_t pxSize;
- BlurLevel blurLevel;
- TransformAlgorithm algorithm;
-};
-
-struct TriangleTransformDataInfo {
- const TransformDataInfo& info;
- Point p1;
- Point p2;
- Point p3;
- bool isRightPart;
- bool ignoreJunctionPoint;
-};
-
-struct TriangleScanInfo {
- int16_t yMin;
- int16_t yMax;
- TriangleEdge& edge1;
- TriangleEdge& edge2;
- ScreenBufferType* screenBuffer;
- Rect screenBufferRect;
- const ColorType& color;
- TransformInitState& init;
- uint16_t screenBufferWidth;
- uint8_t pixelSize;
- const int32_t srcLineWidth;
- const TransformDataInfo& info;
- const Rect& mask;
- bool isRightPart;
- bool ignoreJunctionPoint;
-};
-
-struct TrianglePartInfo {
- const Rect& mask;
- const TransformMap& transMap;
- const Point& position;
- TriangleEdge& edge1;
- TriangleEdge& edge2;
- int16_t yMin;
- int16_t yMax;
- const TransformDataInfo& info;
- const ColorType& color;
- bool isRightPart;
- bool ignoreJunctionPoint;
-};
-
-enum {
- IMG_SRC_VARIABLE,
- IMG_SRC_FILE,
- IMG_SRC_UNKNOWN,
-};
-
-enum PixelType {
- IMG_RGB565 = 2,
- IMG_RGB888 = 3,
- IMG_ARGB8888 = 4,
-};
-
-class DrawUtils : public HeapBase {
-public:
- static DrawUtils* GetInstance()
- {
- static DrawUtils instance;
- return &instance;
- }
-
- void DrawColorArea(const Rect& area, const Rect& mask, const ColorType& color, OpacityType opa) const;
-
- void DrawColorAreaBySides(const Rect& mask, const ColorType& color, OpacityType opa, const EdgeSides& sides) const;
-
- void DrawPixel(int16_t x, int16_t y, const Rect& mask, const ColorType& color, OpacityType opa) const;
-
- void DrawLetter(const LabelLetterInfo& letterInfo) const;
-
- void DrawImage(const Rect& area, const Rect& mask, const uint8_t* image, OpacityType opa, uint8_t pxByteSize) const;
-
- static void GetXAxisErrForJunctionLine(bool ignoreJunctionPoint, bool isRightPart, int32_t& xMinErr,
- int32_t& xMaxErr);
-
- static void GetTransformInitState(const TransformMap& transMap, const Point& position,
- const Rect& trans, TransformInitState& init);
-
- static void DrawTriangleTransform(const Rect& mask, const Point& position, const ColorType& color,
- const TransformMap& transMap, const TriangleTransformDataInfo& dataInfo);
-
- void DrawTransform(const Rect& mask, const Point& position, const ColorType& color, const TransformMap& transMap,
- const TransformDataInfo& dataInfo) const;
-
- void DrawTranspantArea(const Rect& rect, const Rect& mask);
-
- void DrawWithBuffer(const Rect& rect, const Rect& mask, const ColorType* colorBuf);
-
- static uint8_t GetPxSizeByColorMode(uint8_t colorMode);
-
- static uint8_t GetPxSizeByImageInfo(ImageInfo imageInfo);
-
-private:
-#if ENABLE_WINDOW && ENABLE_HARDWARE_ACCELERATION
- bool FillAreaWithHardware(const Rect& fillArea, const ColorType& color, const OpacityType& opa) const;
-#endif
- void FillAreaWithSoftWare(const Rect& fillArea, ScreenBufferType* mem, int16_t bufWidth, const ColorType& color,
- const OpacityType& opa) const;
-#if ENABLE_DMA2D
- bool FillAreaWithDMA2D(const Rect& fillArea, ScreenBufferType* mem, const ColorType& color,
- const OpacityType& opa, const DisplayDevice* disp) const;
- void BlendWithDMA2D(const Rect& fillArea, ScreenBufferType* dest, const Rect& srcArea, const ColorType* src,
- uint32_t srcColorMode, const OpacityType& opa, const DisplayDevice* disp,
- const ColorType& color = Color::White()) const;
-#endif
- void BlendWithSoftWare(ScreenBufferType* dest, const uint8_t* src, uint32_t length,
- OpacityType opa, uint8_t pxByteSize) const;
-
- static void DrawRectTransformNearestTrueColor(const Rect& mask, const Point& position, const ColorType& color,
- const TransformMap& transMap, const TransformDataInfo& dataInfo);
-
- using DrawTriangleTransformFuc = void(*)(const TriangleScanInfo& triangle);
-
- static void DrawTriangleTrueColorNearest(const TriangleScanInfo& triangle);
-
- static void DrawTriangleAlphaBilinear(const TriangleScanInfo& triangle);
-
- static void DrawTriangleTrueColorBilinear565(const TriangleScanInfo& triangle);
-
- static void DrawTriangleTrueColorBilinear888(const TriangleScanInfo& triangle);
-
- static void DrawTriangleTrueColorBilinear8888(const TriangleScanInfo& triangle);
-
- inline static void StepToNextLine(TriangleEdge& edg1, TriangleEdge& edg2);
-
- static void DrawTriangleTransformPart(const TrianglePartInfo& part);
-
- static OpacityType GetPxAlphaForAlphaImg(const TransformDataInfo& dataInfo, const Point& point);
-
- void FillArea(const Rect& rect, const Rect& mask, bool isTransparent, const ColorType* colorBuf);
-};
-} // namespace OHOS
-#endif // GRAPHIC_LITE_DRAW_UTILS_H
diff --git a/frameworks/ui/include/font/ui_base_font.h b/frameworks/ui/include/font/ui_base_font.h
deleted file mode 100755
index b54b3fa..0000000
--- a/frameworks/ui/include/font/ui_base_font.h
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#ifndef UI_BASE_FONT_H
-#define UI_BASE_FONT_H
-
-#include "graphic_config.h"
-#include "font/ui_dynamic_font.h"
-#include "font/ui_font_cache.h"
-#include "font/ui_text_manager.h"
-#include
-
-namespace OHOS {
-class UIBaseFont {
-public:
- UIBaseFont(const UIBaseFont&) = delete;
- UIBaseFont& operator=(const UIBaseFont&) = delete;
- UIBaseFont(UIBaseFont&&) noexcept = delete;
- UIBaseFont& operator=(UIBaseFont&&) noexcept = delete;
-
- virtual bool IsVectorFont() const = 0;
-
- virtual int8_t SetPsramMemory(uintptr_t psramAddr, uint32_t psramLen) = 0;
-
- /**
- * @brief Set the Font Path
- *
- * @param dpath
- * @param spath
- * @return int8_t
- */
- virtual int8_t SetFontPath(const char* dpath) = 0;
-
- virtual int8_t SetCurrentFontId(uint8_t fontId, uint8_t size) = 0;
-
- virtual uint16_t GetHeight() = 0;
-
- uint8_t GetCurrentFontId() const;
-
- virtual uint8_t GetFontId(const char* ttfName, uint8_t size) const = 0;
-
- virtual uint16_t GetWidth(uint32_t unicode, uint8_t shapingId) = 0;
-
- virtual uint8_t* GetBitmap(uint32_t unicode, GlyphNode& glyphNode, uint8_t shapingFont) = 0;
-
- virtual int8_t GetCurrentFontHeader(FontHeader& fontHeader) = 0;
-
- virtual int8_t GetGlyphNode(uint32_t unicode, GlyphNode& glyphNode, bool isGlyph) = 0;
-
- virtual uint8_t GetFontWeight(uint8_t fontId) const = 0;
- virtual uint8_t RegisterFontInfo(const char* ttfName) = 0;
- virtual uint8_t UnregisterFontInfo(const char* ttfName) = 0;
-
-protected:
- static constexpr uint8_t FONT_INVAILD_TTF_ID = 0xFF;
- static constexpr uint8_t FONT_ID_MAX = 0xFF;
- static constexpr uint8_t TTF_NAME_LEN_MAX = 128;
- uint8_t fontId_;
- uintptr_t ramAddr_;
- uint32_t ramLen_;
- UIBaseFont() : fontId_(0), ramAddr_(0), ramLen_(0) {}
- virtual ~UIBaseFont() {}
-};
-} // namespace OHOS
-#endif /* UI_BASE_FONT_H */
\ No newline at end of file
diff --git a/frameworks/ui/include/font/ui_dynamic_font.h b/frameworks/ui/include/font/ui_dynamic_font.h
deleted file mode 100755
index c8275de..0000000
--- a/frameworks/ui/include/font/ui_dynamic_font.h
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#ifndef UI_DYNAMIC_FONT_H
-#define UI_DYNAMIC_FONT_H
-
-#include "font/ui_font_header.h"
-
-namespace OHOS {
-constexpr uint8_t RADIX_TREE_BITS = 4;
-constexpr uint8_t RADIX_SHIFT_START = 32 - RADIX_TREE_BITS;
-constexpr uint32_t RADIX_TREE_SLOT_NUM = 1 << RADIX_TREE_BITS;
-constexpr uint32_t RADIX_TREE_MASK = RADIX_TREE_SLOT_NUM - 1;
-
-constexpr uint8_t FONT_HASH_SHIFT = 3;
-constexpr uint8_t FONT_HASH_NR = 1 << FONT_HASH_SHIFT;
-constexpr uint32_t FONT_HASH_MASK = FONT_HASH_NR - 1;
-constexpr uint8_t UNICODE_HASH_SHIFT = 6;
-constexpr uint8_t UNICODE_HASH_NR = 1 << UNICODE_HASH_SHIFT;
-constexpr uint32_t UNICODE_HASH_MASK = UNICODE_HASH_NR - 1;
-constexpr uint8_t NODE_HASH_SHIFT = 4;
-constexpr uint8_t NODE_HASH_NR = 1 << NODE_HASH_SHIFT;
-
-class DynamicFont {
-public:
- using CacheType = GlyphNode[FONT_HASH_NR][UNICODE_HASH_NR][NODE_HASH_NR];
- using CacheState = uint8_t[FONT_HASH_NR][UNICODE_HASH_NR];
-
- struct IndexNode {
- uint16_t stubs[RADIX_TREE_SLOT_NUM];
- };
-
- DynamicFont();
-
- DynamicFont(const DynamicFont&) = delete;
-
- DynamicFont& operator=(const DynamicFont&) = delete;
-
- ~DynamicFont();
-
- int32_t GetRamUsedLen() const;
-
- int8_t GetFontVersion(char* version, uint8_t len) const;
-
- int16_t GetFontHeight() const;
-
- int16_t GetFontWidth(uint32_t unicode);
-
- const struct FontHeader* GetCurrentFontHeader() const;
-
- const struct GlyphNode* GetGlyphNode(uint32_t unicode);
-
- int8_t GetBitmap(uint32_t unicode, uint8_t* bitmap);
-
- int8_t SetRamBuffer(uintptr_t ramAddr);
-
- int8_t SetFile(int32_t fp, uint32_t start);
-
- int8_t SetCurrentFontId(uint8_t fontId);
-
-private:
- int8_t GlyphNodeCacheInit();
- struct GlyphNode* GetNodeFromCache(uint32_t unicode);
- struct GlyphNode* GetNodeCacheSpace(uint32_t unicode);
- struct GlyphNode* GetNodeFromFile(uint32_t unicode);
- uint32_t AlignUp(uint32_t addr, uint32_t align)
- {
- return (((addr + (1 << align)) >> align) << align);
- }
-
- struct BinHeader binHeader_;
- uint8_t fontNum_;
- uint32_t start_;
- uint32_t fontHeaderSectionStart_;
- uint32_t fontIndexSectionStart_;
- uint32_t curFontIndexSectionStart_;
- uint32_t glyphNodeSectionStart_;
- uint32_t curGlyphNodeSectionStart_;
- uint32_t bitMapSectionStart_;
- uint32_t curBitMapSectionStart_;
-
- uint8_t* ramAddr_;
- uint32_t ramUsedLen_;
- struct FontHeader* fontHeaderCache_;
- uint8_t* indexCache_;
- uint8_t* curIndexCache_;
-
- CacheType* nodeCache_;
- CacheState* cacheStatus_;
-
- int32_t fp_;
- uint8_t fontId_;
- struct FontHeader* curFontHeader_;
- struct GlyphNode* curGlyphNode_;
- uint16_t fontIdx_;
-
- bool isRamSet_;
- bool isFileSet_;
- bool isFontIdSet_;
-};
-} // namespace OHOS
-#endif /* UI_DYNAMIC_FONT_H */
diff --git a/frameworks/ui/include/font/ui_font_allocator.h b/frameworks/ui/include/font/ui_font_allocator.h
deleted file mode 100755
index fb37224..0000000
--- a/frameworks/ui/include/font/ui_font_allocator.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#ifndef UI_FONT_ALLOCATOR_H
-#define UI_FONT_ALLOCATOR_H
-
-#include
-
-namespace OHOS {
-class UIFontAllocator {
- static constexpr uint8_t MEM_ALIGNMENT = 4;
-
- struct Chunk {
- uint32_t next;
- uint32_t prev;
- bool used;
- };
-
-public:
- UIFontAllocator();
-
- ~UIFontAllocator();
-
- void SetRamAddr(uint8_t* ram, uint32_t size);
-
- void SetMinChunkSize(uint32_t size);
-
- void* Allocate(uint32_t size);
-
- void Free(void* addr);
-
-private:
- uint32_t AlignSize(uint32_t size)
- {
- return (size + MEM_ALIGNMENT - 1U) & ~(MEM_ALIGNMENT - 1U);
- }
- void CombineFree(Chunk* cache);
-
- uint8_t* ram_;
- uint32_t ramSize_;
- uint32_t freeSize_;
- uint32_t minSize_;
- struct Chunk* end_;
- struct Chunk* free_;
-};
-} // namespace OHOS
-#endif /* UI_FONT_ALLOCATOR_H */
\ No newline at end of file
diff --git a/frameworks/ui/include/font/ui_font_cache.h b/frameworks/ui/include/font/ui_font_cache.h
deleted file mode 100755
index 1a3ae55..0000000
--- a/frameworks/ui/include/font/ui_font_cache.h
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#ifndef UI_FONT_CACHE_H
-#define UI_FONT_CACHE_H
-
-#include "ui_font_allocator.h"
-
-namespace OHOS {
-class UIFontCache {
-public:
- static constexpr uint8_t FONT_CACHE_HASH_NR = 32;
- static constexpr uint32_t FONT_CACHE_MIN_SIZE = 20 * 20;
- struct ListHead {
- ListHead* prev;
- ListHead* next;
- };
- struct Bitmap {
- ListHead hashHead;
- ListHead lruHead;
- uint8_t fontId;
- uint32_t unicode;
- uint8_t data[];
- };
-
- UIFontCache(uint8_t* ram, uint32_t size);
-
- ~UIFontCache();
-
- uint8_t* GetSpace(uint8_t fontId, uint32_t unicode, uint32_t size);
-
- void PutSpace(uint8_t* addr);
-
- uint8_t* GetBitmap(uint8_t fontId, uint32_t unicode);
-
-private:
- void UpdateLru(Bitmap* bitmap);
- void ListInit(ListHead* head)
- {
- head->prev = head;
- head->next = head;
- }
- void ListAdd(ListHead* node, ListHead* head)
- {
- head->next->prev = node;
- node->next = head->next;
- node->prev = head;
- head->next = node;
- }
- void ListDel(ListHead* node)
- {
- node->next->prev = node->prev;
- node->prev->next = node->next;
- }
-
- UIFontAllocator allocator_;
- ListHead* hashTable_;
- ListHead lruList_;
-};
-} // namespace OHOS
-#endif /* UI_FONT_CACHE_H */
\ No newline at end of file
diff --git a/frameworks/ui/include/font/ui_font_vector.h b/frameworks/ui/include/font/ui_font_vector.h
deleted file mode 100755
index 6c5cd34..0000000
--- a/frameworks/ui/include/font/ui_font_vector.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#ifndef UI_FONT_VECTOR_H
-#define UI_FONT_VECTOR_H
-
-#include "graphic_config.h"
-#if ENABLE_VECTOR_FONT
-#include "ft2build.h"
-#include "freetype/freetype.h"
-#include "font/ui_base_font.h"
-#include "font/ui_font_cache.h"
-#include "font/ui_text_manager.h"
-#include
-
-namespace OHOS {
-class UIFontVector : public UIBaseFont {
-public:
- UIFontVector();
-
- ~UIFontVector();
- UIFontVector(const UIFontVector&) = delete;
- UIFontVector& operator=(const UIFontVector&) noexcept = delete;
-
- bool IsVectorFont() const;
- int8_t SetPsramMemory(uintptr_t psramAddr, uint32_t psramLen);
- int8_t SetFontPath(const char* dpath);
- int8_t SetCurrentFontId(uint8_t fontId, uint8_t size = 0);
- uint16_t GetHeight();
- uint8_t GetFontId(const char* ttfName, uint8_t size = 0) const;
- uint16_t GetWidth(uint32_t unicode, uint8_t shapingId);
- uint8_t* GetBitmap(uint32_t unicode, GlyphNode& glyphNode, uint8_t shapingFont);
- int8_t GetCurrentFontHeader(FontHeader& fontHeader);
- int8_t GetGlyphNode(uint32_t unicode, GlyphNode& glyphNode, bool isGlyph = false);
- uint8_t GetFontWeight(uint8_t fontId) const;
-private:
- const void SetFace(FT_Face ftface, uint32_t unicode) const;
- uint32_t GetKey(uint8_t fontId, uint32_t size);
- static constexpr uint8_t FONT_BPP_8 = 8;
- const char* fontInfo_[FONT_ID_MAX + 1] = {0};
- std::string ttfDir_;
- FT_Library ftLibrary_;
- FT_Face ftFaces_[FONT_ID_MAX + 1] = {0};
- bool freeTypeInited_;
- uint32_t key_ = 0;
-
- uint8_t RegisterFontInfo(const char* ttfName);
- uint8_t UnregisterFontInfo(const char* ttfName);
- const char* GetFontTtfName(uint8_t fontId) const;
- UIFontCache* bitmapCache_;
-};
-} // namespace OHOS
-#endif /* ENABLE_VECTOR_FONT */
-#endif /* UI_FONT_VECTOR_H */
diff --git a/frameworks/ui/include/font/ui_muti_font_manager.h b/frameworks/ui/include/font/ui_muti_font_manager.h
deleted file mode 100755
index 671afa4..0000000
--- a/frameworks/ui/include/font/ui_muti_font_manager.h
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#ifndef UI_MUTI_FONT_MANAGER_H
-#define UI_MUTI_FONT_MANAGER_H
-
-#include "graphic_config.h"
-
-#if ENABLE_MUTI_FONT
-namespace OHOS {
-class UIMutiFontManager {
-public:
- UIMutiFontManager(const UIMutiFontManager&) = delete;
- UIMutiFontManager& operator=(const UIMutiFontManager&) = delete;
- UIMutiFontManager(UIMutiFontManager&&) noexcept = delete;
- UIMutiFontManager& operator=(UIMutiFontManager&&) noexcept = delete;
-
- /**
- * @brief Get the Instance object
- *
- * @return UIMutiFontManager*
- */
- static UIMutiFontManager* GetInstance()
- {
- static UIMutiFontManager instance;
- return &instance;
- }
-
- void ClearSearchFontList();
- int8_t SetSearchFontList(uint8_t fontListId, uint8_t* fontIds, uint8_t size);
- int8_t GetSearchFontList(uint8_t fontListId, uint8_t** fontIds);
- bool IsNeedShaping(char* text, uint8_t& ttfId);
- uint8_t GetShapingFontId(char* text, uint8_t fontId, uint8_t& ttfId);
-
-private:
- /**
- * @brief Construct a new UIMutiFontManager object
- *
- */
- UIMutiFontManager();
-
- /**
- * @brief Destroy the UIMutiFontManager object
- *
- */
- ~UIMutiFontManager();
- int8_t AddNewFont(uint8_t fontListId, uint8_t* fontIds, int8_t size, uint8_t fontId);
- int8_t UpdateFont(uint8_t fontListId, uint8_t* fontIds, uint8_t size);
- int8_t IsShapingLetter(uint32_t unicode, uint8_t& ttfId)
- {
- // arbic
- if (unicode <= 0x06FF && unicode >= 0x0600) {
- ttfId = arbicTtfId_;
- return true;
- }
- // thai
- if (unicode <= 0x0E7F && unicode >= 0x0E00) {
- ttfId = thaiTtfId_;
- return true;
- }
- // Devanagari
- if (unicode <= 0x097F && unicode >= 0x0900) {
- ttfId = devanagariTtfId_;
- return true;
- }
- // Hebrew
- if (unicode <= 0x05FF && unicode >= 0x0590) {
- ttfId = hebrewTtfId_;
- return true;
- }
- // Myanmar
- if (unicode <= 0x109F && unicode >= 0x1000) {
- ttfId = myanmarTtfId_;
- return true;
- }
- return false;
- }
-
- struct FontIdNode {
- uint8_t* fontIds = nullptr;
- int8_t size = 0;
- };
- static constexpr uint8_t MAX_LIST_NUM = 20;
- static constexpr uint8_t DEFAULT_SHAPING_ID = 1;
- static constexpr const char* ARABIC_LANG = "Arabic";
- static constexpr const char* THAI_LANG = "Thai";
- static constexpr const char* MYAN_LANG = "Myanmar";
- static constexpr const char* DVCARI_LANG = "Devanagari";
- static constexpr const char* HBREW_LANG = "Hebrew";
- uint8_t arbicTtfId_;
- uint8_t thaiTtfId_;
- uint8_t myanmarTtfId_;
- uint8_t devanagariTtfId_;
- uint8_t hebrewTtfId_;
- uint8_t topIndex_;
- uint8_t* fontIdIndex_;
- FontIdNode fontNodes_[MAX_LIST_NUM];
-};
-} // namespace OHOS
-#endif
-#endif
\ No newline at end of file
diff --git a/frameworks/ui/include/font/ui_text_manager.h b/frameworks/ui/include/font/ui_text_manager.h
deleted file mode 100755
index 75e8c70..0000000
--- a/frameworks/ui/include/font/ui_text_manager.h
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#ifndef UI_TEXT_MANAGER_H
-#define UI_TEXT_MANAGER_H
-
-#include "font/ui_font_header.h"
-constexpr uint32_t TEXT_UTF8_DATA_MAX = 153600;
-namespace OHOS {
-class TextManager {
-public:
- TextManager();
- TextManager(const TextManager&) = delete;
- TextManager& operator=(const TextManager&) = delete;
-
- ~TextManager();
-
- uint32_t GetRamUsedLen() const;
-
- uint32_t GetBinarySize() const;
-
- int8_t GetTextVersion(char* version, uint8_t len) const;
-
- struct UITextLanguageTextParam* GetTextParam(uint16_t textId) const;
-
- int8_t GetTextUtf8(uint16_t textId, uint8_t** utf8Addr, uint16_t& utf8Len) const;
-
- int8_t
- GetWildCardStaticStr(uint16_t textId, UITextWildcardStaticType type, uint8_t** strAddr, uint16_t& strLen) const;
-
- int8_t SetFile(int32_t fp, uint32_t start);
-
- int8_t SetRamBuffer(uintptr_t addr);
-
- int8_t SetCurrentLangId(uint8_t langId);
-
- int8_t GetLocaleByLangId(uint8_t langId, char** isoStr, uint8_t& len) const;
-
- int8_t GetCodePoints(uint16_t textId, uint32_t** codePoints, uint16_t& codePointsNum) const;
-
-private:
- void CacheInit(void);
- uint32_t getFileLen(int32_t fp, uint32_t offset);
- uint32_t AlignUp(uint32_t addr, uint32_t align)
- {
- return (((addr + (1 << align)) >> align) << align);
- }
-
- int32_t fp_;
- uint8_t langId_;
-
- struct LangBinHeader langBinHeader_;
- struct LangTexsTableHeader langTextHeader_;
- struct TextIsoHeader textIsoHeader_;
-
- uint32_t start_;
- uint32_t end_;
- uint32_t ttfBinStart_;
- uint32_t lineBrkStart_;
- uint32_t lineBrkEnd_;
- uint32_t textParamStart_;
- uint32_t textUtf8ParamStart_;
- uint32_t textUtf8Start_;
- uint32_t textCodepointsStart_;
-
- uint8_t* ramAddr_;
- uint32_t ramUsedLen_;
-
- struct UITextLanguageTextParam* textParamCache_;
- struct LangTexsUtf8Param* textUtf8ParamCache_;
- struct TextIsoParam* textIsoParmCache_;
- uint8_t* textUtf8Cache_;
- uint32_t* textCodepointsCache_;
- char* textIsoUtf8Cache_;
-
- bool isRamSet_;
- bool isFileSet_;
- bool isLangSet_;
-
- bool SetIsoCache();
-};
-} // namespace OHOS
-#endif
diff --git a/frameworks/ui/include/imgdecode/cache_manager.h b/frameworks/ui/include/imgdecode/cache_manager.h
deleted file mode 100755
index bc18bec..0000000
--- a/frameworks/ui/include/imgdecode/cache_manager.h
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#ifndef GRAPHIC_LITE_CACHE_MANAGER_H
-#define GRAPHIC_LITE_CACHE_MANAGER_H
-
-#include "file_img_decoder.h"
-
-namespace OHOS {
-class CacheEntry : public HeapBase {
-public:
- CacheEntry() : dsc_{0}, life_(0) {}
-
- ~CacheEntry() {}
-
- ImageSrcType GetImgSrcType() const
- {
- return dsc_.srcType;
- }
-
- const uint8_t* GetImgData() const;
-
- ImageHeader GetImgHeader() const
- {
- return dsc_.imgInfo.header;
- }
-
- ImageInfo GetImageInfo() const
- {
- return dsc_.imgInfo;
- }
-
- RetCode ReadLine(const Point& start, int16_t bufSize, uint8_t* buf);
-
- bool InCache() const
- {
- return dsc_.inCache_;
- }
-
-private:
- static constexpr uint16_t MAX_SRC_LENGTH = 4096;
-
- friend class CacheManager;
-
- void Clear();
- void ClearSrc();
- RetCode SetSrc(const char* path);
-
- FileImgDecoder::ImgResDsc dsc_;
- int32_t life_;
-};
-
-class CacheManager : public HeapBase {
-public:
- static CacheManager& GetInstance()
- {
- static CacheManager instance;
- return instance;
- }
-
- RetCode Init(uint16_t size);
-
- uint16_t GetSize()
- {
- return size_;
- }
-
- RetCode Open(const char* path, const Style& style, CacheEntry& entry);
-
- RetCode Close(const char* path);
-
- RetCode Reset();
-
- RetCode ReadToCache(CacheEntry& entry);
-
- bool GetImageHeader(const char* path, ImageHeader& header);
-
-private:
- static constexpr uint8_t MAX_CACHE_ENTRY_NUM = 32;
-
- CacheManager() : size_(0), entryArr_(nullptr){}
-
- ~CacheManager() {}
-
- void Clear(CacheEntry& entry);
-
- void AgingAll(int32_t time = AGING_INTERVAL);
-
- RetCode GetIndex(const char* src, uint16_t& hittedIndex);
-
- RetCode SelectEntryToReplace(uint16_t& selectedIndex);
-
- RetCode TryDecode(const char* path, const Style& style, CacheEntry& entry);
-
- uint16_t size_;
- CacheEntry* entryArr_;
- static constexpr uint8_t AGING_INTERVAL = 1;
- static constexpr uint8_t LIFE_GAIN_INTERVAL = 1;
- static constexpr uint16_t LIFE_LIMIT = 1000;
-};
-} // namespace OHOS
-
-#endif
\ No newline at end of file
diff --git a/frameworks/ui/include/imgdecode/file_img_decoder.h b/frameworks/ui/include/imgdecode/file_img_decoder.h
deleted file mode 100755
index ade75f1..0000000
--- a/frameworks/ui/include/imgdecode/file_img_decoder.h
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#ifndef GRAPHIC_LITE_FILE_IMG_DECODER_H
-#define GRAPHIC_LITE_FILE_IMG_DECODER_H
-
-#include "draw/draw_image.h"
-#include "draw/draw_utils.h"
-
-namespace OHOS {
-constexpr uint8_t BYTE_TO_BIT_SHIFT = 3;
-constexpr uint8_t ONE_BIT_LEN_IN_BIT = 1;
-constexpr uint8_t TWO_BIT_LEN_IN_BIT = 2;
-constexpr uint8_t FOUR_BIT_LEN_IN_BIT = 4;
-constexpr uint8_t BYTE_LEN_IN_BIT = 8;
-
-enum class RetCode {
- OK,
- FAIL,
-};
-
-class FileImgDecoder : public HeapBase {
-public:
- static FileImgDecoder& GetInstance()
- {
- static FileImgDecoder instance;
- return instance;
- }
-
- struct ImgResDsc {
- FileImgDecoder* decoder;
- const char* path;
- ImageInfo imgInfo;
- uint32_t timeToOpen;
- int32_t fd;
- ImageSrcType srcType;
- bool inCache_;
- };
-
- RetCode Open(ImgResDsc& dsc);
-
- RetCode Close(ImgResDsc& dsc);
-
- RetCode GetHeader(ImgResDsc& dsc);
-
- RetCode ReadLine(ImgResDsc& dsc, const Point& start, int16_t len, uint8_t* buf);
-
- RetCode ReadToCache(ImgResDsc& dsc);
-
-private:
- FileImgDecoder() {};
- ~FileImgDecoder() {};
-
- bool IsImgValidMode(uint8_t colorMode)
- {
- if (colorMode == RGB565 || colorMode == RGB888 || colorMode == ARGB8888) {
- return true;
- } else {
- return false;
- }
- }
- RetCode ReadLineTrueColor(ImgResDsc& dsc, const Point& start, int16_t len, uint8_t* buf);
-
- FileImgDecoder(const FileImgDecoder&) = delete;
- FileImgDecoder& operator=(const FileImgDecoder&) = delete;
- FileImgDecoder(FileImgDecoder&&) = delete;
- FileImgDecoder& operator=(FileImgDecoder&&) = delete;
-};
-}
-#endif
\ No newline at end of file
diff --git a/frameworks/ui/include/window/window_impl.h b/frameworks/ui/include/window/window_impl.h
deleted file mode 100755
index 43137a8..0000000
--- a/frameworks/ui/include/window/window_impl.h
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#ifndef GRAPHIC_LITE_WINDOW_IMPL_H
-#define GRAPHIC_LITE_WINDOW_IMPL_H
-
-#include "client/iwindow.h"
-#include "components/root_view.h"
-#include "window/window.h"
-#include "dock/screen_device.h"
-
-namespace OHOS {
-class WindowImpl : public Window {
-public:
- WindowImpl();
- virtual ~WindowImpl();
-
- void BindRootView(RootView* rootView) override;
- void UnbindRootView() override;
- RootView* GetRootView() override;
- Rect GetRect() override;
-
- void Show() override;
- void Hide() override;
- void MoveTo(int16_t x, int16_t y) override;
- void Resize(int16_t width, int16_t height) override;
- void RaiseToTop() override;
- void LowerToBottom() override;
-
- int32_t GetWindowId() override;
-
- void Render();
- void Update();
- void Flush();
- bool Create(const WindowConfig& config);
- void Destory();
- void AddToDisplay();
- void RemoveFromDisplay();
-
-private:
- void UpdateHalDisplayBuffer();
-
- RootView* rootView_;
- IWindow* iWindow_;
- WindowConfig config_;
- bool isShow_;
- AllocationInfo gfxAlloc_;
-};
-}
-#endif
\ No newline at end of file
diff --git a/frameworks/ui/src/animator/animator.cpp b/frameworks/ui/src/animator/animator.cpp
deleted file mode 100755
index 2e24c79..0000000
--- a/frameworks/ui/src/animator/animator.cpp
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#include "animator/animator.h"
-
-#include "common/task_manager.h"
-#include "hal_tick.h"
-
-namespace OHOS {
-void Animator::Start()
-{
- SetState(START);
- runTime_ = 0;
- lastRunTime_ = 0;
-}
-
-void Animator::Stop()
-{
- SetState(STOP);
- if (callback_ != nullptr) {
- callback_->OnStop(*view_);
- }
-}
-
-void Animator::Pause()
-{
- SetState(PAUSE);
-}
-
-void Animator::Resume()
-{
- SetState(START);
- lastRunTime_ = HALTick::GetInstance().GetTime();
-}
-
-void Animator::Run()
-{
- if (lastRunTime_ == 0) {
- lastRunTime_ = HALTick::GetInstance().GetTime();
- }
-
- uint32_t elepse = HALTick::GetInstance().GetElapseTime(lastRunTime_);
-
- runTime_ = (UINT32_MAX - elepse > runTime_) ? (runTime_ + elepse) : time_;
- lastRunTime_ = HALTick::GetInstance().GetTime();
- if (callback_ != nullptr) {
- callback_->Callback(view_);
- }
-}
-
-void AnimatorManager::Init()
-{
- Task::Init();
-}
-
-void AnimatorManager::Add(Animator* animator)
-{
- if (animator == nullptr) {
- return;
- }
-
- list_.PushBack(animator);
-}
-
-void AnimatorManager::Remove(const Animator* animator)
-{
- if (animator == nullptr) {
- return;
- }
- ListNode* pos = list_.Begin();
- while (pos != list_.End()) {
- if (pos->data_ == animator) {
- list_.Remove(pos);
- return;
- }
- pos = pos->next_;
- }
-}
-
-void AnimatorManager::AnimatorTask()
-{
- ListNode* pos = list_.Begin();
- Animator* animator = nullptr;
-
- while (pos != list_.End()) {
- animator = pos->data_;
- if (animator->GetState() == Animator::START) {
- if (animator->IsRepeat() || animator->GetRunTime() <= animator->GetTime()) {
- animator->Run();
- } else {
- animator->Stop();
- }
- }
-
- pos = pos->next_;
- }
-}
-}
diff --git a/frameworks/ui/src/animator/easing_equation.cpp b/frameworks/ui/src/animator/easing_equation.cpp
deleted file mode 100755
index 7e3c474..0000000
--- a/frameworks/ui/src/animator/easing_equation.cpp
+++ /dev/null
@@ -1,291 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#include "graphic_math.h"
-#include "animator/easing_equation.h"
-
-namespace OHOS {
-double EasingEquation::overshoot_ = 1.7; // The empirical value commonly used in easing equation
-
-void EasingEquation::SetBackOvershoot(double overshoot)
-{
- if (overshoot >= OVERSHOOT_MIN && overshoot <= OVERSHOOT_MAX) {
- overshoot_ = overshoot;
- }
-}
-
-int16_t EasingEquation::BackEaseIn(int16_t startPos, int16_t endPos, uint16_t curTime, uint16_t durationTime)
-{
- int16_t pos = endPos;
- if (curTime < durationTime) {
- double t = -(static_cast(curTime) / durationTime);
- double x = -t * t * ((overshoot_ + 1) * t + overshoot_);
- pos = static_cast((x * (static_cast(endPos) - startPos)) + startPos);
- }
-
- return pos;
-}
-
-int16_t EasingEquation::BackEaseOut(int16_t startPos, int16_t endPos, uint16_t curTime, uint16_t durationTime)
-{
- int16_t pos = endPos;
- if (curTime < durationTime) {
- double t = static_cast(curTime) / durationTime;
- t -= 1.0;
- double x = t * t * ((overshoot_ + 1) * t + overshoot_) + 1;
- pos = static_cast((x * (static_cast(endPos) - startPos)) + startPos);
- }
-
- return pos;
-}
-
-int16_t EasingEquation::BackEaseInOut(int16_t startPos, int16_t endPos, uint16_t curTime, uint16_t durationTime)
-{
- int16_t pos;
- uint16_t halfTime = durationTime >> 1;
- int16_t halfStep = (endPos >> 1) + (startPos >> 1);
- if (curTime < halfTime) {
- pos = BackEaseIn(startPos, halfStep, curTime, halfTime);
- } else {
- pos = BackEaseOut(halfStep, endPos, curTime - halfTime, halfTime);
- }
-
- return pos;
-}
-
-/* 1 - sqrt(1 - t^2) */
-int16_t EasingEquation::CircEaseIn(int16_t startPos, int16_t endPos, uint16_t curTime, uint16_t durationTime)
-{
- int16_t pos = endPos;
- if (curTime < durationTime) {
- int32_t t = (curTime << INTERPOLATION_RANGE_OFFSET) / durationTime;
- uint32_t x = INTERPOLATION_RANGE - Sqrt(INTERPOLATION_RANGE_SQUARE - t * t);
- pos = static_cast(((x * (static_cast(endPos) - startPos)) >> INTERPOLATION_RANGE_OFFSET) +
- startPos);
- }
-
- return pos;
-}
-
-/* sqrt(1 - (1 - t)^2) */
-int16_t EasingEquation::CircEaseOut(int16_t startPos, int16_t endPos, uint16_t curTime, uint16_t durationTime)
-{
- int16_t pos = endPos;
- if (curTime < durationTime) {
- int32_t t = INTERPOLATION_RANGE - (curTime << INTERPOLATION_RANGE_OFFSET) / durationTime;
- uint32_t x = Sqrt(INTERPOLATION_RANGE_SQUARE - t * t);
- pos = static_cast(((x * (static_cast(endPos) - startPos)) >> INTERPOLATION_RANGE_OFFSET) +
- startPos);
- }
-
- return pos;
-}
-
-int16_t EasingEquation::CircEaseInOut(int16_t startPos, int16_t endPos, uint16_t curTime, uint16_t durationTime)
-{
- int16_t pos;
- uint16_t halfTime = durationTime >> 1;
- int16_t halfStep = (endPos >> 1) + (startPos >> 1);
- if (curTime < halfTime) {
- pos = CircEaseIn(startPos, halfStep, curTime, halfTime);
- } else {
- pos = CircEaseOut(halfStep, endPos, curTime - halfTime, halfTime);
- }
-
- return pos;
-}
-
-/* t^3 */
-int16_t EasingEquation::CubicEaseIn(int16_t startPos, int16_t endPos, uint16_t curTime, uint16_t durationTime)
-{
- int16_t pos = endPos;
- if (curTime < durationTime) {
- int32_t t = (curTime << INTERPOLATION_RANGE_OFFSET) / durationTime;
- int16_t x = (t * t * t) >> (INTERPOLATION_RANGE_OFFSET << 1);
- pos = static_cast(((x * (static_cast(endPos) - startPos)) >> INTERPOLATION_RANGE_OFFSET) +
- startPos);
- }
-
- return pos;
-}
-
-/* 1 - (1 - t)^3 */
-int16_t EasingEquation::CubicEaseOut(int16_t startPos, int16_t endPos, uint16_t curTime, uint16_t durationTime)
-{
- int16_t pos = endPos;
- if (curTime < durationTime) {
- int32_t t = (curTime << INTERPOLATION_RANGE_OFFSET) / durationTime;
- t = INTERPOLATION_RANGE - t;
- int16_t x = INTERPOLATION_RANGE - ((t * t * t) >> (INTERPOLATION_RANGE_OFFSET << 1));
- pos = static_cast(((x * (static_cast(endPos) - startPos)) >> INTERPOLATION_RANGE_OFFSET) +
- startPos);
- }
-
- return pos;
-}
-
-int16_t EasingEquation::CubicEaseInOut(int16_t startPos, int16_t endPos, uint16_t curTime, uint16_t durationTime)
-{
- int16_t pos;
- uint16_t halfTime = durationTime >> 1;
- int16_t halfStep = (endPos >> 1) + (startPos >> 1);
- if (curTime < halfTime) {
- pos = CubicEaseIn(startPos, halfStep, curTime, halfTime);
- } else {
- pos = CubicEaseOut(halfStep, endPos, curTime - halfTime, halfTime);
- }
-
- return pos;
-}
-
-int16_t EasingEquation::LinearEaseNone(int16_t startPos, int16_t endPos, uint16_t curTime, uint16_t durationTime)
-{
- int16_t pos = endPos;
- if (curTime < durationTime) {
- int32_t t = (curTime << INTERPOLATION_RANGE_OFFSET) / durationTime;
- pos = static_cast(((t * (static_cast(endPos) - startPos)) >> INTERPOLATION_RANGE_OFFSET) +
- startPos);
- }
-
- return pos;
-}
-
-/* t^2 */
-int16_t EasingEquation::QuadEaseIn(int16_t startPos, int16_t endPos, uint16_t curTime, uint16_t durationTime)
-{
- int16_t pos = endPos;
- if (curTime < durationTime) {
- int32_t t = (curTime << INTERPOLATION_RANGE_OFFSET) / durationTime;
- int16_t x = (t * t) >> INTERPOLATION_RANGE_OFFSET;
- pos = static_cast(((x * (static_cast(endPos) - startPos)) >> INTERPOLATION_RANGE_OFFSET) +
- startPos);
- }
-
- return pos;
-}
-
-/* 1 - (1 - t)^2 */
-int16_t EasingEquation::QuadEaseOut(int16_t startPos, int16_t endPos, uint16_t curTime, uint16_t durationTime)
-{
- int16_t pos = endPos;
- if (curTime < durationTime) {
- int32_t t = INTERPOLATION_RANGE - (curTime << INTERPOLATION_RANGE_OFFSET) / durationTime;
- int16_t x = INTERPOLATION_RANGE - ((t * t) >> INTERPOLATION_RANGE_OFFSET);
- pos = static_cast(((x * (static_cast(endPos) - startPos)) >> INTERPOLATION_RANGE_OFFSET) +
- startPos);
- }
-
- return pos;
-}
-
-int16_t EasingEquation::QuadEaseInOut(int16_t startPos, int16_t endPos, uint16_t curTime, uint16_t durationTime)
-{
- int16_t pos;
- uint16_t halfTime = durationTime >> 1;
- int16_t halfStep = (endPos >> 1) + (startPos >> 1);
- if (curTime < halfTime) {
- pos = QuadEaseIn(startPos, halfStep, curTime, halfTime);
- } else {
- pos = QuadEaseOut(halfStep, endPos, curTime - halfTime, halfTime);
- }
-
- return pos;
-}
-
-/* t^5 */
-int16_t EasingEquation::QuintEaseIn(int16_t startPos, int16_t endPos, uint16_t curTime, uint16_t durationTime)
-{
- int16_t pos = endPos;
- if (curTime < durationTime) {
- int64_t t = (curTime << INTERPOLATION_RANGE_OFFSET) / durationTime;
-
- /* 4: the fourth power of t */
- int16_t x = (t * t * t * t * t) >> (INTERPOLATION_RANGE_OFFSET * 4);
- pos = static_cast(((x * (static_cast(endPos) - startPos)) >> INTERPOLATION_RANGE_OFFSET) +
- startPos);
- }
-
- return pos;
-}
-
-/* 1 - (1 - t)^5 */
-int16_t EasingEquation::QuintEaseOut(int16_t startPos, int16_t endPos, uint16_t curTime, uint16_t durationTime)
-{
- int16_t pos = endPos;
- if (curTime < durationTime) {
- int64_t t = (curTime << INTERPOLATION_RANGE_OFFSET) / durationTime;
- t = INTERPOLATION_RANGE - t;
-
- /* 4: the fourth power of t */
- int16_t x = INTERPOLATION_RANGE - ((t * t * t * t * t) >> (INTERPOLATION_RANGE_OFFSET * 4));
- pos = static_cast(((x * (static_cast(endPos) - startPos)) >> INTERPOLATION_RANGE_OFFSET) +
- startPos);
- }
-
- return pos;
-}
-
-int16_t EasingEquation::QuintEaseInOut(int16_t startPos, int16_t endPos, uint16_t curTime, uint16_t durationTime)
-{
- int16_t pos;
- uint16_t halfTime = durationTime >> 1;
- int16_t halfStep = (endPos >> 1) + (startPos >> 1);
- if (curTime < halfTime) {
- pos = QuintEaseIn(startPos, halfStep, curTime, halfTime);
- } else {
- pos = QuintEaseOut(halfStep, endPos, curTime - halfTime, halfTime);
- }
-
- return pos;
-}
-
-int16_t EasingEquation::SineEaseIn(int16_t startPos, int16_t endPos, uint16_t curTime, uint16_t durationTime)
-{
- int16_t pos = endPos;
- if (curTime < durationTime) {
- int16_t t = (curTime * QUARTER_IN_DEGREE) / durationTime - QUARTER_IN_DEGREE;
- float x = Sin(t) + 1;
- pos = static_cast(x * (endPos - startPos)) + startPos;
- }
-
- return pos;
-}
-
-int16_t EasingEquation::SineEaseOut(int16_t startPos, int16_t endPos, uint16_t curTime, uint16_t durationTime)
-{
- int16_t pos = endPos;
- if (curTime < durationTime) {
- int16_t t = (curTime * QUARTER_IN_DEGREE) / durationTime;
- float x = Sin(t);
- pos = static_cast(x * (endPos - startPos)) + startPos;
- }
-
- return pos;
-}
-
-int16_t EasingEquation::SineEaseInOut(int16_t startPos, int16_t endPos, uint16_t curTime, uint16_t durationTime)
-{
- int16_t pos;
- uint16_t halfTime = durationTime >> 1;
- int16_t halfStep = (endPos >> 1) + (startPos >> 1);
- if (curTime < halfTime) {
- pos = SineEaseIn(startPos, halfStep, curTime, halfTime);
- } else {
- pos = SineEaseOut(halfStep, endPos, curTime - halfTime, halfTime);
- }
-
- return pos;
-}
-}
\ No newline at end of file
diff --git a/frameworks/ui/src/animator/interpolation.cpp b/frameworks/ui/src/animator/interpolation.cpp
deleted file mode 100755
index 3ded56b..0000000
--- a/frameworks/ui/src/animator/interpolation.cpp
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#include "animator/interpolation.h"
-
-namespace OHOS {
-/* B(t) = P0*(1-t)^3 + 3*P1*t*(1-t)^2 + 3*P2*t^2*(1-t) + P3*t^3 */
-int16_t Interpolation::GetBezierInterpolation(int16_t t, int16_t u0, int16_t u1, int16_t u2, int16_t u3)
-{
- int64_t invT = INTERPOLATION_RANGE - t;
- int64_t invT2 = invT * invT;
- int64_t invT3 = invT2 * invT;
- int64_t t2 = t * t;
- int64_t t3 = t2 * t;
-
- int64_t ret = invT3 * u0;
- ret += BESSEL_COEFFICIENT * invT2 * t * u1;
- ret += BESSEL_COEFFICIENT * invT * t2 * u2;
- ret += t3 * u3;
- ret = ret >> CUBIC_BEZIER_CALCULATE_OFFSET;
- return static_cast(ret);
-}
-}
diff --git a/frameworks/ui/src/common/graphic_startup.cpp b/frameworks/ui/src/common/graphic_startup.cpp
deleted file mode 100755
index 86263a8..0000000
--- a/frameworks/ui/src/common/graphic_startup.cpp
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#include "common/graphic_startup.h"
-#include "animator/animator.h"
-#include "common/input_device_manager.h"
-#include "core/render_manager.h"
-#include "common/task_manager.h"
-#include "file.h"
-#include "font/ui_font.h"
-#include "graphic_log.h"
-#include "imgdecode/cache_manager.h"
-#ifdef VERSION_STANDARD
-#include "dock/ohos/ohos_input_device.h"
-#endif
-#if ENABLE_WINDOW
-#include "client/iwindows_manager.h"
-#if ENABLE_HARDWARE_ACCELERATION
-#include "gfx_engines.h"
-#endif
-#endif
-
-namespace OHOS {
-void GraphicStartUp::InitFontEngine(uintptr_t psramAddr, uint32_t psramLen, const char* dPath, const char* ttfName)
-{
- UIFont* pFont = UIFont::GetInstance();
- if (pFont == nullptr) {
- GRAPHIC_LOGE("Get UIFont error");
- return;
- }
- int8_t ret = pFont->SetPsramMemory(psramAddr, psramLen);
- if (ret == INVALID_RET_VALUE) {
- GRAPHIC_LOGE("SetPsramMemory failed");
- return;
- }
- // font and glyph path
- ret = pFont->SetFontPath(const_cast(dPath));
- if (ret == INVALID_RET_VALUE) {
- GRAPHIC_LOGW("SetFontPath failed");
- }
- if (ttfName != nullptr) {
- ret = pFont->RegisterFontInfo(ttfName);
- if (ret == INVALID_RET_VALUE) {
- GRAPHIC_LOGW("SetTtfName failed");
- }
- }
-}
-
-void GraphicStartUp::Init()
-{
- TaskManager::GetInstance()->SetTaskRun(true);
- FileInit();
-
- if (INDEV_READ_PERIOD > 0) {
- InputDeviceManager::GetInstance()->Init();
- }
- AnimatorManager::GetInstance()->Init();
-
- StyleDefault::Init();
- RenderManager::GetInstance().Init();
-
- CacheManager::GetInstance().Init(IMG_CACHE_SIZE);
-#ifdef VERSION_STANDARD
- OHOSInputDevice* input = new OHOSInputDevice();
- InputDeviceManager::GetInstance()->Add(input);
-#endif
-
-#if ENABLE_WINDOW
- IWindowsManager::GetInstance()->Init();
-#if ENABLE_HARDWARE_ACCELERATION
- GfxEngines::GetInstance()->InitDriver();
-#endif
-#endif
-}
-} // namespace OHOS
diff --git a/frameworks/ui/src/common/image.cpp b/frameworks/ui/src/common/image.cpp
deleted file mode 100755
index edc45fd..0000000
--- a/frameworks/ui/src/common/image.cpp
+++ /dev/null
@@ -1,379 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#include "common/image.h"
-#include "common/image_decode_ability.h"
-#include "draw/draw_image.h"
-#include "graphic_log.h"
-#include "imgdecode/cache_manager.h"
-#include "jpeglib.h"
-#include "png.h"
-#include "securec.h"
-
-namespace OHOS {
-Image::Image() : imageInfo_(nullptr), path_(nullptr), srcType_(IMG_SRC_UNKNOWN), mallocFlag_(false) {}
-
-Image::~Image()
-{
- if (srcType_ == IMG_SRC_FILE) {
- CacheManager::GetInstance().Close(path_);
- }
- if (imageInfo_ != nullptr) {
- if (mallocFlag_) {
- UIFree(reinterpret_cast(const_cast(imageInfo_->data)));
- mallocFlag_ = false;
- }
- UIFree(reinterpret_cast(const_cast(imageInfo_)));
- imageInfo_ = nullptr;
- }
- if (path_ != nullptr) {
- UIFree(reinterpret_cast(const_cast(path_)));
- path_ = nullptr;
- }
- srcType_ = IMG_SRC_UNKNOWN;
-}
-
-void Image::GetHeader(ImageHeader& header) const
-{
- if (srcType_ == IMG_SRC_VARIABLE && imageInfo_ != nullptr) {
- header = imageInfo_->header;
- } else if (srcType_ == IMG_SRC_FILE && path_ != nullptr) {
- CacheManager::GetInstance().GetImageHeader(path_, header);
- }
-}
-
-bool Image::SetStandardSrc(const char* src)
-{
- const char* ptr = strrchr(src, '.');
- if (ptr == nullptr) {
- srcType_ = IMG_SRC_UNKNOWN;
- return false;
- }
-
- if (strcmp(ptr, ".png") == 0 || strcmp(ptr, ".PNG") == 0) {
- return SetPNGSrc(src);
- } else if (strcmp(ptr, ".jpg") == 0 || strcmp(ptr, ".JPG") == 0 || strcmp(ptr, ".jpeg") == 0 ||
- strcmp(ptr, ".JPEG") == 0) {
- return SetJPEGSrc(src);
- }
-
- size_t strLen = strlen(src) + 1;
- char* imagePath = static_cast(UIMalloc(static_cast(strLen)));
- if (imagePath == nullptr) {
- srcType_ = IMG_SRC_UNKNOWN;
- return false;
- }
-
- if (memcpy_s(imagePath, strLen, src, strLen) != EOK) {
- UIFree(reinterpret_cast(imagePath));
- imagePath = nullptr;
- srcType_ = IMG_SRC_UNKNOWN;
- return false;
- }
- path_ = imagePath;
- srcType_ = IMG_SRC_FILE;
- return true;
-}
-
-bool Image::SetLiteSrc(const char* src)
-{
- const char* ptr = strrchr(src, '.');
- if (ptr == nullptr) {
- srcType_ = IMG_SRC_UNKNOWN;
- return false;
- }
-
- size_t strLen = strlen(src) + 1;
- char* imagePath = static_cast(UIMalloc(static_cast(strLen)));
- if (imagePath == nullptr) {
- srcType_ = IMG_SRC_UNKNOWN;
- return false;
- }
- if (strcmp(ptr, ".png") == 0 || strcmp(ptr, ".PNG") == 0 || strcmp(ptr, ".jpg") == 0 || strcmp(ptr, ".JPG") == 0 ||
- strcmp(ptr, ".jpeg") == 0 || strcmp(ptr, ".JPEG") == 0) {
- const char* suffixName = "bin";
- if (memcpy_s(imagePath, strLen, src, strLen) != EOK) {
- UIFree(reinterpret_cast(imagePath));
- imagePath = nullptr;
- srcType_ = IMG_SRC_UNKNOWN;
- return false;
- }
- for (int16_t index = strLen - 2; index >= 0; index--) { // 2: Last but one letter
- if (*(imagePath + index) == '.') {
- imagePath[index + 1] = '\0';
- break;
- }
- }
- if (strcat_s(imagePath, strLen, suffixName) != EOK) {
- UIFree(reinterpret_cast(imagePath));
- imagePath = nullptr;
- srcType_ = IMG_SRC_UNKNOWN;
- return false;
- }
- } else {
- if (memcpy_s(imagePath, strLen, src, strLen) != EOK) {
- UIFree(reinterpret_cast(imagePath));
- imagePath = nullptr;
- srcType_ = IMG_SRC_UNKNOWN;
- return false;
- }
- }
- path_ = imagePath;
- srcType_ = IMG_SRC_FILE;
- return true;
-}
-
-bool Image::SetSrc(const char* src)
-{
- if (path_ != nullptr) {
- UIFree(reinterpret_cast(const_cast(path_)));
- path_ = nullptr;
- }
-
- if (src != nullptr) {
- uint32_t imageType = ImageDecodeAbility::GetInstance().GetImageDecodeAbility();
- if (((imageType & IMG_SUPPORT_JPEG) == IMG_SUPPORT_JPEG) ||
- ((imageType & IMG_SUPPORT_PNG) == IMG_SUPPORT_PNG)) {
- return SetStandardSrc(src);
- } else {
- return SetLiteSrc(src);
- }
- } else {
- path_ = src;
- srcType_ = IMG_SRC_UNKNOWN;
- }
- return true;
-}
-
-bool Image::SetSrc(const ImageInfo* src)
-{
- if (imageInfo_ != nullptr) {
- UIFree(reinterpret_cast(const_cast(imageInfo_)));
- imageInfo_ = nullptr;
- }
-
- if (src != nullptr) {
- imageInfo_ = static_cast(UIMalloc(static_cast(sizeof(ImageInfo))));
- if (imageInfo_ == nullptr) {
- srcType_ = IMG_SRC_UNKNOWN;
- return false;
- }
-
- if (memcpy_s(const_cast(imageInfo_), sizeof(ImageInfo), src, sizeof(ImageInfo)) != EOK) {
- srcType_ = IMG_SRC_UNKNOWN;
- return false;
- }
-
- srcType_ = IMG_SRC_VARIABLE;
- } else {
- imageInfo_ = src;
- srcType_ = IMG_SRC_UNKNOWN;
- }
- return true;
-}
-
-void Image::DrawImage(const Rect& coords, const Rect& mask, const Style& style, uint8_t opaScale) const
-{
- if (srcType_ == IMG_SRC_VARIABLE) {
- DrawImage::DrawCommon(coords, mask, imageInfo_, style, opaScale);
- } else if (srcType_ == IMG_SRC_FILE) {
- DrawImage::DrawCommon(coords, mask, path_, style, opaScale);
- } else {
- GRAPHIC_LOGE("Image::DrawImage:: failed with error srctype!\n");
- }
-}
-
-bool Image::SetPNGSrc(const char* src)
-{
- FILE* infile = nullptr;
- png_bytep* rowPointer = nullptr;
- png_structp png = png_create_read_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr);
- if (png == nullptr) {
- srcType_ = IMG_SRC_UNKNOWN;
- return false;
- }
- png_infop info = png_create_info_struct(png);
- if (info == nullptr) {
- srcType_ = IMG_SRC_UNKNOWN;
- return false;
- }
- if ((infile = fopen(src, "rb")) == nullptr) {
- GRAPHIC_LOGE("can't open %s\n", src);
- srcType_ = IMG_SRC_UNKNOWN;
- return false;
- }
- png_init_io(png, infile);
- png_read_info(png, info);
-
- uint8_t pixelByteSize = DrawUtils::GetPxSizeByColorMode(ARGB8888) >> 3; // 3: Shift right 3 bits
- uint16_t width = png_get_image_width(png, info);
- uint16_t height = png_get_image_height(png, info);
- uint32_t dataSize = height * width * pixelByteSize;
-
- if (png_get_valid(png, info, PNG_INFO_tRNS)) {
- png_set_tRNS_to_alpha(png);
- }
- png_read_update_info(png, info);
-
- rowPointer = static_cast(UIMalloc(sizeof(png_bytep) * height));
- if (rowPointer == nullptr) {
- srcType_ = IMG_SRC_UNKNOWN;
- fclose(infile);
- return false;
- }
- for (uint16_t y = 0; y < height; y++) {
- rowPointer[y] = static_cast(UIMalloc(png_get_rowbytes(png, info)));
- if (rowPointer[y] == nullptr) {
- for (uint16_t i = 0; i < y; i++) {
- UIFree(rowPointer[i]);
- rowPointer[i] = nullptr;
- }
- fclose(infile);
- UIFree(rowPointer);
- srcType_ = IMG_SRC_UNKNOWN;
- png_destroy_read_struct(&png, &info, nullptr);
- return false;
- }
- }
- png_read_image(png, rowPointer);
- fclose(infile);
- png_destroy_read_struct(&png, &info, nullptr);
- ImageInfo* newStr = static_cast(UIMalloc(sizeof(ImageInfo)));
- if (newStr == nullptr) {
- for (uint16_t i = 0; i < height; i++) {
- UIFree(rowPointer[i]);
- rowPointer[i] = nullptr;
- }
- UIFree(rowPointer);
- srcType_ = IMG_SRC_UNKNOWN;
- return false;
- }
- uint8_t* srcData = static_cast(UIMalloc(dataSize));
- if (srcData == nullptr) {
- for (uint16_t i = 0; i < height; i++) {
- UIFree(rowPointer[i]);
- rowPointer[i] = nullptr;
- }
- UIFree(rowPointer);
- UIFree(newStr);
- srcType_ = IMG_SRC_UNKNOWN;
- return false;
- }
- uint32_t n = 0;
- for (uint16_t y = 0; y < height; y++) {
- png_bytep row = rowPointer[y];
- for (uint16_t x = 0; x < width * pixelByteSize; x += pixelByteSize) {
- srcData[n++] = row[x + 2]; // 2: B channel
- srcData[n++] = row[x + 1]; // 1: G channel
- srcData[n++] = row[x + 0]; // 0: R channel
- srcData[n++] = row[x + 3]; // 3: Alpha channel
- }
- UIFree(row);
- row = nullptr;
- }
- UIFree(rowPointer);
-
- newStr->header.width = width;
- newStr->header.height = height;
- newStr->header.colorMode = ARGB8888;
- newStr->dataSize = dataSize;
- newStr->data = srcData;
-
- if (imageInfo_ != nullptr) {
- if (mallocFlag_) {
- UIFree(reinterpret_cast(const_cast(imageInfo_->data)));
- mallocFlag_ = false;
- }
- UIFree(reinterpret_cast(const_cast(imageInfo_)));
- imageInfo_ = nullptr;
- }
- imageInfo_ = newStr;
- mallocFlag_ = true;
- srcType_ = IMG_SRC_VARIABLE;
- return true;
-}
-
-bool Image::SetJPEGSrc(const char* src)
-{
- struct jpeg_decompress_struct cinfo;
- struct jpeg_error_mgr jerr;
- FILE* infile = nullptr;
- JSAMPARRAY buffer;
-
- if ((infile = fopen(src, "rb")) == nullptr) {
- GRAPHIC_LOGE("can't open %s\n", src);
- srcType_ = IMG_SRC_UNKNOWN;
- return false;
- }
- cinfo.err = jpeg_std_error(&jerr);
- jpeg_create_decompress(&cinfo);
- jpeg_stdio_src(&cinfo, infile);
- jpeg_read_header(&cinfo, TRUE);
- jpeg_start_decompress(&cinfo);
-
- uint8_t pixelByteSize = DrawUtils::GetPxSizeByColorMode(ARGB8888) >> 3; // 3: Shift right 3 bits
- uint16_t width = cinfo.output_width;
- uint16_t height = cinfo.output_height;
- uint32_t dataSize = width * height * pixelByteSize;
- uint16_t rowStride = cinfo.output_width * pixelByteSize;
- buffer = (*cinfo.mem->alloc_sarray)(reinterpret_cast(&cinfo), JPOOL_IMAGE, rowStride,
- 1); // 1: one-row-high array
- ImageInfo* newStr = static_cast(UIMalloc(sizeof(ImageInfo)));
- if (newStr == nullptr) {
- fclose(infile);
- srcType_ = IMG_SRC_UNKNOWN;
- return false;
- }
- uint8_t* srcData = static_cast(UIMalloc(dataSize));
- if (srcData == nullptr) {
- fclose(infile);
- UIFree(newStr);
- srcType_ = IMG_SRC_UNKNOWN;
- return false;
- }
- uint32_t n = 0;
- while (cinfo.output_scanline < cinfo.output_height) {
- jpeg_read_scanlines(&cinfo, buffer, 1); // 1: read one line each time
- for (uint16_t x = 0; x < width * 3; x += 3) { // 3: color components per pixel
- srcData[n++] = buffer[0][x + 2]; // 2: B channel
- srcData[n++] = buffer[0][x + 1]; // 1: G channel
- srcData[n++] = buffer[0][x + 0]; // 0: R channel
- srcData[n++] = 255; // 255: set alpha channel
- }
- }
- jpeg_finish_decompress(&cinfo);
- jpeg_destroy_decompress(&cinfo);
- fclose(infile);
-
- newStr->header.width = width;
- newStr->header.height = height;
- newStr->header.colorMode = ARGB8888;
- newStr->dataSize = dataSize;
- newStr->data = srcData;
-
- if (imageInfo_ != nullptr) {
- if (mallocFlag_) {
- UIFree(reinterpret_cast(const_cast(imageInfo_->data)));
- mallocFlag_ = false;
- }
- UIFree(reinterpret_cast(const_cast(imageInfo_)));
- imageInfo_ = nullptr;
- }
- imageInfo_ = newStr;
- mallocFlag_ = true;
- srcType_ = IMG_SRC_VARIABLE;
- return true;
-}
-} // namespace OHOS
\ No newline at end of file
diff --git a/frameworks/ui/src/common/input_device_manager.cpp b/frameworks/ui/src/common/input_device_manager.cpp
deleted file mode 100755
index 23a9925..0000000
--- a/frameworks/ui/src/common/input_device_manager.cpp
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#include "common/input_device_manager.h"
-#include "common/task_manager.h"
-#include "graphic_log.h"
-
-namespace OHOS {
-void InputDeviceManager::Init()
-{
- if (INDEV_READ_PERIOD > 0) {
- SetPeriod(INDEV_READ_PERIOD);
- TaskManager::GetInstance()->Add(this);
- }
-}
-
-void InputDeviceManager::Add(InputDevice* device)
-{
- if (device == nullptr) {
- GRAPHIC_LOGE("InputDeviceManager::Add invalid param\n");
- return;
- }
- deviceList_.PushBack(device);
-}
-
-void InputDeviceManager::Remove(InputDevice* device)
-{
- if (device == nullptr) {
- return;
- }
- ListNode* node = deviceList_.Begin();
- while (node != deviceList_.End()) {
- if (node->data_ == device) {
- deviceList_.Remove(node);
- return;
- }
- node = node->next_;
- }
-}
-
-void InputDeviceManager::Callback()
-{
- ListNode* node = deviceList_.Begin();
- while (node != deviceList_.End()) {
- node->data_->ProcessEvent();
- node = node->next_;
- }
-}
-
-void InputDeviceManager::Clear()
-{
- deviceList_.Clear();
-}
-} // namespace OHOS
\ No newline at end of file
diff --git a/frameworks/ui/src/common/screen.cpp b/frameworks/ui/src/common/screen.cpp
deleted file mode 100755
index d988a2e..0000000
--- a/frameworks/ui/src/common/screen.cpp
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#include "common/screen.h"
-#include "common/screen_device_proxy.h"
-
-namespace OHOS {
-uint16_t Screen::GetWidth()
-{
- return ScreenDeviceProxy::GetInstance()->GetScreenWidth();
-}
-
-uint16_t Screen::GetHeight()
-{
- return ScreenDeviceProxy::GetInstance()->GetScreenHeight();
-}
-} // namespace OHOS
\ No newline at end of file
diff --git a/frameworks/ui/src/common/screen_device_proxy.cpp b/frameworks/ui/src/common/screen_device_proxy.cpp
deleted file mode 100755
index 17d7d36..0000000
--- a/frameworks/ui/src/common/screen_device_proxy.cpp
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#include "common/screen_device_proxy.h"
-#include "graphic_log.h"
-#include "securec.h"
-
-namespace OHOS {
-#if ENABLE_FRAME_BUFFER
-void ScreenDeviceProxy::Flush() {}
-#else
-void ScreenDeviceProxy::Flush()
-{
- flush_.Flushing();
-
- if (device_ != nullptr) {
-#if ENABLE_WINDOW
- device_->Flush(bufferRect_.GetLeft(), bufferRect_.GetTop(), bufferRect_.GetRight(), bufferRect_.GetBottom(),
- (ScreenBufferType*)gfxAlloc_.virAddr);
-#else
- device_->Flush(bufferRect_.GetLeft(), bufferRect_.GetTop(), bufferRect_.GetRight(), bufferRect_.GetBottom(),
- buffer_);
-#endif
- }
-}
-#endif
-
-void ScreenDeviceProxy::OnFlushReady()
-{
- flush_.Notify();
-}
-
-void ScreenDeviceProxy::OnRenderFinish()
-{
- if (device_ != nullptr) {
- device_->RenderFinish();
- }
-}
-
-void ScreenDeviceProxy::SetScreenSize(uint16_t width, uint16_t height)
-{
- if (width == 0 || height == 0) {
- GRAPHIC_LOGE("screen size can not be zero.");
- ASSERT(0);
- return;
- }
- width_ = width;
- height_ = height;
-#if !ENABLE_WINDOW
- if (buffer_ != nullptr) {
- UIFree(buffer_);
- }
- uint32_t bufSize = width * height * sizeof(ScreenBufferType);
- buffer_ = static_cast(UIMalloc(bufSize));
- if (buffer_ == nullptr) {
- GRAPHIC_LOGE("screen buffer malloc failed.");
- ASSERT(0);
- }
- if (memset_s(buffer_, bufSize, 0, bufSize) != EOK) {
- GRAPHIC_LOGE("screen buffer memset failed.");
- UIFree(reinterpret_cast(buffer_));
- buffer_ = nullptr;
- ASSERT(0);
- }
-#endif
-}
-} // namespace OHOS
\ No newline at end of file
diff --git a/frameworks/ui/src/common/task.cpp b/frameworks/ui/src/common/task.cpp
deleted file mode 100755
index bc3b10f..0000000
--- a/frameworks/ui/src/common/task.cpp
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-#include "common/task.h"
-#include "common/task_manager.h"
-#include "hal_tick.h"
-
-namespace OHOS {
-void Task::TaskExecute()
-{
- uint32_t elp = HALTick::GetInstance().GetElapseTime(lastRun_);
- if (elp >= period_) {
- lastRun_ = HALTick::GetInstance().GetTime();
- Callback();
- }
-}
-
-void Task::Init()
-{
- SetPeriod(period_);
- TaskManager::GetInstance()->Add(this);
-}
-}
diff --git a/frameworks/ui/src/common/text.cpp b/frameworks/ui/src/common/text.cpp
deleted file mode 100755
index 8fbc148..0000000
--- a/frameworks/ui/src/common/text.cpp
+++ /dev/null
@@ -1,341 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#include "common/text.h"
-#include "common/typed_text.h"
-#include "draw/draw_label.h"
-#include "font/ui_font.h"
-#include "graphic_log.h"
-#include "securec.h"
-
-namespace OHOS {
-Text::TextLine Text::textLine_[MAX_LINE_COUNT] = { {0} };
-
-Text::Text()
- : text_(nullptr),
- fontId_(0),
- fontSize_(0),
- textSize_({ 0, 0 }),
- needRefresh_(false),
- expandWidth_(false),
- expandHeight_(false),
- direct_(TEXT_DIRECT_LTR),
- rotateAngle_(LabelRotateDegree::DEGREE_0),
- horizontalAlign_(TEXT_ALIGNMENT_LEFT),
- verticalAlign_(TEXT_ALIGNMENT_TOP) {}
-
-Text::~Text()
-{
- if (text_ != nullptr) {
- UIFree(text_);
- text_ = nullptr;
- }
-}
-
-void Text::SetText(const char* text)
-{
- if (text == nullptr) {
- return;
- }
- if (text_ != nullptr) {
- if (strcmp(text, text_) == 0) {
- return;
- }
- UIFree(text_);
- text_ = nullptr;
- }
- uint32_t textLen = static_cast(strlen(text));
- if (textLen > MAX_TEXT_LENGTH) {
- return;
- }
- if (textLen != 0) {
- text_ = static_cast(UIMalloc(++textLen));
- if (text_ == nullptr) {
- return;
- }
- if (memcpy_s(text_, textLen, text, textLen) != EOK) {
- UIFree(text_);
- text_ = nullptr;
- return;
- }
- }
- needRefresh_ = true;
-}
-
-void Text::SetFont(const char* name, uint8_t size)
-{
- if (name == nullptr) {
- return;
- }
- if (UIFont::GetInstance()->IsVectorFont()) {
- fontId_ = UIFont::GetInstance()->GetFontId(name);
- fontSize_ = size;
- } else {
- uint8_t fontId = UIFont::GetInstance()->GetFontId(name, size);
- SetFontId(fontId);
- }
-}
-
-void Text::SetFont(const char* name, uint8_t size, char*& destName, uint8_t& destSize)
-{
- if (name == nullptr) {
- return;
- }
- if (destName != nullptr) {
- if (strcmp(destName, name) == 0) {
- destSize = size;
- return;
- }
- UIFree(destName);
- destName = nullptr;
- }
- uint32_t nameLen = static_cast(strlen(name));
- if (nameLen > MAX_TEXT_LENGTH) {
- return;
- }
- if (nameLen != 0) {
- /* one more to store '\0' */
- destName = static_cast(UIMalloc(++nameLen));
- if (destName == nullptr) {
- return;
- }
- if (memcpy_s(destName, nameLen, name, nameLen) != EOK) {
- UIFree(destName);
- destName = nullptr;
- return;
- }
- destSize = size;
- }
-}
-
-void Text::SetFontId(uint8_t fontId)
-{
- if (fontId >= GetTotalFontId() || fontId_ == fontId) {
- GRAPHIC_LOGE("Text::SetFontId invalid fontId(%d)", fontId);
- return;
- }
- if (!UIFont::GetInstance()->IsVectorFont()) {
- fontId_ = fontId;
- needRefresh_ = true;
- }
-}
-
-void Text::ReMeasureTextSize(const Rect& textRect, const Style& style)
-{
- UIFont::GetInstance()->SetCurrentFontId(fontId_, fontSize_);
- int16_t maxWidth = (expandWidth_ ? COORD_MAX : textRect.GetWidth());
- textSize_ = TypedText::GetTextSize(text_, style.letterSpace_, style.lineSpace_, maxWidth);
-}
-
-void Text::OnDraw(const Rect& invalidatedArea, const Rect& viewOrigRect, const Rect& textRect, int16_t offsetX,
- const Style& style, uint16_t ellipsisIndex)
-{
- if (text_ == nullptr) {
- return;
- }
- UIFont::GetInstance()->SetCurrentFontId(fontId_, fontSize_);
- Rect mask;
- Rect coords;
- uint16_t angle = 0;
- if (rotateAngle_ != LabelRotateDegree::DEGREE_0) {
- coords = viewOrigRect;
- TransformMap reverseMap(invalidatedArea);
- int16_t pivotX = coords.GetLeft() - invalidatedArea.GetLeft();
- int16_t pivotY = coords.GetTop() - invalidatedArea.GetTop();
- angle = GetTextRotateDegree();
- reverseMap.Rotate(-angle, { pivotX, pivotY });
- mask = reverseMap.GetBoxRect();
- } else {
- mask = invalidatedArea;
- coords = textRect;
- }
-
- if (mask.Intersect(mask, coords)) {
- LabelRotation rotation {
- invalidatedArea, coords, { coords.GetLeft(), coords.GetTop() }, angle
- };
- Draw(mask, rotation, style, offsetX, ellipsisIndex);
- }
-}
-
-void Text::Draw(const Rect& mask, const LabelRotation& rotate, const Style& style, int16_t offsetX,
- uint16_t ellipsisIndex)
-{
- Point offset = { offsetX, 0 };
- int16_t lineMaxWidth = expandWidth_ ? textSize_.x : rotate.coords.GetWidth();
- int16_t lineHeight = UIFont::GetInstance()->GetHeight() + style.lineSpace_;
- Point pos;
- pos.y = TextPositionY(rotate.coords);
- char* realText = GetEllipsisText(text_, ellipsisIndex);
- if (realText == nullptr) {
- return;
- }
- uint16_t lineCount = GetLine(realText, lineMaxWidth, style.letterSpace_);
- for (int i = 0; i < lineCount; i++) {
- if (pos.y > mask.GetBottom()) {
- if (ellipsisIndex != TEXT_ELLIPSIS_END_INV) {
- UIFree(realText);
- }
- return;
- }
- uint16_t lineBegin = textLine_[i].lineBegin;
- uint16_t lineWidth;
- int16_t nextLine = pos.y + lineHeight;
- if (nextLine >= mask.GetTop()) {
- int16_t letterSpace = style.letterSpace_;
- lineWidth = TypedText::GetTextWidth(&realText[lineBegin], textLine_[i].lineBytes, letterSpace);
- pos.x = LineStartPos(rotate.coords, lineWidth);
- LabelLineInfo labelLine{ pos, offset, mask, rotate, lineHeight, textLine_[i].lineBytes, 0,
- style.textOpa_, style, &realText[lineBegin], textLine_[i].lineBytes, lineBegin,
- fontId_, static_cast(direct_), nullptr };
- DrawLabel::DrawTextOneLine(labelLine);
- }
- pos.y = nextLine;
- }
- if (ellipsisIndex != TEXT_ELLIPSIS_END_INV) {
- UIFree(realText);
- }
-}
-
-int16_t Text::TextPositionY(const Rect& textRect)
-{
- int16_t yOffset = 0;
- if (!expandHeight_ && (verticalAlign_ != TEXT_ALIGNMENT_TOP) && (textRect.GetHeight() > textSize_.y)) {
- if (verticalAlign_ == TEXT_ALIGNMENT_CENTER) {
- yOffset = (textRect.GetHeight() - textSize_.y) >> 1;
- }
- if (verticalAlign_ == TEXT_ALIGNMENT_BOTTOM) {
- yOffset = textRect.GetHeight() - textSize_.y;
- }
- }
- return textRect.GetY() + yOffset;
-}
-
-int16_t Text::LineStartPos(const Rect& textRect, uint16_t lineWidth)
-{
- int16_t xOffset = 0;
- int16_t rectWidth = textRect.GetWidth();
- if (horizontalAlign_ == TEXT_ALIGNMENT_CENTER) {
- xOffset = (direct_ == TEXT_DIRECT_RTL) ?
- ((rectWidth + lineWidth + 1) >> 1) :
- ((rectWidth - lineWidth) >> 1);
- } else if (horizontalAlign_ == TEXT_ALIGNMENT_RIGHT) {
- xOffset = (direct_ == TEXT_DIRECT_RTL) ? rectWidth : (rectWidth - lineWidth);
- } else {
- xOffset = (direct_ == TEXT_DIRECT_RTL) ? lineWidth : 0;
- }
- return textRect.GetX() + xOffset;
-}
-
-uint16_t Text::GetLine(const char* text, int16_t width, uint8_t letterSpace)
-{
- if (text == nullptr) {
- return 0;
- }
- uint16_t lineNum = 0;
- uint32_t textLen = strlen(text);
- uint16_t begin = 0;
- uint16_t nextBegin = 0;
- while ((begin <= textLen) && (text[begin] != '\0') && (lineNum < MAX_LINE_COUNT)) {
- nextBegin += TypedText::GetNextLine(&text[begin], letterSpace, width);
- textLine_[lineNum].lineBegin = begin;
- textLine_[lineNum].lineBytes = nextBegin - begin;
- begin = nextBegin;
- lineNum++;
- }
- return lineNum;
-}
-
-char* Text::GetEllipsisText(char* text, uint16_t ellipsisIndex)
-{
- if (ellipsisIndex == TEXT_ELLIPSIS_END_INV) {
- return text;
- }
- uint32_t byteIdx = TypedText::GetByteIndexFromUTF8Id(text, ellipsisIndex);
- uint32_t ellipsisTextSize = byteIdx + TEXT_ELLIPSIS_DOT_NUM + 1;
- char* ellipsisText = reinterpret_cast(UIMalloc(ellipsisTextSize));
- if (ellipsisText == nullptr) {
- return nullptr;
- }
- if (memcpy_s(ellipsisText, ellipsisTextSize, text, byteIdx) != EOK) {
- UIFree(ellipsisText);
- return nullptr;
- }
- if (memset_s(ellipsisText + byteIdx, TEXT_ELLIPSIS_DOT_NUM + 1, '.', TEXT_ELLIPSIS_DOT_NUM) != EOK) {
- UIFree(ellipsisText);
- return nullptr;
- }
- ellipsisText[ellipsisTextSize - 1] = '\0';
-
- return ellipsisText;
-}
-
-uint16_t Text::GetEllipsisIndex(const Rect& textRect, const Style& style)
-{
- if (textSize_.y <= textRect.GetHeight() || TypedText::GetUTF8CharacterSize(text_) <= TEXT_ELLIPSIS_DOT_NUM) {
- return TEXT_ELLIPSIS_END_INV;
- }
- UIFont* pFont = UIFont::GetInstance();
- pFont->SetCurrentFontId(fontId_);
- int16_t letterWidth = pFont->GetWidth('.', 0) + style.letterSpace_;
- Point p;
- p.x = textRect.GetWidth() - letterWidth * TEXT_ELLIPSIS_DOT_NUM;
- p.y = textRect.GetHeight();
- int16_t height = pFont->GetHeight() + style.lineSpace_;
- if (height) {
- p.y -= p.y % height;
- }
-
- p.y -= style.lineSpace_;
- return GetLetterIndexByPosition(textRect, style, p);
-}
-
-uint16_t Text::GetLetterIndexByPosition(const Rect& textRect, const Style& style, const Point& pos)
-{
- if (text_ == nullptr) {
- return 0;
- }
- uint32_t lineStart = 0;
- uint32_t nextLineStart = 0;
-
- uint16_t lineHeight = UIFont::GetInstance()->GetHeight();
- int16_t y = 0;
- uint32_t textLen = static_cast(strlen(text_));
- while (lineStart < textLen && text_[lineStart] != '\0') {
- nextLineStart += TypedText::GetNextLine(&text_[lineStart], style.letterSpace_, textRect.GetWidth());
- if (pos.y <= y + lineHeight) {
- break;
- }
- y += lineHeight + style.lineSpace_;
- lineStart = nextLineStart;
- }
- /* Calculate the x coordinate */
- int16_t x = 0;
- uint32_t i = lineStart;
- uint32_t pre = i;
- while (i < nextLineStart - 1) {
- uint32_t tmp = i;
- uint32_t letter = TypedText::GetUTF8Next(text_, tmp, i);
- x += UIFont::GetInstance()->GetWidth(letter, 0);
- if (pos.x < x) {
- i = pre;
- break;
- }
- x += style.letterSpace_;
- pre = i;
- }
- return TypedText::GetUTF8CharacterSize(text_, i);
-}
-} // namespace OHOS
\ No newline at end of file
diff --git a/frameworks/ui/src/common/typed_text.cpp b/frameworks/ui/src/common/typed_text.cpp
deleted file mode 100755
index f2db400..0000000
--- a/frameworks/ui/src/common/typed_text.cpp
+++ /dev/null
@@ -1,298 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#include "common/typed_text.h"
-
-#include "font/ui_font.h"
-#include "graphic_log.h"
-#include "mem_api.h"
-#include "transform.h"
-
-namespace OHOS {
-Point TypedText::GetTextSize(const char* text, int16_t letterSpace, int16_t lineSpace, int16_t maxWidth)
-{
- Point size{0, 0};
- if (text == nullptr) {
- GRAPHIC_LOGE("TypedText::GetTextSize text invalid parameter\n");
- return size;
- }
-
- uint32_t lineBegin = 0;
- uint32_t nextLineBegin = 0;
- uint16_t lineHeight = UIFont::GetInstance()->GetHeight();
- while (text[lineBegin] != '\0') {
- nextLineBegin += GetNextLine(&text[lineBegin], letterSpace, maxWidth);
- size.y += lineHeight;
- size.y += lineSpace;
- size.x = MATH_MAX(GetTextWidth(&text[lineBegin], nextLineBegin - lineBegin, letterSpace), size.x);
- lineBegin = nextLineBegin;
- }
-
- if (size.y == 0) {
- size.y = lineHeight;
- } else {
- size.y -= lineSpace;
- }
- return size;
-}
-
-void TypedText::GetArcTextRect(Rect& rect,
- const char* text,
- const Point& arcCenter,
- int16_t letterSpace,
- UIArcLabel::TextOrientation orientation,
- const UIArcLabel::ArcTextInfo arcTextInfo)
-{
- if (text == nullptr || arcTextInfo.lineStart == arcTextInfo.lineEnd || arcTextInfo.radius == 0 ||
- arcTextInfo.lineEnd > strlen(text)) {
- GRAPHIC_LOGE("TypedText::GetArcTextRect invalid parameter\n");
- return;
- }
-
- uint16_t letterHeight = UIFont::GetInstance()->GetHeight();
- uint16_t letterWidth;
-
- int16_t posX = arcCenter.x + static_cast(arcTextInfo.radius * Sin(arcTextInfo.startAngle));
- int16_t posY =
- arcCenter.y - static_cast(arcTextInfo.radius * Sin(arcTextInfo.startAngle + QUARTER_IN_DEGREE));
- rect.SetPosition(posX, posY);
-
- uint32_t i = arcTextInfo.lineStart;
- uint32_t tmp;
- uint32_t letter;
- uint16_t angle = arcTextInfo.startAngle;
- Rect rectLetter;
- TransformMap transform;
- while (i < arcTextInfo.lineEnd) {
- tmp = i;
- letter = GetUTF8Next(text, tmp, i);
- if (letter == '\r' || letter == '\n') {
- break;
- }
- letterWidth = UIFont::GetInstance()->GetWidth(letter, 0);
-
- rectLetter.SetPosition(posX, posY);
- rectLetter.Resize(letterWidth, letterHeight);
- transform.SetPolygon(Polygon(rectLetter));
- int16_t rotateAngle =
- ((orientation == UIArcLabel::TextOrientation::INSIDE) ? angle : (angle - SEMICIRCLE_IN_DEGREE));
- transform.Rotate(rotateAngle, Vector2(posX, posY));
- rect.Join(rect, transform.GetBoxRect());
- uint32_t arcLen = letterWidth + letterSpace;
- if (arcTextInfo.direct == TEXT_DIRECT_LTR) {
- angle += (SEMICIRCLE_IN_DEGREE * arcLen) / (UI_PI * arcTextInfo.radius);
- } else {
- angle += CIRCLE_IN_DEGREE - (SEMICIRCLE_IN_DEGREE * arcLen) / (UI_PI * arcTextInfo.radius);
- }
- angle = angle % CIRCLE_IN_DEGREE;
- posX = arcCenter.x + static_cast(arcTextInfo.radius * Sin(angle));
- posY = arcCenter.y - static_cast(arcTextInfo.radius * Sin(angle + QUARTER_IN_DEGREE));
- }
-}
-
-uint32_t TypedText::GetNextLine(const char* text, int16_t letterSpace, int16_t maxWidth)
-{
- int16_t lastBreakPos = 0;
- int16_t curW = 0;
- uint32_t index = 0;
- uint32_t tmp = 0;
- if (GetWrapPoint(text, index)) {
- return index;
- }
-
- while (true) {
- curW = TypedText::GetTextWidth(text, index, letterSpace);
- if (curW > maxWidth) {
- index = lastBreakPos;
- if (lastBreakPos == 0) {
- curW = 0;
- uint32_t i = 0;
- uint32_t letter = 0;
- int16_t letterWidth = 0;
- while (text[i] != '\0') {
- tmp = i;
- letter = TypedText::GetUTF8Next(text, tmp, i);
- letterWidth = UIFont::GetInstance()->GetWidth(letter, 0);
- curW += letterWidth;
- if (letterWidth > 0) {
- curW += letterSpace;
- }
- if (curW > maxWidth) {
- index = lastBreakPos;
- return index;
- } else {
- lastBreakPos = i;
- }
- }
- }
- break;
- }
- if (index > 0 && index < strlen(text) && (text[index - 1] == '\r' || text[index - 1] == '\n')) {
- break;
- }
- lastBreakPos = index;
- if (text[index] == '\0') {
- break;
- }
- if (GetWrapPoint(text + index, tmp)) {
- return index + tmp;
- }
- index += tmp;
- if (lastBreakPos == index) {
- break;
- }
- }
- return index;
-}
-
-bool TypedText::GetWrapPoint(const char* text, uint32_t& breakPoint)
-{
- breakPoint = 0;
- uint32_t j = 0;
- uint32_t letter = 0;
- if (text == nullptr) {
- return true;
- }
-
- while (text[breakPoint] != '\0') {
- letter = GetUTF8Next(text, breakPoint, j);
- breakPoint = j;
- if (letter == ' ' || letter == '.' || letter == ',' || letter == '!' || letter == '=' || letter == '?') {
- return false;
- }
- if (letter == '\n') {
- return true;
- }
- if (letter == '\r' && GetUTF8Next(text, breakPoint, j) == '\n') {
- breakPoint = j;
- return true;
- }
- }
- return false;
-}
-
-uint16_t TypedText::GetTextWidth(const char* text, uint32_t length, int16_t letterSpace)
-{
- if (text == nullptr || length == 0 || length > strlen(text)) {
- GRAPHIC_LOGE("TypedText::GetTextWidth invalid parameter\n");
- return 0;
- }
-
- uint32_t i = 0;
- uint32_t tmp;
- uint16_t width = 0;
- uint32_t letter;
-
- while (i < length) {
- tmp = i;
- letter = GetUTF8Next(text, tmp, i);
- if (letter == '\n' || letter == '\r') {
- continue;
- }
- uint16_t charWidth = UIFont::GetInstance()->GetWidth(letter, 0);
- width += charWidth;
- width += letterSpace;
- }
-
- if (width > 0) {
- width -= letterSpace;
- }
- return width;
-}
-
-uint8_t TypedText::GetUTF8OneCharacterSize(const char* str)
-{
- unsigned char c = str[0];
- if (c <= 0x7F) {
- return 1;
- } else if (c >= 0xC0 && c <= 0xDF) {
- return 2; // 2: 2 bytes
- } else if (c >= 0xE0 && c <= 0xEF) {
- return 3; // 3: 3 bytes
- } else if (c >= 0xF0 && c <= 0xF7) {
- return 4; // 4: 4 bytes
- } else {
- return 0;
- }
-}
-
-uint32_t TypedText::GetUTF8Next(const char* text, uint32_t i, uint32_t& j)
-{
- uint32_t unicoode = 0;
- if (text == nullptr) {
- GRAPHIC_LOGE("text invalid parameter");
- return 0;
- }
-
- j = i;
- uint8_t lettetSize = GetUTF8OneCharacterSize(text + i);
- switch (lettetSize) {
- case 1:
- unicoode = text[j];
- break;
- case 2: // 2: letter size
- unicoode = static_cast(text[j] & 0x1F) << UTF8_TO_UNICODE_SHIFT1;
- break;
- case 3: // 3: letter size
- unicoode = static_cast(text[j] & 0x0F) << UTF8_TO_UNICODE_SHIFT2;
- unicoode += static_cast(text[++j] & 0x3F) << UTF8_TO_UNICODE_SHIFT1;
- unicoode += (text[++j] & 0x3F);
- break;
- case 4: // 4: letter size
- unicoode = static_cast(text[j] & 0x07) << UTF8_TO_UNICODE_SHIFT3;
- unicoode += static_cast(text[++j] & 0x3F) << UTF8_TO_UNICODE_SHIFT2;
- unicoode += static_cast(text[++j] & 0x3F) << UTF8_TO_UNICODE_SHIFT1;
- unicoode += text[++j] & 0x3F;
- break;
- default:
- break;
- }
- j++;
- return unicoode;
-}
-
-uint32_t TypedText::GetByteIndexFromUTF8Id(const char* text, uint32_t utf8Id)
-{
- if (text == nullptr) {
- GRAPHIC_LOGE("TypedText::GetByteIndexFromUTF8Id text invalid parameter\n");
- return 0;
- }
- uint32_t byteIndex = 0;
- for (uint32_t i = 0; i < utf8Id; i++) {
- byteIndex += GetUTF8OneCharacterSize(&text[byteIndex]);
- }
-
- return byteIndex;
-}
-
-uint32_t TypedText::GetUTF8CharacterSize(const char* text, uint32_t byteIndex)
-{
- uint32_t i = 0;
- uint32_t size = 0;
- uint32_t tmp;
-
- if (text == nullptr) {
- GRAPHIC_LOGE("TypedText::GetUTF8CharacterSize text invalid parameter\n");
- return 0;
- }
- while (text[i] != '\0' && i < byteIndex) {
- tmp = i;
- GetUTF8Next(text, tmp, i);
- size++;
- }
-
- return size;
-}
-} // namespace OHOS
\ No newline at end of file
diff --git a/frameworks/ui/src/common/ui_text_language.cpp b/frameworks/ui/src/common/ui_text_language.cpp
deleted file mode 100755
index 4d3df3f..0000000
--- a/frameworks/ui/src/common/ui_text_language.cpp
+++ /dev/null
@@ -1,163 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#include "common/ui_text_language.h"
-#include "font/ui_font_header.h"
-
-namespace OHOS {
-static UITextLanguageFontParam g_uiTextLangFontsTable[LANGUAGE_FONT_ID_MAX] = {
- {14, 4, 0, 0, "RobotoCondensed-Regular"},
- {18, 4, 0, 0, "RobotoCondensed-Regular"},
- {20, 4, 0, 0, "RobotoCondensed-Regular"},
- {23, 4, 0, 0, "RobotoCondensed-Regular"},
- {23, 4, 0, 0, "RobotoCondensed-Regular"},
- {26, 4, 0, 0, "RobotoCondensed-Regular"},
- {28, 4, 0, 0, "RobotoCondensed-Regular"},
- {30, 4, 0, 0, "RobotoCondensed-Regular"},
- {38, 4, 0, 0, "RobotoCondensed-Regular"},
- {48, 4, 0, 0, "RobotoCondensed-Regular"},
- {14, 4, 1, 2, "NotoNaskhArabic-Regular"},
- {18, 4, 1, 2, "NotoNaskhArabic-Regular"},
- {24, 4, 1, 2, "NotoNaskhArabic-Regular"},
- {30, 4, 1, 2, "NotoNaskhArabic-Regular"},
- {38, 4, 1, 2, "NotoNaskhArabic-Regular"},
- {20, 4, 1, 2, "NotoNaskhArabic-Regular"},
- {23, 4, 1, 2, "NotoNaskhArabic-Regular"},
- {26, 4, 1, 2, "NotoNaskhArabic-Regular"},
- {28, 4, 1, 2, "NotoNaskhArabic-Regular"},
- {48, 4, 1, 2, "NotoNaskhArabic-Regular"},
- {14, 4, 0, 3, "NotoSansCJKjp-Regular"},
- {18, 4, 0, 3, "NotoSansCJKjp-Regular"},
- {24, 4, 0, 3, "NotoSansCJKjp-Regular"},
- {20, 4, 0, 3, "NotoSansCJKjp-Regular"},
- {23, 4, 0, 3, "NotoSansCJKjp-Regular"},
- {26, 4, 0, 3, "NotoSansCJKjp-Regular"},
- {28, 4, 0, 3, "NotoSansCJKjp-Regular"},
- {30, 4, 0, 3, "NotoSansCJKjp-Regular"},
- {38, 4, 0, 3, "NotoSansCJKjp-Regular"},
- {48, 4, 0, 3, "NotoSansCJKjp-Regular"},
- {14, 4, 0, 4, "NotoSansCJKkr-Regular"},
- {18, 4, 0, 4, "NotoSansCJKkr-Regular"},
- {24, 4, 0, 4, "NotoSansCJKkr-Regular"},
- {20, 4, 0, 4, "NotoSansCJKkr-Regular"},
- {23, 4, 0, 4, "NotoSansCJKkr-Regular"},
- {26, 4, 0, 4, "NotoSansCJKkr-Regular"},
- {28, 4, 0, 4, "NotoSansCJKkr-Regular"},
- {30, 4, 0, 4, "NotoSansCJKkr-Regular"},
- {38, 4, 0, 4, "NotoSansCJKkr-Regular"},
- {48, 4, 0, 4, "NotoSansCJKkr-Regular"},
- {14, 4, 1, 5, "NotoSansThai-Regular"},
- {18, 4, 1, 5, "NotoSansThai-Regular"},
- {24, 4, 1, 5, "NotoSansThai-Regular"},
- {30, 4, 1, 5, "NotoSansThai-Regular"},
- {38, 4, 1, 5, "NotoSansThai-Regular"},
- {14, 4, 0, 6, "NotoSansHebrew-Regular"},
- {18, 4, 0, 6, "NotoSansHebrew-Regular"},
- {24, 4, 0, 6, "NotoSansHebrew-Regular"},
- {30, 4, 0, 6, "NotoSansHebrew-Regular"},
- {38, 4, 0, 6, "NotoSansHebrew-Regular"},
- {20, 4, 0, 6, "NotoSansHebrew-Regular"},
- {23, 4, 0, 6, "NotoSansHebrew-Regular"},
- {26, 4, 0, 6, "NotoSansHebrew-Regular"},
- {28, 4, 0, 6, "NotoSansHebrew-Regular"},
- {48, 4, 0, 6, "NotoSansHebrew-Regular"},
- {20, 4, 1, 5, "NotoSansThai-Regular"},
- {23, 4, 1, 5, "NotoSansThai-Regular"},
- {26, 4, 1, 5, "NotoSansThai-Regular"},
- {28, 4, 1, 5, "NotoSansThai-Regular"},
- {48, 4, 1, 5, "NotoSansThai-Regular"},
- {14, 4, 0, 7, "NotoSansDevanagari-Regular"},
- {18, 4, 0, 7, "NotoSansDevanagari-Regular"},
- {24, 4, 0, 7, "NotoSansDevanagari-Regular"},
- {20, 4, 0, 7, "NotoSansDevanagari-Regular"},
- {23, 4, 0, 7, "NotoSansDevanagari-Regular"},
- {26, 4, 0, 7, "NotoSansDevanagari-Regular"},
- {28, 4, 0, 7, "NotoSansDevanagari-Regular"},
- {30, 4, 0, 7, "NotoSansDevanagari-Regular"},
- {38, 4, 0, 7, "NotoSansDevanagari-Regular"},
- {48, 4, 0, 7, "NotoSansDevanagari-Regular"},
-}; // g_uiTextLangFontsTable
-
-static LangTextParam g_langTextDefaultParamTable[LANGUAGE_MAX] = {
- {0, 30, "RobotoCondensed-Regular", "en"},
- {0, 30, "RobotoCondensed-Regular", "fr"},
- {0, 30, "RobotoCondensed-Regular", "de"},
- {0, 30, "RobotoCondensed-Regular", "pt"},
- {0, 30, "RobotoCondensed-Regular", "ru"},
- {0, 30, "RobotoCondensed-Regular", "es"},
- {0, 30, "RobotoCondensed-Regular", "it"},
- {0, 30, "RobotoCondensed-Regular", "pl"},
- {0, 30, "RobotoCondensed-Regular", "en"},
- {0, 30, "RobotoCondensed-Regular", "tr"},
- {0, 30, "RobotoCondensed-Regular", "da"},
- {0, 30, "RobotoCondensed-Regular", "sv"},
- {0, 30, "RobotoCondensed-Regular", "no"},
- {0, 30, "RobotoCondensed-Regular", "fi"},
- {0, 30, "NotoSansCJKjp-Regular", "jv"},
- {0, 30, "NotoSansCJKkr-Regular", "ko"},
- {1, 30, "NotoNaskhArabic-Regular", "ar"},
- {0, 30, "RobotoCondensed-Regular", "pt"},
- {0, 30, "RobotoCondensed-Regular", "es"},
- {0, 30, "NotoSansThai-Regular", "th"},
- {0, 30, "RobotoCondensed-Regular", "vi"},
- {1, 30, "NotoSansHebrew-Regular", "he"},
- {0, 30, "RobotoCondensed-Regular", "cs"},
- {0, 30, "RobotoCondensed-Regular", "sk"},
- {0, 30, "RobotoCondensed-Regular", "nl"},
- {0, 30, "RobotoCondensed-Regular", "el"},
- {0, 30, "RobotoCondensed-Regular", "hu"},
- {0, 30, "RobotoCondensed-Regular", "ms"},
- {0, 30, "RobotoCondensed-Regular", "ro"},
- {0, 30, "RobotoCondensed-Regular", "sr"},
- {0, 30, "NotoSansDevanagari-Regular", "hi"},
- {0, 30, "RobotoCondensed-Regular", "uk"},
- {0, 30, "RobotoCondensed-Regular", "my"},
- {0, 30, "RobotoCondensed-Regular", "id"},
- {0, 30, "RobotoCondensed-Regular", "bg"},
- {0, 30, "RobotoCondensed-Regular", "hr"},
- {0, 30, "RobotoCondensed-Regular", "sl"},
- {0, 30, "RobotoCondensed-Regular", "lt"},
- {0, 30, "RobotoCondensed-Regular", "lv"},
- {0, 30, "RobotoCondensed-Regular", "et"},
-}; // g_langTextDefaultParamTable
-
-UITextLanguageFontParam* GetTextLangFontsTable(uint8_t langFontId)
-{
- if (langFontId >= LANGUAGE_FONT_ID_MAX) {
- return nullptr;
- }
- return &(g_uiTextLangFontsTable[langFontId]);
-}
-
-uint8_t GetTotalLangId()
-{
- return LANGUAGE_MAX;
-}
-
-uint8_t GetTotalFontId()
-{
- return LANGUAGE_FONT_ID_MAX;
-}
-
-uint16_t GetTotalTextId()
-{
- return LANGUAGE_TEXT_ID_MAX;
-}
-
-LangTextParam* GetLangTextDefaultParamTable()
-{
- return g_langTextDefaultParamTable;
-}
-} // namespace OHOS
diff --git a/frameworks/ui/src/components/root_view.cpp b/frameworks/ui/src/components/root_view.cpp
deleted file mode 100755
index 43081e6..0000000
--- a/frameworks/ui/src/components/root_view.cpp
+++ /dev/null
@@ -1,201 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#include "components/root_view.h"
-#include "common/screen.h"
-#include "common/screen_device_proxy.h"
-#include "core/render_manager.h"
-#include "graphic_log.h"
-#include "securec.h"
-#if ENABLE_WINDOW
-#include "window/window_impl.h"
-#endif
-
-namespace OHOS {
-RootView::RootView()
- : onKeyActListener_(nullptr), onVirtualEventListener_(nullptr), invalidRect_(0, 0, 0, 0), renderFlag_(false),
- stackCount_(0), viewStack_ { { 0 } }
-{
-#if ENABLE_WINDOW
- boundWindow_ = nullptr;
-#endif
-
-#if defined __linux__ || defined __LITEOS__
- pthread_mutex_init(&lock_, nullptr);
-#endif
-}
-
-#if ENABLE_WINDOW
-Window* RootView::GetBoundWindow() const
-{
- return boundWindow_;
-}
-#endif
-
-void RootView::AddInvalidateRect(Rect& rect)
-{
-#if defined __linux__ || defined __LITEOS__
- pthread_mutex_lock(&lock_);
-#endif
-
-#if ENABLE_WINDOW
- Rect screenRect = GetRect();
-#else
- Rect screenRect(0, 0, Screen::GetInstance().GetWidth() - 1, Screen::GetInstance().GetHeight() - 1);
-#endif
-
- Rect commonRect;
- if (commonRect.Intersect(rect, screenRect)) {
- invalidRect_.Join(invalidRect_, commonRect);
- renderFlag_ = true;
- }
-
-#if defined __linux__ || defined __LITEOS__
- pthread_mutex_unlock(&lock_);
-#endif
-}
-
-void RootView::Render()
-{
-#if defined __linux__ || defined __LITEOS__
- pthread_mutex_lock(&lock_);
-#endif
-
- if (renderFlag_) {
- RenderManager::RenderRect(invalidRect_, this);
-#if ENABLE_WINDOW
- if (boundWindow_) {
- boundWindow_->Flush();
- boundWindow_->Update();
- }
-#endif
- ScreenDeviceProxy::GetInstance()->OnRenderFinish();
- }
-
- renderFlag_ = false;
- invalidRect_ = { 0, 0, 0, 0 };
-#if defined __linux__ || defined __LITEOS__
- pthread_mutex_unlock(&lock_);
-#endif
-}
-
-void RootView::DrawTop(UIView* view, const Rect& rect)
-{
- if (view == nullptr) {
- return;
- }
- stackCount_ = 0;
- UIView* par = view->GetParent();
- if (par == nullptr) {
- par = view;
- }
- UIView* curView = view;
- Rect curViewRect;
- Rect mask = rect;
- while (par != nullptr) {
- if (curView != nullptr) {
- if (curView->IsVisible()) {
- curViewRect = curView->GetMaskedRect();
- if (curViewRect.Intersect(curViewRect, mask)) {
- curView->OnDraw(curViewRect);
- if (curView->IsViewGroup() && stackCount_ < COMPONENT_NESTING_DEPTH) {
- par = curView;
- viewStack_[stackCount_] = {
- curView, mask.GetLeft(), mask.GetTop(), mask.GetRight(), mask.GetBottom()
- };
- stackCount_++;
- curView = static_cast(curView)->GetChildrenHead();
- mask = par->GetContentRect();
- mask.Intersect(mask, curViewRect);
- continue;
- }
- curView->OnPostDraw(curViewRect);
- }
- }
- curView = curView->GetNextSibling();
- } else if (--stackCount_ >= 0) {
- ViewMask sides = viewStack_[stackCount_];
- mask = { sides.left, sides.top, sides.right, sides.bottom };
- curViewRect = par->GetMaskedRect();
- if (curViewRect.Intersect(curViewRect, mask)) {
- par->OnPostDraw(curViewRect);
- }
- curView = sides.view->GetNextSibling();
- par = par->GetParent();
- } else {
- stackCount_ = 0;
- curView = par->GetNextSibling();
- par = par->GetParent();
- }
- }
-}
-
-UIView* RootView::GetTopUIView(const Rect& rect)
-{
- int16_t stackCount_ = 0;
- UIView* currentView = this;
- UIView* topView = nullptr;
- while (stackCount_ >= 0) {
- while (currentView != nullptr) {
- if (currentView->GetRect().IsContains(rect) && currentView->IsVisible()) {
- if (currentView->GetStyleConst().bgOpa_ == OPA_OPAQUE && currentView->OnPreDraw(rect)) {
- topView = currentView;
- }
- if (currentView->IsViewGroup() && stackCount_ < COMPONENT_NESTING_DEPTH) {
- viewStack_[stackCount_++].view = currentView;
- currentView = static_cast(currentView)->GetChildrenHead();
- continue;
- }
- }
- currentView = currentView->GetNextSibling();
- }
- if (--stackCount_ >= 0) {
- currentView = (viewStack_[stackCount_].view)->GetNextSibling();
- }
- }
- return topView;
-}
-
-bool RootView::FindSubView(const UIView& parentView, const UIView* subView)
-{
- const UIView* root = &parentView;
- if (root == subView) {
- return true;
- } else if (!root->IsViewGroup() || subView == nullptr) {
- return false;
- }
-
- UIView* currentView = static_cast(root)->GetChildrenHead();
- const UIView* parent = root;
- int8_t deep = 1;
- while (deep > 0) {
- if (currentView == subView) {
- return true;
- }
- if (currentView == nullptr) {
- currentView = parent->GetNextSibling();
- parent = parent->GetParent();
- deep--;
- } else if (currentView->IsViewGroup()) {
- parent = currentView;
- currentView = static_cast(currentView)->GetChildrenHead();
- deep++;
- } else {
- currentView = currentView->GetNextSibling();
- }
- }
- return false;
-}
-} // namespace OHOS
\ No newline at end of file
diff --git a/frameworks/ui/src/components/text_adapter.cpp b/frameworks/ui/src/components/text_adapter.cpp
deleted file mode 100755
index e76abff..0000000
--- a/frameworks/ui/src/components/text_adapter.cpp
+++ /dev/null
@@ -1,234 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#include "components/text_adapter.h"
-#include
-#include "components/ui_label.h"
-#include "securec.h"
-
-namespace OHOS {
-bool TextFormatter::Format(int16_t value, char* outText, uint16_t textLen)
-{
- if (sprintf_s(outText, textLen, "%d", value) < 0) {
- return false;
- }
- return true;
-}
-
-TextAdapter::TextAdapter()
- : fontName_(nullptr),
- fontSize_(0),
- width_(0),
- height_(0),
- direct_(UITextLanguageDirect::TEXT_DIRECT_LTR),
- lineBreakMode_(UILabel::LINE_BREAK_ADAPT),
- dataMode_(DYNAMIC_TEXT_MODE),
- integerTextStart_(0),
- integerTextEnd_(0),
- clickListener_(nullptr),
- formatter_(nullptr)
-{
- style_ = StyleDefault::GetBackgroundTransparentStyle();
- fontId_ = style_.font_;
-}
-
-TextAdapter::~TextAdapter()
-{
- ClearDynamicText();
- if (fontName_ != nullptr) {
- UIFree(fontName_);
- fontName_ = nullptr;
- }
-}
-
-void TextAdapter::SetFont(const char* name, uint8_t size)
-{
- Text::SetFont(name, size, fontName_, fontSize_);
-}
-
-UIView* TextAdapter::GetView(UIView* inView, int16_t index)
-{
- UILabel* newView = nullptr;
-
- switch (dataMode_) {
- case DYNAMIC_TEXT_MODE:
- newView = GetDynamicText(inView, index);
- break;
- case CONTINUOUS_INTEGER_MODE:
- newView = GetIntegerText(inView, index);
- break;
- default:
- break;
- }
-
- if (newView == nullptr) {
- return nullptr;
- }
- newView->SetLineBreakMode(lineBreakMode_);
- newView->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
- if (width_) {
- newView->SetWidth(width_);
- }
- if (height_) {
- newView->SetHeight(height_);
- }
- newView->SetViewIndex(index);
- newView->SetStyle(style_);
- newView->GetHeight();
- if (clickListener_) {
- newView->SetOnClickListener(clickListener_);
- newView->SetTouchable(true);
- }
- return newView;
-}
-
-UILabel* TextAdapter::GetDynamicText(UIView* inView, int16_t index)
-{
- if (dynamicText_.IsEmpty() || index > dynamicText_.Size() - 1 || index < 0) {
- return nullptr;
- }
-
- ListNode* node = dynamicText_.Begin();
- for (uint16_t i = 0; i < index; i++) {
- node = node->next_;
- }
- UILabel* newView = nullptr;
- if (inView == nullptr) {
- newView = new UILabel();
- } else {
- newView = static_cast(inView);
- }
-
- if (newView != nullptr) {
- newView->SetText(node->data_);
- if (fontName_ == nullptr) {
- newView->SetFontId(fontId_);
- } else {
- newView->SetFont(fontName_, fontSize_);
- }
- newView->SetDirect(direct_);
- }
- return newView;
-}
-
-UILabel* TextAdapter::GetIntegerText(UIView* inView, int16_t index)
-{
- if ((index < 0) || ((integerTextEnd_ - integerTextStart_) < index)) {
- return nullptr;
- }
- UILabel* newView = nullptr;
- if (inView == nullptr) {
- newView = new UILabel();
- } else {
- newView = static_cast(inView);
- }
-
- if (newView != nullptr) {
- char buf[BUF_LEN] = {0};
- if (formatter_ != nullptr) {
- if (!formatter_->Format(integerTextStart_ + index, buf, BUF_LEN)) {
- if (inView == nullptr) {
- delete newView;
- newView = nullptr;
- }
- return nullptr;
- }
- } else {
- if (sprintf_s(buf, sizeof(buf), "%02d", integerTextStart_ + index) < 0) {
- if (inView == nullptr) {
- delete newView;
- newView = nullptr;
- }
- return nullptr;
- }
- }
-
- buf[BUF_LEN - 1] = '\0';
- newView->SetText(buf);
- if (fontName_ == nullptr) {
- newView->SetFontId(fontId_);
- } else {
- newView->SetFont(fontName_, fontSize_);
- }
- newView->SetDirect(direct_);
- }
- return newView;
-}
-
-void TextAdapter::ClearDynamicText()
-{
- ListNode* node = dynamicText_.Begin();
- while (node != dynamicText_.End()) {
- if (node->data_) {
- UIFree(reinterpret_cast(const_cast(node->data_)));
- node->data_ = nullptr;
- }
- node = node->next_;
- }
- dynamicText_.Clear();
-}
-
-void TextAdapter::SetData(List* data)
-{
- if (data == nullptr) {
- return;
- }
- if (!dynamicText_.IsEmpty()) {
- ClearDynamicText();
- }
- ListNode* node = data->Begin();
- while (node != data->End()) {
- uint32_t len = strlen(node->data_);
- char* stringData = static_cast(UIMalloc(len + 1));
- if (stringData == nullptr) {
- return;
- }
- if (memcpy_s(stringData, len + 1, node->data_, len) != EOK) {
- UIFree(reinterpret_cast(stringData));
- stringData = nullptr;
- return;
- }
- stringData[len] = '\0';
- dynamicText_.PushBack(stringData);
- node = node->next_;
- }
- dataMode_ = DYNAMIC_TEXT_MODE;
-}
-
-void TextAdapter::SetData(int16_t start, int16_t end)
-{
- if (start <= end) {
- integerTextStart_ = start;
- integerTextEnd_ = end;
- dataMode_ = CONTINUOUS_INTEGER_MODE;
- }
-}
-
-uint16_t TextAdapter::GetCount()
-{
- switch (dataMode_) {
- case DYNAMIC_TEXT_MODE:
- return dynamicText_.Size();
- case CONTINUOUS_INTEGER_MODE:
- if (integerTextStart_ <= integerTextEnd_) {
- return (integerTextEnd_ - integerTextStart_ + 1);
- }
- break;
- default:
- return 0;
- }
- return 0;
-}
-} // namespace OHOS
\ No newline at end of file
diff --git a/frameworks/ui/src/components/ui_abstract_clock.cpp b/frameworks/ui/src/components/ui_abstract_clock.cpp
deleted file mode 100755
index c6e0b46..0000000
--- a/frameworks/ui/src/components/ui_abstract_clock.cpp
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#include "components/ui_abstract_clock.h"
-
-namespace OHOS {
-void UIAbstractClock::SetTime24Hour(uint8_t hour, uint8_t minute, uint8_t second)
-{
- currentHour_ = hour % ONE_DAY_IN_HOUR;
- currentMinute_ = minute % ONE_HOUR_IN_MINUTE;
- currentSecond_ = second % ONE_MINUTE_IN_SECOND;
- UpdateClock(false);
-}
-
-void UIAbstractClock::SetTime12Hour(uint8_t hour, uint8_t minute, uint8_t second, bool am)
-{
- SetTime24Hour((hour % HALF_DAY_IN_HOUR) + (am ? 0 : HALF_DAY_IN_HOUR), minute, second);
-}
-
-void UIAbstractClock::IncOneSecond()
-{
- currentSecond_++;
- currentMinute_ += currentSecond_ / ONE_MINUTE_IN_SECOND;
- currentSecond_ = currentSecond_ % ONE_MINUTE_IN_SECOND;
-
- currentHour_ += currentMinute_ / ONE_HOUR_IN_MINUTE;
- currentMinute_ = currentMinute_ % ONE_HOUR_IN_MINUTE;
- currentHour_ = currentHour_ % ONE_DAY_IN_HOUR;
-
- UpdateClock(false);
-}
-
-void UIAbstractClock::SetWorkMode(WorkMode newMode)
-{
- if (mode_ != newMode) {
- mode_ = newMode;
- Invalidate();
- }
-}
-
-void UIAbstractClock::UpdateClock(bool clockInit)
-{
- Invalidate();
-}
-} // namespace OHOS
\ No newline at end of file
diff --git a/frameworks/ui/src/components/ui_abstract_progress.cpp b/frameworks/ui/src/components/ui_abstract_progress.cpp
deleted file mode 100755
index f6773e4..0000000
--- a/frameworks/ui/src/components/ui_abstract_progress.cpp
+++ /dev/null
@@ -1,198 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#include "components/ui_abstract_progress.h"
-#include "common/image.h"
-#include "draw/draw_utils.h"
-#include "graphic_log.h"
-#include "imgdecode/cache_manager.h"
-#include "themes/theme_manager.h"
-
-namespace OHOS {
-UIAbstractProgress::UIAbstractProgress()
- : enableBackground_(true),
- backgroundStyleAllocFlag_(false),
- foregroundStyleAllocFlag_(false),
- backgroundImage_(nullptr),
- foregroundImage_(nullptr),
- rangeMax_(MAX_PERCENT_VALUE),
- rangeMin_(MIN_PERCENT_VALUE),
- curValue_(0),
- step_(1),
- lastValue_(0)
-{
- style_ = &(StyleDefault::GetBackgroundTransparentStyle());
- Theme* theme = ThemeManager::GetInstance().GetCurrent();
- if (theme != nullptr) {
- backgroundStyle_ = &(theme->GetProgressBackgroundStyle());
- foregroundStyle_ = &(theme->GetProgressForegroundStyle());
- } else {
- backgroundStyle_ = &(StyleDefault::GetProgressBackgroundStyle());
- foregroundStyle_ = &(StyleDefault::GetProgressForegroundStyle());
- }
-}
-
-UIAbstractProgress::~UIAbstractProgress()
-{
- if (backgroundImage_ != nullptr) {
- delete backgroundImage_;
- backgroundImage_ = nullptr;
- }
-
- if (foregroundImage_ != nullptr) {
- delete foregroundImage_;
- foregroundImage_ = nullptr;
- }
-
- if (backgroundStyleAllocFlag_) {
- delete backgroundStyle_;
- backgroundStyle_ = nullptr;
- backgroundStyleAllocFlag_ = false;
- }
-
- if (foregroundStyleAllocFlag_) {
- delete foregroundStyle_;
- foregroundStyle_ = nullptr;
- foregroundStyleAllocFlag_ = false;
- }
-}
-
-void UIAbstractProgress::SetRange(int16_t rangeMax, int16_t rangeMin)
-{
- if (rangeMax >= rangeMin) {
- rangeMax_ = rangeMax;
- rangeMin_ = rangeMin;
- lastValue_ = rangeMin;
- SetValue(curValue_);
- } else {
- GRAPHIC_LOGW("UIAbstractProgress::SetRange rangeMax less than rangeMin !\n");
- }
-};
-
-void UIAbstractProgress::SetValue(int16_t value)
-{
- if (value < rangeMin_) {
- curValue_ = rangeMin_;
- } else if (value > rangeMax_) {
- curValue_ = rangeMax_;
- } else {
- curValue_ = value;
- }
-
- if ((curValue_ != lastValue_) &&
- (curValue_ == rangeMin_ || curValue_ == rangeMax_ || (MATH_ABS(curValue_ - lastValue_) >= step_))) {
- Invalidate();
- lastValue_ = curValue_;
- }
-}
-
-int16_t UIAbstractProgress::GetCurrentPos(int16_t distance) const
-{
- uint32_t delta = lastValue_ - rangeMin_;
- uint16_t rangeSize = GetRangeSize();
- if (rangeSize == 0) {
- return distance;
- }
- int16_t result = delta * distance / rangeSize;
- return result;
-}
-
-uint16_t UIAbstractProgress::GetRangeSize() const
-{
- return (rangeMax_ < rangeMin_) ? 0 : (rangeMax_ - rangeMin_);
-}
-
-void UIAbstractProgress::SetImage(const char* foregroundImage, const char* backgroundImage)
-{
- if (backgroundImage_ == nullptr) {
- backgroundImage_ = new Image();
- }
- backgroundImage_->SetSrc(backgroundImage);
-
- if (foregroundImage_ == nullptr) {
- foregroundImage_ = new Image();
- }
- foregroundImage_->SetSrc(foregroundImage);
-}
-
-void UIAbstractProgress::SetImage(const ImageInfo* foregroundImage, const ImageInfo* backgroundImage)
-{
- if (backgroundImage_ == nullptr) {
- backgroundImage_ = new Image();
- }
- backgroundImage_->SetSrc(backgroundImage);
-
- if (foregroundImage_ == nullptr) {
- foregroundImage_ = new Image();
- }
- foregroundImage_->SetSrc(foregroundImage);
-}
-
-void UIAbstractProgress::SetBackgroundStyle(const Style& style)
-{
- if (!backgroundStyleAllocFlag_) {
- backgroundStyle_ = new Style;
- backgroundStyleAllocFlag_ = true;
- }
- *backgroundStyle_ = style;
-}
-
-void UIAbstractProgress::SetBackgroundStyle(uint8_t key, int64_t value)
-{
- if (!backgroundStyleAllocFlag_) {
- backgroundStyle_ = new Style(*backgroundStyle_);
- backgroundStyleAllocFlag_ = true;
- }
- backgroundStyle_->SetStyle(key, value);
-}
-
-const Style& UIAbstractProgress::GetBackgroundStyle() const
-{
- return *backgroundStyle_;
-}
-
-int64_t UIAbstractProgress::GetBackgroundStyle(uint8_t key) const
-{
- return backgroundStyle_->GetStyle(key);
-}
-
-void UIAbstractProgress::SetForegroundStyle(const Style& style)
-{
- if (!foregroundStyleAllocFlag_) {
- foregroundStyle_ = new Style;
- foregroundStyleAllocFlag_ = true;
- }
- *foregroundStyle_ = style;
-}
-
-void UIAbstractProgress::SetForegroundStyle(uint8_t key, int64_t value)
-{
- if (!foregroundStyleAllocFlag_) {
- foregroundStyle_ = new Style(*foregroundStyle_);
- foregroundStyleAllocFlag_ = true;
- }
- foregroundStyle_->SetStyle(key, value);
-}
-
-const Style& UIAbstractProgress::GetForegroundStyle() const
-{
- return *foregroundStyle_;
-}
-
-int64_t UIAbstractProgress::GetForegroundStyle(uint8_t key) const
-{
- return foregroundStyle_->GetStyle(key);
-}
-} // namespace OHOS
\ No newline at end of file
diff --git a/frameworks/ui/src/components/ui_abstract_scroll.cpp b/frameworks/ui/src/components/ui_abstract_scroll.cpp
deleted file mode 100755
index 01bf395..0000000
--- a/frameworks/ui/src/components/ui_abstract_scroll.cpp
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#include "components/ui_abstract_scroll.h"
-
-namespace OHOS {
-UIAbstractScroll::UIAbstractScroll()
- : scrollBlankSize_(0), reboundSize_(0), maxScrollDistance_(0), lastDeltaY_ { 0 },
- dragAccCoefficient_(DRAG_ACC_FACTOR), swipeAccCoefficient_(0),
- direction_(VERTICAL), deltaYIndex_(0), reserve_(0), throwDrag_(false),
- easingFunc_(EasingEquation::CubicEaseOut),
- animator_(&animatorCallback_, this, 0, true)
-{
- isViewGroup_ = true;
- touchable_ = true;
- SetDraggable(true);
- AnimatorManager::GetInstance()->Add(&animator_);
-}
-
-UIAbstractScroll::~UIAbstractScroll()
-{
- animator_.Stop();
- AnimatorManager::GetInstance()->Remove(&animator_);
-}
-
-void UIAbstractScroll::MoveChildByOffset(int16_t offsetX, int16_t offsetY)
-{
- if (offsetX == 0 && offsetY == 0) {
- return;
- }
- UIView* view = GetChildrenHead();
- int16_t x;
- int16_t y;
- while (view != nullptr) {
- x = view->GetX() + offsetX;
- y = view->GetY() + offsetY;
- view->SetPosition(x, y);
- view = view->GetNextSibling();
- }
- Invalidate();
-}
-
-int16_t UIAbstractScroll::GetMaxDeltaY() const
-{
- int16_t result = 0;
- for (int16_t i = 0; i < MAX_DELTA_Y_SIZE; i++) {
- if (result < MATH_ABS(lastDeltaY_[i])) {
- result = MATH_ABS(lastDeltaY_[i]);
- }
- }
- return result;
-}
-
-void UIAbstractScroll::StopAnimator()
-{
- animator_.Stop();
- animatorCallback_.RsetCallback();
- isDragging_ = false;
-}
-
-bool UIAbstractScroll::DragThrowAnimator(Point currentPos, Point lastPos)
-{
- if (!throwDrag_) {
- return false;
- }
- int16_t dragDistanceX = 0;
- int16_t dragDistanceY = 0;
-
- if (direction_ == VERTICAL || direction_ == HORIZONTAL_AND_VERTICAL) {
- dragDistanceY = (currentPos.y - lastPos.y) * DRAG_DISTANCE_COEFFICIENT;
- if (dragDistanceY > 0) {
- dragDistanceY += GetMaxDeltaY() * GetSwipeACCLevel() / DRAG_ACC_FACTOR;
- } else {
- dragDistanceY -= GetMaxDeltaY() * GetSwipeACCLevel() / DRAG_ACC_FACTOR;
- }
- }
-
- if (direction_ == HORIZONTAL || direction_ == HORIZONTAL_AND_VERTICAL) {
- dragDistanceX = (currentPos.x - lastPos.x) * DRAG_DISTANCE_COEFFICIENT;
- }
-
- if (maxScrollDistance_ != 0) {
- if (MATH_ABS(dragDistanceY) > maxScrollDistance_) {
- int16_t calculatedValue = (dragDistanceY > 0) ? 1 : -1;
- dragDistanceY = calculatedValue * maxScrollDistance_;
- }
- if (MATH_ABS(dragDistanceX) > maxScrollDistance_) {
- int16_t calculatedValue = (dragDistanceX > 0) ? 1 : -1;
- dragDistanceX = calculatedValue * maxScrollDistance_;
- }
- }
-
- int16_t dragTimes = MATH_MAX(MATH_ABS(dragDistanceX), MATH_ABS(dragDistanceY)) / DRAG_TIMES_COEFFICIENT;
- if (dragTimes < MIN_DRAG_TIMES) {
- dragTimes = MIN_DRAG_TIMES;
- }
- animatorCallback_.SetDragStartValue(0, 0);
- animatorCallback_.SetDragEndValue(dragDistanceX, dragDistanceY);
- animatorCallback_.SetDragTimes(dragTimes * DRAG_ACC_FACTOR / GetDragACCLevel());
- animator_.Start();
- return true;
-}
-
-void UIAbstractScroll::ListAnimatorCallback::Callback(UIView* view)
-{
- if (view == nullptr) {
- return;
- }
- curtTime_++;
-
- UIAbstractScroll* scrollView = static_cast(view);
- scrollView->isDragging_ = true;
- bool needStopX = false;
- bool needStopY = false;
- if (curtTime_ <= dragTimes_) {
- int16_t actY;
- int16_t actX;
- if (startValueY_ != endValueY_) {
- actY = scrollView->easingFunc_(startValueY_, endValueY_, curtTime_, dragTimes_);
- if (!scrollView->DragYInner(actY - previousValueY_)) {
- needStopY = true;
- }
- previousValueY_ = actY;
- } else {
- needStopY = true;
- }
- if (startValueX_ != endValueX_) {
- actX = scrollView->easingFunc_(startValueX_, endValueX_, curtTime_, dragTimes_);
- if (!scrollView->DragXInner(actX - previousValueX_)) {
- needStopX = true;
- }
- previousValueX_ = actX;
- } else {
- needStopX = true;
- }
- if (needStopX && needStopY) {
- scrollView->StopAnimator();
- }
- } else {
- scrollView->StopAnimator();
- }
-}
-} // namespace OHOS
\ No newline at end of file
diff --git a/frameworks/ui/src/components/ui_analog_clock.cpp b/frameworks/ui/src/components/ui_analog_clock.cpp
deleted file mode 100755
index 1a921f2..0000000
--- a/frameworks/ui/src/components/ui_analog_clock.cpp
+++ /dev/null
@@ -1,336 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#include "components/ui_analog_clock.h"
-#include "components/ui_image_view.h"
-#include "draw/draw_image.h"
-#include "draw/draw_line.h"
-#include "draw/draw_rect.h"
-#include "graphic_log.h"
-#include "imgdecode/cache_manager.h"
-#include "style.h"
-#include "themes/theme.h"
-
-namespace OHOS {
-UIAnalogClock::UIAnalogClock()
-{
- touchable_ = true;
-}
-
-void UIAnalogClock::SetHandImage(HandType type, const UIImageView& img, Point position, Point center)
-{
- Hand *hand = nullptr;
- if (type == HandType::HOUR_HAND) {
- hand = &hourHand_;
- } else if (type == HandType::MINUTE_HAND) {
- hand = &minuteHand_;
- } else {
- hand = &secondHand_;
- }
-
- hand->center_ = center;
- hand->position_ = position;
- hand->initAngle_ = 0;
- hand->preAngle_ = 0;
- hand->nextAngle_ = 0;
- hand->drawtype_ = DrawType::DRAW_IMAGE;
-
- if (img.GetSrcType() == IMG_SRC_FILE) {
- CacheEntry entry;
- RetCode ret = CacheManager::GetInstance().Open(img.GetPath(), *style_, entry);
- if (ret != RetCode::OK) {
- return;
- }
- hand->imageInfo_ = entry.GetImageInfo();
- } else {
- hand->imageInfo_ = *(img.GetImageInfo());
- }
-}
-
-void UIAnalogClock::SetHandLine(HandType type, Point position, Point center, ColorType color,
- uint16_t width, uint16_t height, OpacityType opacity)
-{
- Hand* hand = nullptr;
- if (type == HandType::HOUR_HAND) {
- hand = &hourHand_;
- } else if (type == HandType::MINUTE_HAND) {
- hand = &minuteHand_;
- } else {
- hand = &secondHand_;
- }
-
- hand->color_ = color;
- hand->height_ = height;
- hand->width_ = width;
- hand->position_ = position;
- hand->center_ = center;
- hand->opacity_ = opacity;
- hand->initAngle_ = 0;
- hand->preAngle_ = 0;
- hand->nextAngle_ = 0;
- hand->drawtype_ = DrawType::DRAW_LINE;
-}
-
-Point UIAnalogClock::GetHandRotateCenter(HandType type) const
-{
- if (type == HandType::HOUR_HAND) {
- return hourHand_.center_;
- } else if (type == HandType::MINUTE_HAND) {
- return minuteHand_.center_;
- } else {
- return secondHand_.center_;
- }
-}
-
-Point UIAnalogClock::GetHandPosition(HandType type) const
-{
- if (type == HandType::HOUR_HAND) {
- return hourHand_.position_;
- } else if (type == HandType::MINUTE_HAND) {
- return minuteHand_.position_;
- } else {
- return secondHand_.position_;
- }
-}
-
-uint16_t UIAnalogClock::GetHandInitAngle(HandType type) const
-{
- if (type == HandType::HOUR_HAND) {
- return hourHand_.initAngle_;
- } else if (type == HandType::MINUTE_HAND) {
- return minuteHand_.initAngle_;
- } else {
- return secondHand_.initAngle_;
- }
-}
-
-uint16_t UIAnalogClock::GetHandCurrentAngle(HandType type) const
-{
- if (type == HandType::HOUR_HAND) {
- return hourHand_.nextAngle_;
- } else if (type == HandType::MINUTE_HAND) {
- return minuteHand_.nextAngle_;
- } else {
- return secondHand_.nextAngle_;
- }
-}
-
-void UIAnalogClock::SetInitTime24Hour(uint8_t hour, uint8_t minute, uint8_t second)
-{
- currentHour_ = hour % ONE_DAY_IN_HOUR;
- currentMinute_ = minute % ONE_HOUR_IN_MINUTE;
- currentSecond_ = second % ONE_MINUTE_IN_SECOND;
-
- hourHand_.initAngle_ = ConvertHandValueToAngle(currentHour_,
- HALF_DAY_IN_HOUR, currentMinute_, ONE_HOUR_IN_MINUTE);
- hourHand_.preAngle_ = hourHand_.initAngle_;
- hourHand_.nextAngle_ = hourHand_.initAngle_;
-
- minuteHand_.initAngle_ = ConvertHandValueToAngle(currentMinute_,
- ONE_HOUR_IN_MINUTE, currentSecond_, ONE_MINUTE_IN_SECOND);
- minuteHand_.preAngle_ = minuteHand_.initAngle_;
- minuteHand_.nextAngle_ = minuteHand_.initAngle_;
-
- secondHand_.initAngle_ = ConvertHandValueToAngle(currentSecond_, ONE_MINUTE_IN_SECOND);
- secondHand_.preAngle_ = secondHand_.initAngle_;
- secondHand_.nextAngle_ = secondHand_.initAngle_;
-
- UpdateClock(true);
-}
-
-void UIAnalogClock::SetInitTime12Hour(uint8_t hour, uint8_t minute, uint8_t second, bool am)
-{
- SetInitTime24Hour((hour % HALF_DAY_IN_HOUR) + (am ? 0 : HALF_DAY_IN_HOUR), minute, second);
-}
-
-uint16_t UIAnalogClock::ConvertHandValueToAngle(uint8_t handValue, uint8_t range,
- uint8_t secondHandValue, uint8_t ratio) const
-{
- if (range == 0 || ratio == 0) {
- GRAPHIC_LOGW("UIAnalogClock::ConvertHandValueToAngle Invalid range or ratio\n");
- return 0;
- }
- /*
- * Example: calculate the angle of hour hand
- * Assume that the time is 5: 30, then range is 12, radio is 60
- * angle is [(5 * 60 + 30) / (12 * 60)] * 360
- */
- uint32_t degree = (static_cast(handValue) * ratio + secondHandValue);
- degree = static_cast(CIRCLE_IN_DEGREE * degree / (static_cast(range) * ratio));
-
- return static_cast(degree % CIRCLE_IN_DEGREE);
-}
-
-uint16_t UIAnalogClock::ConvertHandValueToAngle(uint8_t handValue, uint8_t range) const
-{
- if (range == 0) {
- GRAPHIC_LOGW("UIAnalogClock::ConvertHandValueToAngle Invalid range or ratio\n");
- return 0;
- }
- /*
- * Example: calculate the angle of second hand without millisecond handle
- * Assume that the time is 5:30:30, then range is 60
- * angle is (30 / 60) * 360
- */
- return (static_cast(handValue) * CIRCLE_IN_DEGREE / range);
-}
-
-void UIAnalogClock::UpdateClock(bool clockInit)
-{
- Invalidate();
- hourHand_.nextAngle_ = ConvertHandValueToAngle(currentHour_,
- HALF_DAY_IN_HOUR, currentMinute_, ONE_HOUR_IN_MINUTE);
-
- minuteHand_.nextAngle_ = ConvertHandValueToAngle(currentMinute_,
- ONE_HOUR_IN_MINUTE, currentSecond_, ONE_MINUTE_IN_SECOND);
-
- secondHand_.nextAngle_ = ConvertHandValueToAngle(currentSecond_, ONE_MINUTE_IN_SECOND);
-
- Rect rect = GetRect();
- CalculateRedrawArea(rect, hourHand_, clockInit);
- CalculateRedrawArea(rect, minuteHand_, clockInit);
- if (GetWorkMode() == WorkMode::NORMAL) {
- CalculateRedrawArea(rect, secondHand_, clockInit);
- }
-}
-
-void UIAnalogClock::OnDraw(const Rect& invalidatedArea)
-{
- DrawRect::Draw(GetRect(), invalidatedArea, *style_);
-}
-
-void UIAnalogClock::OnPostDraw(const Rect& invalidatedArea)
-{
- Rect current = GetOrigRect();
- DrawHand(current, invalidatedArea, hourHand_);
- DrawHand(current, invalidatedArea, minuteHand_);
- if (GetWorkMode() == WorkMode::NORMAL) {
- DrawHand(current, invalidatedArea, secondHand_);
- }
-}
-
-void UIAnalogClock::SetPosition(int16_t x, int16_t y)
-{
- UIViewGroup::SetPosition(x, y);
- UpdateClock(true);
-}
-
-void UIAnalogClock::SetPosition(int16_t x, int16_t y, int16_t width, int16_t height)
-{
- UIViewGroup::SetPosition(x, y, width, height);
- UpdateClock(true);
-}
-
-void UIAnalogClock::CalculateRedrawArea(const Rect& current, Hand& hand, bool clockInit)
-{
- /*
- * Use the current image as an independent rectangular area
- * to calculate the coordinate conversion coefficient.
- */
- int16_t imgWidth = hand.imageInfo_.header.width;
- int16_t imgHeight = hand.imageInfo_.header.height;
-
- int16_t left = hand.position_.x + current.GetLeft();
- int16_t right = left + imgWidth;
- int16_t top = hand.position_.y + current.GetTop();
- int16_t bottom = top + imgHeight;
- Rect imgRect(left, top, right, bottom);
- TransformMap backwardMap(imgRect);
- Vector2 pivot;
- pivot.x_ = hand.center_.x;
- pivot.y_ = hand.center_.y;
-
- /* Rotate the specified angle, */
- backwardMap.Rotate(hand.nextAngle_ - hand.initAngle_, pivot);
- Rect redraw = hand.target_;
- hand.target_ = backwardMap.GetBoxRect();
- hand.trans_ = backwardMap;
- hand.preAngle_ = hand.nextAngle_;
- if (clockInit == false) {
- /* Prevent old images from being residued */
- redraw.Join(redraw, hand.target_);
- InvalidateRect(redraw);
- }
-}
-
-void UIAnalogClock::DrawHand(const Rect& current, const Rect& invalidatedArea, Hand& hand)
-{
- if (hand.drawtype_ == DrawType::DRAW_IMAGE) {
- DrawHandImage(current, invalidatedArea, hand);
- } else {
- DrawHandLine(invalidatedArea, hand);
- }
-}
-
-void UIAnalogClock::DrawHandImage(const Rect& current, const Rect& invalidatedArea, Hand& hand)
-{
- uint8_t pxSize = DrawUtils::GetPxSizeByColorMode(hand.imageInfo_.header.colorMode);
- TransformDataInfo imageTranDataInfo = {
- hand.imageInfo_.header, hand.imageInfo_.data, pxSize,
- BlurLevel::LEVEL0, TransformAlgorithm::BILINEAR
- };
- DrawUtils::GetInstance()->DrawTransform(invalidatedArea, { 0, 0 },
- Color::Black(), hand.trans_, imageTranDataInfo);
-}
-
-void UIAnalogClock::DrawHandLine(const Rect& invalidatedArea, Hand& hand)
-{
- float sinma = Sin(hand.nextAngle_);
- float cosma = Sin(hand.nextAngle_ + THREE_QUARTER_IN_DEGREE);
- int32_t handLength = hand.height_;
- Rect rect = GetRect();
- Point start;
- Point end;
- Point curCenter;
- curCenter.x = hand.position_.x + hand.center_.x + rect.GetLeft();
- curCenter.y = hand.position_.y + hand.center_.y + rect.GetTop();
-
- int32_t startToCenterLength = hand.center_.y;
-
- int32_t xPointLength = static_cast(startToCenterLength * sinma);
- int32_t yPointLength = static_cast(startToCenterLength * cosma);
-
- start.x = xPointLength + curCenter.x;
- start.y = yPointLength + curCenter.y;
-
- /*
- * @ startToCenterLength: means the length between StartPoint and CenterPoint.
- * @ handlength: means the hand height.
- * @ xlength: means X-axis length relative to the center point
- * @ ylength: means Y-axis length relative to the center point
- */
- int32_t xlength = static_cast((startToCenterLength - handLength) * sinma);
- int32_t ylength = static_cast((startToCenterLength - handLength) * cosma);
- end.x = xlength + curCenter.x;
- end.y = ylength + curCenter.y;
-
- DrawLine::Draw(start, end, invalidatedArea, hand.width_, hand.color_, hand.opacity_);
-}
-
-void UIAnalogClock::SetWorkMode(WorkMode newMode)
-{
- WorkMode oldMode = mode_;
-
- if (oldMode != newMode) {
- /*
- * After entering the alwayson mode, all child controls are no longer drawn,
- * making the simplest analog clock.
- */
- isViewGroup_ = (newMode == ALWAYS_ON) ? false : true;
- mode_ = newMode;
- Invalidate();
- }
-}
-} // namespace OHOS
diff --git a/frameworks/ui/src/components/ui_arc_label.cpp b/frameworks/ui/src/components/ui_arc_label.cpp
deleted file mode 100755
index 4b2707a..0000000
--- a/frameworks/ui/src/components/ui_arc_label.cpp
+++ /dev/null
@@ -1,206 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#include "components/ui_arc_label.h"
-#include "common/typed_text.h"
-#include "draw/draw_label.h"
-#include "draw/draw_rect.h"
-#include "font/ui_font.h"
-#include "themes/theme_manager.h"
-
-namespace OHOS {
-UIArcLabel::UIArcLabel()
- : needRefresh_(false), textSize_ { 0, 0 }, radius_(0), startAngle_(0), endAngle_(0), arcCenter_({ 0, 0 }),
- orientation_(TextOrientation::INSIDE), arcTextInfo_ { 0 }
-{
- Theme* theme = ThemeManager::GetInstance().GetCurrent();
- style_ = (theme != nullptr) ? &(theme->GetLabelStyle()) : &(StyleDefault::GetLabelStyle());
-
- if (UIFont::GetInstance()->IsVectorFont()) {
- arcLabelText_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, 18); // 18: means font size
- } else {
- arcLabelText_.SetFontId(style_->font_);
- }
-}
-
-UIArcLabel::~UIArcLabel()
-{
-}
-
-void UIArcLabel::SetText(const char* text)
-{
- if (text == nullptr) {
- return;
- }
- arcLabelText_.SetText(text);
- if (arcLabelText_.IsNeedRefresh()) {
- RefreshArcLabel();
- }
-}
-
-const char* UIArcLabel::GetText() const
-{
- return arcLabelText_.GetText();
-}
-
-void UIArcLabel::SetAlign(UITextLanguageAlignment horizontalAlign)
-{
- arcLabelText_.SetAlign(horizontalAlign, TEXT_ALIGNMENT_TOP);
- if (arcLabelText_.IsNeedRefresh()) {
- RefreshArcLabel();
- }
-}
-
-UITextLanguageAlignment UIArcLabel::GetHorAlign() const
-{
- return arcLabelText_.GetHorAlign();
-}
-
-UITextLanguageDirect UIArcLabel::GetDirect()
-{
- return arcLabelText_.GetDirect();
-}
-
-void UIArcLabel::SetFontId(uint8_t fontId)
-{
- arcLabelText_.SetFontId(fontId);
- if (arcLabelText_.IsNeedRefresh()) {
- RefreshArcLabel();
- }
-}
-
-uint8_t UIArcLabel::GetFontId() const
-{
- return arcLabelText_.GetFontId();
-}
-
-void UIArcLabel::SetFont(const char* name, uint8_t size)
-{
- if (name == nullptr) {
- return;
- }
- arcLabelText_.SetFont(name, size);
- if (arcLabelText_.IsNeedRefresh()) {
- RefreshArcLabel();
- }
-}
-
-void UIArcLabel::OnDraw(const Rect& invalidatedArea)
-{
- const char* text = arcLabelText_.GetText();
- if (text == nullptr || radius_ == 0) {
- return;
- }
- UIFont::GetInstance()->SetCurrentFontId(arcLabelText_.GetFontId());
- Rect trunc = invalidatedArea;
- DrawRect::Draw(GetRect(), trunc, *style_);
-
- Rect coords = GetContentRect();
- if (trunc.Intersect(trunc, coords)) {
- DrawArcText(trunc);
- }
-}
-
-void UIArcLabel::DrawArcText(const Rect& mask)
-{
- OpacityType opa;
- if (opaScale_ == OPA_OPAQUE) {
- opa = style_->textOpa_;
- } else {
- opa = (static_cast(style_->textOpa_) * opaScale_) >> 8; // 8: opacity scale
- }
- Point center;
- center.x = arcTextInfo_.arcCenter.x + GetRect().GetX();
- center.y = arcTextInfo_.arcCenter.y + GetRect().GetY();
- DrawLabel::DrawArcText(mask, arcLabelText_.GetText(), center, arcLabelText_.GetFontId(),
- arcTextInfo_, orientation_, *style_, opa);
-}
-
-void UIArcLabel::RefreshArcLabel()
-{
- Invalidate();
- if (!needRefresh_) {
- needRefresh_ = true;
- AddMeasureView();
- }
-}
-
-void UIArcLabel::ReMeasure()
-{
- if (!needRefresh_) {
- return;
- }
- needRefresh_ = false;
- UIFont::GetInstance()->SetCurrentFontId(arcLabelText_.GetFontId());
-
- MeasureArcTextInfo();
- Rect textRect;
- TypedText::GetArcTextRect(textRect, arcLabelText_.GetText(), arcCenter_, style_->letterSpace_,
- orientation_, arcTextInfo_);
- int16_t arcTextWidth = textRect.GetWidth();
- int16_t arcTextHeight = textRect.GetHeight();
-
- SetPosition(textRect.GetX(), textRect.GetY());
- Resize(arcTextWidth, arcTextHeight);
- arcTextInfo_.arcCenter.x = arcCenter_.x - GetX();
- arcTextInfo_.arcCenter.y = arcCenter_.y - GetY();
- textSize_.x = arcTextWidth;
- textSize_.y = arcTextHeight;
- Invalidate();
-}
-
-void UIArcLabel::MeasureArcTextInfo()
-{
- const char* text = arcLabelText_.GetText();
- if (text == nullptr) {
- return;
- }
- uint16_t letterHeight = UIFont::GetInstance()->GetHeight();
- arcTextInfo_.radius = ((orientation_ == TextOrientation::INSIDE) ? radius_ : (radius_ - letterHeight));
- if (arcTextInfo_.radius == 0) {
- return;
- }
-
- uint16_t arcAngle;
- if (startAngle_ < endAngle_) {
- arcAngle = endAngle_ - startAngle_;
- arcTextInfo_.direct = TEXT_DIRECT_LTR; // Clockwise
- arcLabelText_.SetDirect(TEXT_DIRECT_LTR);
- } else {
- arcAngle = startAngle_ - endAngle_;
- arcTextInfo_.direct = TEXT_DIRECT_RTL; // Counterclockwise
- arcLabelText_.SetDirect(TEXT_DIRECT_RTL);
- }
- uint16_t maxLength = static_cast((UI_PI * radius_ * arcAngle) / SEMICIRCLE_IN_DEGREE);
- arcTextInfo_.lineStart = 0;
- arcTextInfo_.lineEnd = TypedText::GetNextLine(&text[arcTextInfo_.lineStart], style_->letterSpace_, maxLength);
- arcTextInfo_.startAngle = startAngle_;
- uint16_t actLength = TypedText::GetTextWidth(&text[arcTextInfo_.lineStart],
- arcTextInfo_.lineEnd - arcTextInfo_.lineStart, style_->letterSpace_);
- if (arcLabelText_.GetHorAlign() != TEXT_ALIGNMENT_LEFT && actLength < maxLength) {
- uint16_t gapLength = maxLength - actLength;
- if (arcLabelText_.GetHorAlign() == TEXT_ALIGNMENT_CENTER) {
- gapLength = gapLength >> 1;
- }
- if (arcTextInfo_.direct == TEXT_DIRECT_LTR) {
- arcTextInfo_.startAngle += (SEMICIRCLE_IN_DEGREE * gapLength) / (UI_PI * arcTextInfo_.radius);
- } else {
- arcTextInfo_.startAngle += CIRCLE_IN_DEGREE -
- (SEMICIRCLE_IN_DEGREE * gapLength) / (UI_PI * arcTextInfo_.radius);
- }
- }
- arcTextInfo_.startAngle %= CIRCLE_IN_DEGREE;
-}
-} // namespace OHOS
\ No newline at end of file
diff --git a/frameworks/ui/src/components/ui_axis.cpp b/frameworks/ui/src/components/ui_axis.cpp
deleted file mode 100755
index 843536f..0000000
--- a/frameworks/ui/src/components/ui_axis.cpp
+++ /dev/null
@@ -1,195 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#include "components/ui_axis.h"
-#include "common/screen.h"
-#include "draw/draw_line.h"
-
-namespace OHOS {
-UIAxis::UIAxis()
- : maxRange_(0),
- minRange_(0),
- start_({0, 0}),
- end_({0, 0}),
- markInterval_(0),
- dataPerMark_(0),
- dataInterval_(0),
- markDataCount_(AXIS_DEFAULT_MARK_INTERVAL),
- enableReverse_(false)
-{
- SetStyle(STYLE_LINE_WIDTH, 1);
- SetStyle(STYLE_LINE_COLOR, Color::White().full);
-}
-
-void UIAxis::SetLineColor(const ColorType& color)
-{
- SetStyle(STYLE_LINE_COLOR, color.full);
-}
-
-void UIXAxis::SetMarkNum(uint16_t count)
-{
- if ((count == 0) || (count > Screen::GetInstance().GetWidth())) {
- return;
- }
- markDataCount_ = count;
- UpdateAxis();
-}
-
-bool UIXAxis::SetDataRange(uint16_t min, uint16_t max)
-{
- if (max <= min) {
- return false;
- }
- maxRange_ = max;
- minRange_ = min;
- return UpdateAxis();
-}
-
-void UIXAxis::UpdateAxisPoints()
-{
- Rect current = GetContentRect();
- start_.x = current.GetLeft();
- end_.x = current.GetRight();
- start_.y = enableReverse_ ? current.GetTop() : current.GetBottom();
- end_.y = start_.y;
-}
-
-bool UIXAxis::UpdateAxis()
-{
- UpdateAxisPoints();
- int16_t xAxisLength = end_.x - start_.x + 1;
- if (xAxisLength <= 0) {
- return false;
- }
-
- if (markDataCount_ != 0) {
- dataInterval_ = static_cast((maxRange_ - minRange_) / markDataCount_);
- markInterval_ = static_cast(xAxisLength) / markDataCount_;
- if (maxRange_ > minRange_) {
- dataPerMark_ = markInterval_ / dataInterval_;
- }
- }
-
- return true;
-}
-
-void UIXAxis::TranslateToPixel(int16_t& value)
-{
- float minXStep = dataPerMark_ ? dataPerMark_ : markInterval_;
- value = start_.x + static_cast((value - minRange_) * minXStep);
-}
-
-void UIAxis::OnDraw(const Rect& invalidatedArea)
-{
- DrawLine::Draw(start_, end_, invalidatedArea, style_->lineWidth_, style_->lineColor_, style_->lineOpa_);
- DrawAxisMark(invalidatedArea);
-}
-
-void UIXAxis::DrawAxisMark(const Rect& invalidatedArea)
-{
- Point start;
- Point end;
- uint16_t index = 1;
- while (index <= markDataCount_) {
- start.y = start_.y;
- start.x = start_.x + static_cast(index * markInterval_);
- end.y = enableReverse_ ? (start.y + AXIS_DEFAULT_MARK_LENGTH) : (start.y - AXIS_DEFAULT_MARK_LENGTH);
- end.x = start.x;
- DrawLine::Draw(start, end, invalidatedArea, style_->lineWidth_, style_->lineColor_, style_->lineOpa_);
- index++;
- }
-}
-
-void UIYAxis::SetMarkNum(uint16_t count)
-{
- if ((count == 0) || (count > Screen::GetInstance().GetHeight())) {
- return;
- }
- markDataCount_ = count;
- dataInterval_ = static_cast((maxRange_ - minRange_) / markDataCount_);
-}
-
-bool UIYAxis::SetDataRange(uint16_t min, uint16_t max)
-{
- if (max <= min) {
- return false;
- }
-
- maxRange_ = max;
- minRange_ = min;
- return UpdateAxis();
-}
-
-void UIYAxis::UpdateAxisPoints()
-{
- Rect current = GetContentRect();
- int16_t top = current.GetTop();
- int16_t bottom = current.GetBottom();
-
- start_.x = current.GetLeft();
- end_.x = start_.x;
- if (enableReverse_) {
- start_.y = top;
- end_.y = bottom;
- } else {
- start_.y = bottom;
- end_.y = top;
- }
-}
-
-void UIYAxis::TranslateToPixel(int16_t& value)
-{
- float minYStep = dataPerMark_ ? dataPerMark_ : markInterval_;
- if (enableReverse_) {
- value = start_.y + static_cast((maxRange_ - value + minRange_) * minYStep);
- } else {
- value = start_.y - static_cast((value - minRange_) * minYStep);
- }
-}
-
-bool UIYAxis::UpdateAxis()
-{
- UpdateAxisPoints();
- int16_t yAxisLength = enableReverse_ ? (end_.y - start_.y + 1) : (start_.y - end_.y + 1);
- if (yAxisLength <= 0) {
- return false;
- }
-
- if (markDataCount_ != 0) {
- dataInterval_ = static_cast((maxRange_ - minRange_) / markDataCount_);
- markInterval_ = static_cast(yAxisLength) / markDataCount_;
- if (dataInterval_ != 0) {
- dataPerMark_ = markInterval_ / dataInterval_;
- }
- }
- return true;
-}
-
-void UIYAxis::DrawAxisMark(const Rect& invalidatedArea)
-{
- uint16_t index = 1;
- while (index <= markDataCount_) {
- Point start;
- Point end;
- start.x = start_.x;
- start.y = enableReverse_ ? (start_.y + static_cast(index * markInterval_))
- : (start_.y - static_cast(index * markInterval_));
- end.x = start.x + AXIS_DEFAULT_MARK_LENGTH;
- end.y = start.y;
- DrawLine::Draw(start, end, invalidatedArea, style_->lineWidth_, style_->lineColor_, style_->lineOpa_);
- index++;
- }
-}
-} // namespace OHOS
\ No newline at end of file
diff --git a/frameworks/ui/src/components/ui_box_progress.cpp b/frameworks/ui/src/components/ui_box_progress.cpp
deleted file mode 100755
index a6ab3f1..0000000
--- a/frameworks/ui/src/components/ui_box_progress.cpp
+++ /dev/null
@@ -1,236 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#include "components/ui_box_progress.h"
-#include "draw/draw_arc.h"
-#include "draw/draw_rect.h"
-#include "graphic_log.h"
-
-namespace OHOS {
-UIBoxProgress::UIBoxProgress() : progressWidth_(0), progressHeight_(0)
-{
- SetDirection(Direction::DIR_LEFT_TO_RIGHT);
-}
-
-void UIBoxProgress::DrawValidRect(const Image* image, const Rect& rect, const Rect& invalidatedArea,
- const Style& style, uint16_t radius)
-{
- Rect cordsTmp;
- if ((image != nullptr) && (image->GetSrcType() != IMG_SRC_UNKNOWN)) {
- ImageHeader header = {0};
- image->GetHeader(header);
-
- Rect area(rect);
- switch (direction_) {
- case Direction::DIR_LEFT_TO_RIGHT:
- cordsTmp.SetPosition(area.GetLeft() - radius, area.GetTop());
- break;
- case Direction::DIR_TOP_TO_BOTTOM:
- cordsTmp.SetPosition(area.GetLeft(), area.GetTop() - radius);
- break;
- case Direction::DIR_RIGHT_TO_LEFT:
- cordsTmp.SetPosition(area.GetRight() + radius - header.width, area.GetTop());
- break;
- case Direction::DIR_BOTTOM_TO_TOP:
- cordsTmp.SetPosition(area.GetLeft(), area.GetBottom() + radius - header.height);
- break;
- default:
- GRAPHIC_LOGE("UIBoxProgress: DrawValidRect direction Err!\n");
- break;
- }
- cordsTmp.SetHeight(header.height);
- cordsTmp.SetWidth(header.width);
- if (area.Intersect(area, invalidatedArea)) {
- image->DrawImage(cordsTmp, area, style, opaScale_);
- }
- } else {
- DrawRect::Draw(rect, invalidatedArea, style);
- }
-
- if (style.lineCap_ == CapType::CAP_ROUND) {
- DrawRoundCap(image, {cordsTmp.GetX(), cordsTmp.GetY()}, rect, invalidatedArea, radius, style);
- }
-}
-
-void UIBoxProgress::DrawRoundCap(const Image* image, const Point& imgPos, const Rect& rect,
- const Rect& invalidatedArea, uint16_t radius, const Style& style)
-{
- Point leftTop;
- Point leftBottom;
- Point rightTop;
- Point rightBottom;
-
- switch (direction_) {
- case Direction::DIR_LEFT_TO_RIGHT:
- case Direction::DIR_RIGHT_TO_LEFT: {
- leftTop.x = rect.GetLeft() - 1;
- leftTop.y = rect.GetTop() + radius - 1;
- leftBottom.x = leftTop.x;
- leftBottom.y = rect.GetBottom() - radius + 1;
- rightTop.x = rect.GetRight() + 1;
- rightTop.y = leftTop.y;
- rightBottom.x = rightTop.x;
- rightBottom.y = leftBottom.y;
- break;
- }
-
- case Direction::DIR_TOP_TO_BOTTOM:
- case Direction::DIR_BOTTOM_TO_TOP: {
- leftTop.x = rect.GetLeft() + radius - 1;
- leftTop.y = rect.GetTop() - 1;
- rightTop.x = rect.GetRight() - radius + 1;
- rightTop.y = leftTop.y;
- leftBottom.x = leftTop.x;
- leftBottom.y = rect.GetBottom() + 1;
- rightBottom.x = rightTop.x;
- rightBottom.y = leftBottom.y;
- break;
- }
- default:
- GRAPHIC_LOGE("UIBoxProgress: DrawRoundCap direction Err!\n");
- break;
- }
-
- Style capStyle = style;
- capStyle.lineWidth_ = radius;
- capStyle.lineColor_ = style.bgColor_;
- capStyle.lineOpa_ = style.bgOpa_;
- ArcInfo arcInfo = {{0}};
- arcInfo.radius = radius;
- arcInfo.imgPos = imgPos;
- arcInfo.imgSrc = image;
-
- arcInfo.center = leftTop;
- arcInfo.startAngle = THREE_QUARTER_IN_DEGREE;
- arcInfo.endAngle = 0;
- DrawArc::GetInstance()->Draw(arcInfo, invalidatedArea, capStyle, opaScale_, CapType::CAP_NONE);
-
- arcInfo.center = leftBottom;
- arcInfo.startAngle = SEMICIRCLE_IN_DEGREE;
- arcInfo.endAngle = THREE_QUARTER_IN_DEGREE;
- DrawArc::GetInstance()->Draw(arcInfo, invalidatedArea, capStyle, opaScale_, CapType::CAP_NONE);
-
- arcInfo.center = rightTop;
- arcInfo.startAngle = 0;
- arcInfo.endAngle = THREE_QUARTER_IN_DEGREE;
- DrawArc::GetInstance()->Draw(arcInfo, invalidatedArea, capStyle, opaScale_, CapType::CAP_NONE);
-
- arcInfo.center = rightBottom;
- arcInfo.startAngle = THREE_QUARTER_IN_DEGREE;
- arcInfo.endAngle = SEMICIRCLE_IN_DEGREE;
- DrawArc::GetInstance()->Draw(arcInfo, invalidatedArea, capStyle, opaScale_, CapType::CAP_NONE);
-}
-
-void UIBoxProgress::GetBackgroundParam(Point& startPoint, int16_t& width, int16_t& height, uint16_t& radius,
- const Style& style)
-{
- Rect rect = GetContentRect();
- startPoint.x = rect.GetLeft() + ((GetWidth() - progressWidth_) >> 1);
- startPoint.y = rect.GetTop() + ((GetHeight() - progressHeight_) >> 1);
-
- radius = 0;
- width = progressWidth_;
- height = progressHeight_;
- if (style.lineCap_ == CapType::CAP_ROUND) {
- switch (direction_) {
- case Direction::DIR_LEFT_TO_RIGHT:
- case Direction::DIR_RIGHT_TO_LEFT:
- radius = (progressHeight_ + 1) >> 1;
- width -= radius << 1;
- startPoint.x += radius;
- break;
- case Direction::DIR_TOP_TO_BOTTOM:
- case Direction::DIR_BOTTOM_TO_TOP:
- radius = (progressWidth_ + 1) >> 1;
- height -= radius << 1;
- startPoint.y += radius;
- break;
- default:
- GRAPHIC_LOGE("UIBoxProgress: GetBackgroundParam direction Err!\n");
- return;
- }
- }
-}
-
-void UIBoxProgress::DrawBackground(const Rect& invalidatedArea)
-{
- Point startPoint;
- int16_t progressWidth;
- int16_t progressHeight;
- uint16_t radius;
- GetBackgroundParam(startPoint, progressWidth, progressHeight, radius, *backgroundStyle_);
-
- Rect coords(startPoint.x, startPoint.y, startPoint.x + progressWidth - 1, startPoint.y + progressHeight - 1);
-
- DrawValidRect(backgroundImage_, coords, invalidatedArea, *backgroundStyle_, radius);
-}
-
-void UIBoxProgress::DrawForeground(const Rect& invalidatedArea, Rect& coords)
-{
- Point startPoint;
- int16_t progressWidth;
- int16_t progressHeight;
- uint16_t radius;
- GetBackgroundParam(startPoint, progressWidth, progressHeight, radius, *foregroundStyle_);
- int16_t length;
-
- switch (direction_) {
- case Direction::DIR_LEFT_TO_RIGHT: {
- length = GetCurrentPos(progressWidth - 1);
- coords.SetRect(startPoint.x, startPoint.y, startPoint.x + length, startPoint.y + progressHeight - 1);
- break;
- }
- case Direction::DIR_RIGHT_TO_LEFT: {
- length = GetCurrentPos(progressWidth - 1);
- coords.SetRect(startPoint.x + progressWidth - 1 - length,
- startPoint.y, startPoint.x + progressWidth - 1, startPoint.y + progressHeight - 1);
- break;
- }
- case Direction::DIR_TOP_TO_BOTTOM: {
- length = GetCurrentPos(progressHeight - 1);
- coords.SetRect(startPoint.x, startPoint.y, startPoint.x + progressWidth - 1, startPoint.y + length);
- break;
- }
- case Direction::DIR_BOTTOM_TO_TOP: {
- length = GetCurrentPos(progressHeight - 1);
- coords.SetRect(startPoint.x, startPoint.y + progressHeight - 1 - length,
- startPoint.x + progressWidth - 1, startPoint.y + progressHeight - 1);
- break;
- }
- default: {
- GRAPHIC_LOGE("UIBoxProgress: DrawForeground direction Err!\n");
- return;
- }
- }
-
- DrawValidRect(foregroundImage_, coords, invalidatedArea, *foregroundStyle_, radius);
-}
-
-void UIBoxProgress::OnDraw(const Rect& invalidatedArea)
-{
- DrawRect::Draw(GetRect(), invalidatedArea, *style_);
- Rect trunc(invalidatedArea);
- if (trunc.Intersect(trunc, GetContentRect())) {
- if (enableBackground_) {
- DrawBackground(trunc);
- }
-
- if (lastValue_ - rangeMin_ != 0 || foregroundStyle_->lineCap_ == CapType::CAP_ROUND) {
- Rect coords;
- DrawForeground(trunc, coords);
- }
- }
-}
-} // namespace OHOS
\ No newline at end of file
diff --git a/frameworks/ui/src/components/ui_button.cpp b/frameworks/ui/src/components/ui_button.cpp
deleted file mode 100755
index e30aeb2..0000000
--- a/frameworks/ui/src/components/ui_button.cpp
+++ /dev/null
@@ -1,219 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#include "components/ui_button.h"
-#include "common/image.h"
-#include "draw/draw_image.h"
-#include "draw/draw_rect.h"
-#include "imgdecode/cache_manager.h"
-#include "style.h"
-#include "themes/theme_manager.h"
-
-namespace OHOS {
-UIButton::UIButton()
- : defaultImgSrc_(nullptr),
- triggeredImgSrc_(nullptr),
- currentImgSrc_(ButtonImageSrc::BTN_IMAGE_DEFAULT),
- imgX_(0),
- imgY_(0),
- contentWidth_(0),
- contentHeight_(0),
- state_(RELEASED),
- styleState_(RELEASED),
- buttonStyleAllocFlag_(false)
-{
- touchable_ = true;
- SetupThemeStyles();
-}
-
-UIButton::~UIButton()
-{
- if (defaultImgSrc_ != nullptr) {
- delete defaultImgSrc_;
- defaultImgSrc_ = nullptr;
- }
-
- if (triggeredImgSrc_ != nullptr) {
- delete triggeredImgSrc_;
- triggeredImgSrc_ = nullptr;
- }
-
- if (buttonStyleAllocFlag_) {
- for (uint8_t i = 0; i < BTN_STATE_NUM; i++) {
- delete buttonStyles_[i];
- buttonStyles_[i] = nullptr;
- }
- buttonStyleAllocFlag_ = false;
- }
-}
-
-void UIButton::DrawImg(const Rect& invalidatedArea)
-{
- const Image* image = GetCurImageSrc();
- if (image == nullptr) {
- return;
- }
-
- ImageHeader header = {0};
- image->GetHeader(header);
- Rect coords;
- Rect viewRect = GetContentRect();
- coords.SetLeft(viewRect.GetLeft() + GetImageX());
- coords.SetTop(viewRect.GetTop() + GetImageY());
- coords.SetWidth(header.width);
- coords.SetHeight(header.height);
-
- Rect trunc(invalidatedArea);
- if (trunc.Intersect(trunc, viewRect)) {
- image->DrawImage(coords, trunc, *buttonStyles_[state_], opaScale_);
- }
-}
-
-void UIButton::OnDraw(const Rect& invalidatedArea)
-{
- DrawRect::Draw(GetRect(), invalidatedArea, *buttonStyles_[state_]);
- DrawImg(invalidatedArea);
-}
-
-void UIButton::SetupThemeStyles()
-{
- Theme* theme = ThemeManager::GetInstance().GetCurrent();
-
- if (theme == nullptr) {
- buttonStyles_[RELEASED] = &(StyleDefault::GetButtonReleasedStyle());
- buttonStyles_[PRESSED] = &(StyleDefault::GetButtonPressedStyle());
- buttonStyles_[INACTIVE] = &(StyleDefault::GetButtonInactivedStyle());
- } else {
- buttonStyles_[RELEASED] = &(theme->GetButtonStyle().released);
- buttonStyles_[PRESSED] = &(theme->GetButtonStyle().pressed);
- buttonStyles_[INACTIVE] = &(theme->GetButtonStyle().inactive);
- }
-}
-
-int64_t UIButton::GetStyle(uint8_t key) const
-{
- return GetStyleForState(key, styleState_);
-}
-
-void UIButton::SetStyle(uint8_t key, int64_t value)
-{
- SetStyleForState(key, value, styleState_);
-}
-
-int64_t UIButton::GetStyleForState(uint8_t key, ButtonState state) const
-{
- if (state < BTN_STATE_NUM) {
- return (buttonStyles_[state])->GetStyle(key);
- }
- return 0;
-}
-
-void UIButton::SetStyleForState(uint8_t key, int64_t value, ButtonState state)
-{
- if (state < BTN_STATE_NUM) {
- if (!buttonStyleAllocFlag_) {
- for (uint8_t i = 0; i < BTN_STATE_NUM; i++) {
- Style styleSaved = *buttonStyles_[i];
- buttonStyles_[i] = new Style;
- *(buttonStyles_[i]) = styleSaved;
- }
- buttonStyleAllocFlag_ = true;
- }
- buttonStyles_[state]->SetStyle(key, value);
- }
-}
-
-void UIButton::OnPressEvent(const PressEvent& event)
-{
- currentImgSrc_ = ButtonImageSrc::BTN_IMAGE_TRIGGERED;
- SetState(PRESSED);
- Resize(contentWidth_, contentHeight_);
- Invalidate();
- UIView::OnPressEvent(event);
-}
-
-void UIButton::OnReleaseEvent(const ReleaseEvent& event)
-{
- currentImgSrc_ = ButtonImageSrc::BTN_IMAGE_DEFAULT;
- SetState(RELEASED);
- Resize(contentWidth_, contentHeight_);
- Invalidate();
- UIView::OnReleaseEvent(event);
-}
-
-void UIButton::OnCancelEvent(const CancelEvent& event)
-{
- currentImgSrc_ = ButtonImageSrc::BTN_IMAGE_DEFAULT;
- SetState(RELEASED);
- Resize(contentWidth_, contentHeight_);
- Invalidate();
- UIView::OnCancelEvent(event);
-}
-
-const Image* UIButton::GetCurImageSrc() const
-{
- if (currentImgSrc_ == ButtonImageSrc::BTN_IMAGE_DEFAULT) {
- return defaultImgSrc_;
- } else if (currentImgSrc_ == ButtonImageSrc::BTN_IMAGE_TRIGGERED) {
- return triggeredImgSrc_;
- } else {
- return nullptr;
- }
-}
-
-void UIButton::SetImageSrc(const char* defaultImgSrc, const char* triggeredImgSrc)
-{
- if (defaultImgSrc_ == nullptr) {
- defaultImgSrc_ = new Image();
- }
- defaultImgSrc_->SetSrc(defaultImgSrc);
-
- if (triggeredImgSrc_ == nullptr) {
- triggeredImgSrc_ = new Image();
- }
- triggeredImgSrc_->SetSrc(triggeredImgSrc);
-}
-
-void UIButton::SetImageSrc(const ImageInfo* defaultImgSrc, const ImageInfo* triggeredImgSrc)
-{
- if (defaultImgSrc_ == nullptr) {
- defaultImgSrc_ = new Image();
- }
- defaultImgSrc_->SetSrc(defaultImgSrc);
-
- if (triggeredImgSrc_ == nullptr) {
- triggeredImgSrc_ = new Image();
- }
- triggeredImgSrc_->SetSrc(triggeredImgSrc);
-}
-
-void UIButton::Disable()
-{
- SetState(INACTIVE);
- touchable_ = false;
-}
-
-void UIButton::Enable()
-{
- SetState(RELEASED);
- touchable_ = true;
-}
-
-void UIButton::SetState(ButtonState state)
-{
- state_ = state;
- Invalidate();
-}
-} // namespace OHOS
\ No newline at end of file
diff --git a/frameworks/ui/src/components/ui_canvas.cpp b/frameworks/ui/src/components/ui_canvas.cpp
deleted file mode 100755
index 6562a11..0000000
--- a/frameworks/ui/src/components/ui_canvas.cpp
+++ /dev/null
@@ -1,469 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#include "common/image.h"
-#include "components/ui_canvas.h"
-#include "draw/draw_arc.h"
-#include "draw/draw_curve.h"
-#include "draw/draw_image.h"
-#include "draw/draw_line.h"
-#include "draw/draw_rect.h"
-
-namespace OHOS {
-UICanvas::~UICanvas()
-{
- void* param = nullptr;
- ListNode* curDraw = drawCmdList_.Begin();
- for (; curDraw != drawCmdList_.End(); curDraw = curDraw->next_) {
- param = curDraw->data_.param;
- curDraw->data_.DeleteParam(param);
- curDraw->data_.param = nullptr;
- }
- drawCmdList_.Clear();
-}
-
-void UICanvas::Clear()
-{
- void* param = nullptr;
- ListNode* curDraw = drawCmdList_.Begin();
- for (; curDraw != drawCmdList_.End(); curDraw = curDraw->next_) {
- param = curDraw->data_.param;
- curDraw->data_.DeleteParam(param);
- curDraw->data_.param = nullptr;
- }
- drawCmdList_.Clear();
- Invalidate();
-}
-
-void UICanvas::DrawLine(const Point& endPoint, const Paint& paint)
-{
- DrawLine(startPoint_, endPoint, paint);
-}
-
-void UICanvas::DrawLine(const Point& startPoint, const Point& endPoint, const Paint& paint)
-{
- LineParam* lineParam = new LineParam;
- lineParam->start = startPoint;
- lineParam->end = endPoint;
- lineParam->paint = paint;
-
- DrawCmd cmd;
- cmd.param = lineParam;
- cmd.DeleteParam = DeleteLineParam;
- cmd.DrawGraphics = DoDrawLine;
- drawCmdList_.PushBack(cmd);
-
- Invalidate();
- SetStartPosition(endPoint);
-}
-
-void UICanvas::DrawCurve(const Point& control1, const Point& control2, const Point& endPoint, const Paint& paint)
-{
- DrawCurve(startPoint_, control1, control2, endPoint, paint);
-}
-
-void UICanvas::DrawCurve(const Point& startPoint, const Point& control1, const Point& control2,
- const Point& endPoint, const Paint& paint)
-{
- CurveParam* curveParam = new CurveParam;
- curveParam->start = startPoint;
- curveParam->control1 = control1;
- curveParam->control2 = control2;
- curveParam->end = endPoint;
- curveParam->paint = paint;
-
- if (paint.GetStrokeWidth() > MAX_CURVE_WIDTH) {
- curveParam->paint.SetStrokeWidth(MAX_CURVE_WIDTH);
- }
-
- DrawCmd cmd;
- cmd.param = curveParam;
- cmd.DeleteParam = DeleteCurveParam;
- cmd.DrawGraphics = DoDrawCurve;
- drawCmdList_.PushBack(cmd);
-
- Invalidate();
- SetStartPosition(endPoint);
-}
-
-void UICanvas::DrawRect(const Point& startPoint, int16_t height, int16_t width, const Paint& paint)
-{
- if (static_cast(paint.GetStyle()) & Paint::PaintStyle::STROKE_STYLE) {
- RectParam* rectParam = new RectParam;
- rectParam->start = startPoint;
- rectParam->height = height;
- rectParam->width = width;
- rectParam->paint = paint;
-
- DrawCmd cmd;
- cmd.param = rectParam;
- cmd.DeleteParam = DeleteRectParam;
- cmd.DrawGraphics = DoDrawRect;
- drawCmdList_.PushBack(cmd);
- }
-
- if (static_cast(paint.GetStyle()) & Paint::PaintStyle::FILL_STYLE) {
- RectParam* rectParam = new RectParam;
- rectParam->start = startPoint;
- rectParam->height = height;
- rectParam->width = width;
- rectParam->paint = paint;
-
- DrawCmd cmd;
- cmd.param = rectParam;
- cmd.DeleteParam = DeleteRectParam;
- cmd.DrawGraphics = DoFillRect;
- drawCmdList_.PushBack(cmd);
- }
-
- Invalidate();
-}
-
-void UICanvas::DrawCircle(const Point& center, uint16_t radius, const Paint& paint)
-{
- CircleParam* circleParam = new CircleParam;
- circleParam->center = center;
- circleParam->radius = radius;
- circleParam->paint = paint;
-
- DrawCmd cmd;
- cmd.param = circleParam;
- cmd.DeleteParam = DeleteCircleParam;
- cmd.DrawGraphics = DoDrawCircle;
- drawCmdList_.PushBack(cmd);
-
- Invalidate();
-}
-
-void UICanvas::DrawSector(const Point& center, uint16_t radius, int16_t startAngle, int16_t endAngle,
- const Paint& paint)
-{
- if (static_cast(paint.GetStyle()) & Paint::PaintStyle::FILL_STYLE) {
- Paint innerPaint = paint;
- innerPaint.SetStyle(Paint::PaintStyle::STROKE_STYLE);
- innerPaint.SetStrokeWidth(radius);
- innerPaint.SetStrokeColor(paint.GetFillColor());
- radius >>= 1;
- DrawArc(center, radius, startAngle, endAngle, innerPaint);
- }
-}
-
-void UICanvas::DrawArc(const Point& center, uint16_t radius, int16_t startAngle, int16_t endAngle, const Paint& paint)
-{
- if (static_cast(paint.GetStyle()) & Paint::PaintStyle::STROKE_STYLE) {
- ArcParam* arcParam = new ArcParam;
- arcParam->center = center;
- arcParam->radius = radius;
-
- int16_t start;
- int16_t end;
- if (startAngle > endAngle) {
- start = endAngle;
- end = startAngle;
- } else {
- start = startAngle;
- end = endAngle;
- }
-
- DrawArc::GetInstance()->GetDrawRange(start, end);
- arcParam->startAngle = start;
- arcParam->endAngle = end;
- arcParam->paint = paint;
-
- DrawCmd cmd;
- cmd.param = arcParam;
- cmd.DeleteParam = DeleteArcParam;
- cmd.DrawGraphics = DoDrawArc;
- drawCmdList_.PushBack(cmd);
-
- Invalidate();
- }
-}
-
-void UICanvas::DrawLabel(const Point& startPoint, const char* text, uint16_t maxWidth,
- const FontStyle& fontStyle, const Paint& paint)
-{
- if (text == nullptr) {
- return;
- }
- if (static_cast(paint.GetStyle()) & Paint::PaintStyle::FILL_STYLE) {
- UILabel *label = new UILabel();
- label->SetLineBreakMode(UILabel::LINE_BREAK_CLIP);
- label->SetPosition(startPoint.x, startPoint.y);
- label->SetWidth(maxWidth);
- label->SetHeight(GetHeight());
- label->SetText(text);
- label->SetFont(fontStyle.fontName, fontStyle.fontSize);
- label->SetAlign(fontStyle.align);
- label->SetDirect(fontStyle.direct);
- label->SetStyle(STYLE_LETTER_SPACE, fontStyle.letterSpace);
- label->SetStyle(STYLE_TEXT_COLOR, paint.GetFillColor().full);
- label->SetStyle(STYLE_TEXT_OPA, paint.GetOpacity());
-
- DrawCmd cmd;
- cmd.param = label;
- cmd.DeleteParam = DeleteLabel;
- cmd.DrawGraphics = DoDrawLabel;
- drawCmdList_.PushBack(cmd);
-
- Invalidate();
- }
-}
-
-void UICanvas::DrawImage(const Point& startPoint, const char* image, const Paint& paint)
-{
- if (image == nullptr) {
- return;
- }
-
- ImageParam* imageParam = new ImageParam;
- imageParam->image = nullptr;
- imageParam->image = new Image();
- if (imageParam->image == nullptr) {
- return;
- }
-
- imageParam->image->SetSrc(image);
- ImageHeader header = { 0 };
- imageParam->image->GetHeader(header);
- imageParam->start = startPoint;
- imageParam->height = header.height;
- imageParam->width = header.width;
-
- imageParam->paint = paint;
-
- DrawCmd cmd;
- cmd.param = imageParam;
- cmd.DeleteParam = DeleteImageParam;
- cmd.DrawGraphics = DoDrawImage;
- drawCmdList_.PushBack(cmd);
-
- Invalidate();
-}
-
-void UICanvas::OnDraw(const Rect& invalidatedArea)
-{
- Rect rect = GetRect();
- DrawRect::Draw(rect, invalidatedArea, *style_);
- void* param = nullptr;
- ListNode* curDraw = drawCmdList_.Begin();
- Rect coords = GetContentRect();
- Rect trunc = invalidatedArea;
- if (trunc.Intersect(trunc, coords)) {
- for (; curDraw != drawCmdList_.End(); curDraw = curDraw->next_) {
- param = curDraw->data_.param;
- curDraw->data_.DrawGraphics(param, rect, trunc, *style_);
- }
- }
-}
-
-void UICanvas::GetAbsolutePosition(Point& point, const Point& prePoint, const Rect& rect, const Style& style)
-{
- point.x = prePoint.x + rect.GetLeft() + style.paddingLeft_ + style.borderWidth_;
- point.y = prePoint.y + rect.GetTop() + style.paddingTop_ + style.borderWidth_;
-}
-
-void UICanvas::DoDrawLine(void* param, const Rect& rect, const Rect& invalidatedArea, const Style& style)
-{
- if (param == nullptr) {
- return;
- }
- LineParam* lineParam = static_cast(param);
- Point start;
- Point end;
- GetAbsolutePosition(start, lineParam->start, rect, style);
- GetAbsolutePosition(end, lineParam->end, rect, style);
-
- DrawLine::Draw(start, end, invalidatedArea, lineParam->paint.GetStrokeWidth(),
- lineParam->paint.GetStrokeColor(), lineParam->paint.GetOpacity());
-}
-
-void UICanvas::DoDrawCurve(void* param, const Rect& rect, const Rect& invalidatedArea, const Style& style)
-{
- if (param == nullptr) {
- return;
- }
- CurveParam* curveParam = static_cast(param);
- Point start;
- Point end;
- Point control1;
- Point control2;
- GetAbsolutePosition(start, curveParam->start, rect, style);
- GetAbsolutePosition(end, curveParam->end, rect, style);
- GetAbsolutePosition(control1, curveParam->control1, rect, style);
- GetAbsolutePosition(control2, curveParam->control2, rect, style);
-
- DrawCurve::DrawCubicBezier(start, control1, control2, end, invalidatedArea, curveParam->paint.GetStrokeWidth(),
- curveParam->paint.GetStrokeColor(), curveParam->paint.GetOpacity());
-}
-
-void UICanvas::DoDrawRect(void* param, const Rect& rect, const Rect& invalidatedArea, const Style& style)
-{
- if (param == nullptr) {
- return;
- }
- RectParam* rectParam = static_cast(param);
- Style drawStyle = StyleDefault::GetDefaultStyle();
- drawStyle.bgColor_ = rectParam->paint.GetStrokeColor();
- drawStyle.bgOpa_ = rectParam->paint.GetOpacity();
- drawStyle.borderRadius_ = 0;
-
- int16_t lineWidth = rectParam->paint.GetStrokeWidth();
- Point start;
- GetAbsolutePosition(start, rectParam->start, rect, style);
-
- int16_t x = start.x - lineWidth / 2; // 2: half
- int16_t y = start.y - lineWidth / 2; // 2: half
- Rect coords;
- if (rectParam->height <= lineWidth || rectParam->width <= lineWidth) {
- coords.SetPosition(x, y);
- coords.SetHeight(rectParam->height + lineWidth);
- coords.SetWidth(rectParam->width + lineWidth);
- DrawRect::Draw(coords, invalidatedArea, drawStyle);
- return;
- }
-
- coords.SetPosition(x, y);
- coords.SetHeight(lineWidth);
- coords.SetWidth(rectParam->width);
- DrawRect::Draw(coords, invalidatedArea, drawStyle);
-
- coords.SetPosition(x + rectParam->width, y);
- coords.SetHeight(rectParam->height);
- coords.SetWidth(lineWidth);
- DrawRect::Draw(coords, invalidatedArea, drawStyle);
-
- coords.SetPosition(x, y + lineWidth);
- coords.SetHeight(rectParam->height);
- coords.SetWidth(lineWidth);
- DrawRect::Draw(coords, invalidatedArea, drawStyle);
-
- coords.SetPosition(x + lineWidth, y + rectParam->height);
- coords.SetHeight(lineWidth);
- coords.SetWidth(rectParam->width);
- DrawRect::Draw(coords, invalidatedArea, drawStyle);
-}
-
-void UICanvas::DoFillRect(void* param, const Rect& rect, const Rect& invalidatedArea, const Style& style)
-{
- if (param == nullptr) {
- return;
- }
- RectParam* rectParam = static_cast(param);
- uint8_t enableStroke = static_cast(rectParam->paint.GetStyle()) & Paint::PaintStyle::STROKE_STYLE;
- int16_t lineWidth = enableStroke ? rectParam->paint.GetStrokeWidth() : 0;
- if (rectParam->height <= lineWidth || rectParam->width <= lineWidth) {
- return;
- }
- Point start;
- GetAbsolutePosition(start, rectParam->start, rect, style);
-
- Rect coords;
- coords.SetPosition(start.x + (lineWidth + 1) / 2, start.y + (lineWidth + 1) / 2); // 2: half
- coords.SetHeight(rectParam->height - lineWidth);
- coords.SetWidth(rectParam->width - lineWidth);
-
- Style drawStyle = StyleDefault::GetDefaultStyle();
- drawStyle.bgColor_ = rectParam->paint.GetFillColor();
- drawStyle.bgOpa_ = rectParam->paint.GetOpacity();
- drawStyle.borderRadius_ = 0;
- DrawRect::Draw(coords, invalidatedArea, drawStyle);
-}
-
-void UICanvas::DoDrawCircle(void* param, const Rect& rect, const Rect& invalidatedArea, const Style& style)
-{
- if (param == nullptr) {
- return;
- }
- CircleParam* circleParam = static_cast(param);
-
- Style drawStyle = StyleDefault::GetDefaultStyle();
- drawStyle.lineOpa_ = circleParam->paint.GetOpacity();
-
- ArcInfo arcInfo = {{0}};
- arcInfo.imgPos = Point{0, 0};
- arcInfo.startAngle = 0;
- arcInfo.endAngle = CIRCLE_IN_DEGREE;
- GetAbsolutePosition(arcInfo.center, circleParam->center, rect, style);
- uint8_t enableStroke = static_cast(circleParam->paint.GetStyle()) & Paint::PaintStyle::STROKE_STYLE;
- uint16_t halfLineWidth = enableStroke ? (circleParam->paint.GetStrokeWidth() >> 1) : 0;
- if (static_cast(circleParam->paint.GetStyle()) & Paint::PaintStyle::FILL_STYLE) {
- arcInfo.radius = circleParam->radius - halfLineWidth;
- drawStyle.lineWidth_ = arcInfo.radius;
- drawStyle.lineColor_ = circleParam->paint.GetFillColor();
- DrawArc::GetInstance()->Draw(arcInfo, invalidatedArea, drawStyle, OPA_OPAQUE, CapType::CAP_NONE);
- }
-
- if (enableStroke) {
- arcInfo.radius = circleParam->radius + halfLineWidth - 1;
- drawStyle.lineWidth_ = circleParam->paint.GetStrokeWidth();
- drawStyle.lineColor_ = circleParam->paint.GetStrokeColor();
- DrawArc::GetInstance()->Draw(arcInfo, invalidatedArea, drawStyle, OPA_OPAQUE, CapType::CAP_NONE);
- }
-}
-
-void UICanvas::DoDrawArc(void* param, const Rect& rect, const Rect& invalidatedArea, const Style& style)
-{
- if (param == nullptr) {
- return;
- }
- ArcParam* arcParam = static_cast(param);
-
- ArcInfo arcInfo = {{0}};
- arcInfo.imgPos = Point{0, 0};
- arcInfo.startAngle = arcParam->startAngle;
- arcInfo.endAngle = arcParam->endAngle;
- Style drawStyle = StyleDefault::GetDefaultStyle();
- drawStyle.lineWidth_ = arcParam->paint.GetStrokeWidth();
- drawStyle.lineColor_ = arcParam->paint.GetStrokeColor();
- drawStyle.lineOpa_ = arcParam->paint.GetOpacity();
- arcInfo.radius = arcParam->radius + ((arcParam->paint.GetStrokeWidth() + 1) >> 1);
-
- GetAbsolutePosition(arcInfo.center, arcParam->center, rect, style);
- DrawArc::GetInstance()->Draw(arcInfo, invalidatedArea, drawStyle, OPA_OPAQUE, CapType::CAP_NONE);
-}
-
-void UICanvas::DoDrawImage(void* param, const Rect& rect, const Rect& invalidatedArea, const Style& style)
-{
- if (param == nullptr) {
- return;
- }
- ImageParam* imageParam = static_cast(param);
-
- Point start;
- GetAbsolutePosition(start, imageParam->start, rect, style);
-
- Rect cordsTmp;
- cordsTmp.SetPosition(start.x, start.y);
- cordsTmp.SetHeight(imageParam->height);
- cordsTmp.SetWidth(imageParam->width);
- DrawImage::DrawCommon(cordsTmp, invalidatedArea, imageParam->image->GetPath(), style,
- imageParam->paint.GetOpacity());
-}
-
-void UICanvas::DoDrawLabel(void* param, const Rect& rect, const Rect& invalidatedArea, const Style& style)
-{
- if (param == nullptr) {
- return;
- }
- UILabel* label = static_cast(param);
- Point startPos = { label->GetX(), label->GetY() };
- Point start;
- GetAbsolutePosition(start, { startPos.x, startPos.y }, rect, style);
- label->SetPosition(start.x, start.y);
- label->OnDraw(invalidatedArea);
- label->SetPosition(startPos.x, startPos.y);
-}
-} // namespace OHOS
\ No newline at end of file
diff --git a/frameworks/ui/src/components/ui_chart.cpp b/frameworks/ui/src/components/ui_chart.cpp
deleted file mode 100755
index b8cf212..0000000
--- a/frameworks/ui/src/components/ui_chart.cpp
+++ /dev/null
@@ -1,779 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#include "components/ui_chart.h"
-#include "common/typed_text.h"
-#include "draw/draw_arc.h"
-#include "draw/draw_line.h"
-#include "geometry2d.h"
-#include "securec.h"
-
-namespace OHOS {
-UIChart::~UIChart()
-{
- if (mixData_ != nullptr) {
- UIFree(mixData_);
- mixData_ = nullptr;
- }
- ClearDataSerial();
- Remove(&xAxis_);
- Remove(&yAxis_);
- DeleteMeasureView();
-}
-
-void UIChart::SetHeight(int16_t height)
-{
- if (GetHeight() == height) {
- return;
- }
-
- if (height > 0) {
- needRefresh_ = true;
- AddMeasureView();
- }
-
- UIViewGroup::SetHeight(height);
- xAxis_.SetHeight(height);
- xAxis_.UpdateAxis();
- yAxis_.SetHeight(height);
- yAxis_.UpdateAxis();
-}
-
-void UIChart::SetWidth(int16_t width)
-{
- UIViewGroup::SetWidth(width);
- xAxis_.SetWidth(width);
- yAxis_.SetWidth(width);
- xAxis_.UpdateAxis();
- yAxis_.UpdateAxis();
-}
-
-void UIChart::OnDraw(const Rect& invalidatedArea)
-{
- UIViewGroup::OnDraw(invalidatedArea);
- Rect rect = GetContentRect();
- if (rect.Intersect(rect, invalidatedArea)) {
- DrawDataSerials(rect);
- }
-}
-
-bool UIChart::AddDataSerial(UIChartDataSerial* dataSerial)
-{
- if (dataSerial == nullptr) {
- return false;
- }
-
- ListNode* serialNode = list_.Head();
- while (serialNode != list_.End()) {
- if (serialNode->data_ == dataSerial) {
- return false;
- }
- serialNode = serialNode->next_;
- }
- list_.PushBack(dataSerial);
- dataSerial->BindToChart(this);
- return true;
-}
-
-bool UIChart::DeleteDataSerial(UIChartDataSerial* dataSerial)
-{
- if ((dataSerial == nullptr) || (list_.IsEmpty())) {
- return false;
- }
-
- bool findSerial = false;
- ListNode* serialNode = list_.Head();
- while (serialNode != list_.End()) {
- if (serialNode->data_ == dataSerial) {
- dataSerial->BindToChart(nullptr);
- list_.Remove(serialNode);
- findSerial = true;
- break;
- }
- serialNode = serialNode->next_;
- }
-
- return findSerial;
-}
-
-void UIChart::ClearDataSerial()
-{
- if (list_.IsEmpty()) {
- return;
- }
-
- ListNode* serialNode = list_.Head();
- while (serialNode != list_.End()) {
- serialNode->data_->BindToChart(nullptr);
- ListNode* tempNode = serialNode;
- serialNode = serialNode->next_;
- list_.Remove(tempNode);
- }
- list_.Clear();
-}
-
-UIChartDataSerial::UIChartDataSerial()
- : maxCount_(0), pointArray_(nullptr), serialColor_(Color::White()), fillColor_(Color::White()),
- dataCount_(0), peakPointIndex_(0), peakData_(0), valleyData_(0), valleyPointIndex_(0),
- lastPointIndex_(0), latestIndex_(0), hideIndex_(0), hideCount_(0), smooth_(false),
- enableGradient_(false), enableHeadPoint_(false), enableTopPoint_(false), enableBottomPoint_(false),
- chart_(nullptr), invalidateRect_(0, 0, 0, 0)
-{
- PointStyle style;
- style.radius = DEFAULT_POINT_RADIUS;
- style.strokeWidth = 1;
- style.fillColor = Color::White();
- style.strokeColor = Color::White();
- topPointStyle_ = style;
- bottomPointStyle_ = style;
- headPointStyle_ = style;
-}
-
-bool UIChartDataSerial::SetMaxDataCount(uint16_t maxCount)
-{
- if (maxCount > MAX_POINTS_COUNT) {
- maxCount = MAX_POINTS_COUNT;
- }
-
- if (maxCount == maxCount_) {
- return true;
- }
-
- if (pointArray_ != nullptr) {
- UIFree(pointArray_);
- pointArray_ = nullptr;
- }
-
- maxCount_ = maxCount;
- if (maxCount_ == 0) {
- return true;
- }
-
- pointArray_ = static_cast(UIMalloc(sizeof(Point) * maxCount_));
- if (pointArray_ == nullptr) {
- maxCount_ = 0;
- return false;
- }
- return true;
-}
-
-bool UIChartDataSerial::ModifyPoint(uint16_t index, const Point& point)
-{
- if ((index >= maxCount_) || (pointArray_ == nullptr)) {
- return false;
- }
-
- pointArray_[index].x = point.x;
- pointArray_[index].y = point.y;
- if (point.y > peakData_) {
- if (enableTopPoint_) {
- RefreshInvalidateRect(peakPointIndex_, topPointStyle_);
- }
- peakPointIndex_ = index;
- peakData_ = point.y;
- } else if (point.y < valleyData_) {
- if (enableBottomPoint_) {
- RefreshInvalidateRect(valleyPointIndex_, bottomPointStyle_);
- }
- valleyPointIndex_ = index;
- valleyData_ = point.y;
- } else if (index == peakPointIndex_ || index == valleyPointIndex_) {
- UpdatePeakAndValley(0, dataCount_);
- }
-
- latestIndex_ = index;
- uint16_t startIndex = (index == 0) ? index : (index - 1);
- RefreshInvalidateRect(startIndex, index + 1);
- return true;
-}
-
-bool UIChartDataSerial::GetPoint(uint16_t index, Point& point)
-{
- if ((index >= dataCount_) || (pointArray_ == nullptr)) {
- return false;
- }
- point = pointArray_[index];
- if (chart_ != nullptr) {
- chart_->GetXAxis().TranslateToPixel(point.x);
- chart_->GetYAxis().TranslateToPixel(point.y);
- }
- return true;
-}
-
-void UIChartDataSerial::HidePoint(uint16_t index, uint16_t count)
-{
- RefreshInvalidateRect(hideIndex_, hideIndex_ + hideCount_);
- hideIndex_ = index;
- hideCount_ = count;
- RefreshInvalidateRect(hideIndex_, hideIndex_ + hideCount_);
-}
-
-void UIChartDataSerial::RefreshInvalidateRect(uint16_t pointIndex, const PointStyle& style)
-{
- Point point;
- if (GetPoint(pointIndex, point)) {
- uint16_t width = style.radius + style.strokeWidth;
- Rect refresh(point.x - width, 0, point.x + width, 0);
- if (invalidateRect_.GetLeft() == 0 && invalidateRect_.GetRight() == 0) {
- invalidateRect_ = refresh;
- } else {
- invalidateRect_.Join(invalidateRect_, refresh);
- }
- }
-}
-
-void UIChartDataSerial::RefreshInvalidateRect(uint16_t startIndex, uint16_t endIndex)
-{
- Point start;
- GetPoint(startIndex, start);
- Point end;
- endIndex = (endIndex >= dataCount_) ? (dataCount_ - 1) : endIndex;
- GetPoint(endIndex, end);
- int16_t xMin = MATH_MIN(start.x, end.x);
- int16_t xMax = MATH_MAX(start.x, end.x);
- Rect refresh(xMin, 0, xMax, 0);
- if (invalidateRect_.GetLeft() == 0 && invalidateRect_.GetRight() == 0) {
- invalidateRect_ = refresh;
- } else {
- invalidateRect_.Join(invalidateRect_, refresh);
- }
-}
-
-bool UIChartDataSerial::UpdatePeakAndValley(uint16_t startPos, uint16_t endPos)
-{
- if ((startPos >= endPos) || (endPos > dataCount_) || (pointArray_ == nullptr)) {
- return false;
- }
-
- if (startPos == 0) {
- peakData_ = pointArray_[startPos].y;
- valleyData_ = pointArray_[startPos].y;
- }
-
- for (uint16_t i = startPos; i < endPos; i++) {
- if (pointArray_[i].y > peakData_) {
- if (enableTopPoint_) {
- RefreshInvalidateRect(peakPointIndex_, topPointStyle_);
- RefreshInvalidateRect(i, topPointStyle_);
- }
- peakPointIndex_ = i;
- peakData_ = pointArray_[i].y;
- }
-
- if (pointArray_[i].y < valleyData_) {
- if (enableBottomPoint_) {
- RefreshInvalidateRect(valleyPointIndex_, bottomPointStyle_);
- RefreshInvalidateRect(i, bottomPointStyle_);
- }
- valleyPointIndex_ = i;
- valleyData_ = pointArray_[i].y;
- }
- }
- return true;
-}
-
-bool UIChartDataSerial::AddPoints(const Point* data, uint16_t count)
-{
- if ((maxCount_ <= dataCount_) || (count == 0) || (pointArray_ == nullptr) || data == nullptr) {
- return false;
- }
-
- if (count > (maxCount_ - dataCount_)) {
- count = maxCount_ - dataCount_;
- }
-
- Point* current = pointArray_ + dataCount_;
- if (memcpy_s(current, (maxCount_ - dataCount_) * sizeof(Point), data, count * sizeof(Point)) != EOK) {
- return false;
- }
- uint16_t i = dataCount_;
- dataCount_ += count;
- UpdatePeakAndValley(i, dataCount_);
- latestIndex_ = dataCount_ - 1;
- uint16_t startIndex = (i == 0) ? i : (i - 1);
- RefreshInvalidateRect(startIndex, latestIndex_);
- return true;
-}
-
-void UIChartDataSerial::ClearData()
-{
- RefreshInvalidateRect(0, dataCount_ - 1);
- if (pointArray_ != nullptr) {
- if (memset_s(pointArray_, maxCount_ * sizeof(Point), 0, maxCount_ * sizeof(Point)) != EOK) {
- return;
- }
- }
- dataCount_ = 0;
- valleyPointIndex_ = 0;
- peakPointIndex_ = 0;
- latestIndex_ = 0;
-}
-
-void UIChartDataSerial::DoDrawPoint(const Point& center, const PointStyle& style, const Rect& mask)
-{
- Style drawStyle = StyleDefault::GetDefaultStyle();
- drawStyle.lineOpa_ = OPA_OPAQUE;
- drawStyle.lineColor_ = style.fillColor;
-
- ArcInfo arcinfo = {{0}};
- arcinfo.center = center;
- arcinfo.imgPos = Point{0, 0};
- arcinfo.radius = style.radius + style.strokeWidth;
- arcinfo.startAngle = 0;
- arcinfo.endAngle = CIRCLE_IN_DEGREE;
-
- if (style.fillColor.full == style.strokeColor.full) {
- drawStyle.lineWidth_ = style.radius + style.strokeWidth;
- DrawArc::GetInstance()->Draw(arcinfo, mask, drawStyle, OPA_OPAQUE, CapType::CAP_NONE);
- } else {
- drawStyle.lineWidth_ = style.radius;
- arcinfo.radius = style.radius;
- DrawArc::GetInstance()->Draw(arcinfo, mask, drawStyle, OPA_OPAQUE, CapType::CAP_NONE);
-
- drawStyle.lineWidth_ = style.strokeWidth;
- drawStyle.lineColor_ = style.strokeColor;
- arcinfo.radius = style.radius + style.strokeWidth;
- DrawArc::GetInstance()->Draw(arcinfo, mask, drawStyle, OPA_OPAQUE, CapType::CAP_NONE);
- }
-}
-
-void UIChartDataSerial::DrawPoint(const Rect& mask)
-{
- Point center;
- if (enableTopPoint_) {
- if (GetPoint(peakPointIndex_, center)) {
- DoDrawPoint(center, topPointStyle_, mask);
- }
- }
-
- if (enableBottomPoint_) {
- if (GetPoint(valleyPointIndex_, center)) {
- DoDrawPoint(center, bottomPointStyle_, mask);
- }
- }
-
- if (enableHeadPoint_) {
- if (GetPoint(latestIndex_, center)) {
- DoDrawPoint(center, headPointStyle_, mask);
- }
- }
-}
-
-void UIChartDataSerial::Refresh()
-{
- if (chart_ != nullptr) {
- Rect refresh = chart_->GetContentRect();
- refresh.SetLeft(invalidateRect_.GetLeft() - headPointStyle_.radius - headPointStyle_.strokeWidth);
- refresh.SetRight(invalidateRect_.GetRight() + headPointStyle_.radius + headPointStyle_.strokeWidth);
- invalidateRect_.SetLeft(0);
- invalidateRect_.SetRight(0);
- chart_->InvalidateRect(refresh);
- }
-}
-
-void UIChartPillar::RefreshChart()
-{
- ListNode* iter = list_.Begin();
- Rect rect = GetContentRect();
- for (; iter != list_.End(); iter = iter->next_) {
- UIChartDataSerial* data = iter->data_;
- uint16_t dataCount = data->GetDataCount();
- if (dataCount <= 1) {
- break;
- }
-
- int16_t index = data->GetLastPointIndex();
- if (index >= dataCount) {
- break;
- }
-
- Point current;
- data->GetPoint(index, current);
- Point last;
- data->GetPoint(dataCount - 1, last);
- Rect refresh(current.x, rect.GetTop(), last.x, rect.GetBottom());
- InvalidateRect(refresh);
- data->SetLastPointIndex(dataCount - 1);
- }
-}
-
-void UIChartPillar::DrawDataSerials(const Rect& invalidatedArea)
-{
- xAxis_.UpdateAxisPoints();
- yAxis_.UpdateAxisPoints();
- uint16_t minXStep = static_cast(xAxis_.GetMarkInterval());
- Point xStart = xAxis_.GetStartPoint();
- uint16_t dataSerialCount = list_.Size();
- if (dataSerialCount == 0) {
- return;
- }
- uint16_t width = minXStep / dataSerialCount;
- uint8_t dataSerialIndex = 0;
- uint16_t barWidth = static_cast(width - DEFAULT_MARK_PERCENTAGE * (width << 1));
-
- for (ListNode* iter = list_.Begin(); iter != list_.End(); iter = iter->next_) {
- UIChartDataSerial* data = iter->data_;
- uint16_t dataSerialWidth = width * dataSerialIndex;
- int16_t x = dataSerialWidth + (width >> 1);
- for (uint16_t index = 0; index < data->GetDataCount(); index++) {
- Point current;
- data->GetPoint(index, current);
- if (current.y == xStart.y) {
- continue;
- }
- current.x += x;
- xStart.x = current.x;
- DrawLine::Draw(current, xStart, invalidatedArea, barWidth, data->GetFillColor(), style_->lineOpa_);
- }
- dataSerialIndex++;
- }
-}
-
-void UIChartPolyline::RefreshChart()
-{
- ListNode* iter = list_.Begin();
- for (; iter != list_.End(); iter = iter->next_) {
- UIChartDataSerial* data = iter->data_;
- uint16_t dataCount = data->GetDataCount();
- if (dataCount == 1) {
- break;
- }
- data->Refresh();
- }
-}
-
-void UIChartPolyline::ReMeasure()
-{
- if (!needRefresh_) {
- return;
- }
- needRefresh_ = false;
- int16_t height = GetHeight();
- if (mixData_ != nullptr) {
- UIFree(mixData_);
- mixData_ = nullptr;
- }
- if (height <= 0) {
- return;
- }
- if (height > COORD_MAX) {
- height = COORD_MAX;
- }
- mixData_ = static_cast(UIMalloc(height));
- if (mixData_ == nullptr) {
- return;
- }
- int16_t opa = maxOpa_ - minOpa_;
- for (int16_t y = 0; y < height; y++) {
- mixData_[y] = static_cast(y * opa / height + minOpa_);
- }
-}
-
-void UIChartPolyline::DrawDataSerials(const Rect& invalidatedArea)
-{
- xAxis_.UpdateAxisPoints();
- yAxis_.UpdateAxisPoints();
- ListNode* iter = list_.Begin();
- for (; iter != list_.End(); iter = iter->next_) {
- UIChartDataSerial* data = iter->data_;
- uint16_t dataCount = data->GetDataCount();
- if (dataCount <= 1) {
- continue;
- }
- if (data->IsGradient()) {
- GradientColor(invalidatedArea, data);
- }
- if (data->GetHideCount() != 0) {
- uint16_t hideIndex = data->GetHideIndex();
- DrawPolyLine(0, hideIndex, invalidatedArea, data);
- DrawPolyLine(hideIndex + data->GetHideCount(), dataCount - 1, invalidatedArea, data);
- } else {
- DrawPolyLine(0, dataCount - 1, invalidatedArea, data);
- }
-
- data->DrawPoint(invalidatedArea);
- }
-}
-
-void UIChartPolyline::DrawSmoothPolyLine(uint16_t startIndex, uint16_t endIndex, const Rect& invalidatedArea,
- UIChartDataSerial* data)
-{
- if (data == nullptr) {
- return;
- }
- Point start;
- Point end;
- ColorType color = data->GetLineColor();
- Style style = *style_;
- style.lineColor_ = color;
-
- uint16_t slope;
- data->GetPoint(startIndex, start);
- data->GetPoint(startIndex + 1, end);
- uint16_t preSlope = (start.x == end.x) ? QUARTER_IN_DEGREE : FastAtan2(end.x - start.x, end.y - start.y);
- Point current;
- for (uint16_t i = startIndex; i < endIndex; i++) {
- data->GetPoint(i + 1, current);
- slope = (current.x == start.x) ? QUARTER_IN_DEGREE : FastAtan2(current.x - start.x, current.y - start.y);
- if (MATH_ABS(slope - preSlope) < SMOOTH_SLOPE_ANGLE) {
- end = current;
- continue;
- }
- preSlope = (current.x == end.x) ? QUARTER_IN_DEGREE : FastAtan2(current.x - end.x, current.y - end.y);
- Rect rect;
- rect.SetLeft(MATH_MIN(start.x, end.x) - style_->lineWidth_);
- rect.SetRight(MATH_MAX(start.x, end.x) + style_->lineWidth_);
- rect.SetTop(MATH_MIN(start.y, end.y) - style_->lineWidth_);
- rect.SetBottom(MATH_MAX(start.y, end.y) + style_->lineWidth_);
- if (!invalidatedArea.IsIntersect(rect)) {
- start = end;
- end = current;
- continue;
- }
-
- DrawLine::Draw(start, end, invalidatedArea, style_->lineWidth_, color, style_->lineOpa_);
- ArcInfo arcinfo = {{0}};
- arcinfo.center = end;
- arcinfo.imgPos = Point{0, 0};
- arcinfo.radius = (style_->lineWidth_ + 1) >> 1;
- arcinfo.startAngle = 0;
- arcinfo.endAngle = CIRCLE_IN_DEGREE;
-
- DrawArc::GetInstance()->Draw(arcinfo, invalidatedArea, style, opaScale_, CapType::CAP_NONE);
-
- start = end;
- end = current;
- }
- DrawLine::Draw(start, end, invalidatedArea, style_->lineWidth_, color, style_->lineOpa_);
-}
-
-void UIChartPolyline::DrawPolyLine(uint16_t startIndex, uint16_t endIndex, const Rect& invalidatedArea,
- UIChartDataSerial* data)
-{
- if (startIndex >= endIndex || data == nullptr) {
- return;
- }
-
- if (data->IsSmooth()) {
- DrawSmoothPolyLine(startIndex, endIndex, invalidatedArea, data);
- } else {
- Point start;
- Point end;
- ColorType color = data->GetLineColor();
- for (uint16_t i = startIndex; i < endIndex; i++) {
- data->GetPoint(i, start);
- data->GetPoint(i + 1, end);
- Rect rect;
- rect.SetLeft(MATH_MIN(start.x, end.x) - style_->lineWidth_);
- rect.SetRight(MATH_MAX(start.x, end.x) + style_->lineWidth_);
- rect.SetTop(MATH_MIN(start.y, end.y) - style_->lineWidth_);
- rect.SetBottom(MATH_MAX(start.y, end.y) + style_->lineWidth_);
- if (!invalidatedArea.IsIntersect(rect)) {
- continue;
- }
-
- DrawLine::Draw(start, end, invalidatedArea, style_->lineWidth_, color, style_->lineOpa_);
- }
- }
-}
-
-bool UIChartPolyline::GetLineCrossPoint(const Point& p1, const Point& p2, const Point& p3, const Point& p4,
- Point& cross)
-{
- /* Rectangular ranges of line segments must intersect. */
- if (MATH_MIN(p1.x, p2.x) <= MATH_MAX(p3.x, p4.x) &&
- MATH_MIN(p3.x, p4.x) <= MATH_MAX(p1.x, p2.x) &&
- MATH_MIN(p1.y, p2.y) <= MATH_MAX(p3.y, p4.y) &&
- MATH_MIN(p3.y, p4.y) <= MATH_MAX(p1.y, p2.y)) {
- /* Check whether the lines are parallel. If the lines are collinear, there is no intersection point. */
- if ((p4.y - p3.y) * (p2.x - p1.x) - (p4.x - p3.x) * (p2.y - p1.y) != 0) {
- /*
- * (y1 - y2)x + (x2 - x1)y = x2y1 - x1y2 -> ax + by = c
- * (y3 - y4)x + (x4 - x3)y = x4y3 - x3y4 -> dx + ey = f
- */
- int64_t a = p1.y - p2.y;
- int64_t b = p2.x - p1.x;
- int64_t c = p2.x * p1.y - p1.x * p2.y;
- int64_t d = p3.y - p4.y;
- int64_t e = p4.x - p3.x;
- int64_t f = p4.x * p3.y - p3.x * p4.y;
- int64_t left = a * e - b * d;
- int64_t right = c * e - b * f;
- if (left == 0) {
- return false;
- }
- cross.x = static_cast(right / left);
- left = b * d - a * e;
- right = c * d - a * f;
- if (left == 0) {
- return false;
- }
- cross.y = static_cast(right / left);
- if (cross.x >= MATH_MIN(p1.x, p2.x) && cross.x <= MATH_MAX(p1.x, p2.x) &&
- cross.x >= MATH_MIN(p3.x, p4.x) && cross.x <= MATH_MAX(p3.x, p4.x)) {
- return true;
- }
- }
- }
- return false;
-}
-
-void UIChartPolyline::FindCrossPoints(const ChartLine& line, const ChartLine& polyLine, CrossPointSet& cross)
-{
- if (GetLineCrossPoint(line.start, line.end, polyLine.start, polyLine.end, cross.nextFirst)) {
- if (!cross.firstFind) {
- /* first corss must on the line like "/" */
- if (polyLine.start.y < polyLine.end.y) {
- cross.first = cross.nextFirst;
- cross.firstFind = true;
- }
- } else if (!cross.secondFind) {
- /* second corss can't be same with first cross. */
- if (cross.first.x != cross.nextFirst.x || cross.first.y != cross.nextFirst.y) {
- cross.second = cross.nextFirst;
- cross.secondFind = true;
- } else {
- /* second corss must on the line like "\", otherwise skip those crosss. */
- if (polyLine.start.y > polyLine.end.y) {
- cross.firstFind = false;
- }
- }
- }
- }
-}
-
-void UIChartPolyline::DrawGradientColor(const Rect& invalidatedArea, UIChartDataSerial* data,
- const ChartLine& linePoints, const ChartLine& limitPoints, int16_t startY)
-{
- if (data == nullptr) {
- return;
- }
- Rect currentRect = GetContentRect();
- CrossPointSet cross = { {0} };
- ChartLine polyLine = { {0} };
- uint16_t pointCount = data->GetDataCount() - 1;
- int16_t y = enableReverse_ ? (linePoints.start.y + startY) : (startY - linePoints.start.y);
- int16_t mixScale = !enableReverse_ ? (currentRect.GetBottom() - y) : (y - currentRect.GetTop());
- if (mixScale < 0 || mixScale >= currentRect.GetHeight()) {
- return;
- }
- bool onVerticalLine = enableReverse_ ? (y <= limitPoints.start.y) : (y >= limitPoints.start.y);
- if (onVerticalLine) {
- cross.first.x = limitPoints.start.x;
- cross.first.y = enableReverse_ ? (y - startY) : (startY - y);
- cross.firstFind = true;
- }
-
- Point start;
- Point end;
- for (uint16_t i = 0; i < pointCount; i++) {
- data->GetPoint(i, start);
- data->GetPoint(i + 1, end);
- if (start.y == end.y) {
- int16_t y = enableReverse_ ? (start.y + startY) : (startY - start.y);
- if (y == linePoints.start.y) {
- cross.firstFind = false;
- cross.secondFind = false;
- }
- continue;
- }
- start.y = enableReverse_ ? (start.y - startY) : (startY - start.y);
- end.y = enableReverse_ ? (end.y - startY) : (startY - end.y);
- polyLine.start = start;
- polyLine.end = end;
- FindCrossPoints(linePoints, polyLine, cross);
- if (cross.firstFind && cross.secondFind) {
- cross.first.y = enableReverse_ ? (cross.first.y + startY) : (startY - cross.first.y);
- cross.second.y = enableReverse_ ? (cross.second.y + startY) : (startY - cross.second.y);
- DrawLine::Draw(cross.first, cross.second, invalidatedArea, 1, data->GetFillColor(), mixData_[mixScale]);
- cross.firstFind = false;
- cross.secondFind = false;
- }
- }
-
- if (cross.firstFind && !cross.secondFind) {
- cross.second.x = limitPoints.end.x;
- cross.second.y = y;
- cross.first.y = y;
- DrawLine::Draw(cross.first, cross.second, invalidatedArea, 1, data->GetFillColor(), mixData_[mixScale]);
- }
-}
-
-void UIChartPolyline::CalcVerticalInfo(int16_t top, int16_t bottom, int16_t start, int16_t end,
- int16_t& y, int16_t& yHeight)
-{
- if (top < start && bottom > start) {
- y = start;
- yHeight = top;
- } else if (bottom <= start && top >= end) {
- y = bottom;
- yHeight = top;
- } else if (top < end && bottom > end) {
- y = bottom;
- yHeight = end;
- }
-}
-
-void UIChartPolyline::GradientColor(const Rect& invalidatedArea, UIChartDataSerial* data)
-{
- if (data == nullptr) {
- return;
- }
- int16_t bottom = invalidatedArea.GetBottom();
- int16_t top = invalidatedArea.GetTop();
- Point yStart = yAxis_.GetStartPoint();
- yStart.y = enableReverse_ ? (yStart.y + gradientBottom_) : (yStart.y - gradientBottom_);
- int16_t topY = enableReverse_ ? data->GetValleyData() : data->GetPeakData();
- int16_t bottomY = enableReverse_ ? data->GetPeakData() : data->GetValleyData();
- yAxis_.TranslateToPixel(topY);
- yAxis_.TranslateToPixel(bottomY);
- int16_t valleyY = enableReverse_ ? topY : bottomY;
- int16_t startY = enableReverse_ ? topY : yStart.y;
- int16_t endY = enableReverse_ ? yStart.y : topY;
- if (bottom < endY || top > startY) {
- return;
- }
-
- int16_t y = 0;
- int16_t yHeight = 0;
- CalcVerticalInfo(top, bottom, startY, endY, y, yHeight);
-
- ChartLine limitPoints = { {0} };
- data->GetPoint(0, limitPoints.start);
- data->GetPoint(data->GetDataCount() - 1, limitPoints.end);
- ChartLine linePoints = { {0} };
- linePoints.start.x = limitPoints.start.x;
- linePoints.end.x = limitPoints.end.x;
- Rect currentRect = GetContentRect();
- while (y >= yHeight) {
- linePoints.start.y = enableReverse_ ? (y - endY) : (startY - y);
- linePoints.end.y = linePoints.start.y;
- if (y <= valleyY) {
- int16_t baseY = enableReverse_ ? endY : startY;
- DrawGradientColor(invalidatedArea, data, linePoints, limitPoints, baseY);
- } else {
- int16_t mixScale = enableReverse_ ? (linePoints.start.y + endY - currentRect.GetTop()) :
- (currentRect.GetBottom() - (startY - linePoints.start.y));
- if (mixScale < 0 || mixScale >= currentRect.GetHeight()) {
- continue;
- }
- Point start = {limitPoints.start.x, y};
- Point end = {limitPoints.end.x, y};
- DrawLine::Draw(start, end, invalidatedArea, 1, data->GetFillColor(), mixData_[mixScale]);
- }
- y--;
- }
-}
-}
\ No newline at end of file
diff --git a/frameworks/ui/src/components/ui_checkbox.cpp b/frameworks/ui/src/components/ui_checkbox.cpp
deleted file mode 100755
index 85a8957..0000000
--- a/frameworks/ui/src/components/ui_checkbox.cpp
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#include "common/image.h"
-#include "components/ui_checkbox.h"
-#include "default_resource/check_box_res.h"
-#include "draw/draw_image.h"
-#include "draw/draw_rect.h"
-#include "imgdecode/cache_manager.h"
-
-namespace OHOS {
-UICheckBox::UICheckBox()
- : state_(UNSELECTED), onStateChangeListener_(nullptr)
-{
- touchable_ = true;
- style_ = &(StyleDefault::GetBackgroundTransparentStyle());
- image_[UNSELECTED].SetSrc(GetCheckBoxOffInfo());
- image_[SELECTED].SetSrc(GetCheckBoxOnInfo());
- ImageHeader header = { 0 };
- image_[UNSELECTED].GetHeader(header);
- Resize(header.width, header.height);
-}
-
-UICheckBox::~UICheckBox()
-{
-}
-
-void UICheckBox::SetState(UICheckBoxState state)
-{
- if (state != state_) {
- state_ = state;
- if (onStateChangeListener_ != nullptr) {
- onStateChangeListener_->OnChange(state);
- }
- Invalidate();
- }
-}
-
-void UICheckBox::ReverseState()
-{
- state_ = (state_ == SELECTED) ? UNSELECTED : SELECTED;
-}
-
-void UICheckBox::OnClickEvent(const ClickEvent& event)
-{
- ReverseState();
- Invalidate();
- UIView::OnClickEvent(event);
-}
-
-void UICheckBox::SetImages(const char* selectedImageSrc, const char* unselectedImageSrc)
-{
- image_[SELECTED].SetSrc(selectedImageSrc);
- image_[UNSELECTED].SetSrc(unselectedImageSrc);
-}
-
-void UICheckBox::SetImages(const ImageInfo* selectedImageSrc, const ImageInfo* unselectedImageSrc)
-{
- image_[SELECTED].SetSrc(selectedImageSrc);
- image_[UNSELECTED].SetSrc(unselectedImageSrc);
-}
-
-void UICheckBox::OnDraw(const Rect& invalidatedArea)
-{
- 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_);
-
- Rect trunc = invalidatedArea;
- Rect contentRect = GetContentRect();
- if (trunc.Intersect(trunc, contentRect)) {
- image_[state_].DrawImage(coords, trunc, *style_, opaScale_);
- }
-}
-} // namespace OHOS
diff --git a/frameworks/ui/src/components/ui_circle_progress.cpp b/frameworks/ui/src/components/ui_circle_progress.cpp
deleted file mode 100755
index 4c45b5e..0000000
--- a/frameworks/ui/src/components/ui_circle_progress.cpp
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#include "components/ui_circle_progress.h"
-#include "draw/draw_arc.h"
-#include "draw/draw_line.h"
-#include "draw/draw_rect.h"
-
-namespace OHOS {
-UICircleProgress::UICircleProgress()
- : center_({0, 0}),
- backgroundImagePos_({0, 0}),
- progressImagePos_({0, 0}),
- radius_(0),
- startAngle_(MIN_ANGLE_VALUE),
- endAngle_(MAX_ANGLE_VALUE)
-{
-}
-
-void UICircleProgress::SetCenterPosition(int16_t x, int16_t y)
-{
- center_.x = x;
- center_.y = y;
-}
-
-void UICircleProgress::SetStartAngle(int16_t startAngle)
-{
- startAngle_ = startAngle;
-}
-
-void UICircleProgress::SetEndAngle(int16_t endAngle)
-{
- endAngle_ = endAngle;
-}
-
-void UICircleProgress::GetStartEndAngle(int16_t& start, int16_t& end) const
-{
- if (startAngle_ > endAngle_) {
- start = endAngle_;
- end = startAngle_;
- } else {
- start = startAngle_;
- end = endAngle_;
- }
-}
-
-void UICircleProgress::GetAngleRange(int16_t& start, int16_t& end) const
-{
- GetStartEndAngle(start, end);
- DrawArc::GetInstance()->GetDrawRange(start, end);
-}
-
-void UICircleProgress::GetRedrawAngle(int16_t& start, int16_t& end) const
-{
- GetStartEndAngle(start, end);
-
- if (startAngle_ == endAngle_) {
- return;
- }
-
- int16_t angleRange = end - start;
- angleRange = (angleRange > CIRCLE_IN_DEGREE) ? CIRCLE_IN_DEGREE : angleRange;
-
- int16_t angle = GetCurrentPos(angleRange);
- if (startAngle_ > endAngle_) {
- start = end - angle;
- } else {
- end = angle + start;
- }
- DrawArc::GetInstance()->GetDrawRange(start, end);
-}
-
-void UICircleProgress::DrawCommonCircle(const Rect& invalidatedArea)
-{
- ArcInfo arcinfo = {{0}};
- arcinfo.radius = radius_;
- int16_t endAngle;
- int16_t startAngle;
- GetRedrawAngle(startAngle, endAngle);
-
- int16_t start;
- int16_t end;
- GetAngleRange(start, end);
- Rect rect = GetRect();
- arcinfo.center.x = center_.x + rect.GetLeft() + style_->paddingLeft_ + style_->borderWidth_;
- arcinfo.center.y = center_.y + rect.GetTop() + style_->paddingTop_ + style_->borderWidth_;
-
- if (enableBackground_ && (start != end || backgroundStyle_->lineCap_ == CapType::CAP_ROUND)) {
- arcinfo.imgPos.x = backgroundImagePos_.x + rect.GetLeft();
- arcinfo.imgPos.y = backgroundImagePos_.y + rect.GetTop();
- arcinfo.startAngle = start;
- arcinfo.endAngle = end;
- arcinfo.imgSrc = backgroundImage_;
- DrawArc::GetInstance()->Draw(arcinfo, invalidatedArea, *backgroundStyle_, opaScale_,
- backgroundStyle_->lineCap_);
- }
-
- if (startAngle != endAngle || foregroundStyle_->lineCap_ == CapType::CAP_ROUND) {
- arcinfo.imgPos.x = progressImagePos_.x + rect.GetLeft();
- arcinfo.imgPos.y = progressImagePos_.y + rect.GetTop();
- arcinfo.startAngle = startAngle;
- arcinfo.endAngle = endAngle;
- arcinfo.imgSrc = foregroundImage_;
- DrawArc::GetInstance()->Draw(arcinfo, invalidatedArea, *foregroundStyle_, opaScale_,
- foregroundStyle_->lineCap_);
- }
-}
-
-void UICircleProgress::OnDraw(const Rect& invalidatedArea)
-{
- if (GetRangeSize() == 0) {
- return;
- }
-
- DrawRect::Draw(GetRect(), invalidatedArea, *style_);
-
- Rect trunc(invalidatedArea);
- if (trunc.Intersect(trunc, GetContentRect())) {
- DrawCommonCircle(trunc);
- }
-}
-} // namespace OHOS
\ No newline at end of file
diff --git a/frameworks/ui/src/components/ui_dialog.cpp b/frameworks/ui/src/components/ui_dialog.cpp
deleted file mode 100755
index f2478fa..0000000
--- a/frameworks/ui/src/components/ui_dialog.cpp
+++ /dev/null
@@ -1,367 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#include "components/ui_dialog.h"
-#include "common/screen.h"
-#include "common/ui_text_language.h"
-#include "graphic_log.h"
-
-namespace OHOS {
-class UIDialogLabelButton : public UILabelButton {
-public:
- virtual void OnClickEvent(const ClickEvent& event)
- {
- if (onClickListener_ != nullptr) {
- onClickListener_->OnClick(*this, event);
- }
- if (parent_ != nullptr) {
- UIDialog* dialog = static_cast(parent_->GetParent());
- if (dialog != nullptr) {
- dialog->SetVisible(false);
- }
- }
- }
-};
-
-UIDialog::UIDialog()
- : buttonNum_(0),
- title_(nullptr),
- text_(nullptr),
- button1_(nullptr),
- button2_(nullptr),
- button3_(nullptr),
- buttonWidth_(0)
-{
- UIViewGroup::SetVisible(false);
- SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT);
- uint16_t screenWidth = Screen::GetInstance().GetWidth();
- uint16_t screenHeight = Screen::GetInstance().GetHeight();
- UIViewGroup::SetPosition(0, 0, screenWidth, screenHeight);
-
- widthMax_ = screenWidth * MAX_WIDTH_PERCENT / 100 - 2 * PADDING; // there are 2 paddings horizontally
- heightMax_ = screenHeight * MAX_HEIGHT_PERCENT / 100 - 2 * PADDING; // there are 2 paddings horizontally
-
- Add(&maskLayer_);
- maskLayer_.SetTouchable(true);
- maskLayer_.SetDraggable(true);
- maskLayer_.SetPosition(0, 0, GetWidth(), GetHeight());
- maskLayer_.SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full);
- maskLayer_.SetStyle(STYLE_BACKGROUND_OPA, 153); // 153 default opa
-
- Add(&dialogLayer_);
- dialogLayer_.SetStyle(STYLE_BORDER_RADIUS, DIALOG_RADIUS);
- dialogLayer_.SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full);
- dialogLayer_.SetStyle(STYLE_BACKGROUND_OPA, 230); // 230 default opa
-}
-
-UIDialog::~UIDialog()
-{
- if (title_ != nullptr) {
- dialogLayer_.Remove(title_);
- delete title_;
- title_ = nullptr;
- }
- if (text_ != nullptr) {
- dialogLayer_.Remove(text_);
- delete text_;
- text_ = nullptr;
- }
- if (button1_ != nullptr) {
- dialogLayer_.Remove(button1_);
- delete button1_;
- button1_ = nullptr;
- }
- if (button2_ != nullptr) {
- dialogLayer_.Remove(button2_);
- delete button2_;
- button2_ = nullptr;
- }
- if (button3_ != nullptr) {
- dialogLayer_.Remove(button3_);
- delete button3_;
- button3_ = nullptr;
- }
- Remove(&maskLayer_);
- Remove(&dialogLayer_);
-}
-
-void UIDialog::SetTitle(const char* title)
-{
- if (title == nullptr) {
- return;
- }
- if (title_ == nullptr) {
- title_ = new UILabel();
- title_->SetViewId("dialogTitle");
- dialogLayer_.Add(title_);
- }
- title_->SetText(title);
- title_->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER);
- dialogLayer_.Add(title_);
-
- ReMeasureSize();
- ReLayout();
-}
-
-void UIDialog::MeasureTitle()
-{
- if (title_ == nullptr) {
- return;
- }
- title_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);
- title_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, TITLE_LARGE_FONT_SIZE);
- if (title_->GetTextWidth() > widthMax_) {
- title_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, TITLE_SMALL_FONT_SIZE);
- }
- title_->SetWidth(title_->GetTextWidth());
- title_->SetHeight(title_->GetTextHeight());
- if (title_->GetTextWidth() > widthMax_) {
- title_->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS);
- title_->SetWidth(widthMax_);
- }
-}
-
-void UIDialog::SetText(const char* text)
-{
- if (text == nullptr) {
- return;
- }
- if (text_ == nullptr) {
- text_ = new UILabel();
- text_->SetViewId("dialogText");
- dialogLayer_.Add(text_);
- }
- text_->SetText(text);
-
- ReMeasureSize();
- ReLayout();
-}
-
-void UIDialog::MeasureText()
-{
- if (text_ == nullptr) {
- return;
- }
- text_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, TEXT_FONT_SIZE);
- text_->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER);
- dialogLayer_.Add(text_);
-
- text_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);
- uint16_t textWidth = text_->GetTextWidth();
- uint16_t textHeight = text_->GetTextHeight();
- if (textWidth <= widthMax_) {
- text_->SetWidth(textWidth);
- text_->SetHeight(textHeight);
- } else {
- text_->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_LEFT);
- text_->SetWidth(widthMax_);
- text_->SetLineBreakMode(UILabel::LINE_BREAK_WRAP);
- textHeight = text_->GetTextHeight();
- // If there is no title, there are 3 paddings vertically
- // If there is a title, there are 4 paddings vertically
- uint16_t textHightMax = (title_ == nullptr) ? (heightMax_ - 3 * PADDING - BUTTON_HEIGHT)
- : (heightMax_ - 4 * PADDING - title_->GetHeight() - BUTTON_HEIGHT);
- if (textHeight <= textHightMax) {
- text_->SetHeight(textHeight);
- } else {
- text_->SetHeight(textHightMax);
- text_->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS);
- }
- }
-}
-
-void UIDialog::SetButton(DialogButtonType buttonType, const char* text, OnClickListener* listener)
-{
- switch (buttonType) {
- case DialogButtonType::BUTTON1:
- if (button1_ == nullptr) {
- button1_ = new UIDialogLabelButton();
- button1_->SetViewId("dialogButton1");
- AddButton(buttonType, button1_, text, listener);
- } else {
- button1_->SetText(text);
- button1_->SetOnClickListener(listener);
- }
- break;
- case DialogButtonType::BUTTON2:
- if (button2_ == nullptr) {
- button2_ = new UIDialogLabelButton();
- button2_->SetViewId("dialogButton2");
- AddButton(buttonType, button2_, text, listener);
- } else {
- button2_->SetText(text);
- button2_->SetOnClickListener(listener);
- }
- break;
- case DialogButtonType::BUTTON3:
- if (button3_ == nullptr) {
- button3_ = new UIDialogLabelButton();
- button3_->SetViewId("dialogButton3");
- AddButton(buttonType, button3_, text, listener);
- } else {
- button3_->SetText(text);
- button3_->SetOnClickListener(listener);
- }
- break;
- default:
- break;
- }
-}
-
-void UIDialog::AddButton(DialogButtonType buttonType,
- UILabelButton* button,
- const char* text,
- OnClickListener* listener)
-{
- buttonNum_++;
-
- dialogLayer_.Add(button);
- button->SetDraggable(true);
- button->SetText(text);
- button->SetOnClickListener(listener);
- button->SetFont(DEFAULT_VECTOR_FONT_FILENAME, BUTTON_FONT_SIZE);
-
- button->SetTextColor(Color::White());
- button->SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full);
- button->SetHeight(BUTTON_HEIGHT);
-
- ReMeasureSize();
- ReLayout();
-}
-
-void UIDialog::MeasureButton()
-{
- if (buttonNum_ == 0) {
- return;
- }
- uint16_t buttonWidthMin = BUTTON_MIN_WIDTH;
- uint16_t buttonTotalWidthMin = buttonWidthMin * buttonNum_ + (buttonNum_ - 1) * PADDING;
- if (buttonTotalWidthMin >= widthMax_) {
- buttonWidth_ = (widthMax_ - (buttonNum_ - 1) * PADDING) / buttonNum_;
- } else {
- buttonWidth_ = buttonWidthMin;
- }
- if (button1_ != nullptr) {
- button1_->SetWidth(buttonWidth_);
- }
- if (button2_ != nullptr) {
- button2_->SetWidth(buttonWidth_);
- }
- if (button3_ != nullptr) {
- button3_->SetWidth(buttonWidth_);
- }
-}
-
-void UIDialog::ReMoveButton()
-{
- if (button1_ != nullptr) {
- button1_->LayoutLeftOfParent(PADDING);
- button1_->LayoutBottomOfParent(PADDING);
- if (button2_ != nullptr) {
- button2_->LayoutRightToSibling("dialogButton1", PADDING - 1);
- button2_->LayoutBottomOfParent(PADDING);
- }
- } else {
- if (button2_ != nullptr) {
- button2_->LayoutLeftOfParent(PADDING);
- button2_->LayoutBottomOfParent(PADDING);
- }
- }
- if (button3_ != nullptr) {
- button3_->LayoutRightOfParent(PADDING);
- button3_->LayoutBottomOfParent(PADDING);
- }
-}
-
-void UIDialog::ReMeasureSize()
-{
- MeasureText();
- MeasureTitle();
- MeasureButton();
-
- uint16_t width = 0;
- uint16_t height = 0;
- uint16_t num = 0;
-
- if (title_ != nullptr) {
- uint16_t titleWidth = title_->GetWidth();
- width = MATH_MAX(width, titleWidth);
- height += title_->GetHeight();
- num++;
- }
- if (text_ != nullptr) {
- uint16_t textWidth = text_->GetWidth();
- width = MATH_MAX(width, textWidth);
- height += text_->GetHeight();
- num++;
- }
- if (buttonNum_ != 0) {
- uint16_t buttonTotalWidth = buttonWidth_ * buttonNum_ + (buttonNum_ - 1) * PADDING;
- width = MATH_MAX(width, buttonTotalWidth);
- height += BUTTON_HEIGHT;
- num++;
- }
-
- if (title_ != nullptr && (title_->GetWidth() != width)) {
- title_->SetWidth(width);
- }
- if (text_ != nullptr && (text_->GetWidth() != width)) {
- text_->SetWidth(width);
- }
- if (buttonNum_ != 0) {
- uint16_t buttonTotalWidth = buttonWidth_ * buttonNum_ + (buttonNum_ - 1) * PADDING;
- if (buttonTotalWidth != width) {
- buttonWidth_ = (width - (buttonNum_ - 1) * PADDING) / buttonNum_;
- if (button1_ != nullptr) {
- button1_->SetWidth(buttonWidth_);
- }
- if (button2_ != nullptr) {
- button2_->SetWidth(buttonWidth_);
- }
- if (button3_ != nullptr) {
- button3_->SetWidth(buttonWidth_);
- }
- }
- }
- uint16_t dialogHeight = height + (num + 1) * PADDING;
- dialogLayer_.SetHeight(dialogHeight);
- dialogLayer_.SetWidth(width + 2 * PADDING); // 2: there are 2 paddings horizontally
-}
-
-void UIDialog::ReLayout()
-{
- if (title_ != nullptr) {
- title_->LayoutLeftOfParent(PADDING);
- title_->LayoutTopOfParent(PADDING);
- if (text_ != nullptr) {
- text_->LayoutLeftOfParent(PADDING);
- text_->LayoutBottomToSibling("dialogTitle", PADDING);
- }
- } else {
- if (text_ != nullptr) {
- text_->LayoutLeftOfParent(PADDING);
- text_->LayoutTopOfParent(PADDING);
- }
- }
- ReMoveButton();
- dialogLayer_.LayoutCenterOfParent();
-}
-
-void UIDialog::SetVisible(bool visible)
-{
- UIViewGroup::SetVisible(visible);
- Invalidate();
-}
-} // namespace OHOS
\ No newline at end of file
diff --git a/frameworks/ui/src/components/ui_digital_clock.cpp b/frameworks/ui/src/components/ui_digital_clock.cpp
deleted file mode 100755
index 9e3dae7..0000000
--- a/frameworks/ui/src/components/ui_digital_clock.cpp
+++ /dev/null
@@ -1,216 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#include "components/ui_digital_clock.h"
-#include
-#include "components/ui_view_group.h"
-#include "font/ui_font.h"
-#include "graphic_log.h"
-#include "securec.h"
-
-namespace OHOS {
-UIDigitalClock::UIDigitalClock()
- : displayMode_(DISPLAY_24_HOUR), leadingZero_(true), color_(Color::White()),
- prevHour_(0), prevMinute_(0), prevSecond_(0), verticalShow_(false)
-{
- for (uint8_t i = 0; i < TIME_ELEMENT_COUNT; i++) {
- timeLabels_[i].SetAlign(TEXT_ALIGNMENT_LEFT);
- timeLabels_[i].SetFontId(style_->font_);
- timeLabels_[i].SetStyle(STYLE_TEXT_COLOR, color_.full);
- timeLabels_[i].SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);
- timeLabels_[i].SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT);
- Add(&timeLabels_[i]);
- }
- style_ = &(StyleDefault::GetBackgroundTransparentStyle());
-}
-
-void UIDigitalClock::DisplayLeadingZero(bool displayLeadingZero)
-{
- leadingZero_ = displayLeadingZero;
- UpdateClock(false);
-}
-
-void UIDigitalClock::SetOpacity(uint8_t opacity)
-{
- opaScale_ = opacity;
- for (uint8_t i = 0; i < TIME_ELEMENT_COUNT; i++) {
- timeLabels_[i].SetStyle(STYLE_TEXT_OPA, opacity);
- }
- RefreshTime();
-}
-
-uint8_t UIDigitalClock::GetOpacity() const
-{
- return opaScale_;
-}
-
-void UIDigitalClock::SetFontId(uint8_t fontId)
-{
- SetStyle(STYLE_TEXT_FONT, fontId);
- for (uint8_t i = 0; i < TIME_ELEMENT_COUNT; i++) {
- timeLabels_[i].SetFontId(fontId);
- }
- UpdateClock(false);
-}
-
-void UIDigitalClock::SetFont(const char* name, uint8_t size)
-{
- for (uint8_t i = 0; i < TIME_ELEMENT_COUNT; i++) {
- timeLabels_[i].SetFont(name, size);
- }
- UpdateClock(false);
-}
-
-void UIDigitalClock::SetColor(ColorType color)
-{
- color_ = color;
- for (uint8_t i = 0; i < TIME_ELEMENT_COUNT; i++) {
- timeLabels_[i].SetStyle(STYLE_TEXT_COLOR, color.full);
- }
- RefreshTime();
-}
-
-void UIDigitalClock::TimeElementRefresh()
-{
- if (currentHour_ != prevHour_) {
- prevHour_ = currentHour_;
- timeLabels_[HOUR_ELEMENT].Invalidate();
- }
-
- if (currentMinute_ != prevMinute_) {
- prevMinute_ = currentMinute_;
- timeLabels_[MINUTE_ELEMENT].Invalidate();
- }
-
- if (currentSecond_ != prevSecond_) {
- prevSecond_ = currentSecond_;
- timeLabels_[SECOND_ELEMENT].Invalidate();
- }
-}
-
-void UIDigitalClock::RefreshTime()
-{
- for (uint8_t i = 0; i < TIME_ELEMENT_COUNT; i++) {
- timeLabels_[i].Invalidate();
- }
-}
-
-void UIDigitalClock::UpdateClock(bool clockInit)
-{
- char buf[TIME_ELEMENT_COUNT][BUFFER_SIZE] = {{ 0 }};
- const char* formatWithColon = leadingZero_ ? "%02d:" : "%d:";
- const char* formatWithoutColon = leadingZero_ ? "%02d" : "%d";
- const char* format = verticalShow_ ? formatWithoutColon : formatWithColon;
- const char* formatForMinute = verticalShow_ ? "%02d" : "%02d:";
- switch (displayMode_) {
- case DISPLAY_24_HOUR_NO_SECONDS: {
- if (sprintf_s(buf[HOUR_ELEMENT], BUFFER_SIZE, format, currentHour_) < 0) {
- return;
- }
- if (sprintf_s(buf[MINUTE_ELEMENT], BUFFER_SIZE, "%02d", currentMinute_) < 0) {
- return;
- }
- break;
- }
- case DISPLAY_12_HOUR_NO_SECONDS: {
- if (sprintf_s(buf[HOUR_ELEMENT], BUFFER_SIZE, format, currentHour_ % HALF_DAY_IN_HOUR) < 0) {
- return;
- }
- if (sprintf_s(buf[MINUTE_ELEMENT], BUFFER_SIZE, "%02d", currentMinute_) < 0) {
- return;
- }
- break;
- }
- case DISPLAY_12_HOUR: {
- if (sprintf_s(buf[HOUR_ELEMENT], BUFFER_SIZE, format, currentHour_ % HALF_DAY_IN_HOUR) < 0) {
- return;
- }
- if (sprintf_s(buf[MINUTE_ELEMENT], BUFFER_SIZE, formatForMinute, currentMinute_) < 0) {
- return;
- }
- if (sprintf_s(buf[SECOND_ELEMENT], BUFFER_SIZE, "%02d", currentSecond_) < 0) {
- return;
- }
- break;
- }
- case DISPLAY_24_HOUR: {
- if (sprintf_s(buf[HOUR_ELEMENT], BUFFER_SIZE, format, currentHour_) < 0) {
- return;
- }
- if (sprintf_s(buf[MINUTE_ELEMENT], BUFFER_SIZE, formatForMinute, currentMinute_) < 0) {
- return;
- }
- if (sprintf_s(buf[SECOND_ELEMENT], BUFFER_SIZE, "%02d", currentSecond_) < 0) {
- return;
- }
- break;
- }
- default: {
- break;
- }
- }
- SetTimeLabels(buf);
-}
-
-void UIDigitalClock::SetTimeLabels(const char buf[TIME_ELEMENT_COUNT][BUFFER_SIZE])
-{
- for (uint8_t i = 0; i < TIME_ELEMENT_COUNT; i++) {
- timeLabels_[i].SetText(buf[i]);
- }
-
- SetTimeLabelsPosition();
- TimeElementRefresh();
-}
-
-void UIDigitalClock::SetHorizontal()
-{
- uint16_t totalWidth = timeLabels_[HOUR_ELEMENT].GetWidth() +
- timeLabels_[MINUTE_ELEMENT].GetWidth() + timeLabels_[SECOND_ELEMENT].GetWidth();
- UITextLanguageAlignment align = timeLabels_[HOUR_ELEMENT].GetHorAlign();
- int16_t x = 0;
- Rect rect = GetContentRect();
- if (align == TEXT_ALIGNMENT_CENTER) {
- x = (rect.GetWidth() >> 1) - (totalWidth >> 1);
- } else if (align == TEXT_ALIGNMENT_RIGHT) {
- x = rect.GetRight() - totalWidth;
- }
- timeLabels_[HOUR_ELEMENT].SetPosition(x, 0);
- int16_t width = timeLabels_[HOUR_ELEMENT].GetWidth();
- for (uint8_t i = 1; i < TIME_ELEMENT_COUNT; i++) {
- timeLabels_[i].SetPosition(x + width, 0);
- width += timeLabels_[i].GetWidth();
- }
-}
-
-void UIDigitalClock::SetTimeLabelsPosition()
-{
- if (verticalShow_) {
- SetVertical();
- } else {
- SetHorizontal();
- }
-}
-
-void UIDigitalClock::SetVertical()
-{
- uint16_t fontHeight = timeLabels_[HOUR_ELEMENT].GetHeight();
- timeLabels_[HOUR_ELEMENT].SetPosition(0, 0);
- uint16_t y = fontHeight;
- for (uint8_t i = 1; i < TIME_ELEMENT_COUNT; i++) {
- timeLabels_[i].SetPosition(0, y);
- y += fontHeight;
- }
-}
-}
diff --git a/frameworks/ui/src/components/ui_image_animator.cpp b/frameworks/ui/src/components/ui_image_animator.cpp
deleted file mode 100755
index 437d7be..0000000
--- a/frameworks/ui/src/components/ui_image_animator.cpp
+++ /dev/null
@@ -1,196 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#include "components/ui_image_animator.h"
-
-namespace OHOS {
-UIImageAnimatorView::UIImageAnimatorView()
- : imageSrc_(nullptr), imageNum_(0), tickOfUpdate_(1), timeOfUpdate_(DEFAULT_TASK_PERIOD),
- timeOfPause_(0), tickOfPause_(0), repeatTimes_(1),
- imageAnimator_(&imageAnimatorCallback_, this, 0, true), listener_(nullptr),
- reverse_(false), repeat_(true), sizeFixed_(false)
-{
- AnimatorManager::GetInstance()->Add(&imageAnimator_);
-}
-
-UIImageAnimatorView::~UIImageAnimatorView()
-{
- AnimatorManager::GetInstance()->Remove(&imageAnimator_);
-}
-
-void UIImageAnimatorView::ImageAnimatorCallback::Callback(UIView* view)
-{
- if (view == nullptr) {
- return;
- }
- UIImageAnimatorView* imageAnimatorView = static_cast(view);
-
- imageSrc_ = imageAnimatorView->GetImageAnimatorSrc();
- imageNum_ = imageAnimatorView->GetImageAnimatorImageNum();
- if ((imageSrc_ == nullptr) || (imageNum_ == 0) || (imageAnimatorView->tickOfUpdate_ == 0)) {
- return;
- }
-
- if (!imageAnimatorView->IsRepeat() && repeat_ == imageAnimatorView->GetRepeatTimes()) {
- imageAnimatorView->Stop(false);
- return;
- }
-
- tickNum_++;
-
- if (loop_ != imageNum_) {
- if (tickNum_ < imageAnimatorView->tickOfUpdate_) {
- return;
- }
- } else {
- if (imageAnimatorView->tickOfPause_ != 0) {
- if (tickNum_ < imageAnimatorView->tickOfPause_) {
- return;
- }
- } else {
- if (tickNum_ < imageAnimatorView->tickOfUpdate_) {
- return;
- }
- }
- repeat_++;
- loop_ = 0;
- if (!imageAnimatorView->IsRepeat() && repeat_ == imageAnimatorView->GetRepeatTimes()) {
- imageAnimatorView->Stop(false);
- return;
- }
- }
- imageAnimatorView->UpdateImage(drawingImage_, loop_);
- tickNum_ = 0;
-}
-
-void UIImageAnimatorView::UpdateImage(uint8_t& drawingImage, uint8_t& loop)
-{
- Invalidate();
- drawingImage = reverse_ ? (imageNum_ - loop - 1) : loop;
- if (drawingImage >= imageNum_) {
- return;
- }
-
- ImageAnimatorInfo* imageAnimatorInfo = &(imageSrc_[drawingImage]);
- SetSrc((const char*)(imageAnimatorInfo->imageInfo));
- if (!sizeFixed_) {
- SetPosition(imageAnimatorInfo->pos.x, imageAnimatorInfo->pos.y);
- SetWidth(imageAnimatorInfo->width);
- SetHeight(imageAnimatorInfo->height);
- }
- Invalidate();
- loop++;
-}
-
-void UIImageAnimatorView::SetImageAnimatorSrc(const char* imageSrc, uint8_t imageNum, uint16_t timeOfUpdate)
-{
- imageSrc_ = reinterpret_cast(const_cast(imageSrc));
- imageNum_ = imageNum;
- timeOfUpdate_ = timeOfUpdate;
- tickOfUpdate_ = GetTickByTime(timeOfUpdate);
- return;
-}
-
-void UIImageAnimatorView::SetImageAnimatorSrc(const char* imageSrc, uint8_t imageNum)
-{
- SetImageAnimatorSrc(imageSrc, imageNum, timeOfUpdate_);
-}
-
-const ImageAnimatorInfo* UIImageAnimatorView::GetImageAnimatorSrc() const
-{
- return imageSrc_;
-}
-
-uint8_t UIImageAnimatorView::GetImageAnimatorImageNum() const
-{
- return imageNum_;
-}
-
-void UIImageAnimatorView::SetTimeOfUpdate(uint16_t timeOfUpdate)
-{
- timeOfUpdate_ = timeOfUpdate;
- tickOfUpdate_ = GetTickByTime(timeOfUpdate);
-}
-
-uint16_t UIImageAnimatorView::GetTimeOfUpdate() const
-{
- return timeOfUpdate_;
-}
-
-void UIImageAnimatorView::SetTimeOfPause(uint16_t timeOfPause)
-{
- timeOfPause_ = timeOfPause;
- tickOfPause_ = GetTickByTime(timeOfPause);
-}
-
-uint16_t UIImageAnimatorView::GetTimeOfPause() const
-{
- return timeOfPause_;
-}
-
-void UIImageAnimatorView::Start()
-{
- Reset();
- imageAnimator_.SetState(Animator::START);
-}
-
-void UIImageAnimatorView::Reset()
-{
- if ((imageSrc_ == nullptr) || (imageNum_ == 0)) {
- return;
- }
-
- Invalidate();
-
- uint8_t drawingImage = reverse_ ? (imageNum_ - 1) : 0;
- ImageAnimatorInfo* imageAnimatorinfo = &(imageSrc_[drawingImage]);
- SetSrc(imageAnimatorinfo->imageInfo);
- if (!sizeFixed_) {
- SetPosition(imageAnimatorinfo->pos.x, imageAnimatorinfo->pos.y);
- SetWidth(imageAnimatorinfo->width);
- SetHeight(imageAnimatorinfo->height);
- }
- Invalidate();
- imageAnimatorCallback_.Reset();
-}
-
-void UIImageAnimatorView::Stop(bool needReset)
-{
- if (imageAnimator_.GetState() == Animator::STOP) {
- return;
- }
-
- imageAnimator_.SetState(Animator::STOP);
-
- if (needReset) {
- Reset();
- }
-
- if (listener_ != nullptr) {
- listener_->OnAnimatorStop(*this);
- }
-}
-
-uint8_t UIImageAnimatorView::GetTickByTime(uint16_t time) const
-{
- uint8_t tick;
- if (time > 0 && time <= DEFAULT_TASK_PERIOD) {
- tick = 1;
- } else {
- tick = time / DEFAULT_TASK_PERIOD;
- }
- return tick;
-}
-}
diff --git a/frameworks/ui/src/components/ui_image_view.cpp b/frameworks/ui/src/components/ui_image_view.cpp
deleted file mode 100755
index a1bbb41..0000000
--- a/frameworks/ui/src/components/ui_image_view.cpp
+++ /dev/null
@@ -1,159 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#include "components/ui_image_view.h"
-#include "common/image.h"
-#include "common/typed_text.h"
-#include "draw/draw_image.h"
-#include "draw/draw_label.h"
-#include "draw/draw_rect.h"
-#include "image_info.h"
-#include "imgdecode/cache_manager.h"
-#include "mem_api.h"
-
-namespace OHOS {
-UIImageView::UIImageView()
- : imageWidth_(0), imageHeight_(0),
- autoEnable_(true), needRefresh_(false), colorFormat_(UNKNOW),
- blurLevel_(BlurLevel::LEVEL0), algorithm_(TransformAlgorithm::BILINEAR), reserve_(0)
-{
- style_ = &(StyleDefault::GetBackgroundTransparentStyle());
-}
-
-UIImageView::~UIImageView()
-{
- DeleteMeasureView();
-}
-
-bool UIImageView::OnPreDraw(const Rect& invalidatedArea)
-{
- bool cover = false;
- if ((image_.GetSrcType() == IMG_SRC_UNKNOWN)) {
- return false;
- }
-
- if ((colorFormat_ == RGB565 || colorFormat_ == RGB888)) {
- cover = GetRect().IsContains(invalidatedArea);
- }
-
- return cover;
-}
-
-void UIImageView::OnDraw(const Rect& invalidatedArea)
-{
- DrawRect::Draw(GetRect(), invalidatedArea, *style_);
- if ((imageHeight_ == 0) || (imageWidth_ == 0)) {
- return;
- }
-
- Rect viewRect = GetContentRect();
- Rect trunc(invalidatedArea);
- if (trunc.Intersect(trunc, viewRect)) {
- uint8_t srcType = image_.GetSrcType();
- if ((srcType == IMG_SRC_FILE) || (srcType == IMG_SRC_VARIABLE)) {
- Rect cordsTmp;
- cordsTmp.SetTop(viewRect.GetY());
- cordsTmp.SetBottom(viewRect.GetY() + imageHeight_ - 1);
-
- if ((transMap_ == nullptr) || transMap_->IsInvalid()) {
- while (cordsTmp.GetTop() <= viewRect.GetBottom()) {
- cordsTmp.SetLeft(viewRect.GetX());
- cordsTmp.SetRight(viewRect.GetX() + imageWidth_ - 1);
- while (cordsTmp.GetLeft() <= viewRect.GetRight()) {
- image_.DrawImage(cordsTmp, trunc, *style_, opaScale_);
- cordsTmp.SetLeft(cordsTmp.GetLeft() + imageWidth_);
- cordsTmp.SetRight(cordsTmp.GetRight() + imageWidth_);
- }
- cordsTmp.SetTop(cordsTmp.GetTop() + imageHeight_);
- cordsTmp.SetBottom(cordsTmp.GetBottom() + imageHeight_);
- }
- } else if ((transMap_ != nullptr) && !transMap_->IsInvalid()) {
- ImageInfo imgInfo;
- if (srcType == IMG_SRC_FILE) {
- CacheEntry entry;
- RetCode ret = CacheManager::GetInstance().Open(GetPath(), *style_, entry);
- if (ret != RetCode::OK) {
- return;
- }
- imgInfo = entry.GetImageInfo();
- } else {
- imgInfo = *(GetImageInfo());
- }
- uint8_t pxSize = DrawUtils::GetPxSizeByColorMode(imgInfo.header.colorMode);
- TransformDataInfo imageTranDataInfo = {
- imgInfo.header, imgInfo.data, pxSize,
- static_cast(blurLevel_), static_cast(algorithm_)
- };
-
- Rect origRect = GetOrigRect();
- int16_t deltaX = origRect.GetX() - transMap_->GetTransMapRect().GetX();
- int16_t deltaY = origRect.GetY() - transMap_->GetTransMapRect().GetY();
- DrawUtils::GetInstance()->DrawTransform(invalidatedArea, Point{ deltaX, deltaY }, Color::Black(),
- *transMap_, imageTranDataInfo);
- }
- }
- }
-}
-
-void UIImageView::SetSrc(const char* src)
-{
- bool updated = image_.SetSrc(src);
- if (updated == false) {
- return;
- }
- needRefresh_ = true;
- if (autoEnable_) {
- ReMeasure();
- } else {
- AddMeasureView();
- }
- Invalidate();
-}
-
-void UIImageView::ReMeasure()
-{
- if (!needRefresh_) {
- return;
- }
- needRefresh_ = false;
-
- ImageHeader header = {0};
- image_.GetHeader(header);
-
- imageWidth_ = header.width;
- imageHeight_ = header.height;
- colorFormat_ = header.colorMode;
-
- if (autoEnable_) {
- Resize(imageWidth_, imageHeight_);
- Invalidate();
- }
-}
-
-void UIImageView::SetSrc(const ImageInfo* src)
-{
- bool updated = image_.SetSrc(src);
- if (updated == false) {
- return;
- }
- needRefresh_ = true;
- if (autoEnable_) {
- ReMeasure();
- } else {
- AddMeasureView();
- }
- Invalidate();
-}
-}
diff --git a/frameworks/ui/src/components/ui_label.cpp b/frameworks/ui/src/components/ui_label.cpp
deleted file mode 100755
index 9b0961f..0000000
--- a/frameworks/ui/src/components/ui_label.cpp
+++ /dev/null
@@ -1,364 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#include "components/ui_label.h"
-#include "font/ui_font.h"
-#include "themes/theme_manager.h"
-
-namespace OHOS {
-class LabelAnimator : public Animator, public AnimatorCallback {
-public:
- LabelAnimator(uint16_t textX, uint16_t labelX, int16_t startPos, UIView* view)
- : Animator(this, view, 0, true),
- startPos_(startPos),
- textX_(textX),
- labelX_(labelX),
- offsetX_(startPos),
- waitCount_(ANIM_WAIT_COUNT),
- speed_(0),
- preRunTime_(0),
- decimal_(0)
- {
- AnimatorManager::GetInstance()->Add(this);
- }
-
- virtual ~LabelAnimator()
- {
- AnimatorManager::GetInstance()->Remove(this);
- }
-
- int16_t GetStartPos() const
- {
- return startPos_;
- }
-
- void SetStartPos(int16_t pos)
- {
- startPos_ = pos;
- }
-
- void UpdateWidth(uint16_t textWidth, uint16_t labelWidth)
- {
- textX_ = textWidth;
- labelX_ = labelWidth;
- waitCount_ = ANIM_WAIT_COUNT;
- preRunTime_ = 0;
- decimal_ = 0;
- offsetX_ = startPos_;
- static_cast(view_)->offsetX_ = offsetX_;
- view_->Invalidate();
- }
-
- void Callback(UIView* view) override
- {
- if (view == nullptr) {
- return;
- }
-
- uint32_t curTime = GetRunTime();
- if (waitCount_ > 0) {
- waitCount_--;
- preRunTime_ = curTime;
- return;
- }
- uint32_t time = (curTime > preRunTime_) ? (curTime - preRunTime_) : (UINT32_MAX - preRunTime_ + curTime);
- // 1000: 1000 milliseconds is 1 second
- float floatStep = (static_cast(time * speed_) / 1000) + decimal_;
- uint16_t integerStep = static_cast(floatStep);
- decimal_ = floatStep - integerStep;
- preRunTime_ = curTime;
-
- if (integerStep != 0) {
- offsetX_ -= integerStep;
- } else {
- return;
- }
- offsetX_ = ((offsetX_ - labelX_) % (textX_ + labelX_)) + labelX_;
- static_cast(view)->offsetX_ = offsetX_;
- view->Invalidate();
- }
-
- void SetAnimatorSpeed(uint16_t animSpeed)
- {
- speed_ = animSpeed;
- decimal_ = 0;
- }
-
-private:
- static constexpr uint8_t ANIM_WAIT_COUNT = 50;
- int16_t startPos_;
- uint16_t textX_;
- uint16_t labelX_;
- int16_t offsetX_;
- uint16_t waitCount_;
- uint16_t speed_;
- uint32_t preRunTime_;
- float decimal_;
-};
-
-UILabel::UILabel()
- : needRefresh_(false), useTextColor_(false), hasAnimator_(false), lineBreakMode_(LINE_BREAK_ELLIPSIS),
- ellipsisIndex_(Text::TEXT_ELLIPSIS_END_INV), offsetX_(0), textColor_(Color::White()), animator_ { nullptr }
-{
- Theme* theme = ThemeManager::GetInstance().GetCurrent();
- Style& style = (theme != nullptr) ? (theme->GetLabelStyle()) : (StyleDefault::GetLabelStyle());
- UIView::SetStyle(style);
- if (UIFont::GetInstance()->IsVectorFont()) {
- labelText_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, 18); // 18: means font size
- } else {
- labelText_.SetFontId(style.font_);
- }
- animator_.speed = DEFAULT_ANIMATOR_SPEED;
-}
-
-UILabel::~UILabel()
-{
- if (hasAnimator_) {
- animator_.animator->Stop();
- delete animator_.animator;
- hasAnimator_ = false;
- }
- DeleteMeasureView();
-}
-
-int16_t UILabel::GetWidth()
-{
- if (needRefresh_ && labelText_.IsExpandWidth()) {
- ReMeasure();
- }
- return UIView::GetWidth();
-}
-
-int16_t UILabel::GetHeight()
-{
- if (needRefresh_ && labelText_.IsExpandHeight()) {
- ReMeasure();
- }
- return UIView::GetHeight();
-}
-
-void UILabel::SetText(const char* text)
-{
- labelText_.SetText(text);
- if (labelText_.IsNeedRefresh()) {
- RefreshLabel();
- }
-}
-
-void UILabel::SetLineBreakMode(const uint8_t lineBreakMode)
-{
- if (lineBreakMode >= LINE_BREAK_MAX || lineBreakMode_ == lineBreakMode) {
- return;
- }
- lineBreakMode_ = lineBreakMode;
- if ((lineBreakMode_ == LINE_BREAK_ADAPT) ||
- (lineBreakMode_ == LINE_BREAK_STRETCH) ||
- (lineBreakMode_ == LINE_BREAK_MARQUEE)) {
- labelText_.SetExpandWidth(true);
- } else {
- labelText_.SetExpandWidth(false);
- }
- if ((lineBreakMode_ == LINE_BREAK_ADAPT) || (lineBreakMode_ == LINE_BREAK_WRAP)) {
- labelText_.SetExpandHeight(true);
- } else {
- labelText_.SetExpandHeight(false);
- }
- RefreshLabel();
-}
-
-void UILabel::SetAlign(UITextLanguageAlignment horizontalAlign, UITextLanguageAlignment verticalAlign)
-{
- labelText_.SetAlign(horizontalAlign, verticalAlign);
- if (labelText_.IsNeedRefresh()) {
- RefreshLabel();
- }
-}
-
-void UILabel::SetFontId(uint8_t fontId)
-{
- labelText_.SetFontId(fontId);
- if (labelText_.IsNeedRefresh()) {
- RefreshLabel();
- }
-}
-
-void UILabel::SetFont(const char* name, uint8_t size)
-{
- labelText_.SetFont(name, size);
- if (labelText_.IsNeedRefresh()) {
- RefreshLabel();
- }
-}
-
-uint16_t UILabel::GetTextWidth()
-{
- if (labelText_.IsNeedRefresh()) {
- Style style = GetStyleConst();
- style.textColor_ = GetTextColor();
- labelText_.ReMeasureTextSize(GetContentRect(), style);
- }
- return labelText_.GetTextSize().x;
-}
-
-uint16_t UILabel::GetTextHeight()
-{
- if (labelText_.IsNeedRefresh()) {
- Style style = GetStyleConst();
- style.textColor_ = GetTextColor();
- labelText_.ReMeasureTextSize(GetContentRect(), style);
- }
- return labelText_.GetTextSize().y;
-}
-
-void UILabel::SetWidth(int16_t width)
-{
- if (GetWidth() != width) {
- UIView::SetWidth(width);
- if (lineBreakMode_ == LINE_BREAK_ELLIPSIS) {
- RefreshLabel();
- }
- Invalidate();
- }
-}
-
-void UILabel::SetHeight(int16_t height)
-{
- if (GetHeight() != height) {
- UIView::SetHeight(height);
- if (lineBreakMode_ == LINE_BREAK_ELLIPSIS) {
- RefreshLabel();
- }
- Invalidate();
- }
-}
-
-void UILabel::RefreshLabel()
-{
- Invalidate();
- if (!needRefresh_) {
- needRefresh_ = true;
- AddMeasureView();
- }
-}
-
-void UILabel::ReMeasure()
-{
- if (!needRefresh_) {
- return;
- }
- needRefresh_ = false;
- Style style = GetStyleConst();
- style.textColor_ = GetTextColor();
- labelText_.ReMeasureTextSize(GetContentRect(), style);
- Point textSize = labelText_.GetTextSize();
- switch (lineBreakMode_) {
- case LINE_BREAK_ADAPT:
- Resize(textSize.x, textSize.y);
- break;
- case LINE_BREAK_STRETCH:
- SetWidth(textSize.x);
- break;
- case LINE_BREAK_WRAP:
- SetHeight(textSize.y);
- break;
- case LINE_BREAK_ELLIPSIS:
- ellipsisIndex_ = labelText_.GetEllipsisIndex(GetContentRect(), style);
- break;
- case LINE_BREAK_MARQUEE:
- RemeasureForMarquee(textSize.x);
- break;
- default:
- break;
- }
- RemeasureForRotate();
-}
-
-void UILabel::RemeasureForMarquee(int16_t textWidth)
-{
- int16_t rectWidth = GetWidth();
- if (textWidth > rectWidth) {
- offsetX_ = GetRollStartPos();
- if (labelText_.GetDirect() == TEXT_DIRECT_RTL) {
- labelText_.SetAlign(TEXT_ALIGNMENT_RIGHT);
- } else {
- labelText_.SetAlign(TEXT_ALIGNMENT_LEFT);
- }
- if (hasAnimator_) {
- static_cast(animator_.animator)->UpdateWidth(textWidth, rectWidth);
- } else {
- LabelAnimator* animator = new LabelAnimator(textWidth, rectWidth, offsetX_, this);
- animator->SetAnimatorSpeed(animator_.speed);
- animator_.animator = animator;
- hasAnimator_ = true;
- }
- animator_.animator->Start();
- } else {
- offsetX_ = 0;
- if (hasAnimator_) {
- animator_.animator->Stop();
- }
- }
-}
-
-void UILabel::SetRollStartPos(int16_t pos)
-{
- if (hasAnimator_) {
- static_cast(animator_.animator)->SetStartPos(pos);
- } else {
- animator_.pos = pos;
- }
-}
-
-int16_t UILabel::GetRollStartPos() const
-{
- return hasAnimator_ ? static_cast(animator_.animator)->GetStartPos() : animator_.pos;
-}
-
-void UILabel::SetRollSpeed(uint16_t speed)
-{
- if (hasAnimator_) {
- static_cast(animator_.animator)->SetAnimatorSpeed(speed);
- } else {
- animator_.speed = speed;
- }
-}
-
-void UILabel::RemeasureForRotate()
-{
- if (labelText_.GetTextRotation() != LabelRotateDegree::DEGREE_0) {
- delete transMap_;
- transMap_ = new TransformMap(GetContentRect());
- transMap_->Rotate(GetTextRotateDegree(), { 0, 0 });
- Invalidate();
- }
-
- if (transMap_ != nullptr && labelText_.GetTextRotation() == LabelRotateDegree::DEGREE_0) {
- delete transMap_;
- transMap_ = nullptr;
- Invalidate();
- }
-}
-
-void UILabel::OnDraw(const Rect& invalidatedArea)
-{
- UIView::OnDraw(invalidatedArea);
- Style style = GetStyleConst();
- style.textColor_ = GetTextColor();
- if (opaScale_ != OPA_OPAQUE) {
- style.textOpa_ = opaScale_;
- }
- labelText_.OnDraw(invalidatedArea, GetOrigRect(), GetContentRect(), offsetX_, style, ellipsisIndex_);
-}
-} // namespace OHOS
\ No newline at end of file
diff --git a/frameworks/ui/src/components/ui_label_button.cpp b/frameworks/ui/src/components/ui_label_button.cpp
deleted file mode 100755
index 2dc294e..0000000
--- a/frameworks/ui/src/components/ui_label_button.cpp
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#include "components/ui_label_button.h"
-#include "common/typed_text.h"
-#include "draw/draw_label.h"
-#include "font/ui_font.h"
-
-namespace OHOS {
-UILabelButton::UILabelButton() : offset_({ 0, 0 })
-{
- labelStyle_ = StyleDefault::GetDefaultStyle();
- if (UIFont::GetInstance()->IsVectorFont()) {
- labelButtonText_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, 18); // 18: means font size
- } else {
- labelButtonText_.SetFontId(style_->font_);
- }
- labelButtonText_.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
-}
-
-void UILabelButton::OnDraw(const Rect& invalidatedArea)
-{
- UIButton::OnDraw(invalidatedArea);
-
- Rect textRect = GetContentRect();
- textRect.SetLeft(textRect.GetLeft() + offset_.x);
- textRect.SetTop(textRect.GetTop() + offset_.y);
- labelButtonText_.ReMeasureTextSize(textRect, labelStyle_);
- labelButtonText_.OnDraw(invalidatedArea, GetOrigRect(), textRect, 0, labelStyle_, Text::TEXT_ELLIPSIS_END_INV);
-}
-} // namespace OHOS
diff --git a/frameworks/ui/src/components/ui_list.cpp b/frameworks/ui/src/components/ui_list.cpp
deleted file mode 100755
index 159865a..0000000
--- a/frameworks/ui/src/components/ui_list.cpp
+++ /dev/null
@@ -1,636 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#include "components/ui_list.h"
-
-namespace OHOS {
-UIList::Recycle::~Recycle()
-{
- ListNode* node = scrapView_.Begin();
- while (node != scrapView_.End()) {
- if (node->data_) {
- UIView* deleteView = node->data_;
- if (deleteView != nullptr) {
- delete deleteView;
- deleteView = nullptr;
- node->data_ = nullptr;
- }
- }
- node = node->next_;
- }
- scrapView_.Clear();
-}
-
-void UIList::Recycle::InitRecycle()
-{
- if (adapter_ == nullptr || listView_ == nullptr) {
- return;
- }
- FillActiveView();
- listView_->Invalidate();
-}
-
-UIView* UIList::Recycle::GetView(int16_t index)
-{
- if (adapter_ == nullptr) {
- return nullptr;
- }
- UIView* inView = nullptr;
- UIView* retView = nullptr;
-
- if (scrapView_.Size() != 0) {
- inView = scrapView_.Back();
- }
-
- retView = adapter_->GetView(inView, index);
- if (retView != nullptr) {
- retView->SetViewIndex(index);
- scrapView_.PopBack();
- }
- return retView;
-}
-
-void UIList::Recycle::FillActiveView()
-{
- if (adapter_ == nullptr || listView_ == nullptr) {
- return;
- }
- int16_t index = listView_->GetStartIndex();
- if (listView_->GetDirection() == UIList::VERTICAL) {
- int16_t childBottom = 0;
- while (index < adapter_->GetCount() && childBottom < listView_->GetHeight()) {
- UIView* view = GetView(index);
- if (view == nullptr) {
- break;
- }
- listView_->PushBack(view);
- if (listView_->childrenTail_) {
- childBottom =
- listView_->childrenTail_->GetY() + listView_->childrenTail_->GetRelativeRect().GetHeight();
- } else {
- break;
- }
- index++;
- }
- } else {
- int16_t childRight = 0;
- while (index < adapter_->GetCount() && childRight < listView_->GetWidth()) {
- UIView* view = GetView(index);
- listView_->PushBack(view);
- if (listView_->childrenTail_) {
- childRight = listView_->childrenTail_->GetX() + listView_->childrenTail_->GetRelativeRect().GetWidth();
- } else {
- break;
- }
- index++;
- }
- }
-}
-
-UIList::UIList()
- : isLoopList_(false),
- isReCalculateDragEnd_(true),
- autoAlign_(false),
- startIndex_(0),
- topIndex_(0),
- bottomIndex_(0),
- selectPosition_(0),
- onSelectedIndex_(0),
- onSelectedView_(nullptr),
- recycle_(this),
- scrollListener_(nullptr)
-{
- direction_ = VERTICAL;
- touchable_ = true;
- SetDraggable(true);
-}
-
-UIList::UIList(uint8_t direction)
- : isLoopList_(false),
- isReCalculateDragEnd_(true),
- autoAlign_(false),
- startIndex_(0),
- topIndex_(0),
- bottomIndex_(0),
- selectPosition_(0),
- onSelectedIndex_(0),
- onSelectedView_(nullptr),
- recycle_(this),
- scrollListener_(nullptr)
-{
- direction_ = direction;
- touchable_ = true;
- SetDraggable(true);
-}
-
-UIList::~UIList()
-{
- UIView* view = GetChildrenHead();
- while (view != nullptr) {
- UIView* tmp = view->GetNextSibling();
- delete view;
- view = tmp;
- }
-}
-
-bool UIList::OnDragEvent(const DragEvent& event)
-{
- if (animator_.GetState() != Animator::STOP) {
- UIAbstractScroll::StopAnimator();
- }
- int16_t xDistance = event.GetDeltaX();
- int16_t yDistance = event.GetDeltaY();
- isReCalculateDragEnd_ = true;
- if (direction_ == VERTICAL) {
- RefreshDeltaY(yDistance);
- DragYInner(yDistance);
- } else {
- DragXInner(xDistance);
- }
- return UIView::OnDragEvent(event);
-}
-
-bool UIList::OnDragEndEvent(const DragEvent& event)
-{
- Point last = event.GetPreLastPoint();
- Point current = event.GetLastPoint();
- if (last.x == current.x && last.y == current.y) {
- last = current;
- current = event.GetCurrentPos();
- }
- isReCalculateDragEnd_ = false;
- if (!DragThrowAnimator(current, last)) {
- if (scrollListener_ && scrollListener_->GetScrollState() == ListScrollListener::SCROLL_STATE_MOVE) {
- scrollListener_->SetScrollState(ListScrollListener::SCROLL_STATE_STOP);
- scrollListener_->OnScrollEnd(onSelectedIndex_, onSelectedView_);
- }
- }
- return UIView::OnDragEndEvent(event);
-}
-
-void UIList::OnPressEvent(const PressEvent& event)
-{
- StopAnimator();
- UIView::OnPressEvent(event);
-}
-
-void UIList::ScrollBy(int16_t distance)
-{
- if (direction_ == VERTICAL) {
- DragYInner(distance);
- } else {
- DragXInner(distance);
- }
- if (scrollListener_ && scrollListener_->GetScrollState() == ListScrollListener::SCROLL_STATE_MOVE) {
- scrollListener_->SetScrollState(ListScrollListener::SCROLL_STATE_STOP);
- scrollListener_->OnScrollEnd(onSelectedIndex_, onSelectedView_);
- }
-}
-
-bool UIList::DragXInner(int16_t distance)
-{
- if (IsNeedReCalculateDragEnd()) {
- return false;
- }
- uint16_t listWidth = GetWidth();
- if (distance == 0) {
- return true;
- }
- bool ret = 0;
- do {
- ret = MoveChildStep(distance);
- } while (ret);
-
- if (isLoopList_) {
- return MoveOffset(distance);
- }
- if (distance > 0) {
- if (childrenHead_ && childrenHead_->GetX() + distance > scrollBlankSize_) {
- distance = scrollBlankSize_ - childrenHead_->GetX();
- }
- } else {
- if (childrenTail_) {
- if (childrenTail_->GetRelativeRect().GetRight() <= listWidth - scrollBlankSize_) {
- distance = 0;
- } else if (listWidth - (childrenTail_->GetX() + childrenTail_->GetRelativeRect().GetWidth() + distance) >
- scrollBlankSize_) {
- distance =
- listWidth - scrollBlankSize_ - childrenTail_->GetX() - childrenTail_->GetRelativeRect().GetWidth();
- }
- }
- }
- return MoveOffset(distance);
-}
-
-bool UIList::DragYInner(int16_t distance)
-{
- if (IsNeedReCalculateDragEnd()) {
- return false;
- }
- uint16_t listHeigh = GetHeight();
- if (distance == 0) {
- return true;
- }
- bool ret = 0;
- do {
- ret = MoveChildStep(distance);
- } while (ret);
-
- if (isLoopList_) {
- return MoveOffset(distance);
- }
- if (distance > 0) {
- if (childrenHead_ && childrenHead_->GetY() + distance > scrollBlankSize_) {
- distance = scrollBlankSize_ - childrenHead_->GetY();
- }
- } else {
- if (childrenTail_) {
- if (childrenTail_->GetRelativeRect().GetBottom() <= listHeigh - scrollBlankSize_) {
- distance = 0;
- } else if (listHeigh - (childrenTail_->GetY() + childrenTail_->GetRelativeRect().GetHeight() + distance) >
- scrollBlankSize_) {
- distance =
- listHeigh - scrollBlankSize_ - childrenTail_->GetY() - childrenTail_->GetRelativeRect().GetHeight();
- }
- }
- }
- return MoveOffset(distance);
-}
-
-bool UIList::MoveOffset(int16_t offset)
-{
- if (offset == 0) {
- return false;
- }
- if (direction_ == VERTICAL) {
- MoveChildByOffset(0, offset);
- } else {
- MoveChildByOffset(offset, 0);
- }
- Invalidate();
- if (scrollListener_ && scrollListener_->GetScrollState() == ListScrollListener::SCROLL_STATE_STOP) {
- scrollListener_->SetScrollState(ListScrollListener::SCROLL_STATE_MOVE);
- scrollListener_->OnScrollStart(onSelectedIndex_, onSelectedView_);
- }
-
- return true;
-}
-
-bool UIList::IsNeedReCalculateDragEnd()
-{
- if (!autoAlign_ || isReCalculateDragEnd_ || onSelectedView_ == nullptr) {
- return false;
- }
- int16_t animationLess = 0;
- if (direction_ == VERTICAL) {
- animationLess = animatorCallback_.endValueY_ - animatorCallback_.previousValueY_;
- } else {
- animationLess = animatorCallback_.endValueX_ - animatorCallback_.previousValueX_;
- }
- if (!isDragging_ || MATH_ABS(animationLess) > RECALCULATE_DRAG_DISTANCE) {
- return false;
- }
- return true;
-}
-bool UIList::ReCalculateDragEnd()
-{
- if (onSelectedView_ == nullptr || isReCalculateDragEnd_ || !autoAlign_) {
- return false;
- }
-
- int16_t offsetX = 0;
- int16_t offsetY = 0;
- if (direction_ == VERTICAL) {
- offsetY = selectPosition_ - (onSelectedView_->GetY() + (onSelectedView_->GetRelativeRect().GetHeight() >> 1));
- } else {
- offsetX = selectPosition_ - (onSelectedView_->GetX() + (onSelectedView_->GetRelativeRect().GetWidth() >> 1));
- }
- animatorCallback_.SetDragStartValue(0, 0);
- animatorCallback_.SetDragEndValue(offsetX, offsetY);
- animatorCallback_.SetDragTimes(RECALCULATE_DRAG_TIMES * DRAG_ACC_FACTOR / GetDragACCLevel());
- animator_.Start();
- isReCalculateDragEnd_ = true;
- return true;
-}
-
-bool UIList::MoveChildStepInner(int16_t distance,
- int16_t (UIView::*pfnGetXOrY)() const,
- int16_t (Rect::*pfnGetWidthOrHeight)() const)
-{
- bool popRet = false;
- bool pushRet = false;
- if (distance > 0) {
- if ((childrenHead_ == nullptr) || ((childrenHead_->*pfnGetXOrY)() + distance > 0)) {
- UIView* newView = recycle_.GetView(GetIndexDec(topIndex_));
- if (newView != nullptr) {
- PushFront(newView);
- pushRet = true;
- } else {
- return false;
- }
- }
- if (childrenTail_ != nullptr &&
- ((childrenTail_->*pfnGetXOrY)() + distance > (this->GetRelativeRect().*pfnGetWidthOrHeight)())) {
- PopItem(childrenTail_);
- popRet = true;
- }
- } else {
- if ((childrenTail_ == nullptr) ||
- ((childrenTail_->*pfnGetXOrY)() + (childrenTail_->GetRelativeRect().*pfnGetWidthOrHeight)() + distance <
- (this->GetRelativeRect().*pfnGetWidthOrHeight)())) {
- UIView* newView = recycle_.GetView(GetIndexInc(bottomIndex_));
- if (newView != nullptr) {
- PushBack(newView);
- pushRet = true;
- } else {
- return false;
- }
- }
- if (childrenHead_ &&
- (childrenHead_->*pfnGetXOrY)() + distance + (childrenHead_->GetRelativeRect().*pfnGetWidthOrHeight)() < 0) {
- PopItem(childrenHead_);
- popRet = true;
- }
- }
- return (popRet || pushRet);
-}
-
-bool UIList::MoveChildStep(int16_t distance)
-{
- if (direction_ == VERTICAL) {
- return MoveChildStepInner(distance, &UIView::GetY, &Rect::GetHeight);
- } else {
- return MoveChildStepInner(distance, &UIView::GetX, &Rect::GetWidth);
- }
-}
-
-void UIList::SetAdapter(AbstractAdapter* adapter)
-{
- recycle_.SetAdapter(adapter);
- recycle_.InitRecycle();
-}
-
-UIView* UIList::GetSelectView()
-{
- if (onSelectedView_ != nullptr) {
- return onSelectedView_;
- }
- if (childrenHead_ == nullptr || selectPosition_ == 0) {
- return nullptr;
- }
- UIView* child = childrenHead_;
- while (child != nullptr) {
- if (direction_ == VERTICAL) {
- if (child->GetY() <= selectPosition_ &&
- child->GetY() + child->GetRelativeRect().GetHeight() >= selectPosition_) {
- if (scrollListener_ != nullptr) {
- scrollListener_->OnItemSelected(child->GetViewIndex(), child);
- }
- return child;
- }
- } else {
- if (child->GetX() <= selectPosition_ &&
- child->GetX() + child->GetRelativeRect().GetWidth() >= selectPosition_) {
- if (scrollListener_ != nullptr) {
- scrollListener_->OnItemSelected(child->GetViewIndex(), child);
- }
- return child;
- }
- }
- child = child->GetNextSibling();
- }
- return nullptr;
-}
-
-void UIList::PushBack(UIView* view)
-{
- if (view == nullptr) {
- return;
- }
- if (childrenTail_ == nullptr) {
- SetHead(view);
- } else {
- if (direction_ == VERTICAL) {
- view->SetPosition(0, childrenTail_->GetY() + childrenTail_->GetRelativeRect().GetHeight());
- } else {
- view->SetPosition(childrenTail_->GetX() + childrenTail_->GetRelativeRect().GetWidth(), 0);
- }
- bottomIndex_ = GetIndexInc(bottomIndex_);
- }
-
- view->SetDragParentInstead(true);
- UIViewGroup::Add(view);
-}
-
-void UIList::PushFront(UIView* view)
-{
- if (view == nullptr) {
- return;
- }
- if (GetChildrenHead() == nullptr) {
- SetHead(view);
- } else {
- if (direction_ == VERTICAL) {
- view->SetPosition(0, GetChildrenHead()->GetY() - view->GetRelativeRect().GetHeight());
- } else {
- view->SetPosition(GetChildrenHead()->GetX() - view->GetRelativeRect().GetWidth(), 0);
- }
- topIndex_ = GetIndexDec(topIndex_);
- }
- view->SetDragParentInstead(true);
- UIViewGroup::Insert(nullptr, view);
-}
-
-void UIList::PopItem(UIView* view)
-{
- if (view == nullptr) {
- return;
- }
- recycle_.AddScrapView(view);
- if (view == GetChildrenHead()) {
- topIndex_ = GetIndexInc(topIndex_);
- }
-
- if (view == childrenTail_) {
- bottomIndex_ = GetIndexDec(bottomIndex_);
- }
- UIViewGroup::Remove(view);
-}
-
-void UIList::SetHead(UIView* view)
-{
- if (view != nullptr) {
- view->SetPosition(0, 0);
- topIndex_ = startIndex_;
- bottomIndex_ = startIndex_;
- }
-}
-
-void UIList::MoveChildByOffset(int16_t xOffset, int16_t yOffset)
-{
- UIView* view = GetChildrenHead();
- if (view == nullptr) {
- return;
- }
- int16_t x;
- int16_t y;
- int16_t height;
- int16_t width;
-
- if (onSelectedIndex_ != NULL_SELECT_INDEX && selectPosition_ != 0) {
- if (direction_ == VERTICAL) {
- height = view->GetRelativeRect().GetHeight();
- if (GetChildrenHead()->GetY() + yOffset > selectPosition_ ||
- childrenTail_->GetY() + height + yOffset < selectPosition_) {
- onSelectedIndex_ = NULL_SELECT_INDEX;
- onSelectedView_ = nullptr;
- if (scrollListener_ != nullptr) {
- scrollListener_->OnItemSelected(onSelectedIndex_, onSelectedView_);
- }
- }
- } else {
- width = view->GetRelativeRect().GetWidth();
- if (GetChildrenHead()->GetX() + xOffset > selectPosition_ ||
- childrenTail_->GetX() + width < selectPosition_) {
- onSelectedIndex_ = NULL_SELECT_INDEX;
- onSelectedView_ = nullptr;
- if (scrollListener_ != nullptr) {
- scrollListener_->OnItemSelected(onSelectedIndex_, onSelectedView_);
- }
- }
- }
- }
- bool isSelectViewFind = false;
- while (view != nullptr) {
- x = view->GetX() + xOffset;
- y = view->GetY() + yOffset;
- view->SetPosition(x, y);
-
- if (selectPosition_ != 0 && !isSelectViewFind) {
- if (direction_ == VERTICAL) {
- height = view->GetRelativeRect().GetHeight();
- if (y <= selectPosition_ && y + height >= selectPosition_ && onSelectedView_ != view) {
- onSelectedIndex_ = view->GetViewIndex();
- onSelectedView_ = view;
- if (scrollListener_ != nullptr) {
- scrollListener_->OnItemSelected(onSelectedIndex_, onSelectedView_);
- }
- isSelectViewFind = true;
- }
- } else {
- width = view->GetRelativeRect().GetWidth();
- if (x <= selectPosition_ && x + width >= selectPosition_ && onSelectedView_ != view) {
- onSelectedIndex_ = view->GetViewIndex();
- onSelectedView_ = view;
- if (scrollListener_ != nullptr) {
- scrollListener_->OnItemSelected(onSelectedIndex_, onSelectedView_);
- }
- isSelectViewFind = true;
- }
- }
- }
- view = view->GetNextSibling();
- }
-}
-
-void UIList::StopAnimator()
-{
- UIAbstractScroll::StopAnimator();
- if (!ReCalculateDragEnd()) {
- if ((scrollListener_ != nullptr) &&
- (scrollListener_->GetScrollState() == ListScrollListener::SCROLL_STATE_MOVE)) {
- scrollListener_->SetScrollState(ListScrollListener::SCROLL_STATE_STOP);
- scrollListener_->OnScrollEnd(onSelectedIndex_, onSelectedView_);
- }
- }
-}
-
-uint16_t UIList::GetIndexInc(uint16_t index)
-{
- uint16_t ret = index + 1;
- if (isLoopList_ && recycle_.GetAdapterItemCount() != 0) {
- ret = ret % recycle_.GetAdapterItemCount();
- }
- return ret;
-}
-
-uint16_t UIList::GetIndexDec(uint16_t index)
-{
- int16_t ret = index - 1;
- if (isLoopList_ && (ret < 0)) {
- ret = recycle_.GetAdapterItemCount() - 1;
- }
- return ret;
-}
-
-void UIList::ScrollTo(uint16_t index)
-{
- UIView* child = GetChildrenHead();
- UIView* tmp = nullptr;
- while (child != nullptr) {
- tmp = child;
- child = child->GetNextSibling();
- PopItem(tmp);
- }
- onSelectedView_ = nullptr;
- SetStartIndex(index);
- recycle_.InitRecycle();
-}
-
-void UIList::RefreshList()
-{
- int16_t topIndex = topIndex_;
- UIView* child = GetChildrenHead();
- UIView* tmp = nullptr;
- int16_t offset = 0;
- if (child != nullptr) {
- if (direction_ == VERTICAL) {
- offset = child->GetY();
- } else {
- offset = child->GetX();
- }
- }
-
- while (child != nullptr) {
- tmp = child;
- child = child->GetNextSibling();
- PopItem(tmp);
- }
- onSelectedView_ = nullptr;
-
- uint16_t tmpStartIndex = startIndex_;
- if (topIndex > recycle_.GetAdapterItemCount() - 1) {
- startIndex_ = 0;
- offset = 0;
- } else {
- startIndex_ = topIndex;
- }
- recycle_.InitRecycle();
- startIndex_ = tmpStartIndex;
-
- if (direction_ == VERTICAL) {
- DragYInner(offset);
- } else {
- DragXInner(offset);
- }
- Invalidate();
-}
-
-void UIList::RemoveAll()
-{
- UIViewGroup::RemoveAll();
- recycle_.ClearScrapView();
-}
-} // namespace OHOS
\ No newline at end of file
diff --git a/frameworks/ui/src/components/ui_picker.cpp b/frameworks/ui/src/components/ui_picker.cpp
deleted file mode 100755
index 57e32f6..0000000
--- a/frameworks/ui/src/components/ui_picker.cpp
+++ /dev/null
@@ -1,443 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#include "components/ui_picker.h"
-#include "draw/draw_line.h"
-#include "draw/draw_rect.h"
-#include "themes/theme_manager.h"
-
-namespace OHOS {
-class PickerListScrollListener : public ListScrollListener {
-public:
- PickerListScrollListener(UIPicker* picker, UIList* list)
- : listView_(list), pickerView_(picker), selectView_(nullptr), lastSelectView_(nullptr),
- selectIndex_(0), isInitted_(false){}
-
- virtual ~PickerListScrollListener() {}
-
- void OnItemSelected(int16_t index, UIView* view) override
- {
- if (!isInitted_) {
- return;
- }
-
- if ((lastSelectView_ != nullptr) && (listView_ != nullptr) && (pickerView_ != nullptr) && (view != nullptr)) {
- lastSelectView_->SetStyle(STYLE_TEXT_COLOR, pickerView_->GetBackgroundTextColor().full);
- if (pickerView_->backgroundFontName_ == nullptr) {
- static_cast(lastSelectView_)->SetFontId(pickerView_->backgroundFontId_);
- } else {
- static_cast(lastSelectView_)
- ->SetFont(pickerView_->backgroundFontName_, pickerView_->backgroundFontSize_);
- }
- view->SetStyle(STYLE_TEXT_COLOR, pickerView_->GetHighlightTextColor().full);
- if (pickerView_->highlightFontName_ == nullptr) {
- static_cast(view)->SetFontId(pickerView_->highlightFontId_);
- } else {
- static_cast(view)
- ->SetFont(pickerView_->highlightFontName_, pickerView_->highlightFontSize_);
- }
- lastSelectView_ = view;
- listView_->Invalidate();
- }
- }
-
- void OnScrollEnd(int16_t index, UIView* view) override
- {
- if ((view == nullptr) || (listView_ == nullptr) || (pickerView_ == nullptr)) {
- return;
- }
-
- if (lastSelectView_ != nullptr) {
- lastSelectView_->SetStyle(STYLE_TEXT_COLOR, pickerView_->GetBackgroundTextColor().full);
- if (pickerView_->backgroundFontName_ == nullptr) {
- static_cast(lastSelectView_)->SetFontId(pickerView_->backgroundFontId_);
- } else {
- static_cast(lastSelectView_)
- ->SetFont(pickerView_->backgroundFontName_, pickerView_->backgroundFontSize_);
- }
- lastSelectView_ = view;
- }
-
- view->SetStyle(STYLE_TEXT_COLOR, pickerView_->GetHighlightTextColor().full);
- if (pickerView_->highlightFontName_ == nullptr) {
- static_cast(view)->SetFontId(pickerView_->highlightFontId_);
- } else {
- static_cast(view)
- ->SetFont(pickerView_->highlightFontName_, pickerView_->highlightFontSize_);
- }
-
- listView_->Invalidate();
- selectView_ = view;
- selectIndex_ = index;
-
- if (pickerView_->pickerListener_) {
- pickerView_->pickerListener_->OnPickerStoped(*pickerView_);
- }
- }
-
- void SetSelectView(UIView* view)
- {
- selectView_ = view;
- lastSelectView_ = view;
- }
-
- const UIView* GetSelectView() const
- {
- return selectView_;
- }
-
- void SetSelectIndex(uint16_t index)
- {
- selectIndex_ = index;
- }
-
- uint16_t GetSelectIndex() const
- {
- return selectIndex_;
- }
-
- void SetInitStatus(bool status)
- {
- isInitted_ = status;
- }
-
-private:
- UIList* listView_;
- UIPicker* pickerView_;
- UIView* selectView_;
- UIView* lastSelectView_;
- uint16_t selectIndex_;
- bool isInitted_;
-};
-
-UIPicker::UIPicker()
- : isWidthSet_(false),
- isHeightSet_(false),
- maxCount_(0),
- setSelectedIndex_(0),
- backgroundFontSize_(0),
- highlightFontSize_(0),
- backgroundFontName_(nullptr),
- highlightFontName_(nullptr),
- itemsWidth_(0),
- itemsHeight_(0),
- rangeValue_(nullptr),
- rangeValueCount_(0),
- startValue_(0),
- endValue_(0),
- isSetAdaptered_(false),
- pickerListener_(nullptr)
-{
- Theme* theme = ThemeManager::GetInstance().GetCurrent();
- if (theme != nullptr) {
- style_ = &(theme->GetPickerBackgroundStyle());
- } else {
- style_ = &(StyleDefault::GetPickerBackgroundStyle());
- }
- backgroundFontId_ = style_->font_;
- backgroundColor_ = style_->textColor_;
- direct_ = UITextLanguageDirect::TEXT_DIRECT_LTR;
-
- if (theme != nullptr) {
- style_ = &(theme->GetPickerHighlightStyle());
- } else {
- style_ = &(StyleDefault::GetPickerHighlightStyle());
- }
- highlightFontId_ = style_->font_;
- highlightColor_ = style_->textColor_;
-
- list_.SetThrowDrag(true);
- list_.SetLoopState(false);
- list_.EnableAutoAlign(true);
- list_.SetIntercept(false);
- PickerListScrollListener* listener = new PickerListScrollListener(this, &list_);
- list_.SetScrollStateListener(listener);
- listListener_ = static_cast(listener);
- Add(&list_);
-}
-
-UIPicker::~UIPicker()
-{
- ClearValues();
- Remove(&list_);
- if (listListener_ != nullptr) {
- delete static_cast(listListener_);
- listListener_ = nullptr;
- }
-
- if (backgroundFontName_ != nullptr) {
- UIFree(backgroundFontName_);
- backgroundFontName_ = nullptr;
- }
-
- if (highlightFontName_ != nullptr) {
- UIFree(highlightFontName_);
- highlightFontName_ = nullptr;
- }
-}
-
-bool UIPicker::SetValues(int16_t start, int16_t end)
-{
- if (start > end) {
- return false;
- }
-
- startValue_ = start;
- endValue_ = end;
- return RefreshValues(start, end);
-}
-
-bool UIPicker::SetValues(const char* value[], uint16_t count)
-{
- if (value == nullptr) {
- return false;
- }
-
- rangeValue_ = value;
- rangeValueCount_ = count;
- return RefreshValues(value, count);
-}
-
-void UIPicker::Refresh()
-{
- if (rangeValue_) {
- RefreshValues(rangeValue_, rangeValueCount_);
- } else if (startValue_ != 0 || endValue_ != 0) {
- RefreshValues(startValue_, endValue_);
- }
-}
-
-bool UIPicker::RefreshValues(int16_t start, int16_t end)
-{
- if (!isWidthSet_ || !isHeightSet_ || !itemsHeight_ || (start == 0 && end == 0)) {
- return false;
- }
-
- ClearList();
- textAdapter_.SetData(start, end);
- maxCount_ = end - start + 1;
- RefreshList();
- if (setSelectedIndex_) {
- RefreshSelected(setSelectedIndex_);
- }
- return true;
-}
-
-bool UIPicker::RefreshValues(const char* value[], uint16_t count)
-{
- if (value == nullptr || !isWidthSet_ || !isHeightSet_ || !itemsHeight_) {
- return false;
- }
-
- ClearList();
- for (uint16_t i = 0; i < count; i++) {
- dataList_.PushBack(value[i]);
- }
- textAdapter_.SetData(&dataList_);
- maxCount_ = count;
- RefreshList();
- if (setSelectedIndex_) {
- RefreshSelected(setSelectedIndex_);
- }
-
- return true;
-}
-
-void UIPicker::RefreshList()
-{
- int16_t height = GetHeight();
- itemsWidth_ = GetWidth();
- textAdapter_.SetWidth(itemsWidth_);
- textAdapter_.SetHeight(itemsHeight_);
- textAdapter_.SetLineBreakMode(UILabel::LINE_BREAK_CLIP);
- if (backgroundFontName_ == nullptr) {
- textAdapter_.SetFontId(backgroundFontId_);
- } else {
- textAdapter_.SetFont(backgroundFontName_, backgroundFontSize_);
- }
- textAdapter_.GetStyle().textColor_ = backgroundColor_;
- textAdapter_.SetDirect(direct_);
- list_.SetHeight(height);
- list_.SetWidth(itemsWidth_);
- list_.SetPosition(GetWidth() / 2 - list_.GetWidth() / 2, 0); // 2: half
- list_.SetScrollBlankSize((height - itemsHeight_) / 2); // 2: half
- list_.SetSelectPosition(height / 2); // 2: half
- list_.SetStyle(*style_);
- list_.SetStyle(STYLE_BORDER_WIDTH, 0);
- list_.SetStyle(STYLE_BACKGROUND_OPA, 0);
- if (!isSetAdaptered_) {
- list_.SetAdapter(&textAdapter_);
- isSetAdaptered_ = true;
- }
-
- list_.RefreshList();
- RefreshSelected(0);
-}
-
-void UIPicker::ClearValues()
-{
- rangeValue_ = nullptr;
- rangeValueCount_ = 0;
- setSelectedIndex_ = 0;
- ClearList();
-}
-
-void UIPicker::ClearList()
-{
- maxCount_ = 0;
- itemsWidth_ = 0;
- if (listListener_) {
- PickerListScrollListener* listListener = static_cast(listListener_);
- listListener->SetSelectView(nullptr);
- listListener->SetSelectIndex(0);
- listListener->SetInitStatus(false);
- }
- dataList_.Clear();
-}
-
-bool UIPicker::SetSelected(uint16_t index)
-{
- setSelectedIndex_ = index;
- return RefreshSelected(index);
-}
-
-bool UIPicker::RefreshSelected(uint16_t index)
-{
- if (itemsHeight_ && (maxCount_ > index) && (list_.GetChildrenHead() != nullptr) && isWidthSet_ && isHeightSet_) {
- uint16_t viewIndex;
- PickerListScrollListener* listListener = static_cast(listListener_);
- listListener->SetInitStatus(false);
- // 2: half
- int16_t yOffset = (list_.GetHeight() - itemsHeight_) / 2 -
- itemsHeight_ * (index - list_.GetChildrenHead()->GetViewIndex());
- list_.ScrollBy(yOffset - list_.GetChildrenHead()->GetY());
- listListener->SetScrollState(ListScrollListener::SCROLL_STATE_STOP);
- UIView* childView = static_cast(list_.GetChildrenHead());
- uint16_t lastSelectIndex = listListener->GetSelectIndex();
-
- while (childView != nullptr) {
- viewIndex = childView->GetViewIndex();
- if (viewIndex == lastSelectIndex) {
- childView->SetStyle(STYLE_TEXT_COLOR, GetBackgroundTextColor().full);
- if (backgroundFontName_ == nullptr) {
- static_cast(childView)->SetFontId(backgroundFontId_);
- } else {
- static_cast(childView)->SetFont(backgroundFontName_, backgroundFontSize_);
- }
- }
- if (viewIndex == index) {
- childView->SetStyle(STYLE_TEXT_COLOR, GetHighlightTextColor().full);
- if (highlightFontName_ == nullptr) {
- static_cast(childView)->SetFontId(highlightFontId_);
- } else {
- static_cast(childView)->SetFont(highlightFontName_, highlightFontSize_);
- }
- listListener->SetSelectView(childView);
- listListener->SetSelectIndex(index);
- listListener->SetInitStatus(true);
- }
- childView = childView->GetNextSibling();
- }
- list_.Invalidate();
- return true;
- }
- return false;
-}
-
-uint16_t UIPicker::GetSelected() const
-{
- PickerListScrollListener* listListener = static_cast(listListener_);
- return listListener->GetSelectIndex();
-}
-
-void UIPicker::SetFontId(uint8_t backgroundFontId, uint8_t highlightFontId)
-{
- backgroundFontId_ = backgroundFontId;
- if (backgroundFontName_ != nullptr) {
- UIFree(backgroundFontName_);
- backgroundFontName_ = nullptr;
- }
-
- highlightFontId_ = highlightFontId;
- if (highlightFontName_ != nullptr) {
- UIFree(highlightFontName_);
- highlightFontName_ = nullptr;
- }
-
- Refresh();
-}
-
-void UIPicker::SetBackgroundFont(const char* name, uint8_t size)
-{
- Text::SetFont(name, size, backgroundFontName_, backgroundFontSize_);
- Refresh();
-}
-
-void UIPicker::SetHighlightFont(const char* name, uint8_t size)
-{
- Text::SetFont(name, size, highlightFontName_, highlightFontSize_);
- Refresh();
-}
-
-void UIPicker::SetTextColor(ColorType backgroundColor, ColorType highlightColor)
-{
- backgroundColor_ = backgroundColor;
- highlightColor_ = highlightColor;
- Refresh();
-}
-
-void UIPicker::SetItemHeight(int16_t height)
-{
- if (height > 0) {
- itemsHeight_ = height;
- Refresh();
- }
-}
-
-void UIPicker::SetWidth(int16_t width)
-{
- if (width > 0) {
- UIView::SetWidth(width);
- isWidthSet_ = true;
- Refresh();
- }
-}
-
-void UIPicker::SetHeight(int16_t height)
-{
- if (height > 0) {
- UIView::SetHeight(height);
- isHeightSet_ = true;
- Refresh();
- }
-}
-
-void UIPicker::SetLoopState(bool state)
-{
- list_.SetLoopState(state);
-}
-
-void UIPicker::SetDirect(UITextLanguageDirect direct)
-{
- direct_ = direct;
- Refresh();
-}
-
-void UIPicker::SetTextFormatter(TextFormatter* formatter)
-{
- textAdapter_.SetTextFormatter(formatter);
- Refresh();
-}
-}
diff --git a/frameworks/ui/src/components/ui_radio_button.cpp b/frameworks/ui/src/components/ui_radio_button.cpp
deleted file mode 100755
index 10b66f9..0000000
--- a/frameworks/ui/src/components/ui_radio_button.cpp
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#include "common/image.h"
-#include "components/root_view.h"
-#include "components/ui_radio_button.h"
-#include "components/ui_view_group.h"
-#include "default_resource/radio_button_res.h"
-#include "draw/draw_image.h"
-#include "graphic_log.h"
-#include "imgdecode/cache_manager.h"
-#include "securec.h"
-
-namespace OHOS {
-UIRadioButton::UIRadioButton() : name_(nullptr)
-{
- image_[UNSELECTED].SetSrc(GetRadioButtonOffInfo());
- image_[SELECTED].SetSrc(GetRadioButtonOnInfo());
- ImageHeader header = { 0 };
- image_[UNSELECTED].GetHeader(header);
- Resize(header.width, header.height);
-}
-
-UIRadioButton::UIRadioButton(const char* name) : name_(nullptr)
-{
- SetName(name);
- image_[UNSELECTED].SetSrc(GetRadioButtonOffInfo());
- image_[SELECTED].SetSrc(GetRadioButtonOnInfo());
- ImageHeader header = { 0 };
- image_[UNSELECTED].GetHeader(header);
- Resize(header.width, header.height);
-}
-
-void UIRadioButton::OnClickEvent(const ClickEvent& event)
-{
- SetState(SELECTED);
- Invalidate();
- UIViewGroup* curViewGroup = nullptr;
- UIViewGroup* viewGroup = static_cast(RootView::GetInstance());
- UIView* uiViewInfo = viewGroup->GetChildrenHead();
- while (uiViewInfo != nullptr) {
- if (!uiViewInfo->IsViewGroup()) {
- UIRadioButton* uiRadioButtonInfo = static_cast(uiViewInfo);
- if (uiRadioButtonInfo == this || uiViewInfo->GetViewType() != UI_RADIO_BUTTON) {
- if (uiViewInfo->GetNextSibling() != nullptr) {
- uiViewInfo = uiViewInfo->GetNextSibling();
- } else {
- if (curViewGroup != nullptr) {
- uiViewInfo = curViewGroup->GetNextSibling();
- curViewGroup = static_cast(curViewGroup->GetParent());
- } else {
- uiViewInfo = nullptr;
- }
- }
- continue;
- }
- if ((uiRadioButtonInfo->GetName() != nullptr) && (strcmp(uiRadioButtonInfo->GetName(), name_) == 0)) {
- uiRadioButtonInfo->SetState(UNSELECTED);
- }
- if (uiViewInfo->GetNextSibling() != nullptr) {
- uiViewInfo = uiViewInfo->GetNextSibling();
- } else {
- if (curViewGroup != nullptr) {
- uiViewInfo = curViewGroup->GetNextSibling();
- curViewGroup = static_cast(curViewGroup->GetParent());
- } else {
- uiViewInfo = nullptr;
- }
- }
- } else {
- if (uiViewInfo->GetNextSibling() != nullptr) {
- curViewGroup = static_cast(uiViewInfo);
- }
- uiViewInfo = (static_cast(uiViewInfo))->GetChildrenHead();
- }
- }
- UIView::OnClickEvent(event);
-}
-
-void UIRadioButton::SetName(const char* name)
-{
- if (name == nullptr) {
- return;
- }
- if (name_ != nullptr) {
- UIFree(name_);
- name_ = nullptr;
- }
- uint32_t nameLen = static_cast(strlen(name) + 1);
- if (nameLen > MAX_TEXT_LENGTH) {
- return;
- }
- name_ = static_cast(UIMalloc(nameLen));
- if (name_ != nullptr) {
- if (memcpy_s(name_, nameLen, name, nameLen) != EOK) {
- UIFree(name_);
- name_ = nullptr;
- return;
- }
- }
-}
-} // namespace OHOS
diff --git a/frameworks/ui/src/components/ui_repeat_button.cpp b/frameworks/ui/src/components/ui_repeat_button.cpp
deleted file mode 100755
index bada646..0000000
--- a/frameworks/ui/src/components/ui_repeat_button.cpp
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#include "components/ui_button.h"
-#include "components/ui_repeat_button.h"
-
-namespace OHOS {
-UIRepeatButton* UIRepeatButton::repeatButton_ = nullptr;
-
-/** default tick interval 200ms. */
-UIRepeatButton::UIRepeatButton() : ticksInterval_(200), event_({ 0, 0 }), longPressed_(false), timerRepeatID_(0) {}
-
-UIRepeatButton::~UIRepeatButton() {}
-
-void UIRepeatButton::OnDraw(const Rect& invalidatedArea)
-{
- UIButton::OnDraw(invalidatedArea);
-}
-
-void UIRepeatButton::OnReleaseEvent(const ReleaseEvent& event)
-{
- if (longPressed_ && (timerRepeatID_ != 0)) {
- longPressed_ = false;
- }
- UIButton::OnReleaseEvent(event);
-}
-
-void UIRepeatButton::OnClickEvent(const ClickEvent& event)
-{
- UIButton::OnClickEvent(event);
- SetEvent(event);
-}
-
-void UIRepeatButton::HandleTickEvent()
-{
- UIButton::OnClickEvent(event_);
-}
-
-void UIRepeatButton::repeatTimer(uint32_t uwPar)
-{
- repeatButton_->HandleTickEvent();
-}
-
-bool UIRepeatButton::OnLongPressEvent(const LongPressEvent& event)
-{
- longPressed_ = true;
- repeatButton_ = this;
- return UIButton::OnLongPressEvent(event);
-}
-
-void UIRepeatButton::SetEvent(const ClickEvent& event)
-{
- event_ = event;
-}
-} // namespace OHOS
\ No newline at end of file
diff --git a/frameworks/ui/src/components/ui_scroll_view.cpp b/frameworks/ui/src/components/ui_scroll_view.cpp
deleted file mode 100755
index 67f717b..0000000
--- a/frameworks/ui/src/components/ui_scroll_view.cpp
+++ /dev/null
@@ -1,415 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#include "components/ui_scroll_view.h"
-#include "draw/draw_rect.h"
-
-namespace OHOS {
-UIScrollView::UIScrollView()
- : xSliderPos_({ 0, 0 }), ySliderPos_({ 0, 0 }), scrollBarWidth_(DEFAULT_BAR_WIDTH),
- xScrollMovable_(false), yScrollMovable_(false), xScrollable_(true), yScrollable_(true),
- minScrollBarLen_(DEFAULT_MIN_BAR_LEN), scrollListener_(nullptr)
-{
- direction_ = HORIZONTAL_AND_VERTICAL;
- xSlider_.SetVisible(false);
- ySlider_.SetVisible(false);
- xSlider_.SetStyle(StyleDefault::GetBrightStyle());
- ySlider_.SetStyle(StyleDefault::GetBrightStyle());
-}
-
-void UIScrollView::OnPostDraw(const Rect& invalidatedArea)
-{
- if (!xSlider_.IsVisible() && !ySlider_.IsVisible()) {
- return;
- }
- Rect scrollRect = GetRect();
- if (xSlider_.IsVisible()) {
- xSlider_.SetPosition(scrollRect.GetX() + xSliderPos_.x, scrollRect.GetY() + xSliderPos_.y);
- xSlider_.OnDraw(invalidatedArea);
- }
- if (ySlider_.IsVisible()) {
- ySlider_.SetPosition(scrollRect.GetX() + ySliderPos_.x, scrollRect.GetY() + ySliderPos_.y);
- ySlider_.OnDraw(invalidatedArea);
- }
-}
-
-bool UIScrollView::OnDragEvent(const DragEvent& event)
-{
- if (animator_.GetState() != Animator::STOP) {
- UIAbstractScroll::StopAnimator();
- }
- Drag(event);
- return UIView::OnDragEvent(event);
-}
-
-bool UIScrollView::OnDragEndEvent(const DragEvent& event)
-{
- Point last = event.GetPreLastPoint();
- Point current = event.GetLastPoint();
- if (last.x == current.x && last.y == current.y) {
- last = current;
- current = event.GetCurrentPos();
- }
-
- if (!DragReboundAnimator()) {
- if (!DragThrowAnimator(current, last)) {
- if (scrollListener_ && scrollListener_->GetScrollState() == OnScrollListener::SCROLL_STATE_MOVE) {
- scrollListener_->OnScrollEnd();
- scrollListener_->SetScrollState(OnScrollListener::SCROLL_STATE_STOP);
- }
- }
- }
- return UIView::OnDragEndEvent(event);
-}
-
-void UIScrollView::Drag(const DragEvent& event)
-{
- int16_t xDistance = event.GetDeltaX();
- int16_t yDistance = event.GetDeltaY();
-
- if (xScrollMovable_ && xDistance != 0) {
- DragXInner(xDistance);
- }
- if (yScrollMovable_ && yDistance != 0) {
- DragYInner(yDistance);
- }
-}
-
-void UIScrollView::OnPressEvent(const PressEvent& event)
-{
- StopAnimator();
- UIView::OnPressEvent(event);
-}
-
-void UIScrollView::ScrollBy(int16_t xDistance, int16_t yDistance)
-{
- if (xScrollMovable_ && xDistance != 0) {
- DragXInner(xDistance);
- }
- if (yScrollMovable_ && yDistance != 0) {
- DragYInner(yDistance);
- }
- if ((scrollListener_ != nullptr) && (scrollListener_->GetScrollState() == OnScrollListener::SCROLL_STATE_MOVE)) {
- scrollListener_->OnScrollEnd();
- scrollListener_->SetScrollState(OnScrollListener::SCROLL_STATE_STOP);
- }
-}
-
-bool UIScrollView::DragXInner(int16_t distance)
-{
- if (!xScrollMovable_) {
- return false;
- }
- Rect childRect = GetAllChildRelativeRect();
- int16_t reboundSize = reboundSize_;
- if (animator_.GetState() != Animator::STOP) {
- reboundSize = 0;
- }
-
- if (distance > 0) {
- if (childRect.GetLeft() > scrollBlankSize_ + reboundSize) {
- distance = 0;
- } else if ((childRect.GetLeft() + distance) > scrollBlankSize_ + reboundSize) {
- distance = scrollBlankSize_ - childRect.GetLeft() + reboundSize;
- }
- } else {
- int16_t childRight = childRect.GetRight();
- int16_t scrollWidth = GetWidth();
- if (yScrollable_ && ySlider_.IsVisible()) {
- if (childRight < scrollWidth - ySlider_.GetWidth() - (scrollBlankSize_ + reboundSize)) {
- distance = 0;
- } else if (childRight + distance < scrollWidth - ySlider_.GetWidth() -
- (scrollBlankSize_ + reboundSize)) {
- distance = scrollWidth - ySlider_.GetWidth() - (scrollBlankSize_ + reboundSize) - childRight;
- }
- } else {
- if (childRight < scrollWidth - (scrollBlankSize_ + reboundSize)) {
- distance = 0;
- } else if (childRight + distance < scrollWidth - (scrollBlankSize_ + reboundSize)) {
- distance = scrollWidth - (scrollBlankSize_ + reboundSize) - childRight - 1;
- }
- }
- }
-
- return MoveOffset(distance, 0);
-}
-
-bool UIScrollView::DragYInner(int16_t distance)
-{
- if (!yScrollMovable_) {
- return false;
- }
- Rect childRect = GetAllChildRelativeRect();
- int16_t reboundSize = reboundSize_;
- if (animator_.GetState() != Animator::STOP) {
- reboundSize = 0;
- }
-
- if (distance > 0) {
- if (childRect.GetTop() > scrollBlankSize_ + reboundSize) {
- distance = 0;
- } else if ((childRect.GetTop() + distance) > scrollBlankSize_ + reboundSize) {
- distance = scrollBlankSize_ - childRect.GetTop() + reboundSize;
- }
- } else {
- int16_t childBottom = childRect.GetBottom();
- int16_t scrollHeight = GetHeight();
- if (xScrollable_ && xSlider_.IsVisible()) {
- if (childBottom < scrollHeight - xSlider_.GetHeight() - (scrollBlankSize_ + reboundSize)) {
- distance = 0;
- } else if (childBottom + distance < scrollHeight - xSlider_.GetHeight() -
- (scrollBlankSize_ + reboundSize)) {
- distance = scrollHeight - xSlider_.GetHeight() - (scrollBlankSize_ + reboundSize) - childBottom;
- }
- } else {
- if (childBottom < scrollHeight - (scrollBlankSize_ + reboundSize)) {
- distance = 0;
- } else if (childBottom + distance < scrollHeight - (scrollBlankSize_ + reboundSize)) {
- distance = scrollHeight - (scrollBlankSize_ + reboundSize) - childBottom - 1;
- }
- }
- }
-
- return MoveOffset(0, distance);
-}
-
-bool UIScrollView::MoveOffset(int16_t offsetX, int16_t offsetY)
-{
- if (offsetX != 0 || offsetY != 0) {
- if ((scrollListener_ != nullptr) &&
- (scrollListener_->GetScrollState() == OnScrollListener::SCROLL_STATE_STOP)) {
- scrollListener_->OnScrollStart();
- scrollListener_->SetScrollState(OnScrollListener::SCROLL_STATE_MOVE);
- }
- UIAbstractScroll::MoveChildByOffset(offsetX, offsetY);
- Invalidate();
- RefreshScrollBarPosition();
- return true;
- }
- return false;
-}
-
-void UIScrollView::RefreshScrollBar()
-{
- Rect childRect = GetAllChildRelativeRect();
- if (xScrollable_ && (childRect.GetWidth() <= GetWidth())) {
- xSliderPos_.y = GetHeight() - scrollBarWidth_;
- xSlider_.SetHeight(scrollBarWidth_);
- // y scroll bar is on, x scroll bar width should be group width - scroll bar width
- if (yScrollable_) {
- xSlider_.SetWidth(GetWidth() - scrollBarWidth_);
- } else {
- xSlider_.SetWidth(GetWidth());
- }
- }
-
- if (yScrollable_ && (childRect.GetHeight() <= GetHeight())) {
- ySliderPos_.x = GetWidth() - scrollBarWidth_;
- ySliderPos_.y = 0;
- ySlider_.SetWidth(scrollBarWidth_);
- // x scroll bar is on, y scroll bar height should be group height - scroll bar width
- if (xScrollable_) {
- ySlider_.SetHeight(GetHeight() - scrollBarWidth_);
- } else {
- ySlider_.SetHeight(GetHeight());
- }
- }
- xScrollMovable_ = false;
- yScrollMovable_ = false;
- float multiple;
-
- // child width is larger than group width, resize the x scroll bar width
- if (xScrollable_ && (childRect.GetWidth() > GetWidth()) && (childRect.GetWidth() != 0)) {
- int16_t groupWidth = GetWidth();
- int16_t xWidth;
- if (yScrollable_) {
- multiple = static_cast(groupWidth - scrollBarWidth_) / childRect.GetWidth();
- xWidth = static_cast((groupWidth - scrollBarWidth_) * multiple);
- } else {
- multiple = static_cast(groupWidth) / childRect.GetWidth();
- xWidth = static_cast(groupWidth * multiple);
- }
- if (xWidth < minScrollBarLen_) {
- xWidth = minScrollBarLen_;
- }
-
- xSliderPos_.x = GetXScrollOffset(childRect);
- xSliderPos_.y = GetHeight() - scrollBarWidth_;
- xSlider_.SetWidth(xWidth);
- xSlider_.SetHeight(scrollBarWidth_);
- xScrollMovable_ = true;
- }
-
- // child height is larger than group height, resize the y scroll height
- if (yScrollable_ && (childRect.GetHeight() > GetHeight()) && (childRect.GetHeight() != 0)) {
- int16_t groupHeight = GetHeight();
- int16_t yHeight;
- if (xScrollable_) {
- multiple = static_cast(groupHeight - scrollBarWidth_) / childRect.GetHeight();
- yHeight = static_cast((groupHeight - scrollBarWidth_) * multiple);
- } else {
- multiple = static_cast(groupHeight) / childRect.GetHeight();
- yHeight = static_cast(groupHeight * multiple);
- }
-
- // scroll bar may be too small, keep it min size
- if (yHeight < minScrollBarLen_) {
- yHeight = minScrollBarLen_;
- }
-
- ySliderPos_.x = GetWidth() - scrollBarWidth_;
- ySliderPos_.y = GetYScrollOffset(childRect);
- ySlider_.SetHeight(yHeight);
- ySlider_.SetWidth(scrollBarWidth_);
- yScrollMovable_ = true;
- }
-}
-
-void UIScrollView::RefreshScrollBarPosition()
-{
- if (!xSlider_.IsVisible() && !ySlider_.IsVisible()) {
- return;
- }
- Rect childRect = GetAllChildRelativeRect();
- if (childRect.GetWidth() == 0 || childRect.GetHeight() == 0) {
- return;
- }
- if (xScrollMovable_ && xScrollable_) {
- int16_t xOffset = GetXScrollOffset(childRect);
- xSliderPos_.x = xOffset;
- Invalidate();
- }
- if (yScrollMovable_ && yScrollable_) {
- int16_t yOffset = GetYScrollOffset(childRect);
- ySliderPos_.y = yOffset;
- Invalidate();
- }
-}
-
-int16_t UIScrollView::GetXScrollOffset(const Rect& childRect)
-{
- Rect scrollRect = GetRelativeRect();
- int16_t xOffset;
- int16_t scrollBarOffset = 0;
- float multiple;
-
- // set x scroll bar position, if y scroll bar is on,
- // x scroll bar should move between group left and y scroll bar left.
- // if y scroll bar off, move between group left and right
- if (yScrollable_) {
- scrollBarOffset = scrollBarWidth_;
- }
-
- int16_t childRectLeft = childRect.GetLeft();
- int16_t childRectWidth = childRect.GetWidth();
- int16_t scrollRectWidth = scrollRect.GetWidth();
- int16_t xSliderWidth = xSlider_.GetWidth();
- if ((childRectLeft >= 0) || (childRectWidth - scrollRectWidth + scrollBarOffset == 0)) {
- xOffset = 0;
- } else {
- multiple = static_cast(scrollRectWidth - scrollBarOffset - xSliderWidth) /
- (childRectWidth - scrollRectWidth + scrollBarOffset);
- xOffset = static_cast(-childRectLeft * multiple);
- }
- return xOffset;
-}
-
-int16_t UIScrollView::GetYScrollOffset(const Rect& childRect)
-{
- Rect scrollRect = GetRelativeRect();
- int16_t yOffset;
- int16_t scrollBarOffset = 0;
- float multiple;
-
- // set x scroll bar position, if y scroll bar is on,
- // x scroll bar should move between group left and y scroll bar left.
- // if y scroll bar off, move between group left and right
- if (xScrollable_) {
- scrollBarOffset = scrollBarWidth_;
- }
-
- int16_t childRectTop = childRect.GetTop();
- int16_t childRectHeight = childRect.GetHeight();
- int16_t scrollRectHeight = scrollRect.GetHeight();
- int16_t ySliderHeight = ySlider_.GetHeight();
- if ((childRectTop >= 0) || (childRectHeight - scrollRectHeight + scrollBarOffset == 0)) {
- yOffset = 0;
- } else {
- multiple = static_cast(scrollRectHeight - scrollBarOffset - ySliderHeight) /
- (childRectHeight - scrollRectHeight + scrollBarOffset);
- yOffset = static_cast(-childRectTop * multiple);
- }
- return yOffset;
-}
-
-void UIScrollView::OnChildChanged()
-{
- RefreshScrollBar();
-}
-
-bool UIScrollView::DragReboundAnimator()
-{
- if (reboundSize_ == 0) {
- return false;
- }
- Rect rect = GetAllChildRelativeRect();
- int16_t top = rect.GetTop();
- int16_t bottom = rect.GetBottom();
- int16_t scrollHeight = GetHeight();
- int16_t dragDistanceY = 0;
- int16_t dragDistanceX = 0;
-
- if (yScrollMovable_) {
- if (scrollBlankSize_ < top) {
- dragDistanceY = scrollBlankSize_ - top;
- } else if (bottom < scrollHeight - 1) {
- dragDistanceY = scrollHeight - scrollBlankSize_ - bottom - 1;
- }
- }
-
- int16_t left = rect.GetLeft();
- int16_t right = rect.GetRight();
- int16_t scrollWidth = GetWidth();
- if (xScrollMovable_) {
- if (scrollBlankSize_ < left) {
- dragDistanceX = scrollBlankSize_ - left;
- } else if (right < scrollWidth - 1) {
- dragDistanceX = scrollWidth - scrollBlankSize_ - right - 1;
- }
- }
-
- if (dragDistanceY || dragDistanceX) {
- int16_t dragTimes = MATH_MAX(MATH_ABS(dragDistanceX), MATH_ABS(dragDistanceY)) / DRAG_TIMES_COEFFICIENT;
- if (dragTimes < MIN_DRAG_TIMES) {
- dragTimes = MIN_DRAG_TIMES;
- }
- animatorCallback_.SetDragStartValue(0, 0);
- animatorCallback_.SetDragEndValue(dragDistanceX, dragDistanceY);
- animatorCallback_.SetDragTimes(dragTimes * DRAG_ACC_FACTOR / GetDragACCLevel());
- animator_.Start();
- return true;
- }
- return false;
-}
-
-void UIScrollView::StopAnimator()
-{
- if (scrollListener_ != nullptr && scrollListener_->GetScrollState() == OnScrollListener::SCROLL_STATE_MOVE) {
- scrollListener_->OnScrollEnd();
- scrollListener_->SetScrollState(OnScrollListener::SCROLL_STATE_STOP);
- }
- UIAbstractScroll::StopAnimator();
-}
-} // namespace OHOS
\ No newline at end of file
diff --git a/frameworks/ui/src/components/ui_slider.cpp b/frameworks/ui/src/components/ui_slider.cpp
deleted file mode 100755
index ff73d5c..0000000
--- a/frameworks/ui/src/components/ui_slider.cpp
+++ /dev/null
@@ -1,271 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#include "common/image.h"
-#include "components/ui_slider.h"
-#include "draw/draw_image.h"
-#include "draw/draw_rect.h"
-#include "graphic_log.h"
-#include "imgdecode/cache_manager.h"
-#include "themes/theme_manager.h"
-
-namespace OHOS {
-UISlider::UISlider()
- : knobWidth_(0), knobWidthSetFlag_(false), knobStyleAllocFlag_(false), knobImage_(nullptr), listener_(nullptr)
-{
- SetTouchable(true);
- SetDraggable(true);
- Theme* theme = ThemeManager::GetInstance().GetCurrent();
- if (theme != nullptr) {
- knobStyle_ = &(theme->GetSliderKnobStyle());
- } else {
- knobStyle_ = &(StyleDefault::GetSliderKnobStyle());
- }
-}
-
-UISlider::~UISlider()
-{
- if (knobImage_ != nullptr) {
- delete knobImage_;
- knobImage_ = nullptr;
- }
-
- if (knobStyleAllocFlag_) {
- delete knobStyle_;
- knobStyle_ = nullptr;
- knobStyleAllocFlag_ = false;
- }
-}
-
-void UISlider::SetKnobStyle(const Style& style)
-{
- if (!knobStyleAllocFlag_) {
- knobStyle_ = new Style;
- knobStyleAllocFlag_ = true;
- }
- *knobStyle_ = style;
-}
-
-void UISlider::SetKnobStyle(uint8_t key, int64_t value)
-{
- if (!knobStyleAllocFlag_) {
- knobStyle_ = new Style(*knobStyle_);
- knobStyleAllocFlag_ = true;
- }
- knobStyle_->SetStyle(key, value);
-}
-
-const Style& UISlider::GetKnobStyle() const
-{
- return *knobStyle_;
-}
-
-int64_t UISlider::GetKnobStyle(uint8_t key) const
-{
- return knobStyle_->GetStyle(key);
-}
-
-int16_t UISlider::CalculateCurrentValue(int16_t length, int16_t totalLength)
-{
- if (totalLength != 0) {
- return static_cast(rangeMin_ + (static_cast(rangeMax_) - rangeMin_) * length / totalLength);
- }
- return 0;
-}
-
-int16_t UISlider::UpdateCurrentValue(const Point& knobPosition)
-{
- Point startPoint;
- Rect rect = GetContentRect();
- startPoint.x = rect.GetLeft() + ((GetWidth() - progressWidth_) >> 1);
- startPoint.y = rect.GetTop() + ((GetHeight() - progressHeight_) >> 1);
-
- int16_t value = curValue_;
- switch (direction_) {
- case Direction::DIR_LEFT_TO_RIGHT:
- if (knobPosition.x <= startPoint.x) {
- value = rangeMin_;
- } else if (knobPosition.x >= startPoint.x + progressWidth_) {
- value = rangeMax_;
- } else {
- value = CalculateCurrentValue(knobPosition.x - startPoint.x, progressWidth_);
- }
- break;
- case Direction::DIR_RIGHT_TO_LEFT:
- if (knobPosition.x <= startPoint.x) {
- value = rangeMax_;
- } else if (knobPosition.x >= startPoint.x + progressWidth_) {
- value = rangeMin_;
- } else {
- value = CalculateCurrentValue(startPoint.x + progressWidth_ - knobPosition.x, progressWidth_);
- }
- break;
- case Direction::DIR_BOTTOM_TO_TOP:
- if (knobPosition.y <= startPoint.y) {
- value = rangeMax_;
- } else if (knobPosition.y >= startPoint.y + progressHeight_) {
- value = rangeMin_;
- } else {
- value = CalculateCurrentValue(startPoint.y + progressHeight_ - knobPosition.y, progressHeight_);
- }
- break;
- case Direction::DIR_TOP_TO_BOTTOM:
- if (knobPosition.y <= startPoint.y) {
- value = rangeMin_;
- } else if (knobPosition.y >= startPoint.y + progressHeight_) {
- value = rangeMax_;
- } else {
- value = CalculateCurrentValue(knobPosition.y - startPoint.y, progressHeight_);
- }
- break;
- default:
- GRAPHIC_LOGW("UISlider::UpdateProgressValue Direction error!\n");
- }
- SetValue(value);
- return value;
-}
-
-void UISlider::OnClickEvent(const ClickEvent& event)
-{
- Point knobPosition = event.GetCurrentPos();
- int16_t value = UpdateCurrentValue(knobPosition);
- if (listener_ != nullptr) {
- listener_->OnChange(value);
- }
- UIView::OnClickEvent(event);
- Invalidate();
-}
-
-bool UISlider::OnDragEvent(const DragEvent& event)
-{
- Point knobPosition = event.GetCurrentPos();
- int16_t value = UpdateCurrentValue(knobPosition);
- if (listener_ != nullptr) {
- listener_->OnChange(value);
- }
- Invalidate();
- return UIView::OnDragEvent(event);
-}
-
-bool UISlider::OnDragEndEvent(const DragEvent& event)
-{
- Point knobPosition = event.GetCurrentPos();
- int16_t value = UpdateCurrentValue(knobPosition);
- if (listener_ != nullptr) {
- listener_->OnChange(value);
- listener_->OnRelease(value);
- }
- Invalidate();
- return UIView::OnDragEndEvent(event);
-}
-
-int16_t UISlider::GetKnobWidth()
-{
- if (!knobWidthSetFlag_) {
- if (direction_ == Direction::DIR_LEFT_TO_RIGHT || direction_ == Direction::DIR_RIGHT_TO_LEFT) {
- knobWidth_ = progressHeight_;
- } else {
- knobWidth_ = progressWidth_;
- }
- }
- return knobWidth_;
-}
-
-void UISlider::SetImage(const ImageInfo* backgroundImage, const ImageInfo* foregroundImage, const ImageInfo* knobImage)
-{
- if (backgroundImage_ == nullptr) {
- backgroundImage_ = new Image();
- }
- backgroundImage_->SetSrc(backgroundImage);
-
- if (foregroundImage_ == nullptr) {
- foregroundImage_ = new Image();
- }
- foregroundImage_->SetSrc(foregroundImage);
-
- if (knobImage_ == nullptr) {
- knobImage_ = new Image();
- }
- knobImage_->SetSrc(knobImage);
-}
-
-void UISlider::SetImage(const char* backgroundImage, const char* foregroundImage, const char* knobImage)
-{
- if (backgroundImage_ == nullptr) {
- backgroundImage_ = new Image();
- }
- backgroundImage_->SetSrc(backgroundImage);
-
- if (foregroundImage_ == nullptr) {
- foregroundImage_ = new Image();
- }
- foregroundImage_->SetSrc(foregroundImage);
-
- if (knobImage_ == nullptr) {
- knobImage_ = new Image();
- }
- knobImage_->SetSrc(knobImage);
-}
-
-void UISlider::DrawKnob(const Rect& invalidatedArea, const Rect& foregroundRect)
-{
- int16_t halfKnobWidth = GetKnobWidth() >> 1;
- int16_t offset;
- Rect knobBar;
- switch (direction_) {
- case Direction::DIR_LEFT_TO_RIGHT: {
- offset = (knobWidth_ - progressHeight_) >> 1;
- knobBar.SetRect(foregroundRect.GetRight() - halfKnobWidth, foregroundRect.GetTop() - offset,
- foregroundRect.GetRight() + halfKnobWidth, foregroundRect.GetBottom() + offset);
- break;
- }
- case Direction::DIR_RIGHT_TO_LEFT: {
- offset = (knobWidth_ - progressHeight_) >> 1;
- knobBar.SetRect(foregroundRect.GetLeft() - halfKnobWidth, foregroundRect.GetTop() - offset,
- foregroundRect.GetLeft() + halfKnobWidth, foregroundRect.GetBottom() + offset);
- break;
- }
- case Direction::DIR_BOTTOM_TO_TOP: {
- offset = (knobWidth_ - progressWidth_) >> 1;
- knobBar.SetRect(foregroundRect.GetLeft() - offset, foregroundRect.GetTop() - halfKnobWidth,
- foregroundRect.GetRight() + offset, foregroundRect.GetTop() + halfKnobWidth);
- break;
- }
- case Direction::DIR_TOP_TO_BOTTOM: {
- offset = (knobWidth_ - progressWidth_) >> 1;
- knobBar.SetRect(foregroundRect.GetLeft() - offset, foregroundRect.GetBottom() - halfKnobWidth,
- foregroundRect.GetRight() + offset, foregroundRect.GetBottom() + halfKnobWidth);
- break;
- }
- default: {
- GRAPHIC_LOGW("UISlider::DrawKnob Direction error!\n");
- }
- }
- DrawValidRect(knobImage_, knobBar, invalidatedArea, *knobStyle_, 0);
-}
-
-void UISlider::OnDraw(const Rect& invalidatedArea)
-{
- DrawRect::Draw(GetRect(), invalidatedArea, *style_);
-
- Rect trunc(invalidatedArea);
- if (trunc.Intersect(trunc, GetContentRect())) {
- DrawBackground(trunc);
- Rect foregroundRect;
- DrawForeground(trunc, foregroundRect);
- DrawKnob(trunc, foregroundRect);
- }
-}
-} // namespace OHOS
\ No newline at end of file
diff --git a/frameworks/ui/src/components/ui_surface_view.cpp b/frameworks/ui/src/components/ui_surface_view.cpp
deleted file mode 100755
index 2814911..0000000
--- a/frameworks/ui/src/components/ui_surface_view.cpp
+++ /dev/null
@@ -1,161 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#include "components/ui_surface_view.h"
-#include
-#include "draw/draw_rect.h"
-#include "draw/draw_utils.h"
-#include "graphic_log.h"
-#include "surface_buffer.h"
-
-namespace OHOS {
-UISurfaceView::UISurfaceView()
-{
- surface_ = Surface::CreateSurface();
- if (surface_ == nullptr) {
- GRAPHIC_LOGE("UISurfaceView::UISurfaceView surface create failed\n");
- return;
- }
- surface_->SetWidthAndHeight(GetWidth(), GetHeight());
- surface_->SetQueueSize(DEFAULT_QUEUE_SIZE);
- surface_->SetFormat(IMAGE_PIXEL_FORMAT_ARGB8888);
-}
-
-UISurfaceView::~UISurfaceView()
-{
- if (surface_ != nullptr) {
- delete surface_;
- surface_ = nullptr;
- }
-}
-
-void UISurfaceView::SetPosition(int16_t x, int16_t y)
-{
- UIView::SetPosition(x, y);
- if (surface_ == nullptr) {
- GRAPHIC_LOGE("UISurfaceView::SetPosition surface is null\n");
- return;
- }
- x = GetRect().GetLeft();
- y = GetRect().GetTop();
- surface_->SetUserData(REGION_POSITION_X, std::to_string(x));
- surface_->SetUserData(REGION_POSITION_Y, std::to_string(y));
-}
-
-void UISurfaceView::SetPosition(int16_t x, int16_t y, int16_t width, int16_t height)
-{
- UIView::SetPosition(x, y, width, height);
- if (surface_ == nullptr) {
- GRAPHIC_LOGE("UISurfaceView::SetPosition surface is null\n");
- return;
- }
- x = GetRect().GetLeft();
- y = GetRect().GetTop();
- surface_->SetUserData(REGION_POSITION_X, std::to_string(x));
- surface_->SetUserData(REGION_POSITION_Y, std::to_string(y));
- surface_->SetUserData(REGION_WIDTH, std::to_string(width));
- surface_->SetUserData(REGION_HEIGHT, std::to_string(height));
-}
-
-void UISurfaceView::Resize(int16_t width, int16_t height)
-{
- UIView::Resize(width, height);
- if (surface_ == nullptr) {
- GRAPHIC_LOGE("UISurfaceView::Resize surface is null\n");
- return;
- }
- surface_->SetUserData(REGION_WIDTH, std::to_string(width));
- surface_->SetUserData(REGION_HEIGHT, std::to_string(height));
-}
-
-void UISurfaceView::SetWidth(int16_t width)
-{
- UIView::SetWidth(width);
- if (surface_ == nullptr) {
- GRAPHIC_LOGE("UISurfaceView::SetWidth surface is null\n");
- return;
- }
- surface_->SetUserData(REGION_WIDTH, std::to_string(width));
-}
-
-void UISurfaceView::SetHeight(int16_t height)
-{
- UIView::SetHeight(height);
- if (surface_ == nullptr) {
- GRAPHIC_LOGE("UISurfaceView::SetHeight surface is null\n");
- return;
- }
- surface_->SetUserData(REGION_HEIGHT, std::to_string(height));
-}
-
-
-void UISurfaceView::SetX(int16_t x)
-{
- UIView::SetX(x);
- if (surface_ == nullptr) {
- GRAPHIC_LOGE("UISurfaceView::SetX surface is null\n");
- return;
- }
- x = GetRect().GetLeft();
- surface_->SetUserData(REGION_POSITION_X, std::to_string(x));
-}
-
-void UISurfaceView::SetY(int16_t y)
-{
- UIView::SetY(y);
- if (surface_ == nullptr) {
- GRAPHIC_LOGE("UISurfaceView::SetY surface is null\n");
- return;
- }
- y = GetRect().GetTop();
- surface_->SetUserData(REGION_POSITION_Y, std::to_string(y));
-}
-
-void UISurfaceView::SetVisible(bool visible)
-{
- GRAPHIC_LOGI("UISurfaceView::SetVisible can not set visible\n");
-}
-
-Surface* UISurfaceView::GetSurface() const
-{
- return surface_;
-}
-
-bool UISurfaceView::OnPreDraw(const Rect& invalidatedArea)
-{
- // need fill transpant color
- return true;
-}
-
-void UISurfaceView::OnDraw(const Rect& invalidatedArea)
-{
- Draw(invalidatedArea);
-}
-
-void UISurfaceView::Draw(const Rect& invalidatedArea)
-{
- SurfaceBuffer* acquireBuffer = (surface_ != nullptr) ? surface_->AcquireBuffer() : nullptr;
- if (acquireBuffer != nullptr) {
- GRAPHIC_LOGE("UISurfaceView::Draw acquireBufferVirAddr=%p \n", acquireBuffer->GetVirAddr());
- // fill with buffer
- DrawUtils::GetInstance()->DrawWithBuffer(GetRect(), invalidatedArea,
- reinterpret_cast(acquireBuffer->GetVirAddr()));
- surface_->ReleaseBuffer(acquireBuffer);
- } else {
- // fill with transpant color
- DrawUtils::GetInstance()->DrawTranspantArea(GetRect(), invalidatedArea);
- }
-}
-} // namespace OHOS
diff --git a/frameworks/ui/src/components/ui_swipe_view.cpp b/frameworks/ui/src/components/ui_swipe_view.cpp
deleted file mode 100755
index fae9041..0000000
--- a/frameworks/ui/src/components/ui_swipe_view.cpp
+++ /dev/null
@@ -1,428 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#include "components/ui_swipe_view.h"
-
-namespace OHOS {
-UISwipeView::UISwipeView(uint8_t direction)
- : swipeListener_(nullptr),
- curIndex_(0),
- blankSize_(DEFAULT_BLANK_SIZE),
- curView_(nullptr),
- direction_(direction),
- loop_(false)
-{
- AnimatorManager::GetInstance()->Add(&animator_);
- tickTime_ = ANIMATOR_TIME;
- swipeAccCoefficient_ = DRAG_ACC_FACTOR;
-}
-
-UISwipeView::~UISwipeView()
-{
- AnimatorManager::GetInstance()->Remove(&animator_);
-}
-
-void UISwipeView::Add(UIView* view)
-{
- if (view == nullptr) {
- return;
- }
- view->SetDragParentInstead(true);
- UIViewGroup::Add(view);
- SortChild();
- Invalidate();
-}
-
-void UISwipeView::Insert(UIView* prevView, UIView* insertView)
-{
- if (insertView == nullptr) {
- return;
- }
- insertView->SetDragParentInstead(true);
- UIViewGroup::Insert(prevView, insertView);
- SortChild();
- Invalidate();
-}
-
-void UISwipeView::Remove(UIView* view)
-{
- if (view == nullptr) {
- return;
- }
- UIViewGroup::Remove(view);
- SortChild();
- Invalidate();
-}
-
-void UISwipeView::SetCurrentPage(uint16_t index, bool needAnimator)
-{
- SwitchToPage(index, needAnimator);
- Invalidate();
-}
-
-bool UISwipeView::DragXInner(int16_t distance)
-{
- if (distance == 0) {
- return true;
- }
- if (!loop_) {
- if ((distance > 0) && (childrenHead_ != nullptr)) {
- if (childrenHead_->GetX() >= blankSize_) {
- distance = 0;
- } else if (childrenHead_ && childrenHead_->GetX() + distance > blankSize_) {
- distance = blankSize_ - childrenHead_->GetX();
- }
- } else if (childrenTail_ != nullptr) {
- uint16_t width = GetWidth();
- if (childrenTail_->GetRelativeRect().GetRight() <= width - blankSize_) {
- distance = 0;
- } else if (width - (childrenTail_->GetX() + childrenTail_->GetWidth() + distance) > blankSize_) {
- distance = width - blankSize_ - childrenTail_->GetX() - childrenTail_->GetWidth();
- }
- }
- }
- CalculateInvalidate();
- MoveChildByOffset(distance, 0);
- CalculateInvalidate();
- return true;
-}
-
-bool UISwipeView::DragYInner(int16_t distance)
-{
- if (distance == 0) {
- return true;
- }
- if (!loop_) {
- if ((distance > 0) && (childrenHead_ != nullptr)) {
- if (childrenHead_->GetY() >= blankSize_) {
- distance = 0;
- } else if ((childrenHead_ != nullptr) && (childrenHead_->GetY() + distance > blankSize_)) {
- distance = blankSize_ - childrenHead_->GetY();
- }
- } else if (childrenTail_ != nullptr) {
- uint16_t height = GetHeight();
- if (childrenTail_->GetRelativeRect().GetBottom() <= height - blankSize_) {
- distance = 0;
- } else if (height - (childrenTail_->GetY() + childrenTail_->GetHeight() + distance) > blankSize_) {
- distance = height - blankSize_ - childrenTail_->GetY() - childrenTail_->GetHeight();
- }
- }
- }
- CalculateInvalidate();
- MoveChildByOffset(0, distance);
- CalculateInvalidate();
- return true;
-}
-
-bool UISwipeView::OnDragEvent(const DragEvent& event)
-{
- UIView* curView = GetViewByIndex(curIndex_);
- if (curView == nullptr) {
- return UIView::OnDragEvent(event);
- }
- if (animator_.GetState() != Animator::STOP) {
- UIAbstractScroll::StopAnimator();
- }
-
- if (direction_ == HORIZONTAL) {
- DragXInner(event.GetDeltaX());
- RefreshDeltaY(event.GetDeltaX());
- } else {
- DragYInner(event.GetDeltaY());
- RefreshDeltaY(event.GetDeltaY());
- }
- return UIView::OnDragEvent(event);
-}
-
-bool UISwipeView::OnDragEndEvent(const DragEvent& event)
-{
- int16_t distance = 0;
- if (direction_ == HORIZONTAL) {
- distance = event.GetCurrentPos().x - event.GetPreLastPoint().x;
- } else {
- distance = event.GetCurrentPos().y - event.GetPreLastPoint().y;
- }
- RefreshCurrentView(distance);
-
- if (curView_ == nullptr) {
- return UIView::OnDragEndEvent(event);
- }
-
- SwitchToPage(curIndex_);
-
- Invalidate();
- return UIView::OnDragEndEvent(event);
-}
-
-UIView* UISwipeView::GetViewByIndex(uint16_t index) const
-{
- UIView* child = childrenHead_;
- while (child != nullptr) {
- if (child->GetViewIndex() == index) {
- return child;
- }
- child = child->GetNextSibling();
- }
- return nullptr;
-}
-
-void UISwipeView::SetAnimatorTime(uint16_t time)
-{
- tickTime_ = time / DEFAULT_TASK_PERIOD;
- if (tickTime_ == 0) {
- tickTime_ = 1;
- }
- animatorCallback_.SetDragTimes(tickTime_);
-}
-
-void UISwipeView::SwitchToPage(int16_t dst, bool needAnimator)
-{
- if (isNeedLoop()) {
- dst = (dst + childrenNum_) % childrenNum_;
- } else if (dst < 0) {
- dst = 0;
- } else if (dst >= childrenNum_) {
- dst = childrenNum_ - 1;
- }
-
- UIView* dstView = GetViewByIndex(dst);
- if (dstView == nullptr) {
- return;
- }
- curIndex_ = dst;
- int16_t xOffset = 0;
- int16_t yOffset = 0;
-
- if (direction_ == HORIZONTAL) {
- xOffset = (GetWidth() >> 1) - (dstView->GetX() + (dstView->GetWidth() >> 1));
- } else {
- yOffset = (GetHeight() >> 1) - (dstView->GetY() + (dstView->GetHeight() >> 1));
- }
-
- if (xOffset != 0 || yOffset != 0) {
- if (animator_.GetState() != Animator::STOP) {
- animator_.Stop();
- }
- if (needAnimator) {
- animatorCallback_.SetDragTimes(tickTime_);
- animatorCallback_.SetDragStartValue(0, 0);
- animatorCallback_.SetDragEndValue(xOffset, yOffset);
- animator_.Start();
- } else {
- MoveChildByOffset(xOffset, yOffset);
- }
- }
-}
-
-void UISwipeView::StopAnimator()
-{
- UIAbstractScroll::StopAnimator();
- if (swipeListener_ != nullptr) {
- swipeListener_->OnSwipe(*this);
- }
-}
-
-void UISwipeView::SortChild()
-{
- if (childrenHead_ == nullptr) {
- return;
- }
- int16_t index = 0;
- UIView* pre = childrenHead_;
- UIView* next = childrenHead_->GetNextSibling();
- if (direction_ == HORIZONTAL) {
- pre->SetX(0);
- } else {
- pre->SetY(0);
- }
- pre->SetViewIndex(index);
- index++;
-
- while (next != nullptr) {
- if (direction_ == HORIZONTAL) {
- next->SetX(pre->GetX() + pre->GetWidth());
- } else {
- next->SetY(pre->GetY() + pre->GetHeight());
- }
- pre = next;
- next->SetViewIndex(index);
- next = next->GetNextSibling();
- index++;
- }
- bool tmpLoop = loop_;
- loop_ = false;
- SwitchToPage(curIndex_, false);
- loop_ = tmpLoop;
-}
-
-void UISwipeView::RefreshCurrentViewInner(int16_t distance, int16_t (UIView::*pfnGetXOrY)() const,
- int16_t(UIView::*pfnGetWidthOrHeight)())
-{
- if (childrenHead_ == nullptr) {
- curIndex_ = 0;
- curView_ = nullptr;
- return;
- }
-
- curIndex_ = 0;
- curView_ = nullptr;
-
- uint16_t swipeMid = (this->*pfnGetWidthOrHeight)() >> 1;
- UIView* view = childrenHead_;
-
- if ((childrenHead_->*pfnGetXOrY)() > swipeMid) {
- curIndex_ = childrenHead_->GetViewIndex();
- curView_ = childrenHead_;
- } else if ((childrenTail_->*pfnGetXOrY)() + (childrenHead_->*pfnGetWidthOrHeight)() < swipeMid) {
- curIndex_ = childrenTail_->GetViewIndex();
- curView_ = childrenTail_;
- } else {
- while (view != nullptr) {
- if (swipeMid >= (view->*pfnGetXOrY)() &&
- swipeMid <= (view->*pfnGetXOrY)() + (view->*pfnGetWidthOrHeight)()) {
- curIndex_ = view->GetViewIndex();
- curView_ = view;
- break;
- }
- view = view->GetNextSibling();
- }
- }
- if (curView_ == nullptr) {
- return;
- }
-
- int16_t accelerationOffset = GetMaxDeltaY() * GetSwipeACCLevel() / DRAG_ACC_FACTOR;
- if (distance < 0) {
- /*
- * 7, 10 : Check whether the current view is dragged by more than 1/5,
- * that is, the x or y coordinate plus 7/10 width or height.
- */
- if (((curView_->*pfnGetXOrY)() + ((curView_->*pfnGetWidthOrHeight)() >> 1) < swipeMid) &&
- ((curView_->*pfnGetXOrY)() + ((curView_->*pfnGetWidthOrHeight)() * 7 / 10) -
- accelerationOffset < swipeMid)) {
- curIndex_++;
- }
- } else if (distance > 0) {
- /*
- * 3, 10 : Check whether the current view is dragged by more than 1/5,
- * that is, the x or y coordinate plus 3/10 width or height.
- */
- if (((curView_->*pfnGetXOrY)() + ((curView_->*pfnGetWidthOrHeight)() >> 1) > swipeMid) &&
- ((curView_->*pfnGetXOrY)() + ((curView_->*pfnGetWidthOrHeight)() * 3 / 10) +
- accelerationOffset > swipeMid)) {
- curIndex_--;
- }
- }
-}
-
-void UISwipeView::RefreshCurrentView(int16_t distance)
-{
- if (direction_ == HORIZONTAL) {
- RefreshCurrentViewInner(distance, &UIView::GetX, &UIView::GetWidth);
- } else {
- RefreshCurrentViewInner(distance, &UIView::GetY, &UIView::GetHeight);
- }
-}
-
-void UISwipeView::MoveChildByOffset(int16_t xOffset, int16_t yOffset)
-{
- UIViewGroup::MoveChildByOffset(xOffset, yOffset);
- if (direction_ == HORIZONTAL) {
- while (isNeedLoop() && childrenHead_->GetX() > 0) {
- MoveLastChildToFirst();
- }
- while (isNeedLoop() && (childrenTail_->GetX() + childrenTail_->GetWidth()) < GetWidth()) {
- MoveFirstChildToLast();
- }
- } else {
- while (isNeedLoop() && childrenHead_->GetY() > 0) {
- MoveLastChildToFirst();
- }
- while (isNeedLoop() && (childrenTail_->GetY() + childrenTail_->GetHeight()) < GetHeight()) {
- MoveFirstChildToLast();
- }
- }
-}
-
-bool UISwipeView::isNeedLoop()
-{
- if (!loop_ || childrenHead_ == nullptr || childrenTail_ == nullptr) {
- return false;
- }
- Rect childRect = GetAllChildRelativeRect();
- if (direction_ == HORIZONTAL) {
- if (childRect.GetWidth() - childrenHead_->GetWidth() >= GetWidth() &&
- childRect.GetWidth() - childrenTail_->GetWidth() >= GetWidth()) {
- return true;
- }
- } else {
- if (childRect.GetHeight() - childrenHead_->GetHeight() >= GetHeight() &&
- childRect.GetHeight() - childrenTail_->GetHeight() >= GetHeight()) {
- return true;
- }
- }
- return false;
-}
-
-void UISwipeView::MoveFirstChildToLast()
-{
- if (childrenTail_ == nullptr || childrenHead_ == nullptr) {
- return;
- }
- if (direction_ == HORIZONTAL) {
- childrenHead_->SetX(childrenTail_->GetX() + childrenTail_->GetWidth());
- } else {
- childrenHead_->SetY(childrenTail_->GetY() + childrenTail_->GetHeight());
- }
- UIView* head = childrenHead_;
- UIViewGroup::Remove(childrenHead_);
- UIViewGroup::Add(head);
-}
-
-void UISwipeView::MoveLastChildToFirst()
-{
- if (childrenTail_ == nullptr || childrenHead_ == nullptr) {
- return;
- }
- if (direction_ == HORIZONTAL) {
- childrenTail_->SetX(childrenHead_->GetX() - childrenTail_->GetWidth());
- } else {
- childrenTail_->SetY(childrenHead_->GetY() - childrenTail_->GetHeight());
- }
- UIView* last = childrenTail_;
- UIViewGroup::Remove(childrenTail_);
- UIViewGroup::Insert(nullptr, last);
-}
-
-void UISwipeView::CalculateInvalidate()
-{
- Rect swipeRect(0, 0, GetRelativeRect().GetWidth() - 1, GetRelativeRect().GetHeight() - 1);
- UIView* view = childrenHead_;
- bool isFound = false;
- while (view != nullptr) {
- Rect rect = view->GetRelativeRect();
- if (rect.IsIntersect(swipeRect)) {
- if (view->IsVisible() && view->GetOpaScale() != OPA_TRANSPARENT) {
- view->Invalidate();
- }
- isFound = true;
- } else if (isFound) {
- return;
- }
-
- view = view->GetNextSibling();
- }
-}
-} // namespace OHOS
diff --git a/frameworks/ui/src/components/ui_texture_mapper.cpp b/frameworks/ui/src/components/ui_texture_mapper.cpp
deleted file mode 100755
index ac3b3bd..0000000
--- a/frameworks/ui/src/components/ui_texture_mapper.cpp
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#include "components/ui_texture_mapper.h"
-
-namespace OHOS {
-void UITextureMapper::TextureMapperAnimatorCallback::Callback(UIView* view)
-{
- if (view == nullptr) {
- return;
- }
- UITextureMapper* mapper = static_cast(view);
- mapper->Callback();
-}
-
-void UITextureMapper::TextureMapperAnimatorCallback::OnStop(UIView& view)
-{
- UITextureMapper& mapper = static_cast(view);
- if (mapper.listener_ != nullptr) {
- mapper.listener_->OnAnimatorStop(view);
- }
-}
-
-UITextureMapper::UITextureMapper()
- : animator_(&animatorCallback_, this, 0, false),
- listener_(nullptr),
- pivot_(0, 0),
- rotateCur_(0),
- rotateStart_(0),
- rotateEnd_(0),
- scaleCur_(SCALE_CONVERTION),
- scaleStart_(SCALE_CONVERTION),
- scaleEnd_(SCALE_CONVERTION),
- delayTime_(0),
- easingFunc_(EasingEquation::LinearEaseNone)
-{
- AnimatorManager::GetInstance()->Add(&animator_);
-}
-
-UITextureMapper::~UITextureMapper()
-{
- AnimatorManager::GetInstance()->Remove(&animator_);
-}
-
-void UITextureMapper::Start()
-{
- rotateStart_ = rotateCur_;
- scaleStart_ = scaleCur_;
- animator_.Start();
-}
-
-void UITextureMapper::Cancel()
-{
- animator_.Stop();
-}
-
-void UITextureMapper::Reset()
-{
- Invalidate();
- GetTransformMap().SetPolygon(Polygon());
- Invalidate();
-}
-
-void UITextureMapper::Callback()
-{
- uint16_t curTime = animator_.GetRunTime();
- if (curTime < delayTime_) {
- return;
- } else {
- Rect viewRect = GetOrigRect();
- TransformMap transMap(viewRect);
- uint16_t actualTime = curTime - delayTime_;
- uint16_t durationTime = animator_.GetTime();
-
- if (scaleStart_ != scaleEnd_) {
- scaleCur_ = easingFunc_(scaleStart_, scaleEnd_, actualTime, durationTime);
- }
- float scale = static_cast(scaleCur_) / SCALE_CONVERTION;
- transMap.Scale(Vector2(scale, scale), pivot_);
-
- if (rotateStart_ != rotateEnd_) {
- rotateCur_ = easingFunc_(rotateStart_, rotateEnd_, actualTime, durationTime);
- }
- transMap.Rotate(rotateCur_, pivot_);
-
- SetTransformMap(transMap);
- }
-}
-}
\ No newline at end of file
diff --git a/frameworks/ui/src/components/ui_time_picker.cpp b/frameworks/ui/src/components/ui_time_picker.cpp
deleted file mode 100755
index 895dbfd..0000000
--- a/frameworks/ui/src/components/ui_time_picker.cpp
+++ /dev/null
@@ -1,275 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#include "components/ui_time_picker.h"
-#include
-#include
-#include "draw/draw_rect.h"
-#include "securec.h"
-#include "themes/theme_manager.h"
-
-namespace OHOS {
-UITimePicker::UITimePicker()
- : selectedValue_{0},
- selectedHour_{0},
- selectedMinute_{0},
- selectedSecond_{0},
- secVisible_(false),
- setSelectedTime_(nullptr),
- pickerWidth_(0),
- itemsHeight_(0),
- xPos_(0),
- backgroundFontSize_(0),
- highlightFontSize_(0),
- backgroundFontName_(nullptr),
- highlightFontName_(nullptr),
- pickerListener_(this),
- timePickerListener_(nullptr)
-{
- Theme* theme = ThemeManager::GetInstance().GetCurrent();
- if (theme != nullptr) {
- style_ = &(theme->GetPickerBackgroundStyle());
- } else {
- style_ = &(StyleDefault::GetPickerBackgroundStyle());
- }
- backgroundFontId_ = style_->font_;
- backgroundColor_ = style_->textColor_;
- if (theme != nullptr) {
- style_ = &(theme->GetPickerHighlightStyle());
- } else {
- style_ = &(StyleDefault::GetPickerHighlightStyle());
- }
- highlightFontId_ = style_->font_;
- highlightColor_ = style_->textColor_;
-
- hourPicker_ = nullptr;
- minutePicker_ = nullptr;
- secondPicker_ = nullptr;
-}
-
-UITimePicker::~UITimePicker()
-{
- DeInitTimePicker();
- if (backgroundFontName_ != nullptr) {
- UIFree(backgroundFontName_);
- backgroundFontName_ = nullptr;
- }
-
- if (highlightFontName_ != nullptr) {
- UIFree(highlightFontName_);
- highlightFontName_ = nullptr;
- }
-}
-
-void UITimePicker::InitTimePicker()
-{
- xPos_ = 0;
- if (secVisible_) {
- pickerWidth_ = GetWidth() / SEC_VISIBLE_COUNT;
- InitPicker(hourPicker_, TIME_START, HOUR_END);
- xPos_ = pickerWidth_;
- InitPicker(minutePicker_, TIME_START, MIN_END);
- xPos_ *= (SEC_VISIBLE_COUNT - 1);
- InitPicker(secondPicker_, TIME_START, SEC_END);
- } else {
- pickerWidth_ = GetWidth() / SEC_INVISIBLE_COUNT;
- InitPicker(hourPicker_, TIME_START, HOUR_END);
- xPos_ = pickerWidth_;
- InitPicker(minutePicker_, TIME_START, MIN_END);
- }
-
- if (setSelectedTime_ == nullptr) {
- const char* curTime = secVisible_ ? "00:00:00" : "00:00";
- RefreshSelected(curTime);
- } else {
- RefreshSelected(setSelectedTime_);
- }
-}
-
-void UITimePicker::DeInitTimePicker()
-{
- DeInitPicker(secondPicker_);
- DeInitPicker(minutePicker_);
- DeInitPicker(hourPicker_);
-}
-
-void UITimePicker::RefreshTimePicker()
-{
- DeInitTimePicker();
- InitTimePicker();
-}
-
-void UITimePicker::InitPicker(UIPicker*& picker, int16_t start, int16_t end)
-{
- picker = new UIPicker();
- picker->SetPosition(xPos_, 0, pickerWidth_, GetHeight());
- picker->SetItemHeight(itemsHeight_);
- picker->SetFontId(backgroundFontId_, highlightFontId_);
- if (backgroundFontName_ == nullptr || highlightFontName_ == nullptr) {
- picker->SetFontId(backgroundFontId_, highlightFontId_);
- } else {
- picker->SetBackgroundFont(backgroundFontName_, backgroundFontSize_);
- picker->SetHighlightFont(highlightFontName_, highlightFontSize_);
- }
- picker->SetTextColor(backgroundColor_, highlightColor_);
- picker->SetValues(start, end);
- picker->RegisterSelectedListener(&pickerListener_);
- picker->SetIntercept(false);
- Add(picker);
-}
-
-void UITimePicker::DeInitPicker(UIPicker*& picker)
-{
- if (picker != nullptr) {
- Remove(picker);
- picker->ClearValues();
- }
-
- if (picker != nullptr) {
- delete picker;
- picker = nullptr;
- }
-}
-
-void UITimePicker::TimeSelectedCallback()
-{
- uint16_t hourSelect = hourPicker_->GetSelected();
- uint16_t minSelect = minutePicker_->GetSelected();
- GetValueByIndex(selectedHour_, BUF_SIZE, hourSelect, TIME_START, HOUR_END);
- GetValueByIndex(selectedMinute_, BUF_SIZE, minSelect, TIME_START, MIN_END);
-
- if (secVisible_) {
- uint16_t secSelect = secondPicker_->GetSelected();
- GetValueByIndex(selectedSecond_, BUF_SIZE, secSelect, TIME_START, SEC_END);
- if (sprintf_s(selectedValue_, SELECTED_VALUE_SIZE, "%s:%s:%s",
- selectedHour_, selectedMinute_, selectedSecond_) < 0) {
- return;
- }
- } else {
- if (sprintf_s(selectedValue_, SELECTED_VALUE_SIZE, "%s:%s", selectedHour_, selectedMinute_) < 0) {
- return;
- }
- }
-
- if (timePickerListener_ != nullptr) {
- timePickerListener_->OnTimePickerStoped(*this);
- }
-}
-
-void UITimePicker::GetValueByIndex(char* value, uint8_t len, uint16_t index, int16_t start, int16_t end)
-{
- if ((value != nullptr) && (index < end - start + 1)) {
- if (sprintf_s(value, len, "%02d", index) < 0) {
- return;
- }
- }
-}
-
-bool UITimePicker::SetSelected(const char* value)
-{
- setSelectedTime_ = value;
- return RefreshSelected(value);
-}
-
-bool UITimePicker::RefreshSelected(const char* value)
-{
- uint32_t hourSelect;
- uint32_t minSelect;
-
- if (value == nullptr) {
- return false;
- }
-
- if (secVisible_) {
- uint32_t secSelect;
- // 3: three variables
- if (sscanf_s(value, "%d:%d:%d", &hourSelect, &minSelect, &secSelect) < 3) {
- return false;
- }
- secondPicker_->SetSelected(secSelect);
- } else {
- if (sscanf_s(value, "%d:%d", &hourSelect, &minSelect) < 2) { // 2: two variables
- return false;
- }
- }
-
- hourPicker_->SetSelected(hourSelect);
- minutePicker_->SetSelected(minSelect);
- return true;
-}
-
-void UITimePicker::SetItemHeight(int16_t height)
-{
- itemsHeight_ = height;
- RefreshTimePicker();
-}
-
-void UITimePicker::EnableSecond(bool state)
-{
- secVisible_ = state;
- RefreshTimePicker();
-}
-
-void UITimePicker::SetTextStyle(uint8_t backgroundFontId, uint8_t highlightFontId,
- ColorType backgroundColor, ColorType highlightColor)
-{
- highlightFontId_ = highlightFontId;
- if (highlightFontName_ != nullptr) {
- UIFree(highlightFontName_);
- highlightFontName_ = nullptr;
- }
-
- backgroundFontId_ = backgroundFontId;
- if (backgroundFontName_ != nullptr) {
- UIFree(backgroundFontName_);
- backgroundFontName_ = nullptr;
- }
-
- highlightColor_ = highlightColor;
- backgroundColor_ = backgroundColor;
- RefreshTimePicker();
-}
-
-void UITimePicker::SetTextColor(ColorType backgroundColor, ColorType highlightColor)
-{
- backgroundColor_ = backgroundColor;
- highlightColor_ = highlightColor;
- RefreshTimePicker();
-}
-
-void UITimePicker::SetBackgroundFont(const char* name, uint8_t size)
-{
- Text::SetFont(name, size, backgroundFontName_, backgroundFontSize_);
- RefreshTimePicker();
-}
-
-void UITimePicker::SetHighlightFont(const char* name, uint8_t size)
-{
- Text::SetFont(name, size, highlightFontName_, highlightFontSize_);
- RefreshTimePicker();
-}
-
-void UITimePicker::SetWidth(int16_t width)
-{
- UIView::SetWidth(width);
- RefreshTimePicker();
-}
-
-void UITimePicker::SetHeight(int16_t height)
-{
- UIView::SetHeight(height);
- RefreshTimePicker();
-}
-}
diff --git a/frameworks/ui/src/components/ui_toggle_button.cpp b/frameworks/ui/src/components/ui_toggle_button.cpp
deleted file mode 100755
index 915b9d4..0000000
--- a/frameworks/ui/src/components/ui_toggle_button.cpp
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#include "common/image.h"
-#include "components/ui_toggle_button.h"
-#include "default_resource/toggle_button_res.h"
-#include "imgdecode/cache_manager.h"
-
-namespace OHOS {
-UIToggleButton::UIToggleButton()
-{
- image_[UNSELECTED].SetSrc(GetToggleButtonOffInfo());
- image_[SELECTED].SetSrc(GetToggleButtonOnInfo());
- ImageHeader header = { 0 };
- image_[UNSELECTED].GetHeader(header);
- Resize(header.width, header.height);
-}
-
-void UIToggleButton::SetState(bool state)
-{
- if (state) {
- UICheckBox::SetState(SELECTED);
- } else {
- UICheckBox::SetState(UNSELECTED);
- }
- Invalidate();
-}
-} // namespace OHOS
\ No newline at end of file
diff --git a/frameworks/ui/src/components/ui_view.cpp b/frameworks/ui/src/components/ui_view.cpp
deleted file mode 100755
index 582baf2..0000000
--- a/frameworks/ui/src/components/ui_view.cpp
+++ /dev/null
@@ -1,443 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#include "components/ui_view.h"
-#include "components/root_view.h"
-#include "core/measure_manager.h"
-#include "core/render_manager.h"
-#include "draw/draw_rect.h"
-#include "themes/theme_manager.h"
-
-namespace OHOS {
-UIView::UIView()
- : touchable_(false), visible_(true), draggable_(false), dragParentInstead_(true), isViewGroup_(false),
- needRedraw_(false), styleAllocFlag_(false), isIntercept_(true), opaScale_(OPA_OPAQUE), index_(0),
- id_(nullptr), parent_(nullptr), nextSibling_(nullptr), style_(nullptr), transMap_(nullptr),
- onClickListener_(nullptr), onLongPressListener_(nullptr), onDragListener_(nullptr),
- onTouchListener_(nullptr), rect_(0, 0, 0, 0), visibleRect_(nullptr)
-{
- SetupThemeStyles();
-}
-
-UIView::~UIView()
-{
- if (transMap_ != nullptr) {
- delete transMap_;
- transMap_ = nullptr;
- }
- if (visibleRect_ != nullptr) {
- delete visibleRect_;
- visibleRect_ = nullptr;
- }
- if (styleAllocFlag_) {
- delete style_;
- style_ = nullptr;
- styleAllocFlag_ = false;
- }
-}
-
-bool UIView::OnPreDraw(const Rect& invalidatedArea)
-{
- Rect rect(GetRect());
- int16_t r = style_->borderRadius_;
- if (r != 0) {
- if (r == COORD_MAX) {
- return false;
- }
- rect.SetLeft(rect.GetX() + r);
- rect.SetWidth(rect.GetWidth() - r);
- rect.SetTop(rect.GetY() + r);
- rect.SetHeight(rect.GetHeight() - r);
- }
- return rect.IsContains(invalidatedArea);
-}
-
-void UIView::OnDraw(const Rect& invalidatedArea)
-{
- DrawRect::Draw(GetRect(), invalidatedArea, *style_);
-}
-
-void UIView::SetupThemeStyles()
-{
- Theme* theme = ThemeManager::GetInstance().GetCurrent();
- if (theme != nullptr) {
- style_ = &(theme->GetMainStyle());
- } else {
- style_ = &(StyleDefault::GetDefaultStyle());
- }
-}
-
-void UIView::SetStyle(Style& style)
-{
- if (styleAllocFlag_) {
- delete style_;
- styleAllocFlag_ = false;
- }
- style_ = &style;
-}
-
-void UIView::SetStyle(uint8_t key, int64_t value)
-{
- if (!styleAllocFlag_) {
- style_ = new Style(*style_);
- styleAllocFlag_ = true;
- }
-
- style_->SetStyle(key, value);
-}
-
-void UIView::AddMeasureView()
-{
- MeasureManager::GetInstance().AddMeasureView(this);
-}
-
-void UIView::DeleteMeasureView()
-{
- MeasureManager::GetInstance().DeleteMeasureView(this);
-}
-
-void UIView::Invalidate()
-{
- InvalidateRect(GetRect());
-}
-
-void UIView::InvalidateRect(const Rect& invalidatedArea)
-{
- if (!visible_) {
- if (needRedraw_) {
- needRedraw_ = false;
- } else {
- return;
- }
- }
-
- Rect trunc(invalidatedArea);
- bool isIntersect = true;
- UIView* par = parent_;
- UIView* cur = this;
-
- while (par != nullptr) {
- if (!par->visible_) {
- return;
- }
-
- isIntersect = trunc.Intersect(par->GetContentRect(), trunc);
- if (isIntersect == false) {
- break;
- }
-
- cur = par;
- par = par->parent_;
- }
-
- if (isIntersect && cur->GetViewType() == UI_ROOT_VIEW) {
- RootView* rootView = reinterpret_cast(cur);
- rootView->AddInvalidateRect(trunc);
- }
-}
-
-void UIView::GetTargetView(const Point& point, UIView** last)
-{
- if (last == nullptr) {
- return;
- }
- UIView* par = parent_;
- Rect rect = GetRect();
-
- if (par != nullptr) {
- rect.Intersect(par->GetContentRect(), rect);
- }
-
- if (visible_ && touchable_ && rect.IsContains(point)) {
- *last = this;
- }
-}
-
-Rect UIView::GetRect() const
-{
- if ((transMap_ != nullptr) && !transMap_->IsInvalid()) {
- Rect r = transMap_->GetBoxRect();
- Rect origRect = GetOrigRect();
- r.SetX(r.GetX() + origRect.GetX() - transMap_->GetTransMapRect().GetX());
- r.SetY(r.GetY() + origRect.GetY() - transMap_->GetTransMapRect().GetY());
- return r;
- }
- return GetOrigRect();
-}
-
-Rect UIView::GetContentRect()
-{
- if ((transMap_ != nullptr) && !transMap_->IsInvalid()) {
- Rect r = transMap_->GetBoxRect();
- Rect origRect = GetOrigRect();
- r.SetX(r.GetX() + origRect.GetX() - transMap_->GetTransMapRect().GetX());
- r.SetY(r.GetY() + origRect.GetY() - transMap_->GetTransMapRect().GetY());
- return r;
- }
-
- Rect contentRect = GetRect();
- contentRect.SetX(contentRect.GetX() + style_->paddingLeft_ + style_->borderWidth_);
- contentRect.SetY(contentRect.GetY() + style_->paddingTop_ + style_->borderWidth_);
- contentRect.SetWidth(GetWidth());
- contentRect.SetHeight(GetHeight());
- return contentRect;
-}
-
-Rect UIView::GetOrigRect() const
-{
- int16_t x = rect_.GetX();
- int16_t y = rect_.GetY();
- UIView* par = parent_;
- while (par != nullptr) {
- x += par->GetX() + par->style_->paddingLeft_ + par->style_->borderWidth_;
- y += par->GetY() + par->style_->paddingTop_ + par->style_->borderWidth_;
- par = par->parent_;
- }
- return Rect(x, y, x + rect_.GetWidth() - 1, y + rect_.GetHeight() - 1);
-}
-
-Rect UIView::GetMaskedRect() const
-{
- Rect mask;
- if (visibleRect_ != nullptr) {
- mask.Intersect(GetRect(), GetVisibleRect());
- } else {
- mask = GetRect();
- }
- return mask;
-}
-
-Rect UIView::GetVisibleRect() const
-{
- if (visibleRect_ == nullptr) {
- return GetRect();
- }
- Rect absoluteRect;
- int16_t x = visibleRect_->GetX();
- int16_t y = visibleRect_->GetY();
- UIView* par = parent_;
- while (par != nullptr) {
- x += par->GetX();
- y += par->GetY();
- par = par->parent_;
- }
- absoluteRect.SetX(x);
- absoluteRect.SetY(y);
- absoluteRect.SetWidth(visibleRect_->GetWidth());
- absoluteRect.SetHeight(visibleRect_->GetHeight());
- return absoluteRect;
-}
-
-void UIView::SetTransformMap(const TransformMap& transMap)
-{
- if (transMap.IsInvalid()) {
- return;
- }
-
- Rect prevRect = GetRect();
- Rect mapRect = transMap.GetBoxRect();
-
- Rect joinRect;
- joinRect.Join(prevRect, mapRect);
-
- InvalidateRect(joinRect);
-
- if (transMap_ == nullptr) {
- transMap_ = new TransformMap();
- }
-
- *transMap_ = transMap;
-}
-
-void UIView::LayoutCenterOfParent(int16_t xOffset, int16_t yOffset)
-{
- if (parent_ == nullptr) {
- return;
- }
-
- int16_t topMargin = style_->marginTop_;
- int16_t leftMargin = style_->marginLeft_;
- int16_t rightMargin = style_->marginRight_;
- int16_t bottomMargin = style_->marginBottom_;
- // 2: half
- int16_t posX = parent_->GetWidth() / 2 - (rect_.GetWidth() - leftMargin + rightMargin) / 2 + xOffset;
- int16_t posY = parent_->GetHeight() / 2 - (rect_.GetHeight() - topMargin + bottomMargin) / 2 + yOffset;
- SetPosition(posX, posY);
-}
-
-void UIView::LayoutLeftOfParent(int16_t offset)
-{
- if (parent_ == nullptr) {
- return;
- }
-
- int16_t leftMargin = style_->marginLeft_;
- SetPosition(leftMargin + offset, GetY());
-}
-
-void UIView::LayoutRightOfParent(int16_t offset)
-{
- if (parent_ == nullptr) {
- return;
- }
-
- int16_t rightMargin = style_->marginRight_;
- SetPosition(parent_->GetWidth() - offset - rect_.GetWidth() - rightMargin, GetY());
-}
-
-void UIView::LayoutTopOfParent(int16_t offset)
-{
- if (parent_ == nullptr) {
- return;
- }
-
- int16_t topMargin = style_->marginTop_;
- SetPosition(GetX(), topMargin + offset);
-}
-
-void UIView::LayoutBottomOfParent(int16_t offset)
-{
- if (parent_ == nullptr) {
- return;
- }
-
- int16_t bottomMargin = style_->marginBottom_;
- SetPosition(GetX(), parent_->GetHeight() - offset - rect_.GetHeight() - bottomMargin);
-}
-
-void UIView::AlignLeftToSibling(const char* id, int16_t offset)
-{
- if (parent_ == nullptr) {
- return;
- }
- UIView* sib = parent_->GetChildById(id);
- if (sib != nullptr) {
- int16_t margin = sib->style_->marginLeft_ - style_->marginLeft_;
- SetPosition(sib->GetX() - margin + offset, GetY());
- }
-}
-
-void UIView::AlignRightToSibling(const char* id, int16_t offset)
-{
- if (parent_ == nullptr) {
- return;
- }
- UIView* sib = parent_->GetChildById(id);
- if (sib != nullptr) {
- int16_t margin = sib->style_->marginRight_ - style_->marginRight_;
- SetPosition(sib->GetX() + sib->rect_.GetWidth() - rect_.GetWidth() - offset + margin, GetY());
- }
-}
-
-void UIView::AlignTopToSibling(const char* id, int16_t offset)
-{
- if (parent_ == nullptr) {
- return;
- }
- UIView* sib = parent_->GetChildById(id);
- if (sib != nullptr) {
- int16_t margin = sib->style_->marginTop_ - style_->marginTop_;
- SetPosition(GetX(), sib->GetY() + offset - margin);
- }
-}
-
-void UIView::AlignBottomToSibling(const char* id, int16_t offset)
-{
- if (parent_ == nullptr) {
- return;
- }
- UIView* sib = parent_->GetChildById(id);
- if (sib != nullptr) {
- int16_t margin = sib->style_->marginBottom_ - style_->marginBottom_;
- SetPosition(GetX(), sib->GetY() + sib->rect_.GetHeight() - rect_.GetHeight() - offset + margin);
- }
-}
-
-void UIView::AlignHorCenterToSibling(const char* id, int16_t offset)
-{
- if (parent_ == nullptr) {
- return;
- }
- UIView* sib = parent_->GetChildById(id);
- if (sib != nullptr) {
- // 2 : half
- int16_t margin = (sib->style_->marginRight_ - sib->style_->marginLeft_ -
- style_->marginRight_ + style_->marginLeft_) / 2;
- SetPosition(sib->GetX() + sib->rect_.GetWidth() / 2 - rect_.GetWidth() / 2 + margin + offset, GetY());
- }
-}
-void UIView::AlignVerCenterToSibling(const char* id, int16_t offset)
-{
- if (parent_ == nullptr) {
- return;
- }
- UIView* sib = parent_->GetChildById(id);
- if (sib != nullptr) {
- // 2 : half
- int16_t margin = (sib->style_->marginBottom_ - sib->style_->marginTop_ -
- style_->marginBottom_ + style_->marginTop_) / 2;
- SetPosition(GetX(), sib->GetY() + sib->rect_.GetHeight() / 2 - rect_.GetHeight() / 2
- + margin + offset);
- }
-}
-
-void UIView::LayoutLeftToSibling(const char* id, int16_t offset)
-{
- if (parent_ == nullptr) {
- return;
- }
- UIView* sib = parent_->GetChildById(id);
- if (sib != nullptr) {
- int16_t margin = sib->style_->marginLeft_ + style_->marginRight_;
- SetPosition(sib->GetX() - offset - rect_.GetWidth() - margin, GetY());
- }
-}
-
-void UIView::LayoutRightToSibling(const char* id, int16_t offset)
-{
- if (parent_ == nullptr) {
- return;
- }
- UIView* sib = parent_->GetChildById(id);
- if (sib != nullptr) {
- int16_t margin = sib->style_->marginRight_ + style_->marginLeft_;
- SetPosition(sib->GetX() + sib->rect_.GetWidth() + offset + margin, GetY());
- }
-}
-
-void UIView::LayoutTopToSibling(const char* id, int16_t offset)
-{
- if (parent_ == nullptr) {
- return;
- }
- UIView* sib = parent_->GetChildById(id);
- if (sib != nullptr) {
- int16_t margin = sib->style_->marginTop_ + style_->marginBottom_;
- SetPosition(GetX(), sib->GetY() - offset - rect_.GetHeight() - margin);
- }
-}
-
-void UIView::LayoutBottomToSibling(const char* id, int16_t offset)
-{
- if (parent_ == nullptr) {
- return;
- }
- UIView* sib = parent_->GetChildById(id);
- if (sib != nullptr) {
- int16_t margin = sib->style_->marginBottom_ + style_->marginTop_;
- SetPosition(GetX(), sib->GetY() + sib->rect_.GetHeight() + offset + margin);
- }
-}
-} // namespace OHOS
diff --git a/frameworks/ui/src/components/ui_view_group.cpp b/frameworks/ui/src/components/ui_view_group.cpp
deleted file mode 100755
index 1d75fe6..0000000
--- a/frameworks/ui/src/components/ui_view_group.cpp
+++ /dev/null
@@ -1,238 +0,0 @@
-/*
- * Copyright (c) 2020 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.
- */
-
-#include "components/ui_view_group.h"
-#include
-
-namespace OHOS {
-UIViewGroup::UIViewGroup()
- : childrenHead_(nullptr), childrenTail_(nullptr), childrenNum_(0),
- isDragging_(false), disallowIntercept_(false), isAutoSize_(false)
-{
- isViewGroup_ = true;
-}
-
-UIViewGroup::~UIViewGroup() {}
-
-void UIViewGroup::Add(UIView* view)
-{
- if ((view == this) || (view == nullptr)) {
- return;
- }
- if (childrenHead_ == nullptr) {
- childrenHead_ = view;
- } else {
- UIView* head = childrenHead_;
- while (head != nullptr) {
- if (view == head ||
- (view->GetViewId() != nullptr &&
- head->GetViewId() != nullptr &&
- !strcmp(view->GetViewId(), head->GetViewId()))) {
- return;
- }
- head = head->GetNextSibling();
- }
- childrenTail_->SetNextSibling(view);
- }
- view->SetParent(this);
- view->SetNextSibling(nullptr);
- childrenTail_ = view;
- childrenNum_++;
- if (isAutoSize_) {
- AutoResize();
- }
- OnChildChanged();
-}
-
-void UIViewGroup::Insert(UIView* prevView, UIView* insertView)
-{
- if (insertView == nullptr) {
- return;
- }
- if (childrenHead_ == nullptr) {
- Add(insertView);
- return;
- }
- UIView* head = childrenHead_;
- while (head != nullptr) {
- if (insertView == head ||
- (insertView->GetViewId() != nullptr &&
- head->GetViewId() != nullptr &&
- !strcmp(insertView->GetViewId(), head->GetViewId()))) {
- return;
- }
- head = head->GetNextSibling();
- }
- if (prevView == nullptr) {
- insertView->SetNextSibling(childrenHead_);
- insertView->SetParent(this);
- childrenHead_ = insertView;
- } else {
- UIView* nextView = prevView->GetNextSibling();
- prevView->SetNextSibling(insertView);
- insertView->SetNextSibling(nextView);
- insertView->SetParent(this);
- }
- if (childrenTail_ == prevView) {
- childrenTail_ = insertView;
- }
- childrenNum_++;
- if (isAutoSize_) {
- AutoResize();
- }
- OnChildChanged();
-}
-
-void UIViewGroup::Remove(UIView* view)
-{
- if (childrenHead_ == nullptr || view == nullptr) {
- return;
- }
- if (childrenHead_ == view) {
- childrenHead_ = childrenHead_->GetNextSibling();
- view->SetParent(nullptr);
- view->SetNextSibling(nullptr);
- if (childrenTail_ == view) {
- childrenTail_ = nullptr;
- }
- childrenNum_--;
- OnChildChanged();
- return;
- }
- UIView* node = childrenHead_;
- while (node->GetNextSibling() != nullptr) {
- if (node->GetNextSibling() == view) {
- node->SetNextSibling(view->GetNextSibling());
- view->SetParent(nullptr);
- view->SetNextSibling(nullptr);
- if (childrenTail_ == view) {
- childrenTail_ = node;
- }
- childrenNum_--;
- OnChildChanged();
- return;
- }
- node = node->GetNextSibling();
- }
-}
-
-void UIViewGroup::RemoveAll()
-{
- UIView* node = childrenHead_;
- childrenHead_ = nullptr;
- childrenTail_ = nullptr;
- childrenNum_ = 0;
- UIView* tmp = nullptr;
- while (node != nullptr) {
- tmp = node;
- node = node->GetNextSibling();
- tmp->SetParent(nullptr);
- tmp->SetNextSibling(nullptr);
- }
- OnChildChanged();
-}
-
-void UIViewGroup::GetTargetView(const Point& point, UIView** last)
-{
- if (last == nullptr) {
- return;
- }
-
- Rect rect = GetRect();
- if (disallowIntercept_) {
- *last = nullptr;
- return;
- }
- if (!rect.IsContains(point)) {
- return;
- }
- if (!visible_) {
- return;
- }
- if (touchable_) {
- *last = this;
- }
- if (isDragging_) {
- return;
- }
- UIView* view = childrenHead_;
- while (view != nullptr) {
- if (!view->IsViewGroup()) {
- Rect rect = view->GetRect();
- if (rect.IsContains(point)) {
- view->GetTargetView(point, last);
- }
- } else {
- UIViewGroup* viewGroup = static_cast