diff --git a/src/app/working-area/model/axImageShape.ts b/src/app/working-area/model/axImageShape.ts index f8bf366..5225df6 100644 --- a/src/app/working-area/model/axImageShape.ts +++ b/src/app/working-area/model/axImageShape.ts @@ -5,7 +5,7 @@ import { PaintMode } from './paintModel'; import * as PIXI from 'pixi.js'; import { PropertyInfo } from './PropertyInfo'; import { AxShape } from './axShape'; -import { Sprite, Point } from 'pixi.js'; +import { Sprite, Point, Rectangle } from 'pixi.js'; import { AxArrowConnector } from './axArrowConnector'; /** @@ -31,6 +31,7 @@ export class AxImageShape extends AxShape { wordWrapWidth: 100, }); + text = new PIXI.Text(this.assetData.Name + '\r\n' + this.assetData.PropertyInfos?.find(item => item.PropertyName === '名称/编号')?.PropertyValue, this.style); @@ -79,41 +80,67 @@ export class AxImageShape extends AxShape { var rightDownPos = new Point(0, 0); // up-left this.upLeft = new PIXI.Sprite(this.pointTexture); + this.upLeft.cursor = 'nwse-resize'; this.upLeft.anchor.set(0.5); this.addChild(this.upLeft); this.upLeft.interactive = true; this.upLeft.on('pointerdown', event => { - event.stopPropagation(); + upLeftDrag = true; - // this.pivot.set(1); - var imageRect = this.image.getLocalBounds(); + var imageRect = new Rectangle(this.image.x, this.image.y, this.image.width, this.image.height); + console.log('图片的边界大小', imageRect); rightDownPos = new Point(imageRect.right, imageRect.bottom); - + this.image.anchor.set(1); + this.image.position.set(this.image.position.x + (this.image.width / 2), this.image.position.y + (this.image.height / 2)); + event.stopPropagation(); }); this.upLeft.on('pointermove', event => { + // 移动时调整形状大小,然后重绘边框 // 检查右下角距离鼠标的位置, - event.stopPropagation(); - leftUpPos = this.toLocal(event.data.global); - this.image.width = Math.abs(leftUpPos.x - rightDownPos.x); - this.image.height = Math.abs(leftUpPos.y - rightDownPos.y); + if (upLeftDrag) { + leftUpPos = event.data.getLocalPosition(this.upLeft.parent); + console.log('鼠标点击位置的坐标', leftUpPos); + + this.assetData.Width = Math.abs(leftUpPos.x); + this.assetData.Height = Math.abs(leftUpPos.x); + this.refresh(); + } + + }); + this.upLeft.on('pointerup', event => { + if (upLeftDrag) { + upLeftDrag = false; + this.image.anchor.set(0.5); + this.image.position.set(this.image.position.x - (this.image.width / 2), this.image.position.y - (this.image.height / 2)); + } + }); + this.upLeft.on('pointerupoutside', event => { + if (upLeftDrag) { + upLeftDrag = false; + this.image.anchor.set(0.5); + this.image.position.set(this.image.position.x - (this.image.width / 2), this.image.position.y - (this.image.height / 2)); + } }); this.upLeft.visible = false; // up-right this.upRight = new PIXI.Sprite(this.pointTexture); + this.upRight.cursor = 'nesw-resize'; this.upRight.anchor.set(0.5); this.addChild(this.upRight); this.upRight.interactive = true; this.upRight.visible = false; // down-left this.downLeft = new PIXI.Sprite(this.pointTexture); + this.downLeft.cursor = 'nesw-resize'; this.downLeft.anchor.set(0.5); this.addChild(this.downLeft); this.downLeft.interactive = true; this.downLeft.visible = false; // down-right this.downRight = new PIXI.Sprite(this.pointTexture); + this.downRight.cursor = 'nwse-resize'; this.downRight.anchor.set(0.5); this.addChild(this.downRight); this.downRight.interactive = true; @@ -215,71 +242,8 @@ export class AxImageShape extends AxShape { this.downRight.scale.set(scale); } } - // paintingPipeline(x: number, y: number) { - // if (this.assetData.CanConnect) { - // if (this.workingArea.getPaintMode() === PaintMode.Pipeline) { - // if (this.workingArea.paintingShape === null) { - // this.workingArea.previewLineSegment.visible = true; - // this.workingArea.currentClickPoint.position = - // new PIXI.Point(this.workingArea.circleShadow.x, this.workingArea.circleShadow.y); - // this.workingArea.paintPoints.push(new PIXI.Point(x, y)); - // const json = JSON.parse(JSON.stringify(this.workingArea.canvasData.selectTemplateData.propertyInfos)); - // const list = []; - // json.forEach(element => { - // const property = new PropertyInfo(element); - // list.push(property); - // }); - // const tempData = { - // TemplateId: this.workingArea.canvasData.selectTemplateData.id, - // CanConnect: this.workingArea.canvasData.selectTemplateData.canConnect, - // Pipelines: new Array(), - // FloorId: this.workingArea.canvasData.selectStorey.id, - // Angle: this.workingArea.canvasData.selectTemplateData.angle, - // Color: this.workingArea.canvasData.selectTemplateData.color, - // Enabled: this.workingArea.canvasData.selectTemplateData.enabled, - // FillMode: this.workingArea.canvasData.selectTemplateData.fillMode, - // FireElementId: this.workingArea.canvasData.selectTemplateData.fireElementId, - // FixedSize: this.workingArea.canvasData.selectTemplateData.fixedSize, - // Height : 32, - // Width : 32, - // Id: ObjectID.default.generate(), - // ImageUrl: this.workingArea.canvasData.selectTemplateData.imageUrl, - // InteractiveMode: this.workingArea.canvasData.selectTemplateData.interactiveMode, - // MultiPoint : JSON.parse(JSON.stringify(this.workingArea.paintPoints)), - // Point: new PIXI.Point(0, 0), - // Name : this.workingArea.canvasData.selectTemplateData.name, - // PropertyInfos: list, - // Border : this.workingArea.canvasData.selectTemplateData.border, - // DrawMode : this.workingArea.canvasData.selectTemplateData.drawMode, - // Thickness : this.workingArea.canvasData.selectTemplateData.thickness, - // IsFromBuilding : this.workingArea.canvasData.selectTemplateData.isFromBuilding, - // GameMode: this.workingArea.canvasData.gameMode, - // LinkedObjects: new Array(this.assetData.Id), - // Tag: this.workingArea.canvasData.selectTemplateData.tag - // }; - // this.workingArea.paintingShape = new AxArrowConnector(tempData, this.workingArea, false, true); - // this.assetData.Pipelines.push(this.workingArea.paintingShape.assetData.Id); - // this.workingArea.emit('createIcon', this.workingArea.paintingShape); - // } else { - // this.workingArea.previewLineSegment.visible = false; - // this.workingArea.currentClickPoint.position = - // new PIXI.Point(this.workingArea.circleShadow.x, this.workingArea.circleShadow.y); - // this.workingArea.paintPoints.push(new PIXI.Point(x, y)); - // this.workingArea.paintingShape.assetData.MultiPoint = - // JSON.parse(JSON.stringify(this.workingArea.paintPoints)); - // this.workingArea.paintingShape.assetData.LinkedObjects.push(this.assetData.Id); - // this.assetData.Pipelines.push(this.workingArea.paintingShape.assetData.Id); - // this.workingArea.paintingShape.redraw(); - // this.workingArea.initPipelineData(); - // } - // } - // } - // } // 刷新 public refresh() { - if (this.assetData.CanConnect) { - - } this.image.width = this.assetData.Width; this.image.height = this.assetData.Height; this.image.angle = this.assetData.Angle; @@ -289,5 +253,6 @@ export class AxImageShape extends AxShape { this.text.x = this.image.x; this.text.y = this.image.y - this.image.height / 2; this.angle = -this.workingArea.backgroundImage.angle; + this.drawBorder(1 / this.workingArea.backgroundImage.scale.x); } } diff --git a/src/app/working-area/model/axShape.ts b/src/app/working-area/model/axShape.ts index 5c6ce51..85ab02c 100644 --- a/src/app/working-area/model/axShape.ts +++ b/src/app/working-area/model/axShape.ts @@ -32,7 +32,7 @@ export class AxShape extends Graphics { this.workingArea.backgroundImage.addChild(this); this.zIndex = 200; this.interactive = true; - this.buttonMode = true; + // this.buttonMode = true; this .on('pointerdown', event => { event.stopPropagation(); @@ -88,10 +88,10 @@ export class AxShape extends Graphics { public hideBorder() { this.border.visible = false; } - /** - * 设置点显示状态 - * @param value 显示状态 - */ + /** + * 设置点显示状态 + * @param value 显示状态 + */ public setPointVisiable(value: boolean) { } @@ -112,7 +112,7 @@ export class AxShape extends Graphics { const spaceLength = scale * 1; const lineLenght = rect.width + 0.5 + 0.5; - const dashLength = scale * ( lineLenght + spaceLength - Math.floor((rect.width + rect.height) / 2 / 4.1)) / Math.floor((rect.width + rect.height) / 2 / 4.1); + const dashLength = scale * (lineLenght + spaceLength - Math.floor((rect.width + rect.height) / 2 / 4.1)) / Math.floor((rect.width + rect.height) / 2 / 4.1); this.drawDash(this.border, p1.x - 0.5 * scale, p1.y, p2.x + 0.5 * scale, p2.y, dashLength, spaceLength); this.drawDash(this.border, p2.x, p2.y - 0.5 * scale, p3.x, p3.y + 0.5 * scale, dashLength, spaceLength); this.drawDash(this.border, p3.x + 0.5 * scale, p3.y, p4.x - 0.5 * scale, p4.y, dashLength, spaceLength); @@ -126,36 +126,36 @@ export class AxShape extends Graphics { this.border.lineTo(p4.x, p4.y); this.border.closePath(); // this.border.endFill(); - } - // 画虚线 - drawDash(target, x1, y1, x2, y2, dashLength = 5, spaceLength = 1) { - const x = x2 - x1; - const y = y2 - y1; - let hyp = Math.sqrt((x) * (x) + (y) * (y)); - const units = hyp / (dashLength + spaceLength); - const dashSpaceRatio = dashLength / (dashLength + spaceLength); - const dashX = (x / units) * dashSpaceRatio; - const spaceX = (x / units) - dashX; - const dashY = (y / units) * dashSpaceRatio; - const spaceY = (y / units) - dashY; + } + // 画虚线 + drawDash(target, x1, y1, x2, y2, dashLength = 5, spaceLength = 1) { + const x = x2 - x1; + const y = y2 - y1; + let hyp = Math.sqrt((x) * (x) + (y) * (y)); + const units = hyp / (dashLength + spaceLength); + const dashSpaceRatio = dashLength / (dashLength + spaceLength); + const dashX = (x / units) * dashSpaceRatio; + const spaceX = (x / units) - dashX; + const dashY = (y / units) * dashSpaceRatio; + const spaceY = (y / units) - dashY; - target.moveTo(x1, y1); + target.moveTo(x1, y1); - while (hyp > 0) { - x1 += dashX; - y1 += dashY; - hyp -= dashLength; - if (hyp < 0) { - x1 = x2; - y1 = y2; + while (hyp > 0) { + x1 += dashX; + y1 += dashY; + hyp -= dashLength; + if (hyp < 0) { + x1 = x2; + y1 = y2; + } + target.lineTo(x1, y1); + x1 += spaceX; + y1 += spaceY; + target.moveTo(x1, y1); + hyp -= spaceLength; } - target.lineTo(x1, y1); - x1 += spaceX; - y1 += spaceY; - target.moveTo(x1, y1); - hyp -= spaceLength; - } - target.moveTo(x2, y2); + target.moveTo(x2, y2); } // 计算多边形重心 public calculatePolygonGravityCenter(points: PIXI.Point[]) {