xref: /aosp_15_r20/external/skia/docs/examples/Path_Iter_setPath.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(Path_Iter_setPath, 256, 256, true, 0) {
draw(SkCanvas * canvas)5 void draw(SkCanvas* canvas) {
6     auto debugster = [](const char* prefix, SkPath::Iter& iter) -> void {
7         SkDebugf("%s:\n", prefix);
8         const char* verbStr[] =  { "Move", "Line", "Quad", "Conic", "Cubic", "Close", "Done" };
9         const int pointCount[] = {     1 ,     2 ,     3 ,      3 ,      4 ,      1 ,     0  };
10         SkPath::Verb verb;
11         do {
12            SkPoint points[4];
13            verb = iter.next(points);
14            SkDebugf("k%s_Verb ", verbStr[(int) verb]);
15            for (int i = 0; i < pointCount[(int) verb]; ++i) {
16                 SkDebugf("{%g, %g}, ", points[i].fX, points[i].fY);
17            }
18            if (SkPath::kConic_Verb == verb) {
19                SkDebugf("weight = %g", iter.conicWeight());
20            }
21            SkDebugf("\n");
22         } while (SkPath::kDone_Verb != verb);
23         SkDebugf("\n");
24     };
25     SkPath path;
26     path.quadTo(10, 20, 30, 40);
27     SkPath::Iter iter(path, false);
28     debugster("quad open", iter);
29     SkPath path2;
30     path2.conicTo(1, 2, 3, 4, .5f);
31     iter.setPath(path2, true);
32     debugster("conic closed", iter);
33 }
34 }  // END FIDDLE
35