Beispiel #1
0
        /// <summary>
        /// Creates the visual for the label.
        /// </summary>
        /// <remarks>
        /// Implementation of LabelStyleBase.CreateVisual.
        /// </remarks>
        /// <param name="context">The render context.</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>
        protected override VisualGroup CreateVisual(IRenderContext context, ILabel label)
        {
            // Updates the dummy label which is internally used for rendering with the properties of the given label.
            UpdateDummyLabel(context, label);
            // creates the container for the visual and sets a transform for view coordinates
            var container = new VisualGroup();

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

            RenderDataCache cache = CreateRenderDataCache(context, label);

            container.SetRenderDataCache(cache);

            var creator = InnerLabelStyle.Renderer.GetVisualCreator(dummyLabel, InnerLabelStyle);

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

            //The wrapped style should always think it's rendering with zoom level 1
            var visual = creator.CreateVisual(innerContext);

            if (visual == null)
            {
                return(container);
            }

            // add the created visual to the container
            container.Children.Add(visual);
            // if the label is selected, add the selection visualization, too.
            if (cache.Selected)
            {
                UIElement selectionVisual = CreateSelectionVisual(innerContext, dummyLabel.GetLayout()) as UIElement;
                if (selectionVisual != null)
                {
                    selectionVisual.IsHitTestVisible = false;
                }
                container.Children.Add(selectionVisual);
            }
            return(container);
        }
        protected override VisualGroup CreateVisual(IRenderContext context, ILabel label)
        {
            // Updates the dummy label which is internally used for rendering with the properties of the given label.
            UpdateDummyLabel(context, label);

            // creates the container for the visual and sets a transform for view coordinates
            var container       = new VisualGroup();
            var toViewTransform = context.WorldTransform.Clone();

            toViewTransform.Invert();
            // ReSharper disable once PossibleUnintendedReferenceComparison
            if (container.Transform != toViewTransform)
            {
                container.Transform = toViewTransform;
            }

            var creator = InnerLabelStyle.Renderer.GetVisualCreator(dummyLabel, InnerLabelStyle);

            // create a new IRenderContext with a zoom of 1
            // TODO: Projections
            var innerContext = new RenderContext(context.Graphics, context.CanvasControl)
            {
                ViewTransform = context.ViewTransform, WorldTransform = context.WorldTransform, Zoom = 1
            };

            //The wrapped style should always think it's rendering with zoom level 1
            var visual = creator.CreateVisual(innerContext);

            if (visual == null)
            {
                return(container);
            }

            // add the created visual to the container
            container.Children.Add(visual);


            IGraphSelection selection = context.CanvasControl != null?context.CanvasControl.Lookup <IGraphSelection>() : null;

            bool selected = selection != null && selection.IsSelected(label);

            // if the label is selected, add the selection visualization, too.

            if (selected)
            {
                //The selection descriptor performs its own calculation in the view coordinate system, so
                //the size and the position of the visualization would be wrong and need to be converted back into world
                //coordinates
                var layout          = dummyLabel.GetLayout();
                var p1              = context.CanvasControl.ToWorldCoordinates(layout.GetAnchorLocation());
                var selectionLayout = new OrientedRectangle
                {
                    Anchor = p1,
                    Width  = layout.Width / context.Zoom,
                    Height = layout.Height / context.Zoom
                };

                selectionLayout.SetUpVector(layout.UpX, layout.UpY);
                var selectionVisual = new OrientedRectangleIndicatorInstaller().Template;
                container.Children.Add(selectionVisual);
            }
            return(container);
        }