2 * Copyright 2012 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
9 #include "sk_tool_utils.h"
10 #include "SkBlurMaskFilter.h"
12 #include "SkGraphics.h"
13 #include "SkLayerDrawLooper.h"
17 static SkRect inset(const SkRect& r) {
19 rect.inset(r.width() / 8, r.height() / 8);
23 class PathInteriorGM : public skiagm::GM {
26 this->setBGColor(sk_tool_utils::color_to_565(0xFFDDDDDD));
30 SkISize onISize() override {
31 return SkISize::Make(770, 770);
34 SkString onShortName() override {
35 return SkString("pathinterior");
38 void show(SkCanvas* canvas, const SkPath& path) {
40 paint.setAntiAlias(true);
44 bool hasInterior = path.hasRectangularInterior(&rect);
46 bool hasInterior = false;
49 paint.setColor(sk_tool_utils::color_to_565(hasInterior ? 0xFF8888FF : SK_ColorGRAY));
50 canvas->drawPath(path, paint);
51 paint.setStyle(SkPaint::kStroke_Style);
52 paint.setColor(SK_ColorRED);
53 canvas->drawPath(path, paint);
56 paint.setStyle(SkPaint::kFill_Style);
57 paint.setColor(0x8800FF00);
58 canvas->drawRect(rect, paint);
62 void onDraw(SkCanvas* canvas) override {
63 canvas->translate(8.5f, 8.5f);
65 const SkRect rect = { 0, 0, 80, 80 };
66 const SkScalar RAD = rect.width()/8;
69 for (int insetFirst = 0; insetFirst <= 1; ++insetFirst) {
70 for (int doEvenOdd = 0; doEvenOdd <= 1; ++doEvenOdd) {
71 for (int outerRR = 0; outerRR <= 1; ++outerRR) {
72 for (int innerRR = 0; innerRR <= 1; ++innerRR) {
73 for (int outerCW = 0; outerCW <= 1; ++outerCW) {
74 for (int innerCW = 0; innerCW <= 1; ++innerCW) {
76 path.setFillType(doEvenOdd ? SkPath::kEvenOdd_FillType : SkPath::kWinding_FillType);
77 SkPath::Direction outerDir = outerCW ? SkPath::kCW_Direction : SkPath::kCCW_Direction;
78 SkPath::Direction innerDir = innerCW ? SkPath::kCW_Direction : SkPath::kCCW_Direction;
80 SkRect r = insetFirst ? inset(rect) : rect;
82 path.addRoundRect(r, RAD, RAD, outerDir);
84 path.addRect(r, outerDir);
86 r = insetFirst ? rect : inset(rect);
88 path.addRoundRect(r, RAD, RAD, innerDir);
90 path.addRect(r, innerDir);
93 SkScalar dx = (i / 8) * rect.width() * 6 / 5;
94 SkScalar dy = (i % 8) * rect.height() * 6 / 5;
98 this->show(canvas, path);
109 typedef GM INHERITED;
112 //////////////////////////////////////////////////////////////////////////////
114 DEF_GM( return new PathInteriorGM; )