Ejemplo n.º 1
0
        /// <summary>
        /// Creates an object containing all necessary data to create an edge visual
        /// </summary>
        private static RenderDataCache CreateRenderDataCache(IRenderContext context, ILabel edge)
        {
            IGraphSelection selection = context.CanvasControl != null?context.CanvasControl.Lookup <IGraphSelection>() : null;

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

            return(new RenderDataCache(selected));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates an object containing all necessary data to create an edge visual
        /// </summary>
        private RenderDataCache CreateRenderDataCache(IRenderContext context, IEdge edge)
        {
            IGraphSelection selection = context.CanvasControl != null?context.CanvasControl.Lookup <IGraphSelection>() : null;

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

            return(new RenderDataCache(PathThickness, selected, GetPath(edge), Arrows));
        }
        /// <summary>
        /// Creates an object containing all necessary data to create an edge visual
        /// </summary>
        private RenderDataCache CreateRenderDataCache(IRenderContext context, IEdge edge)
        {
            IGraphSelection selection = context.CanvasControl != null?context.CanvasControl.Lookup <IGraphSelection>() : null;

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

            //////////////// New in this sample ////////////////
            // The RenderDataCache now also holds information about the bridges (the obstacle hash)
            // so the edge will be re-rendered after the bridges have changed
            // Note that the cached path is the edge path *without* bridges
            return(new RenderDataCache(PathThickness, selected, GetPath(edge), Arrows, GetObstacleHash(context)));
        }
        protected override Pen GetPen()
        {
            var tag = (CustomTag)Edge.Tag;

            if (tag == null)
            {
                return(base.GetPen());
            }
            var thickness = tag.thickness;
            var color     = tag.brush.Color;
            var selected  = selection.IsSelected(Edge);

            color.A = (byte)(selected ? 127 : 204);

            return(new Pen(tag.brush, highlight ? Math.Max(thickness + 2, 2) : thickness));
        }
        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);
        }