skia2/include/core/SkPathBuilder.h
Mike Reed 92c33f329a document Make for paths, and move from pathbuilder into path
Change-Id: I812b5315e06e38ec2c812c76634fe07227a30b39
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/300356
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
2020-07-02 13:48:09 +00:00

97 lines
3.3 KiB
C++

/*
* Copyright 2015 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkPathBuilder_DEFINED
#define SkPathBuilder_DEFINED
#include "include/core/SkMatrix.h"
#include "include/core/SkPath.h"
#include "include/core/SkPathTypes.h"
#include "include/private/SkTDArray.h"
class SkPathBuilder {
public:
SkPathBuilder();
~SkPathBuilder();
SkPath snapshot(); // the builder is unchanged after returning this path
SkPath detach(); // the builder is reset to empty after returning this path
void setFillType(SkPathFillType ft) { fFillType = ft; }
void setIsVolatile(bool isVolatile) { fIsVolatile = isVolatile; }
SkPathBuilder& reset();
SkPathBuilder& moveTo(SkPoint pt);
SkPathBuilder& lineTo(SkPoint pt);
SkPathBuilder& quadTo(SkPoint pt1, SkPoint pt2);
SkPathBuilder& conicTo(SkPoint pt1, SkPoint pt2, SkScalar w);
SkPathBuilder& cubicTo(SkPoint pt1, SkPoint pt2, SkPoint pt3);
SkPathBuilder& close();
SkPathBuilder& moveTo(SkScalar x, SkScalar y) { return this->moveTo(SkPoint::Make(x, y)); }
SkPathBuilder& lineTo(SkScalar x, SkScalar y) { return this->lineTo(SkPoint::Make(x, y)); }
SkPathBuilder& quadTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2) {
return this->quadTo(SkPoint::Make(x1, y1), SkPoint::Make(x2, y2));
}
SkPathBuilder& quadTo(const SkPoint pts[2]) { return this->quadTo(pts[0], pts[1]); }
SkPathBuilder& conicTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar w) {
return this->conicTo(SkPoint::Make(x1, y1), SkPoint::Make(x2, y2), w);
}
SkPathBuilder& conicTo(const SkPoint pts[2], SkScalar w) {
return this->conicTo(pts[0], pts[1], w);
}
SkPathBuilder& cubicTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar x3, SkScalar y3) {
return this->cubicTo(SkPoint::Make(x1, y1), SkPoint::Make(x2, y2), SkPoint::Make(x3, y3));
}
SkPathBuilder& cubicTo(const SkPoint pts[3]) {
return this->cubicTo(pts[0], pts[1], pts[2]);
}
SkPathBuilder& addRect(const SkRect&, SkPathDirection, unsigned startIndex);
SkPathBuilder& addOval(const SkRect&, SkPathDirection, unsigned startIndex);
SkPathBuilder& addRRect(const SkRRect&, SkPathDirection, unsigned startIndex);
SkPathBuilder& addRect(const SkRect& rect, SkPathDirection dir = SkPathDirection::kCW) {
return this->addRect(rect, dir, 0);
}
SkPathBuilder& addOval(const SkRect& rect, SkPathDirection dir = SkPathDirection::kCW) {
return this->addOval(rect, dir, 0);
}
SkPathBuilder& addRRect(const SkRRect& rect, SkPathDirection dir = SkPathDirection::kCW) {
return this->addRRect(rect, dir, 0);
}
void incReserve(int extraPtCount, int extraVerbCount);
void incReserve(int extraPtCount) {
this->incReserve(extraPtCount, extraPtCount);
}
private:
SkTDArray<SkPoint> fPts;
SkTDArray<uint8_t> fVerbs;
SkTDArray<SkScalar> fConicWeights;
SkPathFillType fFillType;
bool fIsVolatile;
unsigned fSegmentMask;
SkPoint fLastMovePoint;
bool fNeedsMoveVerb;
int countVerbs() const { return fVerbs.count(); }
void ensureMove() {
if (fNeedsMoveVerb) {
this->moveTo(fLastMovePoint);
}
}
};
#endif