import { Box2, Vector2 } from '../math'; import type { PictureCutConfig } from '../configs/types'; import { Control, type InputEventKey, type InputEventMouseButton, type InputEventMouseMotion } from '@galacean/effects'; import { Gizmo } from '../gizmo'; import { GizmoType } from '../gizmo-type'; import { type GestureCursorResult } from '../cursor'; import { PictureInteractionType, type PictureDirectionScaleParam, type PictureMoveParam, type PictureNoneParam } from './picture-interaction'; import { VFXItem } from '@galacean/effects'; /** * 图片裁切工具结果 */ export type PictureCutResult = { /** 归一化裁切盒,不依赖渲染帧投影。 */ normalizeCutBox: Box2; }; /** * 图片裁切缩放交互参数 */ export type PictureCutScaleParam = { /** 交互类型 */ type: PictureInteractionType.SCALE; /** 裁切框 */ box: Box2; /** 锚点(对角点) */ anchor: Vector2; /** 起始鼠标位置 */ startMouse: Vector2; /** 起始角点 */ startCorner: Vector2; /** 锁定的宽高比 */ lockedAspect?: number; }; /** * 图片裁切交互参数 */ export type PictureCutInteractionParam = PictureNoneParam | PictureCutScaleParam | PictureDirectionScaleParam | PictureMoveParam; /** * 裁剪工具交互类型 */ export type PictureCutInteractionType = PictureInteractionType; /** 图片裁切 gizmo:在图片元素范围内缩放/移动裁切框,产出归一化裁切盒 */ export declare class PictureCutGizmo extends Gizmo { result: PictureCutResult; /** 仅供当前渲染帧使用的投影快照;输入不读取它。 */ private _renderProjection?; interactionParam: PictureCutInteractionParam; readonly type = GizmoType.PICTURE_CUT; /** 光标结果。 */ cursorResult: GestureCursorResult; private _isLockScale; private _mouseGrabbed; /** 直接读取 ConfigManager 中的唯一配置值。 */ get config(): Readonly; /** 当前选中的元素(直读 selection.getSelectedPlayerItems:id→VFXItem 已解析)。 */ get selectedItems(): VFXItem[]; /** 是否锁定宽高比缩放。 */ get isLockScale(): boolean; /** 设置是否锁定宽高比缩放。 */ set isLockScale(state: boolean); /** * 鼠标移动处理:刷新裁切区域的交互类型,仅控制点 hover 接管元素预选。 * 按 getMousePosition() 刷新交互类型(命中手柄/边/区域)与光标,draw 纯渲染 interactionParam。 * 自己 grabbed 时执行连续交互;否则更新 hover 交互类型。 * @param event 鼠标事件 * @returns grabbed 连续交互或无按键命中缩放控制点时返回 true */ onMouseMove(event: InputEventMouseMotion): void; /** * mouseDrag:裁切会话续接 `_updateGrab`。基类 `onMouseDrag` 空 no-op,本 gizmo 按下抓取 * (`_mouseGrabbed`),Drag 相位由此续接裁切框拖拽。未抓取时不参与。 */ onMouseDrag(event: InputEventMouseMotion): void; /** 鼠标离开交互层:清交互类型(拖拽中不清)。 */ onMouseLeave(): void; /** 自判是否参与派发(取代原 handles:仅单选一个元素时激活)。 */ private _isApplicableSelection; /** * drag:按交互类型处理裁切框移动/缩放/单向缩放。 * 支持 shift 锁定宽高比,结果以归一化裁切盒写入 result。 * @param event 鼠标事件(drag) */ private _updateGrab; /** * 准备触发动作:自算交互类型,存在有效交互时开始 action 会话。 * @param event 鼠标事件 * @returns 有效交互时返回 `Stop`,否则返回 `Pass` */ onMouseDown(event: InputEventMouseButton): void; /** * 交互结束处理:刷新交互类型并提交 action 会话。 * @param event 鼠标事件 * @returns `Stop` */ onMouseUp(event: InputEventMouseButton): void; /** * 键盘松开:清除当前交互的锁定宽高比(下次拖拽重新算)。 * @param _keyCode 键盘事件 */ onKeyUp(_keyCode: InputEventKey): void; /** 渲染前从当前 selection/viewport 生成一次纯投影快照。 */ onPreRender(): void; /** 从真源现场计算投影;不修改业务状态或渲染快照。 */ private _projectSelection; /** * effects 渲染管线绘制入口(由 GizmoControl.onDraw 每帧调用)。 * 绘制裁切交互:蒙版层、网格线、元素包围盒、裁切框、角点。 * 几何与 runtime Control 都使用左上原点、Y 向下的视图坐标。 * 注意:仅读取 onPreRender 产生的当帧投影快照。 * @param control 绘制控制器 */ draw(control: Control): void; /** * 刷新指针结果。 * @param activeType 交互类型 * @param angle 指针方向 */ refreshCursorResult(activeType: PictureCutInteractionType, angle?: number): void; /** * 获取当前裁切信息(裁切框 + 元素包围盒)。 * @returns 裁切信息对象,不可交互时返回 undefined */ getCutInfo(): { cutBox: Box2; itemBox: Box2; } | undefined; /** * 获取归一化裁切包围盒(min/max 取值 [0, 1],相对元素包围盒)。 */ getCutBox(): Box2 | undefined; /** * 设置归一化裁切包围盒(入参为归一化坐标,钳制到 [0, 1])。 * @param normalizeBox 归一化裁切包围盒 * @returns 设置成功时返回更新后的裁切框,不可交互时返回 undefined */ setCutBox(normalizeBox: Box2): Box2 | undefined; /** * 根据鼠标位置判定裁切框的交互类型(角点缩放/边线单向缩放/整体移动), * 同时刷新光标方向。 * @param point 视图坐标鼠标位置 * @param inputPosition Control 本地坐标鼠标位置 */ private refreshInteractionType; }