var __reflect = (this && this.__reflect) || function (p, c, t) {
p.__class__ = c, t ? t.push(c) : t = [c], p.__types__ = p.__types__ ? t.concat(p.__types__) : t;
};
var __extends = (this && this.__extends) || (function () {
var 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 function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
//////////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2014-present, Egret Technology.
// All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of the Egret nor the
// names of its contributors may be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////////////
var egret;
(function (egret) {
var web;
(function (web) {
/**
* @private
*/
var WebFps = (function (_super) {
__extends(WebFps, _super);
function WebFps(stage, showFPS, showLog, logFilter, styles) {
var _this = _super.call(this) || this;
_this.showPanle = true;
_this.fpsHeight = 0;
_this.WIDTH = 101;
_this.HEIGHT = 20;
_this.bgCanvasColor = "#18304b";
_this.fpsFrontColor = "#18fefe";
_this.WIDTH_COST = 33;
_this.cost1Color = "#18fefe";
_this.cost2Color = "#ffff00";
_this.cost3Color = "#ff0000";
_this.arrFps = [];
_this.arrCost = [];
_this.arrLog = [];
if (showFPS || showLog) {
if (egret.Capabilities.renderMode == 'canvas') {
_this.renderMode = "Canvas";
}
else {
_this.renderMode = "WebGL";
}
_this.panelX = styles["x"] === undefined ? 0 : parseInt(styles['x']);
_this.panelY = styles["y"] === undefined ? 0 : parseInt(styles['y']);
_this.fontColor = styles["textColor"] === undefined ? '#ffffff' : styles['textColor'].replace("0x", "#");
_this.fontSize = styles["size"] === undefined ? 12 : parseInt(styles['size']);
if (egret.Capabilities.isMobile) {
_this.fontSize -= 2;
}
var all = document.createElement('div');
all.style.position = 'absolute';
all.style.background = "rgba(0,0,0," + styles['bgAlpha'] + ")";
all.style.left = _this.panelX + 'px';
all.style.top = _this.panelY + 'px';
all.style.pointerEvents = 'none';
document.body.appendChild(all);
var container = document.createElement('div');
container.style.color = _this.fontColor;
container.style.fontSize = _this.fontSize + 'px';
container.style.lineHeight = _this.fontSize + 'px';
container.style.margin = '4px 4px 4px 4px';
_this.container = container;
all.appendChild(container);
if (showFPS)
_this.addFps();
if (showLog)
_this.addLog();
}
return _this;
}
WebFps.prototype.addFps = function () {
var div = document.createElement('div');
div.style.display = 'inline-block';
this.containerFps = div;
this.container.appendChild(div);
var fps = document.createElement('div');
fps.style.paddingBottom = '2px';
this.fps = fps;
this.containerFps.appendChild(fps);
fps.innerHTML = "0 FPS " + this.renderMode + "
min0 max0 avg0";
var canvas = document.createElement('canvas');
this.containerFps.appendChild(canvas);
canvas.width = this.WIDTH;
canvas.height = this.HEIGHT;
this.canvasFps = canvas;
var context = canvas.getContext('2d');
this.contextFps = context;
context.fillStyle = this.bgCanvasColor;
context.fillRect(0, 0, this.WIDTH, this.HEIGHT);
var divDatas = document.createElement('div');
this.divDatas = divDatas;
this.containerFps.appendChild(divDatas);
var left = document.createElement('div');
left.style['float'] = 'left';
left.innerHTML = "Draw
Dirty
Cost";
divDatas.appendChild(left);
var right = document.createElement('div');
right.style.paddingLeft = left.offsetWidth + 20 + "px";
divDatas.appendChild(right);
var draw = document.createElement('div');
this.divDraw = draw;
draw.innerHTML = "0
0
";
right.appendChild(draw);
var cost = document.createElement('div');
this.divCost = cost;
cost.innerHTML = "0 0 0";
right.appendChild(cost);
canvas = document.createElement('canvas');
this.canvasCost = canvas;
this.containerFps.appendChild(canvas);
canvas.width = this.WIDTH;
canvas.height = this.HEIGHT;
context = canvas.getContext('2d');
this.contextCost = context;
context.fillStyle = this.bgCanvasColor;
context.fillRect(0, 0, this.WIDTH, this.HEIGHT);
context.fillStyle = "#000000";
context.fillRect(this.WIDTH_COST, 0, 1, this.HEIGHT);
context.fillRect(this.WIDTH_COST * 2 + 1, 0, 1, this.HEIGHT);
this.fpsHeight = this.container.offsetHeight;
};
WebFps.prototype.addLog = function () {
var log = document.createElement('div');
log.style.maxWidth = document.body.clientWidth - 8 - this.panelX + 'px';
log.style.wordWrap = "break-word";
this.log = log;
this.container.appendChild(log);
};
WebFps.prototype.update = function (datas, showLastData) {
if (showLastData === void 0) { showLastData = false; }
var numFps;
var numCostTicker;
var numCostDirty;
var numCostRender;
if (!showLastData) {
numFps = datas.fps;
numCostTicker = datas.costTicker;
numCostDirty = datas.costDirty;
numCostRender = datas.costRender;
this.lastNumDraw = datas.draw;
this.lastNumDirty = datas.dirty;
this.arrFps.push(numFps);
this.arrCost.push([numCostTicker, numCostDirty, numCostRender]);
}
else {
numFps = this.arrFps[this.arrFps.length - 1];
numCostTicker = this.arrCost[this.arrCost.length - 1][0];
numCostDirty = this.arrCost[this.arrCost.length - 1][1];
numCostRender = this.arrCost[this.arrCost.length - 1][2];
}
var fpsTotal = 0;
var lenFps = this.arrFps.length;
if (lenFps > 101) {
lenFps = 101;
this.arrFps.shift();
this.arrCost.shift();
}
var fpsMin = this.arrFps[0];
var fpsMax = this.arrFps[0];
for (var i = 0; i < lenFps; i++) {
var num = this.arrFps[i];
fpsTotal += num;
if (num < fpsMin)
fpsMin = num;
else if (num > fpsMax)
fpsMax = num;
}
var WIDTH = this.WIDTH;
var HEIGHT = this.HEIGHT;
var context = this.contextFps;
context.drawImage(this.canvasFps, 1, 0, WIDTH - 1, HEIGHT, 0, 0, WIDTH - 1, HEIGHT);
context.fillStyle = this.bgCanvasColor;
context.fillRect(WIDTH - 1, 0, 1, HEIGHT);
var lastHeight = Math.floor(numFps / 60 * 20);
if (lastHeight < 1)
lastHeight = 1;
context.fillStyle = this.fpsFrontColor;
context.fillRect(WIDTH - 1, 20 - lastHeight, 1, lastHeight);
var WIDTH_COST = this.WIDTH_COST;
context = this.contextCost;
context.drawImage(this.canvasCost, 1, 0, WIDTH_COST - 1, HEIGHT, 0, 0, WIDTH_COST - 1, HEIGHT);
context.drawImage(this.canvasCost, WIDTH_COST + 2, 0, WIDTH_COST - 1, HEIGHT, WIDTH_COST + 1, 0, WIDTH_COST - 1, HEIGHT);
context.drawImage(this.canvasCost, WIDTH_COST * 2 + 3, 0, WIDTH_COST - 1, HEIGHT, WIDTH_COST * 2 + 2, 0, WIDTH_COST - 1, HEIGHT);
var c1Height = Math.floor(numCostTicker / 2);
if (c1Height < 1)
c1Height = 1;
else if (c1Height > 20)
c1Height = 20;
var c2Height = Math.floor(numCostDirty / 2);
if (c2Height < 1)
c2Height = 1;
else if (c2Height > 20)
c2Height = 20;
var c3Height = Math.floor(numCostRender / 2);
if (c3Height < 1)
c3Height = 1;
else if (c3Height > 20)
c3Height = 20;
context.fillStyle = this.bgCanvasColor;
context.fillRect(WIDTH_COST - 1, 0, 1, HEIGHT);
context.fillRect(WIDTH_COST * 2, 0, 1, HEIGHT);
context.fillRect(WIDTH_COST * 3 + 1, 0, 1, HEIGHT);
context.fillStyle = this.cost1Color;
context.fillRect(WIDTH_COST - 1, 20 - c1Height, 1, c1Height);
context.fillStyle = this.cost2Color;
context.fillRect(WIDTH_COST * 2, 20 - c2Height, 1, c2Height);
context.fillStyle = this.cost3Color;
context.fillRect(WIDTH_COST * 3 + 1, 20 - c3Height, 1, c3Height);
var fpsAvg = Math.floor(fpsTotal / lenFps);
var fpsOutput = numFps + " FPS " + this.renderMode;
if (this.showPanle) {
fpsOutput += "
min" + fpsMin + " max" + fpsMax + " avg" + fpsAvg;
this.divDraw.innerHTML = this.lastNumDraw + "
" + this.lastNumDirty + "%
";
this.divCost.innerHTML = "" + numCostTicker + " " + numCostDirty + " " + numCostRender + "";
}
this.fps.innerHTML = fpsOutput;
};
;
WebFps.prototype.updateInfo = function (info) {
this.arrLog.push(info);
this.log.innerHTML = this.arrLog.join('
');
while (document.body.clientHeight < (this.log.offsetHeight + this.fpsHeight + this.panelY + this.fontSize * 2)) {
this.arrLog.shift();
this.log.innerHTML = this.arrLog.join('
');
}
};
return WebFps;
}(egret.DisplayObject));
web.WebFps = WebFps;
__reflect(WebFps.prototype, "egret.web.WebFps", ["egret.FPSDisplay", "egret.DisplayObject"]);
egret.FPSDisplay = WebFps;
})(web = egret.web || (egret.web = {}));
})(egret || (egret = {}));
//////////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2014-present, Egret Technology.
// All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of the Egret nor the
// names of its contributors may be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////////////
// There is no HTMLDivElement in webkit for air
if (true && window['HTMLVideoElement'] == undefined) {
window['HTMLVideoElement'] = HTMLDivElement;
}
var egret;
(function (egret) {
var web;
(function (web) {
var className = "egret.BitmapData";
egret.registerClass(HTMLImageElement, className);
egret.registerClass(HTMLCanvasElement, className);
egret.registerClass(HTMLVideoElement, className);
})(web = egret.web || (egret.web = {}));
})(egret || (egret = {}));
(function (egret) {
/**
* 转换 Image,Canvas,Video 为 Egret 框架内使用的 BitmapData 对象。
* @param data 需要转换的对象,包括HTMLImageElement|HTMLCanvasElement|HTMLVideoElement
* @deprecated
*/
function $toBitmapData(data) {
data["hashCode"] = data["$hashCode"] = egret.$hashCount++;
return data;
}
egret.$toBitmapData = $toBitmapData;
})(egret || (egret = {}));
//////////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2014-present, Egret Technology.
// All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of the Egret nor the
// names of its contributors may be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////////////
var egret;
(function (egret) {
var localStorage;
(function (localStorage) {
var web;
(function (web) {
/**
* @private
*
* @param key
* @returns
*/
function getItem(key) {
return window.localStorage.getItem(key);
}
/**
* @private
*
* @param key
* @param value
* @returns
*/
function setItem(key, value) {
try {
window.localStorage.setItem(key, value);
return true;
}
catch (e) {
egret.$warn(1047, key, value);
return false;
}
}
/**
* @private
*
* @param key
*/
function removeItem(key) {
window.localStorage.removeItem(key);
}
/**
* @private
*
*/
function clear() {
window.localStorage.clear();
}
localStorage.getItem = getItem;
localStorage.setItem = setItem;
localStorage.removeItem = removeItem;
localStorage.clear = clear;
})(web = localStorage.web || (localStorage.web = {}));
})(localStorage = egret.localStorage || (egret.localStorage = {}));
})(egret || (egret = {}));
//////////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2014-present, Egret Technology.
// All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of the Egret nor the
// names of its contributors may be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////////////
var egret;
(function (egret) {
var web;
(function (web) {
/**
* @private
* @inheritDoc
*/
var HtmlSound = (function (_super) {
__extends(HtmlSound, _super);
/**
* @private
* @inheritDoc
*/
function HtmlSound() {
var _this = _super.call(this) || this;
/**
* @private
*/
_this.loaded = false;
return _this;
}
Object.defineProperty(HtmlSound.prototype, "length", {
get: function () {
if (this.originAudio) {
return this.originAudio.duration;
}
throw new Error("sound not loaded!");
//return 0;
},
enumerable: true,
configurable: true
});
/**
* @inheritDoc
*/
HtmlSound.prototype.load = function (url) {
var self = this;
this.url = url;
if (true && !url) {
egret.$error(3002);
}
var audio = new Audio(url);
audio.addEventListener("canplaythrough", onAudioLoaded);
audio.addEventListener("error", onAudioError);
var ua = navigator.userAgent.toLowerCase();
if (ua.indexOf("firefox") >= 0) {
audio.autoplay = !0;
audio.muted = true;
}
audio.load();
this.originAudio = audio;
if (HtmlSound.clearAudios[this.url]) {
delete HtmlSound.clearAudios[this.url];
}
HtmlSound.$recycle(this.url, audio);
function onAudioLoaded() {
removeListeners();
if (ua.indexOf("firefox") >= 0) {
audio.pause();
audio.muted = false;
}
self.loaded = true;
self.dispatchEventWith(egret.Event.COMPLETE);
}
function onAudioError() {
removeListeners();
self.dispatchEventWith(egret.IOErrorEvent.IO_ERROR);
}
function removeListeners() {
audio.removeEventListener("canplaythrough", onAudioLoaded);
audio.removeEventListener("error", onAudioError);
}
};
/**
* @inheritDoc
*/
HtmlSound.prototype.play = function (startTime, loops) {
startTime = +startTime || 0;
loops = +loops || 0;
if (true && this.loaded == false) {
egret.$error(1049);
}
var audio = HtmlSound.$pop(this.url);
if (audio == null) {
audio = this.originAudio.cloneNode();
}
else {
//audio.load();
}
audio.autoplay = true;
var channel = new web.HtmlSoundChannel(audio);
channel.$url = this.url;
channel.$loops = loops;
channel.$startTime = startTime;
channel.$play();
egret.sys.$pushSoundChannel(channel);
return channel;
};
/**
* @inheritDoc
*/
HtmlSound.prototype.close = function () {
if (this.loaded == false && this.originAudio)
this.originAudio.src = "";
if (this.originAudio)
this.originAudio = null;
HtmlSound.$clear(this.url);
};
HtmlSound.$clear = function (url) {
HtmlSound.clearAudios[url] = true;
var array = HtmlSound.audios[url];
if (array) {
array.length = 0;
}
};
HtmlSound.$pop = function (url) {
var array = HtmlSound.audios[url];
if (array && array.length > 0) {
return array.pop();
}
return null;
};
HtmlSound.$recycle = function (url, audio) {
if (HtmlSound.clearAudios[url]) {
return;
}
var array = HtmlSound.audios[url];
if (HtmlSound.audios[url] == null) {
array = HtmlSound.audios[url] = [];
}
array.push(audio);
};
/**
* Background music
* @version Egret 2.4
* @platform Web,Native
* @language en_US
*/
/**
* 背景音乐
* @version Egret 2.4
* @platform Web,Native
* @language zh_CN
*/
HtmlSound.MUSIC = "music";
/**
* EFFECT
* @version Egret 2.4
* @platform Web,Native
* @language en_US
*/
/**
* 音效
* @version Egret 2.4
* @platform Web,Native
* @language zh_CN
*/
HtmlSound.EFFECT = "effect";
/**
* @private
*/
HtmlSound.audios = {};
HtmlSound.clearAudios = {};
return HtmlSound;
}(egret.EventDispatcher));
web.HtmlSound = HtmlSound;
__reflect(HtmlSound.prototype, "egret.web.HtmlSound", ["egret.Sound"]);
})(web = egret.web || (egret.web = {}));
})(egret || (egret = {}));
//////////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2014-present, Egret Technology.
// All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of the Egret nor the
// names of its contributors may be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////////////
var egret;
(function (egret) {
var web;
(function (web) {
/**
* @private
* @inheritDoc
*/
var HtmlSoundChannel = (function (_super) {
__extends(HtmlSoundChannel, _super);
/**
* @private
*/
function HtmlSoundChannel(audio) {
var _this = _super.call(this) || this;
/**
* @private
*/
_this.$startTime = 0;
/**
* @private
*/
_this.audio = null;
//声音是否已经播放完成
_this.isStopped = false;
_this.canPlay = function () {
_this.audio.removeEventListener("canplay", _this.canPlay);
try {
_this.audio.currentTime = _this.$startTime;
}
catch (e) {
}
finally {
_this.audio.play();
}
};
/**
* @private
*/
_this.onPlayEnd = function () {
if (_this.$loops == 1) {
_this.stop();
_this.dispatchEventWith(egret.Event.SOUND_COMPLETE);
return;
}
if (_this.$loops > 0) {
_this.$loops--;
}
/////////////
//this.audio.load();
_this.$play();
};
/**
* @private
*/
_this._volume = 1;
audio.addEventListener("ended", _this.onPlayEnd);
_this.audio = audio;
return _this;
}
HtmlSoundChannel.prototype.$play = function () {
if (this.isStopped) {
egret.$error(1036);
return;
}
try {
//this.audio.pause();
this.audio.volume = this._volume;
this.audio.currentTime = this.$startTime;
}
catch (e) {
this.audio.addEventListener("canplay", this.canPlay);
return;
}
this.audio.play();
};
/**
* @private
* @inheritDoc
*/
HtmlSoundChannel.prototype.stop = function () {
if (!this.audio)
return;
if (!this.isStopped) {
egret.sys.$popSoundChannel(this);
}
this.isStopped = true;
var audio = this.audio;
audio.removeEventListener("ended", this.onPlayEnd);
audio.volume = 0;
this._volume = 0;
this.audio = null;
var url = this.$url;
//延迟一定时间再停止,规避chrome报错
window.setTimeout(function () {
audio.pause();
web.HtmlSound.$recycle(url, audio);
}, 200);
};
Object.defineProperty(HtmlSoundChannel.prototype, "volume", {
/**
* @private
* @inheritDoc
*/
get: function () {
return this._volume;
},
/**
* @inheritDoc
*/
set: function (value) {
if (this.isStopped) {
egret.$error(1036);
return;
}
this._volume = value;
if (!this.audio)
return;
this.audio.volume = value;
},
enumerable: true,
configurable: true
});
Object.defineProperty(HtmlSoundChannel.prototype, "position", {
/**
* @private
* @inheritDoc
*/
get: function () {
if (!this.audio)
return 0;
return this.audio.currentTime;
},
enumerable: true,
configurable: true
});
return HtmlSoundChannel;
}(egret.EventDispatcher));
web.HtmlSoundChannel = HtmlSoundChannel;
__reflect(HtmlSoundChannel.prototype, "egret.web.HtmlSoundChannel", ["egret.SoundChannel", "egret.IEventDispatcher"]);
})(web = egret.web || (egret.web = {}));
})(egret || (egret = {}));
//////////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2014-present, Egret Technology.
// All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of the Egret nor the
// names of its contributors may be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////////////
var egret;
(function (egret) {
var web;
(function (web) {
/**
* @private
*/
var WebAudioDecode = (function () {
function WebAudioDecode() {
}
/**
* @private
*
*/
WebAudioDecode.decodeAudios = function () {
if (WebAudioDecode.decodeArr.length <= 0) {
return;
}
if (WebAudioDecode.isDecoding) {
return;
}
WebAudioDecode.isDecoding = true;
var decodeInfo = WebAudioDecode.decodeArr.shift();
WebAudioDecode.ctx.decodeAudioData(decodeInfo["buffer"], function (audioBuffer) {
decodeInfo["self"].audioBuffer = audioBuffer;
if (decodeInfo["success"]) {
decodeInfo["success"]();
}
WebAudioDecode.isDecoding = false;
WebAudioDecode.decodeAudios();
}, function () {
alert("sound decode error: " + decodeInfo["url"] + "!\nsee http://edn.egret.com/cn/docs/page/156");
if (decodeInfo["fail"]) {
decodeInfo["fail"]();
}
WebAudioDecode.isDecoding = false;
WebAudioDecode.decodeAudios();
});
};
/**
* @private
*/
WebAudioDecode.decodeArr = [];
/**
* @private
*/
WebAudioDecode.isDecoding = false;
return WebAudioDecode;
}());
web.WebAudioDecode = WebAudioDecode;
__reflect(WebAudioDecode.prototype, "egret.web.WebAudioDecode");
/**
* @private
* @inheritDoc
*/
var WebAudioSound = (function (_super) {
__extends(WebAudioSound, _super);
/**
* @private
* @inheritDoc
*/
function WebAudioSound() {
var _this = _super.call(this) || this;
/**
* @private
*/
_this.loaded = false;
return _this;
}
Object.defineProperty(WebAudioSound.prototype, "length", {
get: function () {
if (this.audioBuffer) {
return this.audioBuffer.duration;
}
throw new Error("sound not loaded!");
//return 0;
},
enumerable: true,
configurable: true
});
/**
* @inheritDoc
*/
WebAudioSound.prototype.load = function (url) {
var self = this;
this.url = url;
if (true && !url) {
egret.$error(3002);
}
var request = new XMLHttpRequest();
request.open("GET", url, true);
request.responseType = "arraybuffer";
request.onreadystatechange = function () {
if (request.readyState == 4) {
var ioError = (request.status >= 400 || request.status == 0);
if (ioError) {
self.dispatchEventWith(egret.IOErrorEvent.IO_ERROR);
}
else {
WebAudioDecode.decodeArr.push({
"buffer": request.response,
"success": onAudioLoaded,
"fail": onAudioError,
"self": self,
"url": self.url
});
WebAudioDecode.decodeAudios();
}
}
};
request.send();
function onAudioLoaded() {
self.loaded = true;
self.dispatchEventWith(egret.Event.COMPLETE);
}
function onAudioError() {
self.dispatchEventWith(egret.IOErrorEvent.IO_ERROR);
}
};
/**
* @inheritDoc
*/
WebAudioSound.prototype.play = function (startTime, loops) {
startTime = +startTime || 0;
loops = +loops || 0;
if (true && this.loaded == false) {
egret.$error(1049);
}
var channel = new web.WebAudioSoundChannel();
channel.$url = this.url;
channel.$loops = loops;
channel.$audioBuffer = this.audioBuffer;
channel.$startTime = startTime;
channel.$play();
egret.sys.$pushSoundChannel(channel);
return channel;
};
/**
* @inheritDoc
*/
WebAudioSound.prototype.close = function () {
};
/**
* Background music
* @version Egret 2.4
* @platform Web,Native
* @language en_US
*/
/**
* 背景音乐
* @version Egret 2.4
* @platform Web,Native
* @language zh_CN
*/
WebAudioSound.MUSIC = "music";
/**
* EFFECT
* @version Egret 2.4
* @platform Web,Native
* @language en_US
*/
/**
* 音效
* @version Egret 2.4
* @platform Web,Native
* @language zh_CN
*/
WebAudioSound.EFFECT = "effect";
return WebAudioSound;
}(egret.EventDispatcher));
web.WebAudioSound = WebAudioSound;
__reflect(WebAudioSound.prototype, "egret.web.WebAudioSound", ["egret.Sound"]);
})(web = egret.web || (egret.web = {}));
})(egret || (egret = {}));
//////////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2014-present, Egret Technology.
// All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of the Egret nor the
// names of its contributors may be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////////////
var egret;
(function (egret) {
var web;
(function (web) {
/**
* @private
* @inheritDoc
*/
var WebAudioSoundChannel = (function (_super) {
__extends(WebAudioSoundChannel, _super);
/**
* @private
*/
function WebAudioSoundChannel() {
var _this = _super.call(this) || this;
/**
* @private
*/
_this.$startTime = 0;
/**
* @private
*/
_this.bufferSource = null;
/**
* @private
*/
_this.context = web.WebAudioDecode.ctx;
//声音是否已经播放完成
_this.isStopped = false;
/**
* @private
*/
_this._currentTime = 0;
/**
* @private
*/
_this._volume = 1;
/**
* @private
*/
_this.onPlayEnd = function () {
if (_this.$loops == 1) {
_this.stop();
_this.dispatchEventWith(egret.Event.SOUND_COMPLETE);
return;
}
if (_this.$loops > 0) {
_this.$loops--;
}
/////////////
_this.$play();
};
/**
* @private
*/
_this._startTime = 0;
if (_this.context["createGain"]) {
_this.gain = _this.context["createGain"]();
}
else {
_this.gain = _this.context["createGainNode"]();
}
return _this;
}
WebAudioSoundChannel.prototype.$play = function () {
if (this.isStopped) {
egret.$error(1036);
return;
}
if (this.bufferSource) {
this.bufferSource.onended = null;
this.bufferSource = null;
}
var context = this.context;
var gain = this.gain;
var bufferSource = context.createBufferSource();
this.bufferSource = bufferSource;
bufferSource.buffer = this.$audioBuffer;
bufferSource.connect(gain);
gain.connect(context.destination);
bufferSource.onended = this.onPlayEnd;
this._startTime = Date.now();
this.gain.gain.value = this._volume;
bufferSource.start(0, this.$startTime);
this._currentTime = 0;
};
WebAudioSoundChannel.prototype.stop = function () {
if (this.bufferSource) {
var sourceNode = this.bufferSource;
if (sourceNode.stop) {
sourceNode.stop(0);
}
else {
sourceNode.noteOff(0);
}
sourceNode.onended = null;
sourceNode.disconnect();
this.bufferSource = null;
this.$audioBuffer = null;
}
if (!this.isStopped) {
egret.sys.$popSoundChannel(this);
}
this.isStopped = true;
};
Object.defineProperty(WebAudioSoundChannel.prototype, "volume", {
/**
* @private
* @inheritDoc
*/
get: function () {
return this._volume;
},
/**
* @inheritDoc
*/
set: function (value) {
if (this.isStopped) {
egret.$error(1036);
return;
}
this._volume = value;
this.gain.gain.value = value;
},
enumerable: true,
configurable: true
});
Object.defineProperty(WebAudioSoundChannel.prototype, "position", {
/**
* @private
* @inheritDoc
*/
get: function () {
if (this.bufferSource) {
return (Date.now() - this._startTime) / 1000 + this.$startTime;
}
return 0;
},
enumerable: true,
configurable: true
});
return WebAudioSoundChannel;
}(egret.EventDispatcher));
web.WebAudioSoundChannel = WebAudioSoundChannel;
__reflect(WebAudioSoundChannel.prototype, "egret.web.WebAudioSoundChannel", ["egret.SoundChannel", "egret.IEventDispatcher"]);
})(web = egret.web || (egret.web = {}));
})(egret || (egret = {}));
//////////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2014-present, Egret Technology.
// All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of the Egret nor the
// names of its contributors may be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////////////
var egret;
(function (egret) {
var web;
(function (web) {
/**
* @private
* @inheritDoc
*/
var WebVideo = (function (_super) {
__extends(WebVideo, _super);
/**
* @inheritDoc
*/
function WebVideo(url, cache) {
if (cache === void 0) { cache = true; }
var _this = _super.call(this) || this;
/**
* @private
*/
_this.loaded = false;
/**
* @private
*/
_this.closed = false;
/**
* @private
*/
_this.heightSet = NaN;
/**
* @private
*/
_this.widthSet = NaN;
/**
* @private
* pc上视频卡住的时候不能暂停
*/
_this.waiting = false;
/**
* @private
* 用户是否设置了 pause
*/
_this.userPause = false;
/**
* @private
* 用户是否设置了 play
*/
_this.userPlay = false;
_this.isPlayed = false;
_this.screenChanged = function (e) {
var isfullscreen = document.fullscreenEnabled || document.webkitIsFullScreen;
if (!isfullscreen) {
_this.checkFullScreen(false);
if (!egret.Capabilities.isMobile) {
_this._fullscreen = isfullscreen;
}
}
};
_this._fullscreen = true;
/**
* @private
*
*/
_this.onVideoLoaded = function () {
_this.video.removeEventListener("canplay", _this.onVideoLoaded);
var video = _this.video;
_this.loaded = true;
//video.pause();
if (_this.posterData) {
_this.posterData.width = _this.getPlayWidth();
_this.posterData.height = _this.getPlayHeight();
}
video.width = video.videoWidth;
video.height = video.videoHeight;
_this.$invalidateContentBounds();
window.setTimeout(function () {
_this.dispatchEventWith(egret.Event.COMPLETE);
}, 200);
};
_this.$renderNode = new egret.sys.BitmapNode();
_this.src = url;
_this.once(egret.Event.ADDED_TO_STAGE, _this.loadPoster, _this);
if (url) {
_this.load();
}
return _this;
}
/**
* @inheritDoc
*/
WebVideo.prototype.load = function (url, cache) {
var _this = this;
if (cache === void 0) { cache = true; }
url = url || this.src;
this.src = url;
if (true && !url) {
egret.$error(3002);
}
if (this.video && this.video.src == url) {
return;
}
var video;
if (!this.video || egret.Capabilities.isMobile) {
video = document.createElement("video");
this.video = video;
video.controls = null;
}
else {
video = this.video;
}
video.src = url;
video.setAttribute("autoplay", "autoplay");
video.setAttribute("webkit-playsinline", "true");
video.addEventListener("canplay", this.onVideoLoaded);
video.addEventListener("error", function () { return _this.onVideoError(); });
video.addEventListener("ended", function () { return _this.onVideoEnded(); });
var firstPause = false;
video.addEventListener("canplay", function () {
_this.waiting = false;
if (!firstPause) {
firstPause = true;
video.pause();
}
else {
if (_this.userPause) {
_this.pause();
}
else if (_this.userPlay) {
_this.play();
}
}
});
video.addEventListener("waiting", function () {
_this.waiting = true;
});
video.load();
this.videoPlay();
video.style.position = "absolute";
video.style.top = "0px";
video.style.zIndex = "-88888";
video.style.left = "0px";
video.height = 1;
video.width = 1;
};
/**
* @inheritDoc
*/
WebVideo.prototype.play = function (startTime, loop) {
var _this = this;
if (loop === void 0) { loop = false; }
if (this.loaded == false) {
this.load(this.src);
this.once(egret.Event.COMPLETE, function (e) { return _this.play(startTime, loop); }, this);
return;
}
this.isPlayed = true;
var video = this.video;
if (startTime != undefined)
video.currentTime = +startTime || 0;
video.loop = !!loop;
if (egret.Capabilities.isMobile) {
video.style.zIndex = "-88888"; //移动端,就算设置成最小,只要全屏,都会在最上层,而且在自动退出去后,不担心挡住canvas
}
else {
video.style.zIndex = "9999";
}
video.style.position = "absolute";
video.style.top = "0px";
video.style.left = "0px";
video.height = video.videoHeight;
video.width = video.videoWidth;
if (egret.Capabilities.os != "Windows PC" && egret.Capabilities.os != "Mac OS") {
window.setTimeout(function () {
video.width = 0;
}, 1000);
}
this.checkFullScreen(this._fullscreen);
};
WebVideo.prototype.videoPlay = function () {
this.userPause = false;
if (this.waiting) {
this.userPlay = true;
return;
}
this.userPlay = false;
this.video.play();
};
WebVideo.prototype.checkFullScreen = function (playFullScreen) {
var video = this.video;
if (playFullScreen) {
if (video.parentElement == null) {
video.removeAttribute("webkit-playsinline");
document.body.appendChild(video);
}
egret.stopTick(this.markDirty, this);
this.goFullscreen();
}
else {
if (video.parentElement != null) {
video.parentElement.removeChild(video);
}
video.setAttribute("webkit-playsinline", "true");
this.setFullScreenMonitor(false);
egret.startTick(this.markDirty, this);
if (egret.Capabilities.isMobile) {
this.video.currentTime = 0;
this.onVideoEnded();
return;
}
}
this.videoPlay();
};
WebVideo.prototype.goFullscreen = function () {
var video = this.video;
var fullscreenType;
fullscreenType = egret.web.getPrefixStyleName('requestFullscreen', video);
if (!video[fullscreenType]) {
fullscreenType = egret.web.getPrefixStyleName('requestFullScreen', video);
if (!video[fullscreenType]) {
return true;
}
}
video.removeAttribute("webkit-playsinline");
video[fullscreenType]();
this.setFullScreenMonitor(true);
return true;
};
WebVideo.prototype.setFullScreenMonitor = function (use) {
var video = this.video;
if (use) {
video.addEventListener("mozfullscreenchange", this.screenChanged);
video.addEventListener("webkitfullscreenchange", this.screenChanged);
video.addEventListener("mozfullscreenerror", this.screenError);
video.addEventListener("webkitfullscreenerror", this.screenError);
}
else {
video.removeEventListener("mozfullscreenchange", this.screenChanged);
video.removeEventListener("webkitfullscreenchange", this.screenChanged);
video.removeEventListener("mozfullscreenerror", this.screenError);
video.removeEventListener("webkitfullscreenerror", this.screenError);
}
};
WebVideo.prototype.screenError = function () {
egret.$error(3014);
};
WebVideo.prototype.exitFullscreen = function () {
//退出全屏
if (document['exitFullscreen']) {
document['exitFullscreen']();
}
else if (document['msExitFullscreen']) {
document['msExitFullscreen']();
}
else if (document['mozCancelFullScreen']) {
document['mozCancelFullScreen']();
}
else if (document['oCancelFullScreen']) {
document['oCancelFullScreen']();
}
else if (document['webkitExitFullscreen']) {
document['webkitExitFullscreen']();
}
else {
}
};
/**
* @private
*
*/
WebVideo.prototype.onVideoEnded = function () {
this.pause();
this.isPlayed = false;
this.$invalidateContentBounds();
this.dispatchEventWith(egret.Event.ENDED);
};
/**
* @private
*
*/
WebVideo.prototype.onVideoError = function () {
this.dispatchEventWith(egret.IOErrorEvent.IO_ERROR);
};
/**
* @inheritDoc
*/
WebVideo.prototype.close = function () {
var _this = this;
this.closed = true;
this.video.removeEventListener("canplay", this.onVideoLoaded);
this.video.removeEventListener("error", function () { return _this.onVideoError(); });
this.video.removeEventListener("ended", function () { return _this.onVideoEnded(); });
this.pause();
if (this.loaded == false && this.video)
this.video.src = "";
if (this.video && this.video.parentElement) {
this.video.parentElement.removeChild(this.video);
this.video = null;
}
this.loaded = false;
};
/**
* @inheritDoc
*/
WebVideo.prototype.pause = function () {
this.userPlay = false;
if (this.waiting) {
this.userPause = true;
return;
}
this.userPause = false;
egret.stopTick(this.markDirty, this);
this.$invalidate();
};
Object.defineProperty(WebVideo.prototype, "volume", {
/**
* @inheritDoc
*/
get: function () {
if (!this.video)
return 1;
return this.video.volume;
},
/**
* @inheritDoc
*/
set: function (value) {
if (!this.video)
return;
this.video.volume = value;
},
enumerable: true,
configurable: true
});
Object.defineProperty(WebVideo.prototype, "position", {
/**
* @inheritDoc
*/
get: function () {
if (!this.video)
return 0;
return this.video.currentTime;
},
/**
* @inheritDoc
*/
set: function (value) {
if (!this.video)
return;
this.video.currentTime = value;
},
enumerable: true,
configurable: true
});
Object.defineProperty(WebVideo.prototype, "fullscreen", {
/**
* @inheritDoc
*/
get: function () {
return this._fullscreen;
},
/**
* @inheritDoc
*/
set: function (value) {
if (egret.Capabilities.isMobile) {
return;
}
this._fullscreen = !!value;
if (this.video && this.video.paused == false) {
this.checkFullScreen(this._fullscreen);
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(WebVideo.prototype, "bitmapData", {
/**
* @inheritDoc
*/
get: function () {
if (!this.video || !this.loaded)
return null;
if (!this._bitmapData) {
this.video.width = this.video.videoWidth;
this.video.height = this.video.videoHeight;
this._bitmapData = new egret.BitmapData(this.video);
this._bitmapData.$deleteSource = false;
}
return this._bitmapData;
},
enumerable: true,
configurable: true
});
WebVideo.prototype.loadPoster = function () {
var _this = this;
var poster = this.poster;
if (!poster)
return;
var imageLoader = new egret.ImageLoader();
imageLoader.once(egret.Event.COMPLETE, function (e) {
var posterData = imageLoader.data;
_this.posterData = imageLoader.data;
_this.posterData.width = _this.getPlayWidth();
_this.posterData.height = _this.getPlayHeight();
_this.$invalidateContentBounds();
}, this);
imageLoader.load(poster);
};
/**
* @private
*/
WebVideo.prototype.$measureContentBounds = function (bounds) {
var bitmapData = this.bitmapData;
var posterData = this.posterData;
if (bitmapData) {
bounds.setTo(0, 0, this.getPlayWidth(), this.getPlayHeight());
}
else if (posterData) {
bounds.setTo(0, 0, this.getPlayWidth(), this.getPlayHeight());
}
else {
bounds.setEmpty();
}
};
WebVideo.prototype.getPlayWidth = function () {
if (!isNaN(this.widthSet)) {
return this.widthSet;
}
if (this.bitmapData) {
return this.bitmapData.width;
}
if (this.posterData) {
return this.posterData.width;
}
return NaN;
};
WebVideo.prototype.getPlayHeight = function () {
if (!isNaN(this.heightSet)) {
return this.heightSet;
}
if (this.bitmapData) {
return this.bitmapData.height;
}
if (this.posterData) {
return this.posterData.height;
}
return NaN;
};
/**
* @private
*/
WebVideo.prototype.$render = function () {
var node = this.$renderNode;
var bitmapData = this.bitmapData;
var posterData = this.posterData;
var width = this.getPlayWidth();
var height = this.getPlayHeight();
if ((!this.isPlayed || egret.Capabilities.isMobile) && posterData) {
node.image = posterData;
node.imageWidth = width;
node.imageHeight = height;
node.drawImage(0, 0, posterData.width, posterData.height, 0, 0, width, height);
}
else if (this.isPlayed && bitmapData) {
node.image = bitmapData;
node.imageWidth = bitmapData.width;
node.imageHeight = bitmapData.height;
egret.WebGLUtils.deleteWebGLTexture(bitmapData.webGLTexture);
bitmapData.webGLTexture = null;
node.drawImage(0, 0, bitmapData.width, bitmapData.height, 0, 0, width, height);
}
};
WebVideo.prototype.markDirty = function () {
this.$invalidate();
return true;
};
/**
* @private
* 设置显示高度
*/
WebVideo.prototype.$setHeight = function (value) {
this.heightSet = +value || 0;
this.$invalidate();
this.$invalidateContentBounds();
return _super.prototype.$setHeight.call(this, value);
};
/**
* @private
* 设置显示宽度
*/
WebVideo.prototype.$setWidth = function (value) {
this.widthSet = +value || 0;
this.$invalidate();
this.$invalidateContentBounds();
return _super.prototype.$setWidth.call(this, value);
};
Object.defineProperty(WebVideo.prototype, "paused", {
get: function () {
if (this.video) {
return this.video.paused;
}
return true;
},
enumerable: true,
configurable: true
});
Object.defineProperty(WebVideo.prototype, "length", {
/**
* @inheritDoc
*/
get: function () {
if (this.video) {
return this.video.duration;
}
throw new Error("Video not loaded!");
},
enumerable: true,
configurable: true
});
return WebVideo;
}(egret.DisplayObject));
web.WebVideo = WebVideo;
__reflect(WebVideo.prototype, "egret.web.WebVideo", ["egret.Video", "egret.DisplayObject"]);
egret.Video = WebVideo;
})(web = egret.web || (egret.web = {}));
})(egret || (egret = {}));
//////////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2014-present, Egret Technology.
// All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of the Egret nor the
// names of its contributors may be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////////////
var egret;
(function (egret) {
var web;
(function (web) {
/**
* @private
*/
var WebHttpRequest = (function (_super) {
__extends(WebHttpRequest, _super);
/**
* @private
*/
function WebHttpRequest() {
var _this = _super.call(this) || this;
/**
* @private
*/
_this._url = "";
_this._method = "";
return _this;
}
Object.defineProperty(WebHttpRequest.prototype, "response", {
/**
* @private
* 本次请求返回的数据,数据类型根据responseType设置的值确定。
*/
get: function () {
if (!this._xhr) {
return null;
}
if (this._xhr.response != undefined) {
return this._xhr.response;
}
if (this._responseType == "text") {
return this._xhr.responseText;
}
if (this._responseType == "arraybuffer" && /msie 9.0/i.test(navigator.userAgent)) {
var w = window;
return w.convertResponseBodyToText(this._xhr["responseBody"]);
}
if (this._responseType == "document") {
return this._xhr.responseXML;
}
/*if (this._xhr.responseXML) {
return this._xhr.responseXML;
}
if (this._xhr.responseText != undefined) {
return this._xhr.responseText;
}*/
return null;
},
enumerable: true,
configurable: true
});
Object.defineProperty(WebHttpRequest.prototype, "responseType", {
/**
* @private
* 设置返回的数据格式,请使用 HttpResponseType 里定义的枚举值。设置非法的值或不设置,都将使用HttpResponseType.TEXT。
*/
get: function () {
return this._responseType;
},
set: function (value) {
this._responseType = value;
},
enumerable: true,
configurable: true
});
Object.defineProperty(WebHttpRequest.prototype, "withCredentials", {
/**
* @private
* 表明在进行跨站(cross-site)的访问控制(Access-Control)请求时,是否使用认证信息(例如cookie或授权的header)。 默认为 false。(这个标志不会影响同站的请求)
*/
get: function () {
return this._withCredentials;
},
set: function (value) {
this._withCredentials = value;
},
enumerable: true,
configurable: true
});
/**
* @private
*
* @returns
*/
WebHttpRequest.prototype.getXHR = function () {
if (window["XMLHttpRequest"]) {
return new window["XMLHttpRequest"]();
}
else {
return new ActiveXObject("MSXML2.XMLHTTP");
}
};
/**
* @private
* 初始化一个请求.注意,若在已经发出请求的对象上调用此方法,相当于立即调用abort().
* @param url 该请求所要访问的URL该请求所要访问的URL
* @param method 请求所使用的HTTP方法, 请使用 HttpMethod 定义的枚举值.
*/
WebHttpRequest.prototype.open = function (url, method) {
if (method === void 0) { method = "GET"; }
this._url = url;
this._method = method;
if (this._xhr) {
this._xhr.abort();
this._xhr = null;
}
this._xhr = this.getXHR(); //new XMLHttpRequest();
this._xhr.onreadystatechange = this.onReadyStateChange.bind(this);
this._xhr.onprogress = this.updateProgress.bind(this);
this._xhr.open(this._method, this._url, true);
};
/**
* @private
* 发送请求.
* @param data 需要发送的数据
*/
WebHttpRequest.prototype.send = function (data) {
if (this._responseType != null) {
this._xhr.responseType = this._responseType;
}
if (this._withCredentials != null) {
this._xhr.withCredentials = this._withCredentials;
}
if (this.headerObj) {
for (var key in this.headerObj) {
this._xhr.setRequestHeader(key, this.headerObj[key]);
}
}
this._xhr.send(data);
};
/**
* @private
* 如果请求已经被发送,则立刻中止请求.
*/
WebHttpRequest.prototype.abort = function () {
if (this._xhr) {
this._xhr.abort();
}
};
/**
* @private
* 返回所有响应头信息(响应头名和值), 如果响应头还没接受,则返回"".
*/
WebHttpRequest.prototype.getAllResponseHeaders = function () {
if (!this._xhr) {
return null;
}
var result = this._xhr.getAllResponseHeaders();
return result ? result : "";
};
/**
* @private
* 给指定的HTTP请求头赋值.在这之前,您必须确认已经调用 open() 方法打开了一个url.
* @param header 将要被赋值的请求头名称.
* @param value 给指定的请求头赋的值.
*/
WebHttpRequest.prototype.setRequestHeader = function (header, value) {
if (!this.headerObj) {
this.headerObj = {};
}
this.headerObj[header] = value;
};
/**
* @private
* 返回指定的响应头的值, 如果响应头还没被接受,或该响应头不存在,则返回"".
* @param header 要返回的响应头名称
*/
WebHttpRequest.prototype.getResponseHeader = function (header) {
if (!this._xhr) {
return null;
}
var result = this._xhr.getResponseHeader(header);
return result ? result : "";
};
/**
* @private
*/
WebHttpRequest.prototype.onReadyStateChange = function () {
var xhr = this._xhr;
if (xhr.readyState == 4) {
var ioError_1 = (xhr.status >= 400 || xhr.status == 0);
var url_1 = this._url;
var self_1 = this;
window.setTimeout(function () {
if (ioError_1) {
if (true && !self_1.hasEventListener(egret.IOErrorEvent.IO_ERROR)) {
egret.$error(1011, url_1);
}
self_1.dispatchEventWith(egret.IOErrorEvent.IO_ERROR);
}
else {
self_1.dispatchEventWith(egret.Event.COMPLETE);
}
}, 0);
}
};
/**
* @private
*/
WebHttpRequest.prototype.updateProgress = function (event) {
if (event.lengthComputable) {
egret.ProgressEvent.dispatchProgressEvent(this, egret.ProgressEvent.PROGRESS, event.loaded, event.total);
}
};
return WebHttpRequest;
}(egret.EventDispatcher));
web.WebHttpRequest = WebHttpRequest;
__reflect(WebHttpRequest.prototype, "egret.web.WebHttpRequest", ["egret.HttpRequest"]);
egret.HttpRequest = WebHttpRequest;
})(web = egret.web || (egret.web = {}));
})(egret || (egret = {}));
//////////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2014-present, Egret Technology.
// All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of the Egret nor the
// names of its contributors may be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////////////
var egret;
(function (egret) {
var web;
(function (web) {
var winURL = window["URL"] || window["webkitURL"];
/**
* @private
* ImageLoader 类可用于加载图像(JPG、PNG 或 GIF)文件。使用 load() 方法来启动加载。被加载的图像对象数据将存储在 ImageLoader.data 属性上 。
*/
var WebImageLoader = (function (_super) {
__extends(WebImageLoader, _super);
function WebImageLoader() {
var _this = _super !== null && _super.apply(this, arguments) || this;
/**
* @private
* 使用 load() 方法加载成功的 BitmapData 图像数据。
*/
_this.data = null;
/**
* @private
* 当从其他站点加载一个图片时,指定是否启用跨域资源共享(CORS),默认值为null。
* 可以设置为"anonymous","use-credentials"或null,设置为其他值将等同于"anonymous"。
*/
_this._crossOrigin = null;
/**
* @private
* 标记crossOrigin有没有被设置过,设置过之后使用设置的属性
*/
_this._hasCrossOriginSet = false;
/**
* @private
*/
_this.currentImage = null;
/**
* @private
*/
_this.request = null;
return _this;
}
Object.defineProperty(WebImageLoader.prototype, "crossOrigin", {
get: function () {
return this._crossOrigin;
},
set: function (value) {
this._hasCrossOriginSet = true;
this._crossOrigin = value;
},
enumerable: true,
configurable: true
});
/**
* @private
* 启动一次图像加载。注意:若之前已经调用过加载请求,重新调用 load() 将终止先前的请求,并开始新的加载。
* @param url 要加载的图像文件的地址。
*/
WebImageLoader.prototype.load = function (url) {
if (web.Html5Capatibility._canUseBlob
&& url.indexOf("wxLocalResource:") != 0 //微信专用不能使用 blob
&& url.indexOf("data:") != 0
&& url.indexOf("http:") != 0
&& url.indexOf("https:") != 0) {
var request = this.request;
if (!request) {
request = this.request = new egret.web.WebHttpRequest();
request.addEventListener(egret.Event.COMPLETE, this.onBlobLoaded, this);
request.addEventListener(egret.IOErrorEvent.IO_ERROR, this.onBlobError, this);
request.responseType = "blob";
}
if (true) {
this.currentURL = url;
}
request.open(url);
request.send();
}
else {
this.loadImage(url);
}
};
/**
* @private
*/
WebImageLoader.prototype.onBlobLoaded = function (event) {
var blob = this.request.response;
this.request = undefined;
this.loadImage(winURL.createObjectURL(blob));
};
/**
* @private
*/
WebImageLoader.prototype.onBlobError = function (event) {
this.dispatchIOError(this.currentURL);
this.request = undefined;
};
/**
* @private
*/
WebImageLoader.prototype.loadImage = function (src) {
var image = new Image();
this.data = null;
this.currentImage = image;
if (this._hasCrossOriginSet) {
if (this._crossOrigin) {
image.crossOrigin = this._crossOrigin;
}
}
else {
if (WebImageLoader.crossOrigin) {
image.crossOrigin = WebImageLoader.crossOrigin;
}
}
/*else {
if (image.hasAttribute("crossOrigin")) {//兼容猎豹
image.removeAttribute("crossOrigin");
}
}*/
image.onload = this.onImageComplete.bind(this);
image.onerror = this.onLoadError.bind(this);
image.src = src;
};
/**
* @private
*/
WebImageLoader.prototype.onImageComplete = function (event) {
var image = this.getImage(event);
if (!image) {
return;
}
this.data = new egret.BitmapData(image);
var self = this;
window.setTimeout(function () {
self.dispatchEventWith(egret.Event.COMPLETE);
}, 0);
};
/**
* @private
*/
WebImageLoader.prototype.onLoadError = function (event) {
var image = this.getImage(event);
if (!image) {
return;
}
this.dispatchIOError(image.src);
};
WebImageLoader.prototype.dispatchIOError = function (url) {
var self = this;
window.setTimeout(function () {
if (true && !self.hasEventListener(egret.IOErrorEvent.IO_ERROR)) {
egret.$error(1011, url);
}
self.dispatchEventWith(egret.IOErrorEvent.IO_ERROR);
}, 0);
};
/**
* @private
*/
WebImageLoader.prototype.getImage = function (event) {
var image = event.target;
var url = image.src;
if (url.indexOf("blob:") == 0) {
try {
winURL.revokeObjectURL(image.src);
}
catch (e) {
egret.$warn(1037);
}
}
image.onerror = null;
image.onload = null;
if (this.currentImage !== image) {
return null;
}
this.currentImage = null;
return image;
};
/**
* @private
* 指定是否启用跨域资源共享,如果ImageLoader实例有设置过crossOrigin属性将使用设置的属性
*/
WebImageLoader.crossOrigin = null;
return WebImageLoader;
}(egret.EventDispatcher));
web.WebImageLoader = WebImageLoader;
__reflect(WebImageLoader.prototype, "egret.web.WebImageLoader", ["egret.ImageLoader"]);
egret.ImageLoader = WebImageLoader;
})(web = egret.web || (egret.web = {}));
})(egret || (egret = {}));
//////////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2014-present, Egret Technology.
// All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of the Egret nor the
// names of its contributors may be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////////////
var egret;
(function (egret) {
var web;
(function (web) {
/**
* @classdesc
* @extends egret.StageText
* @private
*/
var HTML5StageText = (function (_super) {
__extends(HTML5StageText, _super);
/**
* @private
*/
function HTML5StageText() {
var _this = _super.call(this) || this;
/**
* @private
*/
_this._isNeedShow = false;
/**
* @private
*/
_this.inputElement = null;
/**
* @private
*/
_this.inputDiv = null;
/**
* @private
*/
_this._gscaleX = 0;
/**
* @private
*/
_this._gscaleY = 0;
/**
* @private
*/
_this.textValue = "";
/**
* @private
*/
_this.colorValue = 0xffffff;
/**
* @private
*/
_this._styleInfoes = {};
return _this;
}
/**
* @private
*
* @param textfield
*/
HTML5StageText.prototype.$setTextField = function (textfield) {
this.$textfield = textfield;
return true;
};
/**
* @private
*
*/
HTML5StageText.prototype.$addToStage = function () {
this.htmlInput = egret.web.$getTextAdapter(this.$textfield);
};
/**
* @private
*
*/
HTML5StageText.prototype._initElement = function () {
var point = this.$textfield.localToGlobal(0, 0);
var x = point.x;
var y = point.y;
// let m = this.$textfield.$renderNode.renderMatrix;
// let cX = m.a;
// let cY = m.d;
var scaleX = this.htmlInput.$scaleX;
var scaleY = this.htmlInput.$scaleY;
this.inputDiv.style.left = x * scaleX + "px";
this.inputDiv.style.top = y * scaleY + "px";
if (this.$textfield.multiline && this.$textfield.height > this.$textfield.size) {
this.inputDiv.style.top = (y) * scaleY + "px";
this.inputElement.style.top = (-this.$textfield.lineSpacing / 2) * scaleY + "px";
}
else {
this.inputDiv.style.top = y * scaleY + "px";
this.inputElement.style.top = 0 + "px";
}
var node = this.$textfield;
var cX = 1;
var cY = 1;
var rotation = 0;
while (node.parent) {
cX *= node.scaleX;
cY *= node.scaleY;
rotation += node.rotation;
node = node.parent;
}
var transformKey = egret.web.getPrefixStyleName("transform");
this.inputDiv.style[transformKey] = "rotate(" + rotation + "deg)";
this._gscaleX = scaleX * cX;
this._gscaleY = scaleY * cY;
};
/**
* @private
*
*/
HTML5StageText.prototype.$show = function () {
if (!this.htmlInput.isCurrentStageText(this)) {
this.inputElement = this.htmlInput.getInputElement(this);
if (!this.$textfield.multiline) {
this.inputElement.type = this.$textfield.inputType;
}
else {
this.inputElement.type = "text";
}
this.inputDiv = this.htmlInput._inputDIV;
}
else {
this.inputElement.onblur = null;
}
this.htmlInput._needShow = true;
//标记当前文本被选中
this._isNeedShow = true;
this._initElement();
};
/**
* @private
*
*/
HTML5StageText.prototype.onBlurHandler = function () {
this.htmlInput.clearInputElement();
window.scrollTo(0, 0);
};
/**
* @private
*
*/
HTML5StageText.prototype.executeShow = function () {
var self = this;
//打开
this.inputElement.value = this.$getText();
if (this.inputElement.onblur == null) {
this.inputElement.onblur = this.onBlurHandler.bind(this);
}
this.$resetStageText();
if (this.$textfield.maxChars > 0) {
this.inputElement.setAttribute("maxlength", this.$textfield.maxChars);
}
else {
this.inputElement.removeAttribute("maxlength");
}
this.inputElement.selectionStart = this.inputElement.value.length;
this.inputElement.selectionEnd = this.inputElement.value.length;
this.inputElement.focus();
};
/**
* @private
*/
HTML5StageText.prototype.$hide = function () {
if (this.htmlInput) {
this.htmlInput.disconnectStageText(this);
}
};
/**
* @private
*
* @returns
*/
HTML5StageText.prototype.$getText = function () {
if (!this.textValue) {
this.textValue = "";
}
return this.textValue;
};
/**
* @private
*
* @param value
*/
HTML5StageText.prototype.$setText = function (value) {
this.textValue = value;
this.resetText();
return true;
};
/**
* @private
*
*/
HTML5StageText.prototype.resetText = function () {
if (this.inputElement) {
this.inputElement.value = this.textValue;
}
};
HTML5StageText.prototype.$setColor = function (value) {
this.colorValue = value;
this.resetColor();
return true;
};
/**
* @private
*
*/
HTML5StageText.prototype.resetColor = function () {
if (this.inputElement) {
this.setElementStyle("color", egret.toColorString(this.colorValue));
}
};
HTML5StageText.prototype.$onBlur = function () {
if (web.Html5Capatibility._System_OS == web.SystemOSType.WPHONE) {
egret.Event.dispatchEvent(this, "updateText", false);
}
};
/**
* @private
*
*/
HTML5StageText.prototype._onInput = function () {
var self = this;
if (web.Html5Capatibility._System_OS == web.SystemOSType.WPHONE) {
var values = this.$textfield.$TextField;
if (values[35 /* restrictAnd */] == null && values[36 /* restrictNot */] == null) {
self.textValue = self.inputElement.value;
egret.Event.dispatchEvent(self, "updateText", false);
}
else {
window.setTimeout(function () {
if (self.inputElement && self.inputElement.selectionStart && self.inputElement.selectionEnd) {
if (self.inputElement.selectionStart == self.inputElement.selectionEnd) {
self.textValue = self.inputElement.value;
egret.Event.dispatchEvent(self, "updateText", false);
}
}
}, 0);
}
}
else {
window.setTimeout(function () {
if (self.inputElement && self.inputElement.selectionStart == self.inputElement.selectionEnd) {
self.textValue = self.inputElement.value;
egret.Event.dispatchEvent(self, "updateText", false);
}
}, 0);
}
};
HTML5StageText.prototype.setAreaHeight = function () {
var textfield = this.$textfield;
if (textfield.multiline) {
var textheight = egret.TextFieldUtils.$getTextHeight(textfield);
if (textfield.height <= textfield.size) {
this.setElementStyle("height", (textfield.size) * this._gscaleY + "px");
this.setElementStyle("padding", "0px");
this.setElementStyle("lineHeight", (textfield.size) * this._gscaleY + "px");
}
else if (textfield.height < textheight) {
this.setElementStyle("height", (textfield.height) * this._gscaleY + "px");
this.setElementStyle("padding", "0px");
this.setElementStyle("lineHeight", (textfield.size + textfield.lineSpacing) * this._gscaleY + "px");
}
else {
this.setElementStyle("height", (textheight + textfield.lineSpacing) * this._gscaleY + "px");
var rap = (textfield.height - textheight) * this._gscaleY;
var valign = egret.TextFieldUtils.$getValign(textfield);
var top_1 = rap * valign;
var bottom = rap - top_1;
this.setElementStyle("padding", top_1 + "px 0px " + bottom + "px 0px");
this.setElementStyle("lineHeight", (textfield.size + textfield.lineSpacing) * this._gscaleY + "px");
}
}
};
/**
* @private
*
* @param e
*/
HTML5StageText.prototype._onClickHandler = function (e) {
if (this._isNeedShow) {
e.stopImmediatePropagation();
//e.preventDefault();
this._isNeedShow = false;
this.executeShow();
this.dispatchEvent(new egret.Event("focus"));
}
};
/**
* @private
*
*/
HTML5StageText.prototype._onDisconnect = function () {
this.inputElement = null;
this.dispatchEvent(new egret.Event("blur"));
};
/**
* @private
*
* @param style
* @param value
*/
HTML5StageText.prototype.setElementStyle = function (style, value) {
if (this.inputElement) {
if (this._styleInfoes[style] != value) {
this.inputElement.style[style] = value;
//this._styleInfoes[style] = value;
}
}
};
/**
* @private
*
*/
HTML5StageText.prototype.$removeFromStage = function () {
if (this.inputElement) {
this.htmlInput.disconnectStageText(this);
}
};
/**
* 修改位置
* @private
*/
HTML5StageText.prototype.$resetStageText = function () {
if (this.inputElement) {
var textfield = this.$textfield;
this.setElementStyle("fontFamily", textfield.fontFamily);
this.setElementStyle("fontStyle", textfield.italic ? "italic" : "normal");
this.setElementStyle("fontWeight", textfield.bold ? "bold" : "normal");
this.setElementStyle("textAlign", textfield.textAlign);
this.setElementStyle("fontSize", textfield.size * this._gscaleY + "px");
this.setElementStyle("color", egret.toColorString(textfield.textColor));
var tw = void 0;
if (textfield.stage) {
tw = textfield.localToGlobal(0, 0).x;
tw = Math.min(textfield.width, textfield.stage.stageWidth - tw);
}
else {
tw = textfield.width;
}
this.setElementStyle("width", tw * this._gscaleX + "px");
this.setElementStyle("verticalAlign", textfield.verticalAlign);
if (textfield.multiline) {
this.setAreaHeight();
}
else {
this.setElementStyle("lineHeight", (textfield.size) * this._gscaleY + "px");
if (textfield.height < textfield.size) {
this.setElementStyle("height", (textfield.size) * this._gscaleY + "px");
var bottom = (textfield.size / 2) * this._gscaleY;
this.setElementStyle("padding", "0px 0px " + bottom + "px 0px");
}
else {
this.setElementStyle("height", (textfield.size) * this._gscaleY + "px");
var rap = (textfield.height - textfield.size) * this._gscaleY;
var valign = egret.TextFieldUtils.$getValign(textfield);
var top_2 = rap * valign;
var bottom = rap - top_2;
if (bottom < textfield.size / 2 * this._gscaleY) {
bottom = textfield.size / 2 * this._gscaleY;
}
this.setElementStyle("padding", top_2 + "px 0px " + bottom + "px 0px");
}
}
this.inputDiv.style.clip = "rect(0px " + (textfield.width * this._gscaleX) + "px " + (textfield.height * this._gscaleY) + "px 0px)";
this.inputDiv.style.height = textfield.height * this._gscaleY + "px";
this.inputDiv.style.width = tw * this._gscaleX + "px";
}
};
return HTML5StageText;
}(egret.EventDispatcher));
web.HTML5StageText = HTML5StageText;
__reflect(HTML5StageText.prototype, "egret.web.HTML5StageText", ["egret.StageText"]);
egret.StageText = HTML5StageText;
})(web = egret.web || (egret.web = {}));
})(egret || (egret = {}));
(function (egret) {
var web;
(function (web) {
/**
* @private
*/
var HTMLInput = (function () {
function HTMLInput() {
/**
* @private
*/
this._needShow = false;
/**
* @private
*/
this.$scaleX = 1;
/**
* @private
*/
this.$scaleY = 1;
}
/**
* @private
*
* @returns
*/
HTMLInput.prototype.isInputOn = function () {
return this._stageText != null;
};
/**
* @private
*
* @param stageText
* @returns
*/
HTMLInput.prototype.isCurrentStageText = function (stageText) {
return this._stageText == stageText;
};
/**
* @private
*
* @param dom
*/
HTMLInput.prototype.initValue = function (dom) {
dom.style.position = "absolute";
dom.style.left = "0px";
dom.style.top = "0px";
dom.style.border = "none";
dom.style.padding = "0";
};
/**
* @private
*
*/
HTMLInput.prototype.$updateSize = function () {
if (!this.canvas) {
return;
}
var stageW = this.canvas.width;
var stageH = this.canvas.height;
var screenW = this.canvas.style.width.split("px")[0];
var screenH = this.canvas.style.height.split("px")[0];
this.$scaleX = screenW / stageW;
this.$scaleY = screenH / stageH;
this.StageDelegateDiv.style.left = this.canvas.style.left;
this.StageDelegateDiv.style.top = this.canvas.style.top;
var transformKey = egret.web.getPrefixStyleName("transform");
this.StageDelegateDiv.style[transformKey] = this.canvas.style[transformKey];
this.StageDelegateDiv.style[egret.web.getPrefixStyleName("transformOrigin")] = "0% 0% 0px";
};
/**
* @private
*
* @param container
* @param canvas
* @returns
*/
HTMLInput.prototype._initStageDelegateDiv = function (container, canvas) {
this.canvas = canvas;
var self = this;
var stageDelegateDiv;
if (!stageDelegateDiv) {
stageDelegateDiv = document.createElement("div");
this.StageDelegateDiv = stageDelegateDiv;
stageDelegateDiv.id = "StageDelegateDiv";
container.appendChild(stageDelegateDiv);
self.initValue(stageDelegateDiv);
self._inputDIV = document.createElement("div");
self.initValue(self._inputDIV);
self._inputDIV.style.width = "0px";
self._inputDIV.style.height = "0px";
self._inputDIV.style.left = 0 + "px";
self._inputDIV.style.top = "-100px";
self._inputDIV.style[egret.web.getPrefixStyleName("transformOrigin")] = "0% 0% 0px";
stageDelegateDiv.appendChild(self._inputDIV);
this.canvas.addEventListener("click", function (e) {
if (self._needShow) {
self._needShow = false;
self._stageText._onClickHandler(e);
self.show();
}
else {
if (self._inputElement) {
self.clearInputElement();
self._inputElement.blur();
self._inputElement = null;
}
}
});
self.initInputElement(true);
self.initInputElement(false);
}
};
//初始化输入框
HTMLInput.prototype.initInputElement = function (multiline) {
var self = this;
//增加1个空的textarea
var inputElement;
if (multiline) {
inputElement = document.createElement("textarea");
inputElement.style["resize"] = "none";
self._multiElement = inputElement;
inputElement.id = "egretTextarea";
}
else {
inputElement = document.createElement("input");
self._simpleElement = inputElement;
inputElement.id = "egretInput";
}
inputElement.type = "text";
self._inputDIV.appendChild(inputElement);
inputElement.setAttribute("tabindex", "-1");
inputElement.style.width = "1px";
inputElement.style.height = "12px";
self.initValue(inputElement);
inputElement.style.outline = "thin";
inputElement.style.background = "none";
inputElement.style.overflow = "hidden";
inputElement.style.wordBreak = "break-all";
//隐藏输入框
inputElement.style.opacity = 0;
inputElement.oninput = function () {
if (self._stageText) {
self._stageText._onInput();
}
};
};
/**
* @private
*
*/
HTMLInput.prototype.show = function () {
var self = this;
var inputElement = self._inputElement;
//隐藏输入框
egret.$callAsync(function () {
inputElement.style.opacity = 1;
}, self);
};
/**
* @private
*
* @param stageText
*/
HTMLInput.prototype.disconnectStageText = function (stageText) {
if (this._stageText == null || this._stageText == stageText) {
this.clearInputElement();
if (this._inputElement) {
this._inputElement.blur();
}
}
};
/**
* @private
*
*/
HTMLInput.prototype.clearInputElement = function () {
var self = this;
if (self._inputElement) {
self._inputElement.value = "";
self._inputElement.onblur = null;
self._inputElement.style.width = "1px";
self._inputElement.style.height = "12px";
self._inputElement.style.left = "0px";
self._inputElement.style.top = "0px";
self._inputElement.style.opacity = 0;
var otherElement = void 0;
if (self._simpleElement == self._inputElement) {
otherElement = self._multiElement;
}
else {
otherElement = self._simpleElement;
}
otherElement.style.display = "block";
self._inputDIV.style.left = 0 + "px";
self._inputDIV.style.top = "-100px";
self._inputDIV.style.height = 0 + "px";
self._inputDIV.style.width = 0 + "px";
}
if (self._stageText) {
self._stageText._onDisconnect();
self._stageText = null;
this.canvas['userTyping'] = false;
}
};
/**
* @private
*
* @param stageText
* @returns
*/
HTMLInput.prototype.getInputElement = function (stageText) {
var self = this;
self.clearInputElement();
self._stageText = stageText;
this.canvas['userTyping'] = true;
if (self._stageText.$textfield.multiline) {
self._inputElement = self._multiElement;
}
else {
self._inputElement = self._simpleElement;
}
var otherElement;
if (self._simpleElement == self._inputElement) {
otherElement = self._multiElement;
}
else {
otherElement = self._simpleElement;
}
otherElement.style.display = "none";
return self._inputElement;
};
return HTMLInput;
}());
web.HTMLInput = HTMLInput;
__reflect(HTMLInput.prototype, "egret.web.HTMLInput");
})(web = egret.web || (egret.web = {}));
})(egret || (egret = {}));
(function (egret) {
var web;
(function (web) {
var stageToTextLayerMap = {};
var stageToCanvasMap = {};
var stageToContainerMap = {};
/**
* @private
* 获取
*/
function $getTextAdapter(textfield) {
var stageHash = textfield.stage ? textfield.stage.$hashCode : 0;
var adapter = stageToTextLayerMap[stageHash];
var canvas = stageToCanvasMap[stageHash];
var container = stageToContainerMap[stageHash];
if (canvas && container) {
//adapter._initStageDelegateDiv(container, canvas);
//adapter.$updateSize();
delete stageToCanvasMap[stageHash];
delete stageToContainerMap[stageHash];
}
return adapter;
}
web.$getTextAdapter = $getTextAdapter;
/**
* @private
*/
function $cacheTextAdapter(adapter, stage, container, canvas) {
adapter._initStageDelegateDiv(container, canvas);
stageToTextLayerMap[stage.$hashCode] = adapter;
stageToCanvasMap[stage.$hashCode] = canvas;
stageToContainerMap[stage.$hashCode] = container;
}
web.$cacheTextAdapter = $cacheTextAdapter;
})(web = egret.web || (egret.web = {}));
})(egret || (egret = {}));
//////////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2014-present, Egret Technology.
// All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of the Egret nor the
// names of its contributors may be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////////////
var egret;
(function (egret) {
var web;
(function (web) {
/**
* @private
*/
var context = null;
/**
* @private
*/
var fontCache = {};
/**
* 测量文本在指定样式下的宽度。
* @param text 要测量的文本内容。
* @param fontFamily 字体名称
* @param fontSize 字体大小
* @param bold 是否粗体
* @param italic 是否斜体
*/
function measureText(text, fontFamily, fontSize, bold, italic) {
if (!context) {
createContext();
}
var font = "";
if (italic)
font += "italic ";
if (bold)
font += "bold ";
font += (fontSize || 12) + "px ";
font += (fontFamily || "Arial");
context.font = font;
return context.measureText(text).width;
}
/**
* @private
*/
function createContext() {
context = egret.sys.canvasHitTestBuffer.context;
context.textAlign = "left";
context.textBaseline = "middle";
}
egret.sys.measureText = measureText;
})(web = egret.web || (egret.web = {}));
})(egret || (egret = {}));
//////////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2014-present, Egret Technology.
// All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of the Egret nor the
// names of its contributors may be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////////////
var egret;
(function (egret) {
var web;
(function (web) {
/**
* 创建一个canvas。
*/
function createCanvas(width, height) {
var canvas = document.createElement("canvas");
if (!isNaN(width) && !isNaN(height)) {
canvas.width = width;
canvas.height = height;
}
var context = canvas.getContext("2d");
if (context["imageSmoothingEnabled"] === undefined) {
var keys = ["webkitImageSmoothingEnabled", "mozImageSmoothingEnabled", "msImageSmoothingEnabled"];
var key_1;
for (var i = keys.length - 1; i >= 0; i--) {
key_1 = keys[i];
if (context[key_1] !== void 0) {
break;
}
}
try {
Object.defineProperty(context, "imageSmoothingEnabled", {
get: function () {
return this[key_1];
},
set: function (value) {
this[key_1] = value;
}
});
}
catch (e) {
context["imageSmoothingEnabled"] = context[key_1];
}
}
return canvas;
}
var sharedCanvas;
/**
* @private
* Canvas2D渲染缓冲
*/
var CanvasRenderBuffer = (function () {
function CanvasRenderBuffer(width, height, root) {
this.surface = createCanvas(width, height);
this.context = this.surface.getContext("2d");
}
Object.defineProperty(CanvasRenderBuffer.prototype, "width", {
/**
* 渲染缓冲的宽度,以像素为单位。
* @readOnly
*/
get: function () {
return this.surface.width;
},
enumerable: true,
configurable: true
});
Object.defineProperty(CanvasRenderBuffer.prototype, "height", {
/**
* 渲染缓冲的高度,以像素为单位。
* @readOnly
*/
get: function () {
return this.surface.height;
},
enumerable: true,
configurable: true
});
/**
* 改变渲染缓冲的大小并清空缓冲区
* @param width 改变后的宽
* @param height 改变后的高
* @param useMaxSize 若传入true,则将改变后的尺寸与已有尺寸对比,保留较大的尺寸。
*/
CanvasRenderBuffer.prototype.resize = function (width, height, useMaxSize) {
var surface = this.surface;
if (useMaxSize) {
var change = false;
if (surface.width < width) {
surface.width = width;
change = true;
}
if (surface.height < height) {
surface.height = height;
change = true;
}
//尺寸没有变化时,将绘制属性重置
if (!change) {
this.context.globalCompositeOperation = "source-over";
this.context.setTransform(1, 0, 0, 1, 0, 0);
this.context.globalAlpha = 1;
}
}
else {
if (surface.width != width) {
surface.width = width;
}
if (surface.height != height) {
surface.height = height;
}
}
this.clear();
};
/**
* 改变渲染缓冲为指定大小,但保留原始图像数据
* @param width 改变后的宽
* @param height 改变后的高
* @param offsetX 原始图像数据在改变后缓冲区的绘制起始位置x
* @param offsetY 原始图像数据在改变后缓冲区的绘制起始位置y
*/
CanvasRenderBuffer.prototype.resizeTo = function (width, height, offsetX, offsetY) {
if (!sharedCanvas) {
sharedCanvas = createCanvas();
}
var oldContext = this.context;
var oldSurface = this.surface;
var newSurface = sharedCanvas;
var newContext = newSurface.getContext("2d");
sharedCanvas = oldSurface;
this.context = newContext;
this.surface = newSurface;
newSurface.width = Math.max(width, 257);
newSurface.height = Math.max(height, 257);
newContext.setTransform(1, 0, 0, 1, 0, 0);
newContext.drawImage(oldSurface, offsetX, offsetY);
oldSurface.height = 1;
oldSurface.width = 1;
};
CanvasRenderBuffer.prototype.setDirtyRegionPolicy = function (state) {
};
/**
* 清空并设置裁切
* @param regions 矩形列表
* @param offsetX 矩形要加上的偏移量x
* @param offsetY 矩形要加上的偏移量y
*/
CanvasRenderBuffer.prototype.beginClip = function (regions, offsetX, offsetY) {
offsetX = +offsetX || 0;
offsetY = +offsetY || 0;
var pixelRatio = egret.sys.DisplayList.$pixelRatio;
var context = this.context;
context.save();
context.beginPath();
context.setTransform(1, 0, 0, 1, offsetX, offsetY);
var length = regions.length;
for (var i = 0; i < length; i++) {
var region = regions[i];
context.clearRect(region.minX * pixelRatio, region.minY * pixelRatio, region.width * pixelRatio, region.height * pixelRatio);
context.rect(region.minX * pixelRatio, region.minY * pixelRatio, region.width * pixelRatio, region.height * pixelRatio);
}
context.clip();
};
/**
* 取消上一次设置的clip。
*/
CanvasRenderBuffer.prototype.endClip = function () {
this.context.restore();
};
/**
* 获取指定区域的像素
*/
CanvasRenderBuffer.prototype.getPixels = function (x, y, width, height) {
if (width === void 0) { width = 1; }
if (height === void 0) { height = 1; }
return this.context.getImageData(x, y, width, height).data;
};
/**
* 转换成base64字符串,如果图片(或者包含的图片)跨域,则返回null
* @param type 转换的类型,如: "image/png","image/jpeg"
*/
CanvasRenderBuffer.prototype.toDataURL = function (type, encoderOptions) {
return this.surface.toDataURL(type, encoderOptions);
};
/**
* 清空缓冲区数据
*/
CanvasRenderBuffer.prototype.clear = function () {
this.context.setTransform(1, 0, 0, 1, 0, 0);
this.context.clearRect(0, 0, this.surface.width, this.surface.height);
};
/**
* 销毁绘制对象
*/
CanvasRenderBuffer.prototype.destroy = function () {
this.surface.width = this.surface.height = 0;
};
return CanvasRenderBuffer;
}());
web.CanvasRenderBuffer = CanvasRenderBuffer;
__reflect(CanvasRenderBuffer.prototype, "egret.web.CanvasRenderBuffer", ["egret.sys.RenderBuffer"]);
})(web = egret.web || (egret.web = {}));
})(egret || (egret = {}));
//////////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2014-present, Egret Technology.
// All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided this the following conditions are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of the Egret nor the
// names of its contributors may be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////////////
var egret;
(function (egret) {
var web;
(function (web) {
/**
* @private
*/
var WebTouchHandler = (function (_super) {
__extends(WebTouchHandler, _super);
/**
* @private
*/
function WebTouchHandler(stage, canvas) {
var _this = _super.call(this) || this;
/**
* @private
*/
_this.onTouchBegin = function (event) {
var location = _this.getLocation(event);
_this.touch.onTouchBegin(location.x, location.y, event.identifier);
};
/**
* @private
*/
_this.onTouchMove = function (event) {
var location = _this.getLocation(event);
_this.touch.onTouchMove(location.x, location.y, event.identifier);
};
/**
* @private
*/
_this.onTouchEnd = function (event) {
var location = _this.getLocation(event);
_this.touch.onTouchEnd(location.x, location.y, event.identifier);
};
/**
* @private
*/
_this.scaleX = 1;
/**
* @private
*/
_this.scaleY = 1;
/**
* @private
*/
_this.rotation = 0;
_this.canvas = canvas;
_this.touch = new egret.sys.TouchHandler(stage);
_this.addListeners();
return _this;
}
/**
* @private
* 添加事件监听
*/
WebTouchHandler.prototype.addListeners = function () {
var _this = this;
if (window.navigator.msPointerEnabled) {
this.canvas.addEventListener("MSPointerDown", function (event) {
event.identifier = event.pointerId;
_this.onTouchBegin(event);
_this.prevent(event);
}, false);
this.canvas.addEventListener("MSPointerMove", function (event) {
event.identifier = event.pointerId;
_this.onTouchMove(event);
_this.prevent(event);
}, false);
this.canvas.addEventListener("MSPointerUp", function (event) {
event.identifier = event.pointerId;
_this.onTouchEnd(event);
_this.prevent(event);
}, false);
}
else {
if (!egret.Capabilities.$isMobile) {
this.addMouseListener();
}
this.addTouchListener();
}
};
/**
* @private
*
*/
WebTouchHandler.prototype.addMouseListener = function () {
this.canvas.addEventListener("mousedown", this.onTouchBegin);
this.canvas.addEventListener("mousemove", this.onTouchMove);
this.canvas.addEventListener("mouseup", this.onTouchEnd);
};
/**
* @private
*
*/
WebTouchHandler.prototype.addTouchListener = function () {
var _this = this;
this.canvas.addEventListener("touchstart", function (event) {
var l = event.changedTouches.length;
for (var i = 0; i < l; i++) {
_this.onTouchBegin(event.changedTouches[i]);
}
_this.prevent(event);
}, false);
this.canvas.addEventListener("touchmove", function (event) {
var l = event.changedTouches.length;
for (var i = 0; i < l; i++) {
_this.onTouchMove(event.changedTouches[i]);
}
_this.prevent(event);
}, false);
this.canvas.addEventListener("touchend", function (event) {
var l = event.changedTouches.length;
for (var i = 0; i < l; i++) {
_this.onTouchEnd(event.changedTouches[i]);
}
_this.prevent(event);
}, false);
this.canvas.addEventListener("touchcancel", function (event) {
var l = event.changedTouches.length;
for (var i = 0; i < l; i++) {
_this.onTouchEnd(event.changedTouches[i]);
}
_this.prevent(event);
}, false);
};
/**
* @private
*/
WebTouchHandler.prototype.prevent = function (event) {
event.stopPropagation();
if (event["isScroll"] != true && !this.canvas['userTyping']) {
event.preventDefault();
}
};
/**
* @private
*/
WebTouchHandler.prototype.getLocation = function (event) {
event.identifier = +event.identifier || 0;
var doc = document.documentElement;
var box = this.canvas.getBoundingClientRect();
var left = box.left + window.pageXOffset - doc.clientLeft;
var top = box.top + window.pageYOffset - doc.clientTop;
var x = event.pageX - left, newx = x;
var y = event.pageY - top, newy = y;
if (this.rotation == 90) {
newx = y;
newy = box.width - x;
}
else if (this.rotation == -90) {
newx = box.height - y;
newy = x;
}
newx = newx / this.scaleX;
newy = newy / this.scaleY;
return egret.$TempPoint.setTo(Math.round(newx), Math.round(newy));
};
/**
* @private
* 更新屏幕当前的缩放比例,用于计算准确的点击位置。
* @param scaleX 水平方向的缩放比例。
* @param scaleY 垂直方向的缩放比例。
*/
WebTouchHandler.prototype.updateScaleMode = function (scaleX, scaleY, rotation) {
this.scaleX = scaleX;
this.scaleY = scaleY;
this.rotation = rotation;
};
/**
* @private
* 更新同时触摸点的数量
*/
WebTouchHandler.prototype.$updateMaxTouches = function () {
this.touch.$initMaxTouches();
};
return WebTouchHandler;
}(egret.HashObject));
web.WebTouchHandler = WebTouchHandler;
__reflect(WebTouchHandler.prototype, "egret.web.WebTouchHandler");
})(web = egret.web || (egret.web = {}));
})(egret || (egret = {}));
//////////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2014-present, Egret Technology.
// All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of the Egret nor the
// names of its contributors may be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////////////
var egret;
(function (egret) {
var web;
(function (web) {
/**
* @private
*/
web.WebLifeCycleHandler = function (context) {
var handleVisibilityChange = function () {
if (!document[hidden]) {
context.resume();
}
else {
context.pause();
}
};
window.addEventListener("focus", context.resume, false);
window.addEventListener("blur", context.pause, false);
var hidden, visibilityChange;
if (typeof document.hidden !== "undefined") {
hidden = "hidden";
visibilityChange = "visibilitychange";
}
else if (typeof document["mozHidden"] !== "undefined") {
hidden = "mozHidden";
visibilityChange = "mozvisibilitychange";
}
else if (typeof document["msHidden"] !== "undefined") {
hidden = "msHidden";
visibilityChange = "msvisibilitychange";
}
else if (typeof document["webkitHidden"] !== "undefined") {
hidden = "webkitHidden";
visibilityChange = "webkitvisibilitychange";
}
else if (typeof document["oHidden"] !== "undefined") {
hidden = "oHidden";
visibilityChange = "ovisibilitychange";
}
if ("onpageshow" in window && "onpagehide" in window) {
window.addEventListener("pageshow", context.resume, false);
window.addEventListener("pagehide", context.pause, false);
}
if (hidden && visibilityChange) {
document.addEventListener(visibilityChange, handleVisibilityChange, false);
}
var ua = navigator.userAgent;
var isWX = /micromessenger/gi.test(ua);
var isQQBrowser = /mqq/ig.test(ua);
var isQQ = /mobile.*qq/gi.test(ua);
if (isQQ || isWX) {
isQQBrowser = false;
}
if (isQQBrowser) {
var browser = window["browser"] || {};
browser.execWebFn = browser.execWebFn || {};
browser.execWebFn.postX5GamePlayerMessage = function (event) {
var eventType = event.type;
if (eventType == "app_enter_background") {
context.pause();
}
else if (eventType == "app_enter_foreground") {
context.resume();
}
};
window["browser"] = browser;
}
};
})(web = egret.web || (egret.web = {}));
})(egret || (egret = {}));
//////////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2014-present, Egret Technology.
// All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of the Egret nor the
// names of its contributors may be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////////////
var egret;
(function (egret) {
var web;
(function (web) {
/**
* @private
*/
var AudioType = (function () {
function AudioType() {
}
/**
* @private
*/
AudioType.WEB_AUDIO = 2;
/**
* @private
*/
AudioType.HTML5_AUDIO = 3;
return AudioType;
}());
web.AudioType = AudioType;
__reflect(AudioType.prototype, "egret.web.AudioType");
/**
* @private
*/
var SystemOSType = (function () {
function SystemOSType() {
}
/**
* @private
*/
SystemOSType.WPHONE = 1;
/**
* @private
*/
SystemOSType.IOS = 2;
/**
* @private
*/
SystemOSType.ADNROID = 3;
return SystemOSType;
}());
web.SystemOSType = SystemOSType;
__reflect(SystemOSType.prototype, "egret.web.SystemOSType");
/**
* html5兼容性配置
* @private
*/
var Html5Capatibility = (function (_super) {
__extends(Html5Capatibility, _super);
/**
* @private
*/
function Html5Capatibility() {
return _super.call(this) || this;
}
/**
* @private
*
*/
Html5Capatibility.$init = function () {
var ua = navigator.userAgent.toLowerCase();
Html5Capatibility.ua = ua;
egret.Capabilities.$isMobile = (ua.indexOf('mobile') != -1 || ua.indexOf('android') != -1);
Html5Capatibility._canUseBlob = false;
var canUseWebAudio = window["AudioContext"] || window["webkitAudioContext"] || window["mozAudioContext"];
if (canUseWebAudio) {
try {
//防止某些chrome版本创建异常问题
web.WebAudioDecode.ctx = new (window["AudioContext"] || window["webkitAudioContext"] || window["mozAudioContext"])();
}
catch (e) {
canUseWebAudio = false;
}
}
var audioType = Html5Capatibility._audioType;
var checkAudioType;
if ((audioType == AudioType.WEB_AUDIO && canUseWebAudio) || audioType == AudioType.HTML5_AUDIO) {
checkAudioType = false;
Html5Capatibility.setAudioType(audioType);
}
else {
checkAudioType = true;
Html5Capatibility.setAudioType(AudioType.HTML5_AUDIO);
}
if (ua.indexOf("windows phone") >= 0) {
Html5Capatibility._System_OS = SystemOSType.WPHONE;
egret.Capabilities.$os = "Windows Phone";
}
else if (ua.indexOf("android") >= 0) {
egret.Capabilities.$os = "Android";
Html5Capatibility._System_OS = SystemOSType.ADNROID;
if (checkAudioType && canUseWebAudio) {
Html5Capatibility.setAudioType(AudioType.WEB_AUDIO);
}
}
else if (ua.indexOf("iphone") >= 0 || ua.indexOf("ipad") >= 0 || ua.indexOf("ipod") >= 0) {
egret.Capabilities.$os = "iOS";
Html5Capatibility._System_OS = SystemOSType.IOS;
if (Html5Capatibility.getIOSVersion() >= 7) {
Html5Capatibility._canUseBlob = true;
if (checkAudioType && canUseWebAudio) {
Html5Capatibility.setAudioType(AudioType.WEB_AUDIO);
}
}
}
else {
if (ua.indexOf("windows nt") != -1) {
egret.Capabilities.$os = "Windows PC";
}
else if (ua.indexOf("mac os") != -1) {
egret.Capabilities.$os = "Mac OS";
}
}
var winURL = window["URL"] || window["webkitURL"];
if (!winURL) {
Html5Capatibility._canUseBlob = false;
}
if (ua.indexOf("egretnative") >= 0) {
Html5Capatibility.setAudioType(AudioType.HTML5_AUDIO);
Html5Capatibility._canUseBlob = true;
}
egret.Sound = Html5Capatibility._AudioClass;
};
Html5Capatibility.setAudioType = function (type) {
Html5Capatibility._audioType = type;
switch (type) {
case AudioType.WEB_AUDIO:
Html5Capatibility._AudioClass = egret.web.WebAudioSound;
break;
case AudioType.HTML5_AUDIO:
Html5Capatibility._AudioClass = egret.web.HtmlSound;
break;
}
};
/**
* @private
* 获取ios版本
* @returns {string}
*/
Html5Capatibility.getIOSVersion = function () {
var value = Html5Capatibility.ua.toLowerCase().match(/cpu [^\d]*\d.*like mac os x/)[0];
return parseInt(value.match(/\d+(_\d)*/)[0]) || 0;
};
/**
* @private
*
*/
Html5Capatibility.checkHtml5Support = function () {
var language = (navigator.language || navigator["browserLanguage"]).toLowerCase();
var strings = language.split("-");
if (strings.length > 1) {
strings[1] = strings[1].toUpperCase();
}
egret.Capabilities.$language = strings.join("-");
};
//当前浏览器版本是否支持blob
Html5Capatibility._canUseBlob = false;
//当前浏览器版本是否支持webaudio
Html5Capatibility._audioType = 0;
/**
* @private
*/
Html5Capatibility._System_OS = 0;
/**
* @private
*/
Html5Capatibility.ua = "";
return Html5Capatibility;
}(egret.HashObject));
web.Html5Capatibility = Html5Capatibility;
__reflect(Html5Capatibility.prototype, "egret.web.Html5Capatibility");
/**
* @private
*/
var currentPrefix = null;
/**
* @private
*/
function getPrefixStyleName(name, element) {
var header = "";
if (element != null) {
header = getPrefix(name, element);
}
else {
if (currentPrefix == null) {
var tempStyle = document.createElement('div').style;
currentPrefix = getPrefix("transform", tempStyle);
}
header = currentPrefix;
}
if (header == "") {
return name;
}
return header + name.charAt(0).toUpperCase() + name.substring(1, name.length);
}
web.getPrefixStyleName = getPrefixStyleName;
/**
* @private
*/
function getPrefix(name, element) {
if (name in element) {
return "";
}
name = name.charAt(0).toUpperCase() + name.substring(1, name.length);
var transArr = ["webkit", "ms", "Moz", "O"];
for (var i = 0; i < transArr.length; i++) {
var tempStyle = transArr[i] + name;
if (tempStyle in element) {
return transArr[i];
}
}
return "";
}
web.getPrefix = getPrefix;
})(web = egret.web || (egret.web = {}));
})(egret || (egret = {}));
//////////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2014-present, Egret Technology.
// All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of the Egret nor the
// names of its contributors may be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////////////
var egret;
(function (egret) {
var web;
(function (web) {
var customContext;
var context = {
setAutoClear: function (value) {
web.WebGLRenderBuffer.autoClear = value;
},
save: function () {
// do nothing
},
restore: function () {
var context = web.WebGLRenderContext.getInstance(0, 0);
var gl = context.context;
gl.bindBuffer(gl.ARRAY_BUFFER, context["vertexBuffer"]);
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, context["indexBuffer"]);
gl.activeTexture(gl.TEXTURE0);
context.currentProgram = null;
context["bindIndices"] = false;
var buffer = context.$bufferStack[1];
context["activateBuffer"](buffer);
gl.enable(gl.BLEND);
context["setBlendMode"]("source-over");
}
};
function setRendererContext(custom) {
custom.onStart(context);
customContext = custom;
}
egret.setRendererContext = setRendererContext;
/**
* @private
* 刷新所有Egret播放器的显示区域尺寸。仅当使用外部JavaScript代码动态修改了Egret容器大小时,需要手动调用此方法刷新显示区域。
* 当网页尺寸发生改变时此方法会自动被调用。
*/
function updateAllScreens() {
if (!isRunning) {
return;
}
var containerList = document.querySelectorAll(".egret-player");
var length = containerList.length;
for (var i = 0; i < length; i++) {
var container = containerList[i];
var player = container["egret-player"];
player.updateScreenSize();
}
}
var isRunning = false;
/**
* @private
* 网页加载完成,实例化页面中定义的Egret标签
*/
function runEgret(options) {
if (isRunning) {
return;
}
isRunning = true;
if (!options) {
options = {};
}
web.Html5Capatibility._audioType = options.audioType;
web.Html5Capatibility.$init();
// WebGL上下文参数自定义
if (options.renderMode == "webgl") {
// WebGL抗锯齿默认关闭,提升PC及某些平台性能
var antialias = options.antialias;
web.WebGLRenderContext.antialias = !!antialias;
// WebGLRenderContext.antialias = (typeof antialias == undefined) ? true : antialias;
}
egret.sys.CanvasRenderBuffer = web.CanvasRenderBuffer;
setRenderMode(options.renderMode);
if (options.retina) {
//based on : https://github.com/jondavidjohn/hidpi-canvas-polyfill
var context_1 = egret.sys.canvasHitTestBuffer.context;
var backingStore = context_1.backingStorePixelRatio ||
context_1.webkitBackingStorePixelRatio ||
context_1.mozBackingStorePixelRatio ||
context_1.msBackingStorePixelRatio ||
context_1.oBackingStorePixelRatio ||
context_1.backingStorePixelRatio || 1;
egret.sys.DisplayList.$setDevicePixelRatio((window.devicePixelRatio || 1) / backingStore);
}
var ticker = egret.ticker;
startTicker(ticker);
if (options.screenAdapter) {
egret.sys.screenAdapter = options.screenAdapter;
}
else if (!egret.sys.screenAdapter) {
egret.sys.screenAdapter = new egret.sys.DefaultScreenAdapter();
}
var list = document.querySelectorAll(".egret-player");
var length = list.length;
for (var i = 0; i < length; i++) {
var container = list[i];
var player = new web.WebPlayer(container, options);
container["egret-player"] = player;
//webgl模式关闭脏矩形
if (egret.Capabilities.$renderMode == "webgl") {
player.stage.dirtyRegionPolicy = egret.DirtyRegionPolicy.OFF;
}
}
if (egret.Capabilities.$renderMode == "webgl") {
egret.sys.DisplayList.prototype.setDirtyRegionPolicy = function () { };
}
window.addEventListener("resize", function () {
if (isNaN(resizeTimer)) {
resizeTimer = window.setTimeout(doResize, 300);
}
});
}
/**
* 设置渲染模式。"auto","webgl","canvas"
* @param renderMode
*/
function setRenderMode(renderMode) {
if (renderMode == "webgl" && egret.WebGLUtils.checkCanUseWebGL()) {
egret.sys.RenderBuffer = web.WebGLRenderBuffer;
egret.sys.systemRenderer = new web.WebGLRenderer();
egret.sys.canvasRenderer = new egret.CanvasRenderer();
egret.sys.customHitTestBuffer = new web.WebGLRenderBuffer(3, 3);
egret.sys.canvasHitTestBuffer = new web.CanvasRenderBuffer(3, 3);
egret.Capabilities.$renderMode = "webgl";
}
else {
egret.sys.RenderBuffer = web.CanvasRenderBuffer;
egret.sys.systemRenderer = new egret.CanvasRenderer();
egret.sys.canvasRenderer = egret.sys.systemRenderer;
egret.sys.customHitTestBuffer = new web.CanvasRenderBuffer(3, 3);
egret.sys.canvasHitTestBuffer = egret.sys.customHitTestBuffer;
egret.Capabilities.$renderMode = "canvas";
}
}
/**
* @private
* 启动心跳计时器。
*/
function startTicker(ticker) {
var requestAnimationFrame = window["requestAnimationFrame"] ||
window["webkitRequestAnimationFrame"] ||
window["mozRequestAnimationFrame"] ||
window["oRequestAnimationFrame"] ||
window["msRequestAnimationFrame"];
if (!requestAnimationFrame) {
requestAnimationFrame = function (callback) {
return window.setTimeout(callback, 1000 / 60);
};
}
requestAnimationFrame(onTick);
function onTick() {
if (customContext) {
customContext.onRender(context);
}
ticker.update();
requestAnimationFrame(onTick);
}
}
//覆盖原生的isNaN()方法实现,在不同浏览器上有2~10倍性能提升。
window["isNaN"] = function (value) {
value = +value;
return value !== value;
};
egret.runEgret = runEgret;
egret.updateAllScreens = updateAllScreens;
var resizeTimer = NaN;
function doResize() {
resizeTimer = NaN;
egret.updateAllScreens();
if (customContext) {
customContext.onResize(context);
}
}
})(web = egret.web || (egret.web = {}));
})(egret || (egret = {}));
if (true) {
var language = navigator.language || navigator["browserLanguage"] || "en_US";
language = language.replace("-", "_");
if (language in egret.$locale_strings)
egret.$language = language;
}
//////////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2014-present, Egret Technology.
// All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of the Egret nor the
// names of its contributors may be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////////////
var egret;
(function (egret) {
var web;
(function (web) {
/**
* @private
*/
var WebCapability = (function () {
function WebCapability() {
}
/**
* @private
* 检测系统属性
*/
WebCapability.detect = function () {
var capabilities = egret.Capabilities;
var ua = navigator.userAgent.toLowerCase();
capabilities.$isMobile = (ua.indexOf('mobile') != -1 || ua.indexOf('android') != -1);
if (capabilities.$isMobile) {
if (ua.indexOf("windows") < 0 && (ua.indexOf("iphone") != -1 || ua.indexOf("ipad") != -1 || ua.indexOf("ipod") != -1)) {
capabilities.$os = "iOS";
}
else if (ua.indexOf("android") != -1 && ua.indexOf("linux") != -1) {
capabilities.$os = "Android";
}
else if (ua.indexOf("windows") != -1) {
capabilities.$os = "Windows Phone";
}
}
else {
if (ua.indexOf("windows nt") != -1) {
capabilities.$os = "Windows PC";
}
else if (ua.indexOf("mac os") != -1) {
capabilities.$os = "Mac OS";
}
}
var language = (navigator.language || navigator["browserLanguage"]).toLowerCase();
var strings = language.split("-");
if (strings.length > 1) {
strings[1] = strings[1].toUpperCase();
}
capabilities.$language = strings.join("-");
WebCapability.injectUIntFixOnIE9();
};
WebCapability.injectUIntFixOnIE9 = function () {
if (/msie 9.0/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent)) {
var IEBinaryToArray_ByteStr_Script = "\r\n" +
"