예제 #1
0
        /// <summary>
        /// Re-renders the node using the old visual for performance reasons.
        /// </summary>
        protected override VisualGroup UpdateVisual(IRenderContext context, VisualGroup oldVisual, INode node)
        {
            // get the data with which the old visual was created
            RenderDataCache oldCache = oldVisual.GetRenderDataCache <RenderDataCache>();
            // get the data for the new visual
            RenderDataCache newCache = CreateRenderDataCache(context, node);

            // check if something changed except for the location of the node
            if (!newCache.Equals(oldCache))
            {
                // something changed - re-render the visual
                oldVisual.Children.Clear();
                Render(context, node, oldVisual, newCache);
            }
            // make sure that the location is up to date
            oldVisual.SetCanvasArrangeRect(node.Layout.ToRectD());
            return(oldVisual);
        }
예제 #2
0
        /// <summary>
        /// Re-renders the label using the old visual for performance reasons.
        /// </summary>
        protected override VisualGroup UpdateVisual(IRenderContext context, VisualGroup oldVisual, ILabel label)
        {
            // get the data with which the old visual was created
            RenderDataCache oldCache = oldVisual.GetRenderDataCache <RenderDataCache>();
            // get the data for the new visual
            RenderDataCache newCache    = CreateRenderDataCache(context, label, Typeface);
            var             labelLayout = label.GetLayout();

            if (!oldCache.Equals(newCache))
            {
                // something changed - re-render the visual
                oldVisual.Children.Clear();
                Render(context, label, oldVisual, labelLayout, newCache);
            }
            // nothing changed, return the old visual
            // arrange because the layout might have changed
            ArrangeByLayout(context, oldVisual, labelLayout, true);
            return(oldVisual);
        }
        protected override VisualGroup UpdateVisual(IRenderContext context, VisualGroup oldVisual, IStripe stripe)
        {
            var       layout = stripe.Layout.ToRectD();
            Thickness stripeInsets;
            //Check if values have changed - then update everything
            StripeDescriptor descriptor;

            if (stripe is IColumn)
            {
                var col = (IColumn)stripe;
                stripeInsets = new Thickness(0, col.GetActualInsets().Top, 0, col.GetActualInsets().Bottom);
            }
            else
            {
                var row = (IRow)stripe;
                stripeInsets = new Thickness(row.GetActualInsets().Left, 0, row.GetActualInsets().Right, 0);
            }

            Thickness actualBorderThickness;

            if (stripe.GetChildStripes().Any())
            {
                descriptor            = ParentDescriptor;
                actualBorderThickness = descriptor.BorderThickness;
            }
            else
            {
                int index;
                if (stripe is IColumn)
                {
                    var col   = (IColumn)stripe;
                    var leafs = col.Table.RootColumn.GetLeaves().ToList();
                    index                 = leafs.FindIndex((curr) => col == curr);
                    descriptor            = index % 2 == 0 ? EvenLeafDescriptor : OddLeafDescriptor;
                    actualBorderThickness = descriptor.BorderThickness;
                }
                else
                {
                    var row   = (IRow)stripe;
                    var leafs = row.Table.RootRow.GetLeaves().ToList();
                    index                 = leafs.FindIndex((curr) => row == curr);
                    descriptor            = index % 2 == 0 ? EvenLeafDescriptor : OddLeafDescriptor;
                    actualBorderThickness = descriptor.BorderThickness;
                }
            }

            // get the data with which the oldvisual was created
            var oldCache = oldVisual.GetRenderDataCache <RenderDataCache>();
            // get the data for the new visual
            RenderDataCache newCache = CreateRenderDataCache(context, descriptor, stripe, stripeInsets);

            // check if something changed except for the location of the node
            if (!newCache.Equals(oldCache))
            {
                // something changed - just re-render the visual
                return(CreateVisual(context, stripe));
            }

            Border borderVisual = (Border)oldVisual.Children[0];

            borderVisual.Width           = layout.Width;
            borderVisual.Height          = layout.Height;
            borderVisual.BorderThickness = stripeInsets;

            Border stripeVisual = (Border)oldVisual.Children[1];

            stripeVisual.Width           = layout.Width;
            stripeVisual.Height          = layout.Height;
            stripeVisual.BorderThickness = actualBorderThickness;
            oldVisual.SetCanvasArrangeRect(layout.ToRectD());
            return(oldVisual);
        }
예제 #4
0
        /// <summary>
        /// Update the visual previously created by <see cref="CreateVisual"/>.
        /// </summary>
        /// <remarks>
        /// Implementation of LabelStyleBase.UpdateVisual.
        /// </remarks>
        /// <param name="context">The render context.</param>
        /// <param name="oldVisual">The visual that has been created in the call to <see cref="CreateVisual"/>.</param>
        /// <param name="label">The label to which this style instance is assigned.</param>
        /// <returns>The visual as required by the <see cref="IVisualCreator.CreateVisual"/> interface.</returns>
        /// <seealso cref="CreateVisual"/>
        protected override VisualGroup UpdateVisual(IRenderContext context, VisualGroup oldVisual, ILabel label)
        {
            // get the data with which the old visual was created
            RenderDataCache oldCache = oldVisual.GetRenderDataCache <RenderDataCache>();
            // get the data for the new visual
            RenderDataCache newCache = CreateRenderDataCache(context, label);

            oldVisual.SetRenderDataCache(newCache);

            // create a new visual if the cache has been changed or the container's contents seem to be wrong
            bool cacheChanged = !newCache.Equals(oldCache);

            if (cacheChanged)
            {
                return(CreateVisual(context, label));
            }

            if (oldVisual == null || oldVisual.Children.Count != (newCache.Selected?2:1))
            {
                return(CreateVisual(context, label));
            }

            var visual = oldVisual.Children[0];

            if (visual == null)
            {
                return(CreateVisual(context, label));
            }

            // Updates the dummy label which is internally used for rendering with the properties of the given label.
            UpdateDummyLabel(context, label);

            // create a new IRenderContext with a zoom of 1
            var cc           = new ContextConfigurator(context.CanvasControl.ContentRect);
            var innerContext = cc.CreateRenderContext(context.CanvasControl);

            // ReSharper disable once PossibleUnintendedReferenceComparison
            if (oldVisual.Transform != context.IntermediateTransform)
            {
                oldVisual.Transform = context.IntermediateTransform;
            }

            // update the visual created by the inner style renderer
            var creator       = InnerLabelStyle.Renderer.GetVisualCreator(dummyLabel, InnerLabelStyle);
            var updatedVisual = creator.UpdateVisual(innerContext, visual);

            if (updatedVisual == null)
            {
                // nothing to display -> return nothing
                return(null);
            }

            // ReSharper disable once PossibleUnintendedReferenceComparison
            if (updatedVisual != visual)
            {
                oldVisual.Remove(visual);
                oldVisual.Add(updatedVisual);
            }

            // if selected: update the selection visual, too.
            if (newCache.Selected)
            {
                var oldSelectionVisual = oldVisual.Children[1];

                Visual selectionVisual = UpdateSelectionVisual(innerContext, oldSelectionVisual, dummyLabel.GetLayout());
                // ReSharper disable once PossibleUnintendedReferenceComparison
                if (oldSelectionVisual != selectionVisual)
                {
                    oldVisual.Children.Remove(oldSelectionVisual);
                    oldVisual.Children.Add(selectionVisual);
                }
            }
            return(oldVisual);
        }