// Copyright (c) Wojciech Figat. All rights reserved. using FlaxEngine; using FlaxEngine.GUI; namespace FlaxEditor.Surface { /// /// The surface root control used to navigate around the view (scale and move it). /// /// [HideInEditor] public class SurfaceRootControl : ContainerControl { /// public SurfaceRootControl() { AutoFocus = false; ClipChildren = false; Pivot = Float2.Zero; } /// public override bool IntersectsContent(ref Float2 locationParent, out Float2 location) { location = PointFromParent(ref locationParent); return true; } /// /// Draws the comments. Render them before other controls to prevent foreground override. /// public virtual void DrawComments() { Render2D.PushTransform(_cachedTransform); // Push clipping mask if (ClipChildren) { GetDesireClientArea(out Rectangle clientArea); Render2D.PushClip(clientArea); } // Draw all visible child comments for (int i = 0; i < _children.Count; i++) { var child = _children[i]; if (child is SurfaceComment && child.Visible) { Render2D.PushTransform(child._cachedTransform); child.Draw(); Render2D.PopTransform(); } } // Pop clipping mask if (ClipChildren) { Render2D.PopClip(); } Render2D.PopTransform(); } /// protected override void DrawChildren() { // Skip comments (render them to as background manually by Visject Surface) Render2D.PeekClip(out var globalClipping); Render2D.PeekTransform(out var globalTransform); for (int i = 0; i < _children.Count; i++) { var child = _children[i]; if (!(child is SurfaceComment) && child.Visible) { Matrix3x3.Multiply(ref child._cachedTransform, ref globalTransform, out var globalChildTransform); var childGlobalRect = new Rectangle(globalChildTransform.M31, globalChildTransform.M32, child.Width * globalChildTransform.M11, child.Height * globalChildTransform.M22); if (globalClipping.Intersects(ref childGlobalRect)) { Render2D.PushTransform(child._cachedTransform); child.Draw(); Render2D.PopTransform(); } } } } } }