blob: 01a63adb75d4b1004c92eaecefd5f773fa7929bf [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
2/*
3 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
reed@android.comba974cc2009-05-22 13:48:35 +00008#include "SampleCode.h"
robertphillips@google.comb7061172013-09-06 14:16:12 +00009#include "SkBlurMask.h"
reed@android.comba974cc2009-05-22 13:48:35 +000010#include "SkBlurMaskFilter.h"
robertphillips@google.comb7061172013-09-06 14:16:12 +000011#include "SkCanvas.h"
reed@android.comba974cc2009-05-22 13:48:35 +000012#include "SkColorMatrixFilter.h"
13#include "SkDiscretePathEffect.h"
14#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) {
robertphillips@google.comb7061172013-09-06 14:16:12 +000026 paint->setMaskFilter(SkBlurMaskFilter::Create(
commit-bot@chromium.orge3964552014-04-28 16:25:35 +000027 kNormal_SkBlurStyle,
robertphillips@google.comb7061172013-09-06 14:16:12 +000028 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(2))))->unref();
reed@android.comba974cc2009-05-22 13:48:35 +000029}
30
31static void paint_proc2(SkPaint* paint) {
32 SkScalar dir[3] = { 1, 1, 1};
33 paint->setMaskFilter(
skia.committer@gmail.comb3ec29d2013-09-07 07:01:16 +000034 SkBlurMaskFilter::CreateEmboss(SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(1)),
robertphillips@google.comb7061172013-09-06 14:16:12 +000035 dir,
commit-bot@chromium.org4b413c82013-11-25 19:44:07 +000036 0.1f,
37 0.05f))->unref();
reed@android.comba974cc2009-05-22 13:48:35 +000038}
39
40static void paint_proc3(SkPaint* paint) {
41 SkColor colors[] = { SK_ColorRED, COLOR, SK_ColorBLUE };
senorblanco@chromium.org64cc5792011-05-19 19:58:58 +000042 SkPoint pts[] = { { 3, 0 }, { 7, 5 } };
reed@android.comba974cc2009-05-22 13:48:35 +000043 paint->setShader(SkGradientShader::CreateLinear(pts, colors, NULL, SK_ARRAY_COUNT(colors),
44 SkShader::kMirror_TileMode))->unref();
45}
46
47static void paint_proc5(SkPaint* paint) {
48 paint_proc3(paint);
49 paint_proc2(paint);
50}
51
52typedef void (*PaintProc)(SkPaint*);
53const PaintProc gPaintProcs[] = {
54 paint_proc0,
55 paint_proc1,
56 paint_proc2,
57 paint_proc3,
58 paint_proc5,
59};
60
61///////////////////////////////////////////////////////////////////////////////
62
mike@reedtribe.org5fd92432011-05-05 01:59:48 +000063class EffectsView : public SampleView {
reed@android.comba974cc2009-05-22 13:48:35 +000064public:
65 SkPath fPath;
66 SkPaint fPaint[SK_ARRAY_COUNT(gPaintProcs)];
67
rmistry@google.comae933ce2012-08-23 18:19:56 +000068 EffectsView() {
reed@android.comba974cc2009-05-22 13:48:35 +000069 size_t i;
70 const float pts[] = {
71 0, 0,
72 10, 0,
73 10, 5,
74 20, -5,
75 10, -15,
76 10, -10,
77 0, -10
78 };
79 fPath.moveTo(pts[0], pts[1]);
80 for (i = 2; i < SK_ARRAY_COUNT(pts); i += 2) {
81 fPath.lineTo(pts[i], pts[i+1]);
82 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000083
reed@android.comba974cc2009-05-22 13:48:35 +000084 for (i = 0; i < SK_ARRAY_COUNT(gPaintProcs); i++) {
85 fPaint[i].setAntiAlias(true);
86 fPaint[i].setColor(COLOR);
87 gPaintProcs[i](&fPaint[i]);
88 }
reed@android.com7d970c72010-04-22 16:07:49 +000089
reed@android.com7d970c72010-04-22 16:07:49 +000090 SkColorMatrix cm;
91 cm.setRotate(SkColorMatrix::kG_Axis, 180);
92 cm.setIdentity();
rmistry@google.comae933ce2012-08-23 18:19:56 +000093
mike@reedtribe.org5fd92432011-05-05 01:59:48 +000094 this->setBGColor(0xFFDDDDDD);
reed@android.comba974cc2009-05-22 13:48:35 +000095 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000096
reed@android.comba974cc2009-05-22 13:48:35 +000097protected:
98 // overrides from SkEventSink
99 virtual bool onQuery(SkEvent* evt) {
100 if (SampleCode::TitleQ(*evt)) {
101 SampleCode::TitleR(evt, "Effects");
102 return true;
103 }
104 return this->INHERITED::onQuery(evt);
105 }
rmistry@google.comae933ce2012-08-23 18:19:56 +0000106
mike@reedtribe.org5fd92432011-05-05 01:59:48 +0000107 virtual void onDrawContent(SkCanvas* canvas) {
reed@android.comba974cc2009-05-22 13:48:35 +0000108 canvas->scale(3, 3);
109 canvas->translate(10, 30);
110 for (size_t i = 0; i < SK_ARRAY_COUNT(fPaint); i++) {
111 canvas->drawPath(fPath, fPaint[i]);
112 canvas->translate(32, 0);
113 }
114 }
rmistry@google.comae933ce2012-08-23 18:19:56 +0000115
reed@android.comba974cc2009-05-22 13:48:35 +0000116private:
mike@reedtribe.org5fd92432011-05-05 01:59:48 +0000117 typedef SampleView INHERITED;
reed@android.comba974cc2009-05-22 13:48:35 +0000118};
119
120///////////////////////////////////////////////////////////////////////////////
121
122static SkView* MyFactory() { return new EffectsView; }
123static SkViewRegister reg(MyFactory);