| 1 |
/* |
| 2 |
* Copyright 2012 Google Inc. |
| 3 |
* |
| 4 |
* Use of this source code is governed by a BSD-style license that can be |
| 5 |
* found in the LICENSE file. |
| 6 |
*/ |
| 7 |
|
| 8 |
#include "gm/gm.h" |
| 9 |
#include "include/core/SkCanvas.h" |
| 10 |
#include "include/core/SkColor.h" |
| 11 |
#include "include/core/SkPaint.h" |
| 12 |
#include "include/core/SkPath.h" |
| 13 |
#include "include/core/SkPathBuilder.h" |
| 14 |
#include "include/core/SkRect.h" |
| 15 |
#include "include/core/SkScalar.h" |
| 16 |
#include "include/core/SkSize.h" |
| 17 |
#include "include/core/SkString.h" |
| 18 |
#include "tools/ToolUtils.h" |
| 19 |
|
| 20 |
static SkRect inset(const SkRect& r) { |
| 21 |
SkRect rect = r; |
| 22 |
rect.inset(r.width() / 8, r.height() / 8); |
| 23 |
return rect; |
| 24 |
} |
| 25 |
|
| 26 |
class PathInteriorGM : public skiagm::GM { |
| 27 |
public: |
| 28 |
PathInteriorGM() { |
| 29 |
this->setBGColor(0xFFDDDDDD); |
| 30 |
} |
| 31 |
|
| 32 |
protected: |
| 33 |
SkISize getISize() override { return SkISize::Make(770, 770); } |
| 34 |
|
| 35 |
SkString getName() const override { return SkString("pathinterior"); } |
| 36 |
|
| 37 |
void show(SkCanvas* canvas, const SkPath& path) { |
| 38 |
SkPaint paint; |
| 39 |
paint.setAntiAlias(true); |
| 40 |
|
| 41 |
SkRect rect; |
| 42 |
#if 0 |
| 43 |
bool hasInterior = path.hasRectangularInterior(&rect); |
| 44 |
#else |
| 45 |
bool hasInterior = false; |
| 46 |
#endif |
| 47 |
|
| 48 |
paint.setColor(hasInterior ? ToolUtils::color_to_565(0xFF8888FF) : SK_ColorGRAY); |
| 49 |
canvas->drawPath(path, paint); |
| 50 |
paint.setStyle(SkPaint::kStroke_Style); |
| 51 |
paint.setColor(SK_ColorRED); |
| 52 |
canvas->drawPath(path, paint); |
| 53 |
|
| 54 |
if (hasInterior) { |
| 55 |
paint.setStyle(SkPaint::kFill_Style); |
| 56 |
paint.setColor(0x8800FF00); |
| 57 |
canvas->drawRect(rect, paint); |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
void onDraw(SkCanvas* canvas) override { |
| 62 |
canvas->translate(8.5f, 8.5f); |
| 63 |
|
| 64 |
const SkRect rect = { 0, 0, 80, 80 }; |
| 65 |
const SkScalar RAD = rect.width()/8; |
| 66 |
|
| 67 |
int i = 0; |
| 68 |
for (int insetFirst = 0; insetFirst <= 1; ++insetFirst) { |
| 69 |
for (int doEvenOdd = 0; doEvenOdd <= 1; ++doEvenOdd) { |
| 70 |
for (int outerRR = 0; outerRR <= 1; ++outerRR) { |
| 71 |
for (int innerRR = 0; innerRR <= 1; ++innerRR) { |
| 72 |
for (int outerCW = 0; outerCW <= 1; ++outerCW) { |
| 73 |
for (int innerCW = 0; innerCW <= 1; ++innerCW) { |
| 74 |
SkPathBuilder builder(doEvenOdd ? SkPathFillType::kEvenOdd |
| 75 |
: SkPathFillType::kWinding); |
| 76 |
SkPathDirection outerDir = outerCW ? SkPathDirection::kCW : SkPathDirection::kCCW; |
| 77 |
SkPathDirection innerDir = innerCW ? SkPathDirection::kCW : SkPathDirection::kCCW; |
| 78 |
|
| 79 |
SkRect r = insetFirst ? inset(rect) : rect; |
| 80 |
if (outerRR) { |
| 81 |
builder.addRRect(SkRRect::MakeRectXY(r, RAD, RAD), outerDir); |
| 82 |
} else { |
| 83 |
builder.addRect(r, outerDir); |
| 84 |
} |
| 85 |
r = insetFirst ? rect : inset(rect); |
| 86 |
if (innerRR) { |
| 87 |
builder.addRRect(SkRRect::MakeRectXY(r, RAD, RAD), innerDir); |
| 88 |
} else { |
| 89 |
builder.addRect(r, innerDir); |
| 90 |
} |
| 91 |
|
| 92 |
SkScalar dx = (i / 8) * rect.width() * 6 / 5; |
| 93 |
SkScalar dy = (i % 8) * rect.height() * 6 / 5; |
| 94 |
i++; |
| 95 |
builder.offset(dx, dy); |
| 96 |
|
| 97 |
this->show(canvas, builder.detach()); |
| 98 |
} |
| 99 |
} |
| 100 |
} |
| 101 |
} |
| 102 |
} |
| 103 |
} |
| 104 |
} |
| 105 |
|
| 106 |
private: |
| 107 |
|
| 108 |
using INHERITED = GM; |
| 109 |
}; |
| 110 |
|
| 111 |
////////////////////////////////////////////////////////////////////////////// |
| 112 |
|
| 113 |
DEF_GM( return new PathInteriorGM; ) |