import { Control, spec, type InputEventMouseButton, type InputEventMouseMotion } from '@galacean/effects'; import { Gizmo } from '../gizmo'; import { GizmoType } from '../gizmo-type'; import { Box2 } from '../math'; import type { SpriteTextEditConfig } from '../configs/types'; /** * 图层文字信息 */ export type SpriteTextInfo = { /** * 元素ID */ id: string; /** * 文本框索引 */ index: number; /** * 文本包围盒 */ box: Box2; /** * 文本内容 */ text: string; /** * 是否被修改过 */ hasChanged: boolean; /** * 是否处于编辑态 */ isEditing: boolean; }; /** * 精准改字功能初始化信息 */ export type SpriteTextInitParam = { /** * 元素ID */ id: string; originBox?: Box2; /** * 改字信息 */ info: SpriteTextInitInfo[]; }; export type SpriteTextInitInfo = { /** * 是否被修改过 */ hasChanged: boolean; /** * 文字内容 */ text: string; /** * 包围盒信息 */ box: [spec.vec2, spec.vec2, spec.vec2, spec.vec2]; }; /** 精准改字交互参数 */ type SpriteTextEditInteractionParam = { /** 已选中索引 */ selected: number; /** 预选中索引 */ preSelected: number; }; /** 精准改字结果列表 */ type SpriteTextEditResult = SpriteTextInfo[]; /** 精准改字 gizmo:在图层文字框上提供预选/选中/编辑/文本设置能力并按帧绘制编辑框与编辑态文本 */ export declare class SpriteTextEditGizmo extends Gizmo { readonly type: GizmoType; result: SpriteTextEditResult; interactionParam: SpriteTextEditInteractionParam; /** onMouseMove 命中缓存(坐标未变则跳过 _computePreSelected,避免每帧全 result 命中扫描)。 */ private _cachedCoords; /** 直接读取 ConfigManager 中的唯一配置值。 */ get config(): Readonly; /** * 鼠标移动处理:sprite-text-edit 对 hover 恒接管(精准改字编辑态整画布接管),返 `Stop`。 * 按 getMousePosition() 派生预选中文字框索引(节流缓存),draw 纯渲染 interactionParam.preSelected。 * 平移/离开(由 onMouseLeave 清)时 preSelected=-1(不高亮)。 * @param _event 鼠标事件 * @returns 普通 hover 固定返回 false */ onMouseMove(_event: InputEventMouseMotion): void; /** 鼠标离开交互层:清预选中 + 失效缓存。 */ onMouseLeave(): void; /** * 准备触发动作:将预选中文字框置为编辑态并通过 GestureHandler 抛出 spritetextclick 事件。 * @param event 鼠标事件 * @param event.doubleClick 是否双击;双击时跳过(避免双击误进文字编辑态) * @returns 有效交互时返回 `Stop`,否则返回 `Pass` */ onMouseDown(event: InputEventMouseButton): void; /** * 以初始化参数列表填充 result,将原始角点转换为相对元素包围盒的归一化盒。 * @param initParams 初始化参数列表 */ initResult(initParams: SpriteTextInitParam[]): void; /** 清空当前所有改字结果数据。 */ private _getItemOriginBox; clearResultData(): void; /** * 设置当前选中文字框;找不到时告警。 * @param id 元素 ID * @param index 文本框索引 */ setSelected(id: string, index: number): void; /** * 设置指定文字框的文本内容;找不到时告警。 * @param id 元素 ID * @param index 文本框索引 * @param text 文本内容 */ setText(id: string, index: number, text: string): void; /** * 设置指定文字框的"已改动"状态;找不到时告警。 * @param id 元素 ID * @param index 文本框索引 * @param hasChanged 是否已改动 */ setChangedState(id: string, index: number, hasChanged: boolean): void; /** * 设置指定文字框的编辑态;找不到时告警。 * @param id 元素 ID * @param index 文本框索引 * @param isEditing 是否处于编辑态 */ setEditState(id: string, index: number, isEditing: boolean): void; /** * 绘制结果由 `draw(control)` 自包含完成,无需在此预处理。 */ /** * effects 渲染管线绘制入口(由 GizmoControl.onDraw 每帧调用)。 * 绘制精准改字的编辑框(填充 + 边框)与编辑态文本。 * 几何与 runtime Control 都使用左上原点、Y 向下的视图坐标。 * * z-order:先画未改动组(在下层),再画已改动组(在上层),最后画文本(最上)。 * @param control 绘制控制器 */ draw(control: Control): void; /** * 只读判定:mouse 命中的文字框索引(首个命中),无命中返回 -1。 * 供 draw(pull 现算高亮)与 onMouseDown(按下自算建会话)复用。 */ private _computePreSelected; } export {};