blob: 8325d4a6d28171a5a98504c29c4025619737c01e [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 Canary87515122019-03-15 14:22:51 -04004// HASH=3fdac2b2f48bd227d2e74234c260bc8e
Hal Canarya7181e7c2019-03-18 16:06:34 -04005REG_FIDDLE(Modulate, 256, 256, false, 0) {
Hal Canary87515122019-03-15 14:22:51 -04006void 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 Reedfae8fce2019-04-03 10:27:45 -040012 SkTileMode::kClamp));
Hal Canary87515122019-03-15 14:22:51 -040013 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