@@ -2,36 +2,36 @@ import paper from '@scratch/paper';
22import log from '../../log/log' ;
33import BroadBrushHelper from './broad-brush-helper' ;
44import SegmentBrushHelper from './segment-brush-helper' ;
5- import { MIXED , styleCursorPreview } from '../../helper/style-path' ;
6- import { clearSelection , getItems } from '../../helper/selection' ;
7- import { getGuideLayer , setGuideItem } from '../../helper/layer' ;
8- import { isCompoundPathChild } from '../compound-path' ;
5+ import { MIXED , styleCursorPreview } from '../../helper/style-path' ;
6+ import { clearSelection , getItems } from '../../helper/selection' ;
7+ import { getGuideLayer , setGuideItem } from '../../helper/layer' ;
8+ import { isCompoundPathChild } from '../compound-path' ;
99
1010/**
1111 * Shared code for the brush and eraser mode. Adds functions on the paper tool object
1212 * to handle mouse events, which are delegated to broad-brush-helper and segment-brush-helper
1313 * based on the brushSize in the state.
1414 */
1515class Blobbiness {
16- static get BROAD ( ) {
16+ static get BROAD ( ) {
1717 return 'broadbrush' ;
1818 }
19- static get SEGMENT ( ) {
19+ static get SEGMENT ( ) {
2020 return 'segmentbrush' ;
2121 }
2222
2323 // If brush size >= threshold use segment brush, else use broadbrush
2424 // Segment brush has performance issues at low threshold, but broad brush has weird corners
2525 // which get more obvious the bigger it is
26- static get THRESHOLD ( ) {
26+ static get THRESHOLD ( ) {
2727 return 30 / paper . view . zoom ;
2828 }
2929
3030 /**
3131 * @param {function } onUpdateImage call when the drawing has changed to let listeners know
3232 * @param {function } clearSelectedItems Callback to clear the set of selected items in the Redux state
3333 */
34- constructor ( onUpdateImage , clearSelectedItems ) {
34+ constructor ( onUpdateImage , clearSelectedItems ) {
3535 this . broadBrushHelper = new BroadBrushHelper ( ) ;
3636 this . segmentBrushHelper = new SegmentBrushHelper ( ) ;
3737 this . onUpdateImage = onUpdateImage ;
@@ -53,7 +53,7 @@ class Blobbiness {
5353 * @param {?string } options.strokeColor Color of the brush outline.
5454 * @param {?number } options.strokeWidth Width of the brush outline.
5555 */
56- setOptions ( options ) {
56+ setOptions ( options ) {
5757 const oldFillColor = this . options ? this . options . fillColor : 'black' ;
5858 const oldStrokeColor = this . options ? this . options . strokeColor : null ;
5959 const oldStrokeWidth = this . options ? this . options . strokeWidth : null ;
@@ -67,6 +67,7 @@ class Blobbiness {
6767 strokeWidth : options . strokeWidth === null ? oldStrokeWidth : options . strokeWidth
6868 } ;
6969 this . resizeCursorIfNeeded ( ) ;
70+
7071 }
7172
7273 /**
@@ -79,14 +80,15 @@ class Blobbiness {
7980 * @param {?string } options.strokeColor Color of the brush outline.
8081 * @param {?number } options.strokeWidth Width of the brush outline.
8182 */
82- activateTool ( options ) {
83+ activateTool ( options ) {
8384 this . tool = new paper . Tool ( ) ;
8485 this . cursorPreviewLastPoint = new paper . Point ( - 10000 , - 10000 ) ;
8586 this . setOptions ( options ) ;
8687 this . tool . active = false ;
8788 this . tool . fixedDistance = 1 ;
8889
8990 const blob = this ;
91+
9092 this . tool . onMouseMove = function ( event ) {
9193 blob . resizeCursorIfNeeded ( event . point ) ;
9294 styleCursorPreview ( blob . cursorPreview , blob . options ) ;
@@ -125,6 +127,7 @@ class Blobbiness {
125127 } ;
126128
127129 this . tool . onMouseUp = function ( event ) {
130+
128131 if ( event . event . button > 0 || ! this . active ) return ; // only first mouse button
129132
130133 let lastPath ;
@@ -155,7 +158,7 @@ class Blobbiness {
155158 this . tool . activate ( ) ;
156159 }
157160
158- resizeCursorIfNeeded ( point ) {
161+ resizeCursorIfNeeded ( point ) {
159162 if ( ! this . options ) {
160163 return ;
161164 }
@@ -165,10 +168,10 @@ class Blobbiness {
165168 this . cursorPreview = null ;
166169 }
167170 if ( this . cursorPreview &&
168- this . brushSize === this . options . brushSize &&
169- this . fillColor === this . options . fillColor &&
170- this . strokeColor === this . options . strokeColor &&
171- this . cursorPreviewLastPoint . equals ( point ) ) {
171+ this . brushSize === this . options . brushSize &&
172+ this . fillColor === this . options . fillColor &&
173+ this . strokeColor === this . options . strokeColor &&
174+ this . cursorPreviewLastPoint . equals ( point ) ) {
172175 return ;
173176 }
174177 if ( typeof point !== 'undefined' ) {
@@ -192,7 +195,7 @@ class Blobbiness {
192195 styleCursorPreview ( this . cursorPreview , this . options ) ;
193196 }
194197
195- mergeBrush ( lastPath ) {
198+ mergeBrush ( lastPath ) {
196199 const blob = this ;
197200
198201 // Get all path items to merge with
@@ -243,7 +246,7 @@ class Blobbiness {
243246 }
244247 }
245248
246- mergeEraser ( lastPath ) {
249+ mergeEraser ( lastPath ) {
247250 const blob = this ;
248251
249252 // Get all path items to merge with
@@ -336,7 +339,7 @@ class Blobbiness {
336339 lastPath . remove ( ) ;
337340 }
338341
339- separateCompoundPath ( compoundPath ) {
342+ separateCompoundPath ( compoundPath ) {
340343 if ( ! compoundPath . isClockwise ( ) ) {
341344 compoundPath . reverse ( ) ;
342345 }
@@ -381,35 +384,35 @@ class Blobbiness {
381384 }
382385 }
383386
384- colorMatch ( existingPath , addedPath ) {
387+ colorMatch ( existingPath , addedPath ) {
385388 // Note: transparent fill colors do notdetect as touching
386389 return existingPath . getFillColor ( ) . equals ( addedPath . getFillColor ( ) ) &&
387- ( addedPath . getStrokeColor ( ) === existingPath . getStrokeColor ( ) || // both null
388- ( addedPath . getStrokeColor ( ) &&
389- addedPath . getStrokeColor ( ) . equals ( existingPath . getStrokeColor ( ) ) ) ) &&
390- addedPath . getStrokeWidth ( ) === existingPath . getStrokeWidth ( ) &&
391- this . touches ( existingPath , addedPath ) ;
390+ ( addedPath . getStrokeColor ( ) === existingPath . getStrokeColor ( ) || // both null
391+ ( addedPath . getStrokeColor ( ) &&
392+ addedPath . getStrokeColor ( ) . equals ( existingPath . getStrokeColor ( ) ) ) ) &&
393+ addedPath . getStrokeWidth ( ) === existingPath . getStrokeWidth ( ) &&
394+ this . touches ( existingPath , addedPath ) ;
392395 }
393396
394- touches ( path1 , path2 ) {
397+ touches ( path1 , path2 ) {
395398 // Two shapes are touching if their paths intersect
396399 if ( path1 && path2 && path1 . intersects ( path2 ) ) {
397400 return true ;
398401 }
399402 return this . firstEnclosesSecond ( path1 , path2 ) || this . firstEnclosesSecond ( path2 , path1 ) ;
400403 }
401404
402- firstEnclosesSecond ( path1 , path2 ) {
405+ firstEnclosesSecond ( path1 , path2 ) {
403406 // Two shapes are also touching if one is completely inside the other
404407 if ( path1 && path2 && path2 . firstSegment && path2 . firstSegment . point &&
405- path1 . hitTest ( path2 . firstSegment . point ) ) {
408+ path1 . hitTest ( path2 . firstSegment . point ) ) {
406409 return true ;
407410 }
408411 // TODO: clean up these no point paths
409412 return false ;
410413 }
411414
412- matchesAnyChild ( group , path ) {
415+ matchesAnyChild ( group , path ) {
413416 for ( const child of group . children ) {
414417 if ( child . children && this . matchesAnyChild ( path , child ) ) {
415418 return true ;
@@ -421,7 +424,7 @@ class Blobbiness {
421424 return false ;
422425 }
423426
424- isMergeable ( newPath , existingPath ) {
427+ isMergeable ( newPath , existingPath ) {
425428 // Path or compound path
426429 if ( ! ( existingPath instanceof paper . PathItem ) ) {
427430 return ;
@@ -434,7 +437,7 @@ class Blobbiness {
434437 return existingPath !== newPath ; // don't merge with self
435438 }
436439
437- deactivateTool ( ) {
440+ deactivateTool ( ) {
438441 if ( this . cursorPreview ) {
439442 this . cursorPreview . remove ( ) ;
440443 this . cursorPreview = null ;
0 commit comments