--- /dev/null
+/*
+ * 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<CanvasPresenter>::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<CanvasPresenter>::OnSetUpView();
+ Draw();
+ }
+
+ void CanvasView::OnTearDownView() {
+ View<CanvasPresenter>::OnTearDownView();
+ return;
+ }
+
+ void CanvasView::OnStop() {
+ View<CanvasPresenter>::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