blob: d890232aaf19523a5ec8189ed0ab159c4949083f [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"
robertphillips@google.comb7061172013-09-06 14:16:12 +00009#include "SkCanvas.h"
reed@android.comba974cc2009-05-22 13:48:35 +000010#include "SkColorMatrixFilter.h"
11#include "SkDiscretePathEffect.h"
Ben Wagner339b84e2017-11-10 16:24:50 -050012#include "SkEmbossMaskFilter.h"
reed@android.comba974cc2009-05-22 13:48:35 +000013#include "SkGradientShader.h"
robertphillips@google.comb7061172013-09-06 14:16:12 +000014#include "SkPaint.h"
15#include "SkView.h"
16
reed@android.comba974cc2009-05-22 13:48:35 +000017
18//#define COLOR 0xFFFF8844
19#define COLOR 0xFF888888
20
sugoi@google.com93c7ee32013-03-12 14:36:57 +000021static void paint_proc0(SkPaint*) {
reed@android.comba974cc2009-05-22 13:48:35 +000022}
23
24static void paint_proc1(SkPaint* paint) {
Mike Reed1be1f8d2018-03-14 13:01:17 -040025 paint->setMaskFilter(SkMaskFilter::MakeBlur(
commit-bot@chromium.orge3964552014-04-28 16:25:35 +000026 kNormal_SkBlurStyle,
reedefdfd512016-04-04 10:02:58 -070027 SkBlurMask::ConvertRadiusToSigma(2)));
reed@android.comba974cc2009-05-22 13:48:35 +000028}
29
30static void paint_proc2(SkPaint* paint) {
Ben Wagner339b84e2017-11-10 16:24:50 -050031 paint->setMaskFilter(SkEmbossMaskFilter::Make(
32 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(1)),
33 { { SK_Scalar1, SK_Scalar1, SK_Scalar1 }, 0, 64, 16 }));
reed@android.comba974cc2009-05-22 13:48:35 +000034}
35
36static void paint_proc3(SkPaint* paint) {
37 SkColor colors[] = { SK_ColorRED, COLOR, SK_ColorBLUE };
senorblanco@chromium.org64cc5792011-05-19 19:58:58 +000038 SkPoint pts[] = { { 3, 0 }, { 7, 5 } };
reed8a21c9f2016-03-08 18:50:00 -080039 paint->setShader(SkGradientShader::MakeLinear(pts, colors, nullptr, SK_ARRAY_COUNT(colors),
40 SkShader::kMirror_TileMode));
reed@android.comba974cc2009-05-22 13:48:35 +000041}
42
43static void paint_proc5(SkPaint* paint) {
44 paint_proc3(paint);
45 paint_proc2(paint);
46}
47
48typedef void (*PaintProc)(SkPaint*);
49const PaintProc gPaintProcs[] = {
50 paint_proc0,
51 paint_proc1,
52 paint_proc2,
53 paint_proc3,
54 paint_proc5,
55};
56
57///////////////////////////////////////////////////////////////////////////////
58
mike@reedtribe.org5fd92432011-05-05 01:59:48 +000059class EffectsView : public SampleView {
reed@android.comba974cc2009-05-22 13:48:35 +000060public:
61 SkPath fPath;
62 SkPaint fPaint[SK_ARRAY_COUNT(gPaintProcs)];
63
rmistry@google.comae933ce2012-08-23 18:19:56 +000064 EffectsView() {
reed@android.comba974cc2009-05-22 13:48:35 +000065 size_t i;
66 const float pts[] = {
67 0, 0,
68 10, 0,
69 10, 5,
70 20, -5,
71 10, -15,
72 10, -10,
73 0, -10
74 };
75 fPath.moveTo(pts[0], pts[1]);
76 for (i = 2; i < SK_ARRAY_COUNT(pts); i += 2) {
77 fPath.lineTo(pts[i], pts[i+1]);
78 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000079
reed@android.comba974cc2009-05-22 13:48:35 +000080 for (i = 0; i < SK_ARRAY_COUNT(gPaintProcs); i++) {
81 fPaint[i].setAntiAlias(true);
82 fPaint[i].setColor(COLOR);
83 gPaintProcs[i](&fPaint[i]);
84 }
reed@android.com7d970c72010-04-22 16:07:49 +000085
reed@android.com7d970c72010-04-22 16:07:49 +000086 SkColorMatrix cm;
87 cm.setRotate(SkColorMatrix::kG_Axis, 180);
88 cm.setIdentity();
rmistry@google.comae933ce2012-08-23 18:19:56 +000089
mike@reedtribe.org5fd92432011-05-05 01:59:48 +000090 this->setBGColor(0xFFDDDDDD);
reed@android.comba974cc2009-05-22 13:48:35 +000091 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000092
reed@android.comba974cc2009-05-22 13:48:35 +000093protected:
94 // overrides from SkEventSink
95 virtual bool onQuery(SkEvent* evt) {
96 if (SampleCode::TitleQ(*evt)) {
97 SampleCode::TitleR(evt, "Effects");
98 return true;
99 }
100 return this->INHERITED::onQuery(evt);
101 }
rmistry@google.comae933ce2012-08-23 18:19:56 +0000102
mike@reedtribe.org5fd92432011-05-05 01:59:48 +0000103 virtual void onDrawContent(SkCanvas* canvas) {
reed@android.comba974cc2009-05-22 13:48:35 +0000104 canvas->scale(3, 3);
105 canvas->translate(10, 30);
106 for (size_t i = 0; i < SK_ARRAY_COUNT(fPaint); i++) {
107 canvas->drawPath(fPath, fPaint[i]);
108 canvas->translate(32, 0);
109 }
110 }
rmistry@google.comae933ce2012-08-23 18:19:56 +0000111
reed@android.comba974cc2009-05-22 13:48:35 +0000112private:
mike@reedtribe.org5fd92432011-05-05 01:59:48 +0000113 typedef SampleView INHERITED;
reed@android.comba974cc2009-05-22 13:48:35 +0000114};
115
116///////////////////////////////////////////////////////////////////////////////
117
118static SkView* MyFactory() { return new EffectsView; }
119static SkViewRegister reg(MyFactory);