Example #1
0
        public Renderer(IRenderRoot root, IRenderLoop renderLoop)
        {
            Contract.Requires<ArgumentNullException>(root != null);

            _root = root;
            _renderLoop = renderLoop;
            _renderLoop.Tick += OnRenderLoopTick;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DeferredRenderer"/> class.
        /// </summary>
        /// <param name="root">The control to render.</param>
        /// <param name="renderLoop">The render loop.</param>
        /// <param name="sceneBuilder">The scene builder to use. Optional.</param>
        /// <param name="layerFactory">The layer factory to use. Optional.</param>
        /// <param name="dispatcher">The dispatcher to use. Optional.</param>
        public DeferredRenderer(
            IRenderRoot root,
            IRenderLoop renderLoop,
            ISceneBuilder sceneBuilder       = null,
            IRenderLayerFactory layerFactory = null,
            IDispatcher dispatcher           = null)
        {
            Contract.Requires <ArgumentNullException>(root != null);

            _dispatcher   = dispatcher ?? Dispatcher.UIThread;
            _root         = root;
            _sceneBuilder = sceneBuilder ?? new SceneBuilder();
            _scene        = new Scene(root);
            _layerFactory = layerFactory ?? new DefaultRenderLayerFactory();
            _layers       = new RenderLayers(_layerFactory);
            _renderLoop   = renderLoop;
        }
Example #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DeferredRenderer"/> class.
        /// </summary>
        /// <param name="root">The control to render.</param>
        /// <param name="renderLoop">The render loop.</param>
        /// <param name="sceneBuilder">The scene builder to use. Optional.</param>
        /// <param name="dispatcher">The dispatcher to use. Optional.</param>
        /// <param name="rendererLock">Lock object used before trying to access render target</param>
        public DeferredRenderer(
            IRenderRoot root,
            IRenderLoop renderLoop,
            ISceneBuilder sceneBuilder         = null,
            IDispatcher dispatcher             = null,
            IDeferredRendererLock rendererLock = null) : base(true)
        {
            Contract.Requires <ArgumentNullException>(root != null);

            _dispatcher   = dispatcher ?? Dispatcher.UIThread;
            _root         = root;
            _sceneBuilder = sceneBuilder ?? new SceneBuilder();
            Layers        = new RenderLayers();
            _renderLoop   = renderLoop;
            _lock         = rendererLock ?? new ManagedDeferredRendererLock();
            _updateSceneIfNeededDelegate = UpdateSceneIfNeeded;
        }
Example #4
0
        /// <inheritdoc/>
        protected override void OnAttachedToVisualTree(IRenderRoot root)
        {
            base.OnAttachedToVisualTree(root);

            if (this.GetVisualParent() != null)
            {
                _treeView = this.GetVisualAncestors().OfType<TreeView>().FirstOrDefault();

                if (_treeView == null)
                {
                    throw new InvalidOperationException("TreeViewItems must be added to a TreeView.");
                }
            }
            else
            {
                _treeView = null;
            }
        }
Example #5
0
        /// <inheritdoc/>
        protected override void OnAttachedToVisualTree(IRenderRoot root)
        {
            base.OnAttachedToVisualTree(root);

            if (this.GetVisualParent() != null)
            {
                _treeView = this.GetVisualAncestors().OfType <TreeView>().FirstOrDefault();

                if (_treeView == null)
                {
                    throw new InvalidOperationException("TreeViewItems must be added to a TreeView.");
                }
            }
            else
            {
                _treeView = null;
            }
        }
Example #6
0
        /// <summary>
        /// Calls the <see cref="OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs)"/> method
        /// for this control and all of its visual descendents.
        /// </summary>
        /// <param name="e">The event args.</param>
        protected virtual void OnDetachedFromVisualTreeCore(VisualTreeAttachmentEventArgs e)
        {
            Logger.Verbose(LogArea.Visual, this, "Detached from visual tree");

            VisualRoot = null;

            if (RenderTransform != null)
            {
                RenderTransform.Changed -= RenderTransformChanged;
            }

            OnDetachedFromVisualTree(e);

            if (VisualChildren != null)
            {
                foreach (Visual child in VisualChildren.OfType <Visual>())
                {
                    child.OnDetachedFromVisualTreeCore(e);
                }
            }
        }
Example #7
0
        /// <summary>
        /// Calls the <see cref="OnAttachedToVisualTree(VisualTreeAttachmentEventArgs)"/> method
        /// for this control and all of its visual descendents.
        /// </summary>
        /// <param name="e">The event args.</param>
        protected virtual void OnAttachedToVisualTreeCore(VisualTreeAttachmentEventArgs e)
        {
            Logger.Verbose(LogArea.Visual, this, "Attached to visual tree");

            _visualRoot = e.Root;

            if (RenderTransform != null)
            {
                RenderTransform.Changed += RenderTransformChanged;
            }

            OnAttachedToVisualTree(e);
            InvalidateVisual();

            if (VisualChildren != null)
            {
                foreach (Visual child in VisualChildren.OfType <Visual>())
                {
                    child.OnAttachedToVisualTreeCore(e);
                }
            }
        }
Example #8
0
        /// <summary>
        /// Calls the <see cref="OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs)"/> method
        /// for this control and all of its visual descendants.
        /// </summary>
        /// <param name="e">The event args.</param>
        protected virtual void OnDetachedFromVisualTreeCore(VisualTreeAttachmentEventArgs e)
        {
            Logger.TryGet(LogEventLevel.Verbose)?.Log(LogArea.Visual, this, "Detached from visual tree");

            _visualRoot = null;

            if (RenderTransform != null)
            {
                RenderTransform.Changed -= RenderTransformChanged;
            }

            OnDetachedFromVisualTree(e);
            DetachedFromVisualTree?.Invoke(this, e);
            e.Root?.Renderer?.AddDirty(this);

            if (VisualChildren != null)
            {
                foreach (Visual child in VisualChildren.OfType <Visual>())
                {
                    child.OnDetachedFromVisualTreeCore(e);
                }
            }
        }
Example #9
0
        /// <summary>
        /// Called when the <see cref="MenuItem"/> is attached to the visual tree.
        /// </summary>
        /// <param name="root">The root of the visual tree.</param>
        protected override void OnAttachedToVisualTree(IRenderRoot root)
        {
            base.OnAttachedToVisualTree(root);

            var topLevel = root as TopLevel;

            topLevel.Deactivated += Deactivated;

            var pointerPress = topLevel.AddHandler(
                PointerPressedEvent,
                TopLevelPreviewPointerPress,
                RoutingStrategies.Tunnel);

            _subscription = new CompositeDisposable(
                pointerPress,
                Disposable.Create(() => topLevel.Deactivated -= Deactivated));

            var inputRoot = root as IInputRoot;

            if (inputRoot != null && inputRoot.AccessKeyHandler != null)
            {
                inputRoot.AccessKeyHandler.MainMenu = this;
            }
        }
Example #10
0
        /// <inheritdoc/>
        protected override void OnDetachedFromVisualTree(IRenderRoot oldRoot)
        {
            base.OnDetachedFromVisualTree(oldRoot);

            if (this.IsDefault)
            {
                var inputElement = oldRoot as IInputElement;

                if (inputElement != null)
                {
                    this.StopListeningForDefault(inputElement);
                }
            }
        }
Example #11
0
 public IRenderer CreateRenderer(IRenderRoot root, IRenderLoop renderLoop)
 {
     return(new Renderer(root, renderLoop));
 }
Example #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="VisualTreeAttachmentEventArgs"/> class.
 /// </summary>
 /// <param name="parent">The parent that the visual is being attached to or detached from.</param>
 /// <param name="root">The root visual.</param>
 public VisualTreeAttachmentEventArgs(IVisual parent, IRenderRoot root)
 {
     Parent = parent ?? throw new ArgumentNullException(nameof(parent));
     Root   = root ?? throw new ArgumentNullException(nameof(root));
 }
Example #13
0
 public DeferredRendererProxy(IRenderRoot root)
 {
     _renderer     = new DeferredRenderer(root, this);
     _rendererTask = (IRenderLoopTask)_renderer;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="VisualTreeAttachmentEventArgs"/> class.
 /// </summary>
 /// <param name="root">The root visual.</param>
 public VisualTreeAttachmentEventArgs(IRenderRoot root)
 {
     Root = root;
 }
Example #15
0
 protected virtual void OnAttachedToVisualTree(IRenderRoot root)
 {
 }
Example #16
0
 /// <summary>
 /// Called when the control is removed to the visual tree.
 /// </summary>
 /// <param name="root">THe root of the visual tree.</param>
 protected override void OnDetachedFromVisualTree(IRenderRoot root)
 {
     base.OnDetachedFromVisualTree(root);
     _topLevel = null;
 }
Example #17
0
        /// <summary>
        /// Called when the control is attached to a visual tree.
        /// </summary>
        /// <param name="root">The root of the visual tree.</param>
        protected override void OnAttachedToVisualTree(IRenderRoot root)
        {
            base.OnAttachedToVisualTree(root);
            _accessKeys = (root as IInputRoot)?.AccessKeyHandler;

            if (_accessKeys != null && AccessKey != 0)
            {
                _accessKeys.Register(AccessKey, this);
            }
        }
Example #18
0
 public IRenderer CreateRenderer(IRenderRoot root, IRenderLoop renderLoop)
 {
     return(_cb?.Invoke(root, renderLoop));
 }
Example #19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="VisualTreeAttachmentEventArgs"/> class.
 /// </summary>
 /// <param name="root">The root visual.</param>
 /// <param name="nameScope">The name scope.</param>
 public VisualTreeAttachmentEventArgs(IRenderRoot root, INameScope nameScope)
 {
     Root      = root;
     NameScope = nameScope;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="VisualTreeAttachmentEventArgs"/> class.
        /// </summary>
        /// <param name="root">The root visual.</param>
        public VisualTreeAttachmentEventArgs(IRenderRoot root)
        {
            Contract.Requires <ArgumentNullException>(root != null);

            Root = root;
        }
 public IRenderer Create(IRenderRoot root, IRenderLoop renderLoop)
 => new ImmediateRenderer(root);
Example #22
0
 /// <inheritdoc/>
 protected override void OnAttachedToVisualTree(IRenderRoot root)
 {
     base.OnAttachedToVisualTree(root);
     _treeView = this.GetVisualAncestors().OfType<TreeView>().FirstOrDefault();
 }
 public IRenderer CreateRenderer(IRenderRoot root)
 => AvaloniaHeadlessPlatform.Compositor != null
         ? new CompositingRenderer(root, AvaloniaHeadlessPlatform.Compositor)
         : new DeferredRenderer(root, AvaloniaLocator.Current.GetRequiredService <IRenderLoop>());
Example #24
0
 /// <inheritdoc/>
 protected override void OnAttachedToVisualTree(IRenderRoot root)
 {
     base.OnAttachedToVisualTree(root);
     this.UpdateIsEnabledCore();
 }
 public IRenderer CreateRenderer(IRenderRoot root)
 {
     return(new DeferredRenderer(root, AvaloniaLocator.Current.GetService <IRenderLoop>())
     {
     });
 }
Example #26
0
 protected override void OnAttachedToVisualTree(IRenderRoot root)
 {
     base.OnAttachedToVisualTree(root);
     _grid = this.GetVisualParent <Grid>();
 }
Example #27
0
        protected override void OnAttachedToVisualTree(IRenderRoot root)
        {
            IStyler styler = Locator.Current.GetService <IStyler>();

            styler.ApplyStyles(this);
        }
Example #28
0
 /// <summary>
 /// Called when the control is removed to the visual tree.
 /// </summary>
 /// <param name="root">THe root of the visual tree.</param>
 protected override void OnDetachedFromVisualTree(IRenderRoot root)
 {
     base.OnDetachedFromVisualTree(root);
     _topLevel = null;
 }
Example #29
0
 protected virtual void OnDetachedFromVisualTree(IRenderRoot oldRoot)
 {
 }
Example #30
0
        /// <summary>
        /// Calls the <see cref="OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs)"/> method 
        /// for this control and all of its visual descendents.
        /// </summary>
        /// <param name="e">The event args.</param>
        protected virtual void OnDetachedFromVisualTreeCore(VisualTreeAttachmentEventArgs e)
        {
            Logger.Verbose(LogArea.Visual, this, "Detached from visual tree");

            VisualRoot = null;

            if (RenderTransform != null)
            {
                RenderTransform.Changed -= RenderTransformChanged;
            }

            OnDetachedFromVisualTree(e);

            if (VisualChildren != null)
            {
                foreach (Visual child in VisualChildren.OfType<Visual>())
                {
                    child.OnDetachedFromVisualTreeCore(e);
                }
            }
        }
Example #31
0
 /// <summary>
 /// Called when the <see cref="Menu"/> is detached from the visual tree.
 /// </summary>
 /// <param name="oldRoot">The root of the visual tree being detached from.</param>
 protected override void OnDetachedFromVisualTree(IRenderRoot oldRoot)
 {
     base.OnDetachedFromVisualTree(oldRoot);
     _subscription.Dispose();
 }
Example #32
0
        /// <summary>
        /// Calls the <see cref="OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs)"/> method 
        /// for this control and all of its visual descendents.
        /// </summary>
        /// <param name="e">The event args.</param>
        private void NotifyDetachedFromVisualTree(VisualTreeAttachmentEventArgs e)
        {
            _visualLogger.Verbose("Detached from visual tree");

            VisualRoot = null;
            OnDetachedFromVisualTree(e);

            if (VisualChildren != null)
            {
                foreach (Visual child in VisualChildren.OfType<Visual>())
                {
                    child.NotifyDetachedFromVisualTree(e);
                }
            }
        }
Example #33
0
        /// <summary>
        /// Called when the control is detached from a visual tree.
        /// </summary>
        /// <param name="root">The root of the visual tree.</param>
        protected override void OnDetachedFromVisualTree(IRenderRoot root)
        {
            base.OnDetachedFromVisualTree(root);

            if (_accessKeys != null && AccessKey != 0)
            {
                _accessKeys.Unregister(this);
                _accessKeys = null;
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="VisualTreeAttachmentEventArgs"/> class.
        /// </summary>
        /// <param name="root">The root visual.</param>
        public VisualTreeAttachmentEventArgs(IRenderRoot root)
        {
            Contract.Requires<ArgumentNullException>(root != null);

            Root = root;
        }
Example #35
0
 /// <summary>
 /// Called when the control is added to the visual tree.
 /// </summary>
 /// <param name="root">THe root of the visual tree.</param>
 protected override void OnAttachedToVisualTree(IRenderRoot root)
 {
     base.OnAttachedToVisualTree(root);
     _topLevel = root as TopLevel;
 }
Example #36
0
 protected override void OnAttachedToVisualTree(IRenderRoot root)
 {
     base.OnAttachedToVisualTree(root);
     _grid = this.GetVisualParent<Grid>();
 }
Example #37
0
 /// <inheritdoc/>
 protected override void OnAttachedToVisualTree(IRenderRoot root)
 {
     base.OnAttachedToVisualTree(root);
     _treeView = this.GetVisualAncestors().OfType <TreeView>().FirstOrDefault();
 }
Example #38
0
 /// <inheritdoc/>
 protected override void OnAttachedToVisualTree(IRenderRoot root)
 {
     base.OnAttachedToVisualTree(root);
     UpdateIsEnabledCore();
 }
 public IRenderer CreateRenderer(IRenderRoot root)
 {
     return(Renderer = new CompositingRenderer(root, _compositor));
 }
Example #40
0
        /// <summary>
        /// Called when the <see cref="MenuItem"/> is attached to the visual tree.
        /// </summary>
        /// <param name="root">The root of the visual tree.</param>
        protected override void OnAttachedToVisualTree(IRenderRoot root)
        {
            base.OnAttachedToVisualTree(root);

            var topLevel = root as TopLevel;

            topLevel.Deactivated += this.Deactivated;

            var pointerPress = topLevel.AddHandler(
                InputElement.PointerPressedEvent,
                this.TopLevelPreviewPointerPress,
                RoutingStrategies.Tunnel);

            this.subscription = new CompositeDisposable(
                pointerPress,
                Disposable.Create(() => topLevel.Deactivated -= this.Deactivated));

            var inputRoot = root as IInputRoot;

            if (inputRoot != null && inputRoot.AccessKeyHandler != null)
            {
                inputRoot.AccessKeyHandler.MainMenu = this;
            }
        }
Example #41
0
        /// <summary>
        /// Calls the <see cref="OnAttachedToVisualTree(VisualTreeAttachmentEventArgs)"/> method 
        /// for this control and all of its visual descendents.
        /// </summary>
        /// <param name="e">The event args.</param>
        private void NotifyAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
        {
            _visualLogger.Verbose("Attached to visual tree");

            VisualRoot = e.Root;

            OnAttachedToVisualTree(e);

            if (VisualChildren != null)
            {
                foreach (Visual child in VisualChildren.OfType<Visual>())
                {
                    child.NotifyAttachedToVisualTree(e);
                }
            }
        }
Example #42
0
 /// <summary>
 /// Called when the <see cref="Menu"/> is detached from the visual tree.
 /// </summary>
 /// <param name="oldRoot">The root of the visual tree being detached from.</param>
 protected override void OnDetachedFromVisualTree(IRenderRoot oldRoot)
 {
     base.OnDetachedFromVisualTree(oldRoot);
     this.subscription.Dispose();
 }
Example #43
0
 public IRenderer CreateRenderer(IRenderRoot root) => new ImmediateRenderer(root);
Example #44
0
 /// <summary>
 /// Called when the control is added to a visual tree.
 /// </summary>
 /// <param name="root">The root of the visual tree.</param>
 protected virtual void OnAttachedToVisualTree(IRenderRoot root)
 {
 }
Example #45
0
        /// <inheritdoc/>
        protected override void OnAttachedToVisualTree(IRenderRoot root)
        {
            base.OnAttachedToVisualTree(root);

            if (this.IsDefault)
            {
                var inputElement = root as IInputElement;

                if (inputElement != null)
                {
                    this.ListenForDefault(inputElement);
                }
            }
        }
Example #46
0
 /// <summary>
 /// Called when the control is removed from a visual tree.
 /// </summary>
 /// <param name="root">The root of the visual tree.</param>
 protected virtual void OnDetachedFromVisualTree(IRenderRoot root)
 {
 }
 public IRenderer CreateRenderer(IRenderRoot root, IRenderLoop renderLoop)
 {
     return new Renderer(root, renderLoop);
 }
Example #48
0
        /// <summary>
        /// Calls the <see cref="OnAttachedToVisualTree(IRenderRoot)"/> method for this control
        /// and all of its visual descendents.
        /// </summary>
        /// <param name="root">The root of the visual tree.</param>
        private void NotifyAttachedToVisualTree(IRenderRoot root)
        {
            this.visualLogger.Verbose("Attached to visual tree");

            this.isAttachedToVisualTree = true;
            this.OnAttachedToVisualTree(root);

            if (this.visualChildren != null)
            {
                foreach (Visual child in this.visualChildren.OfType<Visual>())
                {
                    child.NotifyAttachedToVisualTree(root);
                }
            }
        }
Example #49
0
        /// <inheritdoc/>
        protected override void OnDetachedFromVisualTree(IRenderRoot oldRoot)
        {
            base.OnDetachedFromVisualTree(oldRoot);

            if (this.IsFocused)
            {
                FocusManager.Instance.Focus(null);
            }
        }
Example #50
0
        /// <summary>
        /// Calls the <see cref="OnDetachedFromVisualTree(IRenderRoot)"/> method for this control
        /// and all of its visual descendents.
        /// </summary>
        /// <param name="root">The root of the visual tree.</param>
        private void NotifyDetachedFromVisualTree(IRenderRoot root)
        {
            this.visualLogger.Verbose("Detached from visual tree");

            this.isAttachedToVisualTree = false;
            this.OnDetachedFromVisualTree(root);

            if (this.visualChildren != null)
            {
                foreach (Visual child in this.visualChildren.OfType<Visual>())
                {
                    child.NotifyDetachedFromVisualTree(root);
                }
            }
        }
Example #51
0
 /// <summary>
 /// Called when the control is added to the visual tree.
 /// </summary>
 /// <param name="root">THe root of the visual tree.</param>
 protected override void OnAttachedToVisualTree(IRenderRoot root)
 {
     base.OnAttachedToVisualTree(root);
     _topLevel = root as TopLevel;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="VisualTreeAttachmentEventArgs"/> class.
 /// </summary>
 /// <param name="root">The root visual.</param>
 /// <param name="nameScope">The name scope.</param>
 public VisualTreeAttachmentEventArgs(IRenderRoot root, INameScope nameScope)
 {
     Root = root;
     NameScope = nameScope;
 }
Example #53
0
 public IRenderer CreateRenderer(IRenderRoot root)
 {
     return(new ImmediateRenderer(root));
 }
Example #54
0
 private ImmediateRenderer(IVisual root, bool updateTransformedBounds)
 {
     _root       = root ?? throw new ArgumentNullException(nameof(root));
     _renderRoot = root as IRenderRoot;
     _updateTransformedBounds = updateTransformedBounds;
 }