|
@@ -1,6 +1,7 @@
|
|
|
import { SObjectItem } from "./SObjectItem";
|
|
|
-import { SPainter, SRect } from "@saga-web/draw/lib";
|
|
|
+import { SPainter, SRect, SSize } from "@saga-web/draw/lib";
|
|
|
import { SGraphItem } from "@saga-web/graph/lib";
|
|
|
+import { SImageShowType } from "../enums/SImageShowType";
|
|
|
|
|
|
/**
|
|
|
* 图片绘制
|
|
@@ -15,18 +16,22 @@ export class SImageItem extends SObjectItem {
|
|
|
}
|
|
|
set url(v: string) {
|
|
|
this._url = v;
|
|
|
- this.Img = new Image();
|
|
|
- this.Img.src = v;
|
|
|
- this.Img.onload = (): void => {
|
|
|
- // @ts-ignore
|
|
|
- this.width = this.Img.width;
|
|
|
- // @ts-ignore
|
|
|
- this.height = this.Img.height;
|
|
|
+ this.img = new Image();
|
|
|
+ this.img.src = v;
|
|
|
+ this.img.onload = (): void => {
|
|
|
+ if (this.showType == SImageShowType.AutoFit) {
|
|
|
+ // @ts-ignore
|
|
|
+ this.width = this.Img.width;
|
|
|
+ // @ts-ignore
|
|
|
+ this.height = this.Img.height;
|
|
|
+ }
|
|
|
this.update();
|
|
|
};
|
|
|
}
|
|
|
/** 图片dom */
|
|
|
- Img: CanvasImageSource | undefined;
|
|
|
+ img: CanvasImageSource | undefined;
|
|
|
+ /** 展示模式 */
|
|
|
+ showType: SImageShowType = SImageShowType.Full;
|
|
|
|
|
|
/**
|
|
|
* 构造函数
|
|
@@ -35,7 +40,6 @@ export class SImageItem extends SObjectItem {
|
|
|
* */
|
|
|
constructor(parent: SGraphItem | null) {
|
|
|
super(parent);
|
|
|
- this.isTransform = false;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -53,14 +57,24 @@ export class SImageItem extends SObjectItem {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 宽高发发生变化
|
|
|
+ *
|
|
|
+ * @param oldSize 改之前的大小
|
|
|
+ * @param newSize 改之后大小
|
|
|
+ * */
|
|
|
+ protected onResize(oldSize: SSize, newSize: SSize) {
|
|
|
+ this.update();
|
|
|
+ } // Function onResize()
|
|
|
+
|
|
|
+ /**
|
|
|
* Item绘制操作
|
|
|
*
|
|
|
* @param painter painter对象
|
|
|
*/
|
|
|
onDraw(painter: SPainter): void {
|
|
|
- if (this.Img) {
|
|
|
+ if (this.img) {
|
|
|
painter.drawImage(
|
|
|
- this.Img,
|
|
|
+ this.img,
|
|
|
-this.width / 2,
|
|
|
-this.height / 2,
|
|
|
this.width,
|