Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkSVGCircle.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2016 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
12
13SkSVGCircle::SkSVGCircle() : INHERITED(SkSVGTag::kCircle) {}
14
15bool SkSVGCircle::parseAndSetAttribute(const char* n, const char* v) {
17 this->setCx(SkSVGAttributeParser::parse<SkSVGLength>("cx", n, v)) ||
18 this->setCy(SkSVGAttributeParser::parse<SkSVGLength>("cy", n, v)) ||
19 this->setR(SkSVGAttributeParser::parse<SkSVGLength>("r", n, v));
20}
21
22std::tuple<SkPoint, SkScalar> SkSVGCircle::resolve(const SkSVGLengthContext& lctx) const {
24 const auto cy = lctx.resolve(fCy, SkSVGLengthContext::LengthType::kVertical);
25 const auto r = lctx.resolve(fR , SkSVGLengthContext::LengthType::kOther);
26
27 return std::make_tuple(SkPoint::Make(cx, cy), r);
28}
30 const SkPaint& paint, SkPathFillType) const {
32 SkScalar r;
33 std::tie(pos, r) = this->resolve(lctx);
34
35 if (r > 0) {
36 canvas->drawCircle(pos.x(), pos.y(), r, paint);
37 }
38}
39
42 SkScalar r;
43 std::tie(pos, r) = this->resolve(ctx.lengthContext());
44
45 SkPath path = SkPath::Circle(pos.x(), pos.y(), r);
46 this->mapToParent(&path);
47
48 return path;
49}
50
52 const auto [pos, r] = this->resolve(ctx.lengthContext());
53 return SkRect::MakeXYWH(pos.fX - r, pos.fY - r, 2 * r, 2 * r);
54}
SkPoint pos
SkPathFillType
Definition SkPathTypes.h:11
#define INHERITED(method,...)
SkSVGTag
Definition SkSVGNode.h:23
void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint &paint)
static SkPath Circle(SkScalar center_x, SkScalar center_y, SkScalar radius, SkPathDirection dir=SkPathDirection::kCW)
Definition SkPath.cpp:3530
void onDraw(SkCanvas *, const SkSVGLengthContext &, const SkPaint &, SkPathFillType) const override
SkRect onObjectBoundingBox(const SkSVGRenderContext &) const override
SkPath onAsPath(const SkSVGRenderContext &) const override
bool parseAndSetAttribute(const char *, const char *) override
SkScalar resolve(const SkSVGLength &, LengthType) const
virtual bool parseAndSetAttribute(const char *name, const char *value)
Definition SkSVGNode.cpp:90
const SkSVGLengthContext & lengthContext() const
void mapToParent(SkPath *) const
const Paint & paint
float SkScalar
Definition extension.cpp:12
float fX
x-axis value
static constexpr SkPoint Make(float x, float y)
float fY
y-axis value
constexpr float y() const
constexpr float x() const
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition SkRect.h:659