Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 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. |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 3 | #include "tools/fiddle/examples.h" |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 4 | // HASH=3fdac2b2f48bd227d2e74234c260bc8e |
Hal Canary | a7181e7c | 2019-03-18 16:06:34 -0400 | [diff] [blame] | 5 | REG_FIDDLE(Modulate, 256, 256, false, 0) { |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 6 | void draw(SkCanvas* canvas) { |
| 7 | auto drawSquare = [=](int dx, int dy, SkBlendMode mode, const char* label) -> void { |
| 8 | const SkColor colors[] = { SK_ColorBLACK, SK_ColorWHITE }; |
| 9 | const SkPoint horz[] = { { 0, 0 }, { 128, 0 } }; |
| 10 | SkPaint paint; |
| 11 | paint.setShader(SkGradientShader::MakeLinear(horz, colors, nullptr, SK_ARRAY_COUNT(colors), |
Mike Reed | fae8fce | 2019-04-03 10:27:45 -0400 | [diff] [blame] | 12 | SkTileMode::kClamp)); |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 13 | paint.setBlendMode(mode); |
| 14 | canvas->translate(dx, dy); |
| 15 | canvas->drawRect({0, 0, 128, 128}, paint); |
| 16 | paint.setBlendMode(SkBlendMode::kXor); |
| 17 | SkFont font; |
| 18 | canvas->drawString(label, 40, 100, font, paint); |
| 19 | }; |
| 20 | drawSquare(0, 0, SkBlendMode::kSrc, "destination"); |
| 21 | drawSquare(128, 0, SkBlendMode::kSrc, ""); |
| 22 | drawSquare(0, 128, SkBlendMode::kSrc, ""); |
| 23 | canvas->translate(-128, -128); |
| 24 | canvas->rotate(90, 0, 128); |
| 25 | drawSquare(0, 0, SkBlendMode::kSrc, "source"); |
| 26 | drawSquare(0, -128, SkBlendMode::kModulate, "modulate"); |
| 27 | drawSquare(-128, 0, SkBlendMode::kMultiply, "multiply"); |
| 28 | } |
| 29 | } // END FIDDLE |