页边距修改

This commit is contained in:
艾竹
2023-01-24 20:51:39 +08:00
parent 1a291411e6
commit 66d3a6685b
11 changed files with 85 additions and 39 deletions

View File

@@ -102,18 +102,18 @@ namespace AIStudio.Wpf.DiagramDesigner
#endregion
#region GridMargin mm
#region GridMarginSize mm
public static readonly DependencyProperty GridMarginProperty =
DependencyProperty.Register(nameof(GridMargin),
typeof(double),
public static readonly DependencyProperty GridMarginSizeProperty =
DependencyProperty.Register(nameof(GridMarginSize),
typeof(Size),
typeof(DesignerCanvas),
new FrameworkPropertyMetadata(28d, FrameworkPropertyMetadataOptions.AffectsRender));
new FrameworkPropertyMetadata(new Size(28, 28), FrameworkPropertyMetadataOptions.AffectsRender));
public double GridMargin
public Size GridMarginSize
{
get { return (double)GetValue(GridMarginProperty); }
set { SetValue(GridMarginProperty, value); }
get { return (Size)GetValue(GridMarginSizeProperty); }
set { SetValue(GridMarginSizeProperty, value); }
}
#endregion
@@ -137,13 +137,13 @@ namespace AIStudio.Wpf.DiagramDesigner
protected virtual void DrawGrid(DrawingContext dc, Rect rect)
{
//using .5 forces wpf to draw a single pixel line
for (var i = GridMargin + 0.5; i < rect.Height - GridMargin; i += GridCellSize.Height)
dc.DrawLine(new Pen(new SolidColorBrush(GridColor), 1), new Point(GridMargin, i), new Point(rect.Width - GridMargin, i));
dc.DrawLine(new Pen(new SolidColorBrush(GridColor), 1), new Point(GridMargin, rect.Height - GridMargin), new Point(rect.Width - GridMargin, rect.Height - GridMargin));
for (var i = GridMarginSize.Height + 0.5; i < rect.Height - GridMarginSize.Height; i += GridCellSize.Height)
dc.DrawLine(new Pen(new SolidColorBrush(GridColor), 1), new Point(GridMarginSize.Width, i), new Point(rect.Width - GridMarginSize.Width, i));
dc.DrawLine(new Pen(new SolidColorBrush(GridColor), 1), new Point(GridMarginSize.Width, rect.Height - GridMarginSize.Height), new Point(rect.Width - GridMarginSize.Width, rect.Height - GridMarginSize.Height));
for (var i = GridMargin + 0.5; i < rect.Width - GridMargin; i += GridCellSize.Width)
dc.DrawLine(new Pen(new SolidColorBrush(GridColor), 1), new Point(i, GridMargin), new Point(i, rect.Height - GridMargin));
dc.DrawLine(new Pen(new SolidColorBrush(GridColor), 1), new Point(rect.Width - GridMargin, GridMargin), new Point(rect.Width - GridMargin, rect.Height - GridMargin));
for (var i = GridMarginSize.Width + 0.5; i < rect.Width - GridMarginSize.Width; i += GridCellSize.Width)
dc.DrawLine(new Pen(new SolidColorBrush(GridColor), 1), new Point(i, GridMarginSize.Height), new Point(i, rect.Height - GridMarginSize.Height));
dc.DrawLine(new Pen(new SolidColorBrush(GridColor), 1), new Point(rect.Width - GridMarginSize.Width, GridMarginSize.Height), new Point(rect.Width - GridMarginSize.Width, rect.Height - GridMarginSize.Height));
}
private void _service_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)

View File

@@ -38,7 +38,7 @@ namespace AIStudio.Wpf.DiagramDesigner
link.SinkConnectorInfo.MiddlePosition,
link.IsFullConnection ? link.SinkConnectorInfoFully.Orientation : (link.SinkConnectorInfo.MiddlePosition.Y >= link.SourceConnectorInfo.MiddlePosition.Y ? ConnectorOrientation.Top : ConnectorOrientation.Bottom),
_.GridCellSize,
_.GridMargin);
_.GridMarginSize);
middle.Insert(0, route[0]);
middle.Add(route[1]);
@@ -46,7 +46,7 @@ namespace AIStudio.Wpf.DiagramDesigner
return middle.ToArray();
}
private static List<PointBase> GetMiddlePoints(PointBase source, ConnectorOrientation sourceOrientation, PointBase sink, ConnectorOrientation sinkOrientation, SizeBase gridCellSize, double gridMargin)
private static List<PointBase> GetMiddlePoints(PointBase source, ConnectorOrientation sourceOrientation, PointBase sink, ConnectorOrientation sinkOrientation, SizeBase gridCellSize, SizeBase gridMargin)
{
var points = new List<PointBase>();
@@ -56,8 +56,8 @@ namespace AIStudio.Wpf.DiagramDesigner
if (p0 == p1)
return points;
var p2 = new PointBase(GetNearestCross(p0.X, p1.X, gridCellSize.Width, gridMargin), GetNearestCross(p0.Y, p1.Y, gridCellSize.Height, gridMargin));
var p3 = new PointBase(GetNearestCross(p1.X, p0.X, gridCellSize.Width, gridMargin), GetNearestCross(p1.Y, p0.Y, gridCellSize.Height, gridMargin));
var p2 = new PointBase(GetNearestCross(p0.X, p1.X, gridCellSize.Width, gridMargin.Width), GetNearestCross(p0.Y, p1.Y, gridCellSize.Height, gridMargin.Height));
var p3 = new PointBase(GetNearestCross(p1.X, p0.X, gridCellSize.Width, gridMargin.Width), GetNearestCross(p1.Y, p0.Y, gridCellSize.Height, gridMargin.Height));
if (p2 == p3)
{
points.Add(p0);
@@ -77,10 +77,10 @@ namespace AIStudio.Wpf.DiagramDesigner
return points;
}
private static PointBase GetFirstSegment(PointBase point, ConnectorOrientation orientation, SizeBase cellSize, double margin)
private static PointBase GetFirstSegment(PointBase point, ConnectorOrientation orientation, SizeBase cellSize, SizeBase margin)
{
double x = ((int)((point.X - margin) / cellSize.Width) + 0.5) * cellSize.Width + margin;
double y = ((int)((point.Y - margin) / cellSize.Height) + 0.5) * cellSize.Height + margin;
double x = ((int)((point.X - margin.Width) / cellSize.Width) + 0.5) * cellSize.Width + margin.Width;
double y = ((int)((point.Y - margin.Height) / cellSize.Height) + 0.5) * cellSize.Height + margin.Height;
if (orientation == ConnectorOrientation.Top)
return new PointBase(x, y - 0.5 * cellSize.Height);
else if (orientation == ConnectorOrientation.Bottom)

View File

@@ -942,7 +942,7 @@
Width="{Binding PageSize.Width}"
ShowGrid="{Binding ShowGrid}"
GridCellSize="{Binding GridCellSize}"
GridMargin="{Binding GridMargin}"
GridMarginSize="{Binding GridMarginSize}"
GridColor="{Binding GridColor}"
Background="{Binding PageBackground,Converter={StaticResource ColorBrushConverter}}"
AllowDrop="True">

View File

@@ -387,18 +387,18 @@ namespace AIStudio.Wpf.DiagramDesigner
{
if (Root.GridCellSize.Width > this.ItemWidth)
{
this.Left = (int)(this.Left / Root.GridCellSize.Width) * Root.GridCellSize.Width + Root.GridMargin + (Root.GridCellSize.Width - this.ItemWidth) / 2;
this.Left = (int)(this.Left / Root.GridCellSize.Width) * Root.GridCellSize.Width + Root.GridMarginSize.Width + (Root.GridCellSize.Width - this.ItemWidth) / 2;
}
}
else if (Root.CellHorizontalAlignment == CellHorizontalAlignment.Left)
{
this.Left = (int)(this.Left / Root.GridCellSize.Width) * Root.GridCellSize.Width + Root.GridMargin;
this.Left = (int)(this.Left / Root.GridCellSize.Width) * Root.GridCellSize.Width + Root.GridMarginSize.Width;
}
else if (Root.CellHorizontalAlignment == CellHorizontalAlignment.Right)
{
if (Root.GridCellSize.Width > this.ItemWidth)
{
this.Left = (int)(this.Left / Root.GridCellSize.Width) * Root.GridCellSize.Width + Root.GridMargin + (Root.GridCellSize.Width - this.ItemWidth);
this.Left = (int)(this.Left / Root.GridCellSize.Width) * Root.GridCellSize.Width + Root.GridMarginSize.Width + (Root.GridCellSize.Width - this.ItemWidth);
}
}
@@ -406,18 +406,18 @@ namespace AIStudio.Wpf.DiagramDesigner
{
if (Root.GridCellSize.Height > this.ItemHeight)
{
this.Top = (int)(this.Top / Root.GridCellSize.Height) * Root.GridCellSize.Height + Root.GridMargin + (Root.GridCellSize.Height - this.ItemHeight) / 2;
this.Top = (int)(this.Top / Root.GridCellSize.Height) * Root.GridCellSize.Height + Root.GridMarginSize.Height + (Root.GridCellSize.Height - this.ItemHeight) / 2;
}
}
else if (Root.CellVerticalAlignment == CellVerticalAlignment.Top)
{
this.Top = (int)(this.Top / Root.GridCellSize.Height) * Root.GridCellSize.Height + Root.GridMargin;
this.Top = (int)(this.Top / Root.GridCellSize.Height) * Root.GridCellSize.Height + Root.GridMarginSize.Height;
}
else if (Root.CellVerticalAlignment == CellVerticalAlignment.Bottom)
{
if (Root.GridCellSize.Height > this.ItemHeight)
{
this.Top = (int)(this.Top / Root.GridCellSize.Height) * Root.GridCellSize.Height + Root.GridMargin + (Root.GridCellSize.Height - this.ItemHeight);
this.Top = (int)(this.Top / Root.GridCellSize.Height) * Root.GridCellSize.Height + Root.GridMarginSize.Height + (Root.GridCellSize.Height - this.ItemHeight);
}
}
}

View File

@@ -227,8 +227,8 @@ namespace AIStudio.Wpf.DiagramDesigner
}
}
private double _gridMargin = 28d;
public double GridMargin
private Size _gridMargin = new Size(28, 28);
public Size GridMarginSize
{
get
{
@@ -240,6 +240,32 @@ namespace AIStudio.Wpf.DiagramDesigner
}
}
public double GridMarginWidth
{
get
{
return _gridMargin.Width;
}
set
{
_gridMargin.Width = value;
RaisePropertyChanged(nameof(GridMarginSize));
}
}
public double GridMarginHeight
{
get
{
return _gridMargin.Height;
}
set
{
_gridMargin.Height = value;
RaisePropertyChanged(nameof(GridMarginSize));
}
}
private double _zoomValue = 1;
[Browsable(false)]
public double ZoomValue

View File

@@ -228,7 +228,7 @@ namespace AIStudio.Wpf.DiagramDesigner
{
get; set;
}
double GridMargin
Size GridMarginSize
{
get; set;
}