var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
/**
* @module annie
*/
var annie;
(function (annie) {
/**
* 矢量对象
* @class annie.Shape
* @extends annie.Bitmap
* @since 1.0.0
* @public
*/
var Shape = /** @class */ (function (_super) {
__extends(Shape, _super);
function Shape() {
var _this = _super.call(this, null) || this;
//一个数组,每个元素也是一个数组[类型 0是属性,1是方法,名字 执行的属性或方法名,参数]
_this._command = [];
/**
* 径向渐变填充 一般给Annie2x用
* @method beginRadialGradientFill
* @param {Array} points 一组点
* @param {Array} colors 一组颜色值
* @param {Object} matrixDate 如果渐变填充有矩阵变形信息
* @public
* @since 1.0.0
* @return {void}
* @example
* var shape=new annie.Shape();
* shape.beginRadialGradientFill([100,100,100,100,100],[[0,"#00ff00",1],[1,"#000000",1]]);
* shape.drawRect(0,0,200,200);
* shape.endFill();
* s.addChild(shape);
*/
_this.beginRadialGradientFill = function (points, colors) {
this._fill(Shape.getGradientColor(points, colors));
};
/**
* 画径向渐变的线条 一般给Annie2x用
* @method beginRadialGradientStroke
* @param {Array} points 一组点
* @param {Array} colors 一组颜色值
* @param {number} lineWidth
* @param {string} cap 线头的形状 butt round square 默认 butt
* @param {string} join 线与线之间的交接处形状 bevel round miter 默认miter
* @param {number} miter 正数,规定最大斜接长度,如果斜接长度超过 miterLimit 的值,边角会以 lineJoin 的 "bevel" 类型来显示 默认10
* @public
* @since 1.0.0
* @return {void}
*/
_this.beginRadialGradientStroke = function (points, colors, lineWidth, cap, join, miter) {
if (lineWidth === void 0) { lineWidth = 1; }
if (cap === void 0) { cap = 0; }
if (join === void 0) { join = 0; }
if (miter === void 0) { miter = 10; }
this._stroke(Shape.getGradientColor(points, colors), lineWidth, cap, join, miter);
};
//是否矢量元素有更新
_this.a2x_ut = true;
var s = _this;
s._instanceType = "annie.Shape";
s.hitTestWithPixel = true;
s.bitmapData = document.createElement("canvas");
return _this;
}
/**
* 通过一系统参数获取生成颜色或渐变所需要的对象
* 一般给用户使用较少,Annie2x工具自动使用
* @method getGradientColor
* @static
* @param points
* @param colors
* @return {any}
* @since 1.0.0
* @public
*/
Shape.getGradientColor = function (points, colors) {
var colorObj;
var ctx = annie.DisplayObject["_canvas"].getContext("2d");
if (points.length == 4) {
colorObj = ctx.createLinearGradient(points[0], points[1], points[2], points[3]);
}
else {
colorObj = ctx.createRadialGradient(points[0], points[1], 0, points[2], points[3], points[4]);
}
for (var i = 0, l = colors.length; i < l; i++) {
colorObj.addColorStop(colors[i][0], Shape.getRGBA(colors[i][1], colors[i][2]));
}
return colorObj;
};
/**
* 设置位图填充时需要使用的方法,一般给用户使用较少,Annie2x工具自动使用
* @method getBitmapStyle
* @static
* @param {Image} image HTML Image元素
* @return {CanvasPattern}
* @public
* @since 1.0.0
*/
Shape.getBitmapStyle = function (image) {
var ctx = annie.DisplayObject["_canvas"].getContext("2d");
return ctx.createPattern(image, "repeat");
};
/**
* 通过24位颜色值和一个透明度值生成RGBA值
* @method getRGBA
* @static
* @public
* @since 1.0.0
* @param {string} color 字符串的颜色值,如:#33ffee
* @param {number} alpha 0-1区间的一个数据 0完全透明 1完全不透明
* @return {string}
*/
Shape.getRGBA = function (color, alpha) {
if (color.indexOf("0x") == 0) {
color = color.replace("0x", "#");
}
if (color.length < 7) {
color = "#000000";
}
if (alpha != 1) {
var r = parseInt("0x" + color.substr(1, 2));
var g = parseInt("0x" + color.substr(3, 2));
var b = parseInt("0x" + color.substr(5, 2));
color = "rgba(" + r + "," + g + "," + b + "," + alpha + ")";
}
return color;
};
/**
* 添加一条绘画指令,具体可以查阅Html Canvas画图方法
* @method addDraw
* @param {string} commandName ctx指令的方法名 如moveTo lineTo arcTo等
* @param {Array} params
* @public
* @since 1.0.0
* @return {void}
*/
Shape.prototype.addDraw = function (commandName, params) {
var s = this;
s._command[s._command.length] = [1, commandName, params];
};
/**
* 画一个带圆角的矩形
* @method drawRoundRect
* @param {number} x 点x值
* @param {number} y 点y值
* @param {number} w 宽
* @param {number} h 高
* @param {number} rTL 左上圆角半径
* @param {number} rTR 右上圆角半径
* @param {number} rBL 左下圆角半径
* @param {number} rBR 右上圆角半径
* @public
* @since 1.0.0
* @return {void}
*/
Shape.prototype.drawRoundRect = function (x, y, w, h, rTL, rTR, rBL, rBR) {
if (rTL === void 0) { rTL = 0; }
if (rTR === void 0) { rTR = 0; }
if (rBL === void 0) { rBL = 0; }
if (rBR === void 0) { rBR = 0; }
var max = (w < h ? w : h) / 2;
var mTL = 0, mTR = 0, mBR = 0, mBL = 0;
if (rTL < 0) {
rTL *= (mTL = -1);
}
if (rTL > max) {
rTL = max;
}
if (rTR < 0) {
rTR *= (mTR = -1);
}
if (rTR > max) {
rTR = max;
}
if (rBR < 0) {
rBR *= (mBR = -1);
}
if (rBR > max) {
rBR = max;
}
if (rBL < 0) {
rBL *= (mBL = -1);
}
if (rBL > max) {
rBL = max;
}
var c = this._command;
c[c.length] = [1, "moveTo", [x + w - rTR, y]];
c[c.length] = [1, "arcTo", [x + w + rTR * mTR, y - rTR * mTR, x + w, y + rTR, rTR]];
c[c.length] = [1, "lineTo", [x + w, y + h - rBR]];
c[c.length] = [1, "arcTo", [x + w + rBR * mBR, y + h + rBR * mBR, x + w - rBR, y + h, rBR]];
c[c.length] = [1, "lineTo", [x + rBL, y + h]];
c[c.length] = [1, "arcTo", [x - rBL * mBL, y + h + rBL * mBL, x, y + h - rBL, rBL]];
c[c.length] = [1, "lineTo", [x, y + rTL]];
c[c.length] = [1, "arcTo", [x - rTL * mTL, y - rTL * mTL, x + rTL, y, rTL]];
c[c.length] = [1, "closePath", []];
};
/**
* 绘画时移动到某一点
* @method moveTo
* @param {number} x
* @param {number} y
* @public
* @since 1.0.0
* @return {void}
*/
Shape.prototype.moveTo = function (x, y) {
this._command[this._command.length] = [1, "moveTo", [x, y]];
};
/**
* 从上一点画到某一点,如果没有设置上一点,则上一点默认为(0,0)
* @method lineTo
* @param {number} x
* @param {number} y
* @public
* @since 1.0.0
* @return {void}
*/
Shape.prototype.lineTo = function (x, y) {
this._command[this._command.length] = [1, "lineTo", [x, y]];
};
/**
* 从上一点画弧到某一点,如果没有设置上一点,则上一点默认为(0,0)
* @method arcTo
* @param {number} x
* @param {number} y
* @public
* @since 1.0.0
* @return {void}
*/
Shape.prototype.arcTo = function (x, y) {
this._command[this._command.length] = [1, "arcTo", [x, y]];
};
/**
* 二次贝赛尔曲线
* 从上一点画二次贝赛尔曲线到某一点,如果没有设置上一点,则上一占默认为(0,0)
* @method quadraticCurveTo
* @param {number} cpX 控制点X
* @param {number} cpX 控制点Y
* @param {number} x 终点X
* @param {number} y 终点Y
* @public
* @since 1.0.0
* @return {void}
*/
Shape.prototype.quadraticCurveTo = function (cpX, cpY, x, y) {
this._command[this._command.length] = [1, "quadraticCurveTo", [cpX, cpY, x, y]];
};
/**
* 三次贝赛尔曲线
* 从上一点画二次贝赛尔曲线到某一点,如果没有设置上一点,则上一占默认为(0,0)
* @method bezierCurveTo
* @param {number} cp1X 1控制点X
* @param {number} cp1Y 1控制点Y
* @param {number} cp2X 2控制点X
* @param {number} cp2Y 2控制点Y
* @param {number} x 终点X
* @param {number} y 终点Y
* @public
* @since 1.0.0
* @return {void}
*/
Shape.prototype.bezierCurveTo = function (cp1X, cp1Y, cp2X, cp2Y, x, y) {
this._command[this._command.length] = [1, "bezierCurveTo", [cp1X, cp1Y, cp2X, cp2Y, x, y]];
};
/**
* 闭合一个绘画路径
* @method closePath
* @public
* @since 1.0.0
* @return {void}
*/
Shape.prototype.closePath = function () {
this._command[this._command.length] = [1, "closePath", []];
};
/**
* 画一个矩形
* @method drawRect
* @param {number} x
* @param {number} y
* @param {number} w
* @param {number} h
* @public
* @since 1.0.0
* @return {void}
*/
Shape.prototype.drawRect = function (x, y, w, h) {
var c = this._command;
c[c.length] = [1, "moveTo", [x, y]];
c[c.length] = [1, "lineTo", [x + w, y]];
c[c.length] = [1, "lineTo", [x + w, y + h]];
c[c.length] = [1, "lineTo", [x, y + h]];
c[c.length] = [1, "closePath", []];
};
/**
* 画一个弧形
* @method drawArc
* @param {number} x 起始点x
* @param {number} y 起始点y
* @param {number} radius 半径
* @param {number} start 开始角度
* @param {number} end 结束角度
* @public
* @since 1.0.0
* @return {void}
*/
Shape.prototype.drawArc = function (x, y, radius, start, end) {
this._command[this._command.length] = [1, "arc", [x, y, radius, start / 180 * Math.PI, end / 180 * Math.PI]];
};
/**
* 画一个圆
* @method drawCircle
* @param {number} x 圆心x
* @param {number} y 圆心y
* @param {number} radius 半径
* @public
* @since 1.0.0
* @return {void}
*/
Shape.prototype.drawCircle = function (x, y, radius) {
this._command[this._command.length] = [1, "arc", [x, y, radius, 0, 2 * Math.PI]];
};
/**
* 画一个椭圆
* @method drawEllipse
* @param {number} x
* @param {number} y
* @param {number} w
* @param {number} h
* @public
* @since 1.0.0
* @return {void}
*/
Shape.prototype.drawEllipse = function (x, y, w, h) {
var k = 0.5522848;
var ox = (w / 2) * k;
var oy = (h / 2) * k;
var xe = x + w;
var ye = y + h;
var xm = x + w / 2;
var ym = y + h / 2;
var c = this._command;
c[c.length] = [1, "moveTo", [x, ym]];
c[c.length] = [1, "bezierCurveTo", [x, ym - oy, xm - ox, y, xm, y]];
c[c.length] = [1, "bezierCurveTo", [xm + ox, y, xe, ym - oy, xe, ym]];
c[c.length] = [1, "bezierCurveTo", [xe, ym + oy, xm + ox, ye, xm, ye]];
c[c.length] = [1, "bezierCurveTo", [xm - ox, ye, x, ym + oy, x, ym]];
};
/**
* 清除掉之前所有绘画的东西
* @method clear
* @public
* @since 1.0.0
* @return {void}
*/
Shape.prototype.clear = function () {
var s = this;
s._command = [];
s._texture = null;
s._bitmapData.width = 0;
s._bitmapData.height = 0;
s.a2x_ut = false;
s.clearBounds();
};
/**
* 开始绘画填充,如果想画的东西有颜色填充,一定要从此方法开始
* @method beginFill
* @param {string} color 颜色值 单色和RGBA格式
* @public
* @since 1.0.0
* @return {void}
*/
Shape.prototype.beginFill = function (color) {
this._fill(color);
};
/**
* 线性渐变填充 一般给Annie2x用
* @method beginLinearGradientFill
* @param {Array} points 一组点
* @param {Array} colors 一组颜色值
* @public
* @since 1.0.0
* @return {void}
* @example
* var shape=new annie.Shape();
* shape.beginLinearGradientFill([0,0,200,0],[[0,"#ff0000",1],[0.164706,"#ffff00",1],[0.364706,"#00ff00",1],[0.498039,"#00ffff",1],[0.666667,"#0000ff",1],[0.831373,"#ff00ff",1],[1,"#ff0000",1]]);
* shape.drawRect(0,0,200,200);
* shape.endFill();
* s.addChild(shape);
*/
Shape.prototype.beginLinearGradientFill = function (points, colors) {
this._fill(Shape.getGradientColor(points, colors));
};
/**
* 位图填充 一般给Annie2x用
* @method beginBitmapFill
* @param {Image} image
* @param { Array} matrix
* @public
* @since 1.0.0
* @return {void}
*/
Shape.prototype.beginBitmapFill = function (image, matrix) {
var s = this;
if (matrix) {
s._isBitmapFill = matrix;
}
s._fill(Shape.getBitmapStyle(image));
};
Shape.prototype._fill = function (fillStyle) {
var s = this;
var c = s._command;
c[c.length] = [0, "fillStyle", fillStyle];
c[c.length] = [1, "beginPath", []];
};
/**
* 给线条着色
* @method beginStroke
* @param {string} color 颜色值
* @param {number} lineWidth 宽度
* @param {number} cap 线头的形状 0 butt 1 round 2 square 默认 butt
* @param {number} join 线与线之间的交接处形状 0 miter 1 bevel 2 round 默认miter
* @param {number} miter 正数,规定最大斜接长度,如果斜接长度超过 miterLimit 的值,边角会以 lineJoin 的 "bevel" 类型来显示 默认10
* @public
* @since 1.0.0
* @return {void}
*/
Shape.prototype.beginStroke = function (color, lineWidth, cap, join, miter) {
if (lineWidth === void 0) { lineWidth = 1; }
if (cap === void 0) { cap = 0; }
if (join === void 0) { join = 0; }
if (miter === void 0) { miter = 0; }
this._stroke(color, lineWidth, cap, join, miter);
};
/**
* 画线性渐变的线条 一般给Annie2x用
* @method beginLinearGradientStroke
* @param {Array} points 一组点
* @param {Array} colors 一组颜色值
* @param {number} lineWidth
* @param {number} cap 线头的形状 0 butt 1 round 2 square 默认 butt
* @param {number} join 线与线之间的交接处形状 0 miter 1 bevel 2 round 默认miter
* @param {number} miter 正数,规定最大斜接长度,如果斜接长度超过 miterLimit 的值,边角会以 lineJoin 的 "bevel" 类型来显示 默认10
* @public
* @since 1.0.0
* @return {void}
*/
Shape.prototype.beginLinearGradientStroke = function (points, colors, lineWidth, cap, join, miter) {
if (lineWidth === void 0) { lineWidth = 1; }
if (cap === void 0) { cap = 0; }
if (join === void 0) { join = 0; }
if (miter === void 0) { miter = 10; }
this._stroke(Shape.getGradientColor(points, colors), lineWidth, cap, join, miter);
};
/**
* 线条位图填充 一般给Annie2x用
* @method beginBitmapStroke
* @param {Image} image
* @param {Array} matrix
* @param {number} lineWidth
* @param {string} cap 线头的形状 butt round square 默认 butt
* @param {string} join 线与线之间的交接处形状 bevel round miter 默认miter
* @param {number} miter 正数,规定最大斜接长度,如果斜接长度超过 miterLimit 的值,边角会以 lineJoin 的 "bevel" 类型来显示 默认10
* @public
* @since 1.0.0
* @return {void}
*/
Shape.prototype.beginBitmapStroke = function (image, matrix, lineWidth, cap, join, miter) {
if (lineWidth === void 0) { lineWidth = 1; }
if (cap === void 0) { cap = 0; }
if (join === void 0) { join = 0; }
if (miter === void 0) { miter = 10; }
var s = this;
if (matrix) {
s._isBitmapStroke = matrix;
}
s._stroke(Shape.getBitmapStyle(image), lineWidth, cap, join, miter);
};
Shape.prototype._stroke = function (strokeStyle, width, cap, join, miter) {
var c = this._command;
c[c.length] = [0, "lineWidth", width];
c[c.length] = [0, "lineCap", Shape._caps[cap]];
c[c.length] = [0, "lineJoin", Shape._joins[join]];
c[c.length] = [0, "miterLimit", miter];
c[c.length] = [0, "strokeStyle", strokeStyle];
c[c.length] = [1, "beginPath", []];
};
/**
* 结束填充
* @method endFill
* @public
* @since 1.0.0
* @return {void}
*/
Shape.prototype.endFill = function () {
var s = this;
var c = s._command;
var m = s._isBitmapFill;
if (m) {
c[c.length] = [2, "setTransform", m];
}
c[c.length] = ([1, "fill", []]);
if (m) {
s._isBitmapFill = null;
}
s.a2x_ut = true;
};
/**
* 设置虚线参数
* @method setLineDash
* @param {Array} data 一个长度为2的数组,第1个是虚线长度,第2个是虚线间隔,如果此参数为[]的空数组,则是清除虚线。
* 如[5,20]是画虚线,[]则是请除虚线,变为实线
* @since 2.0.2
* @return {void}
*/
Shape.prototype.setLineDash = function (data) {
if (data === void 0) { data = []; }
var c = this._command;
c[c.length] = [1, "setLineDash", [data, 0]];
};
/**
* 结束画线
* @method endStroke
* @public
* @since 1.0.0
* @return {void}
*/
Shape.prototype.endStroke = function () {
var s = this;
var c = s._command;
var m = s._isBitmapStroke;
if (m) {
//如果为2则还需要特别处理
c[c.length] = [2, "setTransform", m];
}
c[c.length] = ([1, "stroke", []]);
if (m) {
s._isBitmapStroke = null;
}
s.a2x_ut = true;
};
/**
* 解析一段路径 一般给Annie2x用
* @method decodePath
* @param {Array} data
* @public
* @since 1.0.0
* @return {void}
*/
Shape.prototype.decodePath = function (data) {
var s = this;
var instructions = ["moveTo", "lineTo", "quadraticCurveTo", "bezierCurveTo", "closePath"];
var count = data.length;
for (var i = 0; i < count; i++) {
if (data[i] == 0 || data[i] == 1) {
s.addDraw(instructions[data[i]], [data[i + 1], data[i + 2]]);
i += 2;
}
else {
s.addDraw(instructions[data[i]], [data[i + 1], data[i + 2], data[i + 3], data[i + 4]]);
i += 4;
}
}
s.a2x_ut = true;
};
;
Shape.prototype._updateMatrix = function (isOffCanvas) {
if (isOffCanvas === void 0) { isOffCanvas = false; }
var s = this;
if (s.a2x_ut) {
var texture = s._bitmapData;
var ctx = texture.getContext("2d");
s.a2x_ut = false;
//更新矢量
var cLen = s._command.length;
var leftX = void 0;
var leftY = void 0;
var buttonRightX = void 0;
var buttonRightY = void 0;
var i = void 0;
if (cLen > 0) {
//确定是否有数据,如果有数据的话就计算出缓存图的宽和高
var data = void 0;
var lastX = 0;
var lastY = 0;
var lineWidth = 0;
for (i = 0; i < cLen; i++) {
data = s._command[i];
if (data[0] == 1) {
if (data[1] == "moveTo" || data[1] == "lineTo" || data[1] == "arcTo" || data[1] == "bezierCurveTo") {
if (leftX == undefined) {
leftX = data[2][0];
}
if (leftY == undefined) {
leftY = data[2][1];
}
if (buttonRightX == undefined) {
buttonRightX = data[2][0];
}
if (buttonRightY == undefined) {
buttonRightY = data[2][1];
}
if (data[1] == "bezierCurveTo") {
leftX = Math.min(leftX, data[2][0], data[2][2], data[2][4]);
leftY = Math.min(leftY, data[2][1], data[2][3], data[2][5]);
buttonRightX = Math.max(buttonRightX, data[2][0], data[2][2], data[2][4]);
buttonRightY = Math.max(buttonRightY, data[2][1], data[2][3], data[2][5]);
lastX = data[2][4];
lastY = data[2][5];
}
else {
leftX = Math.min(leftX, data[2][0]);
leftY = Math.min(leftY, data[2][1]);
buttonRightX = Math.max(buttonRightX, data[2][0]);
buttonRightY = Math.max(buttonRightY, data[2][1]);
lastX = data[2][0];
lastY = data[2][1];
}
}
else if (data[1] == "quadraticCurveTo") {
//求中点
var mid1X = (lastX + data[2][0]) * 0.5;
var mid1Y = (lastY + data[2][1]) * 0.5;
var mid2X = (data[2][0] + data[2][2]) * 0.5;
var mid2Y = (data[2][1] + data[2][3]) * 0.5;
if (leftX == undefined) {
leftX = mid1X;
}
if (leftY == undefined) {
leftY = mid1Y;
}
if (buttonRightX == undefined) {
buttonRightX = mid1X;
}
if (buttonRightY == undefined) {
buttonRightY = mid1Y;
}
leftX = Math.min(leftX, mid1X, mid2X, data[2][2]);
leftY = Math.min(leftY, mid1Y, mid2Y, data[2][3]);
buttonRightX = Math.max(buttonRightX, mid1X, mid2X, data[2][2]);
buttonRightY = Math.max(buttonRightY, mid1Y, mid2Y, data[2][3]);
lastX = data[2][2];
lastY = data[2][3];
}
else if (data[1] == "arc") {
var yuanPointX = data[2][0];
var yuanPointY = data[2][1];
var radio = data[2][2];
var yuanLeftX = yuanPointX - radio;
var yuanLeftY = yuanPointY - radio;
var yuanBRX = yuanPointX + radio;
var yuanBRY = yuanPointY + radio;
if (leftX == undefined) {
leftX = yuanLeftX;
}
if (leftY == undefined) {
leftY = yuanLeftY;
}
if (buttonRightX == undefined) {
buttonRightX = yuanBRX;
}
if (buttonRightY == undefined) {
buttonRightY = yuanBRY;
}
leftX = Math.min(leftX, yuanLeftX);
leftY = Math.min(leftY, yuanLeftY);
buttonRightX = Math.max(buttonRightX, yuanBRX);
buttonRightY = Math.max(buttonRightY, yuanBRY);
}
}
else {
if (data[1] == "lineWidth") {
if (lineWidth < data[2]) {
lineWidth = data[2];
}
}
}
}
if (leftX != undefined || lineWidth > 0) {
if (leftX == undefined) {
leftX = 0;
leftY = 0;
}
leftX -= 2 + lineWidth;
leftY -= 2 + lineWidth;
buttonRightX += 2 + lineWidth;
buttonRightY += 2 + lineWidth;
var width = buttonRightX - leftX;
var height = buttonRightY - leftY;
///////////////////////////是否是遮罩对象,如果是遮罩对象///////////////////////////
s._offsetX = leftX;
s._offsetY = leftY;
s._bounds.x = leftX;
s._bounds.y = leftY;
height = Math.ceil(height);
width = Math.ceil(width);
texture.width = width;
texture.height = height;
texture.style.width = (width / annie.devicePixelRatio) + "px";
texture.style.height = (height / annie.devicePixelRatio) + "px";
ctx.clearRect(0, 0, width, height);
ctx.setTransform(1, 0, 0, 1, -leftX, -leftY);
///////////////////////////
s._draw(ctx);
///////////////////////////
}
}
s._texture = texture;
if (s._filters.length > 0) {
s.a2x_uf = true;
}
}
_super.prototype._updateMatrix.call(this, isOffCanvas);
};
Shape.prototype._draw = function (ctx, isMask) {
if (isMask === void 0) { isMask = false; }
var s = this;
var com = s._command;
var cLen = com.length;
var data;
var leftX = s._offsetX;
var leftY = s._offsetY;
var isStroke = false;
for (var i = 0; i < cLen; i++) {
data = com[i];
if (data[0] > 0) {
var paramsLen = data[2].length;
if (isMask && (isStroke || data[1] == "beginPath" || data[1] == "closePath" || paramsLen == 0))
continue;
if (paramsLen == 0) {
ctx[data[1]]();
}
else if (paramsLen == 2) {
ctx[data[1]](data[2][0], data[2][1]);
}
else if (paramsLen == 4) {
ctx[data[1]](data[2][0], data[2][1], data[2][2], data[2][3]);
}
else if (paramsLen == 5) {
ctx[data[1]](data[2][0], data[2][1], data[2][2], data[2][3], data[2][4]);
}
else if (paramsLen == 6) {
var lx = data[2][4];
var ly = data[2][5];
if (data[0] == 2) {
//位图填充
lx -= leftX;
ly -= leftY;
}
ctx[data[1]](data[2][0], data[2][1], data[2][2], data[2][3], lx, ly);
}
}
else {
if (isMask) {
if (data[1] == "strokeStyle") {
isStroke = true;
}
else if (data[1] == "fillStyle") {
isStroke = false;
}
}
else {
ctx[data[1]] = data[2];
}
}
}
};
/**
* 如果有的话,改变矢量对象的边框或者填充的颜色.
* @method changeColor
* @param {Object} infoObj
* @param {string|any} infoObj.fillColor 填充颜色值,如"#fff" 或者 "rgba(255,255,255,1)"或者是annie.Shape.getGradientColor()方法返回的渐变对象;
* @param {string} infoObj.strokeColor 线条颜色值,如"#fff" 或者 "rgba(255,255,255,1)";
* @param {number} infoObj.lineWidth 线条的粗细,如"1,2,3...";
* @public
* @since 1.0.2
* @return {void}
*/
Shape.prototype.changeColor = function (infoObj) {
var s = this;
var cLen = s._command.length;
var c = s._command;
for (var i = 0; i < cLen; i++) {
if (c[i][0] == 0) {
if (c[i][1] == "fillStyle" && infoObj.fillColor && c[i][2] != infoObj.fillColor) {
c[i][2] = infoObj.fillColor;
s.a2x_ut = true;
}
if (c[i][1] == "strokeStyle" && infoObj.strokeColor && c[i][2] != infoObj.strokeColor) {
c[i][2] = infoObj.strokeColor;
s.a2x_ut = true;
}
if (c[i][1] == "lineWidth" && infoObj.lineWidth && c[i][2] != infoObj.lineWidth) {
c[i][2] = infoObj.lineWidth;
s.a2x_ut = true;
}
}
}
};
Shape.prototype.destroy = function () {
//清除相应的数据引用
var s = this;
s._command = null;
s._isBitmapStroke = null;
s._isBitmapFill = null;
_super.prototype.destroy.call(this);
};
Shape._caps = ["butt", "round", "square"];
Shape._joins = ["miter", "round", "bevel"];
return Shape;
}(annie.Bitmap));
annie.Shape = Shape;
})(annie || (annie = {}));