Skip to content

Commit 5caf5f6

Browse files
committed
Use magictool for eraser
1 parent 5b0886c commit 5caf5f6

File tree

1 file changed

+60
-5
lines changed

1 file changed

+60
-5
lines changed

src/ui/blackboard/blackboardnotepad.jsx

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,10 @@ export class BlackboardNotepad extends Component {
374374

375375
this.rightmousescroll = false
376376

377-
if (this.magictool && this.addformpictmode === 0) {
377+
if (
378+
(this.magictool || event.button === 5) /* eraser */ &&
379+
this.addformpictmode === 0
380+
) {
378381
console.log(
379382
'magic pointerdown pointerId:',
380383
event.pointerId,
@@ -393,6 +396,15 @@ export class BlackboardNotepad extends Component {
393396
'cY',
394397
event.clientY
395398
)
399+
if (!this.magictool) {
400+
this.magictooleraser = true
401+
if (this.realblackboard && this.realblackboard.current)
402+
this.realblackboard.current.setcursor({
403+
mode: 'magic'
404+
})
405+
} else {
406+
this.magictooleraser = false
407+
}
396408
if (this.props.informDraw) this.props.informDraw()
397409
this.magicpointerid = event.pointerId
398410
if (this.copydeletebox()) this.copydeletebox().deactivate()
@@ -470,6 +482,19 @@ export class BlackboardNotepad extends Component {
470482
break
471483
}
472484
} else {
485+
if (
486+
event.isPrimary &&
487+
this.realblackboard &&
488+
this.realblackboard.current &&
489+
this.addformpictmode === 0 &&
490+
(this.toolsize || this.toolcolor)
491+
) {
492+
this.realblackboard.current.setcursor({
493+
mode: 'drawing',
494+
size: this.toolsize,
495+
color: this.toolcolor
496+
})
497+
}
473498
if (this.notetools()) {
474499
this.notetools().setCanTooltip(false)
475500
}
@@ -695,11 +720,15 @@ export class BlackboardNotepad extends Component {
695720
if (!this.rightmousescroll) {
696721
if (
697722
(event.pointerId in this.pointerdraw === true ||
698-
(this.magictool && event.pointerId === this.magicpointerid)) &&
723+
((this.magictool || this.magictooleraser) &&
724+
event.pointerId === this.magicpointerid)) &&
699725
!this.laserpointer
700726
) {
701727
if (event.pointerType === 'touch') {
702-
if (this.checkPalmReject(event) && !this.magictool) {
728+
if (
729+
this.checkPalmReject(event) &&
730+
(!this.magictool || !this.magictooleraser)
731+
) {
703732
// dismiss object
704733
console.log('palm object dismissed')
705734
this.props.outgoingsink.deleteObject(
@@ -724,7 +753,10 @@ export class BlackboardNotepad extends Component {
724753
this.lastTouchTime = now
725754
this.lastTouchPointerId = event.pointerId
726755
// }
727-
if (this.magictool) {
756+
if (
757+
(this.magictool || this.magictooleraser) &&
758+
event.pointerId === this.magicpointerid
759+
) {
728760
const pos = { x: event.clientX, y: event.clientY }
729761
if (this.realblackboard && this.realblackboard.current)
730762
this.realblackboard.current.addToMagicPath(
@@ -803,7 +835,10 @@ export class BlackboardNotepad extends Component {
803835
}
804836
const pos = { x: event.clientX, y: event.clientY }
805837

806-
if (event.pointerId === this.magicpointerid && this.magictool) {
838+
if (
839+
event.pointerId === this.magicpointerid &&
840+
(this.magictool || this.magictooleraser)
841+
) {
807842
console.log(
808843
'magic pointerup pointerId:',
809844
event.pointerId,
@@ -831,14 +866,34 @@ export class BlackboardNotepad extends Component {
831866
tb.reactivate()
832867
}
833868
delete this.magicpointerid
869+
const cleanup = () => {
870+
if (this.magictooleraser) {
871+
this.magictooleraser = false
872+
if (
873+
event.isPrimary &&
874+
this.realblackboard &&
875+
this.realblackboard.current &&
876+
this.addformpictmode === 0 &&
877+
(this.toolsize || this.toolcolor)
878+
)
879+
this.realblackboard.current.setcursor({
880+
mode: 'drawing',
881+
size: this.toolsize,
882+
color: this.toolcolor
883+
})
884+
}
885+
}
834886
if (this.realblackboard && this.realblackboard.current) {
835887
await this.realblackboard.current.finishMagic((pos) => {
836888
if (this.copydeletebox())
837889
this.copydeletebox().reactivate({
838890
x: pos.x,
839891
y: pos.y - this.calcCurpos()
840892
})
893+
cleanup()
841894
})
895+
} else {
896+
cleanup()
842897
}
843898
} else if (event.pointerId in this.pointerdraw === true) {
844899
if (this.notetools()) {

0 commit comments

Comments
 (0)