|
@@ -1,13 +1,11 @@
|
|
|
import { SObjectItem } from "./SObjectItem";
|
|
|
-import { TextData } from "../types/TextData";
|
|
|
-import { SGraphyItem } from "@saga-web/graphy/lib";
|
|
|
import {
|
|
|
SPainter,
|
|
|
SRect,
|
|
|
- STextAlign,
|
|
|
- STextBaseLine,
|
|
|
- STextDirection
|
|
|
+ SColor,
|
|
|
+ SFont
|
|
|
} from "@saga-web/draw/lib";
|
|
|
+import { SMouseEvent } from "@saga-web/base/lib";
|
|
|
|
|
|
/**
|
|
|
* 文本item
|
|
@@ -15,40 +13,42 @@ import {
|
|
|
* @author 郝建龙(1061851420@qq.com)
|
|
|
*/
|
|
|
export class STextItem extends SObjectItem {
|
|
|
- /** 文本item所有数据 */
|
|
|
- data: TextData | null = null;
|
|
|
/** 文本内容 */
|
|
|
- text: string = "";
|
|
|
- /** 文本对齐 */
|
|
|
- private textAlign: STextAlign;
|
|
|
- /** 文本基准线 */
|
|
|
- private baseLine: STextBaseLine;
|
|
|
- /** 文本绘制方向 */
|
|
|
- private textDirection: STextDirection;
|
|
|
+ _text: string = "";
|
|
|
+ get text(): string {
|
|
|
+ return this._text;
|
|
|
+ }
|
|
|
+ set text(v: string) {
|
|
|
+ this._text = v;
|
|
|
+ this.update();
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 文本所占高度 */
|
|
|
+ private height: number = 0;
|
|
|
+ /** 文本所占宽度 */
|
|
|
+ private width: number = 0;
|
|
|
+
|
|
|
+ /** 字体 */
|
|
|
+ _font: SFont = new SFont();
|
|
|
+ get font(): SFont {
|
|
|
+ return this._font;
|
|
|
+ }
|
|
|
+ set font(v: SFont) {
|
|
|
+ this._font = v;
|
|
|
+ this.update();
|
|
|
+ }
|
|
|
+
|
|
|
/** 文本绘制最大宽 */
|
|
|
maxWidth: number | undefined = undefined;
|
|
|
- /** 文本大小 */
|
|
|
- private size: number;
|
|
|
|
|
|
- /**
|
|
|
- * 构造体
|
|
|
- *
|
|
|
- * @param parent 指向父对象
|
|
|
- * @param data 文本数据
|
|
|
- * */
|
|
|
- constructor(parent: SGraphyItem | null, data: TextData) {
|
|
|
- super(parent);
|
|
|
- this.data = data;
|
|
|
- this.text = data.Text;
|
|
|
- this.textAlign = data.TextAlign ? data.TextAlign : STextAlign.Start;
|
|
|
- this.baseLine = data.BaseLine
|
|
|
- ? data.BaseLine
|
|
|
- : STextBaseLine.Alphabetic;
|
|
|
- this.textDirection = data.TextDirection
|
|
|
- ? data.TextDirection
|
|
|
- : STextDirection.Inherit;
|
|
|
- this.maxWidth = data.Width;
|
|
|
- this.size = data.Size ? data.Size : 12;
|
|
|
+ /** 文本颜色 */
|
|
|
+ private _color: string = "#000000";
|
|
|
+ get color(): string {
|
|
|
+ return this._color;
|
|
|
+ }
|
|
|
+ set color(v: string) {
|
|
|
+ this._color = v;
|
|
|
+ this.update();
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -57,19 +57,57 @@ export class STextItem extends SObjectItem {
|
|
|
* @return SRect
|
|
|
*/
|
|
|
boundingRect(): SRect {
|
|
|
- return new SRect();
|
|
|
+ return new SRect(
|
|
|
+ -this.width / 2,
|
|
|
+ -this.height / 2,
|
|
|
+ this.width,
|
|
|
+ this.height
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 判断点是否在区域内
|
|
|
+ *
|
|
|
+ * @param x
|
|
|
+ * @param y
|
|
|
+ */
|
|
|
+ contains(x: number, y: number): boolean {
|
|
|
+ return this.boundingRect().contains(x, y);
|
|
|
+ } // Function contains()
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 鼠标单击事件
|
|
|
+ *
|
|
|
+ * @param event 事件参数
|
|
|
+ * @return boolean
|
|
|
+ */
|
|
|
+ onMouseDown(event: SMouseEvent): boolean {
|
|
|
+ console.log("textDown");
|
|
|
+ this.$emit("click", event);
|
|
|
+ return true;
|
|
|
+ } // Function onMouseDown()
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 鼠标抬起事件
|
|
|
+ *
|
|
|
+ * @param event 事件参数
|
|
|
+ * @return boolean
|
|
|
+ */
|
|
|
+ onMouseUp(event: SMouseEvent): boolean {
|
|
|
+ console.log("textup");
|
|
|
+ return super.onMouseUp(event);
|
|
|
+ } // Function onClick()
|
|
|
+
|
|
|
+ /**
|
|
|
* Item绘制操作
|
|
|
*
|
|
|
* @param painter painter对象
|
|
|
*/
|
|
|
onDraw(painter: SPainter): void {
|
|
|
- painter.font.textAlign = this.textAlign;
|
|
|
- painter.font.textBaseLine = this.baseLine;
|
|
|
- painter.font.textDirection = this.textDirection;
|
|
|
- painter.font.size = painter.toPx(this.size);
|
|
|
+ this.width = painter.toPx(painter.textWidth(this.text));
|
|
|
+ this.height = painter.toPx(this.font.size);
|
|
|
+ painter.font = this.font;
|
|
|
+ painter.brush.color = new SColor(this.color);
|
|
|
painter.drawText(this.text, 0, 0, this.maxWidth);
|
|
|
} // Function onDraw()
|
|
|
} // Class STextItem
|