// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved. using FlaxEditor.Gizmo; using FlaxEditor.Viewport.Cameras; using FlaxEngine; using FlaxEngine.GUI; namespace FlaxEditor.Viewport { /// /// Viewport with free camera and gizmo tools. /// /// /// public class EditorGizmoViewport : EditorViewport, IGizmoOwner { private UpdateDelegate _update; /// /// Initializes a new instance of the class. /// /// The task. /// The undo. public EditorGizmoViewport(SceneRenderTask task, Undo undo) : base(task, new FPSCamera(), true) { Undo = undo; SetUpdate(ref _update, OnUpdate); } private void OnUpdate(float deltaTime) { for (int i = 0; i < Gizmos.Count; i++) { Gizmos[i].Update(deltaTime); } } /// public GizmosCollection Gizmos { get; } = new GizmosCollection(); /// public SceneRenderTask RenderTask => Task; /// public float ViewFarPlane => FarPlane; /// public bool IsLeftMouseButtonDown => _input.IsMouseLeftDown; /// public bool IsRightMouseButtonDown => _input.IsMouseRightDown; /// public bool IsAltKeyDown => _input.IsAltDown; /// public bool IsControlDown => _input.IsControlDown; /// public bool SnapToGround => Editor.Instance.Options.Options.Input.SnapToGround.Process(Root); /// public Vector2 MouseDelta => _mouseDelta * 1000; /// public bool UseSnapping => Root.GetKey(KeyboardKeys.Control); /// public bool UseDuplicate => Root.GetKey(KeyboardKeys.Shift); /// public Undo Undo { get; } /// protected override bool IsControllingMouse => Gizmos.Active?.IsControllingMouse ?? false; /// protected override void AddUpdateCallbacks(RootControl root) { base.AddUpdateCallbacks(root); root.UpdateCallbacksToAdd.Add(_update); } /// protected override void RemoveUpdateCallbacks(RootControl root) { base.RemoveUpdateCallbacks(root); root.UpdateCallbacksToRemove.Add(_update); } } }