blob: 49654983daf0bacb353ea2e5630e9bfd187b8bea [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 */
reed@android.comba974cc2009-05-22 13:48:35 +00007#include "SampleCode.h"
robertphillips@google.comb7061172013-09-06 14:16:12 +00008#include "SkBlurMask.h"
reed@android.comba974cc2009-05-22 13:48:35 +00009#include "SkBlurMaskFilter.h"
robertphillips@google.comb7061172013-09-06 14:16:12 +000010#include "SkCanvas.h"
reed@android.comba974cc2009-05-22 13:48:35 +000011#include "SkColorMatrixFilter.h"
12#include "SkDiscretePathEffect.h"
Ben Wagner339b84e2017-11-10 16:24:50 -050013#include "SkEmbossMaskFilter.h"
reed@android.comba974cc2009-05-22 13:48:35 +000014#include "SkGradientShader.h"
robertphillips@google.comb7061172013-09-06 14:16:12 +000015#include "SkPaint.h"
16#include "SkView.h"
17
reed@android.comba974cc2009-05-22 13:48:35 +000018
19//#define COLOR 0xFFFF8844
20#define COLOR 0xFF888888
21
sugoi@google.com93c7ee32013-03-12 14:36:57 +000022static void paint_proc0(SkPaint*) {
reed@android.comba974cc2009-05-22 13:48:35 +000023}
24
25static void paint_proc1(SkPaint* paint) {
reedefdfd512016-04-04 10:02:58 -070026 paint->setMaskFilter(SkBlurMaskFilter::Make(
commit-bot@chromium.orge3964552014-04-28 16:25:35 +000027 kNormal_SkBlurStyle,
reedefdfd512016-04-04 10:02:58 -070028 SkBlurMask::ConvertRadiusToSigma(2)));
reed@android.comba974cc2009-05-22 13:48:35 +000029}
30
31static void paint_proc2(SkPaint* paint) {
Ben Wagner339b84e2017-11-10 16:24:50 -050032 paint->setMaskFilter(SkEmbossMaskFilter::Make(
33 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(1)),
34 { { SK_Scalar1, SK_Scalar1, SK_Scalar1 }, 0, 64, 16 }));
reed@android.comba974cc2009-05-22 13:48:35 +000035}
36
37static void paint_proc3(SkPaint* paint) {
38 SkColor colors[] = { SK_ColorRED, COLOR, SK_ColorBLUE };
senorblanco@chromium.org64cc5792011-05-19 19:58:58 +000039 SkPoint pts[] = { { 3, 0 }, { 7, 5 } };
reed8a21c9f2016-03-08 18:50:00 -080040 paint->setShader(SkGradientShader::MakeLinear(pts, colors, nullptr, SK_ARRAY_COUNT(colors),
41 SkShader::kMirror_TileMode));
reed@android.comba974cc2009-05-22 13:48:35 +000042}
43
44static void paint_proc5(SkPaint* paint) {
45 paint_proc3(paint);
46 paint_proc2(paint);
47}
48
49typedef void (*PaintProc)(SkPaint*);
50const PaintProc gPaintProcs[] = {
51 paint_proc0,
52 paint_proc1,
53 paint_proc2,
54 paint_proc3,
55 paint_proc5,
56};
57
58///////////////////////////////////////////////////////////////////////////////
59
mike@reedtribe.org5fd92432011-05-05 01:59:48 +000060class EffectsView : public SampleView {
reed@android.comba974cc2009-05-22 13:48:35 +000061public:
62 SkPath fPath;
63 SkPaint fPaint[SK_ARRAY_COUNT(gPaintProcs)];
64
rmistry@google.comae933ce2012-08-23 18:19:56 +000065 EffectsView() {
reed@android.comba974cc2009-05-22 13:48:35 +000066 size_t i;
67 const float pts[] = {
68 0, 0,
69 10, 0,
70 10, 5,
71 20, -5,
72 10, -15,
73 10, -10,
74 0, -10
75 };
76 fPath.moveTo(pts[0], pts[1]);
77 for (i = 2; i < SK_ARRAY_COUNT(pts); i += 2) {
78 fPath.lineTo(pts[i], pts[i+1]);
79 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000080
reed@android.comba974cc2009-05-22 13:48:35 +000081 for (i = 0; i < SK_ARRAY_COUNT(gPaintProcs); i++) {
82 fPaint[i].setAntiAlias(true);
83 fPaint[i].setColor(COLOR);
84 gPaintProcs[i](&fPaint[i]);
85 }
reed@android.com7d970c72010-04-22 16:07:49 +000086
reed@android.com7d970c72010-04-22 16:07:49 +000087 SkColorMatrix cm;
88 cm.setRotate(SkColorMatrix::kG_Axis, 180);
89 cm.setIdentity();
rmistry@google.comae933ce2012-08-23 18:19:56 +000090
mike@reedtribe.org5fd92432011-05-05 01:59:48 +000091 this->setBGColor(0xFFDDDDDD);
reed@android.comba974cc2009-05-22 13:48:35 +000092 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000093
reed@android.comba974cc2009-05-22 13:48:35 +000094protected:
95 // overrides from SkEventSink
96 virtual bool onQuery(SkEvent* evt) {
97 if (SampleCode::TitleQ(*evt)) {
98 SampleCode::TitleR(evt, "Effects");
99 return true;
100 }
101 return this->INHERITED::onQuery(evt);
102 }
rmistry@google.comae933ce2012-08-23 18:19:56 +0000103
mike@reedtribe.org5fd92432011-05-05 01:59:48 +0000104 virtual void onDrawContent(SkCanvas* canvas) {
reed@android.comba974cc2009-05-22 13:48:35 +0000105 canvas->scale(3, 3);
106 canvas->translate(10, 30);
107 for (size_t i = 0; i < SK_ARRAY_COUNT(fPaint); i++) {
108 canvas->drawPath(fPath, fPaint[i]);
109 canvas->translate(32, 0);
110 }
111 }
rmistry@google.comae933ce2012-08-23 18:19:56 +0000112
reed@android.comba974cc2009-05-22 13:48:35 +0000113private:
mike@reedtribe.org5fd92432011-05-05 01:59:48 +0000114 typedef SampleView INHERITED;
reed@android.comba974cc2009-05-22 13:48:35 +0000115};
116
117///////////////////////////////////////////////////////////////////////////////
118
119static SkView* MyFactory() { return new EffectsView; }
120static SkViewRegister reg(MyFactory);