1 /**
  2  * Hilo
  3  * Copyright 2015 alibaba.com
  4  * Licensed under the MIT License
  5  */
  6 
  7 /**
  8  * @language=en
  9  * <iframe src='../../../examples/Bitmap.html?noHeader' width = '300' height = '200' scrolling='no'></iframe>
 10  * <br/>
 11  * Example:
 12  * <pre>
 13  * var bmp = new Hilo.Bitmap({image:imgElem, rect:[0, 0, 100, 100]});
 14  * stage.addChild(bmp);
 15  * </pre>
 16  * @class Bitmap
 17  * @augments View
 18  * @param {Object} properties the options of create Instance.It can contains all writable property and Moreover:
 19  * <ul>
 20  * <li><b>image</b> - the image of bitmap which contained。required。</li>
 21  * <li><b>rect</b> - the range of bitmap in the image。option</li>
 22  * </ul>
 23  * @module hilo/view/Bitmap
 24  * @requires hilo/core/Hilo
 25  * @requires hilo/core/Class
 26  * @requires hilo/view/View
 27  * @requires hilo/view/Drawable
 28  */
 29  var Bitmap = Class.create(/** @lends Bitmap.prototype */{
 30     Extends: View,
 31     constructor: function(properties){
 32         properties = properties || {};
 33         this.id = this.id || properties.id || Hilo.getUid("Bitmap");
 34         Bitmap.superclass.constructor.call(this, properties);
 35 
 36         this.drawable = new Drawable(properties);
 37 
 38         //init width and height
 39         if(!this.width || !this.height){
 40             var rect = this.drawable.rect;
 41             if(rect){
 42                 this.width = rect[2];
 43                 this.height = rect[3];
 44             }
 45         }
 46     },
 47 
 48     /**
 49      * @language=en
 50      * set the image。
 51      * @param {Image|String} Image Object or URL。
 52      * @param {Array} rect the range of bitmap in the image。
 53      * @returns {Bitmap} self。
 54      */
 55     setImage: function(image, rect){
 56         this.drawable.init({image:image, rect:rect});
 57         if(rect){
 58             this.width = rect[2];
 59             this.height = rect[3];
 60         }
 61         else if(!this.width && !this.height){
 62             var rect = this.drawable.rect;
 63             if(rect){
 64                 this.width = rect[2];
 65                 this.height = rect[3];
 66             }
 67         }
 68         return this;
 69     }
 70  });
 71