内部基础ZoomBox

This commit is contained in:
艾竹
2023-02-14 22:54:55 +08:00
parent 3ef7434f5b
commit debd7e711d
8 changed files with 541 additions and 472 deletions

View File

@@ -80,6 +80,20 @@ namespace AIStudio.Wpf.DiagramDesigner
#endregion
public static readonly DependencyProperty OffSetProperty =
DependencyProperty.Register(nameof(OffSet), typeof(bool), typeof(ZoomBox), new UIPropertyMetadata(false));
public bool OffSet
{
get
{
return (bool)GetValue(OffSetProperty);
}
set
{
SetValue(OffSetProperty, value);
}
}
public static readonly DependencyProperty ZoomValueProperty =
DependencyProperty.Register(nameof(ZoomValue), typeof(double), typeof(ZoomBox), new UIPropertyMetadata(1d));
public double ZoomValue
@@ -200,18 +214,36 @@ namespace AIStudio.Wpf.DiagramDesigner
private void InvalidateScale(out double scale, out double xOffset, out double yOffset)
{
Vector vector = System.Windows.Media.VisualTreeHelper.GetOffset(DesignerCanvas);
double w = DesignerCanvas.ActualWidth + vector.X * 2;
double h = DesignerCanvas.ActualHeight + vector.Y * 2;
if (OffSet)
{
Vector vector = System.Windows.Media.VisualTreeHelper.GetOffset(DesignerCanvas);
double w = DesignerCanvas.ActualWidth + vector.X * 2;
double h = DesignerCanvas.ActualHeight + vector.Y * 2;
// zoom canvas size
double x = this.zoomCanvas.ActualWidth;
double y = this.zoomCanvas.ActualHeight;
double scaleX = x / w;
double scaleY = y / h;
scale = (scaleX < scaleY) ? scaleX : scaleY;
xOffset = (x - scale * w) / 2;
yOffset = (y - scale * h) / 2;
// zoom canvas size
double x = this.zoomCanvas.ActualWidth;
double y = this.zoomCanvas.ActualHeight;
double scaleX = x / w;
double scaleY = y / h;
scale = (scaleX < scaleY) ? scaleX : scaleY;
xOffset = (x - scale * w) / 2;
yOffset = (y - scale * h) / 2;
}
else
{
double w = DesignerCanvas.ActualWidth;
double h = DesignerCanvas.ActualHeight;
// zoom canvas size
double x = this.zoomCanvas.ActualWidth;
double y = this.zoomCanvas.ActualHeight;
double scaleX = x / w;
double scaleY = y / h;
scale = (scaleX < scaleY) ? scaleX : scaleY;
xOffset = (x - scale * w) / 2;
yOffset = (y - scale * h) / 2;
}
}
}
}