aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Embroidery
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/Embroidery')
-rw-r--r--Software/Visual_Studio/Embroidery/Tango.EmbroideryUI/EmbroideryFileEditor.xaml.cs33
-rw-r--r--Software/Visual_Studio/Embroidery/Tango.EmbroideryUI/EmbroideryPath.cs6
2 files changed, 36 insertions, 3 deletions
diff --git a/Software/Visual_Studio/Embroidery/Tango.EmbroideryUI/EmbroideryFileEditor.xaml.cs b/Software/Visual_Studio/Embroidery/Tango.EmbroideryUI/EmbroideryFileEditor.xaml.cs
index 1ed1e5b18..6b86c68cb 100644
--- a/Software/Visual_Studio/Embroidery/Tango.EmbroideryUI/EmbroideryFileEditor.xaml.cs
+++ b/Software/Visual_Studio/Embroidery/Tango.EmbroideryUI/EmbroideryFileEditor.xaml.cs
@@ -101,6 +101,7 @@ namespace Tango.EmbroideryUI
EmbroideryFile = output.EmbroideryFile;
DrawFile();
+ ScaleToFit();
}
protected virtual void OnPathsChanged()
@@ -253,5 +254,37 @@ namespace Tango.EmbroideryUI
}
#endregion
+
+ #region Public Methods
+
+ public void ScaleToFit()
+ {
+ double minX = Paths.Select(x => x.Path.GetFlattenedPathGeometry().Bounds.Left).Min();
+ double minY = Paths.Select(x => x.Path.GetFlattenedPathGeometry().Bounds.Top).Min();
+ double maxX = Paths.Select(x => x.Path.GetFlattenedPathGeometry().Bounds.Right).Max();
+ double maxY = Paths.Select(x => x.Path.GetFlattenedPathGeometry().Bounds.Bottom).Max();
+
+ Rect embRect = new Rect(minX, minY, maxX - minX, maxY - minY);
+ Rect editorRect = new Rect(0, 0, ActualWidth, ActualHeight);
+
+ double embRectArea = embRect.Width * embRect.Height;
+ double editorRectArea = editorRect.Width * editorRect.Height;
+
+ double factor = (editorRect.Width / embRect.Width) / 2d;
+
+ if (embRect.Height > embRect.Width)
+ {
+ factor = (editorRect.Height / embRect.Height) / 2d;
+ }
+
+ ScaleFactor = factor;
+
+ minY = Paths.Select(x => x.Path.GetFlattenedPathGeometry().Bounds.Top).Min();
+ minX = Paths.Select(x => x.Path.GetFlattenedPathGeometry().Bounds.Left).Min();
+
+ list.Margin = new Thickness(minX / 2, -minY / 2, 0, 0);
+ }
+
+ #endregion
}
}
diff --git a/Software/Visual_Studio/Embroidery/Tango.EmbroideryUI/EmbroideryPath.cs b/Software/Visual_Studio/Embroidery/Tango.EmbroideryUI/EmbroideryPath.cs
index 5999845bf..33f14cd27 100644
--- a/Software/Visual_Studio/Embroidery/Tango.EmbroideryUI/EmbroideryPath.cs
+++ b/Software/Visual_Studio/Embroidery/Tango.EmbroideryUI/EmbroideryPath.cs
@@ -11,7 +11,7 @@ namespace Tango.EmbroideryUI
{
public class EmbroideryPath : Shape
{
- private PathGeometry _path;
+ public PathGeometry Path { get; private set; }
public Brush Brush
{
@@ -72,14 +72,14 @@ namespace Tango.EmbroideryUI
public EmbroideryPath(PathGeometry path)
{
- _path = path;
+ Path = path;
}
protected override Geometry DefiningGeometry
{
get
{
- return _path;
+ return Path;
}
}
}