页边距修改

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

@@ -85,7 +85,21 @@ namespace AIStudio.Wpf.DiagramApp.Models
public PageSizeType PageSizeType { get; set; } public PageSizeType PageSizeType { get; set; }
[XmlAttribute] [XmlAttribute]
public double GridMargin { get; set; } public Size GridMarginSize { get; set; }
[JsonIgnore]
[XmlAttribute("GridMarginSize")]
public string XmlGridMarginSize
{
get
{
return SerializeHelper.SerializeSize(GridMarginSize);
}
set
{
GridMarginSize = SerializeHelper.DeserializeSize(value);
}
}
[XmlIgnore] [XmlIgnore]
public Color GridColor { get; set; } public Color GridColor { get; set; }

View File

@@ -250,7 +250,7 @@ namespace AIStudio.Wpf.DiagramApp.ViewModels
viewModel.PageSizeOrientation = diagramItem.PageSizeOrientation; viewModel.PageSizeOrientation = diagramItem.PageSizeOrientation;
viewModel.PageSize = diagramItem.PageSize; viewModel.PageSize = diagramItem.PageSize;
viewModel.PageSizeType = diagramItem.PageSizeType; viewModel.PageSizeType = diagramItem.PageSizeType;
viewModel.GridMargin = diagramItem.GridMargin; viewModel.GridMarginSize = diagramItem.GridMarginSize;
viewModel.GridColor = diagramItem.GridColor; viewModel.GridColor = diagramItem.GridColor;
foreach (DesignerItemBase diagramItemData in diagramItem.AllDesignerItems) foreach (DesignerItemBase diagramItemData in diagramItem.AllDesignerItems)
@@ -321,7 +321,7 @@ namespace AIStudio.Wpf.DiagramApp.ViewModels
diagramItem.PageSizeOrientation = viewModel.PageSizeOrientation; diagramItem.PageSizeOrientation = viewModel.PageSizeOrientation;
diagramItem.PageSize = viewModel.PageSize; diagramItem.PageSize = viewModel.PageSize;
diagramItem.PageSizeType = viewModel.PageSizeType; diagramItem.PageSizeType = viewModel.PageSizeType;
diagramItem.GridMargin = viewModel.GridMargin; diagramItem.GridMarginSize = viewModel.GridMarginSize;
diagramItem.GridColor = viewModel.GridColor; diagramItem.GridColor = viewModel.GridColor;
diagramItem.AddItems(DiagramViewModel.Items); diagramItem.AddItems(DiagramViewModel.Items);
@@ -496,7 +496,7 @@ namespace AIStudio.Wpf.DiagramApp.ViewModels
diagramItem.PageSizeOrientation = viewModel.PageSizeOrientation; diagramItem.PageSizeOrientation = viewModel.PageSizeOrientation;
diagramItem.PageSize = viewModel.PageSize; diagramItem.PageSize = viewModel.PageSize;
diagramItem.PageSizeType = viewModel.PageSizeType; diagramItem.PageSizeType = viewModel.PageSizeType;
diagramItem.GridMargin = viewModel.GridMargin; diagramItem.GridMarginSize = viewModel.GridMarginSize;
diagramItem.GridColor = viewModel.GridColor; diagramItem.GridColor = viewModel.GridColor;
diagramItem.AddItems(DiagramViewModel.Items); diagramItem.AddItems(DiagramViewModel.Items);
@@ -523,7 +523,7 @@ namespace AIStudio.Wpf.DiagramApp.ViewModels
viewModel.PageSizeOrientation = diagramItem.PageSizeOrientation; viewModel.PageSizeOrientation = diagramItem.PageSizeOrientation;
viewModel.PageSize = diagramItem.PageSize; viewModel.PageSize = diagramItem.PageSize;
viewModel.PageSizeType = diagramItem.PageSizeType; viewModel.PageSizeType = diagramItem.PageSizeType;
viewModel.GridMargin = diagramItem.GridMargin; viewModel.GridMarginSize = diagramItem.GridMarginSize;
viewModel.GridColor = diagramItem.GridColor; viewModel.GridColor = diagramItem.GridColor;
foreach (DesignerItemBase diagramItemData in diagramItem.AllDesignerItems) foreach (DesignerItemBase diagramItemData in diagramItem.AllDesignerItems)

View File

@@ -1518,6 +1518,12 @@
<TextBlock Margin="5" Text="高度" VerticalAlignment="Center"/> <TextBlock Margin="5" Text="高度" VerticalAlignment="Center"/>
<Fluent:Spinner Margin="5" Width="60" Size="Small" Value="{Binding DiagramsViewModel.DiagramViewModel.GridCellHeight,Mode=TwoWay}" Minimum="0" Format="0" /> <Fluent:Spinner Margin="5" Width="60" Size="Small" Value="{Binding DiagramsViewModel.DiagramViewModel.GridCellHeight,Mode=TwoWay}" Minimum="0" Format="0" />
</StackPanel> </StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Margin="5" Text="左右边距" VerticalAlignment="Center"/>
<Fluent:Spinner Margin="5" Width="60" Size="Small" Value="{Binding DiagramsViewModel.DiagramViewModel.GridMarginWidth,Mode=TwoWay}" Minimum="0" Format="0" />
<TextBlock Margin="5" Text="上下边距" VerticalAlignment="Center"/>
<Fluent:Spinner Margin="5" Width="60" Size="Small" Value="{Binding DiagramsViewModel.DiagramViewModel.GridMarginHeight,Mode=TwoWay}" Minimum="0" Format="0" />
</StackPanel>
<Fluent:SplitButton.ToolTip> <Fluent:SplitButton.ToolTip>
<Fluent:ScreenTip Title="ShowGrid" <Fluent:ScreenTip Title="ShowGrid"

View File

@@ -70,7 +70,7 @@ namespace AIStudio.Wpf.DiagramDesigner.Test.ViewModels
DiagramViewModel = new DiagramViewModel(); DiagramViewModel = new DiagramViewModel();
DiagramViewModel.ShowGrid = true; DiagramViewModel.ShowGrid = true;
DiagramViewModel.GridCellSize = new Size(100, 100); DiagramViewModel.GridCellSize = new Size(100, 100);
DiagramViewModel.GridMargin = 0d; DiagramViewModel.GridMarginSize = new Size(0, 0);
DiagramViewModel.CellHorizontalAlignment = CellHorizontalAlignment.Center; DiagramViewModel.CellHorizontalAlignment = CellHorizontalAlignment.Center;
DiagramViewModel.CellVerticalAlignment = CellVerticalAlignment.Center; DiagramViewModel.CellVerticalAlignment = CellVerticalAlignment.Center;
DiagramViewModel.PageSizeType = PageSizeType.Custom; DiagramViewModel.PageSizeType = PageSizeType.Custom;

View File

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

View File

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

View File

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

View File

@@ -387,18 +387,18 @@ namespace AIStudio.Wpf.DiagramDesigner
{ {
if (Root.GridCellSize.Width > this.ItemWidth) 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) 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) else if (Root.CellHorizontalAlignment == CellHorizontalAlignment.Right)
{ {
if (Root.GridCellSize.Width > this.ItemWidth) 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) 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) 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) else if (Root.CellVerticalAlignment == CellVerticalAlignment.Bottom)
{ {
if (Root.GridCellSize.Height > this.ItemHeight) 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; private Size _gridMargin = new Size(28, 28);
public double GridMargin public Size GridMarginSize
{ {
get 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; private double _zoomValue = 1;
[Browsable(false)] [Browsable(false)]
public double ZoomValue public double ZoomValue

View File

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

View File

@@ -35,7 +35,7 @@ namespace AIStudio.Wpf.Flowchart.Controls
_diagramViewModel.SetScreenScale(); _diagramViewModel.SetScreenScale();
_diagramViewModel.ShowGrid = true; _diagramViewModel.ShowGrid = true;
_diagramViewModel.GridCellSize = new SizeBase(125 / _diagramViewModel.ScreenScale, 125 / _diagramViewModel.ScreenScale); _diagramViewModel.GridCellSize = new SizeBase(125 / _diagramViewModel.ScreenScale, 125 / _diagramViewModel.ScreenScale);
_diagramViewModel.GridMargin = 0d; _diagramViewModel.GridMarginSize = new Size(0, 0);
_diagramViewModel.CellHorizontalAlignment = CellHorizontalAlignment.Center; _diagramViewModel.CellHorizontalAlignment = CellHorizontalAlignment.Center;
_diagramViewModel.CellVerticalAlignment = CellVerticalAlignment.Center; _diagramViewModel.CellVerticalAlignment = CellVerticalAlignment.Center;
_diagramViewModel.PageSizeType = PageSizeType.Custom; _diagramViewModel.PageSizeType = PageSizeType.Custom;