175 lines
12 KiB
JavaScript
175 lines
12 KiB
JavaScript
shadow$provide.module$node_modules$pixi_DOT_js$lib$scene$graphics$canvas$CanvasGraphicsAdaptor = function(global, require, module, exports) {
|
|
function buildShapePath(context, shape) {
|
|
switch(shape.type) {
|
|
case "rectangle":
|
|
context.rect(shape.x, shape.y, shape.width, shape.height);
|
|
break;
|
|
case "roundedRectangle":
|
|
var x = shape.x, y = shape.y, width = shape.width, height = shape.height;
|
|
shape = shape.radius;
|
|
shape = Math.max(0, Math.min(shape, Math.min(width, height) / 2));
|
|
context.moveTo(x + shape, y);
|
|
context.lineTo(x + width - shape, y);
|
|
context.quadraticCurveTo(x + width, y, x + width, y + shape);
|
|
context.lineTo(x + width, y + height - shape);
|
|
context.quadraticCurveTo(x + width, y + height, x + width - shape, y + height);
|
|
context.lineTo(x + shape, y + height);
|
|
context.quadraticCurveTo(x, y + height, x, y + height - shape);
|
|
context.lineTo(x, y + shape);
|
|
context.quadraticCurveTo(x, y, x + shape, y);
|
|
break;
|
|
case "circle":
|
|
context.arc(shape.x, shape.y, shape.radius, 0, 2 * Math.PI);
|
|
break;
|
|
case "ellipse":
|
|
context.ellipse ? context.ellipse(shape.x, shape.y, shape.halfWidth, shape.halfHeight, 0, 0, 2 * Math.PI) : (context.save(), context.translate(shape.x, shape.y), context.scale(shape.halfWidth, shape.halfHeight), context.arc(0, 0, 1, 0, 2 * Math.PI), context.restore());
|
|
break;
|
|
case "triangle":
|
|
context.moveTo(shape.x, shape.y);
|
|
context.lineTo(shape.x2, shape.y2);
|
|
context.lineTo(shape.x3, shape.y3);
|
|
context.closePath();
|
|
break;
|
|
default:
|
|
if (x = shape.points, x?.length) {
|
|
context.moveTo(x[0], x[1]);
|
|
for (y = 2; y < x.length; y += 2) {
|
|
context.lineTo(x[y], x[y + 1]);
|
|
}
|
|
shape.closePath && context.closePath();
|
|
}
|
|
}
|
|
}
|
|
global = require("module$node_modules$pixi_DOT_js$lib$extensions$Extensions");
|
|
var groupD8 = require("module$node_modules$pixi_DOT_js$lib$maths$matrix$groupD8");
|
|
module = require("module$node_modules$pixi_DOT_js$lib$maths$matrix$Matrix");
|
|
var canvasUtils = require("module$node_modules$pixi_DOT_js$lib$rendering$renderers$canvas$utils$canvasUtils"), Texture = require("module$node_modules$pixi_DOT_js$lib$rendering$renderers$shared$texture$Texture"), getGlobalMixin = require("module$node_modules$pixi_DOT_js$lib$scene$container$container_mixins$getGlobalMixin"), multiplyHexColors = require("module$node_modules$pixi_DOT_js$lib$scene$container$utils$multiplyHexColors"), buildLine = require("module$node_modules$pixi_DOT_js$lib$scene$graphics$shared$buildCommands$buildLine"),
|
|
FillGradient = require("module$node_modules$pixi_DOT_js$lib$scene$graphics$shared$fill$FillGradient"), FillPattern = require("module$node_modules$pixi_DOT_js$lib$scene$graphics$shared$fill$FillPattern"), buildContextBatches = require("module$node_modules$pixi_DOT_js$lib$scene$graphics$shared$utils$buildContextBatches"), generateTextureFillMatrix = require("module$node_modules$pixi_DOT_js$lib$scene$graphics$shared$utils$generateTextureFillMatrix");
|
|
"use strict";
|
|
const tempMatrix = new module.Matrix(), tempTextureMatrix = new module.Matrix(), tempGradientMatrix = new module.Matrix(), tempPatternMatrix = new module.Matrix();
|
|
class CanvasGraphicsAdaptor {
|
|
constructor() {
|
|
this.shader = null;
|
|
}
|
|
contextChange(renderer) {
|
|
}
|
|
execute(graphicsPipe, renderable) {
|
|
var renderer = graphicsPipe.renderer;
|
|
graphicsPipe = renderer.canvasContext;
|
|
const context = graphicsPipe.activeContext, baseTransform = renderable.groupTransform;
|
|
var globalColor = renderer.globalUniforms.globalUniformData?.worldColor ?? 4294967295, groupColorAlpha = renderable.groupColorAlpha;
|
|
const groupAlpha = (globalColor >>> 24 & 255) / 255 * ((groupColorAlpha >>> 24 & 255) / 255) * (renderer.filter?.alphaMultiplier ?? 1);
|
|
if (!(0 >= groupAlpha)) {
|
|
globalColor = getGlobalMixin.bgr2rgb(multiplyHexColors.multiplyHexColors(groupColorAlpha & 16777215, globalColor & 16777215));
|
|
renderer = renderer._roundPixels | renderable._roundPixels;
|
|
context.save();
|
|
graphicsPipe.setContextTransform(baseTransform, 1 === renderer);
|
|
graphicsPipe.setBlendMode(renderable.groupBlendMode);
|
|
renderable = renderable.context.instructions;
|
|
for (groupColorAlpha = 0; groupColorAlpha < renderable.length; groupColorAlpha++) {
|
|
var instruction = renderable[groupColorAlpha];
|
|
if ("texture" === instruction.action) {
|
|
var data2 = instruction.data, source = (instruction = data2.image) ? canvasUtils.canvasUtils.getCanvasSource(instruction) : null;
|
|
if (source) {
|
|
var alpha2 = data2.alpha * groupAlpha;
|
|
if (!(0 >= alpha2)) {
|
|
var tint2 = multiplyHexColors.multiplyHexColors(data2.style, globalColor);
|
|
context.globalAlpha = alpha2;
|
|
alpha2 = source;
|
|
16777215 !== tint2 && (alpha2 = canvasUtils.canvasUtils.getTintedCanvas({texture:instruction}, tint2));
|
|
var frame = instruction.frame, resolution = instruction.source._resolution ?? instruction.source.resolution ?? 1;
|
|
tint2 = frame.x * resolution;
|
|
var sy = frame.y * resolution, sw = frame.width * resolution;
|
|
frame = frame.height * resolution;
|
|
alpha2 !== source && (sy = tint2 = 0);
|
|
var hasTransform = (resolution = data2.transform) && !resolution.isIdentity();
|
|
instruction = instruction.rotate;
|
|
hasTransform || instruction ? (tempMatrix.copyFrom(baseTransform), hasTransform && tempMatrix.append(resolution), instruction && groupD8.groupD8.matrixAppendRotationInv(tempMatrix, instruction, data2.dx, data2.dy, data2.dw, data2.dh), graphicsPipe.setContextTransform(tempMatrix, 1 === renderer)) : graphicsPipe.setContextTransform(baseTransform, 1 === renderer);
|
|
context.drawImage(alpha2, tint2, sy, alpha2 === source ? sw : alpha2.width, alpha2 === source ? frame : alpha2.height, instruction ? 0 : data2.dx, instruction ? 0 : data2.dy, data2.dw, data2.dh);
|
|
(hasTransform || instruction) && graphicsPipe.setContextTransform(baseTransform, 1 === renderer);
|
|
}
|
|
}
|
|
} else {
|
|
if (tint2 = instruction.data, alpha2 = tint2?.path?.shapePath, alpha2?.shapePrimitives?.length && (data2 = tint2.style, source = multiplyHexColors.multiplyHexColors(data2.color, globalColor), sy = data2.alpha * groupAlpha, !(0 >= sy))) {
|
|
for (instruction = "stroke" === instruction.action, context.globalAlpha = sy, instruction && (sy = data2, context.lineWidth = sy.width, context.lineCap = sy.cap, context.lineJoin = sy.join, context.miterLimit = sy.miterLimit), alpha2 = alpha2.shapePrimitives, !instruction && tint2.hole?.shapePath?.shapePrimitives?.length && (alpha2[alpha2.length - 1].holes = tint2.hole.shapePath.shapePrimitives), tint2 = 0; tint2 < alpha2.length; tint2++) {
|
|
if (sw = alpha2[tint2], sw?.shape) {
|
|
sy = (frame = sw.transform) && !frame.isIdentity();
|
|
resolution = "global" === data2.textureSpace ? frame : null;
|
|
resolution = data2.texture && data2.texture !== Texture.Texture.WHITE ? generateTextureFillMatrix.generateTextureMatrix(tempTextureMatrix, data2, sw.shape, resolution) : null;
|
|
hasTransform = sy ? tempGradientMatrix.copyFrom(baseTransform).append(frame) : baseTransform;
|
|
a: {
|
|
var fill = data2.fill;
|
|
if (fill instanceof FillGradient.FillGradient) {
|
|
fill.buildGradient();
|
|
const gradientTexture = fill.texture;
|
|
if (gradientTexture) {
|
|
var pattern = canvasUtils.canvasUtils.getTintedPattern(gradientTexture, source);
|
|
resolution = resolution ? tempPatternMatrix.copyFrom(resolution).scale(gradientTexture.source.pixelWidth, gradientTexture.source.pixelHeight) : tempPatternMatrix.copyFrom(fill.transform);
|
|
hasTransform && !data2.textureSpace && resolution.append(hasTransform);
|
|
canvasUtils.canvasUtils.applyPatternTransform(pattern, resolution);
|
|
resolution = pattern;
|
|
break a;
|
|
}
|
|
}
|
|
fill instanceof FillPattern.FillPattern ? (resolution = canvasUtils.canvasUtils.getTintedPattern(fill.texture, source), canvasUtils.canvasUtils.applyPatternTransform(resolution, fill.transform, !1)) : (fill = data2.texture) && fill !== Texture.Texture.WHITE ? fill.source.resource ? (hasTransform = canvasUtils.canvasUtils.getTintedPattern(fill, source), resolution = resolution ? tempPatternMatrix.copyFrom(resolution).scale(fill.source.pixelWidth, fill.source.pixelHeight) : data2.matrix,
|
|
canvasUtils.canvasUtils.applyPatternTransform(hasTransform, resolution), resolution = hasTransform) : resolution = "#808080" : resolution = `#${(source & 16777215).toString(16).padStart(6, "0")}`;
|
|
}
|
|
hasTransform = resolution;
|
|
sy && (context.save(), context.transform(frame.a, frame.b, frame.c, frame.d, frame.tx, frame.ty));
|
|
if (instruction) {
|
|
if (fill = data2, 0.5 === fill.alignment || fill.pixelLine) {
|
|
context.strokeStyle = hasTransform, context.beginPath(), buildShapePath(context, sw.shape), context.stroke();
|
|
} else {
|
|
if (pattern = [], frame = [], resolution = [], buildContextBatches.shapeBuilders[sw.shape.type]?.build(sw.shape, pattern)) {
|
|
buildLine.buildLine(pattern, fill, !1, sw.shape.closePath ?? !0, frame, resolution);
|
|
context.fillStyle = hasTransform;
|
|
context.beginPath();
|
|
for (sw = 0; sw < resolution.length; sw += 3) {
|
|
hasTransform = 2 * resolution[sw], fill = 2 * resolution[sw + 1], pattern = 2 * resolution[sw + 2], context.moveTo(frame[hasTransform], frame[hasTransform + 1]), context.lineTo(frame[fill], frame[fill + 1]), context.lineTo(frame[pattern], frame[pattern + 1]), context.closePath();
|
|
}
|
|
context.fill();
|
|
} else {
|
|
context.strokeStyle = hasTransform, context.beginPath(), buildShapePath(context, sw.shape), context.stroke();
|
|
}
|
|
}
|
|
} else {
|
|
context.fillStyle = hasTransform;
|
|
context.beginPath();
|
|
buildShapePath(context, sw.shape);
|
|
frame = context;
|
|
sw = sw.holes;
|
|
if (sw?.length) {
|
|
for (resolution = 0; resolution < sw.length; resolution++) {
|
|
if (hasTransform = sw[resolution], hasTransform?.shape) {
|
|
if (pattern = (fill = hasTransform.transform) && !fill.isIdentity()) {
|
|
frame.save(), frame.transform(fill.a, fill.b, fill.c, fill.d, fill.tx, fill.ty);
|
|
}
|
|
buildShapePath(frame, hasTransform.shape);
|
|
pattern && frame.restore();
|
|
}
|
|
}
|
|
sw = !0;
|
|
} else {
|
|
sw = !1;
|
|
}
|
|
sw ? context.fill("evenodd") : context.fill();
|
|
}
|
|
sy && context.restore();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
context.restore();
|
|
}
|
|
}
|
|
destroy() {
|
|
this.shader = null;
|
|
}
|
|
}
|
|
CanvasGraphicsAdaptor.extension = {type:[global.ExtensionType.CanvasPipesAdaptor], name:"graphics"};
|
|
exports.CanvasGraphicsAdaptor = CanvasGraphicsAdaptor;
|
|
};
|
|
|
|
//# sourceMappingURL=module$node_modules$pixi_DOT_js$lib$scene$graphics$canvas$CanvasGraphicsAdaptor.js.map
|