diff --git a/invokeai/frontend/web/src/features/controlLayers/components/TransformToolButton.tsx b/invokeai/frontend/web/src/features/controlLayers/components/TransformToolButton.tsx index cf70f59ee9..14ac66706f 100644 --- a/invokeai/frontend/web/src/features/controlLayers/components/TransformToolButton.tsx +++ b/invokeai/frontend/web/src/features/controlLayers/components/TransformToolButton.tsx @@ -19,10 +19,7 @@ export const TransformToolButton = memo(() => { if (!canvasManager) { return; } - canvasManager.onTransform = setIsTransforming; - return () => { - canvasManager.onTransform = null; - }; + return canvasManager.isTransforming.subscribe(setIsTransforming); }, [canvasManager]); const onTransform = useCallback(() => { diff --git a/invokeai/frontend/web/src/features/controlLayers/konva/CanvasManager.ts b/invokeai/frontend/web/src/features/controlLayers/konva/CanvasManager.ts index 0f93253454..b4236cb043 100644 --- a/invokeai/frontend/web/src/features/controlLayers/konva/CanvasManager.ts +++ b/invokeai/frontend/web/src/features/controlLayers/konva/CanvasManager.ts @@ -124,7 +124,7 @@ export class CanvasManager { _isDebugging: boolean; - onTransform: ((isTransforming: boolean) => void) | null; + isTransforming: PubSub; _store: Store; _isFirstRender: boolean; @@ -212,16 +212,16 @@ export class CanvasManager { this._worker.onmessageerror = () => { this.log.error('Worker message error'); }; - this.onTransform = null; this._isDebugging = false; - this.toolState = new PubSub(this.stateApi.getToolState()); - this.currentFill = new PubSub(this.getCurrentFill()); - this.selectedEntityIdentifier = new PubSub( + this.isTransforming = new PubSub(false); + this.toolState = new PubSub(this.stateApi.getToolState()); + this.currentFill = new PubSub(this.getCurrentFill()); + this.selectedEntityIdentifier = new PubSub( this.stateApi.getState().selectedEntityIdentifier, (a, b) => a?.id === b?.id ); - this.selectedEntity = new PubSub( + this.selectedEntity = new PubSub( this.getSelectedEntity(), (a, b) => a?.state === b?.state && a?.adapter === b?.adapter ); @@ -399,7 +399,7 @@ export class CanvasManager { // TODO(psyche): Support other entity types assert(layer?.adapter instanceof CanvasLayer, 'No selected layer'); layer.adapter.transformer.startTransform(); - this.onTransform?.(true); + this.isTransforming.publish(true); } async applyTransform() { @@ -407,7 +407,7 @@ export class CanvasManager { if (layer) { await layer.transformer.applyTransform(); } - this.onTransform?.(false); + this.isTransforming.publish(false); } cancelTransform() { @@ -415,7 +415,7 @@ export class CanvasManager { if (layer) { layer.transformer.stopTransform(); } - this.onTransform?.(false); + this.isTransforming.publish(false); } render = async () => { @@ -451,11 +451,6 @@ export class CanvasManager { } } - this.toolState.publish(state.tool); - this.selectedEntityIdentifier.publish(state.selectedEntityIdentifier); - this.selectedEntity.publish(this.getSelectedEntity()); - this.currentFill.publish(this.getCurrentFill()); - if ( this._isFirstRender || state.initialImage !== this._prevState.initialImage || @@ -499,6 +494,11 @@ export class CanvasManager { await this.renderControlAdapters(); } + this.toolState.publish(state.tool); + this.selectedEntityIdentifier.publish(state.selectedEntityIdentifier); + this.selectedEntity.publish(this.getSelectedEntity()); + this.currentFill.publish(this.getCurrentFill()); + if ( this._isFirstRender || state.bbox !== this._prevState.bbox || diff --git a/invokeai/frontend/web/src/features/controlLayers/konva/CanvasTool.ts b/invokeai/frontend/web/src/features/controlLayers/konva/CanvasTool.ts index 742ac5ad80..ff71ebfda2 100644 --- a/invokeai/frontend/web/src/features/controlLayers/konva/CanvasTool.ts +++ b/invokeai/frontend/web/src/features/controlLayers/konva/CanvasTool.ts @@ -161,7 +161,7 @@ export class CanvasTool { } else if (!isDrawableEntity) { // Non-drawable layers don't have tools stage.container().style.cursor = 'not-allowed'; - } else if (tool === 'move' || toolState.isTransforming) { + } else if (tool === 'move' || this.manager.isTransforming.getValue()) { // Move tool gets a pointer stage.container().style.cursor = 'default'; } else if (tool === 'rect') {