feat: add magic wand tool with settings and controls, including UI integration and functionality
This commit is contained in:
@@ -3,7 +3,7 @@ import type { Vec2D } from "@core/geometry";
|
||||
import type { LayerId, ArtboardId, AssetId } from "@core/id";
|
||||
import type { Layer } from "@core/layer";
|
||||
import type { MaskViewMode } from "@editor/state";
|
||||
import type { BrushSettings, ChromaKeySettings, ToolId } from "@editor/tools";
|
||||
import type { BrushSettings, ChromaKeySettings, MagicWandSettings, ToolId } from "@editor/tools";
|
||||
import type { Command } from "./command";
|
||||
import { commandIds } from "./ids";
|
||||
|
||||
@@ -15,6 +15,8 @@ export type ToolSetBrushSettingsPayload = Partial<BrushSettings>;
|
||||
|
||||
export type ToolSetChromaKeySettingsPayload = Partial<ChromaKeySettings>;
|
||||
|
||||
export type ToolSetMagicWandSettingsPayload = Partial<MagicWandSettings>;
|
||||
|
||||
export type ToolSetBrushPreviewPayload = { position: Vec2D } | undefined;
|
||||
|
||||
export type ToolSetBrushStrokePreviewPayload =
|
||||
@@ -100,6 +102,30 @@ export const toolSetChromaKeySettingsCommand: Command<ToolSetChromaKeySettingsPa
|
||||
},
|
||||
};
|
||||
|
||||
export const toolSetMagicWandSettingsCommand: Command<ToolSetMagicWandSettingsPayload> = {
|
||||
id: commandIds.toolSetMagicWandSettings,
|
||||
name: "Set magic wand settings",
|
||||
execute({ state }, payload) {
|
||||
return {
|
||||
...state,
|
||||
editor: {
|
||||
...state.editor,
|
||||
tools: {
|
||||
...state.editor.tools,
|
||||
magicWand: {
|
||||
tolerance: clampNumber(payload.tolerance ?? state.editor.tools.magicWand.tolerance, 0, 255),
|
||||
feather: clampNumber(payload.feather ?? state.editor.tools.magicWand.feather, 0, 20),
|
||||
choke: clampNumber(payload.choke ?? state.editor.tools.magicWand.choke, -20, 20),
|
||||
despeckle: clampNumber(payload.despeckle ?? state.editor.tools.magicWand.despeckle, 0, 20),
|
||||
contiguous: payload.contiguous ?? state.editor.tools.magicWand.contiguous,
|
||||
mode: payload.mode ?? state.editor.tools.magicWand.mode,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
export const toolSetBrushPreviewCommand: Command<ToolSetBrushPreviewPayload> = {
|
||||
id: commandIds.toolSetBrushPreview,
|
||||
name: "Set brush preview",
|
||||
@@ -250,6 +276,7 @@ export const toolCommands = [
|
||||
toolSetActiveCommand,
|
||||
toolSetBrushSettingsCommand,
|
||||
toolSetChromaKeySettingsCommand,
|
||||
toolSetMagicWandSettingsCommand,
|
||||
toolSetBrushPreviewCommand,
|
||||
toolSetBrushStrokePreviewCommand,
|
||||
toolSetMaskViewModeCommand,
|
||||
|
||||
Reference in New Issue
Block a user