1 /**
  2  * The Render Engine
  3  * Image
  4  *
  5  * @fileoverview An image resource
  6  *
  7  * @author: Brett Fattori (brettf@renderengine.com)
  8  * @author: $Author: bfattori $
  9  * @version: $Revision: 1555 $
 10  *
 11  * Copyright (c) 2011 Brett Fattori (brettf@renderengine.com)
 12  *
 13  * Permission is hereby granted, free of charge, to any person obtaining a copy
 14  * of this software and associated documentation files (the "Software"), to deal
 15  * in the Software without restriction, including without limitation the rights
 16  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 17  * copies of the Software, and to permit persons to whom the Software is
 18  * furnished to do so, subject to the following conditions:
 19  *
 20  * The above copyright notice and this permission notice shall be included in
 21  * all copies or substantial portions of the Software.
 22  *
 23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 24  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 25  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 26  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 27  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 28  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 29  * THE SOFTWARE.
 30  *
 31  */
 32 
 33 // The class this file defines and its required classes
 34 R.Engine.define({
 35     "class":"R.resources.types.Image",
 36     "requires":[
 37         "R.engine.PooledObject",
 38         "R.math.Rectangle2D"
 39     ]
 40 });
 41 
 42 /**
 43  * @class A wrapper class for images.  Images contain a reference to their resource
 44  *          loader and the bitmap dimensions for the image.  Additionally, the dimensions
 45  *          are used to determine the bounding box around the image.
 46  *
 47  * @constructor
 48  * @param name {String} The name of the image object
 49  * @param imageName {String} The name of the image container in the resource loader
 50  * @param imageLoader {ImageLoader} The resource loader used to load the image
 51  * @extends R.engine.PooledObject
 52  */
 53 R.resources.types.Image = function () {
 54     return R.engine.PooledObject.extend(/** @scope R.resources.types.Image.prototype */{
 55 
 56         image:null,
 57 
 58         /** @private */
 59         constructor:function (name, imageName, imageLoader) {
 60             this.base(name || "Image");
 61             this.image = imageLoader.get(imageName);
 62             var dims = imageLoader.getDimensions(imageName);
 63             this.bbox = R.math.Rectangle2D.create(0, 0, dims.x, dims.y);
 64         },
 65 
 66         /**
 67          * Release the image back into the pool for reuse
 68          */
 69         release:function () {
 70             this.base();
 71             this.image = null;
 72             this.bbox = null;
 73         },
 74 
 75         /**
 76          * Get the bounding box for the image.
 77          * @return {R.math.Rectangle2D} The bounding box which contains the entire image
 78          */
 79         getBoundingBox:function () {
 80             return this.bbox;
 81         },
 82 
 83         /**
 84          * Get the HTML image object which contains the image.
 85          * @return {HTMLImage}
 86          */
 87         getImage:function () {
 88             return this.image;
 89         }
 90 
 91     }, /** @scope R.resources.types.Image.prototype */{
 92         /**
 93          * Gets the class name of this object.
 94          * @return {String} The string "R.resources.types.Image"
 95          */
 96         getClassName:function () {
 97             return "R.resources.types.Image";
 98         }
 99 
100     });
101 
102 }