//////////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2014-present, Egret Technology.
// All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of the Egret nor the
// names of its contributors may be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////////////
/// bitmapData property
* to show the data. you can also set the source property, Image will auto load
* and show the url image or the bitmapData.
*
* @event egret.Event.COMPLETE Dispatched when the image loaded complete.
* @version Egret 2.4
* @version eui 1.0
* @platform Web,Native
* @includeExample extension/eui/components/ImageExample.ts
* @language en_US
*/
/**
* Image 控件允许您在运行时显示 JPEG、PNG 等图片文件文件。Image 继承至 Bitmap,因此您可以直接对其 bitmapData 属性,
* 赋值从外部加载得到的位图数据以显示对应图片。同时,Image 还提供了更加方便的 source 属性,source 属性可以接受一个网络图片url作为值,
* 赋值为url后,它内部会自动去加载并显示图片。并且您同样也可以直接把 BitmapData 对象赋值给 source 属性以显示图片。
*
* @event egret.Event.COMPLETE 当图片加载完成后调度
* @version Egret 2.4
* @version eui 1.0
* @platform Web,Native
* @includeExample extension/eui/components/ImageExample.ts
* @language zh_CN
*/
export class Image extends egret.Bitmap implements UIComponent {
/**
* Constructor.
*
* @param source The source used for the bitmap fill. the value can be
* a string or an instance of egret.Texture
*
* @version Egret 2.4
* @version eui 1.0
* @platform Web,Native
* @language en_US
*/
/**
* 构造函数。
*
* @param source 用于位图填充的源。可以是一个字符串或者 egret.Texture 对象
*
* @version Egret 2.4
* @version eui 1.0
* @platform Web,Native
* @language zh_CN
*/
public constructor(source?: string | egret.Texture) {
super();
this.initializeUIValues();
if (source) {
this.source = source;
}
}
/**
* Represent a Rectangle Area that the 9 scale area of Image.
* Notice: This property is valid only when fillMode
* is BitmapFillMode.SCALE.
*
* @version Egret 2.4
* @version eui 1.0
* @platform Web,Native
* @language en_US
*/
/**
* 矩形区域,它定义素材对象的九个缩放区域。
* 注意:此属性仅在fillMode为BitmapFillMode.SCALE时有效。
*
* @version Egret 2.4
* @version eui 1.0
* @platform Web,Native
* @language zh_CN
*/
public get scale9Grid(): egret.Rectangle {
return this.$scale9Grid;
}
public set scale9Grid(value: egret.Rectangle) {
this.$scale9Grid = value;
this.$renderDirty = true;
this.invalidateDisplayList();
}
/**
* Determines how the bitmap fills in the dimensions.
*
When set to BitmapFillMode.CLIP, the bitmap
* ends at the edge of the region.
When set to BitmapFillMode.REPEAT, the bitmap
* repeats to fill the region.
When set to BitmapFillMode.SCALE, the bitmap
* stretches to fill the region.
BitmapFillMode.SCALE
*
* @version Egret 2.4
* @version eui 1.0
* @platform Web,Native
* @language en_US
*/
/**
* 确定位图填充尺寸的方式。
* 设置为 BitmapFillMode.CLIP时,位图将在边缘处被截断。
设置为 BitmapFillMode.REPEAT时,位图将重复以填充区域。
设置为 BitmapFillMode.SCALE时,位图将拉伸以填充区域。
BitmapFillMode.SCALE
*
* @version Egret 2.4
* @version eui 1.0
* @platform Web,Native
* @language zh_CN
*/
public get fillMode(): string {
return this.$fillMode;
}
public set fillMode(value: string) {
if (value == this.$fillMode) {
return;
}
this.$fillMode = value;
this.invalidateDisplayList();
}
//if egret
$setFillMode(value: string): boolean {
let result: boolean = super.$setFillMode(value);
this.invalidateDisplayList();
return result;
}
//endif*/
/**
* @private
*/
private sourceChanged: boolean = false;
/**
* @private
*/
private _source: string | egret.Texture = null;
/**
* The source used for the bitmap fill. the value can be
* a string or an instance of egret.Texture
*
* @version Egret 2.4
* @version eui 1.0
* @platform Web,Native
* @language en_US
*/
/**
* 用于位图填充的源。可以是一个字符串或者 egret.Texture 对象
*
* @version Egret 2.4
* @version eui 1.0
* @platform Web,Native
* @language zh_CN
*/
public get source(): string | egret.Texture {
return this._source;
}
public set source(value: string | egret.Texture) {
if (value == this._source) {
return;
}
this._source = value;
if (this.$stage) {
this.parseSource();
}
else {
this.sourceChanged = true;
this.invalidateProperties();
}
}
$setTexture(value: egret.Texture): boolean {
if (value == this.$texture) {
return false;
}
let result: boolean = super.$setTexture(value);
this.sourceChanged = false;
this.invalidateSize();
this.invalidateDisplayList();
return result;
}
/**
* @private
* 解析source
*/
private parseSource(): void {
this.sourceChanged = false;
let source = this._source;
if (source && typeof source == "string") {
getAssets(