From d5317eebd4dc4a2b582d413ecca7086f6ac7863d Mon Sep 17 00:00:00 2001 From: Caisking Date: Fri, 20 Jun 2025 14:21:11 +0800 Subject: [PATCH] =?utf8?q?=E5=A2=9E=E5=8A=A0=E7=94=BB=E5=B8=83=E7=BB=84?= =?utf8?q?=E4=BB=B6=E6=B5=8B=E8=AF=95Slice?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../wearable/fd230app/CMakeLists.txt | 4 +- .../nativelauncher/include/AppViewIDs.h | 2 + .../nativelauncher/include/NativeLauncher.h | 1 + .../nativelauncher/src/NativeLauncher.cpp | 18 + .../nativeui/applist/src/ApplistModel.cpp | 1 + .../canvastest/include/CanvasPresenter.h | 36 + .../nativeui/canvastest/include/CanvasView.h | 147 +++ .../canvastest/src/CanvasPresenter.cpp | 73 ++ .../nativeui/canvastest/src/CanvasView.cpp | 1015 +++++++++++++++++ 9 files changed, 1296 insertions(+), 1 deletion(-) create mode 100644 code/sdk/application/wearable/fd230app/nativeui/canvastest/include/CanvasPresenter.h create mode 100644 code/sdk/application/wearable/fd230app/nativeui/canvastest/include/CanvasView.h create mode 100644 code/sdk/application/wearable/fd230app/nativeui/canvastest/src/CanvasPresenter.cpp create mode 100644 code/sdk/application/wearable/fd230app/nativeui/canvastest/src/CanvasView.cpp diff --git a/code/sdk/application/wearable/fd230app/CMakeLists.txt b/code/sdk/application/wearable/fd230app/CMakeLists.txt index 2e8fe8b78..63620ac7c 100644 --- a/code/sdk/application/wearable/fd230app/CMakeLists.txt +++ b/code/sdk/application/wearable/fd230app/CMakeLists.txt @@ -855,7 +855,9 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/calendar/src/CalendarPresenter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/calendar/src/CalendarModel.cpp - + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/canvastest/src/CanvasView.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/canvastest/src/CanvasPresenter.cpp + ) diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h b/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h index bbda615ba..bcc445eb0 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h +++ b/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h @@ -103,6 +103,8 @@ typedef enum : uint16_t VIEW_ECG, //疲劳度 VIEW_FATIGUE, + //画布组件测试 + VIEW_CANVAS_TEST, /* -------------------------------------------------------------------------- */ /* ----------------------------------- 训练 ----------------------------------- */ VIEW_TRAINING, // 训练 diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h b/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h index 210e90cd7..493e559ed 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h +++ b/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h @@ -136,6 +136,7 @@ namespace OHOS void InittestSlice(void); void InitBloodPressureCheckSlice(void); + void InitCanvasTestSlice(void); private: void InitAllNativeSlices(void); diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp b/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp index a7905dde6..5a9c7706b 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp +++ b/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp @@ -134,6 +134,9 @@ /*时间格式显示*/ #include "set_time_format/include/SetTimeFormatView.h" #include "set_time_format/include/SetTimeFormatPresenter.h" +/*画布组件测试*/ +#include "canvastest/include/CanvasView.h" +#include "canvastest/include/CanvasPresenter.h" /* -------------------------------------------------------------------------- */ #include "secondaryfunction/include/SecondaryFunctionPresenter.h" #include "secondaryfunction/include/SecondaryFunctionView.h" @@ -479,6 +482,8 @@ namespace OHOS {VIEW_ASSISTANT, &NativeLauncher::InitAssistantSlice}, /*时间格式*/ {VIEW_SET_TIME_FORMAT, &NativeLauncher::InitSetTimeFormatSlice}, + /*画布测试*/ + {VIEW_CANVAS_TEST, &NativeLauncher::InitCanvasTestSlice}, /* -------------------------------------------------------------------------- */ /*智能助手*/ {VIEW_OFFLINEVOICE, &NativeLauncher::InitOfflineVoice}, @@ -1727,4 +1732,17 @@ namespace OHOS NativeAbility::GetInstance().AddSliceProxy(VIEW_SLEEPMODE, t_View); } + /*画布测试*/ + void NativeLauncher::InitCanvasTestSlice(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "NativeLauncher::InitCanvasSlice"); + SliceProxy *t_View = new AbilitySliceProxy; + if (nullptr == t_View) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "View is nullptr"); + return; + } + NativeAbility::GetInstance().AddSliceProxy(VIEW_CANVAS_TEST, t_View); + } + } diff --git a/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistModel.cpp index f787403dc..bba173252 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistModel.cpp @@ -89,6 +89,7 @@ namespace OHOS {VIEW_SCHEDULE, PNG_APPLIST_SCHEDULE_IMAGE_BIG, PNG_APPLIST_SCHEDULE_IMAGE, PNG_APPLIST_DEFAULT_IMG, "schedule", STR_SCHEDULE, nullptr}, {VIEW_CALENDAR, PNG_APPLIST_CALENDAR_IMAGE_BIG, PNG_APPLIST_CALENDAR_IMAGE, PNG_APPLIST_DEFAULT_IMG, "日历", STR_CALENDAR, nullptr}, {VIEW_SETTING, PNG_APPLIST_SETTING_IMAGE_BIG, PNG_APPLIST_SETTING_IMAGE, PNG_APPLIST_DEFAULT_IMG, "设置", STR_SETTINGS, nullptr}, + // {VIEW_CANVAS_TEST, PNG_APPLIST_DISTURB_IMAGE, PNG_APPLIST_DISTURB_IMAGE, PNG_APPLIST_DEFAULT_IMG, "勿扰模式", STR_DO_NOT_DISTURB, nullptr}, #if 0 /*屏蔽Slice*/ {VIEW_DNOTDISTURB, PNG_APPLIST_DISTURB_IMAGE, PNG_APPLIST_DISTURB_IMAGE, PNG_APPLIST_DEFAULT_IMG, "勿扰模式", STR_DO_NOT_DISTURB, nullptr}, diff --git a/code/sdk/application/wearable/fd230app/nativeui/canvastest/include/CanvasPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/canvastest/include/CanvasPresenter.h new file mode 100644 index 000000000..29f1ec068 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/canvastest/include/CanvasPresenter.h @@ -0,0 +1,36 @@ + + +#ifndef _CanvasView_PRESENTER_H +#define _CanvasView_PRESENTER_H + +#include "CanvasView.h" +#include "Presenter.h" + +namespace OHOS { + + +class CanvasView; +class CanvasPresenter : public Presenter, + public UIView::OnClickListener, + public UIView::OnDragListener, + public RootView::OnKeyActListener { +public: + CanvasPresenter(); + virtual ~CanvasPresenter(); + + void OnStart() override; + void OnPause() override; + void OnResume() override; + void OnStop() override; + + static CanvasPresenter *GetInstance(); + +private: + // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件 +}; +} // namespace OHOS + +#endif // SLEEPDETAIL_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/canvastest/include/CanvasView.h b/code/sdk/application/wearable/fd230app/nativeui/canvastest/include/CanvasView.h new file mode 100644 index 000000000..44aa4361d --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/canvastest/include/CanvasView.h @@ -0,0 +1,147 @@ +/* + * 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 + * + * 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_TEST_CANVAS_H +#define UI_TEST_CANVAS_H + +#include "BaseView.h" +#include "View.h" +#include "components/ui_canvas.h" +#include "components/ui_label_button.h" +#include "components/ui_scroll_view.h" +// #include "layout/grid_layout.h" + +#include "canvastest/include/CanvasPresenter.h" + +namespace OHOS { +class CanvasView : public View { +public: + CanvasView(); + ~CanvasView(); + static CanvasView *GetInstance(void); + void OnStop() override; + void OnSetUpView() override; + void OnTearDownView() override; + void OnStart() override; + + void UIKitCanvasTestDrawLine001(); + void UIKitCanvasTestDrawLine002(); + void UIKitCanvasTestDrawCurve001(); + void UIKitCanvasTestDrawCurve002(); + void UIKitCanvasTestDrawRect001(); + void UIKitCanvasTestDrawRect002(); + void UIKitCanvasTestDrawRect003(); + void UIKitCanvasTestDrawCircle001(); + void UIKitCanvasTestDrawCircle002(); + void UIKitCanvasTestDrawCircle003(); + void UIKitCanvasTestDrawArc001(); + void UIKitCanvasTestDrawImage001(); + void UIKitCanvasTestDrawLabel001(); + void UIKitCanvasTestDrawSector001(); + void UIKitCanvasTestClear001(); + void UIKitCanvasTestDrawPath001(); + void UIKitCanvasTestDrawPath002(); + void UIKitCanvasTestDrawPath003(); + void UIKitCanvasTestDrawPath004(); + void UIKitCanvasTestDrawPath005(); + void UIKitCanvasTestDrawPath006(); + void UIKitCanvasTestDrawPath007(); + void UIKitCanvasTestDrawPath008(); + void UIKitCanvasTestDrawPath009(); + void UIKitCanvasTestDrawPath010(); + void UIKitCanvasTestDrawPath011(); + void UIKitCanvasTestDrawPath012(); + void UIKitCanvasTestDrawPath013(); + void UIKitCanvasTestDrawPath014(); + void UIKitCanvasTestDrawPath015(); + void UIKitCanvasTestDrawPath016(); + void UIKitCanvasTestDrawPath017(); + void UIKitCanvasTestDrawPath018(); + void UIKitCanvasTestDrawPath019(); + void UIKitCanvasTestDrawPath020(); + void UIKitCanvasTestDrawPath021(); + void UIKitCanvasTestDrawPath022(); + void UIKitCanvasTestDrawPath023(); + void UIKitCanvasTestDrawPath024(); + void UIKitCanvasTestDrawPath025(); + void UIKitCanvasTestDrawPath026(); + void UIKitCanvasTestDrawPath027(); + void UIKitCanvasTestDrawPath028(); + void UIKitCanvasTestDrawPath029(); + void UIKitCanvasTestDrawPath030(); + void UIKitCanvasTestDrawPath031(); + void UIKitCanvasTestDrawPath032(); + void UIKitCanvasTestDrawPath033(); + void UIKitCanvasTestDrawPath034(); + +private: + const static int16_t GAP = 10; + const static int16_t TITLE_HEIGHT = 29; + const static uint16_t CANVAS_WIDTH = 454; + const static uint16_t CANVAS_HEIGHT = 200; + + static constexpr int16_t START1_X = 10; + static constexpr int16_t START1_Y = 10; + static constexpr int16_t START2_X = 80; + static constexpr int16_t START2_Y = 10; + static constexpr int16_t LINE1_X = 40; + static constexpr int16_t LINE1_Y = 100; + static constexpr int16_t LINE2_X = 100; + static constexpr int16_t LINE2_Y = 120; + static constexpr int16_t CENTER_X = 150; + static constexpr int16_t CENTER_Y = 150; + static constexpr int16_t RADIUS = 50; + static constexpr int16_t START_ANGLE = 30; + static constexpr int16_t END_ANGLE = 250; + static constexpr int16_t RECT_X = 250; + static constexpr int16_t RECT_Y = 50; + static constexpr int16_t RECT_WIDTH = 100; + static constexpr int16_t RECT_HEIGHT = 50; + + static constexpr uint16_t TITLE_LABEL_DEFAULT_HEIGHT = 30; + static constexpr uint16_t FONT_DEFAULT_SIZE = 20; + static constexpr uint16_t VIEW_DISTANCE_TO_LEFT_SIDE = 48; + static constexpr uint16_t VIEW_DISTANCE_TO_TOP_SIDE = 48; + static constexpr uint16_t VIEW_DISTANCE_TO_LEFT_SIDE2 = 24; + static constexpr uint16_t TEXT_DISTANCE_TO_LEFT_SIDE = 50; + static constexpr uint16_t TEXT_DISTANCE_TO_TOP_SIDE = 11; + static constexpr uint16_t HALF_OPA_OPAQUE = OPA_OPAQUE / 2; + static constexpr uint16_t VIEW_STYLE_BORDER_WIDTH = 2; + static constexpr uint16_t VIEW_STYLE_BORDER_RADIUS = 8; + static constexpr uint16_t BUTTON_LABEL_SIZE = 16; + static constexpr uint8_t BUTTON_STYLE_BORDER_RADIUS_VALUE = 20; + static constexpr uint32_t BUTTON_STYLE_BACKGROUND_COLOR_VALUE = 0xFF333333; + static constexpr uint32_t BUTTON_STYLE_BACKGROUND_COLOR_PRESS = 0xFF2D2D2D; + static constexpr int16_t BACK_BUTTON_HEIGHT = 50; + static constexpr uint16_t BUTTON_WIDHT1 = 80; + static constexpr uint16_t BUTTON_HEIGHT1 = 40; + static constexpr uint16_t BUTTON_WIDHT2 = 120; + static constexpr uint16_t BUTTON_HEIGHT2 = 40; + static constexpr uint16_t BUTTON_WIDHT3 = 150; + static constexpr uint16_t BUTTON_HEIGHT3 = 40; + static constexpr uint16_t TEST_LABEL_WIDTH = 300; + static constexpr uint16_t TEST_LABEL_HEIGHT = 50; + static constexpr uint16_t TITLE_X = 150; + static constexpr uint16_t OPA_150 = 150; + static constexpr uint16_t OPA_50 = 50; + + void CreateTitleLabel(const char *title); + UICanvas *CreateCanvas(); + + int16_t positionY_ = 0; + UIScrollView *scrollview_ = nullptr; +}; +} // namespace OHOS +#endif // UI_TEST_CANVAS_H \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/canvastest/src/CanvasPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/canvastest/src/CanvasPresenter.cpp new file mode 100644 index 000000000..9f83edad3 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/canvastest/src/CanvasPresenter.cpp @@ -0,0 +1,73 @@ + +#include "AppViewIDs.h" +#include "KeyInputListener.h" +#include "NativeAbility.h" +#include "common/key_code.h" +#include "components/ui_label_ext.h" +#include "custom_utils.h" +#include "ui_resource_string.h" + +#include "broadcast_service.h" + +#include "canvastest/include/CanvasView.h" +#include "canvastest/include/CanvasPresenter.h" +#include "custom_runtime.h" +#include "custom_utils.h" +#include "gfx_utils/mem_check.h" +#include "graphic_service.h" + +namespace OHOS { + +// 当前Presenter属性实例化的内存指针 +static CanvasPresenter *g_pCanvasPresenter = nullptr; +CanvasPresenter::CanvasPresenter() { + g_pCanvasPresenter = this; +} + +CanvasPresenter::~CanvasPresenter() { + g_pCanvasPresenter = nullptr; +} + +CanvasPresenter *CanvasPresenter::GetInstance() { + + return g_pCanvasPresenter; +} + +void CanvasPresenter::OnStart() { + Presenter::OnStart(); +} + +void CanvasPresenter::OnPause(void) { + Presenter::OnPause(); +} + +void CanvasPresenter::OnResume(void) { + + Presenter::OnResume(); +} + +void CanvasPresenter::OnStop(void) { + Presenter::OnStop(); +} + +bool CanvasPresenter::OnDrag(UIView &view, const DragEvent &event) { + return true; +} + +bool CanvasPresenter::OnClick(UIView &view, const ClickEvent &event) { + + return true; +} + +bool CanvasPresenter::OnKeyAct(UIView &view, const KeyEvent &event) { + unsigned short keyID = event.GetKeyId(); + unsigned short keyState = event.GetState(); + // 如果是power键,且是亮屏状态,按键释放就返回上一级 + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && + keyState == 1 && uapi_get_screen_state() == 0) { + NativeAbility::GetInstance().Back( + TransitionType::TRANSITION_BACK_TO_HEXAGONS); + } + return true; +} +} // namespace OHOS \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/canvastest/src/CanvasView.cpp b/code/sdk/application/wearable/fd230app/nativeui/canvastest/src/CanvasView.cpp new file mode 100644 index 000000000..f935b3395 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/canvastest/src/CanvasView.cpp @@ -0,0 +1,1015 @@ +/* + * 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 + * + * 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_canvas.h" +#include "components/ui_label.h" +#include "canvastest/include/CanvasView.h" +#include "wearable_log.h" +namespace OHOS { + + static CanvasView *g_pCanvasView{nullptr}; + + + CanvasView::CanvasView() + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CanvasView::CanvasView"); + g_pCanvasView = this; + positionY_ = 0; + } + + CanvasView::~CanvasView() + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CanvasView::~CanvasView"); + g_pCanvasView = nullptr; + } + + CanvasView *CanvasView::GetInstance() + { + return g_pCanvasView; + } + +void CanvasView::OnStart() +{ + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BPMainView::OnStart"); + View::OnStart(); + + scrollview_ = new UIScrollView(); + scrollview_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + scrollview_->SetDraggable(true); + scrollview_->SetTouchable(true); + scrollview_->SetOnDragListener(presenter_); + RootView::GetInstance()->SetOnKeyActListener(presenter_); + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Starting UIKitCanvasTestDrawLine001"); + UIKitCanvasTestDrawLine001(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Finished UIKitCanvasTestDrawLine001"); + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Starting UIKitCanvasTestDrawLine002"); + UIKitCanvasTestDrawLine002(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Finished UIKitCanvasTestDrawLine002"); + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Starting UIKitCanvasTestDrawCurve001"); + UIKitCanvasTestDrawCurve001(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Finished UIKitCanvasTestDrawCurve001"); + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Starting UIKitCanvasTestDrawCurve002"); + UIKitCanvasTestDrawCurve002(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Finished UIKitCanvasTestDrawCurve002"); + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Starting UIKitCanvasTestDrawRect001"); + UIKitCanvasTestDrawRect001(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Finished UIKitCanvasTestDrawRect001"); + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Starting UIKitCanvasTestDrawRect002"); + UIKitCanvasTestDrawRect002(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Finished UIKitCanvasTestDrawRect002"); + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Starting UIKitCanvasTestDrawRect003"); + UIKitCanvasTestDrawRect003(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Finished UIKitCanvasTestDrawRect003"); + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Starting UIKitCanvasTestDrawCircle001"); + UIKitCanvasTestDrawCircle001(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Finished UIKitCanvasTestDrawCircle001"); + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Starting UIKitCanvasTestDrawCircle002"); + UIKitCanvasTestDrawCircle002(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Finished UIKitCanvasTestDrawCircle002"); + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Starting UIKitCanvasTestDrawCircle003"); + UIKitCanvasTestDrawCircle003(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Finished UIKitCanvasTestDrawCircle003"); + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Starting UIKitCanvasTestDrawArc001"); + UIKitCanvasTestDrawArc001(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Finished UIKitCanvasTestDrawArc001"); + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Starting UIKitCanvasTestDrawImage001"); + UIKitCanvasTestDrawImage001(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Finished UIKitCanvasTestDrawImage001"); + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Starting UIKitCanvasTestDrawLabel001"); + UIKitCanvasTestDrawLabel001(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Finished UIKitCanvasTestDrawLabel001"); + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Starting UIKitCanvasTestDrawSector001"); + UIKitCanvasTestDrawSector001(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Finished UIKitCanvasTestDrawSector001"); + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Starting UIKitCanvasTestClear001"); + UIKitCanvasTestClear001(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Finished UIKitCanvasTestClear001"); + + // 为DrawPath系列函数添加相同的日志输出 + #define LOG_AND_CALL(func) \ + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Starting " #func); \ + func(); \ + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Finished " #func); + + LOG_AND_CALL(UIKitCanvasTestDrawPath001); + LOG_AND_CALL(UIKitCanvasTestDrawPath002); + LOG_AND_CALL(UIKitCanvasTestDrawPath003); + LOG_AND_CALL(UIKitCanvasTestDrawPath004); + LOG_AND_CALL(UIKitCanvasTestDrawPath005); + LOG_AND_CALL(UIKitCanvasTestDrawPath006); + LOG_AND_CALL(UIKitCanvasTestDrawPath007); + LOG_AND_CALL(UIKitCanvasTestDrawPath008); + LOG_AND_CALL(UIKitCanvasTestDrawPath009); + LOG_AND_CALL(UIKitCanvasTestDrawPath010); + LOG_AND_CALL(UIKitCanvasTestDrawPath011); + LOG_AND_CALL(UIKitCanvasTestDrawPath012); + LOG_AND_CALL(UIKitCanvasTestDrawPath013); + LOG_AND_CALL(UIKitCanvasTestDrawPath014); + LOG_AND_CALL(UIKitCanvasTestDrawPath015); + LOG_AND_CALL(UIKitCanvasTestDrawPath016); + LOG_AND_CALL(UIKitCanvasTestDrawPath017); + LOG_AND_CALL(UIKitCanvasTestDrawPath018); + LOG_AND_CALL(UIKitCanvasTestDrawPath019); + LOG_AND_CALL(UIKitCanvasTestDrawPath020); + LOG_AND_CALL(UIKitCanvasTestDrawPath021); + LOG_AND_CALL(UIKitCanvasTestDrawPath022); + LOG_AND_CALL(UIKitCanvasTestDrawPath023); + LOG_AND_CALL(UIKitCanvasTestDrawPath024); + LOG_AND_CALL(UIKitCanvasTestDrawPath025); + LOG_AND_CALL(UIKitCanvasTestDrawPath026); + LOG_AND_CALL(UIKitCanvasTestDrawPath027); + LOG_AND_CALL(UIKitCanvasTestDrawPath028); + LOG_AND_CALL(UIKitCanvasTestDrawPath029); + LOG_AND_CALL(UIKitCanvasTestDrawPath030); + LOG_AND_CALL(UIKitCanvasTestDrawPath031); + LOG_AND_CALL(UIKitCanvasTestDrawPath032); + LOG_AND_CALL(UIKitCanvasTestDrawPath033); + LOG_AND_CALL(UIKitCanvasTestDrawPath034); + + #undef LOG_AND_CALL + + SetContainerView(scrollview_); +} + void CanvasView::OnSetUpView() { + View::OnSetUpView(); + Draw(); + } + + void CanvasView::OnTearDownView() { + View::OnTearDownView(); + return; + } + + void CanvasView::OnStop() { + View::OnStop(); + if (scrollview_ != nullptr) { + scrollview_->RemoveAll(); + delete scrollview_; + scrollview_ = nullptr; + } + RootView::GetInstance()->RemoveAll(); + return; + } + + void CanvasView::CreateTitleLabel(const char* title) + { + UILabel* titleLabel = new UILabel(); + titleLabel->SetPosition(TEXT_DISTANCE_TO_LEFT_SIDE, positionY_, Screen::GetInstance().GetWidth(), TITLE_HEIGHT); + titleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); + titleLabel->SetText(title); + scrollview_->Add(titleLabel); + positionY_ += TITLE_HEIGHT + 8; // 8: gap + } + + UICanvas* CanvasView::CreateCanvas() + { + UICanvas* canvas = new UICanvas(); + canvas->SetHeight(CANVAS_HEIGHT); + canvas->SetWidth(CANVAS_WIDTH); + canvas->SetPosition(VIEW_DISTANCE_TO_LEFT_SIDE, positionY_); + canvas->SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full); + scrollview_->Add(canvas); + positionY_ += CANVAS_HEIGHT + GAP; + return canvas; + } + + void CanvasView::UIKitCanvasTestDrawLine001() + { + if (scrollview_ == nullptr) { + return; + } + CreateTitleLabel("绘制直线"); + UICanvas* canvas = CreateCanvas(); + Paint paint; + // {0, 10}: Start point coordinates x, y; {50, 10}: end point coordinates x, y + canvas->DrawLine({0, 10}, {50, 10}, paint); + } + + void CanvasView::UIKitCanvasTestDrawLine002() + { + if (scrollview_ == nullptr) { + return; + } + CreateTitleLabel("绘制直线"); + UICanvas* canvas = CreateCanvas(); + + Paint paint; + paint.SetStrokeWidth(5); // 5: line width + canvas->SetStartPosition({ 50, 10 }); // {50, 10}: Start point coordinates x, y; + canvas->DrawLine({ 100, 50 }, paint); // {100, 50}: end point coordinates x, y + } + + void CanvasView::UIKitCanvasTestDrawCurve001() + { + if (scrollview_ == nullptr) { + return; + } + CreateTitleLabel("绘制曲线"); + UICanvas* canvas = CreateCanvas(); + + Paint paint; + paint.SetStrokeColor(Color::Red()); + canvas->DrawCurve({ 100, 50 }, { 150, 50 }, { 150, 50 }, { 150, 100 }, paint); + } + + void CanvasView::UIKitCanvasTestDrawCurve002() + { + if (scrollview_ == nullptr) { + return; + } + CreateTitleLabel("绘制曲线"); + UICanvas* canvas = CreateCanvas(); + + Paint paint; + paint.SetStrokeColor(Color::Red()); + canvas->DrawCurve({ 100, 50 }, { 150, 50 }, { 150, 100 }, paint); + } + + void CanvasView::UIKitCanvasTestDrawRect001() + { + if (scrollview_ == nullptr) { + return; + } + CreateTitleLabel("矩形填充"); + UICanvas* canvas = CreateCanvas(); + + Paint paint; + paint.SetStyle(Paint::PaintStyle::FILL_STYLE); + paint.SetFillColor(Color::Yellow()); + paint.SetStrokeWidth(30); // 30: line width + // {100, 10}: left corner coordinates point, 50: width, 50: rectangle style + canvas->DrawRect({ 100, 10 }, 50, 50, paint); + } + + void CanvasView::UIKitCanvasTestDrawRect002() + { + if (scrollview_ == nullptr) { + return; + } + CreateTitleLabel("矩形描边"); + UICanvas* canvas = CreateCanvas(); + + Paint paint; + paint.SetStyle(Paint::PaintStyle::STROKE_STYLE); + paint.SetStrokeColor(Color::Blue()); + // {200, 10}: left corner coordinates point, 50: width, 50: rectangle style + canvas->DrawRect({ 200, 10 }, 50, 50, paint); + } + + void CanvasView::UIKitCanvasTestDrawRect003() + { + if (scrollview_ == nullptr) { + return; + } + CreateTitleLabel("矩形填充 + 描边"); + UICanvas* canvas = CreateCanvas(); + + Paint paint; + paint.SetStyle(Paint::PaintStyle::STROKE_FILL_STYLE); + paint.SetFillColor(Color::Yellow()); + paint.SetStrokeColor(Color::Blue()); + // {300, 10}: left corner coordinates point, 50: width, 50: rectangle style + canvas->DrawRect({ 300, 10 }, 50, 50, paint); + } + + void CanvasView::UIKitCanvasTestDrawCircle001() + { + if (scrollview_ == nullptr) { + return; + } + CreateTitleLabel("圆形填充"); + UICanvas* canvas = CreateCanvas(); + + Paint paint; + paint.SetStyle(Paint::PaintStyle::FILL_STYLE); + paint.SetStrokeColor(Color::Yellow()); + paint.SetFillColor(Color::Yellow()); + paint.SetStrokeWidth(10); // 10: line width + paint.SetOpacity(127); // 127: opacity + // {100, 100}: circle center coordinates, 30: circle radius + canvas->DrawCircle({ 100, 100 }, 30, paint); + } + + void CanvasView::UIKitCanvasTestDrawCircle002() + { + if (scrollview_ == nullptr) { + return; + } + CreateTitleLabel("圆形描边"); + UICanvas* canvas = CreateCanvas(); + + Paint paint; + paint.SetStyle(Paint::PaintStyle::STROKE_STYLE); + paint.SetStrokeColor(Color::Blue()); + paint.SetStrokeWidth(10); // 10: line width + paint.SetOpacity(127); // 127: opacity + // {200, 100}: circle center coordinates, 30: circle radius + canvas->DrawCircle({ 200, 100 }, 30, paint); + } + + void CanvasView::UIKitCanvasTestDrawCircle003() + { + if (scrollview_ == nullptr) { + return; + } + CreateTitleLabel("圆形填充 + 描边"); + UICanvas* canvas = CreateCanvas(); + + Paint paint; + paint.SetStyle(Paint::PaintStyle::STROKE_FILL_STYLE); + paint.SetFillColor(Color::Yellow()); + paint.SetStrokeColor(Color::Blue()); + paint.SetStrokeWidth(10); // 10: line width + paint.SetOpacity(127); // 127: opacity + // {300, 100}: circle center coordinates, 30: circle radius + canvas->DrawCircle({ 300, 100 }, 30, paint); + } + + void CanvasView::UIKitCanvasTestDrawArc001() + { + if (scrollview_ == nullptr) { + return; + } + CreateTitleLabel("绘制弧线"); + UICanvas* canvas = CreateCanvas(); + + Paint paint; + paint.SetStyle(Paint::PaintStyle::STROKE_STYLE); + paint.SetStrokeColor(Color::Red()); + paint.SetStrokeWidth(10); // 10: line width + // {100, 150}: arc's center coordinates, 50: arc radius, 135: start angle, 270: end angle + canvas->DrawArc({ 100, 150 }, 50, 135, 270, paint); + } + + void CanvasView::UIKitCanvasTestDrawImage001() + { + if (scrollview_ == nullptr) { + return; + } + CreateTitleLabel("绘制图片"); + UICanvas* canvas = CreateCanvas(); + + Paint paint; + paint.SetOpacity(127); // 127: opacity + // {200, 50}: start point coordinates + // canvas->DrawImage({ 200, 50 }, GREEN_IMAGE_PATH, paint); + } + + void CanvasView::UIKitCanvasTestDrawLabel001() + { + if (scrollview_ == nullptr) { + return; + } + CreateTitleLabel("绘制文字"); + UICanvas* canvas = CreateCanvas(); + + Paint paint; + paint.SetFillColor(Color::Blue()); + UICanvas::FontStyle fontStyle; + fontStyle.align = TEXT_ALIGNMENT_RIGHT; + fontStyle.direct = TEXT_DIRECT_RTL; + fontStyle.fontName = DEFAULT_VECTOR_FONT_FILENAME; + fontStyle.fontSize = 30; // 30: font size + fontStyle.letterSpace = 10; // 10 letter space + // {50, 50}: start point coordinates, 100: max width + canvas->DrawLabel({ 50, 50 }, "canvas绘制字体", 100, fontStyle, paint); + } + + void CanvasView::UIKitCanvasTestDrawSector001() + { + if (scrollview_ == nullptr) { + return; + } + CreateTitleLabel("扇形填充"); + UICanvas* canvas = CreateCanvas(); + + Paint paint; + paint.SetStyle(Paint::PaintStyle::FILL_STYLE); + paint.SetFillColor(Color::Yellow()); + // {350, 150}: sector's center coordinates, 100: sector radius, 0: start angle, 30: end angle + canvas->DrawSector({ 350, 150 }, 100, 0, 30, paint); + } + + void CanvasView::UIKitCanvasTestClear001() + { + if (scrollview_ == nullptr) { + return; + } + CreateTitleLabel("清空画布,无显示"); + UICanvas* canvas = CreateCanvas(); + + Paint paint; + // {0, 10}: Start point coordinates x, y; {50, 10}: end point coordinates x, y + canvas->DrawLine({ 0, 10 }, { 50, 10 }, paint); + canvas->Clear(); + } + + void CanvasView::UIKitCanvasTestDrawPath001() + { + if (scrollview_ == nullptr) { + return; + } + CreateTitleLabel("moveTo,无显示"); + UICanvas* canvas = CreateCanvas(); + + Paint paint; + canvas->BeginPath(); + canvas->MoveTo({ START1_X, START1_Y }); + canvas->ClosePath(); + canvas->DrawPath(paint); + } + + void CanvasView::UIKitCanvasTestDrawPath002() + { + if (scrollview_ == nullptr) { + return; + } + CreateTitleLabel("lineTo,无显示"); + UICanvas* canvas = CreateCanvas(); + + Paint paint; + canvas->BeginPath(); + canvas->LineTo({ LINE1_X, LINE1_Y }); + canvas->DrawPath(paint); + } + + void CanvasView::UIKitCanvasTestDrawPath003() + { + if (scrollview_ == nullptr) { + return; + } + CreateTitleLabel("arc"); + UICanvas* canvas = CreateCanvas(); + + Paint paint; + canvas->BeginPath(); + canvas->ArcTo({ CENTER_X, CENTER_Y }, RADIUS, START_ANGLE, END_ANGLE); + canvas->DrawPath(paint); + } + + void CanvasView::UIKitCanvasTestDrawPath004() + { + if (scrollview_ == nullptr) { + return; + } + CreateTitleLabel("rect"); + UICanvas* canvas = CreateCanvas(); + + Paint paint; + canvas->BeginPath(); + canvas->AddRect({ RECT_X, RECT_Y }, RECT_HEIGHT, RECT_WIDTH); + canvas->DrawPath(paint); + } + + void CanvasView::UIKitCanvasTestDrawPath005() + { + if (scrollview_ == nullptr) { + return; + } + CreateTitleLabel("closePath,无显示"); + UICanvas* canvas = CreateCanvas(); + + Paint paint; + canvas->BeginPath(); + canvas->ClosePath(); + canvas->DrawPath(paint); + } + + void CanvasView::UIKitCanvasTestDrawPath006() + { + if (scrollview_ == nullptr) { + return; + } + CreateTitleLabel("moveTo + lineTo"); + UICanvas* canvas = CreateCanvas(); + + Paint paint; + canvas->BeginPath(); + canvas->MoveTo({ START1_X, START1_Y }); + canvas->LineTo({ LINE1_X, LINE1_Y }); + canvas->DrawPath(paint); + } + + void CanvasView::UIKitCanvasTestDrawPath007() + { + if (scrollview_ == nullptr) { + return; + } + CreateTitleLabel("moveTo + arc"); + UICanvas* canvas = CreateCanvas(); + + Paint paint; + canvas->BeginPath(); + canvas->MoveTo({ START1_X, START1_Y }); + canvas->ArcTo({ CENTER_X, CENTER_Y }, RADIUS, START_ANGLE, END_ANGLE); + canvas->DrawPath(paint); + } + + void CanvasView::UIKitCanvasTestDrawPath008() + { + if (scrollview_ == nullptr) { + return; + } + CreateTitleLabel("moveTo + rect"); + UICanvas* canvas = CreateCanvas(); + + Paint paint; + canvas->BeginPath(); + canvas->MoveTo({ START1_X, START1_Y }); + canvas->AddRect({ RECT_X, RECT_Y }, RECT_HEIGHT, RECT_WIDTH); + canvas->DrawPath(paint); + } + + void CanvasView::UIKitCanvasTestDrawPath009() + { + if (scrollview_ == nullptr) { + return; + } + CreateTitleLabel("moveTo + closePath"); + UICanvas* canvas = CreateCanvas(); + + Paint paint; + canvas->BeginPath(); + canvas->MoveTo({ START1_X, START1_Y }); + canvas->LineTo({ LINE1_X, LINE1_Y }); + canvas->LineTo({ LINE2_X, LINE2_Y }); + canvas->ClosePath(); + canvas->DrawPath(paint); + } + + void CanvasView::UIKitCanvasTestDrawPath010() + { + if (scrollview_ == nullptr) { + return; + } + CreateTitleLabel("闭合路径调用closePath"); + UICanvas* canvas = CreateCanvas(); + + Paint paint; + canvas->BeginPath(); + canvas->MoveTo({ START1_X, START1_Y }); + canvas->LineTo({ LINE1_X, LINE1_Y }); + canvas->LineTo({ LINE2_X, LINE2_Y }); + canvas->LineTo({ START1_X, START1_Y }); + canvas->ClosePath(); + canvas->DrawPath(paint); + } + + void CanvasView::UIKitCanvasTestDrawPath011() + { + if (scrollview_ == nullptr) { + return; + } + CreateTitleLabel("moveTo + lineTo + moveTo + lineTo"); + UICanvas* canvas = CreateCanvas(); + + Paint paint; + canvas->BeginPath(); + canvas->MoveTo({ START1_X, START1_Y }); + canvas->LineTo({ LINE1_X, LINE1_Y }); + canvas->MoveTo({ START2_X, START2_Y }); + canvas->LineTo({ LINE2_X, LINE2_Y }); + canvas->DrawPath(paint); + } + + void CanvasView::UIKitCanvasTestDrawPath012() + { + if (scrollview_ == nullptr) { + return; + } + CreateTitleLabel("moveTo + lineTo + arc"); + UICanvas* canvas = CreateCanvas(); + + Paint paint; + canvas->BeginPath(); + canvas->MoveTo({ START1_X, START1_Y }); + canvas->LineTo({ LINE1_X, LINE1_Y }); + canvas->ArcTo({ CENTER_X, CENTER_Y }, RADIUS, START_ANGLE, END_ANGLE); + canvas->DrawPath(paint); + } + + void CanvasView::UIKitCanvasTestDrawPath013() + { + if (scrollview_ == nullptr) { + return; + } + CreateTitleLabel("moveTo + lineTo + arc + closePath"); + UICanvas* canvas = CreateCanvas(); + + Paint paint; + canvas->BeginPath(); + canvas->MoveTo({ START1_X, START1_Y }); + canvas->LineTo({ LINE1_X, LINE1_Y }); + canvas->ArcTo({ CENTER_X, CENTER_Y }, RADIUS, START_ANGLE, END_ANGLE); + canvas->ClosePath(); + canvas->DrawPath(paint); + } + + void CanvasView::UIKitCanvasTestDrawPath014() + { + if (scrollview_ == nullptr) { + return; + } + CreateTitleLabel("moveTo + lineTo + rect"); + UICanvas* canvas = CreateCanvas(); + + Paint paint; + canvas->BeginPath(); + canvas->MoveTo({ START1_X, START1_Y }); + canvas->LineTo({ LINE1_X, LINE1_Y }); + canvas->AddRect({ RECT_X, RECT_Y }, RECT_HEIGHT, RECT_WIDTH); + canvas->DrawPath(paint); + } + + void CanvasView::UIKitCanvasTestDrawPath015() + { + if (scrollview_ == nullptr) { + return; + } + CreateTitleLabel("moveTo + lineTo + rect + closePath"); + UICanvas* canvas = CreateCanvas(); + + Paint paint; + canvas->BeginPath(); + canvas->MoveTo({ START1_X, START1_Y }); + canvas->LineTo({ LINE1_X, LINE1_Y }); + canvas->AddRect({ RECT_X, RECT_Y }, RECT_HEIGHT, RECT_WIDTH); + canvas->ClosePath(); + canvas->DrawPath(paint); + } + + void CanvasView::UIKitCanvasTestDrawPath016() + { + if (scrollview_ == nullptr) { + return; + } + CreateTitleLabel("rect + lineTo"); + UICanvas* canvas = CreateCanvas(); + + Paint paint; + canvas->BeginPath(); + canvas->AddRect({ RECT_X, RECT_Y }, RECT_HEIGHT, RECT_WIDTH); + canvas->LineTo({ LINE1_X, LINE1_Y }); + canvas->DrawPath(paint); + } + + void CanvasView::UIKitCanvasTestDrawPath017() + { + if (scrollview_ == nullptr) { + return; + } + CreateTitleLabel("rect + moveTo + lineTo"); + UICanvas* canvas = CreateCanvas(); + + Paint paint; + canvas->BeginPath(); + canvas->AddRect({ RECT_X, RECT_Y }, RECT_HEIGHT, RECT_WIDTH); + canvas->MoveTo({ START1_X, START1_Y }); + canvas->LineTo({ LINE1_X, LINE1_Y }); + canvas->DrawPath(paint); + } + + void CanvasView::UIKitCanvasTestDrawPath018() + { + if (scrollview_ == nullptr) { + return; + } + CreateTitleLabel("rect + arc"); + UICanvas* canvas = CreateCanvas(); + + Paint paint; + canvas->BeginPath(); + canvas->AddRect({ RECT_X, RECT_Y }, RECT_HEIGHT, RECT_WIDTH); + canvas->ArcTo({ CENTER_X, CENTER_Y }, RADIUS, START_ANGLE, END_ANGLE); + canvas->DrawPath(paint); + } + + void CanvasView::UIKitCanvasTestDrawPath019() + { + if (scrollview_ == nullptr) { + return; + } + CreateTitleLabel("arc + rect"); + UICanvas* canvas = CreateCanvas(); + + Paint paint; + canvas->BeginPath(); + canvas->ArcTo({ CENTER_X, CENTER_Y }, RADIUS, START_ANGLE, END_ANGLE); + canvas->AddRect({ RECT_X, RECT_Y }, RECT_HEIGHT, RECT_WIDTH); + canvas->DrawPath(paint); + } + + void CanvasView::UIKitCanvasTestDrawPath020() + { + if (scrollview_ == nullptr) { + return; + } + CreateTitleLabel("moveTo + arc + closePath + lineTo"); + UICanvas* canvas = CreateCanvas(); + + Paint paint; + canvas->BeginPath(); + canvas->MoveTo({ START1_X, START1_Y }); + canvas->ArcTo({ CENTER_X, CENTER_Y }, RADIUS, START_ANGLE, END_ANGLE); + canvas->ClosePath(); + canvas->LineTo({ LINE1_X, LINE1_Y }); + canvas->DrawPath(paint); + } + + void CanvasView::UIKitCanvasTestDrawPath021() + { + if (scrollview_ == nullptr) { + return; + } + CreateTitleLabel("不调用beginPath,无显示"); + UICanvas* canvas = CreateCanvas(); + + Paint paint; + canvas->MoveTo({ START1_X, START1_Y }); + canvas->ArcTo({ CENTER_X, CENTER_Y }, RADIUS, START_ANGLE, END_ANGLE); + canvas->ClosePath(); + canvas->LineTo({ LINE1_X, LINE1_Y }); + canvas->DrawPath(paint); + } + + void CanvasView::UIKitCanvasTestDrawPath022() + { + if (scrollview_ == nullptr) { + return; + } + CreateTitleLabel("不调用drawPath,无显示"); + UICanvas* canvas = CreateCanvas(); + + Paint paint; + canvas->BeginPath(); + canvas->MoveTo({ START1_X, START1_Y }); + canvas->ArcTo({ CENTER_X, CENTER_Y }, RADIUS, START_ANGLE, END_ANGLE); + canvas->ClosePath(); + canvas->LineTo({ LINE1_X, LINE1_Y }); + } + + void CanvasView::UIKitCanvasTestDrawPath023() + { + if (scrollview_ == nullptr) { + return; + } + CreateTitleLabel("moveTo + lineTo + closePath"); + UICanvas* canvas = CreateCanvas(); + + Paint paint; + canvas->BeginPath(); + canvas->MoveTo({ START1_X, START1_Y }); + canvas->LineTo({ LINE1_X, LINE1_Y }); + canvas->ClosePath(); + canvas->DrawPath(paint); + } + + void CanvasView::UIKitCanvasTestDrawPath024() + { + if (scrollview_ == nullptr) { + return; + } + CreateTitleLabel("moveTo + closePath,无显示"); + UICanvas* canvas = CreateCanvas(); + + Paint paint; + canvas->BeginPath(); + canvas->MoveTo({ START1_X, START1_Y }); + canvas->ClosePath(); + canvas->DrawPath(paint); + } + + void CanvasView::UIKitCanvasTestDrawPath025() + { + if (scrollview_ == nullptr) { + return; + } + CreateTitleLabel("多次drawPath"); + UICanvas* canvas = CreateCanvas(); + + Paint paint; + canvas->BeginPath(); + canvas->MoveTo({ START1_X, START1_Y }); + canvas->LineTo({ LINE1_X, LINE1_Y }); + canvas->DrawPath(paint); + paint.SetStrokeColor(Color::Blue()); + paint.SetStrokeWidth(1); + canvas->LineTo({ LINE2_X, LINE2_Y }); + canvas->DrawPath(paint); + } + + void CanvasView::UIKitCanvasTestDrawPath026() + { + if (scrollview_ == nullptr) { + return; + } + CreateTitleLabel("arc起止角度互换"); + UICanvas* canvas = CreateCanvas(); + + Paint paint; + canvas->BeginPath(); + canvas->MoveTo({ START1_X, START1_Y }); + canvas->ArcTo({ CENTER_X, CENTER_Y }, RADIUS, START_ANGLE, END_ANGLE); + + canvas->MoveTo({ START2_X, START2_Y }); + canvas->ArcTo({ CENTER_X + CENTER_X, CENTER_Y }, RADIUS, END_ANGLE, START_ANGLE); + + canvas->DrawPath(paint); + } + + void CanvasView::UIKitCanvasTestDrawPath027() + { + if (scrollview_ == nullptr) { + return; + } + CreateTitleLabel("arc扫描范围超过360度 "); + UICanvas* canvas = CreateCanvas(); + + Paint paint; + canvas->BeginPath(); + canvas->MoveTo({ START1_X, START1_Y }); + canvas->ArcTo({ CENTER_X, CENTER_Y }, RADIUS, START_ANGLE, START_ANGLE + CIRCLE_IN_DEGREE + QUARTER_IN_DEGREE); + canvas->ArcTo({ CENTER_X + CENTER_X, CENTER_Y }, RADIUS, END_ANGLE, START_ANGLE + CIRCLE_IN_DEGREE); + + canvas->DrawPath(paint); + } + + void CanvasView::UIKitCanvasTestDrawPath028() + { + if (scrollview_ == nullptr) { + return; + } + CreateTitleLabel("创建两条路径,只绘制后一条 "); + UICanvas* canvas = CreateCanvas(); + + Paint paint; + canvas->BeginPath(); + canvas->MoveTo({ START1_X, START1_Y }); + canvas->ArcTo({ CENTER_X, CENTER_Y }, RADIUS, START_ANGLE, START_ANGLE + CIRCLE_IN_DEGREE); + + canvas->BeginPath(); + canvas->MoveTo({ START2_X, START2_Y }); + canvas->ArcTo({ CENTER_X + CENTER_X, CENTER_Y }, RADIUS, END_ANGLE, START_ANGLE + CIRCLE_IN_DEGREE); + + canvas->DrawPath(paint); + } + + void CanvasView::UIKitCanvasTestDrawPath029() + { + if (scrollview_ == nullptr) { + return; + } + CreateTitleLabel("绘制两条不同样式的路径 "); + UICanvas* canvas = CreateCanvas(); + + Paint paint; + canvas->BeginPath(); + canvas->MoveTo({ START1_X, START1_Y }); + canvas->ArcTo({ CENTER_X, CENTER_Y }, RADIUS, START_ANGLE, START_ANGLE + CIRCLE_IN_DEGREE); + canvas->DrawPath(paint); + + canvas->BeginPath(); + canvas->MoveTo({ START2_X, START2_Y }); + canvas->ArcTo({ CENTER_X + CENTER_X, CENTER_Y }, RADIUS, END_ANGLE, START_ANGLE + CIRCLE_IN_DEGREE); + paint.SetStrokeColor(Color::Blue()); + canvas->DrawPath(paint); + } + + void CanvasView::UIKitCanvasTestDrawPath030() + { + if (scrollview_ == nullptr) { + return; + } + CreateTitleLabel("同一条路径绘制100遍 "); + UICanvas* canvas = CreateCanvas(); + + Paint paint; + canvas->BeginPath(); + canvas->MoveTo({ START1_X, START1_Y }); + canvas->LineTo({ LINE1_X, LINE1_Y }); + canvas->ArcTo({ CENTER_X, CENTER_Y }, RADIUS, START_ANGLE, START_ANGLE + CIRCLE_IN_DEGREE); + canvas->AddRect({ RECT_X, RECT_Y }, RECT_HEIGHT, RECT_WIDTH); + for (uint8_t i = 0; i < 100; i++) { // 100: number of times for drawing loops + canvas->DrawPath(paint); + } + } + + void CanvasView::UIKitCanvasTestDrawPath031() + { + if (scrollview_ == nullptr) { + return; + } + CreateTitleLabel("绘制直线超出canvas范围"); + UICanvas* canvas = CreateCanvas(); + + Paint paint; + canvas->BeginPath(); + canvas->MoveTo({ START1_X, START1_Y }); + canvas->LineTo({ LINE1_X + HORIZONTAL_RESOLUTION, LINE1_Y }); + canvas->LineTo({ LINE2_X, LINE2_Y }); + canvas->DrawPath(paint); + } + + void CanvasView::UIKitCanvasTestDrawPath032() + { + if (scrollview_ == nullptr) { + return; + } + CreateTitleLabel("绘制直线传入临界值 "); + UICanvas* canvas = CreateCanvas(); + + Paint paint; + canvas->BeginPath(); + canvas->MoveTo({ INT16_MAX, INT16_MAX }); + canvas->LineTo({ 0, 0 }); + + canvas->MoveTo({ 0, 0 }); + canvas->LineTo({ INT16_MAX, INT16_MAX }); + + canvas->MoveTo({ INT16_MIN, INT16_MIN }); + canvas->LineTo({ 0, 0 }); + + canvas->MoveTo({ 0, 0 }); + canvas->LineTo({ INT16_MIN, INT16_MIN }); + canvas->DrawPath(paint); + } + + + void CanvasView::UIKitCanvasTestDrawPath033() + { + if (scrollview_ == nullptr) { + return; + } + + CreateTitleLabel("绘制arc传入临界值 "); + UICanvas* canvas = CreateCanvas(); + + Paint paint; + canvas->BeginPath(); + canvas->ArcTo({ INT16_MAX, INT16_MAX }, RADIUS, START_ANGLE, END_ANGLE); + canvas->DrawPath(paint); + + canvas->BeginPath(); + canvas->ArcTo({ INT16_MIN, INT16_MIN }, RADIUS, START_ANGLE, END_ANGLE); + paint.SetStrokeColor(Color::Red()); + canvas->DrawPath(paint); + + canvas->BeginPath(); + canvas->ArcTo({ CENTER_X, CENTER_Y }, UINT16_MAX, START_ANGLE, END_ANGLE); + paint.SetStrokeColor(Color::Yellow()); + canvas->DrawPath(paint); + + canvas->BeginPath(); + canvas->ArcTo({ CENTER_X + CENTER_X, CENTER_Y }, RADIUS, INT16_MIN, INT16_MAX); + paint.SetStrokeColor(Color::Blue()); + canvas->DrawPath(paint); + } + + void CanvasView::UIKitCanvasTestDrawPath034() + { + if (scrollview_ == nullptr) { + return; + } + + CreateTitleLabel("绘制rect传入临界值 "); + UICanvas* canvas = CreateCanvas(); + + Paint paint; + canvas->BeginPath(); + canvas->AddRect({ INT16_MAX, INT16_MAX }, RECT_HEIGHT, RECT_WIDTH); + canvas->DrawPath(paint); + + canvas->BeginPath(); + canvas->AddRect({ RECT_X, RECT_Y }, INT16_MAX, INT16_MAX); + paint.SetStrokeColor(Color::Red()); + canvas->DrawPath(paint); + } +} // namespace OHOS \ No newline at end of file -- 2.17.1