* Gizmo provider for FGUIComponent * FGUIComponent 的 Gizmo 提供者 * * Generates rect gizmos for all visible FGUI nodes. * Uses the same coordinate conversion as FGUIRenderDataProvider. * 为所有可见的 FGUI 节点生成矩形 gizmos。 * 使用与 FGUIRenderDataProvider 相同的坐标转换。
(
component: FGUIComponent,
entity: Entity,
isSelected: boolean
)
| 149 | * 使用与 FGUIRenderDataProvider 相同的坐标转换。 |
| 150 | */ |
| 151 | function fguiGizmoProvider( |
| 152 | component: FGUIComponent, |
| 153 | entity: Entity, |
| 154 | isSelected: boolean |
| 155 | ): IGizmoRenderData[] { |
| 156 | const gizmos: IGizmoRenderData[] = []; |
| 157 | |
| 158 | // Get the root GObject |
| 159 | const root = component.root; |
| 160 | if (!root) return gizmos; |
| 161 | |
| 162 | // Get Stage design size for coordinate conversion |
| 163 | // Use the same values as FGUIRenderDataProvider |
| 164 | // 获取 Stage 设计尺寸用于坐标转换,与 FGUIRenderDataProvider 使用相同的值 |
| 165 | const stage = Stage.inst; |
| 166 | const halfWidth = stage.designWidth / 2; |
| 167 | const halfHeight = stage.designHeight / 2; |
| 168 | |
| 169 | // Root gizmo - root is at (0, 0) in FGUI coords |
| 170 | // In engine coords: center is at (-halfWidth + width/2, halfHeight - height/2) |
| 171 | // 根 Gizmo - 根节点在 FGUI 坐标 (0, 0) |
| 172 | // 在引擎坐标中:中心在 (-halfWidth + width/2, halfHeight - height/2) |
| 173 | const rootCenterX = -halfWidth + root.width / 2; |
| 174 | const rootCenterY = halfHeight - root.height / 2; |
| 175 | |
| 176 | const rootGizmo: IRectGizmoData = { |
| 177 | type: 'rect', |
| 178 | x: rootCenterX, |
| 179 | y: rootCenterY, |
| 180 | width: root.width, |
| 181 | height: root.height, |
| 182 | rotation: 0, |
| 183 | originX: 0.5, |
| 184 | originY: 0.5, |
| 185 | color: isSelected ? FGUIGizmoColors.root : { ...FGUIGizmoColors.root, a: 0.4 }, |
| 186 | showHandles: isSelected |
| 187 | }; |
| 188 | gizmos.push(rootGizmo); |
| 189 | |
| 190 | // Collect child gizmos only when selected (performance optimization) |
| 191 | if (isSelected && component.component) { |
| 192 | const comp = component.component; |
| 193 | |
| 194 | // Get currently selected virtual node for this entity |
| 195 | // 获取此实体当前选中的虚拟节点 |
| 196 | const selectedInfo = VirtualNodeRegistry.getSelectedVirtualNode(); |
| 197 | const selectedVirtualNodeId = (selectedInfo && selectedInfo.entityId === entity.id) |
| 198 | ? selectedInfo.virtualNodeId |
| 199 | : null; |
| 200 | |
| 201 | // First add gizmo for the component itself |
| 202 | // 首先为组件本身添加 gizmo |
| 203 | collectFGUIGizmos(comp, halfWidth, halfHeight, gizmos, entity.id, selectedVirtualNodeId, ''); |
| 204 | } |
| 205 | |
| 206 | return gizmos; |
| 207 | } |
| 208 |
nothing calls this directly
no test coverage detected