diff --git a/src/core/const.js b/src/core/const.js index 48c0f8a..22acb9a 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -178,7 +178,7 @@ * The DEFAULT Garbage Collection mode for pixi textures is MANUAL * If set to DEFAULT, the renderer will occasianally check textures usage. If they are not used for a specified period of time they will be removed from the GPU. * They will of corse be uploaded again when they are required. This is a silent behind the scenes process that should ensure that the GPU does not get filled up. - * Handy for mobile devices! + * Handy for mobile devices! * This property only affects WebGL * @static * @constant @@ -215,7 +215,7 @@ RESOLUTION:1, FILTER_RESOLUTION:1, - + /** * The default render options if none are supplied to {@link PIXI.WebGLRenderer} * or {@link PIXI.CanvasRenderer}. @@ -269,7 +269,8 @@ // TODO: maybe change to SPRITE.BATCH_SIZE: 2000 // TODO: maybe add PARTICLE.BATCH_SIZE: 15000 SPRITE_BATCH_SIZE: 4096, //nice balance between mobile and desktop machines - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32)//this is the MAXIMUM - various gpus will have there own limits. + SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32), //this is the MAXIMUM - various gpus will have there own limits. + TEXT_STYLE_CHANGED: 'changed' // }; module.exports = CONST; diff --git a/src/core/const.js b/src/core/const.js index 48c0f8a..22acb9a 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -178,7 +178,7 @@ * The DEFAULT Garbage Collection mode for pixi textures is MANUAL * If set to DEFAULT, the renderer will occasianally check textures usage. If they are not used for a specified period of time they will be removed from the GPU. * They will of corse be uploaded again when they are required. This is a silent behind the scenes process that should ensure that the GPU does not get filled up. - * Handy for mobile devices! + * Handy for mobile devices! * This property only affects WebGL * @static * @constant @@ -215,7 +215,7 @@ RESOLUTION:1, FILTER_RESOLUTION:1, - + /** * The default render options if none are supplied to {@link PIXI.WebGLRenderer} * or {@link PIXI.CanvasRenderer}. @@ -269,7 +269,8 @@ // TODO: maybe change to SPRITE.BATCH_SIZE: 2000 // TODO: maybe add PARTICLE.BATCH_SIZE: 15000 SPRITE_BATCH_SIZE: 4096, //nice balance between mobile and desktop machines - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32)//this is the MAXIMUM - various gpus will have there own limits. + SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32), //this is the MAXIMUM - various gpus will have there own limits. + TEXT_STYLE_CHANGED: 'changed' // }; module.exports = CONST; diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 6a6d59b..7643ea1 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -142,6 +142,10 @@ }, set: function (style) { + if (this._style) { + this._style.removeListener(this._styleListener); + } + style = style || {}; if (style instanceof TextStyle) { @@ -150,7 +154,7 @@ { this._style = new TextStyle(style); } - this._styleListener = this._style.on('styleChanged', function () + this._styleListener = this._style.on(CONST.TEXT_STYLE_CHANGED, function () { this.dirty = true; }.bind(this)); diff --git a/src/core/const.js b/src/core/const.js index 48c0f8a..22acb9a 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -178,7 +178,7 @@ * The DEFAULT Garbage Collection mode for pixi textures is MANUAL * If set to DEFAULT, the renderer will occasianally check textures usage. If they are not used for a specified period of time they will be removed from the GPU. * They will of corse be uploaded again when they are required. This is a silent behind the scenes process that should ensure that the GPU does not get filled up. - * Handy for mobile devices! + * Handy for mobile devices! * This property only affects WebGL * @static * @constant @@ -215,7 +215,7 @@ RESOLUTION:1, FILTER_RESOLUTION:1, - + /** * The default render options if none are supplied to {@link PIXI.WebGLRenderer} * or {@link PIXI.CanvasRenderer}. @@ -269,7 +269,8 @@ // TODO: maybe change to SPRITE.BATCH_SIZE: 2000 // TODO: maybe add PARTICLE.BATCH_SIZE: 15000 SPRITE_BATCH_SIZE: 4096, //nice balance between mobile and desktop machines - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32)//this is the MAXIMUM - various gpus will have there own limits. + SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32), //this is the MAXIMUM - various gpus will have there own limits. + TEXT_STYLE_CHANGED: 'changed' // }; module.exports = CONST; diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 6a6d59b..7643ea1 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -142,6 +142,10 @@ }, set: function (style) { + if (this._style) { + this._style.removeListener(this._styleListener); + } + style = style || {}; if (style instanceof TextStyle) { @@ -150,7 +154,7 @@ { this._style = new TextStyle(style); } - this._styleListener = this._style.on('styleChanged', function () + this._styleListener = this._style.on(CONST.TEXT_STYLE_CHANGED, function () { this.dirty = true; }.bind(this)); diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index c05000d..444bc32 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,4 +1,5 @@ var EventEmitter = require('eventemitter3'), + CONST = require('../const'), utils = require('../utils'); /** @@ -82,6 +83,17 @@ }; /** + * Resets all properties to the defaults specified in TextStyle.prototype._default + */ +TextStyle.prototype.reset = function () +{ + for (var property in this._defaults) + { + this[property] = this._defaults[property]; + } +}; + +/** * Create setters and getters for each of the style properties. Converts colors where necessary. * Any set operation will emit a styleChanged event. */ @@ -95,7 +107,7 @@ if (this._font !== font) { this._font = font; - this.emit('styleChanged'); + this.emit(CONST.TEXT_STYLE_CHANGED); } } }, @@ -109,7 +121,7 @@ if (this._fill !== outputColor) { this._fill = outputColor; - this.emit('styleChanged'); + this.emit(CONST.TEXT_STYLE_CHANGED); } } }, @@ -122,7 +134,7 @@ if (this._align !== align) { this._align = align; - this.emit('styleChanged'); + this.emit(CONST.TEXT_STYLE_CHANGED); } } }, @@ -136,7 +148,7 @@ if (this._stroke !== outputColor) { this._stroke = outputColor; - this.emit('styleChanged'); + this.emit(CONST.TEXT_STYLE_CHANGED); } } }, @@ -149,7 +161,7 @@ if (this._strokeThickness !== strokeThickness) { this._strokeThickness = strokeThickness; - this.emit('styleChanged'); + this.emit(CONST.TEXT_STYLE_CHANGED); } } }, @@ -162,7 +174,7 @@ if (this._wordWrap !== wordWrap) { this._wordWrap = wordWrap; - this.emit('styleChanged'); + this.emit(CONST.TEXT_STYLE_CHANGED); } } }, @@ -175,7 +187,7 @@ if (this._wordWrapWidth !== wordWrapWidth) { this._wordWrapWidth = wordWrapWidth; - this.emit('styleChanged'); + this.emit(CONST.TEXT_STYLE_CHANGED); } } }, @@ -188,7 +200,7 @@ if (this._dropShadow !== dropShadow) { this._dropShadow = dropShadow; - this.emit('styleChanged'); + this.emit(CONST.TEXT_STYLE_CHANGED); } } }, @@ -202,7 +214,7 @@ if (this._dropShadowColor !== outputColor) { this._dropShadowColor = outputColor; - this.emit('styleChanged'); + this.emit(CONST.TEXT_STYLE_CHANGED); } } }, @@ -215,7 +227,7 @@ if (this._dropShadowAngle !== dropShadowAngle) { this._dropShadowAngle = dropShadowAngle; - this.emit('styleChanged'); + this.emit(CONST.TEXT_STYLE_CHANGED); } } }, @@ -228,7 +240,7 @@ if (this._dropShadowDistance !== dropShadowDistance) { this._dropShadowDistance = dropShadowDistance; - this.emit('styleChanged'); + this.emit(CONST.TEXT_STYLE_CHANGED); } } }, @@ -241,7 +253,7 @@ if (this._dropShadowBlur !== dropShadowBlur) { this._dropShadowBlur = dropShadowBlur; - this.emit('styleChanged'); + this.emit(CONST.TEXT_STYLE_CHANGED); } } }, @@ -254,7 +266,7 @@ if (this._padding !== padding) { this._padding = padding; - this.emit('styleChanged'); + this.emit(CONST.TEXT_STYLE_CHANGED); } } }, @@ -267,7 +279,7 @@ if (this._textBaseline !== textBaseline) { this._textBaseline = textBaseline; - this.emit('styleChanged'); + this.emit(CONST.TEXT_STYLE_CHANGED); } } }, @@ -280,7 +292,7 @@ if (this._lineJoin !== lineJoin) { this._lineJoin = lineJoin; - this.emit('styleChanged'); + this.emit(CONST.TEXT_STYLE_CHANGED); } } }, @@ -293,7 +305,7 @@ if (this._lineHeight !== lineHeight) { this._lineHeight = lineHeight; - this.emit('styleChanged'); + this.emit(CONST.TEXT_STYLE_CHANGED); } } }, @@ -306,7 +318,7 @@ if (this._miterLimit !== miterLimit) { this._miterLimit = miterLimit; - this.emit('styleChanged'); + this.emit(CONST.TEXT_STYLE_CHANGED); } } }