1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
/**
* @author Mat Groves http://matgroves.com/ @Doormat23
*/
/**
* Creates a Canvas element of the given size.
*
* @class CanvasBuffer
* @constructor
* @param width {Number} the width for the newly created canvas
* @param height {Number} the height for the newly created canvas
*/
PIXI.CanvasBuffer = function(width, height)
{
/**
* The width of the Canvas in pixels.
*
* @property width
* @type Number
*/
this.width = width;
/**
* The height of the Canvas in pixels.
*
* @property height
* @type Number
*/
this.height = height;
/**
* The Canvas object that belongs to this CanvasBuffer.
*
* @property canvas
* @type HTMLCanvasElement
*/
this.canvas = PIXI.CanvasPool.create(this, this.width, this.height);
/**
* A CanvasRenderingContext2D object representing a two-dimensional rendering context.
*
* @property context
* @type CanvasRenderingContext2D
*/
this.context = this.canvas.getContext("2d");
this.canvas.width = width;
this.canvas.height = height;
};
PIXI.CanvasBuffer.prototype.constructor = PIXI.CanvasBuffer;
/**
* Clears the canvas that was created by the CanvasBuffer class.
*
* @method clear
* @private
*/
PIXI.CanvasBuffer.prototype.clear = function()
{
this.context.setTransform(1, 0, 0, 1, 0, 0);
this.context.clearRect(0,0, this.width, this.height);
};
/**
* Resizes the canvas to the specified width and height.
*
* @method resize
* @param width {Number} the new width of the canvas
* @param height {Number} the new height of the canvas
*/
PIXI.CanvasBuffer.prototype.resize = function(width, height)
{
this.width = this.canvas.width = width;
this.height = this.canvas.height = height;
};
/**
* Frees the canvas up for use again.
*
* @method destroy
*/
PIXI.CanvasBuffer.prototype.destroy = function()
{
PIXI.CanvasPool.remove(this);
};