コード例 #1
0
ファイル: AdornerLayer.cs プロジェクト: Scellow/Perspex
 public static AdornerLayer GetAdornerLayer(IVisual visual)
 {
     return visual.GetVisualAncestors()
         .OfType<AdornerDecorator>()
         .FirstOrDefault()
         ?.AdornerLayer;
 }
コード例 #2
0
        /// <summary>
        /// Translates a point relative to this visual to coordinates that are relative to the specified visual.
        /// The visual and relativeTo should be descendants of the same root window
        /// </summary>
        /// <param name="visual">The visual.</param>
        /// <param name="point">The point value, as relative to this visual.</param>
        /// <param name="relativeTo">The visual to translate the given point into.</param>
        /// <returns>A point value, now relative to the target visual rather than this source element.</returns>
        public static Point TranslatePoint(this IVisual visual, Point point, IVisual relativeTo)
        {
            var pos = GetRootAndPosition(visual);
            var relToPos = GetRootAndPosition(relativeTo);

            return point - (relToPos.Item2 - pos.Item2);
        }
コード例 #3
0
ファイル: RendererBase.cs プロジェクト: rdterner/Perspex
        /// <summary>
        /// Renders the specified visual.
        /// </summary>
        /// <param name="visual">The visual to render.</param>
        /// 
        /// <param name="context">The drawing context.</param>
        public static void Render(this DrawingContext context, IVisual visual)
        {
            var opacity = visual.Opacity;
            if (visual.IsVisible && opacity > 0)
            {
                var m = Matrix.CreateTranslation(visual.Bounds.Position);

                var renderTransform = Matrix.Identity;

                if (visual.RenderTransform != null)
                {
                    var origin = visual.TransformOrigin.ToPixels(new Size(visual.Bounds.Width, visual.Bounds.Height));
                    var offset = Matrix.CreateTranslation(origin);
                    renderTransform = (-offset)*visual.RenderTransform.Value*(offset);
                }
                m = renderTransform*m;

                using (context.PushPostTransform(m))
                using (context.PushOpacity(opacity))
                using (visual.ClipToBounds ? context.PushClip(new Rect(visual.Bounds.Size)) : default(DrawingContext.PushedState))
                using (context.PushTransformContainer())
                {
                    visual.Render(context);
                    foreach (var child in visual.VisualChildren.OrderBy(x => x.ZIndex))
                    {
                        context.Render(child);
                    }
                }
            }
        }
コード例 #4
0
 public void StartVisuals()
 { 
     ParticleSystem ps = Instantiate(VFXPool.Instance.Sprays[SpellInformation.Elements[0].ToString()], StaffTransform.position, StaffTransform.rotation) as ParticleSystem;
     ps.transform.SetParent(StaffTransform);
     particleSystemAnchor = ps.GetComponent<IVisual>();
     particleSystemAnchor.AuthorizeCollisionDetection(ref SpellInformation);
 }
コード例 #5
0
ファイル: RendererBase.cs プロジェクト: healtech/Perspex
 /// <summary>
 /// Renders the specified visual with the specified transform and clip.
 /// </summary>
 /// <param name="visual">The visual to render.</param>
 /// <param name="handle">An optional platform-specific handle.</param>
 /// <param name="transform">The transform.</param>
 /// <param name="clip">An optional clip rectangle.</param>
 public virtual void Render(IVisual visual, IPlatformHandle handle, Matrix transform, Rect? clip = null)
 {
     using (var context = CreateDrawingContext(handle))
     using (clip.HasValue ? context.PushClip(clip.Value) : null)
     {
         Render(visual, context, Matrix.Identity, transform);
     }
 }
コード例 #6
0
 private static bool IsHitTestVisible(IVisual visual)
 {
     var element = visual as IInputElement;
     return element != null &&
            element.IsVisible &&
            element.IsHitTestVisible &&
            element.IsEnabledCore;
 }
コード例 #7
0
ファイル: RenderManager.cs プロジェクト: healtech/Perspex
 /// <summary>
 /// Invalidates the render for the specified visual and raises <see cref="RenderNeeded"/>.
 /// </summary>
 /// <param name="visual">The visual.</param>
 public void InvalidateRender(IVisual visual)
 {
     if (!_renderQueued)
     {
         _renderNeeded.OnNext(Unit.Default);
         _renderQueued = true;
     }
 }
コード例 #8
0
ファイル: RendererBase.cs プロジェクト: Scellow/Perspex
        /// <summary>
        /// Renders the specified visual.
        /// </summary>
        /// <param name="visual">The visual to render.</param>
        /// <param name="handle">An optional platform-specific handle.</param>
        public virtual void Render(IVisual visual, IPlatformHandle handle)
        {
            using (var context = this.CreateDrawingContext(handle))
            {
                this.Render(visual, context, Matrix.Identity, Matrix.Identity);
            }

            ++this.RenderCount;
        }
コード例 #9
0
ファイル: PageSlide.cs プロジェクト: Robertofon/Perspex
        private static IVisual GetVisualParent(IVisual from, IVisual to)
        {
            var p1 = (from ?? to).VisualParent;
            var p2 = (to ?? from).VisualParent;

            if (p1 != null && p2 != null && p1 != p2)
            {
                throw new ArgumentException("Controls for PageSlide must have same parent.");
            }

            return p1;
        }
コード例 #10
0
ファイル: MouseDevice.cs プロジェクト: rdterner/Perspex
        public Point GetPosition(IVisual relativeTo)
        {
            Point p = Position;
            IVisual v = relativeTo;

            while (v != null)
            {
                p -= v.Bounds.Position;
                v = v.VisualParent;
            }

            return p;
        }
コード例 #11
0
ファイル: Core.cs プロジェクト: marcinp7/ChrumGraph
        /// <summary>
        /// Initializes a new instance of the Core class.
        /// </summary>
        public Core(IVisual visual)
        {
            this.visual = visual;
            physics = new Physics(this);

            FPS = defaultFPS;
            refreshTimer.Tick += (sender, e) =>
                {
                    if (visual.Visible)
                    {
                        lock (this) { visual.Refresh(); }
                    }
                };
            refreshTimer.Start();
            physics.StartSimulation(FPS);
        }
コード例 #12
0
ファイル: CrossFade.cs プロジェクト: CarlSosaDev/Avalonia
        /// <summary>
        /// Starts the animation.
        /// </summary>
        /// <param name="from">
        /// The control that is being transitioned away from. May be null.
        /// </param>
        /// <param name="to">
        /// The control that is being transitioned to. May be null.
        /// </param>
        /// <returns>
        /// A <see cref="Task"/> that tracks the progress of the animation.
        /// </returns>
        public async Task Start(IVisual from, IVisual to)
        {
            var tasks = new List<Task>();

            if (to != null)
            {
                to.Opacity = 0;
            }

            if (from != null)
            {
                tasks.Add(Animate.Property(
                    (IAvaloniaObject)from,
                    Visual.OpacityProperty,
                    from.Opacity,
                    0,
                    LinearEasing.For<double>(),
                    Duration).ToTask());
            }

            if (to != null)
            {
                to.Opacity = 0;
                to.IsVisible = true;

                tasks.Add(Animate.Property(
                    (IAvaloniaObject)to,
                    Visual.OpacityProperty,
                    0,
                    1,
                    LinearEasing.For<double>(),
                    Duration).ToTask());
            }

            await Task.WhenAll(tasks.ToArray());

            if (from != null)
            {
                from.IsVisible = false;
                from.Opacity = 1;
            }

            if (to != null)
            {
                to.Opacity = 1;
            }
        }
コード例 #13
0
        /// <summary>
        /// Gets the root of the control's visual tree and the position of the control 
        /// in the root's coordinate space.
        /// </summary>
        /// <param name="v">The visual.</param>
        /// <returns>A tuple containing the root and the position of the control.</returns>
        private static Tuple<IRenderRoot, Vector> GetRootAndPosition(IVisual v)
        {
            var result = new Vector();

            while (!(v is IRenderRoot))
            {
                result = new Vector(result.X + v.Bounds.X, result.Y + v.Bounds.Y);
                v = v.VisualParent;

                if (v == null)
                {
                    throw new InvalidOperationException("Control is not attached to visual tree.");
                }
            }

            return Tuple.Create((IRenderRoot)v, result);
        }
コード例 #14
0
ファイル: Debug.cs プロジェクト: CarlSosaDev/Avalonia
        private static void PrintVisualTree(IVisual visual, StringBuilder builder, int indent)
        {
            Control control = visual as Control;

            builder.Append(Indent(indent - 1));

            if (indent > 0)
            {
                builder.Append(" +- ");
            }

            builder.Append(visual.GetType().Name);

            if (control != null)
            {
                builder.Append(" ");
                builder.AppendLine(control.Classes.ToString());

                foreach (var property in AvaloniaPropertyRegistry.Instance.GetRegistered(control))
                {
                    var value = control.GetDiagnostic(property);

                    if (value.Priority != BindingPriority.Unset)
                    {
                        builder.Append(Indent(indent));
                        builder.Append(" |  ");
                        builder.Append(value.Property.Name);
                        builder.Append(" = ");
                        builder.Append(value.Value ?? "(null)");
                        builder.Append(" [");
                        builder.Append(value.Priority);
                        builder.AppendLine("]");
                    }
                }
            }
            else
            {
                builder.AppendLine();
            }

            foreach (var child in visual.VisualChildren)
            {
                PrintVisualTree(child, builder, indent + 1);
            }
        }
コード例 #15
0
ファイル: VisualTreeNode.cs プロジェクト: Arlorean/Perspex
        public VisualTreeNode(IVisual visual)
            : base((Control)visual)
        {
            var host = visual as IVisualTreeHost;

            if (host?.Root == null)
            {
                Children = visual.VisualChildren.CreateDerivedCollection(x => new VisualTreeNode(x));
            }
            else
            {
                Children = new ReactiveList<VisualTreeNode>(new[] { new VisualTreeNode(host.Root) });
            }

            if (Control != null)
            {
                IsInTemplate = Control.TemplatedParent != null;
            }
        }
コード例 #16
0
ファイル: PageSlide.cs プロジェクト: Arlorean/Perspex
        /// <summary>
        /// Starts the animation.
        /// </summary>
        /// <param name="from">
        /// The control that is being transitioned away from. May be null.
        /// </param>
        /// <param name="to">
        /// The control that is being transitioned to. May be null.
        /// </param>
        /// <param name="forward">
        /// If true, the new page is slid in from the right, or if false from the left.
        /// </param>
        /// <returns>
        /// A <see cref="Task"/> that tracks the progress of the animation.
        /// </returns>
        public async Task Start(IVisual from, IVisual to, bool forward)
        {
            var tasks = new List<Task>();
            var parent = GetVisualParent(from, to);
            var distance = parent.Bounds.Width;

            if (from != null)
            {
                var transform = new TranslateTransform();
                from.RenderTransform = transform;
                tasks.Add(Animate.Property(
                    transform,
                    TranslateTransform.XProperty,
                    0.0,
                    forward ? -distance : distance,
                    LinearEasing.For<double>(),
                    Duration).ToTask());
            }

            if (to != null)
            {
                var transform = new TranslateTransform();
                to.RenderTransform = transform;
                to.IsVisible = true;
                tasks.Add(Animate.Property(
                    transform,
                    TranslateTransform.XProperty,
                    forward ? distance : -distance,
                    0.0,
                    LinearEasing.For<double>(),
                    Duration).ToTask());
            }

            await Task.WhenAll(tasks.ToArray());

            if (from != null)
            {
                from.IsVisible = false;
            }
        }
コード例 #17
0
ファイル: RendererBase.cs プロジェクト: healtech/Perspex
        /// <summary>
        /// Renders the specified visual.
        /// </summary>
        /// <param name="visual">The visual to render.</param>
        /// <param name="context">The drawing context.</param>
        /// <param name="translation">The current translation.</param>
        /// <param name="transform">The current transform.</param>
        protected virtual void Render(IVisual visual, IDrawingContext context, Matrix translation, Matrix transform)
        {
            var opacity = visual.Opacity;

            if (visual.IsVisible && opacity > 0)
            {
                // Translate any existing transform into this controls coordinate system.
                Matrix offset = Matrix.CreateTranslation(visual.Bounds.Position);
                transform = offset * transform * -offset;

                // Update the current offset.
                translation *= Matrix.CreateTranslation(visual.Bounds.Position);

                // Apply the control's render transform, if any.
                if (visual.RenderTransform != null)
                {
                    offset = Matrix.CreateTranslation(visual.TransformOrigin.ToPixels(visual.Bounds.Size));
                    transform *= -offset * visual.RenderTransform.Value * offset;
                }

                // Draw the control and its children.
                var m = transform * translation;
                var d = context.PushTransform(m);

                using (context.PushOpacity(opacity))
                using (visual.ClipToBounds ? context.PushClip(visual.Bounds) : null)
                {
                    visual.Render(context);
                    d.Dispose();

                    foreach (var child in visual.VisualChildren.OrderBy(x => x.ZIndex))
                    {
                        Render(child, context, translation, transform);
                    }
                }
            }
        }
コード例 #18
0
ファイル: DevTools.xaml.cs プロジェクト: jshield/Avalonia
 public static void RemoveDevTool(IVisual visual)
 {
     s_visualTreeRoots.Remove(visual.GetVisualRoot());
 }
コード例 #19
0
ファイル: Visual.cs プロジェクト: jkoritzinsky/Avalonia
 /// <summary>
 /// Called when the control's visual parent changes.
 /// </summary>
 /// <param name="oldParent">The old visual parent.</param>
 /// <param name="newParent">The new visual parent.</param>
 protected virtual void OnVisualParentChanged(IVisual oldParent, IVisual newParent)
 {
     RaisePropertyChanged(VisualParentProperty, oldParent, newParent, BindingPriority.LocalValue);
 }
コード例 #20
0
ファイル: PointerEventArgs.cs プロジェクト: yzq1979/Avalonia
 public Point GetPosition(IVisual relativeTo) => _ev.GetPosition(relativeTo);
コード例 #21
0
ファイル: MouseDevice.cs プロジェクト: rdterner/Perspex
 private IInteractive GetSource(IVisual hit)
 {
     return Captured ??
         (hit as IInteractive) ??
         hit.GetSelfAndVisualAncestors().OfType<IInteractive>().FirstOrDefault();
 }
コード例 #22
0
 /// <inheritdoc/>
 public void RecalculateChildren(IVisual visual) => AddDirty(visual);
コード例 #23
0
ファイル: PointerEventArgs.cs プロジェクト: yzq1979/Avalonia
 public Point GetPosition(IVisual relativeTo)
 {
     if (_rootVisual == null)
     {
         return(default);
コード例 #24
0
        /// <summary>
        /// Converts a point from screen to client coordinates.
        /// </summary>
        /// <param name="visual">The visual.</param>
        /// <param name="point">The point in screen coordinates.</param>
        /// <returns>The point in client coordinates.</returns>
        public static Point PointToClient(this IVisual visual, PixelPoint point)
        {
            var rootPoint = visual.VisualRoot.PointToClient(point);

            return(visual.VisualRoot.TranslatePoint(rootPoint, visual).Value);
        }
コード例 #25
0
ファイル: Visual.cs プロジェクト: KvanTTT/Perspex
        /// <summary>
        /// Gets the visual offset from the specified ancestor.
        /// </summary>
        /// <param name="ancestor">The ancestor visual.</param>
        /// <param name="visual">The visual.</param>
        /// <returns>The visual offset.</returns>
        private static Vector GetOffsetFrom(IVisual ancestor, IVisual visual)
        {
            var result = new Vector();

            while (visual != ancestor)
            {
                result = new Vector(result.X + visual.Bounds.X, result.Y + visual.Bounds.Y);
                visual = visual.VisualParent;

                if (visual == null)
                {
                    throw new ArgumentException("'visual' is not a descendent of 'ancestor'.");
                }
            }

            return result;
        }
コード例 #26
0
ファイル: BinarySceneTest.cs プロジェクト: git-thinh/limada
        public void N1()
        {
            Mock.Scene.Selected.Clear();
            Mock.SetFocused(Mock.SampleFactory.Nodes[1]);   // 1
            Mock.SceneFacade.CollapseToFocused();

            Assert.AreEqual(Mock.Scene.Graph.Count, 1);
            Mock.AreEquivalent(new IVisual[] { Mock.SampleFactory.Nodes[1] }, Mock.Scene.Graph);
            Mock.ProveShapes(Mock.Scene);

            var N1Expanded = new IVisual[] {
                Mock.SampleFactory.Nodes[1], // 1
                Mock.SampleFactory.Nodes[2], // 2
                Mock.SampleFactory.Nodes[3], // 3
                Mock.SampleFactory.Nodes[4], // 4
                Mock.SampleFactory.Edges[1], // [1->2]
                Mock.SampleFactory.Edges[2], // [4->3]
                Mock.SampleFactory.Edges[3], // [1->[4->3]]
            };

            Mock.SceneFacade.Expand(false);
            Mock.AreEquivalent(N1Expanded, Mock.Scene.Graph);
            Mock.ProveShapes(Mock.Scene);

            Mock.Scene.Selected.Clear();
            Mock.SetFocused(Mock.SampleFactory.Nodes[4]);   // 4
            Mock.SceneFacade.Expand(false);

            var N4Expanded = new IVisual[] {
                Mock.SampleFactory.Nodes[1], // 1
                Mock.SampleFactory.Nodes[2], // 2
                Mock.SampleFactory.Nodes[3], // 3
                Mock.SampleFactory.Nodes[4], // 4
                Mock.SampleFactory.Nodes[5], // 3
                Mock.SampleFactory.Nodes[8], // 4
                Mock.SampleFactory.Edges[1], // [1->2]
                Mock.SampleFactory.Edges[2], // [4->3]
                Mock.SampleFactory.Edges[3], // [1->[4->3]]
                Mock.SampleFactory.Edges[4], // [5->8]
                Mock.SampleFactory.Edges[8], //[[4->3]->[5->8]]
            };

            Mock.AreEquivalent(N4Expanded, Mock.Scene.Graph);
            Mock.ProveShapes(Mock.Scene);

            Mock.Scene.Selected.Clear();
            Mock.SetFocused(Mock.SampleFactory.Nodes[5]);
            Mock.SceneFacade.Expand(false);

            var N5Expanded = new IVisual[] {
                Mock.SampleFactory.Nodes[1], // 1
                Mock.SampleFactory.Nodes[2], // 2
                Mock.SampleFactory.Nodes[3], // 3
                Mock.SampleFactory.Nodes[4], // 4
                Mock.SampleFactory.Nodes[5], // 5
                Mock.SampleFactory.Nodes[6], // 6
                Mock.SampleFactory.Nodes[7], // 7
                Mock.SampleFactory.Nodes[8], // 8
                Mock.SampleFactory.Edges[1], // [1->2]
                Mock.SampleFactory.Edges[2], // [4->3]
                Mock.SampleFactory.Edges[3], // [1->[4->3]]
                Mock.SampleFactory.Edges[4], // [5->8]
                Mock.SampleFactory.Edges[5], // [5->6]
                Mock.SampleFactory.Edges[6], //[5->7]
                Mock.SampleFactory.Edges[8], //[[4->3]->[5->8]]
            };

            Mock.AreEquivalent(N5Expanded, Mock.Scene.Graph);
            Mock.ProveShapes(Mock.Scene);

            var N5Collapsed = new IVisual[] {
                Mock.SampleFactory.Nodes[1], // 1
                Mock.SampleFactory.Nodes[2], // 2
                Mock.SampleFactory.Nodes[3], // 3
                Mock.SampleFactory.Nodes[4], // 4
                Mock.SampleFactory.Nodes[5], // 5
                Mock.SampleFactory.Edges[1], // [1->2]
                Mock.SampleFactory.Edges[2], // [4->3]
                Mock.SampleFactory.Edges[3], // [1->[4->3]]
            };

            Mock.SceneFacade.Collapse();
            Mock.AreEquivalent(N5Collapsed, Mock.Scene.Graph);
            Mock.ProveShapes(Mock.Scene);

            Mock.SceneFacade.Expand(false);
            Mock.AreEquivalent(N5Expanded, Mock.Scene.Graph);
            Mock.ProveShapes(Mock.Scene);

            Mock.Scene.Selected.Clear();
            Mock.SetFocused(Mock.SampleFactory.Nodes[8]);
            Mock.SceneFacade.Expand(false);

            Mock.AreEquivalent(FullExpanded, Mock.Scene.Graph);
            Mock.ProveShapes(Mock.Scene);

            Mock.SceneFacade.Collapse();

            Mock.AreEquivalent(N5Expanded, Mock.Scene.Graph);
            Mock.ProveShapes(Mock.Scene);

            this.ReportSummary();
        }
コード例 #27
0
 public void RenderToBuffer(IVisual visual, IntPtr pixels, int width, int height, int rowBytes)
 {
     throw new NotImplementedException();
 }
コード例 #28
0
ファイル: Pointer.cs プロジェクト: soosr/Avalonia
 IInputElement?GetNextCapture(IVisual parent)
 {
     return(parent as IInputElement ?? parent.FindAncestorOfType <IInputElement>());
 }
コード例 #29
0
 internal static void SetDefaultVisual(IVisual visual)
 {
     _defaultVisual = visual;
 }
コード例 #30
0
 private static Point Position(IVisual v)
 {
     return(v.Bounds.Position);
 }
コード例 #31
0
ファイル: Visual.cs プロジェクト: jkoritzinsky/Avalonia
        /// <summary>
        /// Sets the visual parent of the Visual.
        /// </summary>
        /// <param name="value">The visual parent.</param>
        private void SetVisualParent(Visual value)
        {
            if (_visualParent == value)
            {
                return;
            }
            
            var old = _visualParent;
            _visualParent = value;

            if (VisualRoot != null)
            {
                var e = new VisualTreeAttachmentEventArgs(VisualRoot);
                OnDetachedFromVisualTreeCore(e);
            }

            if (_visualParent is IRenderRoot || _visualParent?.IsAttachedToVisualTree == true)
            {
                var root = this.GetVisualAncestors().OfType<IRenderRoot>().FirstOrDefault();
                var e = new VisualTreeAttachmentEventArgs(root);
                OnAttachedToVisualTreeCore(e);
            }

            OnVisualParentChanged(old, value);
        }
コード例 #32
0
        /// <summary>
        /// Converts a point from client to screen coordinates.
        /// </summary>
        /// <param name="visual">The visual.</param>
        /// <param name="point">The point in client coordinates.</param>
        /// <returns>The point in screen coordinates.</returns>
        public static PixelPoint PointToScreen(this IVisual visual, Point point)
        {
            var p = visual.TranslatePoint(point, visual.VisualRoot);

            return(visual.VisualRoot.PointToScreen(p.Value));
        }
コード例 #33
0
ファイル: PointerEventArgs.cs プロジェクト: healtech/Perspex
 public Point GetPosition(IVisual relativeTo)
 {
     return Device.GetPosition(relativeTo);
 }
コード例 #34
0
 /// <summary>
 /// Called when the control's visual parent changes.
 /// </summary>
 /// <param name="oldParent">The old visual parent.</param>
 /// <param name="newParent">The new visual parent.</param>
 protected virtual void OnVisualParentChanged(IVisual oldParent, IVisual newParent)
 {
     RaisePropertyChanged(VisualParentProperty, oldParent, newParent, BindingPriority.LocalValue);
 }
コード例 #35
0
ファイル: Visual.cs プロジェクト: KvanTTT/Perspex
        /// <summary>
        /// Sets the visual parent of the Visual.
        /// </summary>
        /// <param name="value">The visual parent.</param>
        private void SetVisualParent(Visual value)
        {
            if (_visualParent == value)
            {
                return;
            }
            
            var old = _visualParent;
            _visualParent = value;

            if (VisualRoot != null)
            {
                var e = new VisualTreeAttachmentEventArgs(VisualRoot);
                NotifyDetachedFromVisualTree(e);
            }

            if (_visualParent is IRenderRoot || _visualParent?.IsAttachedToVisualTree == true)
            {
                var root = this.GetVisualAncestors().OfType<IRenderRoot>().FirstOrDefault();
                var e = new VisualTreeAttachmentEventArgs(root);
                NotifyAttachedToVisualTree(e);
            }

            RaisePropertyChanged(VisualParentProperty, old, value, BindingPriority.LocalValue);
        }
コード例 #36
0
 /// <summary>
 /// Renders the specified visual.
 /// </summary>
 /// <param name="visual">The visual to render.</param>
 /// <param name="context">The drawing context.</param>
 public static void Render(this DrawingContext context, IVisual visual)
 {
     context.Render(visual, visual.Bounds);
 }
 public IVisual UpdateVisual(IRenderContext context, IVisual oldVisual)
 {
     return(CreateVisual(context));
 }
コード例 #38
0
        /// <summary>
        /// Renders the specified visual.
        /// </summary>
        /// <param name="visual">The visual to render.</param>
        /// <param name="context">The drawing context.</param>
        /// <param name="clipRect">
        /// The current clip rect, in coordinates relative to <paramref name="visual"/>.
        /// </param>
        private static void Render(this DrawingContext context, IVisual visual, Rect clipRect)
        {
            var opacity      = visual.Opacity;
            var clipToBounds = visual.ClipToBounds;
            var bounds       = new Rect(visual.Bounds.Size);

            if (visual.IsVisible && opacity > 0)
            {
                var m = Matrix.CreateTranslation(visual.Bounds.Position);

                var renderTransform = Matrix.Identity;

                if (visual.RenderTransform != null)
                {
                    var origin = visual.RenderTransformOrigin.ToPixels(new Size(visual.Bounds.Width, visual.Bounds.Height));
                    var offset = Matrix.CreateTranslation(origin);
                    renderTransform = (-offset) * visual.RenderTransform.Value * (offset);
                }

                m = renderTransform * m;

                if (clipToBounds)
                {
                    clipRect = clipRect.Intersect(new Rect(visual.Bounds.Size));
                }

                using (context.PushPostTransform(m))
                    using (context.PushOpacity(opacity))
                        using (clipToBounds ? context.PushClip(bounds) : default(DrawingContext.PushedState))
                            using (visual.Clip != null ? context.PushGeometryClip(visual.Clip) : default(DrawingContext.PushedState))
                                using (visual.OpacityMask != null ? context.PushOpacityMask(visual.OpacityMask, bounds) : default(DrawingContext.PushedState))
                                    using (context.PushTransformContainer())
                                    {
                                        visual.Render(context);

#pragma warning disable 0618
                                        var transformed =
                                            new TransformedBounds(bounds, new Rect(), context.CurrentContainerTransform);
#pragma warning restore 0618

                                        if (visual is Visual)
                                        {
                                            BoundsTracker.SetTransformedBounds((Visual)visual, transformed);
                                        }

                                        var lst = GetSortedVisualList(visual.VisualChildren);

                                        foreach (var child in lst)
                                        {
                                            var childBounds = GetTransformedBounds(child);

                                            if (!child.ClipToBounds || clipRect.Intersects(childBounds))
                                            {
                                                var childClipRect = clipRect.Translate(-childBounds.Position);
                                                context.Render(child, childClipRect);
                                            }
                                            else
                                            {
                                                ClearTransformedBounds(child);
                                            }
                                        }

                                        ReturnListToPool(lst);
                                    }
            }

            if (!visual.IsVisible)
            {
                ClearTransformedBounds(visual);
            }
        }
コード例 #39
0
        /// <summary>
        /// Removes a visual child from the control;
        /// </summary>
        /// <param name="visual">The child to remove.</param>
        protected void RemoveVisualChild(IVisual visual)
        {
            Contract.Requires <ArgumentNullException>(visual != null);

            _visualChildren.Remove(visual);
        }
コード例 #40
0
ファイル: RenderTargetBitmap.cs プロジェクト: Scellow/Perspex
 /// <summary>
 /// Renders an <see cref="IVisual"/> into the bitmap.
 /// </summary>
 /// <param name="visual">The visual to render.</param>
 /// <remarks>
 /// Before calling this method, ensure that <paramref name="visual"/> has been measured.
 /// </remarks>
 public void Render(IVisual visual)
 {
     this.PlatformImpl.Render(visual);
 }
コード例 #41
0
 public void Remove(IVisual element)
 {
     _items.Remove(element);
 }
コード例 #42
0
ファイル: ControlTests.cs プロジェクト: yuyu2you/Avalonia
 public void AddDirty(IVisual visual)
 {
 }
コード例 #43
0
ファイル: DevTools.xaml.cs プロジェクト: jshield/Avalonia
 public static bool BelongsToDevTool(IVisual visual)
 {
     return(s_visualTreeRoots.Contains(visual.GetVisualRoot()));
 }
コード例 #44
0
ファイル: DeferredRenderer.cs プロジェクト: soosr/Avalonia
 public void RecalculateChildren(IVisual visual) => _recalculateChildren?.Add(visual);
コード例 #45
0
ファイル: FullLayoutTests.cs プロジェクト: hacklex/Perspex
 private static Point Position(IVisual v)
 {
     return v.Bounds.Position;
 }
コード例 #46
0
ファイル: Scene.cs プロジェクト: rebider/Avalonia
        /// <summary>
        /// Gets the visuals at a point in the scene.
        /// </summary>
        /// <param name="p">The point.</param>
        /// <param name="root">The root of the subtree to search.</param>
        /// <param name="filter">A filter. May be null.</param>
        /// <returns>The visuals at the specified point.</returns>
        public IEnumerable <IVisual> HitTest(Point p, IVisual root, Func <IVisual, bool> filter)
        {
            var node = FindNode(root);

            return((node != null) ? new HitTestEnumerable(node, filter, p, Root) : Enumerable.Empty <IVisual>());
        }
コード例 #47
0
ファイル: Visual.cs プロジェクト: jkoritzinsky/Avalonia
        /// <summary>
        /// Ensures a visual child is not null and not already parented.
        /// </summary>
        /// <param name="c">The visual child.</param>
        private static void ValidateVisualChild(IVisual c)
        {
            if (c == null)
            {
                throw new ArgumentNullException("Cannot add null to VisualChildren.");
            }

            if (c.VisualParent != null)
            {
                throw new InvalidOperationException("The control already has a visual parent.");
            }
        }
コード例 #48
0
ファイル: DevTools.xaml.cs プロジェクト: jshield/Avalonia
 /// <summary>
 /// Marks a visual as part of the DevTools, so it can be excluded from event tracking.
 /// </summary>
 /// <param name="visual">The visual whose root is to be marked.</param>
 public static void MarkAsDevTool(IVisual visual)
 {
     s_visualTreeRoots.Add(visual.GetVisualRoot());
 }
コード例 #49
0
 public void Render(IVisual visual)
 {
     Renderer renderer = new Renderer(this.Surface);
     renderer.Render(visual, new PlatformHandle(IntPtr.Zero, "RTB"));
 }
コード例 #50
0
 public void Add(IVisual element)
 {
     _items.Add(element);
 }
コード例 #51
0
ファイル: Visual.cs プロジェクト: KvanTTT/Perspex
        /// <summary>
        /// Returns a transform that transforms the visual's coordinates into the coordinates
        /// of the specified <paramref name="visual"/>.
        /// </summary>
        /// <param name="visual">The visual to translate the coordinates to.</param>
        /// <returns>
        /// A <see cref="Matrix"/> containing the transform or null if the visuals don't share a
        /// common ancestor.
        /// </returns>
        public Matrix? TransformToVisual(IVisual visual)
        {
            var common = this.FindCommonVisualAncestor(visual);

            if (common != null)
            {
                var thisOffset = GetOffsetFrom(common, this);
                var thatOffset = GetOffsetFrom(common, visual);
                return Matrix.CreateTranslation(-thatOffset) * Matrix.CreateTranslation(thisOffset);
            }

            return null;
        }
コード例 #52
0
ファイル: SceneBuilder.cs プロジェクト: webek/Avalonia
        /// <inheritdoc/>
        public bool Update(Scene scene, IVisual visual)
        {
            Contract.Requires <ArgumentNullException>(scene != null);
            Contract.Requires <ArgumentNullException>(visual != null);

            Dispatcher.UIThread.VerifyAccess();

            if (!scene.Root.Visual.IsVisible)
            {
                throw new AvaloniaInternalException("Cannot update the scene for an invisible root visual.");
            }

            var node = (VisualNode)scene.FindNode(visual);

            if (visual == scene.Root.Visual)
            {
                UpdateSize(scene);
            }

            if (visual.VisualRoot != null)
            {
                if (visual.IsVisible)
                {
                    // If the node isn't yet part of the scene, find the nearest ancestor that is.
                    node = node ?? FindExistingAncestor(scene, visual);

                    // We don't need to do anything if this part of the tree has already been fully
                    // updated.
                    if (node != null && !node.SubTreeUpdated)
                    {
                        // If the control we've been asked to update isn't part of the scene then
                        // we're carrying out an add operation, so recurse and add all the
                        // descendents too.
                        var recurse = node.Visual != visual;

                        using (var impl = new DeferredDrawingContextImpl(this, scene.Layers))
                            using (var context = new DrawingContext(impl))
                            {
                                var clip = scene.Root.Visual.Bounds;

                                if (node.Parent != null)
                                {
                                    context.PushPostTransform(node.Parent.Transform);
                                    clip = node.Parent.ClipBounds;
                                }

                                using (context.PushTransformContainer())
                                {
                                    Update(context, scene, node, clip, recurse);
                                }
                            }

                        return(true);
                    }
                }
                else
                {
                    if (node != null)
                    {
                        // The control has been hidden so remove it from its parent and deindex the
                        // node and its descendents.
                        ((VisualNode)node.Parent)?.RemoveChild(node);
                        Deindex(scene, node);
                        return(true);
                    }
                }
            }
            else if (node != null)
            {
                // The control has been removed so remove it from its parent and deindex the
                // node and its descendents.
                var trim = FindFirstDeadAncestor(scene, node);
                ((VisualNode)trim.Parent).RemoveChild(trim);
                Deindex(scene, trim);
                return(true);
            }

            return(false);
        }
コード例 #53
0
ファイル: Visual.cs プロジェクト: KvanTTT/Perspex
 /// <summary>
 /// Ensures a visual child is not null.
 /// </summary>
 /// <param name="c">The visual child.</param>
 private static void ValidateLogicalChild(IVisual c)
 {
     if (c == null)
     {
         throw new ArgumentNullException("Cannot add null to VisualChildren.");
     }
 }
コード例 #54
0
 public static AdornerLayer?GetAdornerLayer(IVisual visual)
 {
     return(visual.FindAncestorOfType <VisualLayerManager>()?.AdornerLayer);
 }
コード例 #55
0
 private static int GetTabsCount(IVisual window) =>
 window
 .GetVisualDescendants()
 .OfType <TabView>()
 .Count();
コード例 #56
0
 /// <inheritdoc/>
 public IEnumerable <IVisual> HitTest(Point p, IVisual root, Func <IVisual, bool> filter)
 {
     return(HitTest(root, p, filter));
 }
コード例 #57
0
 public void AddVisualChild(IVisual visual)
 {
     VisualChildren.Add(visual);
 }
コード例 #58
0
ファイル: ControlTests.cs プロジェクト: yuyu2you/Avalonia
 public IEnumerable <IVisual> HitTest(Point p, IVisual root, Func <IVisual, bool> filter) => null;
コード例 #59
0
        /// <summary>
        /// Attempts to bring a portion of the target visual into view by scrolling the content.
        /// </summary>
        /// <param name="target">The target visual.</param>
        /// <param name="targetRect">The portion of the target visual to bring into view.</param>
        /// <returns>True if the scroll offset was changed; otherwise false.</returns>
        public bool BringDescendentIntoView(IVisual target, Rect targetRect)
        {
            if (Child == null)
            {
                return false;
            }

            var transform = target.TransformToVisual(Child);

            if (transform == null)
            {
                return false;
            }

            var rect = targetRect * transform.Value;
            var offset = Offset;
            var result = false;

            if (rect.Bottom > offset.Y + Viewport.Height)
            {
                offset = offset.WithY((rect.Bottom - Viewport.Height) + Child.Margin.Top);
                result = true;
            }

            if (rect.Y < offset.Y)
            {
                offset = offset.WithY(rect.Y);
                result = true;
            }

            if (rect.Right > offset.X + Viewport.Width)
            {
                offset = offset.WithX((rect.Right - Viewport.Width) + Child.Margin.Left);
                result = true;
            }

            if (rect.X < offset.X)
            {
                offset = offset.WithX(rect.X);
                result = true;
            }

            if (result)
            {
                Offset = offset;
            }

            return result;
        }
コード例 #60
0
ファイル: DeferredRenderer.cs プロジェクト: soosr/Avalonia
 /// <inheritdoc/>
 public void AddDirty(IVisual visual)
 {
     _dirty?.Add(visual);
 }