2011-07-28 14:26:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/effects/SkColorMatrixFilter.h"
|
|
|
|
#include "include/effects/SkDiscretePathEffect.h"
|
|
|
|
#include "include/effects/SkGradientShader.h"
|
|
|
|
#include "samplecode/Sample.h"
|
|
|
|
#include "src/core/SkBlurMask.h"
|
|
|
|
#include "src/effects/SkEmbossMaskFilter.h"
|
2013-09-06 14:16:12 +00:00
|
|
|
|
2009-05-22 13:48:35 +00:00
|
|
|
|
|
|
|
//#define COLOR 0xFFFF8844
|
|
|
|
#define COLOR 0xFF888888
|
|
|
|
|
2013-03-12 14:36:57 +00:00
|
|
|
static void paint_proc0(SkPaint*) {
|
2009-05-22 13:48:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void paint_proc1(SkPaint* paint) {
|
2018-03-14 17:01:17 +00:00
|
|
|
paint->setMaskFilter(SkMaskFilter::MakeBlur(
|
2014-04-28 16:25:35 +00:00
|
|
|
kNormal_SkBlurStyle,
|
2016-04-04 17:02:58 +00:00
|
|
|
SkBlurMask::ConvertRadiusToSigma(2)));
|
2009-05-22 13:48:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void paint_proc2(SkPaint* paint) {
|
2017-11-10 21:24:50 +00:00
|
|
|
paint->setMaskFilter(SkEmbossMaskFilter::Make(
|
|
|
|
SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(1)),
|
|
|
|
{ { SK_Scalar1, SK_Scalar1, SK_Scalar1 }, 0, 64, 16 }));
|
2009-05-22 13:48:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void paint_proc3(SkPaint* paint) {
|
|
|
|
SkColor colors[] = { SK_ColorRED, COLOR, SK_ColorBLUE };
|
2011-05-19 19:58:58 +00:00
|
|
|
SkPoint pts[] = { { 3, 0 }, { 7, 5 } };
|
2016-03-09 02:50:00 +00:00
|
|
|
paint->setShader(SkGradientShader::MakeLinear(pts, colors, nullptr, SK_ARRAY_COUNT(colors),
|
2019-04-03 14:27:45 +00:00
|
|
|
SkTileMode::kMirror));
|
2009-05-22 13:48:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
class EffectsView : public Sample {
|
2009-05-22 13:48:35 +00:00
|
|
|
public:
|
|
|
|
SkPath fPath;
|
|
|
|
SkPaint fPaint[SK_ARRAY_COUNT(gPaintProcs)];
|
|
|
|
|
2012-08-23 18:19:56 +00:00
|
|
|
EffectsView() {
|
2009-05-22 13:48:35 +00:00
|
|
|
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]);
|
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2009-05-22 13:48:35 +00:00
|
|
|
for (i = 0; i < SK_ARRAY_COUNT(gPaintProcs); i++) {
|
|
|
|
fPaint[i].setAntiAlias(true);
|
|
|
|
fPaint[i].setColor(COLOR);
|
|
|
|
gPaintProcs[i](&fPaint[i]);
|
|
|
|
}
|
2010-04-22 16:07:49 +00:00
|
|
|
|
2011-05-05 01:59:48 +00:00
|
|
|
this->setBGColor(0xFFDDDDDD);
|
2009-05-22 13:48:35 +00:00
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2009-05-22 13:48:35 +00:00
|
|
|
protected:
|
2019-07-03 14:55:44 +00:00
|
|
|
virtual SkString name() { return SkString("Effects"); }
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2011-05-05 01:59:48 +00:00
|
|
|
virtual void onDrawContent(SkCanvas* canvas) {
|
2009-05-22 13:48:35 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2009-05-22 13:48:35 +00:00
|
|
|
private:
|
2018-08-08 15:36:17 +00:00
|
|
|
typedef Sample INHERITED;
|
2009-05-22 13:48:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
DEF_SAMPLE( return new EffectsView(); )
|