|
@@ -1,16 +1,16 @@
|
|
import { SObjectItem } from "./SObjectItem";
|
|
import { SObjectItem } from "./SObjectItem";
|
|
-import { SPainter, SRect, SColor, SFont, SPoint } from "@saga-web/draw/lib";
|
|
|
|
|
|
+import { SPainter, SRect, SColor, SFont, SPoint } from "@saga-web/draw";
|
|
import { SGraphItem } from "../SGraphItem";
|
|
import { SGraphItem } from "../SGraphItem";
|
|
-import { SLineStyle } from "../enums/SLineStyle";
|
|
|
|
-import { STextOrigin } from "../enums/STextOrigin";
|
|
|
|
|
|
+import { SLineStyle } from "..";
|
|
|
|
+import { STextOrigin } from "..";
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 文本item
|
|
|
|
|
|
+ * 文本 item
|
|
*
|
|
*
|
|
- * @author 张宇(taohuzy@163.com)
|
|
|
|
|
|
+ * @author 张宇 <taohuzy@163.com>
|
|
*/
|
|
*/
|
|
export class STextItem extends SObjectItem {
|
|
export class STextItem extends SObjectItem {
|
|
- /** 记录painter */
|
|
|
|
|
|
+ /** 记录 painter */
|
|
private _painter: SPainter | null = null;
|
|
private _painter: SPainter | null = null;
|
|
|
|
|
|
/** 文本内容 */
|
|
/** 文本内容 */
|
|
@@ -79,7 +79,7 @@ export class STextItem extends SObjectItem {
|
|
this.update();
|
|
this.update();
|
|
}
|
|
}
|
|
|
|
|
|
- /** 边框样式 */
|
|
|
|
|
|
+ /** 边框样式 */
|
|
private _borderStyle: SLineStyle = SLineStyle.None;
|
|
private _borderStyle: SLineStyle = SLineStyle.None;
|
|
get borderStyle(): SLineStyle {
|
|
get borderStyle(): SLineStyle {
|
|
return this._borderStyle;
|
|
return this._borderStyle;
|
|
@@ -89,7 +89,7 @@ export class STextItem extends SObjectItem {
|
|
this.update();
|
|
this.update();
|
|
}
|
|
}
|
|
|
|
|
|
- /** 原点位置 */
|
|
|
|
|
|
+ /** 原点位置 */
|
|
private _originPosition: STextOrigin = STextOrigin.LeftTop;
|
|
private _originPosition: STextOrigin = STextOrigin.LeftTop;
|
|
get originPosition(): STextOrigin {
|
|
get originPosition(): STextOrigin {
|
|
return this._originPosition;
|
|
return this._originPosition;
|
|
@@ -105,43 +105,48 @@ export class STextItem extends SObjectItem {
|
|
/**
|
|
/**
|
|
* 构造函数
|
|
* 构造函数
|
|
*
|
|
*
|
|
- * @param parent 指向父Item
|
|
|
|
- * @param str 文本内容
|
|
|
|
|
|
+ * @param parent 指向父 Item
|
|
|
|
+ * @param str 文本内容
|
|
*/
|
|
*/
|
|
constructor(parent: SGraphItem | null, str: string = "") {
|
|
constructor(parent: SGraphItem | null, str: string = "") {
|
|
super(parent);
|
|
super(parent);
|
|
- this._text = str;
|
|
|
|
|
|
+ this.text = str;
|
|
this._font = new SFont("sans-serif", 12);
|
|
this._font = new SFont("sans-serif", 12);
|
|
this.height = 12;
|
|
this.height = 12;
|
|
- } // Constructor
|
|
|
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
/**
|
|
* 对象边界区域
|
|
* 对象边界区域
|
|
*
|
|
*
|
|
- * @return 边界区域
|
|
|
|
|
|
+ * @return 边界区域
|
|
*/
|
|
*/
|
|
boundingRect(): SRect {
|
|
boundingRect(): SRect {
|
|
- return new SRect(-this.origin.x, -this.origin.y, this.width, this.height);
|
|
|
|
- } // Function boundingRect()
|
|
|
|
|
|
+ return new SRect(
|
|
|
|
+ -this.origin.x,
|
|
|
|
+ -this.origin.y,
|
|
|
|
+ this.width,
|
|
|
|
+ this.height
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
/**
|
|
* 移动后处理所有坐标,并肩原点置为场景原点
|
|
* 移动后处理所有坐标,并肩原点置为场景原点
|
|
*
|
|
*
|
|
- * @param x x坐标
|
|
|
|
- * @param y y坐标
|
|
|
|
- * */
|
|
|
|
|
|
+ * @param x x 坐标
|
|
|
|
+ * @param y y 坐标
|
|
|
|
+ */
|
|
moveToOrigin(x: number, y: number): void {
|
|
moveToOrigin(x: number, y: number): void {
|
|
this.moveTo(this.x + x, this.y + y);
|
|
this.moveTo(this.x + x, this.y + y);
|
|
- } // Function moveToOrigin()
|
|
|
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 绘制显示状态文本Item
|
|
|
|
|
|
+ * 绘制显示状态文本 Item
|
|
*
|
|
*
|
|
- * @param painter 绘制类
|
|
|
|
|
|
+ * @param painter 绘制对象
|
|
*/
|
|
*/
|
|
protected drawShowText(painter: SPainter): void {
|
|
protected drawShowText(painter: SPainter): void {
|
|
painter.translate(-this.origin.x, -this.origin.y);
|
|
painter.translate(-this.origin.x, -this.origin.y);
|
|
- //绘制矩形轮廓
|
|
|
|
|
|
+ //绘制矩形轮廓,是否选中
|
|
if (this.selected) {
|
|
if (this.selected) {
|
|
painter.shadow.shadowBlur = 10;
|
|
painter.shadow.shadowBlur = 10;
|
|
painter.shadow.shadowColor = new SColor(`#00000033`);
|
|
painter.shadow.shadowColor = new SColor(`#00000033`);
|
|
@@ -159,19 +164,18 @@ export class STextItem extends SObjectItem {
|
|
painter.brush.color = new SColor(this.color);
|
|
painter.brush.color = new SColor(this.color);
|
|
painter.shadow.shadowColor = SColor.Transparent;
|
|
painter.shadow.shadowColor = SColor.Transparent;
|
|
painter.font = this.font;
|
|
painter.font = this.font;
|
|
- this._textArr.forEach((text: string, index: number) => {
|
|
|
|
|
|
+ this._textArr.forEach((text: string, index: number): void => {
|
|
painter.drawText(
|
|
painter.drawText(
|
|
text,
|
|
text,
|
|
- (this.font.size / 4),
|
|
|
|
- index * (this.font.size * 1.25) + (this.font.size / 4),
|
|
|
|
|
|
+ this.font.size / 4,
|
|
|
|
+ index * (this.font.size * 1.25) + this.font.size / 4,
|
|
this.maxWidth
|
|
this.maxWidth
|
|
);
|
|
);
|
|
});
|
|
});
|
|
- } // Function drawShowText()
|
|
|
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
/**
|
|
* 根据换行切割文本,绘制多行并计算外轮廓宽高
|
|
* 根据换行切割文本,绘制多行并计算外轮廓宽高
|
|
- *
|
|
|
|
*/
|
|
*/
|
|
protected drawFormatText(): void {
|
|
protected drawFormatText(): void {
|
|
if (this._painter instanceof SPainter) {
|
|
if (this._painter instanceof SPainter) {
|
|
@@ -179,29 +183,29 @@ export class STextItem extends SObjectItem {
|
|
this._painter.font = this.font;
|
|
this._painter.font = this.font;
|
|
let textMaxWidth = 0;
|
|
let textMaxWidth = 0;
|
|
let fontSize: number = this.font.size;
|
|
let fontSize: number = this.font.size;
|
|
- this._textArr.forEach((text: string, index: number) => {
|
|
|
|
|
|
+ this._textArr.forEach((text: string, index: number): void => {
|
|
let textWidth: number = this._painter
|
|
let textWidth: number = this._painter
|
|
- ? this._painter.textWidth(text) + (fontSize / 2)
|
|
|
|
- : (fontSize / 2);
|
|
|
|
|
|
+ ? this._painter.textWidth(text) + fontSize / 2
|
|
|
|
+ : fontSize / 2;
|
|
if (textWidth > textMaxWidth) {
|
|
if (textWidth > textMaxWidth) {
|
|
textMaxWidth = textWidth;
|
|
textMaxWidth = textWidth;
|
|
}
|
|
}
|
|
});
|
|
});
|
|
// 在绘制文本后计算文本的宽高
|
|
// 在绘制文本后计算文本的宽高
|
|
this.width = textMaxWidth;
|
|
this.width = textMaxWidth;
|
|
- this.height = (fontSize * 1.25) * this._textArr.length + (fontSize / 8);
|
|
|
|
|
|
+ this.height = fontSize * 1.25 * this._textArr.length + fontSize / 8;
|
|
// 设置原点位置(默认左上角)
|
|
// 设置原点位置(默认左上角)
|
|
- if (this.originPosition == STextOrigin.Centrum) {
|
|
|
|
|
|
+ if (this.originPosition == STextOrigin.Center) {
|
|
this.origin = new SPoint(this.width / 2, this.height / 2);
|
|
this.origin = new SPoint(this.width / 2, this.height / 2);
|
|
}
|
|
}
|
|
this._painter.restore();
|
|
this._painter.restore();
|
|
}
|
|
}
|
|
- } // Function drawFormatText()
|
|
|
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Item绘制操作
|
|
|
|
|
|
+ * Item 绘制操作
|
|
*
|
|
*
|
|
- * @param painter 绘画类
|
|
|
|
|
|
+ * @param painter 绘画对象
|
|
*/
|
|
*/
|
|
onDraw(painter: SPainter): void {
|
|
onDraw(painter: SPainter): void {
|
|
if (!(this._painter instanceof SPainter)) {
|
|
if (!(this._painter instanceof SPainter)) {
|
|
@@ -209,5 +213,5 @@ export class STextItem extends SObjectItem {
|
|
this.drawFormatText();
|
|
this.drawFormatText();
|
|
}
|
|
}
|
|
this.drawShowText(painter);
|
|
this.drawShowText(painter);
|
|
- } // Function onDraw()
|
|
|
|
-} // Class STextItem
|
|
|
|
|
|
+ }
|
|
|
|
+}
|