xref: /aosp_15_r20/external/skia/docs/examples/IPoint_subtractfrom_operator.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(IPoint_subtractfrom_operator, 256, 64, false, 0) {
draw(SkCanvas * canvas)5 void draw(SkCanvas* canvas) {
6     auto draw_lines = [=](const SkIPoint pts[], size_t count, SkPaint& paint) -> void {
7         for (size_t i = 0; i < count - 1; ++i) {
8             SkPoint p0, p1;
9             p0.iset(pts[i]);
10             p1.iset(pts[i + 1]);
11             canvas->drawLine(p0, p1, paint);
12         }
13     };
14     SkIPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 } };
15     SkPaint paint;
16     paint.setAntiAlias(true);
17     paint.setStyle(SkPaint::kStroke_Style);
18     canvas->scale(30, 15);
19     draw_lines(points, std::size(points), paint);
20     points[1] -= {1, 1};
21     points[2] -= {-1, -1};
22     paint.setColor(SK_ColorRED);
23     draw_lines(points, std::size(points), paint);
24 }
25 }  // END FIDDLE
26