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(Paint_setStyle, 256, 256, false, 0) {
draw(SkCanvas * canvas)5 void draw(SkCanvas* canvas) {
6 SkPaint paint;
7 paint.setStrokeWidth(5);
8 SkRegion region;
9 region.op({140, 10, 160, 30}, SkRegion::kUnion_Op);
10 region.op({170, 40, 190, 60}, SkRegion::kUnion_Op);
11 SkBitmap bitmap;
12 bitmap.setInfo(SkImageInfo::MakeA8(50, 50), 50);
13 uint8_t pixels[50][50];
14 for (int x = 0; x < 50; ++x) {
15 for (int y = 0; y < 50; ++y) {
16 pixels[y][x] = (x + y) % 5 ? 0xFF : 0x00;
17 }
18 }
19 bitmap.setPixels(pixels);
20 for (auto style : { SkPaint::kFill_Style,
21 SkPaint::kStroke_Style,
22 SkPaint::kStrokeAndFill_Style }) {
23 paint.setStyle(style);
24 canvas->drawLine(10, 10, 60, 60, paint);
25 canvas->drawRect({80, 10, 130, 60}, paint);
26 canvas->drawRegion(region, paint);
27 canvas->drawImage(bitmap.asImage(), 200, 10, SkSamplingOptions(), &paint);
28 canvas->translate(0, 80);
29 }
30 }
31 } // END FIDDLE
32