mirror of
https://gitee.com/langsisi_admin/serein-flow
synced 2026-03-02 15:50:47 +08:00
优化了画布平移、缩放、改变尺寸
This commit is contained in:
@@ -87,14 +87,11 @@
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Grid.Row="1"
|
||||
x:Name="FlowChartStackPanel">
|
||||
|
||||
|
||||
x:Name="FlowChartStackPanel"
|
||||
ClipToBounds="True">
|
||||
<Canvas
|
||||
|
||||
x:Name="FlowChartCanvas"
|
||||
|
||||
Background="#F2EEE8"
|
||||
Background="#D9FFEA"
|
||||
AllowDrop="True"
|
||||
MouseDown="FlowChartCanvas_MouseDown"
|
||||
MouseMove="FlowChartCanvas_MouseMove"
|
||||
@@ -111,12 +108,12 @@
|
||||
Canvas.Left="0" Canvas.Top="0"/>-->
|
||||
|
||||
<!-- Top-Right Thumb -->
|
||||
<Thumb x:Name="TopRightThumb"
|
||||
<!--<Thumb x:Name="TopRightThumb"
|
||||
Width="10" Height="10"
|
||||
DragDelta="Thumb_DragDelta_TopRight"
|
||||
Cursor="SizeNESW"
|
||||
Canvas.Left="{Binding ActualWidth, ElementName=FlowChartCanvas, Mode=OneWay, Converter={StaticResource RightThumbPositionConverter}}"
|
||||
Canvas.Top="0"/>
|
||||
Canvas.Top="0"/>-->
|
||||
|
||||
<!-- Bottom-Left Thumb -->
|
||||
<!--<Thumb x:Name="BottomLeftThumb"
|
||||
@@ -143,12 +140,15 @@
|
||||
Canvas.Top="{Binding ActualHeight, ElementName=FlowChartCanvas, Mode=OneWay, Converter={StaticResource VerticalCenterThumbPositionConverter}}"/>-->
|
||||
|
||||
<!-- Right Thumb -->
|
||||
<Thumb x:Name="RightThumb"
|
||||
Width="10" Height="10"
|
||||
DragDelta="Thumb_DragDelta_Right"
|
||||
Cursor="SizeWE"
|
||||
Canvas.Left="{Binding ActualWidth, ElementName=FlowChartCanvas, Mode=OneWay, Converter={StaticResource RightThumbPositionConverter}}"
|
||||
Canvas.Top="{Binding ActualHeight, ElementName=FlowChartCanvas, Mode=OneWay, Converter={StaticResource VerticalCenterThumbPositionConverter}}"/>
|
||||
<!--Canvas.Left="{Binding ActualWidth, ElementName=FlowChartCanvas, Mode=OneWay, Converter={StaticResource RightThumbPositionConverter}}"
|
||||
Canvas.Top="{Binding ActualHeight, ElementName=FlowChartCanvas, Mode=OneWay, Converter={StaticResource VerticalCenterThumbPositionConverter}}"-->
|
||||
<Thumb x:Name="RightThumb" Width="5" Cursor="SizeWE" Canvas.Top="0" Canvas.Right="0" DragDelta="Thumb_DragDelta_Right">
|
||||
<Thumb.Template>
|
||||
<ControlTemplate>
|
||||
<Border Background="#B1B9F8" Width="5" Height="{Binding RelativeSource={RelativeSource AncestorType=Canvas}, Path=ActualHeight}" />
|
||||
</ControlTemplate>
|
||||
</Thumb.Template>
|
||||
</Thumb>
|
||||
|
||||
<!-- Top Thumb -->
|
||||
<!--<Thumb x:Name="TopThumb"
|
||||
@@ -159,12 +159,15 @@
|
||||
Canvas.Top="0"/>-->
|
||||
|
||||
<!-- Bottom Thumb -->
|
||||
<Thumb x:Name="BottomThumb"
|
||||
Width="10" Height="10"
|
||||
DragDelta="Thumb_DragDelta_Bottom"
|
||||
Cursor="SizeNS"
|
||||
Canvas.Left="{Binding ActualWidth, ElementName=FlowChartCanvas, Mode=OneWay, Converter={StaticResource HorizontalCenterThumbPositionConverter}}"
|
||||
Canvas.Top="{Binding ActualHeight, ElementName=FlowChartCanvas, Mode=OneWay, Converter={StaticResource BottomThumbPositionConverter}}"/>
|
||||
<!--Canvas.Left="{Binding ActualWidth, ElementName=FlowChartCanvas, Mode=OneWay, Converter={StaticResource HorizontalCenterThumbPositionConverter}}"
|
||||
Canvas.Top="{Binding ActualHeight, ElementName=FlowChartCanvas, Mode=OneWay, Converter={StaticResource BottomThumbPositionConverter}}"-->
|
||||
<Thumb x:Name="BottomThumb" Height="5" Cursor="SizeNS" Canvas.Bottom="0" Canvas.Left="0" DragDelta="Thumb_DragDelta_Bottom">
|
||||
<Thumb.Template>
|
||||
<ControlTemplate>
|
||||
<Border Background="#B1B9F8" Height="5" Width="{Binding RelativeSource={RelativeSource AncestorType=Canvas}, Path=ActualWidth}" />
|
||||
</ControlTemplate>
|
||||
</Thumb.Template>
|
||||
</Thumb>
|
||||
</Canvas>
|
||||
|
||||
|
||||
|
||||
@@ -221,9 +221,11 @@ namespace Serein.WorkBench
|
||||
var logTextWriter = new LogTextWriter(WriteLog);
|
||||
Console.SetOut(logTextWriter);
|
||||
|
||||
//transform = new TranslateTransform();
|
||||
//FlowChartCanvas.RenderTransform = transform;
|
||||
UIInit();
|
||||
}
|
||||
|
||||
private void UIInit()
|
||||
{
|
||||
canvasTransformGroup = new TransformGroup();
|
||||
scaleTransform = new ScaleTransform();
|
||||
translateTransform = new TranslateTransform();
|
||||
@@ -232,6 +234,7 @@ namespace Serein.WorkBench
|
||||
canvasTransformGroup.Children.Add(translateTransform);
|
||||
|
||||
FlowChartCanvas.RenderTransform = canvasTransformGroup;
|
||||
|
||||
FlowChartCanvas.RenderTransformOrigin = new Point(0.5, 0.5);
|
||||
}
|
||||
|
||||
@@ -1164,9 +1167,6 @@ namespace Serein.WorkBench
|
||||
((UIElement)sender).CaptureMouse(); // 捕获鼠标
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 控件的鼠标移动事件,根据鼠标拖动更新控件的位置。
|
||||
/// </summary>
|
||||
@@ -1203,6 +1203,7 @@ namespace Serein.WorkBench
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 调整FlowChartCanvas的尺寸,确保显示所有控件。
|
||||
/// </summary>
|
||||
@@ -1284,7 +1285,9 @@ namespace Serein.WorkBench
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// FlowChartCanvas中移动时处理,用于实时更新连接线的终点位置。
|
||||
/// 鼠标在画布移动。
|
||||
/// 连接状态下,实时更新连接线的终点位置。
|
||||
/// 移动画布状态下,移动画布。
|
||||
/// </summary>
|
||||
private void FlowChartCanvas_MouseMove(object sender, MouseEventArgs e)
|
||||
{
|
||||
@@ -1667,33 +1670,13 @@ namespace Serein.WorkBench
|
||||
|
||||
if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
|
||||
{
|
||||
if (e.Delta < 0 && scaleTransform.ScaleX < 0.4) return;
|
||||
if (e.Delta > 0 && scaleTransform.ScaleX > 3.0) return;
|
||||
if (e.Delta < 0 && scaleTransform.ScaleX < 0.2) return;
|
||||
if (e.Delta > 0 && scaleTransform.ScaleX > 2.0) return;
|
||||
double scale = e.Delta > 0 ? 0.1 : -0.1;
|
||||
|
||||
|
||||
scaleTransform.ScaleX += scale;
|
||||
scaleTransform.ScaleY += scale;
|
||||
//AdjustCanvasSize();
|
||||
|
||||
|
||||
//double zoomFactor = e.Delta > 0 ? 1.1 : 0.9;
|
||||
|
||||
//// 获取鼠标相对于Canvas的位置
|
||||
//Point mousePosition = e.GetPosition(this);
|
||||
|
||||
//// 计算缩放后的Canvas中心位置
|
||||
//double absoluteX = mousePosition.X * scaleTransform.ScaleX;
|
||||
//double absoluteY = mousePosition.Y * scaleTransform.ScaleY;
|
||||
|
||||
//// 应用缩放
|
||||
//scaleTransform.ScaleX *= zoomFactor;
|
||||
//scaleTransform.ScaleY *= zoomFactor;
|
||||
|
||||
//// 平移,使缩放中心保持在鼠标光标处
|
||||
//translateTransform.X = mousePosition.X - absoluteX * zoomFactor;
|
||||
//translateTransform.Y = mousePosition.Y - absoluteY * zoomFactor;
|
||||
|
||||
//// 调整画布大小,使其始终占据整个容器
|
||||
//AdjustCanvasSizeToContainer();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1795,84 +1778,92 @@ namespace Serein.WorkBench
|
||||
|
||||
|
||||
#region 动态调整区域大小
|
||||
private void Thumb_DragDelta_TopLeft(object sender, DragDeltaEventArgs e)
|
||||
{
|
||||
// 从左上角调整大小
|
||||
double newWidth = Math.Max(FlowChartCanvas.ActualWidth - e.HorizontalChange, 0);
|
||||
double newHeight = Math.Max(FlowChartCanvas.ActualHeight - e.VerticalChange, 0);
|
||||
//private void Thumb_DragDelta_TopLeft(object sender, DragDeltaEventArgs e)
|
||||
//{
|
||||
// // 从左上角调整大小
|
||||
// double newWidth = Math.Max(FlowChartCanvas.ActualWidth - e.HorizontalChange, 0);
|
||||
// double newHeight = Math.Max(FlowChartCanvas.ActualHeight - e.VerticalChange, 0);
|
||||
|
||||
FlowChartCanvas.Width = newWidth;
|
||||
FlowChartCanvas.Height = newHeight;
|
||||
// FlowChartCanvas.Width = newWidth;
|
||||
// FlowChartCanvas.Height = newHeight;
|
||||
|
||||
Canvas.SetLeft(FlowChartCanvas, Canvas.GetLeft(FlowChartCanvas) + e.HorizontalChange);
|
||||
Canvas.SetTop(FlowChartCanvas, Canvas.GetTop(FlowChartCanvas) + e.VerticalChange);
|
||||
}
|
||||
// Canvas.SetLeft(FlowChartCanvas, Canvas.GetLeft(FlowChartCanvas) + e.HorizontalChange);
|
||||
// Canvas.SetTop(FlowChartCanvas, Canvas.GetTop(FlowChartCanvas) + e.VerticalChange);
|
||||
//}
|
||||
|
||||
private void Thumb_DragDelta_TopRight(object sender, DragDeltaEventArgs e)
|
||||
{
|
||||
// 从右上角调整大小
|
||||
double newWidth = Math.Max(FlowChartCanvas.ActualWidth + e.HorizontalChange, 0);
|
||||
double newHeight = Math.Max(FlowChartCanvas.ActualHeight - e.VerticalChange, 0);
|
||||
//private void Thumb_DragDelta_TopRight(object sender, DragDeltaEventArgs e)
|
||||
//{
|
||||
// // 从右上角调整大小
|
||||
// double newWidth = Math.Max(FlowChartCanvas.ActualWidth + e.HorizontalChange, 0);
|
||||
// double newHeight = Math.Max(FlowChartCanvas.ActualHeight - e.VerticalChange, 0);
|
||||
|
||||
FlowChartCanvas.Width = newWidth;
|
||||
FlowChartCanvas.Height = newHeight;
|
||||
// FlowChartCanvas.Width = newWidth;
|
||||
// FlowChartCanvas.Height = newHeight;
|
||||
|
||||
Canvas.SetTop(FlowChartCanvas, Canvas.GetTop(FlowChartCanvas) + e.VerticalChange);
|
||||
}
|
||||
// Canvas.SetTop(FlowChartCanvas, Canvas.GetTop(FlowChartCanvas) + e.VerticalChange);
|
||||
//}
|
||||
|
||||
private void Thumb_DragDelta_BottomLeft(object sender, DragDeltaEventArgs e)
|
||||
{
|
||||
// 从左下角调整大小
|
||||
double newWidth = Math.Max(FlowChartCanvas.ActualWidth - e.HorizontalChange, 0);
|
||||
double newHeight = Math.Max(FlowChartCanvas.ActualHeight + e.VerticalChange, 0);
|
||||
//private void Thumb_DragDelta_BottomLeft(object sender, DragDeltaEventArgs e)
|
||||
//{
|
||||
// // 从左下角调整大小
|
||||
// double newWidth = Math.Max(FlowChartCanvas.ActualWidth - e.HorizontalChange, 0);
|
||||
// double newHeight = Math.Max(FlowChartCanvas.ActualHeight + e.VerticalChange, 0);
|
||||
|
||||
FlowChartCanvas.Width = newWidth;
|
||||
FlowChartCanvas.Height = newHeight;
|
||||
// FlowChartCanvas.Width = newWidth;
|
||||
// FlowChartCanvas.Height = newHeight;
|
||||
|
||||
Canvas.SetLeft(FlowChartCanvas, Canvas.GetLeft(FlowChartCanvas) + e.HorizontalChange);
|
||||
}
|
||||
// Canvas.SetLeft(FlowChartCanvas, Canvas.GetLeft(FlowChartCanvas) + e.HorizontalChange);
|
||||
//}
|
||||
|
||||
private void Thumb_DragDelta_BottomRight(object sender, DragDeltaEventArgs e)
|
||||
{
|
||||
// 从右下角调整大小
|
||||
double newWidth = Math.Max(FlowChartCanvas.ActualWidth + e.HorizontalChange, 0);
|
||||
double newHeight = Math.Max(FlowChartCanvas.ActualHeight + e.VerticalChange, 0);
|
||||
double newWidth = Math.Max(FlowChartCanvas.ActualWidth + e.HorizontalChange * scaleTransform.ScaleX, 0);
|
||||
double newHeight = Math.Max(FlowChartCanvas.ActualHeight + e.VerticalChange * scaleTransform.ScaleY, 0);
|
||||
|
||||
|
||||
|
||||
newWidth = newWidth < 400 ? 400 : newWidth;
|
||||
newHeight = newHeight < 400 ? 400 : newHeight;
|
||||
|
||||
FlowChartCanvas.Width = newWidth;
|
||||
FlowChartCanvas.Height = newHeight;
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void Thumb_DragDelta_Left(object sender, DragDeltaEventArgs e)
|
||||
{
|
||||
// 从左侧调整大小
|
||||
double newWidth = Math.Max(FlowChartCanvas.ActualWidth - e.HorizontalChange, 0);
|
||||
//private void Thumb_DragDelta_Left(object sender, DragDeltaEventArgs e)
|
||||
//{
|
||||
// // 从左侧调整大小
|
||||
// double newWidth = Math.Max(FlowChartCanvas.ActualWidth - e.HorizontalChange, 0);
|
||||
|
||||
FlowChartCanvas.Width = newWidth;
|
||||
Canvas.SetLeft(FlowChartCanvas, Canvas.GetLeft(FlowChartCanvas) + e.HorizontalChange);
|
||||
}
|
||||
// FlowChartCanvas.Width = newWidth;
|
||||
// Canvas.SetLeft(FlowChartCanvas, Canvas.GetLeft(FlowChartCanvas) + e.HorizontalChange);
|
||||
//}
|
||||
|
||||
private void Thumb_DragDelta_Right(object sender, DragDeltaEventArgs e)
|
||||
{
|
||||
//从右侧调整大小
|
||||
double newWidth = Math.Max(FlowChartCanvas.ActualWidth + e.HorizontalChange, 0);
|
||||
double newWidth = Math.Max(FlowChartCanvas.ActualWidth + e.HorizontalChange * scaleTransform.ScaleX, 0);
|
||||
newWidth = newWidth < 400 ? 400 : newWidth;
|
||||
|
||||
FlowChartCanvas.Width = newWidth;
|
||||
}
|
||||
|
||||
private void Thumb_DragDelta_Top(object sender, DragDeltaEventArgs e)
|
||||
{
|
||||
// 从顶部调整大小
|
||||
double newHeight = Math.Max(FlowChartCanvas.ActualHeight - e.VerticalChange, 0);
|
||||
|
||||
FlowChartCanvas.Height = newHeight;
|
||||
Canvas.SetTop(FlowChartCanvas, Canvas.GetTop(FlowChartCanvas) + e.VerticalChange);
|
||||
}
|
||||
//private void Thumb_DragDelta_Top(object sender, DragDeltaEventArgs e)
|
||||
//{
|
||||
// // 从顶部调整大小
|
||||
// double newHeight = Math.Max(FlowChartCanvas.ActualHeight - e.VerticalChange, 0);
|
||||
|
||||
// FlowChartCanvas.Height = newHeight;
|
||||
// Canvas.SetTop(FlowChartCanvas, Canvas.GetTop(FlowChartCanvas) + e.VerticalChange);
|
||||
//}
|
||||
|
||||
private void Thumb_DragDelta_Bottom(object sender, DragDeltaEventArgs e)
|
||||
{
|
||||
// 从底部调整大小
|
||||
double newHeight = Math.Max(FlowChartCanvas.ActualHeight + e.VerticalChange, 0);
|
||||
|
||||
double newHeight = Math.Max(FlowChartCanvas.ActualHeight + e.VerticalChange * scaleTransform.ScaleY, 0);
|
||||
newHeight = newHeight < 400 ? 400 : newHeight;
|
||||
FlowChartCanvas.Height = newHeight;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,14 +16,6 @@
|
||||
</StackPanel>
|
||||
</Border>
|
||||
|
||||
<Thumb x:Name="ResizeTop" Cursor="SizeNS" Height="4" HorizontalAlignment="Stretch" VerticalAlignment="Top"
|
||||
DragDelta="ResizeTop_DragDelta"/>
|
||||
<Thumb x:Name="ResizeBottom" Cursor="SizeNS" Height="4" HorizontalAlignment="Stretch" VerticalAlignment="Bottom"
|
||||
DragDelta="ResizeBottom_DragDelta"/>
|
||||
<Thumb x:Name="ResizeLeft" Cursor="SizeWE" Width="4" HorizontalAlignment="Left" VerticalAlignment="Stretch"
|
||||
DragDelta="ResizeLeft_DragDelta"/>
|
||||
<Thumb x:Name="ResizeRight" Cursor="SizeWE" Width="4" HorizontalAlignment="Right" VerticalAlignment="Stretch"
|
||||
DragDelta="ResizeRight_DragDelta"/>
|
||||
</Grid>
|
||||
|
||||
</local:NodeControlBase>
|
||||
|
||||
@@ -16,7 +16,6 @@ namespace Serein.WorkBench.Node.View
|
||||
private new readonly CompositeActionNode Node;
|
||||
|
||||
public ActionRegionControl() : base()
|
||||
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
@@ -27,38 +26,6 @@ namespace Serein.WorkBench.Node.View
|
||||
base.Name = "动作组合节点";
|
||||
}
|
||||
|
||||
#region 动态调整区域大小
|
||||
private void ResizeTop_DragDelta(object sender, DragDeltaEventArgs e)
|
||||
{
|
||||
double oldHeight = Height;
|
||||
double newHeight = Math.Max(MinHeight, oldHeight - e.VerticalChange);
|
||||
Height = newHeight;
|
||||
Canvas.SetTop(this, Canvas.GetTop(this) + (oldHeight - newHeight));
|
||||
}
|
||||
|
||||
private void ResizeBottom_DragDelta(object sender, DragDeltaEventArgs e)
|
||||
{
|
||||
double newHeight = Math.Max(MinHeight, Height + e.VerticalChange);
|
||||
Height = newHeight;
|
||||
}
|
||||
|
||||
private void ResizeLeft_DragDelta(object sender, DragDeltaEventArgs e)
|
||||
{
|
||||
double oldWidth = Width;
|
||||
double newWidth = Math.Max(MinWidth, oldWidth - e.HorizontalChange);
|
||||
Width = newWidth;
|
||||
Canvas.SetLeft(this, Canvas.GetLeft(this) + (oldWidth - newWidth));
|
||||
}
|
||||
|
||||
private void ResizeRight_DragDelta(object sender, DragDeltaEventArgs e)
|
||||
{
|
||||
double newWidth = Math.Max(MinWidth, Width + e.HorizontalChange);
|
||||
Width = newWidth;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
public void AddAction(NodeControlBase node, bool isTask = false)
|
||||
{
|
||||
/*TextBlock actionText = new TextBlock
|
||||
|
||||
@@ -20,14 +20,5 @@
|
||||
<ListBox x:Name="ConditionsListBox" AllowDrop="True" Drop="ConditionsListBox_Drop"/>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
|
||||
<Thumb x:Name="ResizeTop" Cursor="SizeNS" Height="4" HorizontalAlignment="Stretch" VerticalAlignment="Top"
|
||||
DragDelta="ResizeTop_DragDelta"/>
|
||||
<Thumb x:Name="ResizeBottom" Cursor="SizeNS" Height="4" HorizontalAlignment="Stretch" VerticalAlignment="Bottom"
|
||||
DragDelta="ResizeBottom_DragDelta"/>
|
||||
<Thumb x:Name="ResizeLeft" Cursor="SizeWE" Width="4" HorizontalAlignment="Left" VerticalAlignment="Stretch"
|
||||
DragDelta="ResizeLeft_DragDelta"/>
|
||||
<Thumb x:Name="ResizeRight" Cursor="SizeWE" Width="4" HorizontalAlignment="Right" VerticalAlignment="Stretch"
|
||||
DragDelta="ResizeRight_DragDelta"/>
|
||||
</Grid>
|
||||
</local:NodeControlBase>
|
||||
|
||||
@@ -23,36 +23,6 @@ namespace Serein.WorkBench.Node.View
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
#region 动态调整区域大小
|
||||
private void ResizeTop_DragDelta(object sender, DragDeltaEventArgs e)
|
||||
{
|
||||
double oldHeight = Height;
|
||||
double newHeight = Math.Max(MinHeight, oldHeight - e.VerticalChange);
|
||||
Height = newHeight;
|
||||
Canvas.SetTop(this, Canvas.GetTop(this) + (oldHeight - newHeight));
|
||||
}
|
||||
|
||||
private void ResizeBottom_DragDelta(object sender, DragDeltaEventArgs e)
|
||||
{
|
||||
double newHeight = Math.Max(MinHeight, Height + e.VerticalChange);
|
||||
Height = newHeight;
|
||||
}
|
||||
|
||||
private void ResizeLeft_DragDelta(object sender, DragDeltaEventArgs e)
|
||||
{
|
||||
double oldWidth = Width;
|
||||
double newWidth = Math.Max(MinWidth, oldWidth - e.HorizontalChange);
|
||||
Width = newWidth;
|
||||
Canvas.SetLeft(this, Canvas.GetLeft(this) + (oldWidth - newWidth));
|
||||
}
|
||||
|
||||
private void ResizeRight_DragDelta(object sender, DragDeltaEventArgs e)
|
||||
{
|
||||
double newWidth = Math.Max(MinWidth, Width + e.HorizontalChange);
|
||||
Width = newWidth;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user