1 /**
  2 * Bitmap by Grant Skinner. Dec 5, 2010
  3 * Visit www.gskinner.com/blog for documentation, updates and more free code.
  4 *
  5 *
  6 * Copyright (c) 2010 Grant Skinner
  7 * 
  8 * Permission is hereby granted, free of charge, to any person
  9 * obtaining a copy of this software and associated documentation
 10 * files (the "Software"), to deal in the Software without
 11 * restriction, including without limitation the rights to use,
 12 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 13 * copies of the Software, and to permit persons to whom the
 14 * Software is furnished to do so, subject to the following
 15 * conditions:
 16 * 
 17 * The above copyright notice and this permission notice shall be
 18 * included in all copies or substantial portions of the Software.
 19 * 
 20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 21 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 22 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 23 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 24 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 25 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 26 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 27 * OTHER DEALINGS IN THE SOFTWARE.
 28 **/
 29 
 30 
 31 
 32 /**
 33 * Constructs a Bitmap object with the specified source image.
 34 * @param image The Image, Canvas, or Video to render to the display list.
 35 * @class A Bitmap represents an Image, Canvas, or Video in the display list.
 36 * @augments DisplayObject
 37 **/
 38 function Bitmap(image) {
 39   this.init(image);
 40 this.prototype = new DisplayObject();
 41 
 42 // public properties:
 43 	/** The image to render. This can be an Image, a Canvas, or a Video. **/
 44 	this.image = null;
 45 	
 46 // constructor:
 47 	/** @private **/
 48 	this._init = this.init;
 49 	/** @private **/
 50 	this.init = function(image) {
 51 		this._init();
 52 		this.image = image;
 53 	}
 54 	
 55 // public methods:
 56 	/** @borrows DisplayObject#draw as this.draw **/
 57 	this._draw = this.draw;
 58 	this.draw = function(ctx,ignoreCache) {
 59 		if (this.image == null || !this.image.complete) { return false; }
 60 		if (!this._draw(ctx,ignoreCache)) { return false; }
 61 		ctx.drawImage(this.image,0,0);
 62 	}
 63 	
 64 	/**
 65 	* Because the content of a Bitmap is already in a simple format, cache is unnecessary for Bitmap instances.
 66 	**/
 67 	this.cache = function() {}
 68 	
 69 	/**
 70 	* Because the content of a Bitmap is already in a simple format, cache is unnecessary for Bitmap instances.
 71 	**/
 72 	this.uncache = function() {}
 73 	
 74 	this.clone = function() {
 75 		var o = new Bitmap(this.image);
 76 		this.cloneProps(o);
 77 		return o;
 78 	}
 79 	
 80 	this.toString = function() {
 81 		return "[Bitmap (name="+  this.name +")]";
 82 	}
 83 }