| 1 |
// Copyright 2019 Google LLC. |
| 2 |
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. |
| 3 |
#include "tools/fiddle/examples.h" |
| 4 |
REG_FIDDLE(Path_isRect, 256, 256, true, 0) { |
| 5 |
void draw(SkCanvas* canvas) { |
| 6 |
auto debugster = [](const char* prefix, const SkPathBuilder& builder) -> void { |
| 7 |
SkPath path = builder.snapshot(); |
| 8 |
SkRect rect; |
| 9 |
SkPathDirection direction; |
| 10 |
bool isClosed; |
| 11 |
path.isRect(&rect, &isClosed, &direction) ? |
| 12 |
SkDebugf("%s is rect (%g, %g, %g, %g); is %s" "closed; direction %s\n", prefix, |
| 13 |
rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, isClosed ? "" : "not ", |
| 14 |
SkPathDirection::kCW == direction ? "CW" : "CCW") : |
| 15 |
SkDebugf("%s is not rect\n", prefix); |
| 16 |
}; |
| 17 |
SkPathBuilder path; |
| 18 |
debugster("empty", path); |
| 19 |
path.addRect({10, 20, 30, 40}); |
| 20 |
debugster("addRect", path); |
| 21 |
path.moveTo(60, 70); |
| 22 |
debugster("moveTo", path); |
| 23 |
path.lineTo(60, 70); |
| 24 |
debugster("lineTo", path); |
| 25 |
path.reset(); |
| 26 |
const SkPoint pts[] = { {0, 0}, {0, 80}, {80, 80}, {80, 0}, {40, 0}, {20, 0} }; |
| 27 |
path.addPolygon(pts, false); |
| 28 |
debugster("addPoly", path); |
| 29 |
} |
| 30 |
} // END FIDDLE |