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/SkPath.h"
|
|
|
|
#include "include/core/SkRegion.h"
|
|
|
|
#include "include/core/SkShader.h"
|
|
|
|
#include "include/effects/SkCornerPathEffect.h"
|
|
|
|
#include "include/effects/SkGradientShader.h"
|
|
|
|
#include "samplecode/Sample.h"
|
|
|
|
#include "src/utils/SkUTF.h"
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
class FillTypeView : public Sample {
|
2008-12-17 15:59:43 +00:00
|
|
|
SkPath fPath;
|
|
|
|
public:
|
2012-08-23 18:19:56 +00:00
|
|
|
FillTypeView() {
|
2008-12-17 15:59:43 +00:00
|
|
|
const SkScalar radius = SkIntToScalar(45);
|
|
|
|
fPath.addCircle(SkIntToScalar(50), SkIntToScalar(50), radius);
|
|
|
|
fPath.addCircle(SkIntToScalar(100), SkIntToScalar(100), radius);
|
2011-05-05 14:03:48 +00:00
|
|
|
|
|
|
|
this->setBGColor(0xFFDDDDDD);
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
protected:
|
2020-07-21 21:03:56 +00:00
|
|
|
SkString name() override{ return SkString("FillType"); }
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2019-11-26 17:17:17 +00:00
|
|
|
void showPath(SkCanvas* canvas, int x, int y, SkPathFillType ft,
|
2008-12-17 15:59:43 +00:00
|
|
|
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();
|
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
void showFour(SkCanvas* canvas, SkScalar scale, const SkPaint& paint) {
|
2019-11-26 17:17:17 +00:00
|
|
|
showPath(canvas, 0, 0, SkPathFillType::kWinding,
|
2019-09-14 19:13:23 +00:00
|
|
|
scale, paint);
|
2019-11-26 17:17:17 +00:00
|
|
|
showPath(canvas, 200, 0, SkPathFillType::kEvenOdd,
|
2019-09-14 19:13:23 +00:00
|
|
|
scale, paint);
|
2019-11-26 17:17:17 +00:00
|
|
|
showPath(canvas, 00, 200, SkPathFillType::kInverseWinding,
|
2019-09-14 19:13:23 +00:00
|
|
|
scale, paint);
|
2019-11-26 17:17:17 +00:00
|
|
|
showPath(canvas, 200, 200, SkPathFillType::kInverseEvenOdd,
|
2019-09-14 19:13:23 +00:00
|
|
|
scale, paint);
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2020-07-21 21:03:56 +00:00
|
|
|
void onDrawContent(SkCanvas* canvas) override {
|
2008-12-17 15:59:43 +00:00
|
|
|
canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
SkPaint paint;
|
|
|
|
const SkScalar scale = SkIntToScalar(5)/4;
|
|
|
|
|
|
|
|
paint.setAntiAlias(false);
|
2009-07-10 15:58:53 +00:00
|
|
|
paint.setColor(0x8000FF00);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
showFour(canvas, SK_Scalar1, paint);
|
|
|
|
canvas->translate(SkIntToScalar(450), 0);
|
|
|
|
showFour(canvas, scale, paint);
|
|
|
|
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
|
|
|
|
canvas->translate(SkIntToScalar(-450), SkIntToScalar(450));
|
|
|
|
showFour(canvas, SK_Scalar1, paint);
|
|
|
|
canvas->translate(SkIntToScalar(450), 0);
|
|
|
|
showFour(canvas, scale, paint);
|
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
private:
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = Sample;
|
2008-12-17 15:59:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
DEF_SAMPLE( return new FillTypeView(); )
|