1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "arcofzorro.h"
17
18 #include <native_drawing/drawing_color.h>
19 #include <native_drawing/drawing_brush.h>
20 #include <native_drawing/drawing_matrix.h>
21 #include <native_drawing/drawing_path.h>
22 #include <native_drawing/drawing_pen.h>
23 #include <native_drawing/drawing_round_rect.h>
24 #include <native_drawing/drawing_round_rect.h>
25 #include <native_drawing/drawing_shader_effect.h>
26 #include <native_drawing/drawing_point.h>
27
28 #include "test_common.h"
29 #include "common/log_common.h"
30
ArcOfZorro()31 ArcOfZorro::ArcOfZorro()
32 {
33 // file gm/arcofzorro.cpp
34 bitmapWidth_ = 1000; // width is 1000
35 bitmapHeight_ = 1000; // height is 1000
36 fileName_ = "arcofzorro";
37 }
38
~ArcOfZorro()39 ArcOfZorro::~ArcOfZorro() {}
40
OnTestFunction(OH_Drawing_Canvas * canvas)41 void ArcOfZorro::OnTestFunction(OH_Drawing_Canvas *canvas)
42 {
43 // 用例名: arcofzorro 测试 OH_Drawing_CanvasDrawArc
44 // 迁移基于源码arcofzorro->arcofzorro
45 DRAWING_LOGI("ArcOfZorro::OnTestFunction start");
46 // 使用指定颜色设置清空画布底色
47 OH_Drawing_CanvasClear(canvas, 0xFFCCCCCC);
48 // 创建一个矩形对象
49 TestRend rand;
50 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(x, y, x + w, y + h);
51 // 创建画笔pen对象
52 OH_Drawing_Pen *pen = OH_Drawing_PenCreate();
53 OH_Drawing_PenSetWidth(pen, 35); // stroke width is 35
54 for (float arc = 134.0f; arc < 136.0f; arc += 0.01f) {
55 DRAWING_LOGI("ArcOfZorro::arc");
56 uint32_t color = rand.nextU();
57 color |= 0xff000000;
58 OH_Drawing_PenSetColor(pen, color);
59 OH_Drawing_CanvasSave(canvas);
60 OH_Drawing_CanvasTranslate(canvas, xOffset, yOffset);
61 OH_Drawing_CanvasAttachPen(canvas, pen);
62 OH_Drawing_CanvasDrawArc(canvas, rect, 0, arc);
63 OH_Drawing_CanvasRestore(canvas);
64
65 switch (direction) {
66 case 0:
67 DRAWING_LOGI("ArcOfZorro::OnTestFunction direction0");
68 xOffset += 10; // 10 count
69 if (xOffset >= 700) { // 700 max
70 direction = 1; // direction 1
71 }
72 break;
73 case 1: // 1 case
74 DRAWING_LOGI("ArcOfZorro::OnTestFunction direction1");
75 xOffset -= 10; // 10 count
76 yOffset += 10; // 10 count
77 if (xOffset < 50) { // 50 max
78 direction = 2; // direction 2
79 }
80 break;
81 case 2: // 2 case
82 DRAWING_LOGI("ArcOfZorro::OnTestFunction direction2");
83 xOffset += 10; // 10 count
84 break;
85 default:
86 DRAWING_LOGI("ArcOfZorro::OnTestFunction direction3");
87 break;
88 }
89 }
90 DRAWING_LOGI("ArcOfZorro::OnTestFunction end");
91 OH_Drawing_CanvasDetachPen(canvas);
92 OH_Drawing_RectDestroy(rect);
93 OH_Drawing_PenDestroy(pen);
94 }
95