Skip to content

Commit 64e6592

Browse files
committed
更新尺寸标注
1 parent 2fcc31d commit 64e6592

11 files changed

Lines changed: 8663 additions & 137 deletions

File tree

‎pnpm-lock.yaml‎

Lines changed: 8284 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/app/fabricCanvas.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ import { Canvas, FabricImage, FabricObject } from 'fabric'
55
import { shallowRef } from 'vue'
66
import { toRef } from './attribute/toRef'
77
import { FabricRuler } from './fabricRuler'
8+
import { FabricTool } from './fabricTool'
89

910
export class FabricCanvas extends Canvas {
1011
public ruler?: FabricRuler
12+
public tool?: FabricTool
1113
public loading?: FabricImage
14+
public swipe?: boolean
1215
public activeObject = shallowRef<FabricObject>()
1316

1417
constructor(el: string | HTMLCanvasElement, options?: any) {

‎src/app/fabricGuide.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export class FabricGuide extends Disposable {
6464

6565
private objectMoving({ target }: any) {
6666
this.clearStretLine()
67-
if (check.isCircle(target)) {
67+
if (check.isCircle(target) || target.type.toLowerCase() === 'circlenum') {
6868
return false
6969
}
7070
const transform = this.canvas._currentTransform

‎src/app/fabricRuler.ts‎

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ export class FabricRuler extends Disposable {
7676
x: HighlightRect[],
7777
y: HighlightRect[]
7878
}
79+
private isHoveringRuler: boolean = false
7980

8081
constructor(private readonly canvas: FabricCanvas) {
8182
super()
@@ -124,6 +125,18 @@ export class FabricRuler extends Disposable {
124125
}
125126
this.enabled = this.options.enabled
126127
canvas.ruler = this
128+
129+
// 当鼠标离开画布时,若处于标尺区样式,恢复到进入前的样式
130+
this.canvas.upperCanvasEl?.addEventListener('mouseleave', this.onCanvasMouseLeave)
131+
}
132+
133+
private onCanvasMouseLeave = () => {
134+
if (!this.isHoveringRuler) return
135+
const restore = this.lastCursor || 'default'
136+
this.canvas.defaultCursor = restore
137+
this.canvas.setCursor(restore)
138+
this.canvas.upperCanvasEl && (this.canvas.upperCanvasEl.style.cursor = restore)
139+
this.isHoveringRuler = false
127140
}
128141

129142
public getPointHover(point: Point): 'vertical' | 'horizontal' | '' {
@@ -168,10 +181,24 @@ export class FabricRuler extends Disposable {
168181
this.tempReferenceLine.fire('moving', event);
169182
}
170183
const status = this.getPointHover(e.viewportPoint)
171-
this.canvas.defaultCursor = this.lastCursor
172-
if (!status) return
173-
this.lastCursor = this.canvas.defaultCursor
174-
this.canvas.defaultCursor = status === 'horizontal' ? 'ns-resize' : 'ew-resize';
184+
if (status) {
185+
if (!this.isHoveringRuler) {
186+
// 首次进入标尺区,记录进入前的光标
187+
this.lastCursor = this.canvas.defaultCursor
188+
this.isHoveringRuler = true
189+
}
190+
const resizeCursor = status === 'horizontal' ? 'ns-resize' : 'ew-resize'
191+
this.canvas.defaultCursor = resizeCursor
192+
this.canvas.setCursor(resizeCursor)
193+
this.canvas.upperCanvasEl && (this.canvas.upperCanvasEl.style.cursor = resizeCursor)
194+
} else if (this.isHoveringRuler) {
195+
// 离开标尺区,恢复光标
196+
const restore = this.lastCursor || 'default'
197+
this.canvas.defaultCursor = restore
198+
this.canvas.setCursor(restore)
199+
this.canvas.upperCanvasEl && (this.canvas.upperCanvasEl.style.cursor = restore)
200+
this.isHoveringRuler = false
201+
}
175202
}
176203

177204
private mouseDown(e: TPointerEventInfo<TPointerEvent>) {
@@ -596,5 +623,6 @@ export class FabricRuler extends Disposable {
596623
public dispose(): void {
597624
super.dispose()
598625
this.enabled = false
626+
this.canvas.upperCanvasEl?.removeEventListener('mouseleave', this.onCanvasMouseLeave)
599627
}
600628
}

0 commit comments

Comments
 (0)