1 /**
  2  * Hilo
  3  * Copyright 2015 alibaba.com
  4  * Licensed under the MIT License
  5  */
  6 
  7 /**
  8  * <iframe src='../../../examples/Bitmap.html?noHeader' width = '300' height = '200' scrolling='no'></iframe>
  9  * <br/>
 10  * 使用示例:
 11  * <pre>
 12  * var bmp = new Hilo.Bitmap({image:imgElem, rect:[0, 0, 100, 100]});
 13  * stage.addChild(bmp);
 14  * </pre>
 15  * @class Bitmap类表示位图图像类。
 16  * @augments View
 17  * @param {Object} properties 创建对象的属性参数。可包含此类所有可写属性。此外还包括:
 18  * <ul>
 19  * <li><b>image</b> - 位图所在的图像image。必需。</li>
 20  * <li><b>rect</b> - 位图在图像image中矩形区域。</li>
 21  * </ul>
 22  * @module hilo/view/Bitmap
 23  * @requires hilo/core/Hilo
 24  * @requires hilo/core/Class
 25  * @requires hilo/view/View
 26  * @requires hilo/view/Drawable
 27  */
 28  var Bitmap = Class.create(/** @lends Bitmap.prototype */{
 29     Extends: View,
 30     constructor: function(properties){
 31         properties = properties || {};
 32         this.id = this.id || properties.id || Hilo.getUid("Bitmap");
 33         Bitmap.superclass.constructor.call(this, properties);
 34 
 35         this.drawable = new Drawable(properties);
 36 
 37         //init width and height
 38         if(!this.width || !this.height){
 39             var rect = this.drawable.rect;
 40             if(rect){
 41                 this.width = rect[2];
 42                 this.height = rect[3];
 43             }
 44         }
 45     },
 46 
 47     /**
 48      * 设置位图的图片。
 49      * @param {Image|String} image 图片对象或地址。
 50      * @param {Array} rect 指定位图在图片image的矩形区域。
 51      * @returns {Bitmap} 位图本身。
 52      */
 53     setImage: function(image, rect){
 54         this.drawable.init({image:image, rect:rect});
 55         if(rect){
 56             this.width = rect[2];
 57             this.height = rect[3];
 58         }
 59         return this;
 60     }
 61  });