Comparing version 4.4.4 to 4.5.0
@@ -39,3 +39,3 @@ 'use strict'; | ||
/** | ||
* The Accessibility manager reacreates the ability to tab and and have content read by screen | ||
* The Accessibility manager recreates the ability to tab and have content read by screen | ||
* readers. This is very important as it can possibly help people with disabilities access pixi | ||
@@ -45,3 +45,3 @@ * content. | ||
* Much like interaction any DisplayObject can be made accessible. This manager will map the | ||
* events as if the mouse was being used, minimizing the efferot required to implement. | ||
* events as if the mouse was being used, minimizing the effort required to implement. | ||
* | ||
@@ -100,3 +100,3 @@ * An instance of this class is automatically created by default, and can be found at renderer.plugins.accessibility | ||
/** | ||
* Setting this to true will visually show the divs | ||
* Setting this to true will visually show the divs. | ||
* | ||
@@ -131,3 +131,3 @@ * @type {boolean} | ||
/** | ||
* stores the state of the manager. If there are no accessible objects or the mouse is moving the will be false. | ||
* stores the state of the manager. If there are no accessible objects or the mouse is moving, this will be false. | ||
* | ||
@@ -175,3 +175,3 @@ * @member {Array<*>} | ||
* Activating will cause the Accessibility layer to be shown. This is called when a user | ||
* preses the tab key | ||
* preses the tab key. | ||
* | ||
@@ -201,3 +201,3 @@ * @private | ||
* Deactivating will cause the Accessibility layer to be hidden. This is called when a user moves | ||
* the mouse | ||
* the mouse. | ||
* | ||
@@ -226,3 +226,3 @@ * @private | ||
/** | ||
* This recursive function will run throught he scene graph and add any new accessible objects to the DOM layer. | ||
* This recursive function will run through the scene graph and add any new accessible objects to the DOM layer. | ||
* | ||
@@ -417,3 +417,3 @@ * @private | ||
/** | ||
* Maps the div focus events to pixis InteractionManager (mouseover) | ||
* Maps the div focus events to pixi's InteractionManager (mouseover) | ||
* | ||
@@ -432,3 +432,3 @@ * @private | ||
/** | ||
* Maps the div focus events to pixis InteractionManager (mouseout) | ||
* Maps the div focus events to pixi's InteractionManager (mouseout) | ||
* | ||
@@ -435,0 +435,0 @@ * @private |
@@ -15,2 +15,8 @@ 'use strict'; | ||
var _settings = require('./settings'); | ||
var _settings2 = _interopRequireDefault(_settings); | ||
var _const = require('./const'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -39,135 +45,161 @@ | ||
var Application = function () { | ||
/** | ||
* @param {number} [width=800] - the width of the renderers view | ||
* @param {number} [height=600] - the height of the renderers view | ||
* @param {object} [options] - The optional renderer parameters | ||
* @param {HTMLCanvasElement} [options.view] - the canvas to use as a view, optional | ||
* @param {boolean} [options.transparent=false] - If the render view is transparent, default false | ||
* @param {boolean} [options.antialias=false] - sets antialias (only applicable in chrome at the moment) | ||
* @param {boolean} [options.preserveDrawingBuffer=false] - enables drawing buffer preservation, enable this if you | ||
* need to call toDataUrl on the webgl context | ||
* @param {number} [options.resolution=1] - The resolution / device pixel ratio of the renderer, retina would be 2 | ||
* @param {boolean} [noWebGL=false] - prevents selection of WebGL renderer, even if such is present | ||
* @param {boolean} [options.legacy=false] - If true Pixi will aim to ensure compatibility | ||
* with older / less advanced devices. If you experience unexplained flickering try setting this to true. | ||
* @param {boolean} [useSharedTicker=false] - `true` to use PIXI.ticker.shared, `false` to create new ticker. | ||
*/ | ||
function Application(width, height, options, noWebGL) { | ||
var useSharedTicker = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false; | ||
_classCallCheck(this, Application); | ||
// eslint-disable-next-line valid-jsdoc | ||
/** | ||
* WebGL renderer if available, otherwise CanvasRenderer | ||
* @member {PIXI.WebGLRenderer|PIXI.CanvasRenderer} | ||
* @param {object} [options] - The optional renderer parameters | ||
* @param {number} [options.width=800] - the width of the renderers view | ||
* @param {number} [options.height=600] - the height of the renderers view | ||
* @param {HTMLCanvasElement} [options.view] - the canvas to use as a view, optional | ||
* @param {boolean} [options.transparent=false] - If the render view is transparent, default false | ||
* @param {boolean} [options.antialias=false] - sets antialias (only applicable in chrome at the moment) | ||
* @param {boolean} [options.preserveDrawingBuffer=false] - enables drawing buffer preservation, enable this if you | ||
* need to call toDataUrl on the webgl context | ||
* @param {number} [options.resolution=1] - The resolution / device pixel ratio of the renderer, retina would be 2 | ||
* @param {boolean} [options.forceCanvas=false] - prevents selection of WebGL renderer, even if such is present | ||
* @param {boolean} [options.legacy=false] - If true Pixi will aim to ensure compatibility | ||
* with older / less advanced devices. If you experience unexplained flickering try setting this to true. | ||
* @param {boolean} [options.sharedTicker=false] - `true` to use PIXI.ticker.shared, `false` to create new ticker. | ||
* @param {boolean} [options.sharedLoader=false] - `true` to use PIXI.loaders.shared, `false` to create new Loader. | ||
*/ | ||
this.renderer = (0, _autoDetectRenderer.autoDetectRenderer)(width, height, options, noWebGL); | ||
function Application(options, arg2, arg3, arg4, arg5) { | ||
_classCallCheck(this, Application); | ||
/** | ||
* The root display container that's rendered. | ||
* @member {PIXI.Container} | ||
*/ | ||
this.stage = new _Container2.default(); | ||
// Support for constructor(width, height, options, noWebGL, useSharedTicker) | ||
if (typeof options === 'number') { | ||
options = Object.assign({ | ||
width: options, | ||
height: arg2 || _settings2.default.RENDER_OPTIONS.height, | ||
forceCanvas: !!arg4, | ||
sharedTicker: !!arg5 | ||
}, arg3); | ||
} | ||
/** | ||
* The default options, so we mixin functionality later. | ||
* @member {object} | ||
* @protected | ||
*/ | ||
this._options = options = Object.assign({ | ||
sharedTicker: false, | ||
forceCanvas: false, | ||
sharedLoader: false | ||
}, options); | ||
/** | ||
* WebGL renderer if available, otherwise CanvasRenderer | ||
* @member {PIXI.WebGLRenderer|PIXI.CanvasRenderer} | ||
*/ | ||
this.renderer = (0, _autoDetectRenderer.autoDetectRenderer)(options); | ||
/** | ||
* The root display container that's rendered. | ||
* @member {PIXI.Container} | ||
*/ | ||
this.stage = new _Container2.default(); | ||
/** | ||
* Internal reference to the ticker | ||
* @member {PIXI.ticker.Ticker} | ||
* @private | ||
*/ | ||
this._ticker = null; | ||
/** | ||
* Ticker for doing render updates. | ||
* @member {PIXI.ticker.Ticker} | ||
* @default PIXI.ticker.shared | ||
*/ | ||
this.ticker = options.sharedTicker ? _ticker.shared : new _ticker.Ticker(); | ||
// Start the rendering | ||
this.start(); | ||
} | ||
/** | ||
* Internal reference to the ticker | ||
* @member {PIXI.ticker.Ticker} | ||
* @private | ||
* Render the current stage. | ||
*/ | ||
this._ticker = null; | ||
Application.prototype.render = function render() { | ||
this.renderer.render(this.stage); | ||
}; | ||
/** | ||
* Ticker for doing render updates. | ||
* @member {PIXI.ticker.Ticker} | ||
* @default PIXI.ticker.shared | ||
* Convenience method for stopping the render. | ||
*/ | ||
this.ticker = useSharedTicker ? _ticker.shared : new _ticker.Ticker(); | ||
// Start the rendering | ||
this.start(); | ||
} | ||
/** | ||
* Render the current stage. | ||
*/ | ||
Application.prototype.render = function render() { | ||
this.renderer.render(this.stage); | ||
}; | ||
Application.prototype.stop = function stop() { | ||
this._ticker.stop(); | ||
}; | ||
/** | ||
* Convenience method for stopping the render. | ||
*/ | ||
/** | ||
* Convenience method for starting the render. | ||
*/ | ||
Application.prototype.stop = function stop() { | ||
this._ticker.stop(); | ||
}; | ||
Application.prototype.start = function start() { | ||
this._ticker.start(); | ||
}; | ||
/** | ||
* Convenience method for starting the render. | ||
*/ | ||
/** | ||
* Reference to the renderer's canvas element. | ||
* @member {HTMLCanvasElement} | ||
* @readonly | ||
*/ | ||
Application.prototype.start = function start() { | ||
this._ticker.start(); | ||
}; | ||
/** | ||
* Destroy and don't use after this. | ||
* @param {Boolean} [removeView=false] Automatically remove canvas from DOM. | ||
*/ | ||
Application.prototype.destroy = function destroy(removeView) { | ||
var oldTicker = this._ticker; | ||
/** | ||
* Reference to the renderer's canvas element. | ||
* @member {HTMLCanvasElement} | ||
* @readonly | ||
*/ | ||
this.ticker = null; | ||
oldTicker.destroy(); | ||
/** | ||
* Destroy and don't use after this. | ||
* @param {Boolean} [removeView=false] Automatically remove canvas from DOM. | ||
*/ | ||
Application.prototype.destroy = function destroy(removeView) { | ||
this.stop(); | ||
this.ticker = null; | ||
this.stage.destroy(); | ||
this.stage = null; | ||
this.stage.destroy(); | ||
this.stage = null; | ||
this.renderer.destroy(removeView); | ||
this.renderer = null; | ||
this.renderer.destroy(removeView); | ||
this.renderer = null; | ||
}; | ||
this._options = null; | ||
}; | ||
_createClass(Application, [{ | ||
key: 'ticker', | ||
set: function set(ticker) // eslint-disable-line require-jsdoc | ||
{ | ||
if (this._ticker) { | ||
this._ticker.remove(this.render, this); | ||
} | ||
this._ticker = ticker; | ||
if (ticker) { | ||
ticker.add(this.render, this); | ||
} | ||
}, | ||
get: function get() // eslint-disable-line require-jsdoc | ||
{ | ||
return this._ticker; | ||
} | ||
}, { | ||
key: 'view', | ||
get: function get() { | ||
return this.renderer.view; | ||
} | ||
_createClass(Application, [{ | ||
key: 'ticker', | ||
set: function set(ticker) // eslint-disable-line require-jsdoc | ||
{ | ||
if (this._ticker) { | ||
this._ticker.remove(this.render, this); | ||
} | ||
this._ticker = ticker; | ||
if (ticker) { | ||
ticker.add(this.render, this, _const.UPDATE_PRIORITY.LOW); | ||
} | ||
}, | ||
get: function get() // eslint-disable-line require-jsdoc | ||
{ | ||
return this._ticker; | ||
} | ||
}, { | ||
key: 'view', | ||
get: function get() { | ||
return this.renderer.view; | ||
} | ||
/** | ||
* Reference to the renderer's screen rectangle. Its safe to use as filterArea or hitArea for whole screen | ||
* @member {PIXI.Rectangle} | ||
* @readonly | ||
*/ | ||
/** | ||
* Reference to the renderer's screen rectangle. Its safe to use as filterArea or hitArea for whole screen | ||
* @member {PIXI.Rectangle} | ||
* @readonly | ||
*/ | ||
}, { | ||
key: 'screen', | ||
get: function get() { | ||
return this.renderer.screen; | ||
} | ||
}]); | ||
}, { | ||
key: 'screen', | ||
get: function get() { | ||
return this.renderer.screen; | ||
} | ||
}]); | ||
return Application; | ||
return Application; | ||
}(); | ||
@@ -174,0 +206,0 @@ |
@@ -22,2 +22,3 @@ 'use strict'; | ||
// eslint-disable-next-line valid-jsdoc | ||
/** | ||
@@ -30,5 +31,5 @@ * This helper function will automatically detect which renderer you should be using. | ||
* @function autoDetectRenderer | ||
* @param {number} [width=800] - the width of the renderers view | ||
* @param {number} [height=600] - the height of the renderers view | ||
* @param {object} [options] - The optional renderer parameters | ||
* @param {number} [options.width=800] - the width of the renderers view | ||
* @param {number} [options.height=600] - the height of the renderers view | ||
* @param {HTMLCanvasElement} [options.view] - the canvas to use as a view, optional | ||
@@ -40,17 +41,19 @@ * @param {boolean} [options.transparent=false] - If the render view is transparent, default false | ||
* @param {number} [options.resolution=1] - The resolution / device pixel ratio of the renderer, retina would be 2 | ||
* @param {boolean} [noWebGL=false] - prevents selection of WebGL renderer, even if such is present | ||
* @param {boolean} [options.forceCanvas=false] - prevents selection of WebGL renderer, even if such is present | ||
* @return {PIXI.WebGLRenderer|PIXI.CanvasRenderer} Returns WebGL renderer if available, otherwise CanvasRenderer | ||
*/ | ||
function autoDetectRenderer() { | ||
var width = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 800; | ||
var height = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 600; | ||
var options = arguments[2]; | ||
var noWebGL = arguments[3]; | ||
function autoDetectRenderer(options, arg1, arg2, arg3) { | ||
// Backward-compatible support for noWebGL option | ||
var forceCanvas = options && options.forceCanvas; | ||
if (!noWebGL && utils.isWebGLSupported()) { | ||
return new _WebGLRenderer2.default(width, height, options); | ||
if (arg3 !== undefined) { | ||
forceCanvas = arg3; | ||
} | ||
return new _CanvasRenderer2.default(width, height, options); | ||
if (!forceCanvas && utils.isWebGLSupported()) { | ||
return new _WebGLRenderer2.default(options, arg1, arg2); | ||
} | ||
return new _CanvasRenderer2.default(options, arg1, arg2); | ||
} | ||
//# sourceMappingURL=autoDetectRenderer.js.map |
@@ -13,3 +13,3 @@ 'use strict'; | ||
*/ | ||
var VERSION = exports.VERSION = '4.4.4'; | ||
var VERSION = exports.VERSION = '4.5.0'; | ||
@@ -316,2 +316,26 @@ /** | ||
}; | ||
/** | ||
* Represents the update priorities used by internal PIXI classes when registered with | ||
* the {@link PIXI.ticker.Ticker} object. Higher priority items are updated first and lower | ||
* priority items, such as render, should go later. | ||
* | ||
* @static | ||
* @constant | ||
* @name UPDATE_PRIORITY | ||
* @memberof PIXI | ||
* @type {object} | ||
* @property {number} INTERACTION=50 Highest priority, used for {@link PIXI.interaction.InteractionManager} | ||
* @property {number} HIGH=25 High priority updating, {@link PIXI.VideoBaseTexture} and {@link PIXI.extras.AnimatedSprite} | ||
* @property {number} NORMAL=0 Default priority for ticker events, see {@link PIXI.ticker.Ticker#add}. | ||
* @property {number} LOW=-25 Low priority used for {@link PIXI.Application} rendering. | ||
* @property {number} UTILITY=-50 Lowest priority used for {@link PIXI.prepare.BasePrepare} utility. | ||
*/ | ||
var UPDATE_PRIORITY = exports.UPDATE_PRIORITY = { | ||
INTERACTION: 50, | ||
HIGH: 25, | ||
NORMAL: 0, | ||
LOW: -25, | ||
UTILITY: -50 | ||
}; | ||
//# sourceMappingURL=const.js.map |
@@ -47,3 +47,2 @@ 'use strict'; | ||
* @extends EventEmitter | ||
* @mixes PIXI.interaction.interactiveTarget | ||
* @memberof PIXI | ||
@@ -159,2 +158,16 @@ */ | ||
_this._destroyed = false; | ||
/** | ||
* Fired when this DisplayObject is added to a Container. | ||
* | ||
* @event PIXI.DisplayObject#added | ||
* @param {PIXI.Container} container - The container added to. | ||
*/ | ||
/** | ||
* Fired when this DisplayObject is removed from a Container. | ||
* | ||
* @event PIXI.DisplayObject#removed | ||
* @param {PIXI.Container} container - The container removed from. | ||
*/ | ||
return _this; | ||
@@ -161,0 +174,0 @@ } |
@@ -814,4 +814,4 @@ 'use strict'; | ||
sprite.texture._frame.width = rect.width; | ||
sprite.texture._frame.height = rect.height; | ||
sprite._texture._frame.width = rect.width; | ||
sprite._texture._frame.height = rect.height; | ||
@@ -1070,3 +1070,3 @@ sprite.transform.worldTransform = this.transform.worldTransform; | ||
var texture = _Texture2.default.fromCanvas(canvasBuffer.baseTexture._canvasRenderTarget.canvas, scaleMode); | ||
var texture = _Texture2.default.fromCanvas(canvasBuffer.baseTexture._canvasRenderTarget.canvas, scaleMode, 'graphics'); | ||
@@ -1073,0 +1073,0 @@ texture.baseTexture.resolution = resolution; |
'use strict'; | ||
exports.__esModule = true; | ||
exports.autoDetectRenderer = exports.Application = exports.Filter = exports.SpriteMaskFilter = exports.Quad = exports.RenderTarget = exports.ObjectRenderer = exports.WebGLManager = exports.Shader = exports.CanvasRenderTarget = exports.TextureUvs = exports.VideoBaseTexture = exports.BaseRenderTexture = exports.RenderTexture = exports.BaseTexture = exports.Texture = exports.Spritesheet = exports.CanvasGraphicsRenderer = exports.GraphicsRenderer = exports.GraphicsData = exports.Graphics = exports.TextStyle = exports.Text = exports.SpriteRenderer = exports.CanvasTinter = exports.CanvasSpriteRenderer = exports.Sprite = exports.TransformBase = exports.TransformStatic = exports.Transform = exports.Container = exports.DisplayObject = exports.Bounds = exports.glCore = exports.WebGLRenderer = exports.CanvasRenderer = exports.ticker = exports.utils = exports.settings = undefined; | ||
exports.autoDetectRenderer = exports.Application = exports.Filter = exports.SpriteMaskFilter = exports.Quad = exports.RenderTarget = exports.ObjectRenderer = exports.WebGLManager = exports.Shader = exports.CanvasRenderTarget = exports.TextureUvs = exports.VideoBaseTexture = exports.BaseRenderTexture = exports.RenderTexture = exports.BaseTexture = exports.Texture = exports.Spritesheet = exports.CanvasGraphicsRenderer = exports.GraphicsRenderer = exports.GraphicsData = exports.Graphics = exports.TextMetrics = exports.TextStyle = exports.Text = exports.SpriteRenderer = exports.CanvasTinter = exports.CanvasSpriteRenderer = exports.Sprite = exports.TransformBase = exports.TransformStatic = exports.Transform = exports.Container = exports.DisplayObject = exports.Bounds = exports.glCore = exports.WebGLRenderer = exports.CanvasRenderer = exports.ticker = exports.utils = exports.settings = undefined; | ||
@@ -147,2 +147,11 @@ var _const = require('./const'); | ||
var _TextMetrics = require('./text/TextMetrics'); | ||
Object.defineProperty(exports, 'TextMetrics', { | ||
enumerable: true, | ||
get: function get() { | ||
return _interopRequireDefault(_TextMetrics).default; | ||
} | ||
}); | ||
var _Graphics = require('./graphics/Graphics'); | ||
@@ -149,0 +158,0 @@ |
@@ -49,6 +49,7 @@ 'use strict'; | ||
// eslint-disable-next-line valid-jsdoc | ||
/** | ||
* @param {number} [screenWidth=800] - the width of the screen | ||
* @param {number} [screenHeight=600] - the height of the screen | ||
* @param {object} [options] - The optional renderer parameters | ||
* @param {number} [options.width=800] - the width of the screen | ||
* @param {number} [options.height=600] - the height of the screen | ||
* @param {HTMLCanvasElement} [options.view] - the canvas to use as a view, optional | ||
@@ -67,8 +68,6 @@ * @param {boolean} [options.transparent=false] - If the render view is transparent, default false | ||
*/ | ||
function CanvasRenderer(screenWidth, screenHeight) { | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
function CanvasRenderer(options, arg2, arg3) { | ||
_classCallCheck(this, CanvasRenderer); | ||
var _this = _possibleConstructorReturn(this, _SystemRenderer.call(this, 'Canvas', screenWidth, screenHeight, options)); | ||
var _this = _possibleConstructorReturn(this, _SystemRenderer.call(this, 'Canvas', options, arg2, arg3)); | ||
@@ -125,3 +124,15 @@ _this.type = _const.RENDERER_TYPE.CANVAS; | ||
_this.resize(screenWidth, screenHeight); | ||
_this.resize(_this.options.width, _this.options.height); | ||
/** | ||
* Fired after rendering finishes. | ||
* | ||
* @event PIXI.CanvasRenderer#postrender | ||
*/ | ||
/** | ||
* Fired before rendering starts. | ||
* | ||
* @event PIXI.CanvasRenderer#prerender | ||
*/ | ||
return _this; | ||
@@ -312,6 +323,25 @@ } | ||
exports.default = CanvasRenderer; | ||
/** | ||
* Collection of installed plugins. These are included by default in PIXI, but can be excluded | ||
* by creating a custom build. Consult the README for more information about creating custom | ||
* builds and excluding plugins. | ||
* @name PIXI.CanvasRenderer#plugins | ||
* @type {object} | ||
* @readonly | ||
* @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. | ||
* @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. | ||
* @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. | ||
* @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. | ||
*/ | ||
/** | ||
* Adds a plugin to the renderer. | ||
* | ||
* @method PIXI.CanvasRenderer#registerPlugin | ||
* @param {string} pluginName - The name of the plugin. | ||
* @param {Function} ctor - The constructor function or class for the plugin. | ||
*/ | ||
exports.default = CanvasRenderer; | ||
_utils.pluginTarget.mixin(CanvasRenderer); | ||
//# sourceMappingURL=CanvasRenderer.js.map |
@@ -52,7 +52,8 @@ 'use strict'; | ||
// eslint-disable-next-line valid-jsdoc | ||
/** | ||
* @param {string} system - The name of the system this renderer is for. | ||
* @param {number} [screenWidth=800] - the width of the screen | ||
* @param {number} [screenHeight=600] - the height of the screen | ||
* @param {object} [options] - The optional renderer parameters | ||
* @param {number} [options.width=800] - the width of the screen | ||
* @param {number} [options.height=600] - the height of the screen | ||
* @param {HTMLCanvasElement} [options.view] - the canvas to use as a view, optional | ||
@@ -71,3 +72,3 @@ * @param {boolean} [options.transparent=false] - If the render view is transparent, default false | ||
*/ | ||
function SystemRenderer(system, screenWidth, screenHeight, options) { | ||
function SystemRenderer(system, options, arg2, arg3) { | ||
_classCallCheck(this, SystemRenderer); | ||
@@ -79,14 +80,22 @@ | ||
// prepare options | ||
if (options) { | ||
for (var i in _settings2.default.RENDER_OPTIONS) { | ||
if (typeof options[i] === 'undefined') { | ||
options[i] = _settings2.default.RENDER_OPTIONS[i]; | ||
} | ||
} | ||
} else { | ||
options = _settings2.default.RENDER_OPTIONS; | ||
// Support for constructor(system, screenWidth, screenHeight, options) | ||
if (typeof options === 'number') { | ||
options = Object.assign({ | ||
width: options, | ||
height: arg2 || _settings2.default.RENDER_OPTIONS.height | ||
}, arg3); | ||
} | ||
// Add the default render options | ||
options = Object.assign({}, _settings2.default.RENDER_OPTIONS, options); | ||
/** | ||
* The supplied constructor options. | ||
* | ||
* @member {Object} | ||
* @readOnly | ||
*/ | ||
_this.options = options; | ||
/** | ||
* The type of the renderer. | ||
@@ -107,3 +116,3 @@ * | ||
*/ | ||
_this.screen = new _math.Rectangle(0, 0, screenWidth || 800, screenHeight || 600); | ||
_this.screen = new _math.Rectangle(0, 0, options.width, options.height); | ||
@@ -297,2 +306,4 @@ /** | ||
this.options = null; | ||
this.preserveDrawingBuffer = false; | ||
@@ -299,0 +310,0 @@ this.clearBeforeRender = false; |
@@ -10,3 +10,3 @@ 'use strict'; | ||
/* | ||
/** | ||
* Calculates the mapped matrix | ||
@@ -13,0 +13,0 @@ * @param filterArea {Rectangle} The filter area |
@@ -31,3 +31,3 @@ 'use strict'; | ||
/* | ||
/** | ||
* the current WebGL drawing context | ||
@@ -62,19 +62,27 @@ * | ||
/* | ||
* @member {Uint16Array} An array containing the indices of the vertices | ||
/** | ||
* An array containing the indices of the vertices | ||
* | ||
* @member {Uint16Array} | ||
*/ | ||
this.indices = (0, _createIndicesForQuads2.default)(1); | ||
/* | ||
* @member {glCore.GLBuffer} The vertex buffer | ||
/** | ||
* The vertex buffer | ||
* | ||
* @member {glCore.GLBuffer} | ||
*/ | ||
this.vertexBuffer = _pixiGlCore2.default.GLBuffer.createVertexBuffer(gl, this.interleaved, gl.STATIC_DRAW); | ||
/* | ||
* @member {glCore.GLBuffer} The index buffer | ||
/** | ||
* The index buffer | ||
* | ||
* @member {glCore.GLBuffer} | ||
*/ | ||
this.indexBuffer = _pixiGlCore2.default.GLBuffer.createIndexBuffer(gl, this.indices, gl.STATIC_DRAW); | ||
/* | ||
* @member {glCore.VertexArrayObject} The index buffer | ||
/** | ||
* The vertex array object | ||
* | ||
* @member {glCore.VertexArrayObject} | ||
*/ | ||
@@ -81,0 +89,0 @@ this.vao = new _pixiGlCore2.default.VertexArrayObject(gl, state); |
@@ -85,7 +85,8 @@ 'use strict'; | ||
// eslint-disable-next-line valid-jsdoc | ||
/** | ||
* | ||
* @param {number} [screenWidth=800] - the width of the screen | ||
* @param {number} [screenHeight=600] - the height of the screen | ||
* @param {object} [options] - The optional renderer parameters | ||
* @param {number} [options.width=800] - the width of the screen | ||
* @param {number} [options.height=600] - the height of the screen | ||
* @param {HTMLCanvasElement} [options.view] - the canvas to use as a view, optional | ||
@@ -110,10 +111,8 @@ * @param {boolean} [options.transparent=false] - If the render view is transparent, default false | ||
*/ | ||
function WebGLRenderer(screenWidth, screenHeight) { | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
function WebGLRenderer(options, arg2, arg3) { | ||
_classCallCheck(this, WebGLRenderer); | ||
var _this = _possibleConstructorReturn(this, _SystemRenderer.call(this, 'WebGL', screenWidth, screenHeight, options)); | ||
var _this = _possibleConstructorReturn(this, _SystemRenderer.call(this, 'WebGL', options, arg2, arg3)); | ||
_this.legacy = !!options.legacy; | ||
_this.legacy = _this.options.legacy; | ||
@@ -146,6 +145,6 @@ if (_this.legacy) { | ||
alpha: _this.transparent, | ||
antialias: options.antialias, | ||
antialias: _this.options.antialias, | ||
premultipliedAlpha: _this.transparent && _this.transparent !== 'notMultiplied', | ||
stencil: true, | ||
preserveDrawingBuffer: options.preserveDrawingBuffer | ||
preserveDrawingBuffer: _this.options.preserveDrawingBuffer | ||
}; | ||
@@ -191,8 +190,8 @@ | ||
// initialize the context so it is ready for the managers. | ||
if (options.context) { | ||
if (_this.options.context) { | ||
// checks to see if a context is valid.. | ||
(0, _validateContext2.default)(options.context); | ||
(0, _validateContext2.default)(_this.options.context); | ||
} | ||
_this.gl = options.context || _pixiGlCore2.default.createContext(_this.view, _this._contextOptions); | ||
_this.gl = _this.options.context || _pixiGlCore2.default.createContext(_this.view, _this._contextOptions); | ||
@@ -246,2 +245,21 @@ _this.CONTEXT_UID = CONTEXT_UID++; | ||
_this.setBlendMode(0); | ||
/** | ||
* Fired after rendering finishes. | ||
* | ||
* @event PIXI.WebGLRenderer#postrender | ||
*/ | ||
/** | ||
* Fired before rendering starts. | ||
* | ||
* @event PIXI.WebGLRenderer#prerender | ||
*/ | ||
/** | ||
* Fired when the WebGL context is set. | ||
* | ||
* @event PIXI.WebGLRenderer#context | ||
* @param {WebGLRenderingContext} gl - WebGL context. | ||
*/ | ||
return _this; | ||
@@ -758,6 +776,25 @@ } | ||
exports.default = WebGLRenderer; | ||
/** | ||
* Collection of installed plugins. These are included by default in PIXI, but can be excluded | ||
* by creating a custom build. Consult the README for more information about creating custom | ||
* builds and excluding plugins. | ||
* @name PIXI.WebGLRenderer#plugins | ||
* @type {object} | ||
* @readonly | ||
* @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. | ||
* @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. | ||
* @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. | ||
* @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. | ||
*/ | ||
/** | ||
* Adds a plugin to the renderer. | ||
* | ||
* @method PIXI.WebGLRenderer#registerPlugin | ||
* @param {string} pluginName - The name of the plugin. | ||
* @param {Function} ctor - The constructor function or class for the plugin. | ||
*/ | ||
exports.default = WebGLRenderer; | ||
_utils.pluginTarget.mixin(WebGLRenderer); | ||
//# sourceMappingURL=WebGLRenderer.js.map |
@@ -16,2 +16,11 @@ 'use strict'; | ||
/** | ||
* User's customizable globals for overriding the default PIXI settings, such | ||
* as a renderer's default resolution, framerate, float percision, etc. | ||
* @example | ||
* // Use the native window resolution as the default resolution | ||
* // will support high-density displays when rendering | ||
* PIXI.settings.RESOLUTION = window.devicePixelRatio. | ||
* | ||
* // Disable interpolation when scaling, will make texture be pixelated | ||
* PIXI.settings.SCALE_MODE = PIXI.SCALE_MODES.NEAREST; | ||
* @namespace PIXI.settings | ||
@@ -116,2 +125,5 @@ */ | ||
* @property {boolean} roundPixels=false | ||
* @property {number} width=800 | ||
* @property {number} height=600 | ||
* @property {boolean} legacy=false | ||
*/ | ||
@@ -127,3 +139,6 @@ RENDER_OPTIONS: { | ||
preserveDrawingBuffer: false, | ||
roundPixels: false | ||
roundPixels: false, | ||
width: 800, | ||
height: 600, | ||
legacy: false | ||
}, | ||
@@ -130,0 +145,0 @@ |
@@ -29,3 +29,3 @@ 'use strict'; | ||
getTintedTexture: function getTintedTexture(sprite, color) { | ||
var texture = sprite.texture; | ||
var texture = sprite._texture; | ||
@@ -32,0 +32,0 @@ color = CanvasTinter.roundColor(color); |
@@ -176,7 +176,7 @@ 'use strict'; | ||
if (this._width) { | ||
this.scale.x = (0, _utils.sign)(this.scale.x) * this._width / this.texture.orig.width; | ||
this.scale.x = (0, _utils.sign)(this.scale.x) * this._width / this._texture.orig.width; | ||
} | ||
if (this._height) { | ||
this.scale.y = (0, _utils.sign)(this.scale.y) * this._height / this.texture.orig.height; | ||
this.scale.y = (0, _utils.sign)(this.scale.y) * this._height / this._texture.orig.height; | ||
} | ||
@@ -183,0 +183,0 @@ }; |
@@ -156,3 +156,3 @@ 'use strict'; | ||
var shader = this.shader = (0, _generateMultiTextureShader2.default)(gl, this.MAX_TEXTURES); | ||
this.shader = (0, _generateMultiTextureShader2.default)(gl, this.MAX_TEXTURES); | ||
@@ -167,15 +167,17 @@ // create a couple of buffers | ||
var attrs = this.shader.attributes; | ||
for (var i = 0; i < this.vaoMax; i++) { | ||
this.vertexBuffers[i] = _pixiGlCore2.default.GLBuffer.createVertexBuffer(gl, null, gl.STREAM_DRAW); | ||
/* eslint-disable max-len */ | ||
var vertexBuffer = this.vertexBuffers[i] = _pixiGlCore2.default.GLBuffer.createVertexBuffer(gl, null, gl.STREAM_DRAW); | ||
/* eslint-enable max-len */ | ||
// build the vao object that will render.. | ||
this.vaos[i] = this.renderer.createVao().addIndex(this.indexBuffer).addAttribute(this.vertexBuffers[i], shader.attributes.aVertexPosition, gl.FLOAT, false, this.vertByteSize, 0).addAttribute(this.vertexBuffers[i], shader.attributes.aTextureCoord, gl.UNSIGNED_SHORT, true, this.vertByteSize, 2 * 4).addAttribute(this.vertexBuffers[i], shader.attributes.aColor, gl.UNSIGNED_BYTE, true, this.vertByteSize, 3 * 4); | ||
var vao = this.renderer.createVao().addIndex(this.indexBuffer).addAttribute(vertexBuffer, attrs.aVertexPosition, gl.FLOAT, false, this.vertByteSize, 0).addAttribute(vertexBuffer, attrs.aTextureCoord, gl.UNSIGNED_SHORT, true, this.vertByteSize, 2 * 4).addAttribute(vertexBuffer, attrs.aColor, gl.UNSIGNED_BYTE, true, this.vertByteSize, 3 * 4); | ||
if (shader.attributes.aTextureId) { | ||
this.vaos[i].addAttribute(this.vertexBuffers[i], shader.attributes.aTextureId, gl.FLOAT, false, this.vertByteSize, 4 * 4); | ||
if (attrs.aTextureId) { | ||
vao.addAttribute(vertexBuffer, attrs.aTextureId, gl.FLOAT, false, this.vertByteSize, 4 * 4); | ||
} | ||
/* eslint-enable max-len */ | ||
this.vaos[i] = vao; | ||
} | ||
@@ -402,14 +404,17 @@ | ||
this.vaoMax++; | ||
this.vertexBuffers[this.vertexCount] = _pixiGlCore2.default.GLBuffer.createVertexBuffer(gl, null, gl.STREAM_DRAW); | ||
var attrs = this.shader.attributes; | ||
/* eslint-disable max-len */ | ||
var vertexBuffer = this.vertexBuffers[this.vertexCount] = _pixiGlCore2.default.GLBuffer.createVertexBuffer(gl, null, gl.STREAM_DRAW); | ||
/* eslint-enable max-len */ | ||
// build the vao object that will render.. | ||
this.vaos[this.vertexCount] = this.renderer.createVao().addIndex(this.indexBuffer).addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aVertexPosition, gl.FLOAT, false, this.vertByteSize, 0).addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aTextureCoord, gl.UNSIGNED_SHORT, true, this.vertByteSize, 2 * 4).addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aColor, gl.UNSIGNED_BYTE, true, this.vertByteSize, 3 * 4); | ||
var vao = this.renderer.createVao().addIndex(this.indexBuffer).addAttribute(vertexBuffer, attrs.aVertexPosition, gl.FLOAT, false, this.vertByteSize, 0).addAttribute(vertexBuffer, attrs.aTextureCoord, gl.UNSIGNED_SHORT, true, this.vertByteSize, 2 * 4).addAttribute(vertexBuffer, attrs.aColor, gl.UNSIGNED_BYTE, true, this.vertByteSize, 3 * 4); | ||
if (this.shader.attributes.aTextureId) { | ||
this.vaos[this.vertexCount].addAttribute(this.vertexBuffers[this.vertexCount], this.shader.attributes.aTextureId, gl.FLOAT, false, this.vertByteSize, 4 * 4); | ||
if (attrs.aTextureId) { | ||
vao.addAttribute(vertexBuffer, attrs.aTextureId, gl.FLOAT, false, this.vertByteSize, 4 * 4); | ||
} | ||
/* eslint-enable max-len */ | ||
this.vaos[this.vertexCount] = vao; | ||
} | ||
@@ -416,0 +421,0 @@ |
@@ -29,2 +29,6 @@ 'use strict'; | ||
var _TextMetrics = require('./TextMetrics'); | ||
var _TextMetrics2 = _interopRequireDefault(_TextMetrics); | ||
var _trimCanvas = require('../utils/trimCanvas'); | ||
@@ -80,3 +84,3 @@ | ||
var texture = _Texture2.default.fromCanvas(canvas); | ||
var texture = _Texture2.default.fromCanvas(canvas, _settings2.default.SCALE_MODE, 'text'); | ||
@@ -86,2 +90,7 @@ texture.orig = new _math.Rectangle(); | ||
// base texture is already automatically added to the cache, now adding the actual texture | ||
var _this = _possibleConstructorReturn(this, _Sprite.call(this, texture)); | ||
_Texture2.default.addToCache(_this._texture, _this._texture.baseTexture.textureCacheIds[0]); | ||
/** | ||
@@ -92,4 +101,2 @@ * The canvas element that everything is drawn to | ||
*/ | ||
var _this = _possibleConstructorReturn(this, _Sprite.call(this, texture)); | ||
_this.canvas = canvas; | ||
@@ -169,42 +176,14 @@ | ||
this._font = Text.getFontStyle(style); | ||
this._font = this._style.toFontString(); | ||
this.context.font = this._font; | ||
var measured = _TextMetrics2.default.measureText(this._text, this._style, this._style.wordWrap, this.canvas); | ||
var width = measured.width; | ||
var height = measured.height; | ||
var lines = measured.lines; | ||
var lineHeight = measured.lineHeight; | ||
var lineWidths = measured.lineWidths; | ||
var maxLineWidth = measured.maxLineWidth; | ||
var fontProperties = measured.fontProperties; | ||
// word wrap | ||
// preserve original text | ||
var outputText = style.wordWrap ? this.wordWrap(this._text) : this._text; | ||
// split text into lines | ||
var lines = outputText.split(/(?:\r\n|\r|\n)/); | ||
// calculate text width | ||
var lineWidths = new Array(lines.length); | ||
var maxLineWidth = 0; | ||
var fontProperties = Text.calculateFontProperties(this._font); | ||
for (var i = 0; i < lines.length; i++) { | ||
var lineWidth = this.context.measureText(lines[i]).width + (lines[i].length - 1) * style.letterSpacing; | ||
lineWidths[i] = lineWidth; | ||
maxLineWidth = Math.max(maxLineWidth, lineWidth); | ||
} | ||
var width = maxLineWidth + style.strokeThickness; | ||
if (style.dropShadow) { | ||
width += style.dropShadowDistance; | ||
} | ||
this.canvas.width = Math.ceil((width + style.padding * 2) * this.resolution); | ||
// calculate text height | ||
var lineHeight = style.lineHeight || fontProperties.fontSize + style.strokeThickness; | ||
var height = Math.max(lineHeight, fontProperties.fontSize + style.strokeThickness) + (lines.length - 1) * lineHeight; | ||
if (style.dropShadow) { | ||
height += style.dropShadowDistance; | ||
} | ||
this.canvas.height = Math.ceil((height + style.padding * 2) * this.resolution); | ||
@@ -239,18 +218,18 @@ | ||
for (var _i = 0; _i < lines.length; _i++) { | ||
for (var i = 0; i < lines.length; i++) { | ||
linePositionX = style.strokeThickness / 2; | ||
linePositionY = style.strokeThickness / 2 + _i * lineHeight + fontProperties.ascent; | ||
linePositionY = style.strokeThickness / 2 + i * lineHeight + fontProperties.ascent; | ||
if (style.align === 'right') { | ||
linePositionX += maxLineWidth - lineWidths[_i]; | ||
linePositionX += maxLineWidth - lineWidths[i]; | ||
} else if (style.align === 'center') { | ||
linePositionX += (maxLineWidth - lineWidths[_i]) / 2; | ||
linePositionX += (maxLineWidth - lineWidths[i]) / 2; | ||
} | ||
if (style.fill) { | ||
this.drawLetterSpacing(lines[_i], linePositionX + xShadowOffset + style.padding, linePositionY + yShadowOffset + style.padding); | ||
this.drawLetterSpacing(lines[i], linePositionX + xShadowOffset + style.padding, linePositionY + yShadowOffset + style.padding); | ||
if (style.stroke && style.strokeThickness) { | ||
this.context.strokeStyle = style.dropShadowColor; | ||
this.drawLetterSpacing(lines[_i], linePositionX + xShadowOffset + style.padding, linePositionY + yShadowOffset + style.padding, true); | ||
this.drawLetterSpacing(lines[i], linePositionX + xShadowOffset + style.padding, linePositionY + yShadowOffset + style.padding, true); | ||
this.context.strokeStyle = style.stroke; | ||
@@ -270,18 +249,18 @@ } | ||
// draw lines line by line | ||
for (var _i2 = 0; _i2 < lines.length; _i2++) { | ||
for (var _i = 0; _i < lines.length; _i++) { | ||
linePositionX = style.strokeThickness / 2; | ||
linePositionY = style.strokeThickness / 2 + _i2 * lineHeight + fontProperties.ascent; | ||
linePositionY = style.strokeThickness / 2 + _i * lineHeight + fontProperties.ascent; | ||
if (style.align === 'right') { | ||
linePositionX += maxLineWidth - lineWidths[_i2]; | ||
linePositionX += maxLineWidth - lineWidths[_i]; | ||
} else if (style.align === 'center') { | ||
linePositionX += (maxLineWidth - lineWidths[_i2]) / 2; | ||
linePositionX += (maxLineWidth - lineWidths[_i]) / 2; | ||
} | ||
if (style.stroke && style.strokeThickness) { | ||
this.drawLetterSpacing(lines[_i2], linePositionX + style.padding, linePositionY + style.padding, true); | ||
this.drawLetterSpacing(lines[_i], linePositionX + style.padding, linePositionY + style.padding, true); | ||
} | ||
if (style.fill) { | ||
this.drawLetterSpacing(lines[_i2], linePositionX + style.padding, linePositionY + style.padding); | ||
this.drawLetterSpacing(lines[_i], linePositionX + style.padding, linePositionY + style.padding); | ||
} | ||
@@ -356,2 +335,3 @@ } | ||
var style = this._style; | ||
var padding = style.trim ? 0 : style.padding; | ||
@@ -368,7 +348,7 @@ texture.baseTexture.hasLoaded = true; | ||
texture.trim.x = -style.padding; | ||
texture.trim.y = -style.padding; | ||
texture.trim.x = -padding; | ||
texture.trim.y = -padding; | ||
texture.orig.width = texture._frame.width - style.padding * 2; | ||
texture.orig.height = texture._frame.height - style.padding * 2; | ||
texture.orig.width = texture._frame.width - padding * 2; | ||
texture.orig.height = texture._frame.height - padding * 2; | ||
@@ -421,72 +401,2 @@ // call sprite onTextureUpdate to update scale if _width or _height were set | ||
/** | ||
* Applies newlines to a string to have it optimally fit into the horizontal | ||
* bounds set by the Text object's wordWrapWidth property. | ||
* | ||
* @private | ||
* @param {string} text - String to apply word wrapping to | ||
* @return {string} New string with new lines applied where required | ||
*/ | ||
Text.prototype.wordWrap = function wordWrap(text) { | ||
// Greedy wrapping algorithm that will wrap words as the line grows longer | ||
// than its horizontal bounds. | ||
var result = ''; | ||
var style = this._style; | ||
var lines = text.split('\n'); | ||
var wordWrapWidth = style.wordWrapWidth; | ||
for (var i = 0; i < lines.length; i++) { | ||
var spaceLeft = wordWrapWidth; | ||
var words = lines[i].split(' '); | ||
for (var j = 0; j < words.length; j++) { | ||
var wordWidth = this.context.measureText(words[j]).width; | ||
if (style.breakWords && wordWidth > wordWrapWidth) { | ||
// Word should be split in the middle | ||
var characters = words[j].split(''); | ||
for (var c = 0; c < characters.length; c++) { | ||
var characterWidth = this.context.measureText(characters[c]).width; | ||
if (characterWidth > spaceLeft) { | ||
result += '\n' + characters[c]; | ||
spaceLeft = wordWrapWidth - characterWidth; | ||
} else { | ||
if (c === 0) { | ||
result += ' '; | ||
} | ||
result += characters[c]; | ||
spaceLeft -= characterWidth; | ||
} | ||
} | ||
} else { | ||
var wordWidthWithSpace = wordWidth + this.context.measureText(' ').width; | ||
if (j === 0 || wordWidthWithSpace > spaceLeft) { | ||
// Skip printing the newline if it's the first word of the line that is | ||
// greater than the word wrap width. | ||
if (j > 0) { | ||
result += '\n'; | ||
} | ||
result += words[j]; | ||
spaceLeft = wordWrapWidth - wordWidth; | ||
} else { | ||
spaceLeft -= wordWidthWithSpace; | ||
result += ' ' + words[j]; | ||
} | ||
} | ||
} | ||
if (i < lines.length - 1) { | ||
result += '\n'; | ||
} | ||
} | ||
return result; | ||
}; | ||
/** | ||
* Gets the local bounds of the text object. | ||
@@ -586,7 +496,7 @@ * | ||
currentIteration = 0; | ||
for (var _i3 = 0; _i3 < lines.length; _i3++) { | ||
for (var _i2 = 0; _i2 < lines.length; _i2++) { | ||
currentIteration += 1; | ||
for (var j = 0; j < fill.length; j++) { | ||
if (fillGradientStops[j]) { | ||
stop = fillGradientStops[j] / lines.length + _i3 / lines.length; | ||
stop = fillGradientStops[j] / lines.length + _i2 / lines.length; | ||
} else { | ||
@@ -608,9 +518,9 @@ stop = currentIteration / totalIterations; | ||
for (var _i4 = 0; _i4 < fill.length; _i4++) { | ||
if (fillGradientStops[_i4]) { | ||
stop = fillGradientStops[_i4]; | ||
for (var _i3 = 0; _i3 < fill.length; _i3++) { | ||
if (fillGradientStops[_i3]) { | ||
stop = fillGradientStops[_i3]; | ||
} else { | ||
stop = currentIteration / totalIterations; | ||
} | ||
gradient.addColorStop(stop, fill[_i4]); | ||
gradient.addColorStop(stop, fill[_i3]); | ||
currentIteration++; | ||
@@ -660,134 +570,2 @@ } | ||
/** | ||
* Generates a font style string to use for Text.calculateFontProperties(). Takes the same parameter | ||
* as Text.style. | ||
* | ||
* @static | ||
* @param {object|TextStyle} style - String representing the style of the font | ||
* @return {string} Font style string, for passing to Text.calculateFontProperties() | ||
*/ | ||
Text.getFontStyle = function getFontStyle(style) { | ||
style = style || {}; | ||
if (!(style instanceof _TextStyle2.default)) { | ||
style = new _TextStyle2.default(style); | ||
} | ||
// build canvas api font setting from individual components. Convert a numeric style.fontSize to px | ||
var fontSizeString = typeof style.fontSize === 'number' ? style.fontSize + 'px' : style.fontSize; | ||
// Clean-up fontFamily property by quoting each font name | ||
// this will support font names with spaces | ||
var fontFamilies = style.fontFamily; | ||
if (!Array.isArray(style.fontFamily)) { | ||
fontFamilies = style.fontFamily.split(','); | ||
} | ||
for (var i = fontFamilies.length - 1; i >= 0; i--) { | ||
// Trim any extra white-space | ||
var fontFamily = fontFamilies[i].trim(); | ||
// Check if font already contains strings | ||
if (!/([\"\'])[^\'\"]+\1/.test(fontFamily)) { | ||
fontFamily = '"' + fontFamily + '"'; | ||
} | ||
fontFamilies[i] = fontFamily; | ||
} | ||
return style.fontStyle + ' ' + style.fontVariant + ' ' + style.fontWeight + ' ' + fontSizeString + ' ' + fontFamilies.join(','); | ||
}; | ||
/** | ||
* Calculates the ascent, descent and fontSize of a given fontStyle | ||
* | ||
* @static | ||
* @param {string} fontStyle - String representing the style of the font | ||
* @return {Object} Font properties object | ||
*/ | ||
Text.calculateFontProperties = function calculateFontProperties(fontStyle) { | ||
// as this method is used for preparing assets, don't recalculate things if we don't need to | ||
if (Text.fontPropertiesCache[fontStyle]) { | ||
return Text.fontPropertiesCache[fontStyle]; | ||
} | ||
var properties = {}; | ||
var canvas = Text.fontPropertiesCanvas; | ||
var context = Text.fontPropertiesContext; | ||
context.font = fontStyle; | ||
var width = Math.ceil(context.measureText('|MÉq').width); | ||
var baseline = Math.ceil(context.measureText('M').width); | ||
var height = 2 * baseline; | ||
baseline = baseline * 1.4 | 0; | ||
canvas.width = width; | ||
canvas.height = height; | ||
context.fillStyle = '#f00'; | ||
context.fillRect(0, 0, width, height); | ||
context.font = fontStyle; | ||
context.textBaseline = 'alphabetic'; | ||
context.fillStyle = '#000'; | ||
context.fillText('|MÉq', 0, baseline); | ||
var imagedata = context.getImageData(0, 0, width, height).data; | ||
var pixels = imagedata.length; | ||
var line = width * 4; | ||
var i = 0; | ||
var idx = 0; | ||
var stop = false; | ||
// ascent. scan from top to bottom until we find a non red pixel | ||
for (i = 0; i < baseline; ++i) { | ||
for (var j = 0; j < line; j += 4) { | ||
if (imagedata[idx + j] !== 255) { | ||
stop = true; | ||
break; | ||
} | ||
} | ||
if (!stop) { | ||
idx += line; | ||
} else { | ||
break; | ||
} | ||
} | ||
properties.ascent = baseline - i; | ||
idx = pixels - line; | ||
stop = false; | ||
// descent. scan from bottom to top until we find a non red pixel | ||
for (i = height; i > baseline; --i) { | ||
for (var _j = 0; _j < line; _j += 4) { | ||
if (imagedata[idx + _j] !== 255) { | ||
stop = true; | ||
break; | ||
} | ||
} | ||
if (!stop) { | ||
idx -= line; | ||
} else { | ||
break; | ||
} | ||
} | ||
properties.descent = i - baseline; | ||
properties.fontSize = properties.ascent + properties.descent; | ||
Text.fontPropertiesCache[fontStyle] = properties; | ||
return properties; | ||
}; | ||
_createClass(Text, [{ | ||
@@ -886,7 +664,2 @@ key: 'width', | ||
exports.default = Text; | ||
Text.fontPropertiesCache = {}; | ||
Text.fontPropertiesCanvas = document.createElement('canvas'); | ||
Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); | ||
//# sourceMappingURL=Text.js.map |
@@ -132,2 +132,33 @@ 'use strict'; | ||
/** | ||
* Generates a font style string to use for `TextMetrics.measureFont()`. | ||
* | ||
* @return {string} Font style string, for passing to `TextMetrics.measureFont()` | ||
*/ | ||
TextStyle.prototype.toFontString = function toFontString() { | ||
// build canvas api font setting from individual components. Convert a numeric this.fontSize to px | ||
var fontSizeString = typeof this.fontSize === 'number' ? this.fontSize + 'px' : this.fontSize; | ||
// Clean-up fontFamily property by quoting each font name | ||
// this will support font names with spaces | ||
var fontFamilies = this.fontFamily; | ||
if (!Array.isArray(this.fontFamily)) { | ||
fontFamilies = this.fontFamily.split(','); | ||
} | ||
for (var i = fontFamilies.length - 1; i >= 0; i--) { | ||
// Trim any extra white-space | ||
var fontFamily = fontFamilies[i].trim(); | ||
// Check if font already contains strings | ||
if (!/([\"\'])[^\'\"]+\1/.test(fontFamily)) { | ||
fontFamily = '"' + fontFamily + '"'; | ||
} | ||
fontFamilies[i] = fontFamily; | ||
} | ||
return this.fontStyle + ' ' + this.fontVariant + ' ' + this.fontWeight + ' ' + fontSizeString + ' ' + fontFamilies.join(','); | ||
}; | ||
_createClass(TextStyle, [{ | ||
@@ -134,0 +165,0 @@ key: 'align', |
@@ -222,7 +222,2 @@ 'use strict'; | ||
// if no source passed don't try to load | ||
if (source) { | ||
_this.loadSource(source); | ||
} | ||
/** | ||
@@ -238,7 +233,21 @@ * If the object has been destroyed via destroy(). If true, it should not be used. | ||
/** | ||
* The ids under which this BaseTexture has been added to the base texture cache. This is | ||
* automatically set as long as BaseTexture.addToCache is used, but may not be set if a | ||
* BaseTexture is added directly to the BaseTextureCache array. | ||
* | ||
* @member {string[]} | ||
*/ | ||
_this.textureCacheIds = []; | ||
// if no source passed don't try to load | ||
if (source) { | ||
_this.loadSource(source); | ||
} | ||
/** | ||
* Fired when a not-immediately-available source finishes loading. | ||
* | ||
* @protected | ||
* @event loaded | ||
* @memberof PIXI.BaseTexture# | ||
* @event PIXI.BaseTexture#loaded | ||
* @param {PIXI.BaseTexture} baseTexture - Resource loaded. | ||
*/ | ||
@@ -250,5 +259,21 @@ | ||
* @protected | ||
* @event error | ||
* @memberof PIXI.BaseTexture# | ||
* @event PIXI.BaseTexture#error | ||
* @param {PIXI.BaseTexture} baseTexture - Resource errored. | ||
*/ | ||
/** | ||
* Fired when BaseTexture is updated. | ||
* | ||
* @protected | ||
* @event PIXI.BaseTexture#update | ||
* @param {PIXI.BaseTexture} baseTexture - Instance of texture being updated. | ||
*/ | ||
/** | ||
* Fired when BaseTexture is destroyed. | ||
* | ||
* @protected | ||
* @event PIXI.BaseTexture#dispose | ||
* @param {PIXI.BaseTexture} baseTexture - Instance of texture being destroyed. | ||
*/ | ||
return _this; | ||
@@ -260,3 +285,3 @@ } | ||
* | ||
* @fires update | ||
* @fires PIXI.BaseTexture#update | ||
*/ | ||
@@ -530,3 +555,3 @@ | ||
* | ||
* @fires loaded | ||
* @fires PIXI.BaseTexture#loaded | ||
*/ | ||
@@ -566,3 +591,3 @@ | ||
// Add also the canvas in cache (destroy clears by `imageUrl` and `source._pixiId`) | ||
_utils.BaseTextureCache[canvas._pixiId] = this; | ||
BaseTexture.addToCache(this, canvas._pixiId); | ||
@@ -595,3 +620,2 @@ this.isLoading = false; | ||
if (this.imageUrl) { | ||
delete _utils.BaseTextureCache[this.imageUrl]; | ||
delete _utils.TextureCache[this.imageUrl]; | ||
@@ -605,6 +629,2 @@ | ||
} | ||
// An svg source has both `imageUrl` and `__pixiId`, so no `else if` here | ||
if (this.source && this.source._pixiId) { | ||
delete _utils.BaseTextureCache[this.source._pixiId]; | ||
} | ||
@@ -615,2 +635,5 @@ this.source = null; | ||
BaseTexture.removeFromCache(this); | ||
this.textureCacheIds = null; | ||
this._destroyed = true; | ||
@@ -624,2 +647,3 @@ }; | ||
* | ||
* @fires PIXI.BaseTexture#dispose | ||
*/ | ||
@@ -683,3 +707,3 @@ | ||
_utils.BaseTextureCache[imageUrl] = baseTexture; | ||
BaseTexture.addToCache(baseTexture, imageUrl); | ||
} | ||
@@ -696,2 +720,3 @@ | ||
* @param {number} scaleMode - See {@link PIXI.SCALE_MODES} for possible values | ||
* @param {string} [origin='canvas'] - A string origin of who created the base texture | ||
* @return {PIXI.BaseTexture} The new base texture. | ||
@@ -702,4 +727,6 @@ */ | ||
BaseTexture.fromCanvas = function fromCanvas(canvas, scaleMode) { | ||
var origin = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'canvas'; | ||
if (!canvas._pixiId) { | ||
canvas._pixiId = 'canvas_' + (0, _utils.uid)(); | ||
canvas._pixiId = origin + '_' + (0, _utils.uid)(); | ||
} | ||
@@ -711,3 +738,3 @@ | ||
baseTexture = new BaseTexture(canvas, scaleMode); | ||
_utils.BaseTextureCache[canvas._pixiId] = baseTexture; | ||
BaseTexture.addToCache(baseTexture, canvas._pixiId); | ||
} | ||
@@ -748,3 +775,3 @@ | ||
_utils.BaseTextureCache[imageUrl] = baseTexture; | ||
BaseTexture.addToCache(baseTexture, imageUrl); | ||
} | ||
@@ -761,2 +788,66 @@ | ||
/** | ||
* Adds a BaseTexture to the global BaseTextureCache. This cache is shared across the whole PIXI object. | ||
* | ||
* @static | ||
* @param {PIXI.BaseTexture} baseTexture - The BaseTexture to add to the cache. | ||
* @param {string} id - The id that the BaseTexture will be stored against. | ||
*/ | ||
BaseTexture.addToCache = function addToCache(baseTexture, id) { | ||
if (id) { | ||
if (baseTexture.textureCacheIds.indexOf(id) === -1) { | ||
baseTexture.textureCacheIds.push(id); | ||
} | ||
// @if DEBUG | ||
/* eslint-disable no-console */ | ||
if (_utils.BaseTextureCache[id]) { | ||
console.warn('BaseTexture added to the cache with an id [' + id + '] that already had an entry'); | ||
} | ||
/* eslint-enable no-console */ | ||
// @endif | ||
_utils.BaseTextureCache[id] = baseTexture; | ||
} | ||
}; | ||
/** | ||
* Remove a BaseTexture from the global BaseTextureCache. | ||
* | ||
* @static | ||
* @param {string|PIXI.BaseTexture} baseTexture - id of a BaseTexture to be removed, or a BaseTexture instance itself. | ||
* @return {PIXI.BaseTexture|null} The BaseTexture that was removed. | ||
*/ | ||
BaseTexture.removeFromCache = function removeFromCache(baseTexture) { | ||
if (typeof baseTexture === 'string') { | ||
var baseTextureFromCache = _utils.BaseTextureCache[baseTexture]; | ||
if (baseTextureFromCache) { | ||
var index = baseTextureFromCache.textureCacheIds.indexOf(baseTexture); | ||
if (index > -1) { | ||
baseTextureFromCache.textureCacheIds.splice(index, 1); | ||
} | ||
delete _utils.BaseTextureCache[baseTexture]; | ||
return baseTextureFromCache; | ||
} | ||
} else { | ||
for (var i = 0; i < baseTexture.textureCacheIds.length; ++i) { | ||
delete _utils.BaseTextureCache[baseTexture.textureCacheIds[i]]; | ||
} | ||
baseTexture.textureCacheIds.length = 0; | ||
return baseTexture; | ||
} | ||
return null; | ||
}; | ||
return BaseTexture; | ||
@@ -763,0 +854,0 @@ }(_eventemitter2.default); |
@@ -190,3 +190,3 @@ 'use strict'; | ||
// lets also add the frame to pixi's global cache for fromFrame and fromImage functions | ||
_utils.TextureCache[i] = this.textures[i]; | ||
_.Texture.addToCache(this.textures[i], i); | ||
} | ||
@@ -193,0 +193,0 @@ |
@@ -27,2 +27,6 @@ 'use strict'; | ||
var _settings = require('../settings'); | ||
var _settings2 = _interopRequireDefault(_settings); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -168,5 +172,5 @@ | ||
* | ||
* @event update | ||
* @memberof PIXI.Texture# | ||
* @event PIXI.Texture#update | ||
* @protected | ||
* @param {PIXI.Texture} texture - Instance of texture being updated. | ||
*/ | ||
@@ -181,2 +185,11 @@ | ||
_this.transform = null; | ||
/** | ||
* The ids under which this Texture has been added to the texture cache. This is | ||
* automatically set as long as Texture.addToCache is used, but may not be set if a | ||
* Texture is added directly to the TextureCache array. | ||
* | ||
* @member {string[]} | ||
*/ | ||
_this.textureCacheIds = []; | ||
return _this; | ||
@@ -247,3 +260,3 @@ } | ||
if (_utils.TextureCache[this.baseTexture.imageUrl]) { | ||
delete _utils.TextureCache[this.baseTexture.imageUrl]; | ||
Texture.removeFromCache(this.baseTexture.imageUrl); | ||
} | ||
@@ -267,4 +280,4 @@ | ||
this.off('dispose', this.dispose, this); | ||
this.off('update', this.update, this); | ||
Texture.removeFromCache(this); | ||
this.textureCacheIds = null; | ||
}; | ||
@@ -318,3 +331,3 @@ | ||
texture = new Texture(_BaseTexture2.default.fromImage(imageUrl, crossorigin, scaleMode, sourceScale)); | ||
_utils.TextureCache[imageUrl] = texture; | ||
Texture.addToCache(texture, imageUrl); | ||
} | ||
@@ -351,2 +364,3 @@ | ||
* @param {number} [scaleMode=PIXI.settings.SCALE_MODE] - See {@link PIXI.SCALE_MODES} for possible values | ||
* @param {string} [origin='canvas'] - A string origin of who created the base texture | ||
* @return {PIXI.Texture} The newly created texture | ||
@@ -357,3 +371,5 @@ */ | ||
Texture.fromCanvas = function fromCanvas(canvas, scaleMode) { | ||
return new Texture(_BaseTexture2.default.fromCanvas(canvas, scaleMode)); | ||
var origin = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'canvas'; | ||
return new Texture(_BaseTexture2.default.fromCanvas(canvas, scaleMode, origin)); | ||
}; | ||
@@ -425,3 +441,3 @@ | ||
} else if (source instanceof HTMLCanvasElement) { | ||
return Texture.fromCanvas(source); | ||
return Texture.fromCanvas(source, _settings2.default.SCALE_MODE, 'HTMLCanvasElement'); | ||
} else if (source instanceof HTMLVideoElement) { | ||
@@ -461,9 +477,9 @@ return Texture.fromVideo(source); | ||
// lets also add the frame to pixi's global cache for fromFrame and fromImage fucntions | ||
_utils.BaseTextureCache[name] = baseTexture; | ||
_utils.TextureCache[name] = texture; | ||
_BaseTexture2.default.addToCache(texture.baseTexture, name); | ||
Texture.addToCache(texture, name); | ||
// also add references by url if they are different. | ||
if (name !== imageUrl) { | ||
_utils.BaseTextureCache[imageUrl] = baseTexture; | ||
_utils.TextureCache[imageUrl] = texture; | ||
_BaseTexture2.default.addToCache(texture.baseTexture, imageUrl); | ||
Texture.addToCache(texture, imageUrl); | ||
} | ||
@@ -475,30 +491,63 @@ | ||
/** | ||
* Adds a texture to the global TextureCache. This cache is shared across the whole PIXI object. | ||
* Adds a Texture to the global TextureCache. This cache is shared across the whole PIXI object. | ||
* | ||
* @static | ||
* @param {PIXI.Texture} texture - The Texture to add to the cache. | ||
* @param {string} id - The id that the texture will be stored against. | ||
* @param {string} id - The id that the Texture will be stored against. | ||
*/ | ||
Texture.addTextureToCache = function addTextureToCache(texture, id) { | ||
_utils.TextureCache[id] = texture; | ||
Texture.addToCache = function addToCache(texture, id) { | ||
if (id) { | ||
if (texture.textureCacheIds.indexOf(id) === -1) { | ||
texture.textureCacheIds.push(id); | ||
} | ||
// @if DEBUG | ||
/* eslint-disable no-console */ | ||
if (_utils.TextureCache[id]) { | ||
console.warn('Texture added to the cache with an id [' + id + '] that already had an entry'); | ||
} | ||
/* eslint-enable no-console */ | ||
// @endif | ||
_utils.TextureCache[id] = texture; | ||
} | ||
}; | ||
/** | ||
* Remove a texture from the global TextureCache. | ||
* Remove a Texture from the global TextureCache. | ||
* | ||
* @static | ||
* @param {string} id - The id of the texture to be removed | ||
* @return {PIXI.Texture} The texture that was removed | ||
* @param {string|PIXI.Texture} texture - id of a Texture to be removed, or a Texture instance itself | ||
* @return {PIXI.Texture|null} The Texture that was removed | ||
*/ | ||
Texture.removeTextureFromCache = function removeTextureFromCache(id) { | ||
var texture = _utils.TextureCache[id]; | ||
Texture.removeFromCache = function removeFromCache(texture) { | ||
if (typeof texture === 'string') { | ||
var textureFromCache = _utils.TextureCache[texture]; | ||
delete _utils.TextureCache[id]; | ||
delete _utils.BaseTextureCache[id]; | ||
if (textureFromCache) { | ||
var index = textureFromCache.textureCacheIds.indexOf(texture); | ||
return texture; | ||
if (index > -1) { | ||
textureFromCache.textureCacheIds.splice(index, 1); | ||
} | ||
delete _utils.TextureCache[texture]; | ||
return textureFromCache; | ||
} | ||
} else { | ||
for (var i = 0; i < texture.textureCacheIds.length; ++i) { | ||
delete _utils.TextureCache[texture.textureCacheIds[i]]; | ||
} | ||
texture.textureCacheIds.length = 0; | ||
return texture; | ||
} | ||
return null; | ||
}; | ||
@@ -505,0 +554,0 @@ |
@@ -15,6 +15,4 @@ 'use strict'; | ||
var ticker = _interopRequireWildcard(_ticker); | ||
var _const = require('../const'); | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -149,3 +147,3 @@ | ||
if (!this._isAutoUpdating && this.autoUpdate) { | ||
ticker.shared.add(this.update, this); | ||
_ticker.shared.add(this.update, this, _const.UPDATE_PRIORITY.HIGH); | ||
this._isAutoUpdating = true; | ||
@@ -164,3 +162,3 @@ } | ||
if (this._isAutoUpdating) { | ||
ticker.shared.remove(this.update, this); | ||
_ticker.shared.remove(this.update, this); | ||
this._isAutoUpdating = false; | ||
@@ -209,7 +207,7 @@ } | ||
if (this._isAutoUpdating) { | ||
ticker.shared.remove(this.update, this); | ||
_ticker.shared.remove(this.update, this); | ||
} | ||
if (this.source && this.source._pixiId) { | ||
delete _utils.BaseTextureCache[this.source._pixiId]; | ||
_BaseTexture3.default.removeFromCache(this.source._pixiId); | ||
delete this.source._pixiId; | ||
@@ -240,3 +238,3 @@ } | ||
baseTexture = new VideoBaseTexture(video, scaleMode); | ||
_utils.BaseTextureCache[video._pixiId] = baseTexture; | ||
_BaseTexture3.default.addToCache(baseTexture, video._pixiId); | ||
} | ||
@@ -301,6 +299,6 @@ | ||
if (!this._autoUpdate && this._isAutoUpdating) { | ||
ticker.shared.remove(this.update, this); | ||
_ticker.shared.remove(this.update, this); | ||
this._isAutoUpdating = false; | ||
} else if (this._autoUpdate && !this._isAutoUpdating) { | ||
ticker.shared.add(this.update, this); | ||
_ticker.shared.add(this.update, this, _const.UPDATE_PRIORITY.HIGH); | ||
this._isAutoUpdating = true; | ||
@@ -307,0 +305,0 @@ } |
@@ -57,4 +57,20 @@ 'use strict'; | ||
shared.autoStart = true; | ||
shared.destroy = function () { | ||
// protect destroying shared ticker | ||
// this is used by other internal systems | ||
// like AnimatedSprite and InteractionManager | ||
}; | ||
/** | ||
* This namespace contains an API for interacting with PIXI's internal global update loop. | ||
* | ||
* This ticker is used for rendering, {@link PIXI.extras.AnimatedSprite AnimatedSprite}, | ||
* {@link PIXI.interaction.InteractionManager InteractionManager} and many other time-based PIXI systems. | ||
* @example | ||
* const ticker = new PIXI.ticker.Ticker(); | ||
* ticker.stop(); | ||
* ticker.add((deltaTime) => { | ||
* // do something every frame | ||
* }); | ||
* ticker.start(); | ||
* @namespace PIXI.ticker | ||
@@ -61,0 +77,0 @@ */ |
@@ -11,6 +11,8 @@ 'use strict'; | ||
var _eventemitter = require('eventemitter3'); | ||
var _const = require('../const'); | ||
var _eventemitter2 = _interopRequireDefault(_eventemitter); | ||
var _TickerListener = require('./TickerListener'); | ||
var _TickerListener2 = _interopRequireDefault(_TickerListener); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -20,8 +22,5 @@ | ||
// Internal event used by composed emitter | ||
var TICK = 'tick'; | ||
/** | ||
* A Ticker class that runs an update loop that other objects listen to. | ||
* This class is composed around an EventEmitter object to add listeners | ||
* This class is composed around listeners | ||
* meant for execution on the next requested animation frame. | ||
@@ -34,3 +33,2 @@ * Animation frames are requested only when necessary, | ||
*/ | ||
var Ticker = function () { | ||
@@ -46,6 +44,7 @@ /** | ||
/** | ||
* Internal emitter used to fire 'tick' event | ||
* The first listener. All new listeners added are chained on this. | ||
* @private | ||
* @type {TickerListener} | ||
*/ | ||
this._emitter = new _eventemitter2.default(); | ||
this._head = new _TickerListener2.default(null, null, Infinity); | ||
@@ -154,3 +153,3 @@ /** | ||
// Listener side effects may have modified ticker state. | ||
if (_this.started && _this._requestId === null && _this._emitter.listeners(TICK, true)) { | ||
if (_this.started && _this._requestId === null && _this._head.next) { | ||
_this._requestId = requestAnimationFrame(_this._tick); | ||
@@ -172,3 +171,3 @@ } | ||
Ticker.prototype._requestIfNeeded = function _requestIfNeeded() { | ||
if (this._requestId === null && this._emitter.listeners(TICK, true)) { | ||
if (this._requestId === null && this._head.next) { | ||
// ensure callbacks get correct delta | ||
@@ -215,8 +214,8 @@ this.lastTime = performance.now(); | ||
/** | ||
* Calls {@link module:eventemitter3.EventEmitter#on} internally for the | ||
* internal 'tick' event. It checks if the emitter has listeners, | ||
* and if so it requests a new animation frame at this point. | ||
* Register a handler for tick events. Calls continuously unless | ||
* it is removed or the ticker is stopped. | ||
* | ||
* @param {Function} fn - The listener function to be added for updates | ||
* @param {Function} [context] - The listener context | ||
* @param {number} [priority=PIXI.UPDATE_PRIORITY.NORMAL] - The priority for emitting | ||
* @returns {PIXI.ticker.Ticker} This instance of a ticker | ||
@@ -227,16 +226,13 @@ */ | ||
Ticker.prototype.add = function add(fn, context) { | ||
this._emitter.on(TICK, fn, context); | ||
var priority = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _const.UPDATE_PRIORITY.NORMAL; | ||
this._startIfPossible(); | ||
return this; | ||
return this._addListener(new _TickerListener2.default(fn, context, priority)); | ||
}; | ||
/** | ||
* Calls {@link module:eventemitter3.EventEmitter#once} internally for the | ||
* internal 'tick' event. It checks if the emitter has listeners, | ||
* and if so it requests a new animation frame at this point. | ||
* Add a handler for the tick event which is only execute once. | ||
* | ||
* @param {Function} fn - The listener function to be added for one update | ||
* @param {Function} [context] - The listener context | ||
* @param {number} [priority=PIXI.UPDATE_PRIORITY.NORMAL] - The priority for emitting | ||
* @returns {PIXI.ticker.Ticker} This instance of a ticker | ||
@@ -247,4 +243,43 @@ */ | ||
Ticker.prototype.addOnce = function addOnce(fn, context) { | ||
this._emitter.once(TICK, fn, context); | ||
var priority = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _const.UPDATE_PRIORITY.NORMAL; | ||
return this._addListener(new _TickerListener2.default(fn, context, priority, true)); | ||
}; | ||
/** | ||
* Internally adds the event handler so that it can be sorted by priority. | ||
* Priority allows certain handler (user, AnimatedSprite, Interaction) to be run | ||
* before the rendering. | ||
* | ||
* @private | ||
* @param {TickerListener} listener - Current listener being added. | ||
* @returns {PIXI.ticker.Ticker} This instance of a ticker | ||
*/ | ||
Ticker.prototype._addListener = function _addListener(listener) { | ||
// For attaching to head | ||
var current = this._head.next; | ||
var previous = this._head; | ||
// Add the first item | ||
if (!current) { | ||
listener.connect(previous); | ||
} else { | ||
// Go from highest to lowest priority | ||
while (current) { | ||
if (listener.priority >= current.priority) { | ||
listener.connect(previous); | ||
break; | ||
} | ||
previous = current; | ||
current = current.next; | ||
} | ||
// Not yet connected | ||
if (!listener.previous) { | ||
listener.connect(previous); | ||
} | ||
} | ||
this._startIfPossible(); | ||
@@ -256,7 +291,6 @@ | ||
/** | ||
* Calls {@link module:eventemitter3.EventEmitter#off} internally for 'tick' event. | ||
* It checks if the emitter has listeners for 'tick' event. | ||
* If it does, then it cancels the animation frame. | ||
* Removes any handlers matching the function and context parameters. | ||
* If no handlers are left after removing, then it cancels the animation frame. | ||
* | ||
* @param {Function} [fn] - The listener function to be removed | ||
* @param {Function} fn - The listener function to be removed | ||
* @param {Function} [context] - The listener context to be removed | ||
@@ -268,5 +302,16 @@ * @returns {PIXI.ticker.Ticker} This instance of a ticker | ||
Ticker.prototype.remove = function remove(fn, context) { | ||
this._emitter.off(TICK, fn, context); | ||
var listener = this._head.next; | ||
if (!this._emitter.listeners(TICK, true)) { | ||
while (listener) { | ||
// We found a match, lets remove it | ||
// no break to delete all possible matches | ||
// incase a listener was added 2+ times | ||
if (listener.match(fn, context)) { | ||
listener = listener.destroy(); | ||
} else { | ||
listener = listener.next; | ||
} | ||
} | ||
if (!this._head.next) { | ||
this._cancelIfNeeded(); | ||
@@ -305,2 +350,21 @@ } | ||
/** | ||
* Destroy the ticker and don't use after this. Calling | ||
* this method removes all references to internal events. | ||
*/ | ||
Ticker.prototype.destroy = function destroy() { | ||
this.stop(); | ||
var listener = this._head.next; | ||
while (listener) { | ||
listener = listener.destroy(true); | ||
} | ||
this._head.destroy(); | ||
this._head = null; | ||
}; | ||
/** | ||
* Triggers an update. An update entails setting the | ||
@@ -351,4 +415,16 @@ * current {@link PIXI.ticker.Ticker#elapsedMS}, | ||
// Cache a local reference, in-case ticker is destroyed | ||
// during the emit, we can still check for head.next | ||
var head = this._head; | ||
// Invoke listeners added to internal emitter | ||
this._emitter.emit(TICK, this.deltaTime); | ||
var listener = head.next; | ||
while (listener) { | ||
listener = listener.emit(this.deltaTime); | ||
} | ||
if (!head.next) { | ||
this._cancelIfNeeded(); | ||
} | ||
} else { | ||
@@ -355,0 +431,0 @@ this.deltaTime = this.elapsedMS = 0; |
@@ -51,2 +51,17 @@ 'use strict'; | ||
/** | ||
* Generalized convenience utilities for PIXI. | ||
* @example | ||
* // Extend PIXI's internal Event Emitter. | ||
* class MyEmitter extends PIXI.utils.EventEmitter { | ||
* constructor() { | ||
* super(); | ||
* console.log("Emitter created!"); | ||
* } | ||
* } | ||
* | ||
* // Get info on current device | ||
* console.log(PIXI.utils.isMobile); | ||
* | ||
* // Convert hex color to string | ||
* console.log(PIXI.utils.hex2string(0xff00ff)); // returns: "#ff00ff" | ||
* @namespace PIXI.utils | ||
@@ -336,3 +351,3 @@ */ | ||
*/ | ||
var TextureCache = exports.TextureCache = {}; | ||
var TextureCache = exports.TextureCache = Object.create(null); | ||
@@ -345,3 +360,3 @@ /** | ||
*/ | ||
var BaseTextureCache = exports.BaseTextureCache = {}; | ||
var BaseTextureCache = exports.BaseTextureCache = Object.create(null); | ||
@@ -348,0 +363,0 @@ /** |
@@ -657,2 +657,41 @@ 'use strict'; | ||
/** | ||
* Calculates the ascent, descent and fontSize of a given fontStyle | ||
* | ||
* @name PIXI.Text.calculateFontProperties | ||
* @see PIXI.TextMetrics.measureFont | ||
* @deprecated since version 4.5.0 | ||
* @param {string} font - String representing the style of the font | ||
* @return {Object} Font properties object | ||
*/ | ||
core.Text.calculateFontProperties = function calculateFontProperties(font) { | ||
warn('Text.calculateFontProperties is now deprecated, please use the TextMetrics.measureFont'); | ||
return core.TextMetrics.measureFont(font); | ||
}; | ||
Object.defineProperties(core.Text, { | ||
fontPropertiesCache: { | ||
get: function get() { | ||
warn('Text.fontPropertiesCache is deprecated'); | ||
return core.TextMetrics._fonts; | ||
} | ||
}, | ||
fontPropertiesCanvas: { | ||
get: function get() { | ||
warn('Text.fontPropertiesCanvas is deprecated'); | ||
return core.TextMetrics._canvas; | ||
} | ||
}, | ||
fontPropertiesContext: { | ||
get: function get() { | ||
warn('Text.fontPropertiesContext is deprecated'); | ||
return core.TextMetrics._context; | ||
} | ||
} | ||
}); | ||
/** | ||
* @method | ||
@@ -672,3 +711,3 @@ * @name PIXI.Text#setStyle | ||
* @name PIXI.Text#determineFontProperties | ||
* @see PIXI.Text#calculateFontProperties | ||
* @see PIXI.Text#measureFontProperties | ||
* @deprecated since version 4.2.0 | ||
@@ -680,7 +719,27 @@ * @private | ||
core.Text.prototype.determineFontProperties = function determineFontProperties(fontStyle) { | ||
warn('determineFontProperties is now deprecated, please use the static calculateFontProperties method, ' + 'e.g : Text.calculateFontProperties(fontStyle);'); | ||
warn('determineFontProperties is now deprecated, please use TextMetrics.measureFont method'); | ||
return core.Text.calculateFontProperties(fontStyle); | ||
return core.TextMetrics.measureFont(fontStyle); | ||
}; | ||
/** | ||
* @method | ||
* @name PIXI.Text.getFontStyle | ||
* @see PIXI.TextMetrics.getFontStyle | ||
* @deprecated since version 4.5.0 | ||
* @param {PIXI.TextStyle} style - The style to use. | ||
* @return {string} Font string | ||
*/ | ||
core.Text.getFontStyle = function getFontStyle(style) { | ||
warn('getFontStyle is now deprecated, please use TextStyle.toFontString() instead'); | ||
style = style || {}; | ||
if (!(style instanceof core.TextStyle)) { | ||
style = new core.TextStyle(style); | ||
} | ||
return style.toFontString(); | ||
}; | ||
Object.defineProperties(core.TextStyle.prototype, { | ||
@@ -771,2 +830,33 @@ /** | ||
/** | ||
* @static | ||
* @function | ||
* @name PIXI.Texture.addTextureToCache | ||
* @see PIXI.Texture.addToCache | ||
* @deprecated since 4.5.0 | ||
* @param {PIXI.Texture} texture - The Texture to add to the cache. | ||
* @param {string} id - The id that the texture will be stored against. | ||
*/ | ||
core.Texture.addTextureToCache = function addTextureToCache(texture, id) { | ||
core.Texture.addToCache(texture, id); | ||
warn('Texture.addTextureToCache is deprecated, please use Texture.addToCache from now on.'); | ||
}; | ||
/** | ||
* @static | ||
* @function | ||
* @name PIXI.Texture.removeTextureFromCache | ||
* @see PIXI.Texture.removeFromCache | ||
* @deprecated since 4.5.0 | ||
* @param {string} id - The id of the texture to be removed | ||
* @return {PIXI.Texture|null} The texture that was removed | ||
*/ | ||
core.Texture.removeTextureFromCache = function removeTextureFromCache(id) { | ||
warn('Texture.removeTextureFromCache is deprecated, please use Texture.removeFromCache from now on. ' + 'Be aware that Texture.removeFromCache does not automatically its BaseTexture from the BaseTextureCache. ' + 'For that, use BaseTexture.removeFromCache'); | ||
core.BaseTexture.removeFromCache(id); | ||
return core.Texture.removeFromCache(id); | ||
}; | ||
Object.defineProperties(filters, { | ||
@@ -853,2 +943,27 @@ | ||
/** | ||
* @method | ||
* @name PIXI.prepare.BasePrepare#register | ||
* @see PIXI.prepare.BasePrepare#registerFindHook | ||
* @deprecated since version 4.4.2 | ||
* @param {Function} [addHook] - Function call that takes two parameters: `item:*, queue:Array` | ||
* function must return `true` if it was able to add item to the queue. | ||
* @param {Function} [uploadHook] - Function call that takes two parameters: `prepare:CanvasPrepare, item:*` and | ||
* function must return `true` if it was able to handle upload of item. | ||
* @return {PIXI.BasePrepare} Instance of plugin for chaining. | ||
*/ | ||
prepare.BasePrepare.prototype.register = function register(addHook, uploadHook) { | ||
warn('renderer.plugins.prepare.register is now deprecated, ' + 'please use renderer.plugins.prepare.registerFindHook & renderer.plugins.prepare.registerUploadHook'); | ||
if (addHook) { | ||
this.registerFindHook(addHook); | ||
} | ||
if (uploadHook) { | ||
this.registerUploadHook(uploadHook); | ||
} | ||
return this; | ||
}; | ||
/** | ||
* The number of graphics or textures to upload to the GPU. | ||
@@ -897,56 +1012,61 @@ * | ||
Object.defineProperties(loaders.Resource.prototype, { | ||
isJson: { | ||
get: function get() { | ||
warn('The isJson property is deprecated, please use `resource.type === Resource.TYPE.JSON`.'); | ||
if (loaders.Loader) { | ||
var Resource = loaders.Resource; | ||
var Loader = loaders.Loader; | ||
return this.type === loaders.Loader.Resource.TYPE.JSON; | ||
} | ||
}, | ||
isXml: { | ||
get: function get() { | ||
warn('The isXml property is deprecated, please use `resource.type === Resource.TYPE.XML`.'); | ||
Object.defineProperties(Resource.prototype, { | ||
isJson: { | ||
get: function get() { | ||
warn('The isJson property is deprecated, please use `resource.type === Resource.TYPE.JSON`.'); | ||
return this.type === loaders.Loader.Resource.TYPE.XML; | ||
} | ||
}, | ||
isImage: { | ||
get: function get() { | ||
warn('The isImage property is deprecated, please use `resource.type === Resource.TYPE.IMAGE`.'); | ||
return this.type === Resource.TYPE.JSON; | ||
} | ||
}, | ||
isXml: { | ||
get: function get() { | ||
warn('The isXml property is deprecated, please use `resource.type === Resource.TYPE.XML`.'); | ||
return this.type === loaders.Loader.Resource.TYPE.IMAGE; | ||
} | ||
}, | ||
isAudio: { | ||
get: function get() { | ||
warn('The isAudio property is deprecated, please use `resource.type === Resource.TYPE.AUDIO`.'); | ||
return this.type === Resource.TYPE.XML; | ||
} | ||
}, | ||
isImage: { | ||
get: function get() { | ||
warn('The isImage property is deprecated, please use `resource.type === Resource.TYPE.IMAGE`.'); | ||
return this.type === loaders.Loader.Resource.TYPE.AUDIO; | ||
} | ||
}, | ||
isVideo: { | ||
get: function get() { | ||
warn('The isVideo property is deprecated, please use `resource.type === Resource.TYPE.VIDEO`.'); | ||
return this.type === Resource.TYPE.IMAGE; | ||
} | ||
}, | ||
isAudio: { | ||
get: function get() { | ||
warn('The isAudio property is deprecated, please use `resource.type === Resource.TYPE.AUDIO`.'); | ||
return this.type === loaders.Loader.Resource.TYPE.VIDEO; | ||
return this.type === Resource.TYPE.AUDIO; | ||
} | ||
}, | ||
isVideo: { | ||
get: function get() { | ||
warn('The isVideo property is deprecated, please use `resource.type === Resource.TYPE.VIDEO`.'); | ||
return this.type === Resource.TYPE.VIDEO; | ||
} | ||
} | ||
} | ||
}); | ||
}); | ||
Object.defineProperties(loaders.Loader.prototype, { | ||
before: { | ||
get: function get() { | ||
warn('The before() method is deprecated, please use pre().'); | ||
Object.defineProperties(Loader.prototype, { | ||
before: { | ||
get: function get() { | ||
warn('The before() method is deprecated, please use pre().'); | ||
return this.pre; | ||
} | ||
}, | ||
after: { | ||
get: function get() { | ||
warn('The after() method is deprecated, please use use().'); | ||
return this.pre; | ||
} | ||
}, | ||
after: { | ||
get: function get() { | ||
warn('The after() method is deprecated, please use use().'); | ||
return this.use; | ||
return this.use; | ||
} | ||
} | ||
} | ||
}); | ||
}); | ||
} | ||
@@ -953,0 +1073,0 @@ /** |
@@ -21,3 +21,3 @@ 'use strict'; | ||
* @class | ||
* @memberof PIXI | ||
* @memberof PIXI.extract | ||
*/ | ||
@@ -36,5 +36,5 @@ | ||
* | ||
* @member {PIXI.CanvasExtract} extract | ||
* @member {PIXI.extract.CanvasExtract} extract | ||
* @memberof PIXI.CanvasRenderer# | ||
* @see PIXI.CanvasExtract | ||
* @see PIXI.extract.CanvasExtract | ||
*/ | ||
@@ -41,0 +41,0 @@ renderer.extract = this; |
@@ -22,3 +22,3 @@ 'use strict'; | ||
* @class | ||
* @memberof PIXI | ||
* @memberof PIXI.extract | ||
*/ | ||
@@ -37,5 +37,5 @@ | ||
* | ||
* @member {PIXI.WebGLExtract} extract | ||
* @member {PIXI.extract.WebGLExtract} extract | ||
* @memberof PIXI.WebGLRenderer# | ||
* @see PIXI.WebGLExtract | ||
* @see PIXI.extract.WebGLExtract | ||
*/ | ||
@@ -42,0 +42,0 @@ renderer.extract = this; |
@@ -157,3 +157,3 @@ 'use strict'; | ||
if (this._autoUpdate) { | ||
core.ticker.shared.add(this.update, this); | ||
core.ticker.shared.add(this.update, this, core.UPDATE_PRIORITY.HIGH); | ||
} | ||
@@ -160,0 +160,0 @@ }; |
@@ -7,2 +7,14 @@ 'use strict'; | ||
var _Texture = require('../core/textures/Texture'); | ||
var _Texture2 = _interopRequireDefault(_Texture); | ||
var _BaseTexture = require('../core/textures/BaseTexture'); | ||
var _BaseTexture2 = _interopRequireDefault(_BaseTexture); | ||
var _utils = require('../core/utils'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } | ||
@@ -33,2 +45,4 @@ | ||
this.textureCacheId = null; | ||
this.originalRenderWebGL = null; | ||
@@ -185,2 +199,9 @@ this.originalRenderCanvas = null; | ||
var textureCacheId = 'cacheAsBitmap_' + (0, _utils.uid)(); | ||
this._cacheData.textureCacheId = textureCacheId; | ||
_BaseTexture2.default.addToCache(renderTexture.baseTexture, textureCacheId); | ||
_Texture2.default.addToCache(renderTexture, textureCacheId); | ||
// need to set // | ||
@@ -228,3 +249,9 @@ var m = _tempMatrix; | ||
// restore the transform of the cached sprite to avoid the nasty flicker.. | ||
this.updateTransform(); | ||
if (!this.parent) { | ||
this.parent = renderer._tempDisplayObjectParent; | ||
this.updateTransform(); | ||
this.parent = null; | ||
} else { | ||
this.updateTransform(); | ||
} | ||
@@ -278,2 +305,9 @@ // map the hit test.. | ||
var textureCacheId = 'cacheAsBitmap_' + (0, _utils.uid)(); | ||
this._cacheData.textureCacheId = textureCacheId; | ||
_BaseTexture2.default.addToCache(renderTexture.baseTexture, textureCacheId); | ||
_Texture2.default.addToCache(renderTexture, textureCacheId); | ||
// need to set // | ||
@@ -313,3 +347,10 @@ var m = _tempMatrix; | ||
this.updateTransform(); | ||
if (!this.parent) { | ||
this.parent = renderer._tempDisplayObjectParent; | ||
this.updateTransform(); | ||
this.parent = null; | ||
} else { | ||
this.updateTransform(); | ||
} | ||
this.updateTransform = this.displayObjectUpdateTransform; | ||
@@ -349,2 +390,7 @@ | ||
this._cacheData.sprite = null; | ||
_BaseTexture2.default.removeFromCache(this._cacheData.textureCacheId); | ||
_Texture2.default.removeFromCache(this._cacheData.textureCacheId); | ||
this._cacheData.textureCacheId = null; | ||
}; | ||
@@ -351,0 +397,0 @@ |
'use strict'; | ||
exports.__esModule = true; | ||
exports.BitmapText = exports.TilingSpriteRenderer = exports.TilingSprite = exports.AnimatedSprite = exports.TextureTransform = undefined; | ||
exports.BitmapText = exports.TilingSpriteRenderer = exports.TilingSprite = exports.AnimatedSprite = undefined; | ||
var _TextureTransform = require('./TextureTransform'); | ||
Object.defineProperty(exports, 'TextureTransform', { | ||
enumerable: true, | ||
get: function get() { | ||
return _interopRequireDefault(_TextureTransform).default; | ||
} | ||
}); | ||
var _AnimatedSprite = require('./AnimatedSprite'); | ||
@@ -16,0 +7,0 @@ |
@@ -72,5 +72,32 @@ 'use strict'; | ||
/** | ||
* Multiplies uvs array to transform | ||
* @param {Float32Array} uvs mesh uvs | ||
* @param {Float32Array} [out=uvs] output | ||
* @returns {Float32Array} output | ||
*/ | ||
TextureTransform.prototype.multiplyUvs = function multiplyUvs(uvs, out) { | ||
if (out === undefined) { | ||
out = uvs; | ||
} | ||
var mat = this.mapCoord; | ||
for (var i = 0; i < uvs.length; i += 2) { | ||
var x = uvs[i]; | ||
var y = uvs[i + 1]; | ||
out[i] = x * mat.a + y * mat.c + mat.tx; | ||
out[i + 1] = x * mat.b + y * mat.d + mat.ty; | ||
} | ||
return out; | ||
}; | ||
/** | ||
* updates matrices if texture was changed | ||
* @param {boolean} forceUpdate if true, matrices will be updated any case | ||
* @returns {boolean} whether or not it was updated | ||
*/ | ||
TextureTransform.prototype.update = function update(forceUpdate) { | ||
@@ -80,7 +107,7 @@ var tex = this._texture; | ||
if (!tex || !tex.valid) { | ||
return; | ||
return false; | ||
} | ||
if (!forceUpdate && this._lastTextureID === tex._updateID) { | ||
return; | ||
return false; | ||
} | ||
@@ -113,2 +140,4 @@ | ||
this.uClampOffset[1] = offset / texBase.realHeight; | ||
return true; | ||
}; | ||
@@ -115,0 +144,0 @@ |
@@ -173,5 +173,5 @@ 'use strict'; | ||
var baseTexture = texture.baseTexture; | ||
var baseTextureResolution = texture.baseTexture.resolution; | ||
var modX = this.tilePosition.x / this.tileScale.x % texture._frame.width; | ||
var modY = this.tilePosition.y / this.tileScale.y % texture._frame.height; | ||
var baseTextureResolution = baseTexture.resolution; | ||
var modX = this.tilePosition.x / this.tileScale.x % texture._frame.width * baseTextureResolution; | ||
var modY = this.tilePosition.y / this.tileScale.y % texture._frame.height * baseTextureResolution; | ||
@@ -178,0 +178,0 @@ // create a nice shiny pattern! |
@@ -28,3 +28,3 @@ 'use strict'; | ||
* @class | ||
* @memberof PIXI | ||
* @memberof PIXI.extras | ||
* @extends PIXI.ObjectRenderer | ||
@@ -138,3 +138,3 @@ */ | ||
if (isSimple) { | ||
tempMat.append(uv.mapCoord); | ||
tempMat.prepend(uv.mapCoord); | ||
} else { | ||
@@ -141,0 +141,0 @@ shader.uniforms.uMapCoord = uv.mapCoord.toArray(true); |
@@ -55,3 +55,3 @@ 'use strict'; | ||
_this.uniforms.mapSampler = sprite.texture; | ||
_this.uniforms.mapSampler = sprite._texture; | ||
_this.uniforms.filterMatrix = maskMatrix; | ||
@@ -58,0 +58,0 @@ _this.uniforms.scale = { x: 1, y: 1 }; |
@@ -86,4 +86,14 @@ 'use strict'; | ||
/** | ||
* Alias for {@link PIXI.loaders.shared}. | ||
* @name loader | ||
* @memberof PIXI | ||
* @type {PIXI.loader.Loader} | ||
*/ | ||
// handle mixins now, after all code has been added, including deprecation | ||
// import polyfills. Done as an export to make sure polyfills are imported first | ||
var loader = loaders.shared || null; | ||
exports.accessibility = accessibility; | ||
@@ -98,13 +108,2 @@ exports.extract = extract; | ||
exports.prepare = prepare; | ||
/** | ||
* A premade instance of the loader that can be used to load resources. | ||
* | ||
* @name loader | ||
* @memberof PIXI | ||
* @property {PIXI.loaders.Loader} | ||
*/ | ||
var loader = loaders && loaders.Loader ? new loaders.Loader() : null; // check is there in case user excludes loader lib | ||
exports.loader = loader; | ||
@@ -111,0 +110,0 @@ |
@@ -43,3 +43,6 @@ 'use strict'; | ||
* | ||
* @member {Event} | ||
* @see https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent | ||
* @see https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent | ||
* @see https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent | ||
* @member {MouseEvent|TouchEvent|PointerEvent} | ||
*/ | ||
@@ -46,0 +49,0 @@ this.originalEvent = null; |
@@ -42,3 +42,3 @@ "use strict"; | ||
/* | ||
/** | ||
* Type of the event | ||
@@ -50,3 +50,3 @@ * | ||
/* | ||
/** | ||
* InteractionData related to this event | ||
@@ -53,0 +53,0 @@ * |
@@ -44,4 +44,6 @@ "use strict"; | ||
/** | ||
* Unique pointer id of the event | ||
* | ||
* @readonly | ||
* @type {number} Unique pointer id of the event | ||
* @member {number} | ||
*/ | ||
@@ -48,0 +50,0 @@ |
@@ -8,3 +8,3 @@ 'use strict'; | ||
* | ||
* @mixin | ||
* @private | ||
* @name interactiveTarget | ||
@@ -21,6 +21,15 @@ * @memberof PIXI.interaction | ||
exports.default = { | ||
/** | ||
* Determines if the displayObject be clicked/touched | ||
* Enable interaction events for the DisplayObject. Touch, pointer and mouse | ||
* events will not be emitted unless `interactive` is set to `true`. | ||
* | ||
* @inner {boolean} | ||
* @example | ||
* const sprite = new PIXI.Sprite(texture); | ||
* sprite.interactive = true; | ||
* sprite.on('tap', (event) => { | ||
* //handle event | ||
* }); | ||
* @member {boolean} | ||
* @memberof PIXI.DisplayObject# | ||
*/ | ||
@@ -31,5 +40,6 @@ interactive: false, | ||
* Determines if the children to the displayObject can be clicked/touched | ||
* Setting this to false allows pixi to bypass a recursive hitTest function | ||
* Setting this to false allows pixi to bypass a recursive `hitTest` function | ||
* | ||
* @inner {boolean} | ||
* @member {boolean} | ||
* @memberof PIXI.Container# | ||
*/ | ||
@@ -42,3 +52,8 @@ interactiveChildren: true, | ||
* | ||
* @inner {PIXI.Rectangle|PIXI.Circle|PIXI.Ellipse|PIXI.Polygon|PIXI.RoundedRectangle} | ||
* @example | ||
* const sprite = new PIXI.Sprite(texture); | ||
* sprite.interactive = true; | ||
* sprite.hitArea = new PIXI.Rectangle(0, 0, 100, 100); | ||
* @member {PIXI.Rectangle|PIXI.Circle|PIXI.Ellipse|PIXI.Polygon|PIXI.RoundedRectangle} | ||
* @memberof PIXI.DisplayObject# | ||
*/ | ||
@@ -51,4 +66,8 @@ hitArea: null, | ||
* | ||
* @example | ||
* const sprite = new PIXI.Sprite(texture); | ||
* sprite.interactive = true; | ||
* sprite.buttonMode = true; | ||
* @member {boolean} | ||
* @memberof PIXI.interaction.interactiveTarget# | ||
* @memberof PIXI.DisplayObject# | ||
*/ | ||
@@ -70,5 +89,10 @@ get buttonMode() { | ||
* | ||
* @example | ||
* const sprite = new PIXI.Sprite(texture); | ||
* sprite.interactive = true; | ||
* sprite.cursor = 'wait'; | ||
* @see https://developer.mozilla.org/en/docs/Web/CSS/cursor | ||
* | ||
* @inner {string} | ||
* @member {string} | ||
* @memberof PIXI.DisplayObject# | ||
*/ | ||
@@ -81,3 +105,3 @@ cursor: null, | ||
* @member {Map<number, InteractionTrackingData>} | ||
* @memberof PIXI.interaction.interactiveTarget# | ||
* @memberof PIXI.DisplayObject# | ||
* @private | ||
@@ -94,3 +118,4 @@ */ | ||
* | ||
* @private {Map<number, InteractionTrackingData>} | ||
* @private | ||
* @type {Map<number, InteractionTrackingData>} | ||
*/ | ||
@@ -97,0 +122,0 @@ _trackedPointers: undefined |
'use strict'; | ||
exports.__esModule = true; | ||
exports.shared = exports.Resource = exports.textureParser = exports.getResourcePath = exports.spritesheetParser = exports.parseBitmapFontData = exports.bitmapFontParser = exports.Loader = undefined; | ||
var _loader = require('./loader'); | ||
Object.defineProperty(exports, 'Loader', { | ||
enumerable: true, | ||
get: function get() { | ||
return _interopRequireDefault(_loader).default; | ||
} | ||
}); | ||
var _bitmapFontParser = require('./bitmapFontParser'); | ||
Object.defineProperty(exports, 'bitmapFontParser', { | ||
enumerable: true, | ||
get: function get() { | ||
return _interopRequireDefault(_bitmapFontParser).default; | ||
} | ||
enumerable: true, | ||
get: function get() { | ||
return _interopRequireDefault(_bitmapFontParser).default; | ||
} | ||
}); | ||
Object.defineProperty(exports, 'parseBitmapFontData', { | ||
enumerable: true, | ||
get: function get() { | ||
return _bitmapFontParser.parse; | ||
} | ||
enumerable: true, | ||
get: function get() { | ||
return _bitmapFontParser.parse; | ||
} | ||
}); | ||
@@ -32,7 +24,13 @@ | ||
Object.defineProperty(exports, 'spritesheetParser', { | ||
enumerable: true, | ||
get: function get() { | ||
return _interopRequireDefault(_spritesheetParser).default; | ||
} | ||
enumerable: true, | ||
get: function get() { | ||
return _interopRequireDefault(_spritesheetParser).default; | ||
} | ||
}); | ||
Object.defineProperty(exports, 'getResourcePath', { | ||
enumerable: true, | ||
get: function get() { | ||
return _spritesheetParser.getResourcePath; | ||
} | ||
}); | ||
@@ -42,6 +40,6 @@ var _textureParser = require('./textureParser'); | ||
Object.defineProperty(exports, 'textureParser', { | ||
enumerable: true, | ||
get: function get() { | ||
return _interopRequireDefault(_textureParser).default; | ||
} | ||
enumerable: true, | ||
get: function get() { | ||
return _interopRequireDefault(_textureParser).default; | ||
} | ||
}); | ||
@@ -52,9 +50,81 @@ | ||
Object.defineProperty(exports, 'Resource', { | ||
enumerable: true, | ||
get: function get() { | ||
return _resourceLoader.Resource; | ||
} | ||
enumerable: true, | ||
get: function get() { | ||
return _resourceLoader.Resource; | ||
} | ||
}); | ||
var _Application = require('../core/Application'); | ||
var _Application2 = _interopRequireDefault(_Application); | ||
var _loader = require('./loader'); | ||
var _loader2 = _interopRequireDefault(_loader); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/** | ||
* This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module | ||
* for loading assets, data, and other resources dynamically. | ||
* @example | ||
* const loader = new PIXI.loaders.Loader(); | ||
* loader.add('bunny', 'data/bunny.png') | ||
* .add('spaceship', 'assets/spritesheet.json'); | ||
* loader.load((loader, resources) => { | ||
* // resources.bunny | ||
* // resources.spaceship | ||
* }); | ||
* @namespace PIXI.loaders | ||
*/ | ||
exports.Loader = _loader2.default; | ||
/** | ||
* A premade instance of the loader that can be used to load resources. | ||
* @name shared | ||
* @memberof PIXI.loaders | ||
* @type {PIXI.loaders.Loader} | ||
*/ | ||
var shared = new _loader2.default(); | ||
shared.destroy = function () { | ||
// protect destroying shared loader | ||
}; | ||
exports.shared = shared; | ||
// Mixin the loader construction | ||
var AppPrototype = _Application2.default.prototype; | ||
AppPrototype._loader = null; | ||
/** | ||
* Loader instance to help with asset loading. | ||
* @name PIXI.Application#loader | ||
* @type {PIXI.loaders.Loader} | ||
*/ | ||
Object.defineProperty(AppPrototype, 'loader', { | ||
get: function get() { | ||
if (!this._loader) { | ||
var sharedLoader = this._options.sharedLoader; | ||
this._loader = sharedLoader ? shared : new _loader2.default(); | ||
} | ||
return this._loader; | ||
} | ||
}); | ||
// Override the destroy function | ||
// making sure to destroy the current Loader | ||
AppPrototype._parentDestroy = AppPrototype.destroy; | ||
AppPrototype.destroy = function destroy() { | ||
if (this._loader) { | ||
this._loader.destroy(); | ||
this._loader = null; | ||
} | ||
this._parentDestroy(); | ||
}; | ||
//# sourceMappingURL=index.js.map |
@@ -135,2 +135,12 @@ 'use strict'; | ||
/** | ||
* Destroy the loader, removes references. | ||
*/ | ||
Loader.prototype.destroy = function destroy() { | ||
this.removeAllListeners(); | ||
this.reset(); | ||
}; | ||
return Loader; | ||
@@ -137,0 +147,0 @@ }(_resourceLoader2.default); |
@@ -7,3 +7,2 @@ 'use strict'; | ||
return function spritesheetParser(resource, next) { | ||
var resourcePath = void 0; | ||
var imageResourceName = resource.name + '_image'; | ||
@@ -25,8 +24,3 @@ | ||
// Prepend url path unless the resource image is a data url | ||
if (resource.isDataUrl) { | ||
resourcePath = resource.data.meta.image; | ||
} else { | ||
resourcePath = _path2.default.dirname(resource.url.replace(this.baseUrl, '')) + '/' + resource.data.meta.image; | ||
} | ||
var resourcePath = getResourcePath(resource, this.baseUrl); | ||
@@ -46,7 +40,9 @@ // load the image for this sheet | ||
exports.getResourcePath = getResourcePath; | ||
var _resourceLoader = require('resource-loader'); | ||
var _path = require('path'); | ||
var _url = require('url'); | ||
var _path2 = _interopRequireDefault(_path); | ||
var _url2 = _interopRequireDefault(_url); | ||
@@ -56,2 +52,11 @@ var _core = require('../core'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function getResourcePath(resource, baseUrl) { | ||
// Prepend url path unless the resource image is a data url | ||
if (resource.isDataUrl) { | ||
return resource.data.meta.image; | ||
} | ||
return _url2.default.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); | ||
} | ||
//# sourceMappingURL=spritesheetParser.js.map |
@@ -134,9 +134,27 @@ 'use strict'; | ||
var u0 = uvs[index0] * base.width; | ||
var u1 = uvs[index1] * base.width; | ||
var u2 = uvs[index2] * base.width; | ||
var v0 = uvs[index0 + 1] * base.height; | ||
var v1 = uvs[index1 + 1] * base.height; | ||
var v2 = uvs[index2 + 1] * base.height; | ||
var u0 = void 0; | ||
var u1 = void 0; | ||
var u2 = void 0; | ||
var v0 = void 0; | ||
var v1 = void 0; | ||
var v2 = void 0; | ||
if (mesh.uploadUvTransform) { | ||
var ut = mesh._uvTransform.mapCoord; | ||
u0 = (uvs[index0] * ut.a + uvs[index0 + 1] * ut.c + ut.tx) * base.width; | ||
u1 = (uvs[index1] * ut.a + uvs[index1 + 1] * ut.c + ut.tx) * base.width; | ||
u2 = (uvs[index2] * ut.a + uvs[index2 + 1] * ut.c + ut.tx) * base.width; | ||
v0 = (uvs[index0] * ut.b + uvs[index0 + 1] * ut.d + ut.ty) * base.height; | ||
v1 = (uvs[index1] * ut.b + uvs[index1 + 1] * ut.d + ut.ty) * base.height; | ||
v2 = (uvs[index2] * ut.b + uvs[index2 + 1] * ut.d + ut.ty) * base.height; | ||
} else { | ||
u0 = uvs[index0] * base.width; | ||
u1 = uvs[index1] * base.width; | ||
u2 = uvs[index2] * base.width; | ||
v0 = uvs[index0 + 1] * base.height; | ||
v1 = uvs[index1 + 1] * base.height; | ||
v2 = uvs[index2 + 1] * base.height; | ||
} | ||
var x0 = vertices[index0]; | ||
@@ -143,0 +161,0 @@ var x1 = vertices[index1]; |
@@ -11,2 +11,8 @@ 'use strict'; | ||
var _TextureTransform = require('../extras/TextureTransform'); | ||
var _TextureTransform2 = _interopRequireDefault(_TextureTransform); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } | ||
@@ -51,3 +57,3 @@ | ||
_this._texture = null; | ||
_this._texture = texture; | ||
@@ -68,4 +74,6 @@ /** | ||
/* | ||
* @member {Uint16Array} An array containing the indices of the vertices | ||
/** | ||
* An array containing the indices of the vertices | ||
* | ||
* @member {Uint16Array} | ||
*/ | ||
@@ -115,5 +123,2 @@ // TODO auto generate this based on draw mode! | ||
// run texture setter; | ||
_this.texture = texture; | ||
/** | ||
@@ -143,5 +148,23 @@ * The default shader that is used if a mesh doesn't have a more specific one. | ||
/** | ||
* transform that is applied to UV to get the texture coords | ||
* its updated independently from texture uvTransform | ||
* updates of uvs are tied to that thing | ||
* | ||
* @member {PIXI.extras.TextureTransform} | ||
* @private | ||
*/ | ||
_this._uvTransform = new _TextureTransform2.default(texture); | ||
/** | ||
* whether or not upload uvTransform to shader | ||
* if its false, then uvs should be pre-multiplied | ||
* if you change it for generated mesh, please call 'refresh(true)' | ||
* @member {boolean} | ||
* @default false | ||
*/ | ||
_this.uploadUvTransform = false; | ||
/** | ||
* Plugin that is responsible for rendering this element. | ||
* Allows to customize the rendering process without overriding '_renderWebGL' & '_renderCanvas' methods. | ||
* | ||
* @member {string} | ||
@@ -163,2 +186,3 @@ * @default 'mesh' | ||
Mesh.prototype._renderWebGL = function _renderWebGL(renderer) { | ||
this.refresh(); | ||
renderer.setObjectRenderer(renderer.plugins[this.pluginName]); | ||
@@ -177,2 +201,3 @@ renderer.plugins[this.pluginName].render(this); | ||
Mesh.prototype._renderCanvas = function _renderCanvas(renderer) { | ||
this.refresh(); | ||
renderer.plugins[this.pluginName].render(this); | ||
@@ -188,3 +213,41 @@ }; | ||
Mesh.prototype._onTextureUpdate = function _onTextureUpdate() {} | ||
Mesh.prototype._onTextureUpdate = function _onTextureUpdate() { | ||
this._uvTransform.texture = this._texture; | ||
this.refresh(); | ||
}; | ||
/** | ||
* multiplies uvs only if uploadUvTransform is false | ||
* call it after you change uvs manually | ||
* make sure that texture is valid | ||
*/ | ||
Mesh.prototype.multiplyUvs = function multiplyUvs() { | ||
if (!this.uploadUvTransform) { | ||
this._uvTransform.multiplyUvs(this.uvs); | ||
} | ||
}; | ||
/** | ||
* Refreshes uvs for generated meshes (rope, plane) | ||
* sometimes refreshes vertices too | ||
* | ||
* @param {boolean} [forceUpdate=false] if true, matrices will be updated any case | ||
*/ | ||
Mesh.prototype.refresh = function refresh(forceUpdate) { | ||
if (this._uvTransform.update(forceUpdate)) { | ||
this._refresh(); | ||
} | ||
}; | ||
/** | ||
* re-calculates mesh coords | ||
* @protected | ||
*/ | ||
Mesh.prototype._refresh = function _refresh() {} | ||
/* empty */ | ||
@@ -191,0 +254,0 @@ |
@@ -74,4 +74,4 @@ 'use strict'; | ||
_this._origWidth = texture.width; | ||
_this._origHeight = texture.height; | ||
_this._origWidth = texture.orig.width; | ||
_this._origHeight = texture.orig.height; | ||
_this._uvw = 1 / _this._origWidth; | ||
@@ -87,3 +87,3 @@ _this._uvh = 1 / _this._origHeight; | ||
*/ | ||
_this.width = texture.width; | ||
_this.width = _this._origWidth; | ||
@@ -97,3 +97,3 @@ /** | ||
*/ | ||
_this.height = texture.height; | ||
_this.height = _this._origHeight; | ||
@@ -140,2 +140,4 @@ uvs[2] = uvs[10] = uvs[18] = uvs[26] = _this._uvw * leftWidth; | ||
_this.bottomHeight = typeof bottomHeight !== 'undefined' ? bottomHeight : DEFAULT_BORDER_SIZE; | ||
_this.refresh(true); | ||
return _this; | ||
@@ -142,0 +144,0 @@ } |
@@ -63,3 +63,3 @@ 'use strict'; | ||
/** | ||
* Refreshes | ||
* Refreshes plane coordinates | ||
* | ||
@@ -69,3 +69,4 @@ */ | ||
Plane.prototype.refresh = function refresh() { | ||
Plane.prototype._refresh = function _refresh() { | ||
var texture = this._texture; | ||
var total = this.verticesX * this.verticesY; | ||
@@ -76,3 +77,2 @@ var verts = []; | ||
var indices = []; | ||
var texture = this.texture; | ||
@@ -86,13 +86,8 @@ var segmentsX = this.verticesX - 1; | ||
for (var i = 0; i < total; i++) { | ||
if (texture._uvs) { | ||
var x = i % this.verticesX; | ||
var y = i / this.verticesX | 0; | ||
var x = i % this.verticesX; | ||
var y = i / this.verticesX | 0; | ||
verts.push(x * sizeX, y * sizeY); | ||
verts.push(x * sizeX, y * sizeY); | ||
// this works for rectangular textures. | ||
uvs.push(texture._uvs.x0 + (texture._uvs.x1 - texture._uvs.x0) * (x / (this.verticesX - 1)), texture._uvs.y0 + (texture._uvs.y3 - texture._uvs.y0) * (y / (this.verticesY - 1))); | ||
} else { | ||
uvs.push(0); | ||
} | ||
uvs.push(x / segmentsX, y / segmentsY); | ||
} | ||
@@ -122,4 +117,5 @@ | ||
this.indices = new Uint16Array(indices); | ||
this.indexDirty = true; | ||
this.indexDirty = true; | ||
this.multiplyUvs(); | ||
}; | ||
@@ -126,0 +122,0 @@ |
@@ -9,8 +9,2 @@ 'use strict'; | ||
var _core = require('../core'); | ||
var core = _interopRequireWildcard(_core); | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -49,4 +43,6 @@ | ||
/* | ||
* @member {PIXI.Point[]} An array of points that determine the rope | ||
/** | ||
* An array of points that determine the rope | ||
* | ||
* @member {PIXI.Point[]} | ||
*/ | ||
@@ -57,19 +53,27 @@ var _this = _possibleConstructorReturn(this, _Mesh.call(this, texture)); | ||
/* | ||
* @member {Float32Array} An array of vertices used to construct this rope. | ||
/** | ||
* An array of vertices used to construct this rope. | ||
* | ||
* @member {Float32Array} | ||
*/ | ||
_this.vertices = new Float32Array(points.length * 4); | ||
/* | ||
* @member {Float32Array} The WebGL Uvs of the rope. | ||
/** | ||
* The WebGL Uvs of the rope. | ||
* | ||
* @member {Float32Array} | ||
*/ | ||
_this.uvs = new Float32Array(points.length * 4); | ||
/* | ||
* @member {Float32Array} An array containing the color components | ||
/** | ||
* An array containing the color components | ||
* | ||
* @member {Float32Array} | ||
*/ | ||
_this.colors = new Float32Array(points.length * 2); | ||
/* | ||
* @member {Uint16Array} An array containing the indices of the vertices | ||
/** | ||
* An array containing the indices of the vertices | ||
* | ||
* @member {Uint16Array} | ||
*/ | ||
@@ -79,9 +83,7 @@ _this.indices = new Uint16Array(points.length * 2); | ||
/** | ||
* Tracker for if the rope is ready to be drawn. Needed because Mesh ctor can | ||
* call _onTextureUpdated which could call refresh too early. | ||
* | ||
* refreshes vertices on every updateTransform | ||
* @member {boolean} | ||
* @private | ||
* @default true | ||
*/ | ||
_this._ready = true; | ||
_this.autoUpdate = true; | ||
@@ -98,3 +100,3 @@ _this.refresh(); | ||
Rope.prototype.refresh = function refresh() { | ||
Rope.prototype._refresh = function _refresh() { | ||
var points = this.points; | ||
@@ -120,11 +122,7 @@ | ||
var textureUvs = this._texture._uvs; | ||
var offset = new core.Point(textureUvs.x0, textureUvs.y0); | ||
var factor = new core.Point(textureUvs.x2 - textureUvs.x0, Number(textureUvs.y2 - textureUvs.y0)); | ||
uvs[0] = 0; | ||
uvs[1] = 0; | ||
uvs[2] = 0; | ||
uvs[3] = 1; | ||
uvs[0] = 0 + offset.x; | ||
uvs[1] = 0 + offset.y; | ||
uvs[2] = 0 + offset.x; | ||
uvs[3] = factor.y + offset.y; | ||
colors[0] = 1; | ||
@@ -143,7 +141,7 @@ colors[1] = 1; | ||
uvs[index] = amount * factor.x + offset.x; | ||
uvs[index + 1] = 0 + offset.y; | ||
uvs[index] = amount; | ||
uvs[index + 1] = 0; | ||
uvs[index + 2] = amount * factor.x + offset.x; | ||
uvs[index + 3] = factor.y + offset.y; | ||
uvs[index + 2] = amount; | ||
uvs[index + 3] = 1; | ||
@@ -162,28 +160,13 @@ index = i * 2; | ||
this.indexDirty++; | ||
}; | ||
/** | ||
* Clear texture UVs when new texture is set | ||
* | ||
* @private | ||
*/ | ||
Rope.prototype._onTextureUpdate = function _onTextureUpdate() { | ||
_Mesh.prototype._onTextureUpdate.call(this); | ||
// wait for the Rope ctor to finish before calling refresh | ||
if (this._ready) { | ||
this.refresh(); | ||
} | ||
this.multiplyUvs(); | ||
this.refreshVertices(); | ||
}; | ||
/** | ||
* Updates the object transform for rendering | ||
* | ||
* @private | ||
* refreshes vertices of Rope mesh | ||
*/ | ||
Rope.prototype.updateTransform = function updateTransform() { | ||
Rope.prototype.refreshVertices = function refreshVertices() { | ||
var points = this.points; | ||
@@ -240,3 +223,15 @@ | ||
} | ||
}; | ||
/** | ||
* Updates the object transform for rendering | ||
* | ||
* @private | ||
*/ | ||
Rope.prototype.updateTransform = function updateTransform() { | ||
if (this.autoUpdate) { | ||
this.refreshVertices(); | ||
} | ||
this.containerUpdateTransform(); | ||
@@ -243,0 +238,0 @@ }; |
@@ -29,2 +29,4 @@ 'use strict'; | ||
var matrixIdentity = core.Matrix.IDENTITY; | ||
/** | ||
@@ -37,2 +39,3 @@ * WebGL renderer plugin for tiling sprites | ||
*/ | ||
var MeshRenderer = function (_core$ObjectRenderer) { | ||
@@ -65,3 +68,3 @@ _inherits(MeshRenderer, _core$ObjectRenderer); | ||
this.shader = new core.Shader(gl, 'attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\n\nuniform mat3 translationMatrix;\nuniform mat3 projectionMatrix;\n\nvarying vec2 vTextureCoord;\n\nvoid main(void)\n{\n gl_Position = vec4((projectionMatrix * translationMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);\n\n vTextureCoord = aTextureCoord;\n}\n', 'varying vec2 vTextureCoord;\nuniform float alpha;\nuniform vec3 tint;\n\nuniform sampler2D uSampler;\n\nvoid main(void)\n{\n gl_FragColor = texture2D(uSampler, vTextureCoord) * vec4(tint * alpha, alpha);\n}\n'); | ||
this.shader = new core.Shader(gl, 'attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\n\nuniform mat3 projectionMatrix;\nuniform mat3 translationMatrix;\nuniform mat3 uTransform;\n\nvarying vec2 vTextureCoord;\n\nvoid main(void)\n{\n gl_Position = vec4((projectionMatrix * translationMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);\n\n vTextureCoord = (uTransform * vec3(aTextureCoord, 1.0)).xy;\n}\n', 'varying vec2 vTextureCoord;\nuniform float alpha;\nuniform vec3 tint;\n\nuniform sampler2D uSampler;\n\nvoid main(void)\n{\n gl_FragColor = texture2D(uSampler, vTextureCoord) * vec4(tint * alpha, alpha);\n}\n'); | ||
}; | ||
@@ -127,2 +130,9 @@ | ||
if (glData.shader.uniforms.uTransform) { | ||
if (mesh.uploadUvTransform) { | ||
glData.shader.uniforms.uTransform = mesh._uvTransform.mapCoord.toArray(true); | ||
} else { | ||
glData.shader.uniforms.uTransform = matrixIdentity.toArray(true); | ||
} | ||
} | ||
glData.shader.uniforms.translationMatrix = mesh.worldTransform.toArray(true); | ||
@@ -129,0 +139,0 @@ glData.shader.uniforms.alpha = mesh.worldAlpha; |
@@ -300,3 +300,3 @@ 'use strict'; | ||
context.drawImage(child._texture.baseTexture.source, frame.x * resolution, frame.y * resolution, frame.width * resolution, frame.height * resolution, positionX * resolution, positionY * resolution, finalWidth * resolution, finalHeight * resolution); | ||
context.drawImage(child._texture.baseTexture.source, frame.x * resolution, frame.y * resolution, frame.width * resolution, frame.height * resolution, positionX * renderer.resolution, positionY * renderer.resolution, finalWidth * renderer.resolution, finalHeight * renderer.resolution); | ||
} | ||
@@ -303,0 +303,0 @@ }; |
@@ -37,2 +37,14 @@ 'use strict'; | ||
* | ||
* @example | ||
* // Create a sprite | ||
* const sprite = new PIXI.Sprite.fromImage('something.png'); | ||
* | ||
* // Load object into GPU | ||
* app.renderer.plugins.prepare.upload(sprite, () => { | ||
* | ||
* //Texture(s) has been uploaded to GPU | ||
* app.stage.addChild(sprite); | ||
* | ||
* }) | ||
* | ||
* @abstract | ||
@@ -121,4 +133,12 @@ * @class | ||
this.register(findText, drawText); | ||
this.register(findTextStyle, calculateTextStyle); | ||
// hooks to find the correct texture | ||
this.registerFindHook(findText); | ||
this.registerFindHook(findTextStyle); | ||
this.registerFindHook(findMultipleBaseTextures); | ||
this.registerFindHook(findBaseTexture); | ||
this.registerFindHook(findTexture); | ||
// upload hooks | ||
this.registerUploadHook(drawText); | ||
this.registerUploadHook(calculateTextStyle); | ||
} | ||
@@ -156,3 +176,3 @@ | ||
this.ticking = true; | ||
SharedTicker.addOnce(this.tick, this); | ||
SharedTicker.addOnce(this.tick, this, core.UPDATE_PRIORITY.UTILITY); | ||
} | ||
@@ -218,3 +238,3 @@ } else if (done) { | ||
// if we are not finished, on the next rAF do this again | ||
SharedTicker.addOnce(this.tick, this); | ||
SharedTicker.addOnce(this.tick, this, core.UPDATE_PRIORITY.UTILITY); | ||
} | ||
@@ -224,13 +244,11 @@ }; | ||
/** | ||
* Adds hooks for finding and uploading items. | ||
* Adds hooks for finding items. | ||
* | ||
* @param {Function} [addHook] - Function call that takes two parameters: `item:*, queue:Array` | ||
function must return `true` if it was able to add item to the queue. | ||
* @param {Function} [uploadHook] - Function call that takes two parameters: `prepare:CanvasPrepare, item:*` and | ||
* function must return `true` if it was able to handle upload of item. | ||
* @return {PIXI.CanvasPrepare} Instance of plugin for chaining. | ||
* @param {Function} addHook - Function call that takes two parameters: `item:*, queue:Array` | ||
* function must return `true` if it was able to add item to the queue. | ||
* @return {PIXI.BasePrepare} Instance of plugin for chaining. | ||
*/ | ||
BasePrepare.prototype.register = function register(addHook, uploadHook) { | ||
BasePrepare.prototype.registerFindHook = function registerFindHook(addHook) { | ||
if (addHook) { | ||
@@ -240,2 +258,15 @@ this.addHooks.push(addHook); | ||
return this; | ||
}; | ||
/** | ||
* Adds hooks for uploading items. | ||
* | ||
* @param {Function} uploadHook - Function call that takes two parameters: `prepare:CanvasPrepare, item:*` and | ||
* function must return `true` if it was able to handle upload of item. | ||
* @return {PIXI.BasePrepare} Instance of plugin for chaining. | ||
*/ | ||
BasePrepare.prototype.registerUploadHook = function registerUploadHook(uploadHook) { | ||
if (uploadHook) { | ||
@@ -300,2 +331,76 @@ this.uploadHooks.push(uploadHook); | ||
/** | ||
* Built-in hook to find multiple textures from objects like AnimatedSprites. | ||
* | ||
* @private | ||
* @param {PIXI.DisplayObject} item - Display object to check | ||
* @param {Array<*>} queue - Collection of items to upload | ||
* @return {boolean} if a PIXI.Texture object was found. | ||
*/ | ||
exports.default = BasePrepare; | ||
function findMultipleBaseTextures(item, queue) { | ||
var result = false; | ||
// Objects with mutliple textures | ||
if (item && item._textures && item._textures.length) { | ||
for (var i = 0; i < item._textures.length; i++) { | ||
if (item._textures[i] instanceof core.Texture) { | ||
var baseTexture = item._textures[i].baseTexture; | ||
if (queue.indexOf(baseTexture) === -1) { | ||
queue.push(baseTexture); | ||
result = true; | ||
} | ||
} | ||
} | ||
} | ||
return result; | ||
} | ||
/** | ||
* Built-in hook to find BaseTextures from Sprites. | ||
* | ||
* @private | ||
* @param {PIXI.DisplayObject} item - Display object to check | ||
* @param {Array<*>} queue - Collection of items to upload | ||
* @return {boolean} if a PIXI.Texture object was found. | ||
*/ | ||
function findBaseTexture(item, queue) { | ||
// Objects with textures, like Sprites/Text | ||
if (item instanceof core.BaseTexture) { | ||
if (queue.indexOf(item) === -1) { | ||
queue.push(item); | ||
} | ||
return true; | ||
} | ||
return false; | ||
} | ||
/** | ||
* Built-in hook to find textures from objects. | ||
* | ||
* @private | ||
* @param {PIXI.DisplayObject} item - Display object to check | ||
* @param {Array<*>} queue - Collection of items to upload | ||
* @return {boolean} if a PIXI.Texture object was found. | ||
*/ | ||
function findTexture(item, queue) { | ||
if (item._texture && item._texture instanceof core.Texture) { | ||
var texture = item._texture.baseTexture; | ||
if (queue.indexOf(texture) === -1) { | ||
queue.push(texture); | ||
} | ||
return true; | ||
} | ||
return false; | ||
} | ||
/** | ||
* Built-in hook to draw PIXI.Text to its texture. | ||
@@ -308,5 +413,2 @@ * | ||
*/ | ||
exports.default = BasePrepare; | ||
function drawText(helper, item) { | ||
@@ -313,0 +415,0 @@ if (item instanceof core.Text) { |
@@ -68,3 +68,3 @@ 'use strict'; | ||
// Add textures to upload | ||
_this.register(findBaseTextures, uploadBaseTextures); | ||
_this.registerUploadHook(uploadBaseTextures); | ||
return _this; | ||
@@ -119,32 +119,3 @@ } | ||
/** | ||
* Built-in hook to find textures from Sprites. | ||
* | ||
* @private | ||
* @param {PIXI.DisplayObject} item -Display object to check | ||
* @param {Array<*>} queue - Collection of items to upload | ||
* @return {boolean} if a PIXI.Texture object was found. | ||
*/ | ||
function findBaseTextures(item, queue) { | ||
// Objects with textures, like Sprites/Text | ||
if (item instanceof core.BaseTexture) { | ||
if (queue.indexOf(item) === -1) { | ||
queue.push(item); | ||
} | ||
return true; | ||
} else if (item._texture && item._texture instanceof core.Texture) { | ||
var texture = item._texture.baseTexture; | ||
if (queue.indexOf(texture) === -1) { | ||
queue.push(texture); | ||
} | ||
return true; | ||
} | ||
return false; | ||
} | ||
core.CanvasRenderer.registerPlugin('prepare', CanvasPrepare); | ||
//# sourceMappingURL=CanvasPrepare.js.map |
@@ -46,3 +46,5 @@ 'use strict'; | ||
// Add textures and graphics to upload | ||
_this.register(findBaseTextures, uploadBaseTextures).register(findGraphics, uploadGraphics); | ||
_this.registerFindHook(findGraphics); | ||
_this.registerUploadHook(uploadBaseTextures); | ||
_this.registerUploadHook(uploadGraphics); | ||
return _this; | ||
@@ -53,3 +55,2 @@ } | ||
}(_BasePrepare3.default); | ||
/** | ||
@@ -104,31 +105,2 @@ * Built-in hook to upload PIXI.Texture objects to the GPU. | ||
/** | ||
* Built-in hook to find textures from Sprites. | ||
* | ||
* @private | ||
* @param {PIXI.DisplayObject} item - Display object to check | ||
* @param {Array<*>} queue - Collection of items to upload | ||
* @return {boolean} if a PIXI.Texture object was found. | ||
*/ | ||
function findBaseTextures(item, queue) { | ||
// Objects with textures, like Sprites/Text | ||
if (item instanceof core.BaseTexture) { | ||
if (queue.indexOf(item) === -1) { | ||
queue.push(item); | ||
} | ||
return true; | ||
} else if (item._texture && item._texture instanceof core.Texture) { | ||
var texture = item._texture.baseTexture; | ||
if (queue.indexOf(texture) === -1) { | ||
queue.push(texture); | ||
} | ||
return true; | ||
} | ||
return false; | ||
} | ||
/** | ||
* Built-in hook to find graphics. | ||
@@ -135,0 +107,0 @@ * |
{ | ||
"name": "pixi.js", | ||
"version": "4.4.4", | ||
"version": "4.5.0", | ||
"description": "Pixi.js is a fast lightweight 2D library that works across all devices.", | ||
@@ -43,7 +43,7 @@ "author": "Mat Groves", | ||
"docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md", | ||
"publish:patch": "npm version patch --no-git-tag-version && npm publish", | ||
"publish:minor": "npm version minor --no-git-tag-version && npm publish", | ||
"publish:major": "npm version major --no-git-tag-version && npm publish", | ||
"publish:patch": "npm version patch && npm publish", | ||
"publish:minor": "npm version minor && npm publish", | ||
"publish:major": "npm version major && npm publish", | ||
"postversion": "npm run clean && npm run build && npm run lib && npm test", | ||
"postpublish": "node scripts/release.js" | ||
"postpublish": "git push && git push --tags" | ||
}, | ||
@@ -77,3 +77,2 @@ "files": [ | ||
"floss": "^2.0.1", | ||
"gh-pages": "^0.11.0", | ||
"jaguarjs-jsdoc": "^1.0.1", | ||
@@ -80,0 +79,0 @@ "js-md5": "^0.4.1", |
@@ -39,3 +39,3 @@ Pixi.js — A 2D JavaScript Renderer | ||
### Community ### | ||
- Forums: Check out the [forum] (http://www.html5gamedevs.com/forum/15-pixijs/) and [Stackoverflow] (http://stackoverflow.com/search?q=pixi.js), both friendly places to ask your pixi questions. | ||
- Forums: Check out the [forum](http://www.html5gamedevs.com/forum/15-pixijs/) and [Stackoverflow](http://stackoverflow.com/search?q=pixi.js), both friendly places to ask your pixi questions. | ||
- Inspiration: Check out the [gallery](http://www.pixijs.com/gallery) to see some of the amazing things people have created! | ||
@@ -47,12 +47,4 @@ - Chat: You can join us on [Gitter](https://gitter.im/pixijs/pixi.js) To chat about Pixi. We also now have a Slack channel. If you would like to join it please Send me an email (mat@goodboydigital.com) and I will invite you in. | ||
It's easy to get started with Pixi.js! Simply grab the pre-built versions from here: | ||
It's easy to get started with Pixi.js! Simply download a [prebuilt build](https://github.com/pixijs/pixi.js/wiki/FAQs#where-can-i-get-a-build)! | ||
Release Branch - Nice and stable Pixi.js | ||
- Unminified: [http://pixijs.download/release/pixi.js] | ||
- Minified: [http://pixijs.download/release/pixi.min.js] | ||
Develop Branch - The bleeding edge version of Pixi.js | ||
- Unminified: [http://pixijs.download/dev/pixi.js] | ||
- Minified: [http://pixijs.download/dev/pixi.min.js] | ||
Alternatively, Pixi.js can be installed with [Bower](https://bower.io/#getting-started), [npm](https://docs.npmjs.com/getting-started/what-is-npm) or simply using a content delivery network (CDN) URL to embed Pixi.js directly on your HTML page. | ||
@@ -75,6 +67,6 @@ | ||
```html | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/pixi.js/4.2.2/pixi.min.js"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/pixi.js/4.4.3/pixi.min.js"></script> | ||
``` | ||
_Note: `4.2.2` can be replaced by any [released](https://github.com/pixijs/pixi.js/releases) version._ | ||
_Note: `4.4.3` can be replaced by any [released](https://github.com/pixijs/pixi.js/releases) version._ | ||
@@ -136,3 +128,3 @@ ### Demos ### | ||
// The application will create a canvas element for you that you | ||
// The application will create a canvas element for you that you | ||
// can then insert into the DOM. | ||
@@ -157,3 +149,3 @@ document.body.appendChild(app.view); | ||
app.stage.addChild(bunny); | ||
// Listen for frame updates | ||
@@ -160,0 +152,0 @@ app.ticker.add(function() { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7200267
18
308
57947
203