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 __extends(t, e) { function r() { this.constructor = t; } for (var i in e) e.hasOwnProperty(i) && (t[i] = e[i]); r.prototype = e.prototype, t.prototype = new r(); }; var egret; (function (egret) { var web; (function (web) { /** * @private */ var WebGeolocation = (function (_super) { __extends(WebGeolocation, _super); /** * @private */ function WebGeolocation(option) { var _this = _super.call(this) || this; /** * @private */ _this.onUpdate = function (position) { var event = new egret.GeolocationEvent(egret.Event.CHANGE); var coords = position.coords; event.altitude = coords.altitude; event.heading = coords.heading; event.accuracy = coords.accuracy; event.latitude = coords.latitude; event.longitude = coords.longitude; event.speed = coords.speed; event.altitudeAccuracy = coords.altitudeAccuracy; _this.dispatchEvent(event); }; /** * @private */ _this.onError = function (error) { var errorType = egret.GeolocationEvent.UNAVAILABLE; if (error.code == error.PERMISSION_DENIED) errorType = egret.GeolocationEvent.PERMISSION_DENIED; var event = new egret.GeolocationEvent(egret.IOErrorEvent.IO_ERROR); event.errorType = errorType; event.errorMessage = error.message; _this.dispatchEvent(event); }; _this.geolocation = navigator.geolocation; return _this; } /** * @private * */ WebGeolocation.prototype.start = function () { var geo = this.geolocation; if (geo) this.watchId = geo.watchPosition(this.onUpdate, this.onError); else this.onError({ code: 2, message: egret.sys.tr(3004), PERMISSION_DENIED: 1, POSITION_UNAVAILABLE: 2 }); }; /** * @private * */ WebGeolocation.prototype.stop = function () { var geo = this.geolocation; geo.clearWatch(this.watchId); }; return WebGeolocation; }(egret.EventDispatcher)); web.WebGeolocation = WebGeolocation; __reflect(WebGeolocation.prototype, "egret.web.WebGeolocation", ["egret.Geolocation"]); })(web = egret.web || (egret.web = {})); })(egret || (egret = {})); var egret; (function (egret) { var web; (function (web) { /** * @private */ var WebMotion = (function (_super) { __extends(WebMotion, _super); function WebMotion() { var _this = _super !== null && _super.apply(this, arguments) || this; /** * @private */ _this.onChange = function (e) { var event = new egret.MotionEvent(egret.Event.CHANGE); var acceleration = { x: e.acceleration.x, y: e.acceleration.y, z: e.acceleration.z }; var accelerationIncludingGravity = { x: e.accelerationIncludingGravity.x, y: e.accelerationIncludingGravity.y, z: e.accelerationIncludingGravity.z }; var rotation = { alpha: e.rotationRate.alpha, beta: e.rotationRate.beta, gamma: e.rotationRate.gamma }; event.acceleration = acceleration; event.accelerationIncludingGravity = accelerationIncludingGravity; event.rotationRate = rotation; _this.dispatchEvent(event); }; return _this; } /** * @private * */ WebMotion.prototype.start = function () { window.addEventListener("devicemotion", this.onChange); }; /** * @private * */ WebMotion.prototype.stop = function () { window.removeEventListener("devicemotion", this.onChange); }; return WebMotion; }(egret.EventDispatcher)); web.WebMotion = WebMotion; __reflect(WebMotion.prototype, "egret.web.WebMotion", ["egret.Motion"]); })(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 */ function getOption(key) { if (window.location) { var search = location.search; if (search == "") { return ""; } search = search.slice(1); var searchArr = search.split("&"); var length_1 = searchArr.length; for (var i = 0; i < length_1; i++) { var str = searchArr[i]; var arr = str.split("="); if (arr[0] == key) { return arr[1]; } } } return ""; } web.getOption = getOption; egret.getOption = getOption; })(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.removeEventListener("canplay", this.canPlay); 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 () { egret.log('sound decode error'); 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.addEventListener("load", function () { var ioError = (request.status >= 400); 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.addEventListener("error", function () { self.dispatchEventWith(egret.IOErrorEvent.IO_ERROR); }); 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; 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; } WebVideo.prototype.createNativeDisplayObject = function () { this.$nativeDisplayObject = new egret_native.NativeDisplayObject(1 /* BITMAP */); }; /** * @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.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; this.video.pause(); egret.stopTick(this.markDirty, this); }; 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.$renderDirty = true; _this.posterData.width = _this.getPlayWidth(); _this.posterData.height = _this.getPlayHeight(); if (egret.nativeRender) { var texture = new egret.Texture(); texture._setBitmapData(_this.posterData); _this.$nativeDisplayObject.setTexture(texture); } }, 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.$updateRenderNode = 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.$renderDirty = true; return true; }; /** * @private * 设置显示高度 */ WebVideo.prototype.$setHeight = function (value) { this.heightSet = value; if (this.paused) { var self_1 = this; this.$renderDirty = true; window.setTimeout(function () { self_1.$renderDirty = false; }, 200); } _super.prototype.$setHeight.call(this, value); }; /** * @private * 设置显示宽度 */ WebVideo.prototype.$setWidth = function (value) { this.widthSet = value; if (this.paused) { var self_2 = this; this.$renderDirty = true; window.setTimeout(function () { self_2.$renderDirty = false; }, 200); } _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; /** * */ _this.timeout = 0; /** * @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; } var xhr = this.getXHR(); //new XMLHttpRequest(); if (window["XMLHttpRequest"]) { xhr.addEventListener("load", this.onload.bind(this)); xhr.addEventListener("error", this.onerror.bind(this)); } else { xhr.onreadystatechange = this.onReadyStateChange.bind(this); } xhr.onprogress = this.updateProgress.bind(this); xhr.ontimeout = this.onTimeout.bind(this); xhr.open(this._method, this._url, true); this._xhr = xhr; }; /** * @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.timeout = this.timeout; 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.onTimeout = function () { if (true) { egret.$warn(1052, this._url); } this.dispatchEventWith(egret.IOErrorEvent.IO_ERROR); }; /** * @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_3 = this; window.setTimeout(function () { if (ioError_1) { if (true && !self_3.hasEventListener(egret.IOErrorEvent.IO_ERROR)) { egret.$error(1011, url_1); } self_3.dispatchEventWith(egret.IOErrorEvent.IO_ERROR); } else { self_3.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); } }; /** * @private */ WebHttpRequest.prototype.onload = function () { var self = this; var xhr = this._xhr; var url = this._url; var ioError = (xhr.status >= 400); window.setTimeout(function () { if (ioError) { if (true && !self.hasEventListener(egret.IOErrorEvent.IO_ERROR)) { egret.$error(1011, url); } self.dispatchEventWith(egret.IOErrorEvent.IO_ERROR); } else { self.dispatchEventWith(egret.Event.COMPLETE); } }, 0); }; /** * @private */ WebHttpRequest.prototype.onerror = function () { var url = this._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); }; 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.onFocusHandler = function () { //the soft keyboard will cover the input box in some cases var self = this; window.setTimeout(function () { if (self.inputElement) { self.inputElement.scrollIntoView(); } }, 200); }; /** * @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); } if (this.inputElement.onfocus == null) { this.inputElement.onfocus = this.onFocusHandler.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 () { }; /** * @private * */ HTML5StageText.prototype._onInput = function () { var self = this; 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; } this.$scaleX = egret.sys.DisplayList.$canvasScaleX; this.$scaleY = egret.sys.DisplayList.$canvasScaleY; 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) { if (this._inputElement) { this._inputElement.blur(); } this.clearInputElement(); } this._needShow = false; }; /** * @private * */ HTMLInput.prototype.clearInputElement = function () { var self = this; if (self._inputElement) { self._inputElement.value = ""; self._inputElement.onblur = null; self._inputElement.onfocus = 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 egret.sys.measureTextWith(context, text); } /** * @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 = egret.sys.createCanvas(width, 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 = egret.sys.createCanvasRenderBufferSurface(__createCanvas__, width, height, root); this.context = this.surface.getContext("2d"); if (this.context) { this.context.$offsetX = 0; this.context.$offsetY = 0; } this.resize(width, height); } 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) { egret.sys.resizeCanvasRenderBuffer(this, width, height, useMaxSize); }; /** * 获取指定区域的像素 */ 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); }; _this.onMouseMove = function (event) { if (event.buttons == 0) { _this.onTouchEnd(event); } else { _this.onTouchMove(event); } }; /** * @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.onMouseMove); 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"); /** * 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; Html5Capatibility._canUseBlob = false; var canUseWebAudio = window["AudioContext"] || window["webkitAudioContext"] || window["mozAudioContext"]; var isIos = ua.indexOf("iphone") >= 0 || ua.indexOf("ipad") >= 0 || ua.indexOf("ipod") >= 0; 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 if (!isIos && ua.indexOf("safari") >= 0 && ua.indexOf("chrome") === -1) { // In Safari browser on Mac,use web audio checkAudioType = false; Html5Capatibility.setAudioType(AudioType.WEB_AUDIO); } else { checkAudioType = true; Html5Capatibility.setAudioType(AudioType.HTML5_AUDIO); } if (ua.indexOf("android") >= 0) { if (checkAudioType && canUseWebAudio) { Html5Capatibility.setAudioType(AudioType.WEB_AUDIO); } } else if (isIos) { if (Html5Capatibility.getIOSVersion() >= 7) { Html5Capatibility._canUseBlob = true; if (checkAudioType && canUseWebAudio) { Html5Capatibility.setAudioType(AudioType.WEB_AUDIO); } } } 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 matches = Html5Capatibility.ua.toLowerCase().match(/cpu [^\d]*\d.*like mac os x/); if (!matches || matches.length == 0) { return 0; } var value = matches[0]; return parseInt(value.match(/\d+(_\d)*/)[0]) || 0; }; //当前浏览器版本是否支持blob Html5Capatibility._canUseBlob = false; //当前浏览器版本是否支持webaudio Html5Capatibility._audioType = 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) { /** * 创建一个canvas。 */ function mainCanvas(width, height) { return createCanvas(width, height); } egret.sys.mainCanvas = mainCanvas; function createCanvas(width, height) { var canvas = document.createElement("canvas"); if (!isNaN(width) && !isNaN(height)) { canvas.width = width; canvas.height = height; } return canvas; } egret.sys.createCanvas = createCanvas; /** * sys.resizeContext。 */ function resizeContext(renderContext, width, height, useMaxSize) { if (!renderContext) { return; } var webglrendercontext = renderContext; var surface = webglrendercontext.surface; if (useMaxSize) { if (surface.width < width) { surface.width = width; } if (surface.height < height) { surface.height = height; } } else { if (surface.width !== width) { surface.width = width; } if (surface.height !== height) { surface.height = height; } } webglrendercontext.onResize(); } web.resizeContext = resizeContext; egret.sys.resizeContext = resizeContext; /** * sys.getContextWebGL */ function getContextWebGL(surface) { var options = { antialias: web.WebGLRenderContext.antialias, stencil: true //设置可以使用模板(用于不规则遮罩) }; var gl = null; //todo 是否使用chrome源码names //let contextNames = ["moz-webgl", "webkit-3d", "experimental-webgl", "webgl", "3d"]; var names = ["webgl", "experimental-webgl"]; for (var i = 0; i < names.length; ++i) { try { gl = surface.getContext(names[i], options); } catch (e) { } if (gl) { break; } } if (!gl) { egret.$error(1021); } return gl; } egret.sys.getContextWebGL = getContextWebGL; /** * sys.getContext2d */ function getContext2d(surface) { return surface ? surface.getContext('2d') : null; } web.getContext2d = getContext2d; egret.sys.getContext2d = getContext2d; /** * 创建一个WebGLTexture */ function createTexture(renderContext, bitmapData) { var webglrendercontext = renderContext; var gl = webglrendercontext.context; var texture = gl.createTexture(); if (!texture) { //先创建texture失败,然后lost事件才发出来.. webglrendercontext.contextLost = true; return; } texture[egret.glContext] = gl; gl.bindTexture(gl.TEXTURE_2D, texture); gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, 1); texture[egret.UNPACK_PREMULTIPLY_ALPHA_WEBGL] = true; gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, bitmapData); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); return texture; } egret.sys.createTexture = createTexture; /** * 创建一个WebGLTexture */ function _createTexture(renderContext, width, height, data) { var webglrendercontext = renderContext; var gl = webglrendercontext.context; var texture = gl.createTexture(); if (!texture) { //先创建texture失败,然后lost事件才发出来.. webglrendercontext.contextLost = true; return null; } // texture[egret.glContext] = gl; gl.bindTexture(gl.TEXTURE_2D, texture); gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, 1); texture[egret.UNPACK_PREMULTIPLY_ALPHA_WEBGL] = true; gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, data); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); return texture; } egret.sys._createTexture = _createTexture; /** * 画texture **/ function drawTextureElements(renderContext, data, offset) { var webglrendercontext = renderContext; var gl = webglrendercontext.context; gl.activeTexture(gl.TEXTURE0); gl.bindTexture(gl.TEXTURE_2D, data.texture); var size = data.count * 3; gl.drawElements(gl.TRIANGLES, size, gl.UNSIGNED_SHORT, offset * 2); return size; } egret.sys.drawTextureElements = drawTextureElements; /** * 测量文本的宽度 * @param context * @param text */ function measureTextWith(context, text) { return context.measureText(text).width; } egret.sys.measureTextWith = measureTextWith; /** * 为CanvasRenderBuffer创建一个HTMLCanvasElement * @param defaultFunc * @param width * @param height * @param root */ function createCanvasRenderBufferSurface(defaultFunc, width, height, root) { return defaultFunc(width, height); } egret.sys.createCanvasRenderBufferSurface = createCanvasRenderBufferSurface; /** * 改变渲染缓冲的大小并清空缓冲区 * @param renderContext * @param width * @param height * @param useMaxSize */ function resizeCanvasRenderBuffer(renderContext, width, height, useMaxSize) { var canvasRenderBuffer = renderContext; var surface = canvasRenderBuffer.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) { canvasRenderBuffer.context.globalCompositeOperation = "source-over"; canvasRenderBuffer.context.setTransform(1, 0, 0, 1, 0, 0); canvasRenderBuffer.context.globalAlpha = 1; } } else { if (surface.width != width) { surface.width = width; } if (surface.height != height) { surface.height = height; } } canvasRenderBuffer.clear(); } egret.sys.resizeCanvasRenderBuffer = resizeCanvasRenderBuffer; egret.Geolocation = egret.web.WebGeolocation; egret.Motion = egret.web.WebMotion; })(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 * 刷新所有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 = {}; } var ua = navigator.userAgent.toLowerCase(); if (ua.indexOf("egretnative") >= 0 && ua.indexOf("egretwebview") == -1) { egret.Capabilities["runtimeType" + ""] = egret.RuntimeType.RUNTIME2; } if (ua.indexOf("egretnative") >= 0 && egret.nativeRender) { egret_native.addModuleCallback(function () { web.Html5Capatibility.$init(); // WebGL上下文参数自定义 if (options.renderMode == "webgl") { // WebGL抗锯齿默认关闭,提升PC及某些平台性能 var antialias = options.antialias; web.WebGLRenderContext.antialias = !!antialias; } egret.sys.CanvasRenderBuffer = web.CanvasRenderBuffer; setRenderMode(options.renderMode); egret_native.nrSetRenderMode(2); var canvasScaleFactor; if (options.canvasScaleFactor) { canvasScaleFactor = options.canvasScaleFactor; } else if (options.calculateCanvasScaleFactor) { canvasScaleFactor = options.calculateCanvasScaleFactor(egret.sys.canvasHitTestBuffer.context); } else { canvasScaleFactor = window.devicePixelRatio; } egret.sys.DisplayList.$canvasScaleFactor = canvasScaleFactor; 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; } window.addEventListener("resize", function () { if (isNaN(resizeTimer)) { resizeTimer = window.setTimeout(doResize, 300); } }); }, null); egret_native.initNativeRender(); } else { web.Html5Capatibility._audioType = options.audioType; web.Html5Capatibility.$init(); var renderMode = options.renderMode; // WebGL上下文参数自定义 if (renderMode == "webgl") { // WebGL抗锯齿默认关闭,提升PC及某些平台性能 var antialias = options.antialias; web.WebGLRenderContext.antialias = !!antialias; // WebGLRenderContext.antialias = (typeof antialias == undefined) ? true : antialias; } egret.sys.CanvasRenderBuffer = web.CanvasRenderBuffer; if (ua.indexOf("egretnative") >= 0 && renderMode != "webgl") { egret.$warn(1051); renderMode = "webgl"; } setRenderMode(renderMode); var canvasScaleFactor = void 0; if (options.canvasScaleFactor) { canvasScaleFactor = options.canvasScaleFactor; } else if (options.calculateCanvasScaleFactor) { canvasScaleFactor = options.calculateCanvasScaleFactor(egret.sys.canvasHitTestBuffer.context); } else { //based on : https://github.com/jondavidjohn/hidpi-canvas-polyfill var context = egret.sys.canvasHitTestBuffer.context; var backingStore = context.backingStorePixelRatio || context.webkitBackingStorePixelRatio || context.mozBackingStorePixelRatio || context.msBackingStorePixelRatio || context.oBackingStorePixelRatio || context.backingStorePixelRatio || 1; canvasScaleFactor = (window.devicePixelRatio || 1) / backingStore; } egret.sys.DisplayList.$canvasScaleFactor = canvasScaleFactor; var ticker_1 = egret.ticker; startTicker(ticker_1); 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_2 = list.length; for (var i = 0; i < length_2; i++) { var container = list[i]; var player = new web.WebPlayer(container, options); container["egret-player"] = player; } 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() { requestAnimationFrame(onTick); ticker.update(); } } //覆盖原生的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(); } })(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 (navigator.platform == "MacIntel" && navigator.maxTouchPoints > 1) { capabilities["os" + ""] = "iOS"; capabilities["isMobile" + ""] = true; } 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" + "