2015-11-19 17:47:12 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2015 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "gm/gm.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkPath.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkPathEffect.h"
|
|
|
|
#include "include/core/SkPoint.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkRRect.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkScalar.h"
|
|
|
|
#include "include/core/SkSize.h"
|
|
|
|
#include "include/core/SkString.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/effects/SkDashPathEffect.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/private/SkTArray.h"
|
|
|
|
#include "include/private/SkTemplates.h"
|
2015-11-19 17:47:12 +00:00
|
|
|
|
|
|
|
namespace skiagm {
|
|
|
|
|
|
|
|
class ContourStartGM : public GM {
|
2020-11-05 15:05:19 +00:00
|
|
|
protected:
|
|
|
|
void onOnceBeforeDraw() override {
|
2015-11-19 17:47:12 +00:00
|
|
|
const SkScalar kMaxDashLen = 100;
|
|
|
|
const SkScalar kDashGrowth = 1.2f;
|
|
|
|
|
|
|
|
SkSTArray<100, SkScalar> intervals;
|
|
|
|
for (SkScalar len = 1; len < kMaxDashLen; len *= kDashGrowth) {
|
|
|
|
intervals.push_back(len);
|
|
|
|
intervals.push_back(len);
|
|
|
|
}
|
|
|
|
|
|
|
|
fDashPaint.setAntiAlias(true);
|
|
|
|
fDashPaint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
fDashPaint.setStrokeWidth(6);
|
|
|
|
fDashPaint.setColor(0xff008000);
|
2016-03-18 18:22:57 +00:00
|
|
|
fDashPaint.setPathEffect(SkDashPathEffect::Make(intervals.begin(), intervals.count(), 0));
|
2015-11-19 17:47:12 +00:00
|
|
|
|
|
|
|
fPointsPaint.setColor(0xff800000);
|
|
|
|
fPointsPaint.setStrokeWidth(3);
|
|
|
|
|
|
|
|
fRect = SkRect::MakeLTRB(10, 10, 100, 70);
|
|
|
|
}
|
|
|
|
|
|
|
|
SkString onShortName() override {
|
|
|
|
return SkString("contour_start");
|
|
|
|
}
|
|
|
|
|
|
|
|
SkISize onISize() override { return SkISize::Make(kImageWidth, kImageHeight); }
|
|
|
|
|
|
|
|
void onDraw(SkCanvas* canvas) override {
|
|
|
|
|
2019-11-22 18:34:02 +00:00
|
|
|
drawDirs(canvas, [](const SkRect& rect, SkPathDirection dir, unsigned startIndex) {
|
2020-08-25 15:48:41 +00:00
|
|
|
return SkPath::Rect(rect, dir, startIndex);
|
2015-11-19 17:47:12 +00:00
|
|
|
});
|
|
|
|
|
2019-11-22 18:34:02 +00:00
|
|
|
drawDirs(canvas, [](const SkRect& rect, SkPathDirection dir, unsigned startIndex) {
|
2020-08-25 21:36:28 +00:00
|
|
|
return SkPath::Oval(rect, dir, startIndex);
|
2015-11-19 17:47:12 +00:00
|
|
|
});
|
|
|
|
|
2019-11-22 18:34:02 +00:00
|
|
|
drawDirs(canvas, [](const SkRect& rect, SkPathDirection dir, unsigned startIndex) {
|
2015-11-19 17:47:12 +00:00
|
|
|
SkRRect rrect;
|
|
|
|
const SkVector radii[4] = { {15, 15}, {15, 15}, {15, 15}, {15, 15}};
|
|
|
|
rrect.setRectRadii(rect, radii);
|
2020-08-25 21:36:28 +00:00
|
|
|
return SkPath::RRect(rrect, dir, startIndex);
|
2015-11-19 17:47:12 +00:00
|
|
|
});
|
|
|
|
|
2019-11-22 18:34:02 +00:00
|
|
|
drawDirs(canvas, [](const SkRect& rect, SkPathDirection dir, unsigned startIndex) {
|
2015-11-19 17:47:12 +00:00
|
|
|
SkRRect rrect;
|
|
|
|
rrect.setRect(rect);
|
2020-08-25 21:36:28 +00:00
|
|
|
return SkPath::RRect(rrect, dir, startIndex);
|
2015-11-19 17:47:12 +00:00
|
|
|
});
|
|
|
|
|
2019-11-22 18:34:02 +00:00
|
|
|
drawDirs(canvas, [](const SkRect& rect, SkPathDirection dir, unsigned startIndex) {
|
2015-11-19 17:47:12 +00:00
|
|
|
SkRRect rrect;
|
|
|
|
rrect.setOval(rect);
|
2020-08-25 21:36:28 +00:00
|
|
|
return SkPath::RRect(rrect, dir, startIndex);
|
2015-11-19 17:47:12 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2016-09-01 18:24:54 +00:00
|
|
|
static constexpr int kImageWidth = 1200;
|
|
|
|
static constexpr int kImageHeight = 600;
|
2015-11-19 17:47:12 +00:00
|
|
|
|
|
|
|
SkPaint fDashPaint, fPointsPaint;
|
|
|
|
SkRect fRect;
|
|
|
|
|
|
|
|
void drawDirs(SkCanvas* canvas,
|
2019-11-22 18:34:02 +00:00
|
|
|
SkPath (*makePath)(const SkRect&, SkPathDirection, unsigned)) const {
|
|
|
|
drawOneColumn(canvas, SkPathDirection::kCW, makePath);
|
2015-11-19 17:47:12 +00:00
|
|
|
canvas->translate(kImageWidth / 10, 0);
|
2019-11-22 18:34:02 +00:00
|
|
|
drawOneColumn(canvas, SkPathDirection::kCCW, makePath);
|
2015-11-19 17:47:12 +00:00
|
|
|
canvas->translate(kImageWidth / 10, 0);
|
|
|
|
}
|
|
|
|
|
2019-11-22 18:34:02 +00:00
|
|
|
void drawOneColumn(SkCanvas* canvas, SkPathDirection dir,
|
|
|
|
SkPath (*makePath)(const SkRect&, SkPathDirection, unsigned)) const {
|
2015-11-19 17:47:12 +00:00
|
|
|
SkAutoCanvasRestore acr(canvas, true);
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < 8; ++i) {
|
|
|
|
const SkPath path = makePath(fRect, dir, i);
|
|
|
|
canvas->drawPath(path, fDashPaint);
|
|
|
|
|
|
|
|
const int n = path.countPoints();
|
|
|
|
SkAutoTArray<SkPoint> points(n);
|
|
|
|
path.getPoints(points.get(), n);
|
|
|
|
canvas->drawPoints(SkCanvas::kPoints_PointMode, n, points.get(), fPointsPaint);
|
|
|
|
|
|
|
|
canvas->translate(0, kImageHeight / 8);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = GM;
|
2015-11-19 17:47:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
DEF_GM( return new ContourStartGM(); )
|
|
|
|
|
|
|
|
} // namespace skiagm
|