123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- exports.STextItem = void 0;
- const SObjectItem_1 = require("./SObjectItem");
- const lib_1 = require("@persagy-web/draw/lib");
- const __1 = require("..");
- const __2 = require("..");
- class STextItem extends SObjectItem_1.SObjectItem {
- constructor(parent, str = "") {
- super(parent);
- this._painter = null;
- this._text = "";
- this._textArr = [];
- this._color = new lib_1.SColor("#333333");
- this._backgroundColor = lib_1.SColor.Transparent;
- this._strokeColor = lib_1.SColor.Transparent;
- this._lineWidth = 1;
- this._borderStyle = __1.SLineStyle.None;
- this._originPosition = __2.STextOrigin.LeftTop;
- this.maxWidth = undefined;
- this._text = str;
- this._font = new lib_1.SFont("sans-serif", 12);
- this.height = 12;
- }
- get text() {
- return this._text;
- }
- set text(v) {
- this._text = v;
- this._textArr = this.text.split(/\n/g);
- this.drawFormatText();
- this.update();
- }
- get color() {
- return this._color;
- }
- set color(v) {
- this._color = v;
- this.update();
- }
- get font() {
- return this._font;
- }
- set font(v) {
- this._font = v;
- this.drawFormatText();
- this.update();
- }
- get backgroundColor() {
- return this._backgroundColor;
- }
- set backgroundColor(v) {
- this._backgroundColor = v;
- this.update();
- }
- get strokeColor() {
- return this._strokeColor;
- }
- set strokeColor(v) {
- this._strokeColor = v;
- this.update();
- }
- get lineWidth() {
- return this._lineWidth;
- }
- set lineWidth(v) {
- this._lineWidth = v;
- this.update();
- }
- get borderStyle() {
- return this._borderStyle;
- }
- set borderStyle(v) {
- this._borderStyle = v;
- this.update();
- }
- get originPosition() {
- return this._originPosition;
- }
- set originPosition(v) {
- this._originPosition = v;
- this.update();
- }
- boundingRect() {
- return new lib_1.SRect(-this.origin.x, -this.origin.y, this.width, this.height);
- }
- moveToOrigin(x, y) {
- this.moveTo(this.x + x, this.y + y);
- }
- drawShowText(painter) {
- painter.translate(-this.origin.x, -this.origin.y);
- if (this.selected) {
- painter.shadow.shadowBlur = 10;
- painter.shadow.shadowColor = new lib_1.SColor(`#00000033`);
- painter.shadow.shadowOffsetX = 5;
- painter.shadow.shadowOffsetY = 5;
- }
- else {
- painter.shadow.shadowColor = lib_1.SColor.Transparent;
- }
- painter.brush.color = this.backgroundColor;
- painter.pen.lineWidth = this.lineWidth;
- painter.pen.color = this.strokeColor;
- painter.drawRect(0, 0, this.width, this.height);
- painter.brush.color = new lib_1.SColor(this.color);
- painter.shadow.shadowColor = lib_1.SColor.Transparent;
- painter.font = this.font;
- this._textArr.forEach((text, index) => {
- painter.drawText(text, this.font.size / 4, index * (this.font.size * 1.25) + this.font.size / 4, this.maxWidth);
- });
- }
- drawFormatText() {
- if (this._painter instanceof lib_1.SPainter) {
- this._painter.save();
- this._painter.font = this.font;
- let textMaxWidth = 0;
- let fontSize = this.font.size;
- this._textArr.forEach((text, index) => {
- let textWidth = this._painter
- ? this._painter.textWidth(text) + fontSize / 2
- : fontSize / 2;
- if (textWidth > textMaxWidth) {
- textMaxWidth = textWidth;
- }
- });
- this.width = textMaxWidth;
- this.height = fontSize * 1.25 * this._textArr.length + fontSize / 8;
- if (this.originPosition == __2.STextOrigin.Centrum) {
- this.origin = new lib_1.SPoint(this.width / 2, this.height / 2);
- }
- this._painter.restore();
- }
- }
- onDraw(painter) {
- if (!(this._painter instanceof lib_1.SPainter)) {
- this._painter = painter;
- this.drawFormatText();
- }
- this.drawShowText(painter);
- }
- }
- exports.STextItem = STextItem;
|