diff --git a/src/pixi/primitives/Graphics.js b/src/pixi/primitives/Graphics.js index 948e351..91a44ea 100644 --- a/src/pixi/primitives/Graphics.js +++ b/src/pixi/primitives/Graphics.js @@ -57,7 +57,7 @@ * @default 0xFFFFFF */ this.tint = 0xFFFFFF; - + /** * The blend mode to be applied to the graphic shape. Apply a value of PIXI.blendModes.NORMAL to reset the blend mode. * @@ -638,7 +638,7 @@ * * @method generateTexture * @param resolution {Number} The resolution of the texture being generated - * @param scaleMode {Number} See {{#crossLink "PIXI/scaleModes:property"}}PIXI.scaleModes{{/crossLink}} for possible values + * @param scaleMode {Number} Should be one of the PIXI.scaleMode consts * @return {Texture} a texture of the graphics object */ PIXI.Graphics.prototype.generateTexture = function(resolution, scaleMode) @@ -1109,9 +1109,11 @@ this.lineWidth = lineWidth; this.lineColor = lineColor; this.lineAlpha = lineAlpha; + this._lineTint = lineColor; this.fillColor = fillColor; this.fillAlpha = fillAlpha; + this._fillTint = fillColor; this.fill = fill; this.shape = shape; diff --git a/src/pixi/primitives/Graphics.js b/src/pixi/primitives/Graphics.js index 948e351..91a44ea 100644 --- a/src/pixi/primitives/Graphics.js +++ b/src/pixi/primitives/Graphics.js @@ -57,7 +57,7 @@ * @default 0xFFFFFF */ this.tint = 0xFFFFFF; - + /** * The blend mode to be applied to the graphic shape. Apply a value of PIXI.blendModes.NORMAL to reset the blend mode. * @@ -638,7 +638,7 @@ * * @method generateTexture * @param resolution {Number} The resolution of the texture being generated - * @param scaleMode {Number} See {{#crossLink "PIXI/scaleModes:property"}}PIXI.scaleModes{{/crossLink}} for possible values + * @param scaleMode {Number} Should be one of the PIXI.scaleMode consts * @return {Texture} a texture of the graphics object */ PIXI.Graphics.prototype.generateTexture = function(resolution, scaleMode) @@ -1109,9 +1109,11 @@ this.lineWidth = lineWidth; this.lineColor = lineColor; this.lineAlpha = lineAlpha; + this._lineTint = lineColor; this.fillColor = fillColor; this.fillAlpha = fillAlpha; + this._fillTint = fillColor; this.fill = fill; this.shape = shape; diff --git a/src/pixi/renderers/canvas/CanvasGraphics.js b/src/pixi/renderers/canvas/CanvasGraphics.js index 632e23f..97224d6 100644 --- a/src/pixi/renderers/canvas/CanvasGraphics.js +++ b/src/pixi/renderers/canvas/CanvasGraphics.js @@ -24,14 +24,21 @@ PIXI.CanvasGraphics.renderGraphics = function(graphics, context) { var worldAlpha = graphics.worldAlpha; - var color = ''; + + if(graphics.dirty) + { + this.updateGraphicsTint(graphics); + graphics.dirty = false; + } + for (var i = 0; i < graphics.graphicsData.length; i++) { var data = graphics.graphicsData[i]; var shape = data.shape; - context.strokeStyle = color = '#' + ('00000' + ( data.lineColor | 0).toString(16)).substr(-6); + var fillColor = data._fillTint; + var lineColor = data._lineTint; context.lineWidth = data.lineWidth; @@ -62,12 +69,13 @@ if(data.fill) { context.globalAlpha = data.fillAlpha * worldAlpha; - context.fillStyle = color = '#' + ('00000' + ( data.fillColor | 0).toString(16)).substr(-6); + context.fillStyle = '#' + ('00000' + ( fillColor | 0).toString(16)).substr(-6); context.fill(); } if(data.lineWidth) { context.globalAlpha = data.lineAlpha * worldAlpha; + context.strokeStyle = '#' + ('00000' + ( lineColor | 0).toString(16)).substr(-6); context.stroke(); } } @@ -77,13 +85,14 @@ if(data.fillColor || data.fillColor === 0) { context.globalAlpha = data.fillAlpha * worldAlpha; - context.fillStyle = color = '#' + ('00000' + ( data.fillColor | 0).toString(16)).substr(-6); - context.fillRect(shape.x, shape.y, shape.width, shape.height); + context.fillStyle = '#' + ('00000' + ( fillColor | 0).toString(16)).substr(-6); + context.colorRect(shape.x, shape.y, shape.width, shape.height); } if(data.lineWidth) { context.globalAlpha = data.lineAlpha * worldAlpha; + context.strokeStyle = '#' + ('00000' + ( lineColor | 0).toString(16)).substr(-6); context.strokeRect(shape.x, shape.y, shape.width, shape.height); } } @@ -97,12 +106,13 @@ if(data.fill) { context.globalAlpha = data.fillAlpha * worldAlpha; - context.fillStyle = color = '#' + ('00000' + ( data.fillColor | 0).toString(16)).substr(-6); + context.fillStyle = '#' + ('00000' + ( fillColor | 0).toString(16)).substr(-6); context.fill(); } if(data.lineWidth) { context.globalAlpha = data.lineAlpha * worldAlpha; + context.strokeStyle = '#' + ('00000' + ( lineColor | 0).toString(16)).substr(-6); context.stroke(); } } @@ -137,12 +147,13 @@ if(data.fill) { context.globalAlpha = data.fillAlpha * worldAlpha; - context.fillStyle = color = '#' + ('00000' + ( data.fillColor | 0).toString(16)).substr(-6); + context.fillStyle = '#' + ('00000' + ( fillColor | 0).toString(16)).substr(-6); context.fill(); } if(data.lineWidth) { context.globalAlpha = data.lineAlpha * worldAlpha; + context.strokeStyle = '#' + ('00000' + ( lineColor | 0).toString(16)).substr(-6); context.stroke(); } } @@ -172,13 +183,14 @@ if(data.fillColor || data.fillColor === 0) { context.globalAlpha = data.fillAlpha * worldAlpha; - context.fillStyle = color = '#' + ('00000' + ( data.fillColor | 0).toString(16)).substr(-6); + context.fillStyle = '#' + ('00000' + ( fillColor | 0).toString(16)).substr(-6); context.fill(); } if(data.lineWidth) { context.globalAlpha = data.lineAlpha * worldAlpha; + context.strokeStyle = '#' + ('00000' + ( lineColor | 0).toString(16)).substr(-6); context.stroke(); } } @@ -299,3 +311,48 @@ } } }; + +PIXI.CanvasGraphics.updateGraphicsTint = function(graphics) +{ + if(graphics.tint === 0xFFFFFF)return; + + var tintR = (graphics.tint >> 16 & 0xFF) / 255; + var tintG = (graphics.tint >> 8 & 0xFF) / 255; + var tintB = (graphics.tint & 0xFF)/ 255; + + for (var i = 0; i < graphics.graphicsData.length; i++) + { + var data = graphics.graphicsData[i]; + + var fillColor = data.fillColor | 0; + var lineColor = data.lineColor | 0; + + /* + var colorR = (fillColor >> 16 & 0xFF) / 255; + var colorG = (fillColor >> 8 & 0xFF) / 255; + var colorB = (fillColor & 0xFF) / 255; + + colorR *= tintR; + colorG *= tintG; + colorB *= tintB; + + fillColor = ((colorR*255 << 16) + (colorG*255 << 8) + colorB*255); + + colorR = (lineColor >> 16 & 0xFF) / 255; + colorG = (lineColor >> 8 & 0xFF) / 255; + colorB = (lineColor & 0xFF) / 255; + + colorR *= tintR; + colorG *= tintG; + colorB *= tintB; + + lineColor = ((colorR*255 << 16) + (colorG*255 << 8) + colorB*255); + */ + + // super inline cos im an optimization NAZI :) + data._fillTint = (((fillColor >> 16 & 0xFF) / 255 * tintR*255 << 16) + ((fillColor >> 8 & 0xFF) / 255 * tintG*255 << 8) + (fillColor & 0xFF) / 255 * tintB*255); + data._lineTint = (((lineColor >> 16 & 0xFF) / 255 * tintR*255 << 16) + ((lineColor >> 8 & 0xFF) / 255 * tintG*255 << 8) + (lineColor & 0xFF) / 255 * tintB*255); + + } +}; +