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/core/SkVertices.h"
|
|
|
|
#include "include/effects/SkGradientShader.h"
|
|
|
|
#include "samplecode/Sample.h"
|
|
|
|
#include "src/core/SkBlurMask.h"
|
|
|
|
#include "src/core/SkReadBuffer.h"
|
|
|
|
#include "src/core/SkWriteBuffer.h"
|
|
|
|
|
|
|
|
#include "tools/ToolUtils.h"
|
2016-11-23 15:55:18 +00:00
|
|
|
|
2009-10-12 17:02:22 +00:00
|
|
|
#define BG_COLOR 0xFFDDDDDD
|
|
|
|
|
2009-10-06 21:19:18 +00:00
|
|
|
typedef void (*SlideProc)(SkCanvas*);
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/effects/Sk1DPathEffect.h"
|
|
|
|
#include "include/effects/Sk2DPathEffect.h"
|
|
|
|
#include "include/effects/SkCornerPathEffect.h"
|
|
|
|
#include "include/effects/SkDashPathEffect.h"
|
|
|
|
#include "include/effects/SkDiscretePathEffect.h"
|
2009-10-06 21:19:18 +00:00
|
|
|
|
|
|
|
static void compose_pe(SkPaint* paint) {
|
|
|
|
SkPathEffect* pe = paint->getPathEffect();
|
2016-03-18 18:22:57 +00:00
|
|
|
sk_sp<SkPathEffect> corner = SkCornerPathEffect::Make(25);
|
|
|
|
sk_sp<SkPathEffect> compose;
|
2009-10-06 21:19:18 +00:00
|
|
|
if (pe) {
|
2017-02-26 03:34:32 +00:00
|
|
|
compose = SkPathEffect::MakeCompose(sk_ref_sp(pe), corner);
|
2009-10-06 21:19:18 +00:00
|
|
|
} else {
|
|
|
|
compose = corner;
|
|
|
|
}
|
2016-03-18 18:22:57 +00:00
|
|
|
paint->setPathEffect(compose);
|
2009-10-06 21:19:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void hair_pe(SkPaint* paint) {
|
|
|
|
paint->setStrokeWidth(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void hair2_pe(SkPaint* paint) {
|
|
|
|
paint->setStrokeWidth(0);
|
|
|
|
compose_pe(paint);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void stroke_pe(SkPaint* paint) {
|
|
|
|
paint->setStrokeWidth(12);
|
|
|
|
compose_pe(paint);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dash_pe(SkPaint* paint) {
|
|
|
|
SkScalar inter[] = { 20, 10, 10, 10 };
|
|
|
|
paint->setStrokeWidth(12);
|
2016-03-18 18:22:57 +00:00
|
|
|
paint->setPathEffect(SkDashPathEffect::Make(inter, SK_ARRAY_COUNT(inter), 0));
|
2009-10-06 21:19:18 +00:00
|
|
|
compose_pe(paint);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const int gXY[] = {
|
|
|
|
4, 0, 0, -4, 8, -4, 12, 0, 8, 4, 0, 4
|
|
|
|
};
|
|
|
|
|
|
|
|
static void scale(SkPath* path, SkScalar scale) {
|
|
|
|
SkMatrix m;
|
|
|
|
m.setScale(scale, scale);
|
|
|
|
path->transform(m);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void one_d_pe(SkPaint* paint) {
|
|
|
|
SkPath path;
|
|
|
|
path.moveTo(SkIntToScalar(gXY[0]), SkIntToScalar(gXY[1]));
|
|
|
|
for (unsigned i = 2; i < SK_ARRAY_COUNT(gXY); i += 2)
|
|
|
|
path.lineTo(SkIntToScalar(gXY[i]), SkIntToScalar(gXY[i+1]));
|
|
|
|
path.close();
|
|
|
|
path.offset(SkIntToScalar(-6), 0);
|
2013-11-25 19:44:07 +00:00
|
|
|
scale(&path, 1.5f);
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2016-03-18 18:22:57 +00:00
|
|
|
paint->setPathEffect(SkPath1DPathEffect::Make(path, SkIntToScalar(21), 0,
|
|
|
|
SkPath1DPathEffect::kRotate_Style));
|
2009-10-06 21:19:18 +00:00
|
|
|
compose_pe(paint);
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef void (*PE_Proc)(SkPaint*);
|
|
|
|
static const PE_Proc gPE[] = { hair_pe, hair2_pe, stroke_pe, dash_pe, one_d_pe };
|
|
|
|
|
|
|
|
static void fill_pe(SkPaint* paint) {
|
|
|
|
paint->setStyle(SkPaint::kFill_Style);
|
2015-08-27 14:41:13 +00:00
|
|
|
paint->setPathEffect(nullptr);
|
2009-10-06 21:19:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void discrete_pe(SkPaint* paint) {
|
2016-03-18 18:22:57 +00:00
|
|
|
paint->setPathEffect(SkDiscretePathEffect::Make(10, 4));
|
2009-10-06 21:19:18 +00:00
|
|
|
}
|
|
|
|
|
2016-03-18 18:22:57 +00:00
|
|
|
static sk_sp<SkPathEffect> MakeTileEffect() {
|
2011-08-09 19:01:50 +00:00
|
|
|
SkMatrix m;
|
|
|
|
m.setScale(SkIntToScalar(12), SkIntToScalar(12));
|
2009-10-06 21:19:18 +00:00
|
|
|
|
2011-08-09 19:01:50 +00:00
|
|
|
SkPath path;
|
|
|
|
path.addCircle(0, 0, SkIntToScalar(5));
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2016-03-18 18:22:57 +00:00
|
|
|
return SkPath2DPathEffect::Make(m, path);
|
2011-08-09 19:01:50 +00:00
|
|
|
}
|
2009-10-06 21:19:18 +00:00
|
|
|
|
|
|
|
static void tile_pe(SkPaint* paint) {
|
2016-03-18 18:22:57 +00:00
|
|
|
paint->setPathEffect(MakeTileEffect());
|
2009-10-06 21:19:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const PE_Proc gPE2[] = { fill_pe, discrete_pe, tile_pe };
|
|
|
|
|
|
|
|
static void patheffect_slide(SkCanvas* canvas) {
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
|
|
|
|
SkPath path;
|
|
|
|
path.moveTo(20, 20);
|
|
|
|
path.lineTo(70, 120);
|
|
|
|
path.lineTo(120, 30);
|
|
|
|
path.lineTo(170, 80);
|
|
|
|
path.lineTo(240, 50);
|
|
|
|
|
|
|
|
size_t i;
|
|
|
|
canvas->save();
|
|
|
|
for (i = 0; i < SK_ARRAY_COUNT(gPE); i++) {
|
|
|
|
gPE[i](&paint);
|
|
|
|
canvas->drawPath(path, paint);
|
|
|
|
canvas->translate(0, 75);
|
|
|
|
}
|
|
|
|
canvas->restore();
|
|
|
|
|
|
|
|
path.reset();
|
|
|
|
SkRect r = { 0, 0, 250, 120 };
|
2019-11-22 18:34:02 +00:00
|
|
|
path.addOval(r, SkPathDirection::kCW);
|
2009-10-06 21:19:18 +00:00
|
|
|
r.inset(50, 50);
|
2019-11-22 18:34:02 +00:00
|
|
|
path.addRect(r, SkPathDirection::kCCW);
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2009-10-06 21:19:18 +00:00
|
|
|
canvas->translate(320, 20);
|
|
|
|
for (i = 0; i < SK_ARRAY_COUNT(gPE2); i++) {
|
|
|
|
gPE2[i](&paint);
|
|
|
|
canvas->drawPath(path, paint);
|
|
|
|
canvas->translate(0, 160);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/effects/SkGradientShader.h"
|
2009-10-06 21:19:18 +00:00
|
|
|
|
|
|
|
struct GradData {
|
|
|
|
int fCount;
|
|
|
|
const SkColor* fColors;
|
|
|
|
const SkScalar* fPos;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const SkColor gColors[] = {
|
|
|
|
SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK
|
|
|
|
};
|
|
|
|
static const SkScalar gPos0[] = { 0, SK_Scalar1 };
|
|
|
|
static const SkScalar gPos1[] = { SK_Scalar1/4, SK_Scalar1*3/4 };
|
|
|
|
static const SkScalar gPos2[] = {
|
|
|
|
0, SK_Scalar1/8, SK_Scalar1/2, SK_Scalar1*7/8, SK_Scalar1
|
|
|
|
};
|
|
|
|
|
|
|
|
static const GradData gGradData[] = {
|
2015-08-27 14:41:13 +00:00
|
|
|
{ 2, gColors, nullptr },
|
2009-10-06 21:19:18 +00:00
|
|
|
{ 2, gColors, gPos0 },
|
|
|
|
{ 2, gColors, gPos1 },
|
2015-08-27 14:41:13 +00:00
|
|
|
{ 5, gColors, nullptr },
|
2009-10-06 21:19:18 +00:00
|
|
|
{ 5, gColors, gPos2 }
|
|
|
|
};
|
|
|
|
|
2019-04-03 14:27:45 +00:00
|
|
|
static sk_sp<SkShader> MakeLinear(const SkPoint pts[2], const GradData& data, SkTileMode tm) {
|
2016-03-09 02:50:00 +00:00
|
|
|
return SkGradientShader::MakeLinear(pts, data.fColors, data.fPos, data.fCount, tm);
|
2009-10-06 21:19:18 +00:00
|
|
|
}
|
|
|
|
|
2019-04-03 14:27:45 +00:00
|
|
|
static sk_sp<SkShader> MakeRadial(const SkPoint pts[2], const GradData& data, SkTileMode tm) {
|
2009-10-06 21:19:18 +00:00
|
|
|
SkPoint center;
|
|
|
|
center.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
|
|
|
SkScalarAve(pts[0].fY, pts[1].fY));
|
2016-03-09 02:50:00 +00:00
|
|
|
return SkGradientShader::MakeRadial(center, center.fX, data.fColors,
|
2014-05-22 12:27:41 +00:00
|
|
|
data.fPos, data.fCount, tm);
|
2009-10-06 21:19:18 +00:00
|
|
|
}
|
|
|
|
|
2019-04-03 14:27:45 +00:00
|
|
|
static sk_sp<SkShader> MakeSweep(const SkPoint pts[2], const GradData& data, SkTileMode tm) {
|
2009-10-06 21:19:18 +00:00
|
|
|
SkPoint center;
|
|
|
|
center.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
|
|
|
SkScalarAve(pts[0].fY, pts[1].fY));
|
2016-03-09 02:50:00 +00:00
|
|
|
return SkGradientShader::MakeSweep(center.fX, center.fY, data.fColors, data.fPos, data.fCount);
|
2009-10-06 21:19:18 +00:00
|
|
|
}
|
|
|
|
|
2019-04-03 14:27:45 +00:00
|
|
|
static sk_sp<SkShader> Make2Conical(const SkPoint pts[2], const GradData& data, SkTileMode tm) {
|
2009-10-06 21:19:18 +00:00
|
|
|
SkPoint center0, center1;
|
|
|
|
center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
|
|
|
SkScalarAve(pts[0].fY, pts[1].fY));
|
|
|
|
center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
|
|
|
|
SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
|
2016-03-09 02:50:00 +00:00
|
|
|
return SkGradientShader::MakeTwoPointConical(center1, (pts[1].fX - pts[0].fX) / 7,
|
2009-10-06 21:19:18 +00:00
|
|
|
center0, (pts[1].fX - pts[0].fX) / 2,
|
2014-05-22 12:27:41 +00:00
|
|
|
data.fColors, data.fPos, data.fCount, tm);
|
2009-10-06 21:19:18 +00:00
|
|
|
}
|
|
|
|
|
2019-04-03 14:27:45 +00:00
|
|
|
typedef sk_sp<SkShader> (*GradMaker)(const SkPoint pts[2], const GradData&, SkTileMode);
|
2009-10-06 21:19:18 +00:00
|
|
|
static const GradMaker gGradMakers[] = {
|
2015-05-04 15:32:51 +00:00
|
|
|
MakeLinear, MakeRadial, MakeSweep, Make2Conical
|
2009-10-06 21:19:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void gradient_slide(SkCanvas* canvas) {
|
|
|
|
SkPoint pts[2] = {
|
|
|
|
{ 0, 0 },
|
|
|
|
{ SkIntToScalar(100), SkIntToScalar(100) }
|
|
|
|
};
|
2019-04-03 14:27:45 +00:00
|
|
|
SkTileMode tm = SkTileMode::kClamp;
|
2009-10-06 21:19:18 +00:00
|
|
|
SkRect r = { 0, 0, SkIntToScalar(100), SkIntToScalar(100) };
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setDither(true);
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2009-10-06 21:19:18 +00:00
|
|
|
canvas->translate(SkIntToScalar(20), SkIntToScalar(10));
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(gGradData); i++) {
|
|
|
|
canvas->save();
|
|
|
|
for (size_t j = 0; j < SK_ARRAY_COUNT(gGradMakers); j++) {
|
2016-03-09 02:50:00 +00:00
|
|
|
paint.setShader(gGradMakers[j](pts, gGradData[i], tm));
|
2009-10-06 21:19:18 +00:00
|
|
|
canvas->drawRect(r, paint);
|
|
|
|
canvas->translate(0, SkIntToScalar(120));
|
|
|
|
}
|
|
|
|
canvas->restore();
|
|
|
|
canvas->translate(SkIntToScalar(120), 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkStream.h"
|
|
|
|
#include "include/utils/SkRandom.h"
|
|
|
|
#include "samplecode/DecodeFile.h"
|
|
|
|
#include "src/core/SkOSFile.h"
|
2009-10-06 21:19:18 +00:00
|
|
|
|
2016-03-09 02:50:00 +00:00
|
|
|
static sk_sp<SkShader> make_shader0(SkIPoint* size) {
|
2009-10-06 21:19:18 +00:00
|
|
|
SkBitmap bm;
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2016-03-18 22:48:49 +00:00
|
|
|
decode_file("/skimages/logo.gif", &bm);
|
2009-10-06 21:19:18 +00:00
|
|
|
size->set(bm.width(), bm.height());
|
2021-01-15 02:59:01 +00:00
|
|
|
return bm.makeShader(SkSamplingOptions(SkFilterMode::kLinear));
|
2009-10-06 21:19:18 +00:00
|
|
|
}
|
|
|
|
|
2016-03-09 02:50:00 +00:00
|
|
|
static sk_sp<SkShader> make_shader1(const SkIPoint& size) {
|
2011-05-19 19:58:58 +00:00
|
|
|
SkPoint pts[] = { { 0, 0 },
|
|
|
|
{ SkIntToScalar(size.fX), SkIntToScalar(size.fY) } };
|
2009-10-06 21:19:18 +00:00
|
|
|
SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorRED };
|
2016-03-09 02:50:00 +00:00
|
|
|
return SkGradientShader::MakeLinear(pts, colors, nullptr,
|
2019-04-03 14:27:45 +00:00
|
|
|
SK_ARRAY_COUNT(colors), SkTileMode::kMirror);
|
2009-10-06 21:19:18 +00:00
|
|
|
}
|
|
|
|
|
2010-12-20 18:26:13 +00:00
|
|
|
class Rec {
|
|
|
|
public:
|
2017-04-03 15:11:09 +00:00
|
|
|
SkVertices::VertexMode fMode;
|
2009-10-06 21:19:18 +00:00
|
|
|
int fCount;
|
|
|
|
SkPoint* fVerts;
|
|
|
|
SkPoint* fTexs;
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2015-08-27 14:41:13 +00:00
|
|
|
Rec() : fCount(0), fVerts(nullptr), fTexs(nullptr) {}
|
2009-10-06 21:19:18 +00:00
|
|
|
~Rec() { delete[] fVerts; delete[] fTexs; }
|
|
|
|
};
|
|
|
|
|
2012-06-06 12:09:51 +00:00
|
|
|
static void make_tris(Rec* rec) {
|
2009-10-06 21:19:18 +00:00
|
|
|
int n = 10;
|
2013-09-09 20:09:12 +00:00
|
|
|
SkRandom rand;
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2017-04-03 15:11:09 +00:00
|
|
|
rec->fMode = SkVertices::kTriangles_VertexMode;
|
2009-10-06 21:19:18 +00:00
|
|
|
rec->fCount = n * 3;
|
|
|
|
rec->fVerts = new SkPoint[rec->fCount];
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2009-10-06 21:19:18 +00:00
|
|
|
for (int i = 0; i < n; i++) {
|
|
|
|
SkPoint* v = &rec->fVerts[i*3];
|
|
|
|
for (int j = 0; j < 3; j++) {
|
|
|
|
v[j].set(rand.nextUScalar1() * 250, rand.nextUScalar1() * 250);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-06 12:09:51 +00:00
|
|
|
static void make_fan(Rec* rec, int texWidth, int texHeight) {
|
2009-10-06 21:19:18 +00:00
|
|
|
const SkScalar tx = SkIntToScalar(texWidth);
|
|
|
|
const SkScalar ty = SkIntToScalar(texHeight);
|
|
|
|
const int n = 24;
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2017-04-03 15:11:09 +00:00
|
|
|
rec->fMode = SkVertices::kTriangleFan_VertexMode;
|
2009-10-06 21:19:18 +00:00
|
|
|
rec->fCount = n + 2;
|
|
|
|
rec->fVerts = new SkPoint[rec->fCount];
|
|
|
|
rec->fTexs = new SkPoint[rec->fCount];
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2009-10-06 21:19:18 +00:00
|
|
|
SkPoint* v = rec->fVerts;
|
|
|
|
SkPoint* t = rec->fTexs;
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2009-10-06 21:19:18 +00:00
|
|
|
v[0].set(0, 0);
|
|
|
|
t[0].set(0, 0);
|
|
|
|
for (int i = 0; i < n; i++) {
|
2019-04-02 14:59:28 +00:00
|
|
|
SkScalar r = SK_ScalarPI * 2 * i / n,
|
|
|
|
sin = SkScalarSin(r),
|
|
|
|
cos = SkScalarCos(r);
|
2009-10-06 21:19:18 +00:00
|
|
|
v[i+1].set(cos, sin);
|
|
|
|
t[i+1].set(i*tx/n, ty);
|
|
|
|
}
|
|
|
|
v[n+1] = v[1];
|
|
|
|
t[n+1].set(tx, ty);
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2009-10-06 21:19:18 +00:00
|
|
|
SkMatrix m;
|
|
|
|
m.setScale(SkIntToScalar(100), SkIntToScalar(100));
|
|
|
|
m.postTranslate(SkIntToScalar(110), SkIntToScalar(110));
|
|
|
|
m.mapPoints(v, rec->fCount);
|
|
|
|
}
|
|
|
|
|
2012-06-06 12:09:51 +00:00
|
|
|
static void make_strip(Rec* rec, int texWidth, int texHeight) {
|
2009-10-06 21:19:18 +00:00
|
|
|
const SkScalar tx = SkIntToScalar(texWidth);
|
|
|
|
const SkScalar ty = SkIntToScalar(texHeight);
|
|
|
|
const int n = 24;
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2017-04-03 15:11:09 +00:00
|
|
|
rec->fMode = SkVertices::kTriangleStrip_VertexMode;
|
2009-10-06 21:19:18 +00:00
|
|
|
rec->fCount = 2 * (n + 1);
|
|
|
|
rec->fVerts = new SkPoint[rec->fCount];
|
|
|
|
rec->fTexs = new SkPoint[rec->fCount];
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2009-10-06 21:19:18 +00:00
|
|
|
SkPoint* v = rec->fVerts;
|
|
|
|
SkPoint* t = rec->fTexs;
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2009-10-06 21:19:18 +00:00
|
|
|
for (int i = 0; i < n; i++) {
|
2019-04-02 14:59:28 +00:00
|
|
|
SkScalar r = SK_ScalarPI * 2 * i / n,
|
|
|
|
sin = SkScalarSin(r),
|
|
|
|
cos = SkScalarCos(r);
|
2009-10-06 21:19:18 +00:00
|
|
|
v[i*2 + 0].set(cos/2, sin/2);
|
|
|
|
v[i*2 + 1].set(cos, sin);
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2009-10-06 21:19:18 +00:00
|
|
|
t[i*2 + 0].set(tx * i / n, ty);
|
|
|
|
t[i*2 + 1].set(tx * i / n, 0);
|
|
|
|
}
|
|
|
|
v[2*n + 0] = v[0];
|
|
|
|
v[2*n + 1] = v[1];
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2009-10-06 21:19:18 +00:00
|
|
|
t[2*n + 0].set(tx, ty);
|
|
|
|
t[2*n + 1].set(tx, 0);
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2009-10-06 21:19:18 +00:00
|
|
|
SkMatrix m;
|
|
|
|
m.setScale(SkIntToScalar(100), SkIntToScalar(100));
|
|
|
|
m.postTranslate(SkIntToScalar(110), SkIntToScalar(110));
|
|
|
|
m.mapPoints(v, rec->fCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mesh_slide(SkCanvas* canvas) {
|
|
|
|
Rec fRecs[3];
|
|
|
|
SkIPoint size;
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2016-03-09 02:50:00 +00:00
|
|
|
auto fShader0 = make_shader0(&size);
|
|
|
|
auto fShader1 = make_shader1(size);
|
2010-12-20 18:26:13 +00:00
|
|
|
|
2009-10-06 21:19:18 +00:00
|
|
|
make_strip(&fRecs[0], size.fX, size.fY);
|
|
|
|
make_fan(&fRecs[1], size.fX, size.fY);
|
|
|
|
make_tris(&fRecs[2]);
|
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setDither(true);
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2011-05-19 19:58:58 +00:00
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(fRecs); i++) {
|
2017-04-03 15:11:09 +00:00
|
|
|
auto verts = SkVertices::MakeCopy(fRecs[i].fMode, fRecs[i].fCount,
|
|
|
|
fRecs[i].fVerts, fRecs[i].fTexs, nullptr);
|
2009-10-06 21:19:18 +00:00
|
|
|
canvas->save();
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2015-08-27 14:41:13 +00:00
|
|
|
paint.setShader(nullptr);
|
2017-04-03 15:11:09 +00:00
|
|
|
canvas->drawVertices(verts, SkBlendMode::kModulate, paint);
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2009-10-06 21:19:18 +00:00
|
|
|
canvas->translate(SkIntToScalar(210), 0);
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2009-10-06 21:19:18 +00:00
|
|
|
paint.setShader(fShader0);
|
2017-04-03 15:11:09 +00:00
|
|
|
canvas->drawVertices(verts, SkBlendMode::kModulate, paint);
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2009-10-06 21:19:18 +00:00
|
|
|
canvas->translate(SkIntToScalar(210), 0);
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2009-10-06 21:19:18 +00:00
|
|
|
paint.setShader(fShader1);
|
2017-04-03 15:11:09 +00:00
|
|
|
canvas->drawVertices(verts, SkBlendMode::kModulate, paint);
|
2009-10-06 21:19:18 +00:00
|
|
|
canvas->restore();
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2009-10-06 21:19:18 +00:00
|
|
|
canvas->translate(0, SkIntToScalar(250));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkTypeface.h"
|
2009-10-12 17:02:22 +00:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkImageEncoder.h"
|
2009-10-06 21:19:18 +00:00
|
|
|
|
|
|
|
static const SlideProc gProc[] = {
|
|
|
|
patheffect_slide,
|
|
|
|
gradient_slide,
|
2009-10-12 17:02:22 +00:00
|
|
|
mesh_slide,
|
2009-10-06 21:19:18 +00:00
|
|
|
};
|
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
class SlideView : public Sample {
|
2009-10-06 21:19:18 +00:00
|
|
|
int fIndex;
|
2012-03-12 21:13:48 +00:00
|
|
|
bool fOnce;
|
2009-10-06 21:19:18 +00:00
|
|
|
public:
|
|
|
|
SlideView() {
|
2012-03-12 21:13:48 +00:00
|
|
|
fOnce = false;
|
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2012-03-12 21:13:48 +00:00
|
|
|
void init() {
|
|
|
|
if (fOnce) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
fOnce = true;
|
|
|
|
|
2009-10-06 21:19:18 +00:00
|
|
|
fIndex = 0;
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2009-10-06 21:19:18 +00:00
|
|
|
SkBitmap bm;
|
2014-02-17 02:55:57 +00:00
|
|
|
bm.allocN32Pixels(1024, 768);
|
2009-10-06 21:19:18 +00:00
|
|
|
SkCanvas canvas(bm);
|
|
|
|
SkScalar s = SkIntToScalar(1024) / 640;
|
|
|
|
canvas.scale(s, s);
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(gProc); i++) {
|
|
|
|
canvas.save();
|
2009-10-12 17:02:22 +00:00
|
|
|
canvas.drawColor(BG_COLOR);
|
2009-10-06 21:19:18 +00:00
|
|
|
gProc[i](&canvas);
|
|
|
|
canvas.restore();
|
|
|
|
SkString str;
|
2020-05-05 03:17:21 +00:00
|
|
|
str.printf("/skimages/slide_%zu.png", i);
|
2019-03-20 16:12:10 +00:00
|
|
|
ToolUtils::EncodeImageToFile(str.c_str(), bm, SkEncodedImageFormat::kPNG, 100);
|
2009-10-06 21:19:18 +00:00
|
|
|
}
|
2011-06-01 12:42:36 +00:00
|
|
|
this->setBGColor(BG_COLOR);
|
2009-10-06 21:19:18 +00:00
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2009-10-06 21:19:18 +00:00
|
|
|
protected:
|
2019-07-03 14:55:44 +00:00
|
|
|
SkString name() override { return SkString("Slides"); }
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDrawContent(SkCanvas* canvas) override {
|
2012-03-12 21:13:48 +00:00
|
|
|
this->init();
|
2009-10-06 21:19:18 +00:00
|
|
|
gProc[fIndex](canvas);
|
|
|
|
}
|
|
|
|
|
2019-08-29 14:39:22 +00:00
|
|
|
Sample::Click* onFindClickHandler(SkScalar x, SkScalar y, skui::ModifierKey) override {
|
2012-03-12 21:13:48 +00:00
|
|
|
this->init();
|
2009-10-06 21:19:18 +00:00
|
|
|
fIndex = (fIndex + 1) % SK_ARRAY_COUNT(gProc);
|
2015-08-27 14:41:13 +00:00
|
|
|
return nullptr;
|
2009-10-06 21:19:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = Sample;
|
2009-10-06 21:19:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
DEF_SAMPLE( return new SlideView(); )
|