123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280 |
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- exports.SIconTextItem = void 0;
- const lib_1 = require("@persagy-web/graph/lib");
- const __1 = require("..");
- const draw_1 = require("@persagy-web/draw");
- class SIconTextItem extends lib_1.SObjectItem {
- constructor(parent, data) {
- super(parent);
- this._status = __1.SItemStatus.Normal;
- this._showText = true;
- this._isActive = false;
- this._activeColor = new draw_1.SColor("#00000033");
- this._showAnchor = false;
- this.img = new lib_1.SImageItem(this);
- this.textItem = new lib_1.STextItem(this);
- this.img.width = 32;
- this.img.height = 32;
- this.img.origin = new draw_1.SPoint(this.img.width * 0.5, this.img.height * 0.5);
- this.img.connect("onMove", this, this.changeAhchorPoint.bind(this));
- let anchorPoint;
- if (data && data.length) {
- anchorPoint = data.map(t => {
- return {
- x: t.Pos.X,
- y: t.Pos.Y,
- id: t.ID
- };
- });
- }
- else {
- anchorPoint = [
- { x: this.img.x, y: this.img.y, id: "" },
- { x: this.img.x, y: this.img.y, id: "" },
- { x: this.img.x, y: this.img.y, id: "" },
- { x: this.img.x, y: this.img.y, id: "" }
- ];
- }
- this.anchorList = anchorPoint.map(t => {
- let item = new lib_1.SAnchorItem(this);
- if (t.id) {
- item.id = t.id;
- }
- item.moveTo(t.x, t.y);
- return item;
- });
- this.showAnchor = false;
- this.textItem.text = "";
- this.textItem.font.size = 12;
- this.textItem.moveTo((this.img.width * 0.5), -(this.font.size * 1.25 * 0.5));
- this.moveable = true;
- this.selectable = true;
- }
- get status() {
- return this._status;
- }
- set status(v) {
- this._status = v;
- if (v == __1.SItemStatus.Normal) {
- this.moveable = true;
- this.textItem.moveable = false;
- this.img.moveable = false;
- }
- else if (v == __1.SItemStatus.Edit) {
- this.moveable = false;
- this.textItem.moveable = true;
- this.img.moveable = true;
- }
- else if (v == __1.SItemStatus.Create) {
- this.moveable = true;
- this.textItem.moveable = false;
- this.img.moveable = false;
- }
- this.update();
- }
- get showText() {
- return this._showText;
- }
- set showText(v) {
- if (v === this._showText) {
- return;
- }
- this._showText = v;
- if (v) {
- this.textItem.show();
- }
- else {
- this.textItem.hide();
- }
- }
- get selected() {
- return this._selected && this.selectable && this.enabled;
- }
- set selected(value) {
- if (this.selected == value) {
- return;
- }
- this._selected = value;
- if (value) {
- this.img.scale = 1.25;
- this.zOrder = __1.ItemOrder.highLightOrder;
- }
- else {
- this.img.scale = 1;
- this.zOrder = __1.ItemOrder.markOrder;
- }
- this.update();
- }
- get isActive() {
- return this._isActive;
- }
- set isActive(v) {
- this._isActive = v;
- if (v) {
- this.cursor = "pointer";
- this.textItem.cursor = "pointer";
- this.img.cursor = "pointer";
- }
- else {
- this.cursor = "auto";
- this.textItem.cursor = "auto";
- this.img.cursor = "auto";
- }
- this.update();
- }
- get activeColor() {
- return this._activeColor;
- }
- set activeColor(v) {
- this._activeColor = v;
- this.update();
- }
- get x() {
- return this.pos.x;
- }
- set x(v) {
- this.pos.x = v;
- this.$emit("changePos");
- this.update();
- }
- get y() {
- return this.pos.y;
- }
- set y(v) {
- this.pos.y = v;
- this.$emit("changePos");
- this.update();
- }
- get sWidth() {
- return this.img.width;
- }
- set sWidth(v) {
- this.img.width = v;
- this.img.origin = new draw_1.SPoint(this.img.width * 0.5, this.img.height * 0.5);
- this.changeAhchorPoint();
- this.update();
- }
- get sHeight() {
- return this.img.height;
- }
- set sHeight(v) {
- this.img.height = v;
- this.img.origin = new draw_1.SPoint(this.img.width * 0.5, this.img.height * 0.5);
- this.changeAhchorPoint();
- this.update();
- }
- get showAnchor() {
- return this._showAnchor;
- }
- set showAnchor(v) {
- this._showAnchor = v;
- this.anchorList.forEach(t => {
- t.visible = v;
- });
- }
- get text() {
- return this.textItem.text;
- }
- set text(v) {
- this.textItem.text = v;
- this.update();
- }
- get color() {
- return this.textItem.color;
- }
- set color(v) {
- this.textItem.color = v;
- this.update();
- }
- get font() {
- return this.textItem.font;
- }
- set font(v) {
- this.textItem.font = v;
- this.update();
- }
- changeAhchorPoint() {
- if (this.anchorList.length) {
- let anchorPoint = [
- { x: this.img.x, y: this.img.y },
- { x: this.img.x, y: this.img.y },
- { x: this.img.x, y: this.img.y },
- { x: this.img.x, y: this.img.y }
- ];
- this.anchorList.forEach((item, index) => {
- item.moveTo(anchorPoint[index].x, anchorPoint[index].y);
- });
- }
- }
- onMouseDown(event) {
- if (this.status == __1.SItemStatus.Normal) {
- return super.onMouseDown(event);
- }
- else if (this.status == __1.SItemStatus.Edit) {
- return super.onMouseDown(event);
- }
- return true;
- }
- onResize(oldSize, newSize) {
- console.log(arguments);
- }
- onDoubleClick(event) {
- if (__1.SItemStatus.Normal == this.status) {
- this.status = __1.SItemStatus.Edit;
- this.grabItem(this);
- }
- else if (__1.SItemStatus.Edit == this.status) {
- this.status = __1.SItemStatus.Normal;
- this.releaseItem();
- }
- this.update();
- return true;
- }
- boundingRect() {
- let rect = this.img
- .boundingRect()
- .adjusted(this.img.pos.x, this.img.pos.y, 0, 0);
- if (this.showText) {
- rect = rect.unioned(this.textItem
- .boundingRect()
- .adjusted(this.textItem.pos.x, this.textItem.pos.y, 0, 0));
- }
- return rect.adjusted(-5, -5, 10, 10);
- }
- onDraw(painter) {
- if (this.status == __1.SItemStatus.Edit) {
- painter.pen.lineWidth = painter.toPx(1);
- painter.pen.lineDash = [painter.toPx(3), painter.toPx(7)];
- painter.pen.color = draw_1.SColor.Black;
- painter.brush.color = draw_1.SColor.Transparent;
- painter.drawRect(this.boundingRect());
- }
- if (this.isActive) {
- painter.pen.color = draw_1.SColor.Transparent;
- painter.brush.color = this.activeColor;
- if (this.selected) {
- painter.shadow.shadowBlur = 10;
- painter.shadow.shadowColor = this.activeColor;
- painter.shadow.shadowOffsetX = 5;
- painter.shadow.shadowOffsetY = 5;
- painter.drawCircle(this.img.x, this.img.y, (this.sWidth / 2.0 + 3) * 1.25);
- }
- else {
- painter.drawCircle(this.img.x, this.img.y, this.sWidth / 2.0 + 3);
- }
- }
- else {
- if (this.selected) {
- painter.pen.color = draw_1.SColor.Transparent;
- painter.brush.color = draw_1.SColor.Transparent;
- painter.shadow.shadowBlur = 10;
- painter.shadow.shadowColor = new draw_1.SColor(`#00000033`);
- painter.shadow.shadowOffsetX = 5;
- painter.shadow.shadowOffsetY = 5;
- painter.drawCircle(this.img.x, this.img.y, this.sWidth / 2.0);
- }
- }
- }
- }
- exports.SIconTextItem = SIconTextItem;
|