Click here to Skip to main content
15,888,069 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
have a canvas on which I have a set of curves stored in

private List<System.Windows.Shapes.Path> paths = new List<System.Windows.Shapes.Path>();


in it there can be several curves of which some of them can be PolyLineSegments with a very large number of points.

AFTER having drawn the curves I may have to pan/zoom the canvas. On the internet I've found this very brilliant solution:

C#
public static class CanvasUtils
{
    public static Canvas SetCoordinateSystem(this Canvas canvas, Double xMin, Double xMax, Double yMin, Double yMax)
    {
        var width = xMax - xMin;
        var height = yMax - yMin;
        var translateX = -xMin;
        var translateY = height + yMin;
        var group = new TransformGroup();
        group.Children.Add(new TranslateTransform(translateX, -translateY));
        group.Children.Add(new ScaleTransform(canvas.ActualWidth / width, canvas.ActualHeight / -height));
        canvas.RenderTransform = group;
        return canvas;
    }
}



Unfortunately it doesn't do for me since this enlarges everything making the curve look horrible (just like looking at it through a lens), with a thick stroke. This just like a real lens zoom.

So the only solution which comes to my mind is to REPROCESS all points and transform EACH of them to the new coordinate system. But that's not very smart and time consuming. Any other more brilliant solution?

Thanks in advance Patrick
Posted
Comments
Kenneth Haugland 15-Sep-15 13:52pm    
>So the only solution which comes to my mind is to REPROCESS all points and transform >EACH of them to the new coordinate system. But that's not very smart and time >consuming. Any other more brilliant solution?

I would think all the points need to be recalculated in any zoom, its just that you don't see those calculations.

1 solution

This is how WPF works. Do you mean to have everything with the same line thickness, regardless of the zoom level?
If so, I would reconsider this requirement: it does not look very reasonable. What's really wrong with "lens zoom"? This is real zoom.

If you really want the zoom preserving visible absolute thickness, you still have to reprocess, as you suggested. All I can advice is: streamline this "reprocessing" in the following way: for all the types of the Canvas children, create derived classes and use only them. In those derived class, abstract out the "line thickness factor" property, which changes all thicknesses of all lines (which have to be stored in the instance fields) by some factor. That is, if you traverse all your Canvas children and change only this factors, nothing will zoom, only the line thicknesses will change proportionally. Now, combine this process with zoom: if you zoom by factor in Z; change "line thickness factor" by 1/Z.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900