@@ -218,9 +218,6 @@ class PaintManager {
218218
219219 // Cancel any pending text placement
220220 this . cancelTextPlacement ( ) ;
221-
222- // Update brush cursor visibility
223- this . updateBrushCursorVisibility ( ) ;
224221 }
225222
226223 createBrushCursor ( ) {
@@ -259,54 +256,54 @@ class PaintManager {
259256 this . brushCursor . style . height = size + 'px' ;
260257 }
261258
262- updateBrushCursorVisibility ( ) {
263- if ( ! this . brushCursor ) return ;
264-
265- if ( this . currentTool === 'brush' || this . currentTool === 'eraser' ) {
266- this . brushCursor . style . display = 'block' ;
267- this . canvas . style . cursor = 'none' ;
268- } else {
269- this . brushCursor . style . display = 'none' ;
270- this . canvas . style . cursor = 'default' ;
271- }
272- }
273-
274259 updateBrushCursor ( e ) {
275260 if ( ! this . brushCursor ) return ;
276261
277262 if ( this . currentTool === 'brush' || this . currentTool === 'eraser' ) {
278- this . brushCursor . style . display = 'block' ;
279- this . canvas . style . cursor = 'none' ;
280-
281- // Store the pending position
282- this . pendingCursorX = e . clientX ;
283- this . pendingCursorY = e . clientY ;
284-
285- // Schedule update using requestAnimationFrame for smooth movement
286- if ( ! this . cursorUpdateScheduled ) {
287- this . cursorUpdateScheduled = true ;
288- requestAnimationFrame ( ( ) => {
289- this . brushCursor . style . transform = `translate(${ this . pendingCursorX } px, ${ this . pendingCursorY } px) translate(-50%, -50%)` ;
290- this . cursorUpdateScheduled = false ;
291- } ) ;
292- }
263+ // Check if mouse is within canvas bounds
264+ const rect = this . canvas . getBoundingClientRect ( ) ;
265+ const isInCanvas = e . clientX >= rect . left &&
266+ e . clientX <= rect . right &&
267+ e . clientY >= rect . top &&
268+ e . clientY <= rect . bottom ;
269+
270+ if ( isInCanvas ) {
271+ this . brushCursor . style . display = 'block' ;
272+ this . canvas . style . cursor = 'none' ;
273+
274+ // Store the pending position
275+ this . pendingCursorX = e . clientX ;
276+ this . pendingCursorY = e . clientY ;
277+
278+ // Schedule update using requestAnimationFrame for smooth movement
279+ if ( ! this . cursorUpdateScheduled ) {
280+ this . cursorUpdateScheduled = true ;
281+ requestAnimationFrame ( ( ) => {
282+ this . brushCursor . style . transform = `translate(${ this . pendingCursorX } px, ${ this . pendingCursorY } px) translate(-50%, -50%)` ;
283+ this . cursorUpdateScheduled = false ;
284+ } ) ;
285+ }
293286
294- // Update color to match brush or show white for eraser (only needs to happen once or when tool changes)
295- if ( this . currentTool === 'eraser' ) {
296- if ( this . brushCursor . getAttribute ( 'data-tool' ) !== 'eraser' ) {
297- this . brushCursor . style . border = '2px solid rgba(255, 0, 0, 0.7)' ;
298- this . brushCursor . style . backgroundColor = 'rgba(255, 255, 255, 0.2)' ;
299- this . brushCursor . style . boxShadow = 'none' ;
300- this . brushCursor . setAttribute ( 'data-tool' , 'eraser' ) ;
287+ // Update color to match brush or show white for eraser (only needs to happen once or when tool changes)
288+ if ( this . currentTool === 'eraser' ) {
289+ if ( this . brushCursor . getAttribute ( 'data-tool' ) !== 'eraser' ) {
290+ this . brushCursor . style . border = '2px solid rgba(255, 0, 0, 0.7)' ;
291+ this . brushCursor . style . backgroundColor = 'rgba(255, 255, 255, 0.2)' ;
292+ this . brushCursor . style . boxShadow = 'none' ;
293+ this . brushCursor . setAttribute ( 'data-tool' , 'eraser' ) ;
294+ }
295+ } else {
296+ if ( this . brushCursor . getAttribute ( 'data-tool' ) !== 'brush' ) {
297+ // Use a contrasting border - white with black outline for visibility
298+ this . brushCursor . style . border = '1px solid white' ;
299+ this . brushCursor . style . boxShadow = '0 0 0 1px black, inset 0 0 0 1px black' ;
300+ this . brushCursor . style . backgroundColor = 'transparent' ;
301+ this . brushCursor . setAttribute ( 'data-tool' , 'brush' ) ;
302+ }
301303 }
302304 } else {
303- if ( this . brushCursor . getAttribute ( 'data-tool' ) !== 'brush' ) {
304- // Use a contrasting border - white with black outline for visibility
305- this . brushCursor . style . border = '1px solid white' ;
306- this . brushCursor . style . boxShadow = '0 0 0 1px black, inset 0 0 0 1px black' ;
307- this . brushCursor . style . backgroundColor = 'transparent' ;
308- this . brushCursor . setAttribute ( 'data-tool' , 'brush' ) ;
309- }
305+ // Hide cursor when outside canvas
306+ this . brushCursor . style . display = 'none' ;
310307 }
311308 }
312309 }
0 commit comments