blob: 1169725fa0321e6e57f9f37c9ccc9b2b29b52604 [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"
9#include "SkCanvas.h"
10#include "SkPaint.h"
reed@android.comba974cc2009-05-22 13:48:35 +000011#include "SkView.h"
12
13#include "SkBlurMaskFilter.h"
14#include "SkColorMatrixFilter.h"
15#include "SkDiscretePathEffect.h"
16#include "SkGradientShader.h"
17
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) {
25 paint->setMaskFilter(SkBlurMaskFilter::Create(2,
26 SkBlurMaskFilter::kNormal_BlurStyle))->unref();
27}
28
29static void paint_proc2(SkPaint* paint) {
30 SkScalar dir[3] = { 1, 1, 1};
31 paint->setMaskFilter(
reed@google.com261b8e22011-04-14 17:53:24 +000032 SkBlurMaskFilter::CreateEmboss(dir, 0.1f, 0.05f, 1))->unref();
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 } };
reed@android.comba974cc2009-05-22 13:48:35 +000038 paint->setShader(SkGradientShader::CreateLinear(pts, colors, NULL, SK_ARRAY_COUNT(colors),
39 SkShader::kMirror_TileMode))->unref();
40}
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
mike@reedtribe.org5fd92432011-05-05 01:59:48 +000058class EffectsView : public SampleView {
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
reed@android.com7d970c72010-04-22 16:07:49 +000085 SkColorMatrix cm;
86 cm.setRotate(SkColorMatrix::kG_Axis, 180);
87 cm.setIdentity();
rmistry@google.comae933ce2012-08-23 18:19:56 +000088
mike@reedtribe.org5fd92432011-05-05 01:59:48 +000089 this->setBGColor(0xFFDDDDDD);
reed@android.comba974cc2009-05-22 13:48:35 +000090 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000091
reed@android.comba974cc2009-05-22 13:48:35 +000092protected:
93 // overrides from SkEventSink
94 virtual bool onQuery(SkEvent* evt) {
95 if (SampleCode::TitleQ(*evt)) {
96 SampleCode::TitleR(evt, "Effects");
97 return true;
98 }
99 return this->INHERITED::onQuery(evt);
100 }
rmistry@google.comae933ce2012-08-23 18:19:56 +0000101
mike@reedtribe.org5fd92432011-05-05 01:59:48 +0000102 virtual void onDrawContent(SkCanvas* canvas) {
reed@android.comba974cc2009-05-22 13:48:35 +0000103 canvas->scale(3, 3);
104 canvas->translate(10, 30);
105 for (size_t i = 0; i < SK_ARRAY_COUNT(fPaint); i++) {
106 canvas->drawPath(fPath, fPaint[i]);
107 canvas->translate(32, 0);
108 }
109 }
rmistry@google.comae933ce2012-08-23 18:19:56 +0000110
reed@android.comba974cc2009-05-22 13:48:35 +0000111private:
mike@reedtribe.org5fd92432011-05-05 01:59:48 +0000112 typedef SampleView INHERITED;
reed@android.comba974cc2009-05-22 13:48:35 +0000113};
114
115///////////////////////////////////////////////////////////////////////////////
116
117static SkView* MyFactory() { return new EffectsView; }
118static SkViewRegister reg(MyFactory);