forked from revery-ui/esy-skia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SampleEffects.cpp
119 lines (100 loc) · 3.09 KB
/
SampleEffects.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SampleCode.h"
#include "SkBlurMask.h"
#include "SkCanvas.h"
#include "SkColorMatrixFilter.h"
#include "SkDiscretePathEffect.h"
#include "SkEmbossMaskFilter.h"
#include "SkGradientShader.h"
#include "SkPaint.h"
#include "SkView.h"
//#define COLOR 0xFFFF8844
#define COLOR 0xFF888888
static void paint_proc0(SkPaint*) {
}
static void paint_proc1(SkPaint* paint) {
paint->setMaskFilter(SkMaskFilter::MakeBlur(
kNormal_SkBlurStyle,
SkBlurMask::ConvertRadiusToSigma(2)));
}
static void paint_proc2(SkPaint* paint) {
paint->setMaskFilter(SkEmbossMaskFilter::Make(
SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(1)),
{ { SK_Scalar1, SK_Scalar1, SK_Scalar1 }, 0, 64, 16 }));
}
static void paint_proc3(SkPaint* paint) {
SkColor colors[] = { SK_ColorRED, COLOR, SK_ColorBLUE };
SkPoint pts[] = { { 3, 0 }, { 7, 5 } };
paint->setShader(SkGradientShader::MakeLinear(pts, colors, nullptr, SK_ARRAY_COUNT(colors),
SkShader::kMirror_TileMode));
}
static void paint_proc5(SkPaint* paint) {
paint_proc3(paint);
paint_proc2(paint);
}
typedef void (*PaintProc)(SkPaint*);
const PaintProc gPaintProcs[] = {
paint_proc0,
paint_proc1,
paint_proc2,
paint_proc3,
paint_proc5,
};
///////////////////////////////////////////////////////////////////////////////
class EffectsView : public SampleView {
public:
SkPath fPath;
SkPaint fPaint[SK_ARRAY_COUNT(gPaintProcs)];
EffectsView() {
size_t i;
const float pts[] = {
0, 0,
10, 0,
10, 5,
20, -5,
10, -15,
10, -10,
0, -10
};
fPath.moveTo(pts[0], pts[1]);
for (i = 2; i < SK_ARRAY_COUNT(pts); i += 2) {
fPath.lineTo(pts[i], pts[i+1]);
}
for (i = 0; i < SK_ARRAY_COUNT(gPaintProcs); i++) {
fPaint[i].setAntiAlias(true);
fPaint[i].setColor(COLOR);
gPaintProcs[i](&fPaint[i]);
}
SkColorMatrix cm;
cm.setRotate(SkColorMatrix::kG_Axis, 180);
cm.setIdentity();
this->setBGColor(0xFFDDDDDD);
}
protected:
// overrides from SkEventSink
virtual bool onQuery(SkEvent* evt) {
if (SampleCode::TitleQ(*evt)) {
SampleCode::TitleR(evt, "Effects");
return true;
}
return this->INHERITED::onQuery(evt);
}
virtual void onDrawContent(SkCanvas* canvas) {
canvas->scale(3, 3);
canvas->translate(10, 30);
for (size_t i = 0; i < SK_ARRAY_COUNT(fPaint); i++) {
canvas->drawPath(fPath, fPaint[i]);
canvas->translate(32, 0);
}
}
private:
typedef SampleView INHERITED;
};
///////////////////////////////////////////////////////////////////////////////
static SkView* MyFactory() { return new EffectsView; }
static SkViewRegister reg(MyFactory);