Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
removeChildAt(index)
{
const child = this.getChildAt(index);
// ensure child transform will be recalculated..
child.parent = null;
child.transform._parentID = -1;
removeItems(this.children, index, 1);
// ensure bounds will be recalculated
this._boundsID++;
// TODO - lets either do all callbacks or all events.. not both!
this.onChildrenChange(index);
child.emit('removed', this);
this.emit('childRemoved', child, this, index);
return child;
}
removeChildAt(index)
{
const child = this.getChildAt(index);
// ensure child transform will be recalculated..
child.parent = null;
child.transform._parentID = -1;
removeItems(this.children, index, 1);
// ensure bounds will be recalculated
this._boundsID++;
// TODO - lets either do all callbacks or all events.. not both!
this.onChildrenChange(index);
child.emit('removed', this);
this.emit('childRemoved', child, this, index);
return child;
}
}
// can be handy to know!
this.renderingToScreen = !renderTexture;
this.emit('prerender');
const rootResolution = this.resolution;
if (renderTexture)
{
renderTexture = renderTexture.baseTexture || renderTexture;
if (!renderTexture._canvasRenderTarget)
{
renderTexture._canvasRenderTarget = new CanvasRenderTarget(
renderTexture.width,
renderTexture.height,
renderTexture.resolution
);
renderTexture.resource = new resources.CanvasResource(renderTexture._canvasRenderTarget.canvas);
renderTexture.valid = true;
}
this.context = renderTexture._canvasRenderTarget.context;
this.resolution = renderTexture._canvasRenderTarget.resolution;
}
else
{
this.context = this.rootContext;
}
}
// can be handy to know!
this.renderingToScreen = !renderTexture;
this.emit('prerender');
const rootResolution = this.resolution;
if (renderTexture)
{
renderTexture = renderTexture.baseTexture || renderTexture;
if (!renderTexture._canvasRenderTarget)
{
renderTexture._canvasRenderTarget = new CanvasRenderTarget(
renderTexture.width,
renderTexture.height,
renderTexture.resolution
);
renderTexture.source = renderTexture._canvasRenderTarget.canvas;
renderTexture.valid = true;
}
this.context = renderTexture._canvasRenderTarget.context;
this.resolution = renderTexture._canvasRenderTarget.resolution;
}
else
{
this.context = this.rootContext;
}
static fromLoader(source, imageUrl, name)
{
// console.log('added from loader...')
const resource = new ImageResource(source);
resource.url = imageUrl;
// console.log('base resource ' + resource.width);
const baseTexture = new BaseTexture(resource, {
scaleMode: settings.SCALE_MODE,
resolution: getResolutionOfUrl(imageUrl),
});
const texture = new Texture(baseTexture);
// No name, use imageUrl instead
if (!name)
{
name = imageUrl;
}
// lets also add the frame to pixi's global cache for fromFrame and fromImage functions
BaseTexture.addToCache(texture.baseTexture, name);
Texture.addToCache(texture, name);
// also add references by url if they are different.
if (name !== imageUrl)
constructor(system, options)
{
super();
// Add the default render options
options = Object.assign({}, settings.RENDER_OPTIONS, options);
// Deprecation notice for renderer roundPixels option
if (options.roundPixels)
{
settings.ROUND_PIXELS = options.roundPixels;
deprecation('5.0.0', 'Renderer roundPixels option is deprecated, please use PIXI.settings.ROUND_PIXELS', 2);
}
/**
* The supplied constructor options.
*
* @member {Object}
* @readOnly
*/
this.options = options;
/**
* The type of the renderer.
*
* @member {number}
* @default PIXI.RENDERER_TYPE.UNKNOWN
* @see PIXI.RENDERER_TYPE
context.clearRect(0, 0, this.canvas.width, this.canvas.height);
context.font = this._font;
context.strokeStyle = style.stroke;
context.lineWidth = style.strokeThickness;
context.textBaseline = style.textBaseline;
context.lineJoin = style.lineJoin;
context.miterLimit = style.miterLimit;
let linePositionX;
let linePositionY;
if (style.dropShadow)
{
const dropShadowColor = style.dropShadowColor;
const rgb = hex2rgb(typeof dropShadowColor === 'number' ? dropShadowColor : string2hex(dropShadowColor));
context.shadowColor = `rgba(${rgb[0] * 255},${rgb[1] * 255},${rgb[2] * 255},${style.dropShadowAlpha})`;
context.shadowBlur = style.dropShadowBlur;
context.shadowOffsetX = Math.cos(style.dropShadowAngle) * style.dropShadowDistance;
context.shadowOffsetY = Math.sin(style.dropShadowAngle) * style.dropShadowDistance;
}
else
{
context.shadowColor = 0;
context.shadowBlur = 0;
context.shadowOffsetX = 0;
context.shadowOffsetY = 0;
}
// set canvas text styles
context.fillStyle = this._generateFillStyle(style, lines);
this.updateGraphics(graphics);
webGL = graphics._webGL[this.CONTEXT_UID];
}
// This could be speeded up for sure!
const shader = this.primitiveShader;
renderer.state.setBlendMode(graphics.blendMode);
for (let i = 0, n = webGL.data.length; i < n; i++)
{
webGLData = webGL.data[i];
shader.uniforms.translationMatrix = graphics.transform.worldTransform.toArray(true);
shader.uniforms.tint = hex2rgb(graphics.tint);
shader.uniforms.alpha = graphics.worldAlpha;
renderer.shader.bind(shader);
renderer.geometry.bind(webGLData.geometry);
if (webGLData.nativeLines)
{
renderer.geometry.draw(gl.LINES, webGLData.indices.length / 6);
}
else
{
renderer.geometry.draw(gl.TRIANGLE_STRIP, webGLData.indices.length);
}
}
}
const radius = rrectData.radius;
const recPoints = [];
recPoints.push(x, y + radius);
quadraticBezierCurve(x, y + height - radius, x, y + height, x + radius, y + height, recPoints);
quadraticBezierCurve(x + width - radius, y + height, x + width, y + height, x + width, y + height - radius, recPoints);
quadraticBezierCurve(x + width, y + radius, x + width, y, x + width - radius, y, recPoints);
quadraticBezierCurve(x + radius, y, x, y, x, y + radius + 0.0000000001, recPoints);
// this tiny number deals with the issue that occurs when points overlap and earcut fails to triangulate the item.
// TODO - fix this properly, this is not very elegant.. but it works for now.
if (graphicsData.fill)
{
const color = hex2rgb(graphicsData.fillColor);
const alpha = graphicsData.fillAlpha;
const r = color[0] * alpha;
const g = color[1] * alpha;
const b = color[2] * alpha;
const verts = webGLData.points;
const indices = webGLData.indices;
const vecPos = verts.length / 6;
const triangles = earcut(recPoints, null, 2);
for (let i = 0, j = triangles.length; i < j; i += 3)
{
indices.push(triangles[i] + vecPos);
setChildIndex(child, index)
{
if (index < 0 || index >= this.children.length)
{
throw new Error(`The index ${index} supplied is out of bounds ${this.children.length}`);
}
const currentIndex = this.getChildIndex(child);
removeItems(this.children, currentIndex, 1); // remove from old position
this.children.splice(index, 0, child); // add at new position
this.onChildrenChange(index);
}