@@ -15,7 +15,8 @@ import {
15
15
import type Konva from 'konva' ;
16
16
import type { KonvaEventObject } from 'konva/lib/Node' ;
17
17
import type { Vector2d } from 'konva/lib/types' ;
18
- import { useCallback , useRef } from 'react' ;
18
+ import { clamp } from 'lodash-es' ;
19
+ import { useCallback , useMemo , useRef } from 'react' ;
19
20
20
21
const getIsFocused = ( stage : Konva . Stage ) => {
21
22
return stage . container ( ) . contains ( document . activeElement ) ;
@@ -67,7 +68,9 @@ const syncCursorPos = (stage: Konva.Stage): Vector2d | null => {
67
68
return pos ;
68
69
} ;
69
70
70
- const BRUSH_SPACING = 20 ;
71
+ const BRUSH_SPACING_PCT = 10 ;
72
+ const MIN_BRUSH_SPACING_PX = 5 ;
73
+ const MAX_BRUSH_SPACING_PX = 15 ;
71
74
72
75
export const useMouseEvents = ( ) => {
73
76
const dispatch = useAppDispatch ( ) ;
@@ -83,6 +86,10 @@ export const useMouseEvents = () => {
83
86
const lastCursorPosRef = useRef < [ number , number ] | null > ( null ) ;
84
87
const shouldInvertBrushSizeScrollDirection = useAppSelector ( ( s ) => s . canvas . shouldInvertBrushSizeScrollDirection ) ;
85
88
const brushSize = useAppSelector ( ( s ) => s . controlLayers . present . brushSize ) ;
89
+ const brushSpacingPx = useMemo (
90
+ ( ) => clamp ( brushSize / BRUSH_SPACING_PCT , MIN_BRUSH_SPACING_PX , MAX_BRUSH_SPACING_PX ) ,
91
+ [ brushSize ]
92
+ ) ;
86
93
87
94
const onMouseDown = useCallback (
88
95
( e : KonvaEventObject < MouseEvent > ) => {
@@ -158,7 +165,7 @@ export const useMouseEvents = () => {
158
165
// Continue the last line
159
166
if ( lastCursorPosRef . current ) {
160
167
// Dispatching redux events impacts perf substantially - using brush spacing keeps dispatches to a reasonable number
161
- if ( Math . hypot ( lastCursorPosRef . current [ 0 ] - pos . x , lastCursorPosRef . current [ 1 ] - pos . y ) < BRUSH_SPACING ) {
168
+ if ( Math . hypot ( lastCursorPosRef . current [ 0 ] - pos . x , lastCursorPosRef . current [ 1 ] - pos . y ) < brushSpacingPx ) {
162
169
return ;
163
170
}
164
171
}
@@ -171,7 +178,7 @@ export const useMouseEvents = () => {
171
178
$isDrawing . set ( true ) ;
172
179
}
173
180
} ,
174
- [ dispatch , selectedLayerId , selectedLayerType , tool ]
181
+ [ brushSpacingPx , dispatch , selectedLayerId , selectedLayerType , tool ]
175
182
) ;
176
183
177
184
const onMouseLeave = useCallback (
0 commit comments