/// <summary> /// Converts the given <see cref="OrientedRectangle"/> from the world into the view coordinate space. /// </summary> internal static void WorldToIntermediateCoordinates(ICanvasContext context, OrientedRectangle rect) { var anchor = new PointD(rect.Anchor); var anchorAndUp = anchor + rect.GetUp(); var renderContext = context as IRenderContext ?? context.Lookup(typeof(IRenderContext)) as IRenderContext; if (renderContext != null) { anchor = renderContext.WorldToIntermediateCoordinates(anchor); anchorAndUp = renderContext.WorldToIntermediateCoordinates(anchorAndUp); } else { var cc = context.Lookup(typeof(CanvasControl)) as CanvasControl; if (cc != null) { anchor = cc.WorldToIntermediateCoordinates(anchor); anchorAndUp = cc.WorldToIntermediateCoordinates(anchorAndUp); } else { // too bad - infer trivial scale matrix anchor *= context.Zoom; anchorAndUp *= context.Zoom; } } rect.SetUpVector((anchorAndUp - anchor).Normalized); rect.SetAnchor(anchor); rect.Width *= context.Zoom; rect.Height *= context.Zoom; }
public Visual UpdateSelectionVisual(IRenderContext context, Visual oldVisual, IOrientedRectangle layout) { var container = oldVisual as VisualGroup; if (container != null && container.Children.Count == 1) { var visual = container.Children[0] as FrameworkElement; if (visual != null) { Transform transform = context.IntermediateTransform; container.Transform = transform; var anchor = layout.GetAnchorLocation(); var anchorAndUp = anchor + layout.GetUp(); anchor = context.WorldToIntermediateCoordinates(anchor); anchorAndUp = context.WorldToIntermediateCoordinates(anchorAndUp); var or = new OrientedRectangle(); or.SetUpVector((anchorAndUp - anchor).Normalized); or.SetAnchor(anchor); or.Width = layout.Width * context.Zoom; or.Height = layout.Height * context.Zoom; visual.Width = or.Width; visual.Height = or.Height; visual.SetCanvasArrangeRect(new Rect(0, 0, or.Width, or.Height)); ArrangeByLayout(context, visual, or, false); if (!container.IsMeasureValid) { container.Arrange(new Rect(0, 0, or.Width, or.Height)); } return(container); } } return(CreateSelectionVisual(context, layout)); }