Ejemplo n.º 1
0
        /// <summary>
        /// RealizeItems from the itemsToRealize enumerable upto the maxItemsToRealize limit.
        /// </summary>
        /// <param name="itemsToRealize">items to realize</param>
        /// <param name="realizedItems">Set of Realized Items</param>
        /// <param name="maxItemsToRealize">Max limit of items to realize</param>
        /// <returns>count of items realized.</returns>
        private int RealizeItems(IEnumerator <ISpatialItem> itemsToRealize, HashSet <ISpatialItem> realizedItems, int maxItemsToRealize)
        {
            int itemsRealized = 0;

            // This has to happen again because of the lazy throttling that can happen after RealizeOverride has returned.
            IVisualFactory f = VisualFactory ?? this.defaultFactory;

            f.BeginRealize();

            // Realize n items where n <= this.realizationQuantum.
            while (itemsRealized < maxItemsToRealize && itemsToRealize.MoveNext())
            {
                ISpatialItem item           = itemsToRealize.Current;
                Visual       realizedVisual = RealizeItem(item, false);

                if (realizedVisual != null)
                {
                    itemsRealized++;
                    realizedItems.Add(item);
                }
            }

            f.EndRealize();

            return(itemsRealized);
        }
Ejemplo n.º 2
0
        public void TickleZoomables(bool visibleOnly)
        {
            double         scale   = canvas.Scale;
            IVisualFactory factory = canvas.VisualFactory;

            factory.BeginRealize();

            // todo: timeslice this work (throttle it)
            IEnumerable <ISpatialItem> query = null;

            if (visibleOnly)
            {
                query = canvas.Items.GetItemsIntersecting(canvas.ActualViewbox);
            }
            else
            {
                query = canvas.Items;
            }
            foreach (ISpatialItem item in query)
            {
                Visual visual = canvas.VisualFromItem(item);
                if (visual == null && !canvas.IsPaused)
                {
                    visual = canvas.RealizeItem(item, false);
                }
                if (visual != null)
                {
                    TickleZoomable(scale, visual);
                    // see if there are any adorners on the visual that also need to be scaled
                    var layer = AdornerLayer.GetAdornerLayer(visual);
                    if (layer != null)
                    {
                        var adorners = layer.GetAdorners(visual as UIElement);
                        if (adorners != null)
                        {
                            foreach (var zoomableAdorner in adorners.OfType <ISemanticZoomable>())
                            {
                                TickleZoomable(scale, zoomableAdorner);
                            }
                        }
                    }
                }
            }

            factory.EndRealize();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Realizes and virtualizes items based on the current viewbox.
        /// </summary>
        /// <returns>An enumerator which allows this method to continue realization where it left off.</returns>
        private IEnumerator RealizeOverride()
        {
            IVisualFactory f = VisualFactory ?? this.defaultFactory;

            f.BeginRealize();
            IEnumerator <ISpatialItem> itemEnumerator = null;
            HashSet <ISpatialItem>     realizedItems  = new HashSet <ISpatialItem>();

            // RealizeItems
            if (this.Items != null)
            {
                IEnumerable <ISpatialItem> itemsToRealize = null;
                if (this.IsVirtualizing)
                {
                    // Only realize the items within our viewbox.
                    double scale   = Scale;
                    Rect   viewbox = ActualViewbox;

                    // Buffer the viewbox.
                    // This just seems to make things worse, especially when zoomed out a long way.
                    // A smarter algorithm would predict the direction we are moving and only prefetch those.
                    // viewbox.Inflate(viewbox.Width / 2, viewbox.Height / 2);

                    // Query the index for all items that intersect our viewbox.
                    // use ToList() because we can't leave the query to be lazy.
                    // by the time RealizeItems is called below the contents of the query
                    // may have mutated.
                    itemsToRealize = Items.GetItemsIntersecting(viewbox).ToList();
                }
                else
                {
                    // Get all items.
                    itemsToRealize = Items;
                }

                itemEnumerator = itemsToRealize.GetEnumerator();
                QuantizedWorkHandler realizeHandler = delegate(int realizationQuantum)
                {
                    return(this.RealizeItems(itemEnumerator, realizedItems, realizationQuantum));
                };

                while (this.SelfThrottlingWorker(ref this.realizationQuantum, realizeHandler))
                {
                    yield return(true);
                }

                // Raise VisualChildrenChanged only if new
                if (realizedItems.Count > 0)
                {
                    // Raise the VisualChildrenChanged event since all items are visible.
                    if (this.VisualChildrenChanged != null)
                    {
                        this.VisualChildrenChanged(this, EventArgs.Empty);
                    }
                }
            }

            // VirtualizeItems
            // Build a list of items to virtualize.
            IList <ISpatialItem> itemsToVirtualize = new List <ISpatialItem>(this.visualMap.Count);

            // Get any items that are no longer part of our result set.
            foreach (ISpatialItem item in this.visualMap.Keys)
            {
                if (!realizedItems.Contains(item))
                {
                    if (this.ShouldVirtualize(item))
                    {
                        itemsToVirtualize.Add(item);
                    }
                }
            }

            itemEnumerator = itemsToVirtualize.GetEnumerator();
            QuantizedWorkHandler virtualizingHandler = delegate(int virtualizationQuantum)
            {
                return(this.VirtualizeItems(itemEnumerator, virtualizationQuantum));
            };

            while (this.SelfThrottlingWorker(ref this.virtualizationQuantum, virtualizingHandler))
            {
                yield return(true);
            }

            f.EndRealize();
        }