2011-09-13 15:27:18 +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.
|
|
|
|
*/
|
|
|
|
#include "gm.h"
|
2011-09-13 15:39:00 +00:00
|
|
|
#include "SkGradientShader.h"
|
2011-09-13 15:27:18 +00:00
|
|
|
|
|
|
|
namespace skiagm {
|
|
|
|
|
|
|
|
class FillTypePerspGM : public GM {
|
|
|
|
SkPath fPath;
|
|
|
|
public:
|
2012-03-30 20:04:21 +00:00
|
|
|
FillTypePerspGM() {}
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-03-30 20:04:21 +00:00
|
|
|
void makePath() {
|
|
|
|
if (fPath.isEmpty()) {
|
|
|
|
const SkScalar radius = SkIntToScalar(45);
|
|
|
|
fPath.addCircle(SkIntToScalar(50), SkIntToScalar(50), radius);
|
|
|
|
fPath.addCircle(SkIntToScalar(100), SkIntToScalar(100), radius);
|
|
|
|
}
|
2011-09-13 15:27:18 +00:00
|
|
|
}
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2011-09-13 15:27:18 +00:00
|
|
|
protected:
|
2014-04-30 13:20:45 +00:00
|
|
|
virtual uint32_t onGetFlags() const SK_OVERRIDE {
|
|
|
|
return kSkipTiled_Flag;
|
|
|
|
}
|
|
|
|
|
2011-09-13 15:27:18 +00:00
|
|
|
virtual SkString onShortName() {
|
|
|
|
return SkString("filltypespersp");
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual SkISize onISize() {
|
2014-06-10 06:59:03 +00:00
|
|
|
return SkISize::Make(835, 840);
|
2011-09-13 15:27:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void showPath(SkCanvas* canvas, int x, int y, SkPath::FillType ft,
|
|
|
|
SkScalar scale, const SkPaint& paint) {
|
|
|
|
|
|
|
|
const SkRect r = { 0, 0, SkIntToScalar(150), SkIntToScalar(150) };
|
|
|
|
|
|
|
|
canvas->save();
|
|
|
|
canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
|
|
|
|
canvas->clipRect(r);
|
|
|
|
canvas->drawColor(SK_ColorWHITE);
|
|
|
|
fPath.setFillType(ft);
|
|
|
|
canvas->translate(r.centerX(), r.centerY());
|
|
|
|
canvas->scale(scale, scale);
|
|
|
|
canvas->translate(-r.centerX(), -r.centerY());
|
|
|
|
canvas->drawPath(fPath, paint);
|
|
|
|
canvas->restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
void showFour(SkCanvas* canvas, SkScalar scale, bool aa) {
|
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
SkPoint center = SkPoint::Make(SkIntToScalar(100), SkIntToScalar(100));
|
|
|
|
SkColor colors[] = {SK_ColorBLUE, SK_ColorRED, SK_ColorGREEN};
|
|
|
|
SkScalar pos[] = {0, SK_ScalarHalf, SK_Scalar1};
|
|
|
|
SkShader* s = SkGradientShader::CreateRadial(center,
|
|
|
|
SkIntToScalar(100),
|
|
|
|
colors,
|
|
|
|
pos,
|
|
|
|
SK_ARRAY_COUNT(colors),
|
|
|
|
SkShader::kClamp_TileMode);
|
|
|
|
paint.setShader(s)->unref();
|
|
|
|
paint.setAntiAlias(aa);
|
|
|
|
|
|
|
|
showPath(canvas, 0, 0, SkPath::kWinding_FillType,
|
|
|
|
scale, paint);
|
|
|
|
showPath(canvas, 200, 0, SkPath::kEvenOdd_FillType,
|
|
|
|
scale, paint);
|
|
|
|
showPath(canvas, 00, 200, SkPath::kInverseWinding_FillType,
|
|
|
|
scale, paint);
|
|
|
|
showPath(canvas, 200, 200, SkPath::kInverseEvenOdd_FillType,
|
|
|
|
scale, paint);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void onDraw(SkCanvas* canvas) {
|
2012-03-30 20:04:21 +00:00
|
|
|
this->makePath();
|
|
|
|
|
2011-09-13 15:27:18 +00:00
|
|
|
// do perspective drawPaint as the background;
|
|
|
|
SkPaint bkgnrd;
|
2011-09-13 15:39:00 +00:00
|
|
|
SkPoint center = SkPoint::Make(SkIntToScalar(100),
|
|
|
|
SkIntToScalar(100));
|
|
|
|
SkColor colors[] = {SK_ColorBLACK, SK_ColorCYAN,
|
|
|
|
SK_ColorYELLOW, SK_ColorWHITE};
|
|
|
|
SkScalar pos[] = {0, SK_ScalarHalf / 2,
|
|
|
|
3 * SK_ScalarHalf / 2, SK_Scalar1};
|
2011-09-13 15:27:18 +00:00
|
|
|
SkShader* s = SkGradientShader::CreateRadial(center,
|
|
|
|
SkIntToScalar(1000),
|
|
|
|
colors,
|
|
|
|
pos,
|
|
|
|
SK_ARRAY_COUNT(colors),
|
|
|
|
SkShader::kClamp_TileMode);
|
|
|
|
bkgnrd.setShader(s)->unref();
|
|
|
|
canvas->save();
|
|
|
|
canvas->translate(SkIntToScalar(100), SkIntToScalar(100));
|
|
|
|
SkMatrix mat;
|
|
|
|
mat.reset();
|
2011-10-07 21:55:56 +00:00
|
|
|
mat.setPerspY(SkScalarToPersp(SK_Scalar1 / 1000));
|
2011-09-13 15:27:18 +00:00
|
|
|
canvas->concat(mat);
|
|
|
|
canvas->drawPaint(bkgnrd);
|
|
|
|
canvas->restore();
|
|
|
|
|
|
|
|
// draw the paths in perspective
|
|
|
|
SkMatrix persp;
|
|
|
|
persp.reset();
|
2011-10-07 21:55:56 +00:00
|
|
|
persp.setPerspX(SkScalarToPersp(-SK_Scalar1 / 1800));
|
|
|
|
persp.setPerspY(SkScalarToPersp(SK_Scalar1 / 500));
|
2011-09-13 15:27:18 +00:00
|
|
|
canvas->concat(persp);
|
|
|
|
|
|
|
|
canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
|
|
|
|
const SkScalar scale = SkIntToScalar(5)/4;
|
|
|
|
|
|
|
|
showFour(canvas, SK_Scalar1, false);
|
|
|
|
canvas->translate(SkIntToScalar(450), 0);
|
2011-09-13 15:39:00 +00:00
|
|
|
showFour(canvas, scale, false);
|
2011-09-13 15:27:18 +00:00
|
|
|
|
|
|
|
canvas->translate(SkIntToScalar(-450), SkIntToScalar(450));
|
|
|
|
showFour(canvas, SK_Scalar1, true);
|
|
|
|
canvas->translate(SkIntToScalar(450), 0);
|
2011-09-13 15:39:00 +00:00
|
|
|
showFour(canvas, scale, true);
|
2011-09-13 15:27:18 +00:00
|
|
|
}
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2011-09-13 15:27:18 +00:00
|
|
|
private:
|
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-09-13 15:39:00 +00:00
|
|
|
static GM* MyFactory(void*) { return new FillTypePerspGM; }
|
2011-09-13 15:27:18 +00:00
|
|
|
static GMRegistry reg(MyFactory);
|
|
|
|
|
|
|
|
}
|