-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
140 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
"clonedeep", | ||
"Dists", | ||
"Formatjs", | ||
"IRGB", | ||
"IRGBA", | ||
"isequal", | ||
"outfile", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { cloneDeep, noop } from '@suika/common'; | ||
|
||
import { AddGraphCmd } from '../commands'; | ||
import { type ICursor } from '../cursor_manager'; | ||
import { type Editor } from '../editor'; | ||
import { Path } from '../graphs'; | ||
import { type ITool } from './type'; | ||
|
||
const TYPE = 'pencil'; | ||
const HOTKEY = ''; | ||
|
||
export class PencilTool implements ITool { | ||
static readonly type = TYPE; | ||
static readonly hotkey = HOTKEY; | ||
readonly type = TYPE; | ||
readonly hotkey = HOTKEY; | ||
cursor: ICursor = 'crosshair'; | ||
commandDesc = 'draw by Pencil'; | ||
private unbindEvent: () => void = noop; | ||
|
||
private path: Path | null = null; | ||
private isFirstDrag = true; | ||
|
||
constructor(private editor: Editor) {} | ||
onActive() { | ||
// do nothing | ||
} | ||
onInactive() { | ||
this.unbindEvent(); | ||
} | ||
onMoveExcludeDrag() { | ||
// do nothing | ||
} | ||
|
||
onStart(e: PointerEvent) { | ||
this.path = new Path({ | ||
objectName: '', | ||
width: 0, | ||
height: 0, | ||
pathData: [ | ||
{ | ||
segs: [], | ||
closed: false, | ||
}, | ||
], | ||
stroke: [cloneDeep(this.editor.setting.get('firstStroke'))], | ||
strokeWidth: 3, | ||
}); | ||
|
||
const point = this.editor.getSceneCursorXY(e); | ||
this.path!.addSeg(0, { | ||
point, | ||
in: { x: 0, y: 0 }, | ||
out: { x: 0, y: 0 }, | ||
}); | ||
} | ||
|
||
onDrag(e: PointerEvent) { | ||
const point = this.editor.getSceneCursorXY(e); | ||
this.path!.addSeg(0, { | ||
point, | ||
in: { x: 0, y: 0 }, | ||
out: { x: 0, y: 0 }, | ||
}); | ||
|
||
if (this.isFirstDrag) { | ||
this.editor.sceneGraph.addItems([this.path!]); | ||
this.isFirstDrag = false; | ||
} | ||
this.editor.render(); | ||
} | ||
|
||
onEnd(_e: PointerEvent, isDragHappened: boolean) { | ||
if (isDragHappened) { | ||
this.editor.commandManager.pushCommand( | ||
new AddGraphCmd('Add Path by pencil', this.editor, [this.path!]), | ||
); | ||
} else { | ||
this.editor.sceneGraph.removeItems([this.path!]); | ||
} | ||
} | ||
|
||
afterEnd() { | ||
this.path = null; | ||
this.isFirstDrag = true; | ||
} | ||
|
||
getDragBlockStep() { | ||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import React from 'react'; | ||
|
||
export const PencilOutlined = React.memo(() => { | ||
return ( | ||
<svg | ||
width="24" | ||
height="24" | ||
viewBox="0 0 24 24" | ||
fill="none" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<path | ||
d="M17.6992 9.30076L8.7158 18.2842C8.66927 18.3307 8.61198 18.3651 8.54902 18.3842L5.3017 19.3687C4.99583 19.4615 4.71011 19.1757 4.80285 18.8699L5.78742 15.6226C5.80651 15.5596 5.84084 15.5023 5.88737 15.4558L14.8708 6.47233M17.6992 9.30076L19.8593 7.14071C20.0155 6.9845 20.0155 6.73123 19.8593 6.57502L17.5966 4.31228C17.4403 4.15607 17.1871 4.15607 17.0309 4.31228L14.8708 6.47233M17.6992 9.30076L14.8708 6.47233" | ||
stroke="currentColor" | ||
/> | ||
</svg> | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters