var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
/**
* @module annieUI
*/
var annieUI;
(function (annieUI) {
/**
* 刮刮卡类
* @class annieUI.ScratchCard
* @public
* @extends annie.DrawingBoard
* @since 1.1.1
*/
var ScratchCard = (function (_super) {
__extends(ScratchCard, _super);
//Events
/**
* annie.ScratchCard 刮刮卡事件,刮了多少,一个百分比
* @event annie.Event.ON_DRAW_PERCENT
* @since 1.0.9
*
*/
/**
* 构造函数
* 请监听 annie.Event.ON_DRAW_PERCENT事件来判断刮完多少百分比了。
* @method ScratchCard
* @param width 宽
* @param height 高
* @param frontColorObj 没刮开之前的图,可以为单色,也可以为位图填充。一般是用位图填充,如果生成位图填充,请自行复习canvas位图填充
* @param backColorObj 被刮开之后的图,可以为单色,也可以为位图填充。一般是用位图填充,如果生成位图填充,请自行复习canvas位图填充
* @param drawRadius 刮刮卡刮的时候的半径,默认为50
*/
function ScratchCard(width, height, frontColorObj, backColorObj, drawRadius) {
if (drawRadius === void 0) { drawRadius = 50; }
_super.call(this, width, height, frontColorObj);
this._drawList = [];
this._totalDraw = 1;
this._currentDraw = 0;
var s = this;
s._instanceType = "annieUI.ScratchCard";
s.drawColor = backColorObj;
s.drawRadius = drawRadius;
s.addEventListener(annie.MouseEvent.MOUSE_MOVE, function (e) {
if (s._isMouseDown) {
//通过移动,计算刮开的面积
var dw = Math.floor(e.localX / s._drawRadius);
var dh = Math.floor(e.localY / s._drawRadius);
if (s._drawList[dw] && s._drawList[dw][dh]) {
s._drawList[dw][dh] = false;
s._currentDraw++;
//抛事件
var per = Math.floor(s._currentDraw / s._totalDraw * 100);
s.dispatchEvent("onDrawPercent", { per: per });
}
}
});
}
/**
* 重置刮刮卡
* @method reset
* @param frontColorObj 没刮开之前的图,可以为单色,也可以为位图填充。赋值为""会用之前已设置的
* @param backColorObj 被刮开之后的图,可以为单色,也可以为位图填充。赋值为""会用之前已设置的
* @since 1.1.1
* @public
*/
ScratchCard.prototype.reset = function (frontColorObj, backColorObj) {
if (frontColorObj === void 0) { frontColorObj = ""; }
if (backColorObj === void 0) { backColorObj = ""; }
_super.prototype.reset.call(this, frontColorObj);
var s = this;
if (s._drawList) {
if (backColorObj != "") {
s.drawColor = backColorObj;
}
s._currentDraw = 0;
var dw = Math.floor(s._bitmapData.width / s._drawRadius);
var dh = Math.floor(s._bitmapData.height / s._drawRadius);
s._totalDraw = dw * dh;
for (var i = 0; i < dw; i++) {
s._drawList[i] = [];
for (var j = 0; j < dh; j++) {
s._drawList[i][j] = true;
}
}
}
};
/**
* 撤销步骤 没有任何功能,只是把从基类中的代码移除,调用不会产生任何效果
* @method cancel
* @param step
* @public
* @since 1.1.1
* @return {boolean}
*/
ScratchCard.prototype.cancel = function (step) {
if (step === void 0) { step = 0; }
console.log("no support");
return false;
};
Object.defineProperty(ScratchCard.prototype, "drawRadius", {
set: function (value) {
var s = this;
s._drawRadius = value;
var dw = Math.floor(s._bitmapData.width / s._drawRadius);
var dh = Math.floor(s._bitmapData.height / s._drawRadius);
s._totalDraw = dw * dh;
for (var i = 0; i < dw; i++) {
s._drawList[i] = [];
for (var j = 0; j < dh; j++) {
s._drawList[i][j] = true;
}
}
},
enumerable: true,
configurable: true
});
ScratchCard.prototype.destroy = function () {
var s = this;
s._drawList = null;
_super.prototype.destroy.call(this);
};
return ScratchCard;
}(annieUI.DrawingBoard));
annieUI.ScratchCard = ScratchCard;
})(annieUI || (annieUI = {}));