blob: c380d4d8766a6fbc180c294c1ab932cd67b59b8e [file] [log] [blame]
Hal Canary87515122019-03-15 14:22:51 -04001// 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.
Mike Kleinc0bd9f92019-04-23 12:05:21 -05003#include "tools/fiddle/examples.h"
Hal Canarya7181e7c2019-03-18 16:06:34 -04004REG_FIDDLE(Paint_setStyle, 256, 256, false, 0) {
Hal Canary87515122019-03-15 14:22:51 -04005void draw(SkCanvas* canvas) {
6 SkPaint paint;
7 paint.setStrokeWidth(5);
8 SkRegion region;
Mike Reed92b33352019-08-24 19:39:13 -04009 region.op({140, 10, 160, 30}, SkRegion::kUnion_Op);
10 region.op({170, 40, 190, 60}, SkRegion::kUnion_Op);
Hal Canary87515122019-03-15 14:22:51 -040011 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);
Mike Reedb339d052021-01-28 11:20:41 -050027 canvas->drawImage(bitmap.asImage(), 200, 10, SkSamplingOptions(), &paint);
Hal Canary87515122019-03-15 14:22:51 -040028 canvas->translate(0, 80);
29 }
30}
31} // END FIDDLE