blob: c099bb9739ce23623ab1a908033b6113d8ee8c2b [file] [log] [blame]
Hal Canary87515122019-03-15 14:22:51 -04001// 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.
Mike Kleinc0bd9f92019-04-23 12:05:21 -05003#include "tools/fiddle/examples.h"
Hal Canary87515122019-03-15 14:22:51 -04004// HASH=81a2aac1b8f0ff3d4c8d35ccb9149b16
Hal Canarya7181e7c2019-03-18 16:06:34 -04005REG_FIDDLE(Path_isRect, 256, 256, true, 0) {
Hal Canary87515122019-03-15 14:22:51 -04006void draw(SkCanvas* canvas) {
7 auto debugster = [](const char* prefix, const SkPath& path) -> void {
8 SkRect rect;
Mike Reed30bc5272019-11-22 18:34:02 +00009 SkPathDirection direction;
Hal Canary87515122019-03-15 14:22:51 -040010 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 ",
Mike Reed30bc5272019-11-22 18:34:02 +000014 SkPathDirection::kCW == direction ? "CW" : "CCW") :
Hal Canary87515122019-03-15 14:22:51 -040015 SkDebugf("%s is not rect\n", prefix);
16 };
17 SkPath 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.addPoly(pts, SK_ARRAY_COUNT(pts), false);
28 debugster("addPoly", path);
29}
30} // END FIDDLE