Skip to content

The VS Code of video editing, built for agents.

TypeScript

Enhance Object Mask Bar and Interaction Logic

konstantin-paulus7e788582a467
diff --git a/apps/web/src/components/canvas/object-mask-bar.tsx b/apps/web/src/components/canvas/object-mask-bar.tsx
index 55e1087a..8ae83798 100644
--- a/apps/web/src/components/canvas/object-mask-bar.tsx
+++ b/apps/web/src/components/canvas/object-mask-bar.tsx
@@ -122,7 +122,7 @@ export function ObjectMaskBar() {
<ModelMenu disabled={busy()} />
<Separator orientation="vertical" class="min-h-5" />
<ModePopover />
- <OpMenu />
+ <OpMenu disabled={objectMaskMode() === "brush"} />
<Separator orientation="vertical" class="min-h-5" />
<Tooltip>
<TooltipTrigger as={Button} variant="ghost" class="text-muted-foreground" onClick={() => cancelObjectMask(world)}>
@@ -293,10 +293,10 @@ function ModePopover() {
}
/** Whether clicks add to the object or subtract from it; the button shows the op alt swaps in while held. */
-function OpMenu() {
+function OpMenu(props: { disabled: boolean }) {
const world = useWorld();
const held = useDerived(() => heldObjectMaskOp(world));
- const op = () => OPS.find((entry) => entry.value === held()) ?? OPS[0];
+ const op = () => (props.disabled ? OPS[0] : OPS.find((entry) => entry.value === held()) ?? OPS[0]);
return (
<DropdownMenu placement="top-start" gutter={8}>
@@ -305,6 +305,7 @@ function OpMenu() {
as={(triggerProps: object) => (
<DropdownMenuTrigger<typeof Button>
{...triggerProps}
+ disabled={props.disabled}
as={(buttonProps) => (
<Button {...buttonProps} variant="ghost" class="gap-0 pl-0.5 text-muted-foreground">
<Icon name={op().icon} />
diff --git a/apps/web/src/engine/object-mask/interaction.ts b/apps/web/src/engine/object-mask/interaction.ts
index b8a793aa..80113321 100644
--- a/apps/web/src/engine/object-mask/interaction.ts
+++ b/apps/web/src/engine/object-mask/interaction.ts
@@ -19,9 +19,10 @@ const CLICK_DISTANCE = 4;
/**
* The handler for the region the HUD lays over the tool's clip. With points,
- * a click prompts the object under the pointer; with the brush, a drag paints
- * it into the mask. Either adds to the object or subtracts from it, as the
- * tool's op says; alt or shift held swaps the op.
+ * a click prompts the object under the pointer, adding to it or subtracting
+ * from it as the tool's op says (alt or shift held swaps the op); with the
+ * brush, a drag paints what the model missed into the mask. The brush only
+ * adds: taking away is left to points.
*/
export function handleObjectMaskInteraction(world: World, event: DispatchedPointerEvent): void {
if (objectMaskMode() === 'brush') {
@@ -44,12 +45,12 @@ export function handleObjectMaskInteraction(world: World, event: DispatchedPoint
promptObjectMask(world, clip, { ...point, label: heldObjectMaskLabel(world) });
}
-/** A press starts a stroke on the video, every move until the release carries it on. */
+/** A press starts an adding stroke on the video, every move until the release carries it on. */
function handleBrush(world: World, event: DispatchedPointerEvent): void {
switch (event.type) {
case 'dragstart':
if (event.target.kind !== 'hud' || !event.target.entity) return;
- beginMaskStroke(world, event.target.entity, event.clientX, event.clientY, heldObjectMaskLabel(world));
+ beginMaskStroke(world, event.target.entity, event.clientX, event.clientY, 1);
return;
case 'drag':
extendMaskStroke(world, event.clientX, event.clientY);
diff --git a/apps/web/src/engine/object-mask/overlay.ts b/apps/web/src/engine/object-mask/overlay.ts
index bd4385dc..af7bddd5 100644
--- a/apps/web/src/engine/object-mask/overlay.ts
+++ b/apps/web/src/engine/object-mask/overlay.ts
@@ -196,7 +196,7 @@ function drawMask(ctx: Ctx2D, rect: VideoRect, mask: Sam2Mask | MaskFrame, size:
/**
* The brush's outline under the pointer, round on the footage, while there is
- * a mask on the clip to correct: red when it erases, as a background point is.
+ * a mask on the clip to correct.
*/
function drawBrush(world: World, ctx: Ctx2D, target: { clip: Entity; rect: VideoRect }, resolution: number): void {
const pointer = world.get(Pointer);
@@ -219,7 +219,7 @@ function drawBrush(world: World, ctx: Ctx2D, target: { clip: Entity; rect: Video
ctx.strokeStyle = 'rgba(0, 0, 0, 0.4)';
ctx.stroke();
ctx.lineWidth = 1.5 * resolution;
- ctx.strokeStyle = heldObjectMaskLabel(world) === 0 ? BACKGROUND_POINT : '#FFFFFF';
+ ctx.strokeStyle = '#FFFFFF';
ctx.stroke();
ctx.restore();
}