fix(ui): brush preview fill for inpaint/region

This commit is contained in:
psychedelicious 2024-08-06 13:43:32 +10:00
parent f4de2fd3b1
commit d8e3708e0f
3 changed files with 32 additions and 19 deletions

View File

@ -23,18 +23,19 @@ import {
} from 'features/controlLayers/konva/util'; } from 'features/controlLayers/konva/util';
import type { Extents, ExtentsResult, GetBboxTask, WorkerLogMessage } from 'features/controlLayers/konva/worker'; import type { Extents, ExtentsResult, GetBboxTask, WorkerLogMessage } from 'features/controlLayers/konva/worker';
import { $lastProgressEvent, $shouldShowStagedImage } from 'features/controlLayers/store/canvasV2Slice'; import { $lastProgressEvent, $shouldShowStagedImage } from 'features/controlLayers/store/canvasV2Slice';
import type { import {
CanvasControlAdapterState, type CanvasControlAdapterState,
CanvasEntityIdentifier, type CanvasEntityIdentifier,
CanvasEntityState, type CanvasEntityState,
CanvasInpaintMaskState, type CanvasInpaintMaskState,
CanvasLayerState, type CanvasLayerState,
CanvasRegionalGuidanceState, type CanvasRegionalGuidanceState,
CanvasV2State, type CanvasV2State,
Coordinate, type Coordinate,
GenerationMode, type GenerationMode,
GetLoggingContext, type GetLoggingContext,
RgbaColor, RGBA_WHITE,
type RgbaColor,
} from 'features/controlLayers/store/types'; } from 'features/controlLayers/store/types';
import type Konva from 'konva'; import type Konva from 'konva';
import { atom } from 'nanostores'; import { atom } from 'nanostores';
@ -366,11 +367,22 @@ export class CanvasManager {
let currentFill: RgbaColor = state.tool.fill; let currentFill: RgbaColor = state.tool.fill;
const selectedEntity = this.getSelectedEntity(); const selectedEntity = this.getSelectedEntity();
if (selectedEntity) { if (selectedEntity) {
// These two entity types use a compositing rect for opacity. Their alpha is always 1. // These two entity types use a compositing rect for opacity. Their fill is always white.
if (selectedEntity.state.type === 'regional_guidance') { if (selectedEntity.state.type === 'regional_guidance' || selectedEntity.state.type === 'inpaint_mask') {
currentFill = { ...selectedEntity.state.fill, a: 1 }; currentFill = RGBA_WHITE;
} else if (selectedEntity.state.type === 'inpaint_mask') { }
currentFill = { ...state.inpaintMask.fill, a: 1 }; }
return currentFill;
};
getBrushPreviewFill = () => {
const state = this.stateApi.getState();
let currentFill: RgbaColor = state.tool.fill;
const selectedEntity = this.getSelectedEntity();
if (selectedEntity) {
// The brush should use the mask opacity for these entity types
if (selectedEntity.state.type === 'regional_guidance' || selectedEntity.state.type === 'inpaint_mask') {
currentFill = { ...selectedEntity.state.fill, a: this.stateApi.getSettings().maskOpacity };
} }
} }
return currentFill; return currentFill;

View File

@ -127,7 +127,6 @@ export class CanvasTool {
const stage = this.manager.stage; const stage = this.manager.stage;
const renderedEntityCount: number = 1; // TODO(psyche): this.manager should be renderable entity count const renderedEntityCount: number = 1; // TODO(psyche): this.manager should be renderable entity count
const toolState = this.manager.stateApi.getToolState(); const toolState = this.manager.stateApi.getToolState();
const currentFill = this.manager.getCurrentFill();
const selectedEntity = this.manager.getSelectedEntity(); const selectedEntity = this.manager.getSelectedEntity();
const cursorPos = this.manager.stateApi.$lastCursorPos.get(); const cursorPos = this.manager.stateApi.$lastCursorPos.get();
const isDrawing = this.manager.stateApi.$isDrawing.get(); const isDrawing = this.manager.stateApi.$isDrawing.get();
@ -172,6 +171,7 @@ export class CanvasTool {
// No need to render the brush preview if the cursor position or color is missing // No need to render the brush preview if the cursor position or color is missing
if (cursorPos && tool === 'brush') { if (cursorPos && tool === 'brush') {
const brushPreviewFill = this.manager.getBrushPreviewFill();
const alignedCursorPos = alignCoordForTool(cursorPos, toolState.brush.width); const alignedCursorPos = alignCoordForTool(cursorPos, toolState.brush.width);
const scale = stage.scaleX(); const scale = stage.scaleX();
// Update the fill circle // Update the fill circle
@ -181,7 +181,7 @@ export class CanvasTool {
x: alignedCursorPos.x, x: alignedCursorPos.x,
y: alignedCursorPos.y, y: alignedCursorPos.y,
radius, radius,
fill: isDrawing ? '' : rgbaColorToString(currentFill), fill: isDrawing ? '' : rgbaColorToString(brushPreviewFill),
}); });
// Update the inner border of the brush preview // Update the inner border of the brush preview

View File

@ -503,6 +503,7 @@ const zRgbaColor = zRgbColor.extend({
}); });
export type RgbaColor = z.infer<typeof zRgbaColor>; export type RgbaColor = z.infer<typeof zRgbaColor>;
export const RGBA_RED: RgbaColor = { r: 255, g: 0, b: 0, a: 1 }; export const RGBA_RED: RgbaColor = { r: 255, g: 0, b: 0, a: 1 };
export const RGBA_WHITE: RgbaColor = { r: 255, g: 255, b: 255, a: 1 };
const zOpacity = z.number().gte(0).lte(1); const zOpacity = z.number().gte(0).lte(1);