2012-12-04 22:52:28 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2015-08-05 20:57:49 +00:00
|
|
|
#include "SkBlurMaskFilter.h"
|
2012-12-04 22:52:28 +00:00
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkGraphics.h"
|
2015-08-05 01:44:56 +00:00
|
|
|
#include "SkLayerDrawLooper.h"
|
2015-08-05 20:57:49 +00:00
|
|
|
#include "SkPath.h"
|
|
|
|
#include "SkRandom.h"
|
2019-03-20 16:12:10 +00:00
|
|
|
#include "ToolUtils.h"
|
|
|
|
#include "gm.h"
|
2012-12-04 22:52:28 +00:00
|
|
|
|
|
|
|
static SkRect inset(const SkRect& r) {
|
|
|
|
SkRect rect = r;
|
|
|
|
rect.inset(r.width() / 8, r.height() / 8);
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
|
|
|
class PathInteriorGM : public skiagm::GM {
|
|
|
|
public:
|
|
|
|
PathInteriorGM() {
|
2018-08-16 14:17:03 +00:00
|
|
|
this->setBGColor(0xFFDDDDDD);
|
2012-12-04 22:52:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
SkISize onISize() override {
|
2012-12-05 05:34:51 +00:00
|
|
|
return SkISize::Make(770, 770);
|
2012-12-04 22:52:28 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkString onShortName() override {
|
2012-12-04 22:52:28 +00:00
|
|
|
return SkString("pathinterior");
|
|
|
|
}
|
|
|
|
|
|
|
|
void show(SkCanvas* canvas, const SkPath& path) {
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
|
|
|
|
SkRect rect;
|
|
|
|
#if 0
|
|
|
|
bool hasInterior = path.hasRectangularInterior(&rect);
|
|
|
|
#else
|
|
|
|
bool hasInterior = false;
|
|
|
|
#endif
|
|
|
|
|
2019-03-20 16:12:10 +00:00
|
|
|
paint.setColor(hasInterior ? ToolUtils::color_to_565(0xFF8888FF) : SK_ColorGRAY);
|
2012-12-04 22:52:28 +00:00
|
|
|
canvas->drawPath(path, paint);
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
paint.setColor(SK_ColorRED);
|
|
|
|
canvas->drawPath(path, paint);
|
2012-12-05 02:01:21 +00:00
|
|
|
|
2012-12-04 22:52:28 +00:00
|
|
|
if (hasInterior) {
|
|
|
|
paint.setStyle(SkPaint::kFill_Style);
|
|
|
|
paint.setColor(0x8800FF00);
|
|
|
|
canvas->drawRect(rect, paint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2012-12-05 05:34:51 +00:00
|
|
|
canvas->translate(8.5f, 8.5f);
|
2012-12-04 22:52:28 +00:00
|
|
|
|
2012-12-05 05:34:51 +00:00
|
|
|
const SkRect rect = { 0, 0, 80, 80 };
|
2012-12-04 22:52:28 +00:00
|
|
|
const SkScalar RAD = rect.width()/8;
|
|
|
|
|
|
|
|
int i = 0;
|
2012-12-05 05:34:51 +00:00
|
|
|
for (int insetFirst = 0; insetFirst <= 1; ++insetFirst) {
|
|
|
|
for (int doEvenOdd = 0; doEvenOdd <= 1; ++doEvenOdd) {
|
|
|
|
for (int outerRR = 0; outerRR <= 1; ++outerRR) {
|
|
|
|
for (int innerRR = 0; innerRR <= 1; ++innerRR) {
|
|
|
|
for (int outerCW = 0; outerCW <= 1; ++outerCW) {
|
|
|
|
for (int innerCW = 0; innerCW <= 1; ++innerCW) {
|
|
|
|
SkPath path;
|
|
|
|
path.setFillType(doEvenOdd ? SkPath::kEvenOdd_FillType : SkPath::kWinding_FillType);
|
|
|
|
SkPath::Direction outerDir = outerCW ? SkPath::kCW_Direction : SkPath::kCCW_Direction;
|
|
|
|
SkPath::Direction innerDir = innerCW ? SkPath::kCW_Direction : SkPath::kCCW_Direction;
|
2012-12-06 02:01:25 +00:00
|
|
|
|
2012-12-05 05:34:51 +00:00
|
|
|
SkRect r = insetFirst ? inset(rect) : rect;
|
|
|
|
if (outerRR) {
|
|
|
|
path.addRoundRect(r, RAD, RAD, outerDir);
|
|
|
|
} else {
|
|
|
|
path.addRect(r, outerDir);
|
|
|
|
}
|
|
|
|
r = insetFirst ? rect : inset(rect);
|
|
|
|
if (innerRR) {
|
|
|
|
path.addRoundRect(r, RAD, RAD, innerDir);
|
|
|
|
} else {
|
|
|
|
path.addRect(r, innerDir);
|
|
|
|
}
|
|
|
|
|
|
|
|
SkScalar dx = (i / 8) * rect.width() * 6 / 5;
|
|
|
|
SkScalar dy = (i % 8) * rect.height() * 6 / 5;
|
|
|
|
i++;
|
|
|
|
path.offset(dx, dy);
|
2012-12-06 02:01:25 +00:00
|
|
|
|
2012-12-05 05:34:51 +00:00
|
|
|
this->show(canvas, path);
|
2012-12-04 22:52:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-12-10 21:31:59 +00:00
|
|
|
DEF_GM( return new PathInteriorGM; )
|