@@ -72,6 +72,12 @@ export class Brush extends AbstractComponent<Required<BrushAttributes>> {
7272 * 3. 如果是绘制状态: 标记绘制状态 & 标记正在绘制的mask & 清除之前的mask & 添加新的mask
7373 */
7474 private _onBrushStart = ( e : FederatedPointerEvent ) => {
75+ if ( this . attribute . interactive === false ) {
76+ return ;
77+ }
78+ if ( this . _beforeBrushEvent ( e ) === false ) {
79+ return ;
80+ }
7581 const {
7682 updateTrigger = DEFAULT_BRUSH_ATTRIBUTES . updateTrigger ,
7783 endTrigger = DEFAULT_BRUSH_ATTRIBUTES . endTrigger ,
@@ -95,6 +101,13 @@ export class Brush extends AbstractComponent<Required<BrushAttributes>> {
95101 * 2. 如果是移动状态: 标记移动状态 & 计算位移量 & 给被移动的mask偏移属性
96102 */
97103 private _onBrushing = ( e : FederatedPointerEvent ) => {
104+ if ( this . attribute . interactive === false ) {
105+ return ;
106+ }
107+ if ( this . _beforeBrushEvent ( e ) === false ) {
108+ return ;
109+ }
110+
98111 if ( this . _outOfInteractiveRange ( e ) ) {
99112 return ;
100113 }
@@ -119,6 +132,9 @@ export class Brush extends AbstractComponent<Required<BrushAttributes>> {
119132 * @description 取消绘制 和 移动 状态
120133 */
121134 private _onBrushEnd = ( e : FederatedPointerEvent ) => {
135+ if ( this . attribute . interactive === false ) {
136+ return ;
137+ }
122138 this . _releaseBrushUpdateEvents ( ) ;
123139 e . preventDefault ( ) ;
124140 this . _activeDrawState && this . _drawEnd ( e ) ;
@@ -129,6 +145,12 @@ export class Brush extends AbstractComponent<Required<BrushAttributes>> {
129145 } ;
130146
131147 private _onBrushClear = ( e : FederatedPointerEvent ) => {
148+ if ( this . attribute . interactive === false ) {
149+ return ;
150+ }
151+ if ( this . _beforeBrushEvent ( e ) === false ) {
152+ return ;
153+ }
132154 e . preventDefault ( ) ;
133155 if ( ! this . _isEmptyMask ( ) ) {
134156 this . _clearMask ( ) ;
@@ -143,6 +165,9 @@ export class Brush extends AbstractComponent<Required<BrushAttributes>> {
143165 * @description 清除之前的mask & 添加新的mask
144166 */
145167 private _initDraw ( e : FederatedPointerEvent ) {
168+ if ( this . attribute . interactive === false ) {
169+ return ;
170+ }
146171 const { brushMode } = this . attribute as BrushAttributes ;
147172 const pos = this . eventPosToStagePos ( e ) ;
148173
@@ -158,6 +183,9 @@ export class Brush extends AbstractComponent<Required<BrushAttributes>> {
158183 * @description 初始化mask的dx和dy
159184 */
160185 private _initMove ( e : FederatedPointerEvent ) {
186+ if ( this . attribute . interactive === false ) {
187+ return ;
188+ }
161189 this . _cacheMovePoint = this . eventPosToStagePos ( e ) ;
162190
163191 this . _operatingMaskMoveDx = this . _operatingMask . attribute . dx ?? 0 ;
@@ -185,6 +213,9 @@ export class Brush extends AbstractComponent<Required<BrushAttributes>> {
185213 * @description 更新_cacheDrawPoints 和 mask的points属性
186214 */
187215 private _drawing ( e : FederatedPointerEvent ) {
216+ if ( this . attribute . interactive === false ) {
217+ return ;
218+ }
188219 const pos = this . eventPosToStagePos ( e ) ;
189220 const { brushType, sizeThreshold = DEFAULT_SIZE_THRESHOLD } = this . attribute as BrushAttributes ;
190221
@@ -227,6 +258,9 @@ export class Brush extends AbstractComponent<Required<BrushAttributes>> {
227258 * @description 标记移动状态 & 计算位移量 & 给被移动的mask偏移属性
228259 */
229260 private _moving ( e : FederatedPointerEvent ) {
261+ if ( this . attribute . interactive === false ) {
262+ return ;
263+ }
230264 const startPos = this . _cacheMovePoint ;
231265 const pos = this . eventPosToStagePos ( e ) ;
232266 // 如果当前点的位置和上一次点的位置一致,则无需更新
@@ -252,6 +286,9 @@ export class Brush extends AbstractComponent<Required<BrushAttributes>> {
252286 }
253287
254288 private _drawEnd ( e : FederatedPointerEvent ) {
289+ if ( this . attribute . interactive === false ) {
290+ return ;
291+ }
255292 const { removeOnClick = true , sizeThreshold = DEFAULT_SIZE_THRESHOLD } = this . attribute as BrushAttributes ;
256293 if ( this . _outOfInteractiveRange ( e ) ) {
257294 if ( ! this . _isEmptyMask ( ) ) {
@@ -290,6 +327,9 @@ export class Brush extends AbstractComponent<Required<BrushAttributes>> {
290327 }
291328
292329 private _moveEnd ( e : FederatedPointerEvent ) {
330+ if ( this . attribute . interactive === false ) {
331+ return ;
332+ }
293333 if ( this . _operatingMask ) {
294334 this . _operatingMask . setAttribute ( 'pickable' , false ) ;
295335 }
@@ -442,6 +482,14 @@ export class Brush extends AbstractComponent<Required<BrushAttributes>> {
442482 return false ;
443483 }
444484
485+ /**
486+ * 触发框选前事件
487+ * @returns 返回 false 表示中断后续逻辑,返回 true 或 undefined 表示继续执行
488+ */
489+ private _beforeBrushEvent ( e : FederatedPointerEvent ) : void | boolean {
490+ return this . attribute . beforeBrushChange ?.( e ) ;
491+ }
492+
445493 /**
446494 * 根据操作类型触发对应的事件
447495 */
0 commit comments