diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index 40d434c..2b2a553 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -90,3 +90,42 @@ return false; }; + +Rectangle.prototype.pad = function (paddingX, paddingY) +{ + paddingX = paddingX || 0; + paddingY = paddingY || ( (paddingY !== 0) ? paddingX : 0 ); + + this.x -= paddingX; + this.y -= paddingY; + + this.width += paddingX * 2; + this.height += paddingY * 2; +} + + +Rectangle.prototype.fit = function (rectangle) +{ + if (this.x < rectangle.x) + { + this.width += this.x; + this.x = rectangle.x; + } + + if (this.y < rectangle.y) + { + this.height += this.y; + this.y = rectangle.y; + } + + if ( this.x + this.width > rectangle.width ) + { + this.width = rectangle.width - this.x; + } + + if ( this.y + this.height > rectangle.height ) + { + this.height = rectangle.height - this.y; + } +} + diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index 40d434c..2b2a553 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -90,3 +90,42 @@ return false; }; + +Rectangle.prototype.pad = function (paddingX, paddingY) +{ + paddingX = paddingX || 0; + paddingY = paddingY || ( (paddingY !== 0) ? paddingX : 0 ); + + this.x -= paddingX; + this.y -= paddingY; + + this.width += paddingX * 2; + this.height += paddingY * 2; +} + + +Rectangle.prototype.fit = function (rectangle) +{ + if (this.x < rectangle.x) + { + this.width += this.x; + this.x = rectangle.x; + } + + if (this.y < rectangle.y) + { + this.height += this.y; + this.y = rectangle.y; + } + + if ( this.x + this.width > rectangle.width ) + { + this.width = rectangle.width - this.x; + } + + if ( this.y + this.height > rectangle.height ) + { + this.height = rectangle.height - this.y; + } +} + diff --git a/src/core/renderers/webgl/managers/FilterManagerRoundTwo.js b/src/core/renderers/webgl/managers/FilterManagerRoundTwo.js index 50766fd..efa8173 100644 --- a/src/core/renderers/webgl/managers/FilterManagerRoundTwo.js +++ b/src/core/renderers/webgl/managers/FilterManagerRoundTwo.js @@ -28,6 +28,7 @@ this.stack = []; this.stackIndex = -1; + // todo add default! } FilterManager.prototype = Object.create(WebGLManager.prototype); @@ -36,7 +37,10 @@ FilterManager.prototype.pushFilter = function(target, filters) { + var bounds = target.getBounds(); + bounds.pad(4); + bounds.fit(new PIXI.Rectangle(0,0,800, 800)) //TODO - output.size? var renderTarget = FilterManager.getPotRenderTarget(this.renderer.gl, bounds.width, bounds.height);