xref: /aosp_15_r20/external/skia/docs/examples/Canvas_drawPath.cpp (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 // Copyright 2019 Google LLC.
2 // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
3 #include "tools/fiddle/examples.h"
4 REG_FIDDLE(Canvas_drawPath, 256, 256, false, 0) {
draw(SkCanvas * canvas)5 void draw(SkCanvas* canvas) {
6     SkPath path;
7     path.moveTo(20, 20);
8     path.quadTo(60, 20, 60, 60);
9     path.close();
10     path.moveTo(60, 20);
11     path.quadTo(60, 60, 20, 60);
12     SkPaint paint;
13     paint.setStrokeWidth(10);
14     paint.setAntiAlias(true);
15     paint.setStyle(SkPaint::kStroke_Style);
16     for (auto join: { SkPaint::kBevel_Join, SkPaint::kRound_Join, SkPaint::kMiter_Join } ) {
17         paint.setStrokeJoin(join);
18         for (auto cap: { SkPaint::kButt_Cap, SkPaint::kSquare_Cap, SkPaint::kRound_Cap  } ) {
19             paint.setStrokeCap(cap);
20             canvas->drawPath(path, paint);
21             canvas->translate(80, 0);
22         }
23         canvas->translate(-240, 60);
24     }
25     paint.setStyle(SkPaint::kFill_Style);
26     for (auto fill : { SkPathFillType::kWinding,
27                        SkPathFillType::kEvenOdd,
28                        SkPathFillType::kInverseWinding } ) {
29         path.setFillType(fill);
30         canvas->save();
31         canvas->clipRect({0, 10, 80, 70});
32         canvas->drawPath(path, paint);
33         canvas->restore();
34         canvas->translate(80, 0);
35     }
36 }
37 }  // END FIDDLE
38