|
@@ -0,0 +1,109 @@
|
|
|
+import { SelectCtrl } from ".";
|
|
|
+
|
|
|
+export class AssistCtrl {
|
|
|
+ ctrl: SelectCtrl
|
|
|
+
|
|
|
+ constructor(ctrl: SelectCtrl) {
|
|
|
+ this.ctrl = ctrl;
|
|
|
+ }
|
|
|
+
|
|
|
+ _flashTimer?:any;
|
|
|
+ _flashDraw(cb:()=>void) {
|
|
|
+ let total = 0
|
|
|
+ const ctx = this.ctrl._selCtx;
|
|
|
+ const size = this.ctrl._selCanvaseSize;
|
|
|
+
|
|
|
+ if (this._flashTimer) {
|
|
|
+ clearInterval(this._flashTimer);
|
|
|
+ cb();
|
|
|
+ }
|
|
|
+ this._flashTimer = setInterval(()=>{
|
|
|
+ total += 1;
|
|
|
+ if (total > 3) {
|
|
|
+ clearInterval(this._flashTimer);
|
|
|
+ ctx.clearRect(0, 0, size.w, size.h)
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ cb();
|
|
|
+ }, 100)
|
|
|
+ }
|
|
|
+
|
|
|
+ drawCardDists() {
|
|
|
+ if ( !this.ctrl.objContainer ) return;
|
|
|
+
|
|
|
+ const size = this.ctrl._selCanvaseSize;
|
|
|
+ const ctx = this.ctrl._selCtx;
|
|
|
+ const cardBox = this.ctrl.getCurrCardBox();
|
|
|
+
|
|
|
+ const ObjC = this.ctrl.objContainer
|
|
|
+ const bound = ObjC.getBound()
|
|
|
+ ctx.clearRect(0, 0, size.w, size.h)
|
|
|
+ ctx.lineWidth = 2;
|
|
|
+ ctx.beginPath(); // Start a new path
|
|
|
+ ctx.strokeStyle = "orange";
|
|
|
+ ctx.font = "36px Arial";
|
|
|
+ ctx.fillStyle = "orange";
|
|
|
+ ctx.setLineDash([5, 5]);
|
|
|
+
|
|
|
+ //左边
|
|
|
+ let x = (cardBox.x + bound.x)*2;
|
|
|
+ let y = (cardBox.y + bound.y + bound.height / 2.0) *2
|
|
|
+ ctx.moveTo(x, y); // Move the pen to (30, 50)
|
|
|
+ ctx.lineTo(cardBox.x *2 , y); // Draw a line to (150, 100)
|
|
|
+ ctx.stroke(); // Render the path
|
|
|
+ //关闭当前的绘制路径
|
|
|
+ ctx.closePath();
|
|
|
+
|
|
|
+ //右边
|
|
|
+ const tl = ( x / 2.0 - cardBox.x).toFixed(0);
|
|
|
+ ctx.fillText(tl, cardBox.x*2, y - 18);
|
|
|
+ x = (cardBox.x + bound.x + bound.width);
|
|
|
+ const x2 = (cardBox.x + cardBox.width);
|
|
|
+ ctx.moveTo(x*2, y); // Move the pen to (30, 50)
|
|
|
+ ctx.lineTo( x2*2, y); // Draw a line to (150, 100)
|
|
|
+ ctx.stroke(); // Render the path
|
|
|
+ ctx.closePath();
|
|
|
+ const tr = (x2-x).toFixed(0);
|
|
|
+ const m = ctx.measureText(tr)
|
|
|
+ ctx.fillText(tr, x2*2 - m.width, y-18);
|
|
|
+
|
|
|
+ //上边
|
|
|
+ x = cardBox.x + cardBox.width / 2.0;
|
|
|
+ y = cardBox.y;
|
|
|
+
|
|
|
+ ctx.moveTo(x*2, y*2); // Move the pen to (30, 50)
|
|
|
+ ctx.lineTo( x*2, (y + bound.y)*2); // Draw a line to (150, 100)
|
|
|
+ ctx.stroke(); // Render the path
|
|
|
+ ctx.closePath();
|
|
|
+ let dy = (bound.y).toFixed(0);
|
|
|
+ ctx.fillText(dy, x*2, cardBox.y *2 + 36);
|
|
|
+
|
|
|
+
|
|
|
+ //下边
|
|
|
+ x = cardBox.x + cardBox.width / 2.0;
|
|
|
+ y = cardBox.y + cardBox.height;
|
|
|
+
|
|
|
+ ctx.moveTo(x*2, y*2); // Move the pen to (30, 50)
|
|
|
+ ctx.lineTo( x*2, (cardBox.y + bound.y + bound.height)*2); // Draw a line to (150, 100)
|
|
|
+ ctx.stroke(); // Render the path
|
|
|
+ ctx.closePath();
|
|
|
+ dy = (cardBox.height - bound.y - bound.height).toFixed(0);
|
|
|
+ ctx.fillText(dy, x*2, y*2);
|
|
|
+
|
|
|
+
|
|
|
+ //如果有旋转角度
|
|
|
+ if ( Math.abs(ObjC.parent.rotation) > 0.001 ) {
|
|
|
+ ctx.strokeRect((bound.x + cardBox.x)*2, (bound.y + cardBox.y)*2, bound.width *2, bound.height *2);
|
|
|
+ //绘制角度
|
|
|
+
|
|
|
+ const r = (ObjC.parent.rotation * 180 / Math.PI).toFixed(1) + "°";
|
|
|
+ const m = ctx.measureText(r )
|
|
|
+
|
|
|
+ ctx.fillText(r , (bound.x + cardBox.x)*2 + bound.width - m.width / 2, (bound.y + cardBox.y)*2 + bound.height - 18);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ flashDrawCardDists() {
|
|
|
+ this._flashDraw(this.drawCardDists.bind(this));
|
|
|
+ }
|
|
|
+}
|