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.
|
|
|
|
*/
|
2008-12-17 15:59:43 +00:00
|
|
|
#include "SampleCode.h"
|
|
|
|
#include "SkView.h"
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkCornerPathEffect.h"
|
|
|
|
#include "SkGradientShader.h"
|
|
|
|
#include "SkPath.h"
|
|
|
|
#include "SkRegion.h"
|
|
|
|
#include "SkShader.h"
|
|
|
|
#include "SkUtils.h"
|
|
|
|
|
2011-05-05 14:03:48 +00:00
|
|
|
class FillTypeView : public SampleView {
|
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:
|
|
|
|
// overrides from SkEventSink
|
|
|
|
virtual bool onQuery(SkEvent* evt) {
|
|
|
|
if (SampleCode::TitleQ(*evt)) {
|
|
|
|
SampleCode::TitleR(evt, "FillType");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return this->INHERITED::onQuery(evt);
|
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2008-12-17 15:59:43 +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();
|
|
|
|
}
|
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) {
|
|
|
|
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);
|
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2011-05-05 14:03:48 +00:00
|
|
|
virtual void onDrawContent(SkCanvas* canvas) {
|
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:
|
2011-05-05 14:03:48 +00:00
|
|
|
typedef SampleView INHERITED;
|
2008-12-17 15:59:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static SkView* MyFactory() { return new FillTypeView; }
|
|
|
|
static SkViewRegister reg(MyFactory);
|