xref: /aosp_15_r20/external/skia/docs/examples/Canvas_drawRoundRect.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_drawRoundRect, 256, 256, false, 0) {
draw(SkCanvas * canvas)5 void draw(SkCanvas* canvas) {
6     SkVector radii[] = { {0, 20}, {10, 10}, {10, 20}, {10, 40} };
7     SkPaint paint;
8     paint.setStrokeWidth(15);
9     paint.setStrokeJoin(SkPaint::kRound_Join);
10     paint.setAntiAlias(true);
11     for (auto style : { SkPaint::kStroke_Style, SkPaint::kFill_Style  } ) {
12         paint.setStyle(style );
13         for (size_t i = 0; i < std::size(radii); ++i) {
14            canvas->drawRoundRect({10, 10, 60, 40}, radii[i].fX, radii[i].fY, paint);
15            canvas->translate(0, 60);
16         }
17         canvas->translate(80, -240);
18     }
19 }
20 }  // END FIDDLE
21