| 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(Modulate, 256, 256, false, 0) { |
| 5 |
void draw(SkCanvas* canvas) { |
| 6 |
auto drawSquare = [=](int dx, int dy, SkBlendMode mode, const char* label) -> void { |
| 7 |
const SkColor4f colors[] = { SkColors::kBlack, SkColors::kWhite }; |
| 8 |
const SkPoint horz[] = { { 0, 0 }, { 128, 0 } }; |
| 9 |
SkPaint paint; |
| 10 |
paint.setShader(SkShaders::LinearGradient(horz, {{colors, {}, SkTileMode::kClamp}, {}})); |
| 11 |
paint.setBlendMode(mode); |
| 12 |
canvas->translate(dx, dy); |
| 13 |
canvas->drawRect({0, 0, 128, 128}, paint); |
| 14 |
paint.setBlendMode(SkBlendMode::kXor); |
| 15 |
SkFont font = SkFont(fontMgr->matchFamilyStyle(nullptr, {})); |
| 16 |
canvas->drawString(label, 40, 100, font, paint); |
| 17 |
}; |
| 18 |
drawSquare(0, 0, SkBlendMode::kSrc, "destination"); |
| 19 |
drawSquare(128, 0, SkBlendMode::kSrc, ""); |
| 20 |
drawSquare(0, 128, SkBlendMode::kSrc, ""); |
| 21 |
canvas->translate(-128, -128); |
| 22 |
canvas->rotate(90, 0, 128); |
| 23 |
drawSquare(0, 0, SkBlendMode::kSrc, "source"); |
| 24 |
drawSquare(0, -128, SkBlendMode::kModulate, "modulate"); |
| 25 |
drawSquare(-128, 0, SkBlendMode::kMultiply, "multiply"); |
| 26 |
} |
| 27 |
} // END FIDDLE |