blob: 5a49ded3730330a72d722fef2aa859577bbbea7e [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001/*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
Mike Kleinc0bd9f92019-04-23 12:05:21 -05007#include "include/core/SkCanvas.h"
8#include "include/core/SkPaint.h"
9#include "include/effects/SkColorMatrixFilter.h"
10#include "include/effects/SkDiscretePathEffect.h"
11#include "include/effects/SkGradientShader.h"
12#include "samplecode/Sample.h"
13#include "src/core/SkBlurMask.h"
14#include "src/effects/SkEmbossMaskFilter.h"
robertphillips@google.comb7061172013-09-06 14:16:12 +000015
reed@android.comba974cc2009-05-22 13:48:35 +000016
17//#define COLOR 0xFFFF8844
18#define COLOR 0xFF888888
19
sugoi@google.com93c7ee32013-03-12 14:36:57 +000020static void paint_proc0(SkPaint*) {
reed@android.comba974cc2009-05-22 13:48:35 +000021}
22
23static void paint_proc1(SkPaint* paint) {
Mike Reed1be1f8d2018-03-14 13:01:17 -040024 paint->setMaskFilter(SkMaskFilter::MakeBlur(
commit-bot@chromium.orge3964552014-04-28 16:25:35 +000025 kNormal_SkBlurStyle,
reedefdfd512016-04-04 10:02:58 -070026 SkBlurMask::ConvertRadiusToSigma(2)));
reed@android.comba974cc2009-05-22 13:48:35 +000027}
28
29static void paint_proc2(SkPaint* paint) {
Ben Wagner339b84e2017-11-10 16:24:50 -050030 paint->setMaskFilter(SkEmbossMaskFilter::Make(
31 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(1)),
32 { { SK_Scalar1, SK_Scalar1, SK_Scalar1 }, 0, 64, 16 }));
reed@android.comba974cc2009-05-22 13:48:35 +000033}
34
35static void paint_proc3(SkPaint* paint) {
36 SkColor colors[] = { SK_ColorRED, COLOR, SK_ColorBLUE };
senorblanco@chromium.org64cc5792011-05-19 19:58:58 +000037 SkPoint pts[] = { { 3, 0 }, { 7, 5 } };
reed8a21c9f2016-03-08 18:50:00 -080038 paint->setShader(SkGradientShader::MakeLinear(pts, colors, nullptr, SK_ARRAY_COUNT(colors),
Mike Reedfae8fce2019-04-03 10:27:45 -040039 SkTileMode::kMirror));
reed@android.comba974cc2009-05-22 13:48:35 +000040}
41
42static void paint_proc5(SkPaint* paint) {
43 paint_proc3(paint);
44 paint_proc2(paint);
45}
46
47typedef void (*PaintProc)(SkPaint*);
48const PaintProc gPaintProcs[] = {
49 paint_proc0,
50 paint_proc1,
51 paint_proc2,
52 paint_proc3,
53 paint_proc5,
54};
55
56///////////////////////////////////////////////////////////////////////////////
57
Ben Wagnerb2c4ea62018-08-08 11:36:17 -040058class EffectsView : public Sample {
reed@android.comba974cc2009-05-22 13:48:35 +000059public:
60 SkPath fPath;
61 SkPaint fPaint[SK_ARRAY_COUNT(gPaintProcs)];
62
rmistry@google.comae933ce2012-08-23 18:19:56 +000063 EffectsView() {
reed@android.comba974cc2009-05-22 13:48:35 +000064 size_t i;
65 const float pts[] = {
66 0, 0,
67 10, 0,
68 10, 5,
69 20, -5,
70 10, -15,
71 10, -10,
72 0, -10
73 };
74 fPath.moveTo(pts[0], pts[1]);
75 for (i = 2; i < SK_ARRAY_COUNT(pts); i += 2) {
76 fPath.lineTo(pts[i], pts[i+1]);
77 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000078
reed@android.comba974cc2009-05-22 13:48:35 +000079 for (i = 0; i < SK_ARRAY_COUNT(gPaintProcs); i++) {
80 fPaint[i].setAntiAlias(true);
81 fPaint[i].setColor(COLOR);
82 gPaintProcs[i](&fPaint[i]);
83 }
reed@android.com7d970c72010-04-22 16:07:49 +000084
mike@reedtribe.org5fd92432011-05-05 01:59:48 +000085 this->setBGColor(0xFFDDDDDD);
reed@android.comba974cc2009-05-22 13:48:35 +000086 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000087
reed@android.comba974cc2009-05-22 13:48:35 +000088protected:
Brian Salomond0072812020-07-21 17:03:56 -040089 SkString name() override { return SkString("Effects"); }
rmistry@google.comae933ce2012-08-23 18:19:56 +000090
Brian Salomond0072812020-07-21 17:03:56 -040091 void onDrawContent(SkCanvas* canvas) override {
reed@android.comba974cc2009-05-22 13:48:35 +000092 canvas->scale(3, 3);
93 canvas->translate(10, 30);
94 for (size_t i = 0; i < SK_ARRAY_COUNT(fPaint); i++) {
95 canvas->drawPath(fPath, fPaint[i]);
96 canvas->translate(32, 0);
97 }
98 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000099
reed@android.comba974cc2009-05-22 13:48:35 +0000100private:
John Stiles7571f9e2020-09-02 22:42:33 -0400101 using INHERITED = Sample;
reed@android.comba974cc2009-05-22 13:48:35 +0000102};
103
104///////////////////////////////////////////////////////////////////////////////
105
Ben Wagnerb2c4ea62018-08-08 11:36:17 -0400106DEF_SAMPLE( return new EffectsView(); )