|
@@ -5,12 +5,12 @@ import { Measure } from "../measure";
|
|
/**
|
|
/**
|
|
* Class used to create 2D images
|
|
* Class used to create 2D images
|
|
*/
|
|
*/
|
|
-class GUIImage extends Control {
|
|
|
|
|
|
+export class Image extends Control {
|
|
private _domImage: HTMLImageElement;
|
|
private _domImage: HTMLImageElement;
|
|
private _imageWidth: number;
|
|
private _imageWidth: number;
|
|
private _imageHeight: number;
|
|
private _imageHeight: number;
|
|
private _loaded = false;
|
|
private _loaded = false;
|
|
- private _stretch = GUIImage.STRETCH_FILL;
|
|
|
|
|
|
+ private _stretch = Image.STRETCH_FILL;
|
|
private _source: Nullable<string>;
|
|
private _source: Nullable<string>;
|
|
private _autoScale = false;
|
|
private _autoScale = false;
|
|
|
|
|
|
@@ -169,7 +169,7 @@ class GUIImage extends Control {
|
|
this._loaded = false;
|
|
this._loaded = false;
|
|
this._source = value;
|
|
this._source = value;
|
|
|
|
|
|
- this._domImage = new Image();
|
|
|
|
|
|
+ this._domImage = document.createElement("img");
|
|
|
|
|
|
this._domImage.onload = () => {
|
|
this._domImage.onload = () => {
|
|
this._onImageLoaded();
|
|
this._onImageLoaded();
|
|
@@ -286,15 +286,15 @@ class GUIImage extends Control {
|
|
if (this._processMeasures(parentMeasure, context)) {
|
|
if (this._processMeasures(parentMeasure, context)) {
|
|
if (this._loaded) {
|
|
if (this._loaded) {
|
|
switch (this._stretch) {
|
|
switch (this._stretch) {
|
|
- case GUIImage.STRETCH_NONE:
|
|
|
|
|
|
+ case Image.STRETCH_NONE:
|
|
context.drawImage(this._domImage, x, y, width, height,
|
|
context.drawImage(this._domImage, x, y, width, height,
|
|
this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
|
|
this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
|
|
break;
|
|
break;
|
|
- case GUIImage.STRETCH_FILL:
|
|
|
|
|
|
+ case Image.STRETCH_FILL:
|
|
context.drawImage(this._domImage, x, y, width, height,
|
|
context.drawImage(this._domImage, x, y, width, height,
|
|
this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
|
|
this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
|
|
break;
|
|
break;
|
|
- case GUIImage.STRETCH_UNIFORM:
|
|
|
|
|
|
+ case Image.STRETCH_UNIFORM:
|
|
var hRatio = this._currentMeasure.width / width;
|
|
var hRatio = this._currentMeasure.width / width;
|
|
var vRatio = this._currentMeasure.height / height;
|
|
var vRatio = this._currentMeasure.height / height;
|
|
var ratio = Math.min(hRatio, vRatio);
|
|
var ratio = Math.min(hRatio, vRatio);
|
|
@@ -304,7 +304,7 @@ class GUIImage extends Control {
|
|
context.drawImage(this._domImage, x, y, width, height,
|
|
context.drawImage(this._domImage, x, y, width, height,
|
|
this._currentMeasure.left + centerX, this._currentMeasure.top + centerY, width * ratio, height * ratio);
|
|
this._currentMeasure.left + centerX, this._currentMeasure.top + centerY, width * ratio, height * ratio);
|
|
break;
|
|
break;
|
|
- case GUIImage.STRETCH_EXTEND:
|
|
|
|
|
|
+ case Image.STRETCH_EXTEND:
|
|
context.drawImage(this._domImage, x, y, width, height,
|
|
context.drawImage(this._domImage, x, y, width, height,
|
|
this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
|
|
this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
|
|
if (this._autoScale) {
|
|
if (this._autoScale) {
|
|
@@ -322,30 +322,12 @@ class GUIImage extends Control {
|
|
}
|
|
}
|
|
|
|
|
|
// Static
|
|
// Static
|
|
- private static _STRETCH_NONE = 0;
|
|
|
|
- private static _STRETCH_FILL = 1;
|
|
|
|
- private static _STRETCH_UNIFORM = 2;
|
|
|
|
- private static _STRETCH_EXTEND = 3;
|
|
|
|
-
|
|
|
|
/** STRETCH_NONE */
|
|
/** STRETCH_NONE */
|
|
- public static get STRETCH_NONE(): number {
|
|
|
|
- return GUIImage._STRETCH_NONE;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ public static readonly STRETCH_NONE = 0;
|
|
/** STRETCH_FILL */
|
|
/** STRETCH_FILL */
|
|
- public static get STRETCH_FILL(): number {
|
|
|
|
- return GUIImage._STRETCH_FILL;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ public static readonly STRETCH_FILL = 1;
|
|
/** STRETCH_UNIFORM */
|
|
/** STRETCH_UNIFORM */
|
|
- public static get STRETCH_UNIFORM(): number {
|
|
|
|
- return GUIImage._STRETCH_UNIFORM;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ public static readonly STRETCH_UNIFORM = 2;
|
|
/** STRETCH_EXTEND */
|
|
/** STRETCH_EXTEND */
|
|
- public static get STRETCH_EXTEND(): number {
|
|
|
|
- return GUIImage._STRETCH_EXTEND;
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-export { GUIImage as Image };
|
|
|
|
|
|
+ public static readonly STRETCH_EXTEND = 3;
|
|
|
|
+}
|