Skip to content

Commit

Permalink
Adds new public method to make it easier to reuse Graphics objects
Browse files Browse the repository at this point in the history
  • Loading branch information
bigtimebuddy committed May 27, 2020
1 parent 0c7394b commit 9c9540e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
3 changes: 2 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

declare namespace PIXI {
export class SVG extends PIXI.Graphics {
constructor(svg:SVGSVGElement|SVGElement|string);
constructor(svg?:SVGSVGElement|SVGElement|string);
drawSVG(svg:SVGSVGElement|SVGElement|string): this;
}
}

Expand Down
18 changes: 17 additions & 1 deletion src/SVG.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,28 @@ import color from 'tinycolor2';
* @class SVG
* @extends PIXI.Graphics
* @memberof PIXI
* @param {SVGSVGElement|SVGElement|string} svg - Inline SVGElement `<svg>` or buffer.
* @param {SVGSVGElement|SVGElement|string} [svg] - Inline SVGElement `<svg>` or buffer.
*/
class SVG extends Graphics
{
constructor(svg)
{
super();

if (svg)
{
this.drawSVG(svg);
}
}

/**
* Draw an SVG element.
* @method PIXI.SVG#drawSVG
* @param {SVGSVGElement|SVGElement|string} svg - Inline SVGElement `<svg>` or buffer.
* @return {PIXI.SVG} Element suitable for chaining.
*/
drawSVG(svg)
{
if (typeof svg === 'string')
{
const div = document.createElement('div');
Expand All @@ -30,6 +44,8 @@ class SVG extends Graphics

this._svgFill(svg);
this._svgChildren(svg.children);

return this;
}

/**
Expand Down

0 comments on commit 9c9540e

Please sign in to comment.