Skip to content

Commit 17f3684

Browse files
committed
Fix for scaling.
I use matrix for render tranform. Some refactoring
1 parent f89a5c4 commit 17f3684

38 files changed

+346
-427
lines changed

SimpleStateMachineNodeEditor/Helpers/Extensions/MatrixExtension.cs

Lines changed: 4 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -6,124 +6,23 @@ namespace SimpleStateMachineNodeEditor.Helpers.Extensions
66
{
77
public static class MatrixExtension
88
{
9-
/// <summary>
10-
/// Creates a translation matrix using the specified offsets.
11-
/// </summary>
12-
/// <param name="offsetX">X-coordinate offset.</param>
13-
/// <param name="offsetY">Y-coordinate offset.</param>
14-
/// <returns>The created translation matrix.</returns>
15-
public static Matrix Translate(double offsetX, double offsetY)
16-
{
17-
return new Matrix(1.0, 0.0, 0.0, 1.0, offsetX, offsetY);
18-
}
19-
20-
/// <summary>
21-
/// Prepends a translation around the center of provided matrix.
22-
/// </summary>
23-
/// <param name="matrix">The matrix to prepend translation.</param>
24-
/// <param name="offsetX">X-coordinate offset.</param>
25-
/// <param name="offsetY">Y-coordinate offset.</param>
26-
/// <returns>The created translation matrix.</returns>
27-
public static Matrix TranslatePrepend(Matrix matrix, double offsetX, double offsetY)
28-
{
29-
return Translate(offsetX, offsetY) * matrix;
30-
}
31-
32-
/// <summary>
33-
/// Creates a matrix that scales along the x-axis and y-axis.
34-
/// </summary>
35-
/// <param name="scaleX">Scaling factor that is applied along the x-axis.</param>
36-
/// <param name="scaleY">Scaling factor that is applied along the y-axis.</param>
37-
/// <returns>The created scaling matrix.</returns>
38-
public static Matrix Scale(double scaleX, double scaleY)
39-
{
40-
return new Matrix(scaleX, 0, 0, scaleY, 0.0, 0.0);
41-
}
42-
43-
/// <summary>
44-
/// Creates a matrix that is scaling from a specified center.
45-
/// </summary>
46-
/// <param name="scaleX">Scaling factor that is applied along the x-axis.</param>
47-
/// <param name="scaleY">Scaling factor that is applied along the y-axis.</param>
48-
/// <param name="centerX">The center X-coordinate of the scaling.</param>
49-
/// <param name="centerY">The center Y-coordinate of the scaling.</param>
50-
/// <returns>The created scaling matrix.</returns>
519
public static Matrix ScaleAt(double scaleX, double scaleY, double centerX, double centerY)
5210
{
5311
return new Matrix(scaleX, 0, 0, scaleY, centerX - (scaleX * centerX), centerY - (scaleY * centerY));
5412
}
5513

56-
/// <summary>
57-
/// Prepends a scale around the center of provided matrix.
58-
/// </summary>
59-
/// <param name="matrix">The matrix to prepend scale.</param>
60-
/// <param name="scaleX">Scaling factor that is applied along the x-axis.</param>
61-
/// <param name="scaleY">Scaling factor that is applied along the y-axis.</param>
62-
/// <param name="centerX">The center X-coordinate of the scaling.</param>
63-
/// <param name="centerY">The center Y-coordinate of the scaling.</param>
64-
/// <returns>The created scaling matrix.</returns>
6514
public static Matrix ScaleAtPrepend(Matrix matrix, double scaleX, double scaleY, double centerX, double centerY)
6615
{
6716
return ScaleAt(scaleX, scaleY, centerX, centerY) * matrix;
6817
}
6918

70-
/// <summary>
71-
/// Creates a skew matrix.
72-
/// </summary>
73-
/// <param name="angleX">Angle of skew along the X-axis in radians.</param>
74-
/// <param name="angleY">Angle of skew along the Y-axis in radians.</param>
75-
/// <returns>When the method completes, contains the created skew matrix.</returns>
76-
public static Matrix Skew(float angleX, float angleY)
19+
public static Matrix ScaleAtPrepend(Matrix matrix, double scaleX, double scaleY)
7720
{
78-
return new Matrix(1.0, Tan(angleX), Tan(angleY), 1.0, 0.0, 0.0);
21+
return ScaleAt2(scaleX, scaleY, matrix.OffsetX, matrix.OffsetY) * matrix;
7922
}
80-
81-
/// <summary>
82-
/// Creates a matrix that rotates.
83-
/// </summary>
84-
/// <param name="radians">Angle of rotation in radians. Angles are measured clockwise when looking along the rotation axis.</param>
85-
/// <returns>The created rotation matrix.</returns>
86-
public static Matrix Rotation(double radians)
87-
{
88-
double cos = Cos(radians);
89-
double sin = Sin(radians);
90-
return new Matrix(cos, sin, -sin, cos, 0, 0);
91-
}
92-
93-
/// <summary>
94-
/// Creates a matrix that rotates about a specified center.
95-
/// </summary>
96-
/// <param name="angle">Angle of rotation in radians.</param>
97-
/// <param name="centerX">The center X-coordinate of the rotation.</param>
98-
/// <param name="centerY">The center Y-coordinate of the rotation.</param>
99-
/// <returns>The created rotation matrix.</returns>
100-
public static Matrix Rotation(double angle, double centerX, double centerY)
101-
{
102-
return Translate(-centerX, -centerY) * Rotation(angle) * Translate(centerX, centerY);
103-
}
104-
105-
/// <summary>
106-
/// Creates a matrix that rotates about a specified center.
107-
/// </summary>
108-
/// <param name="angle">Angle of rotation in radians.</param>
109-
/// <param name="center">The center of the rotation.</param>
110-
/// <returns>The created rotation matrix.</returns>
111-
public static Matrix Rotation(double angle, Vector center)
112-
{
113-
return Translate(-center.X, -center.Y) * Rotation(angle) * Translate(center.X, center.Y);
114-
}
115-
116-
/// <summary>
117-
/// Transforms a point by this matrix.
118-
/// </summary>
119-
/// <param name="matrix">The matrix to use as a transformation matrix.</param>
120-
/// <param name="point">>The original point to apply the transformation.</param>
121-
/// <returns>The result of the transformation for the input point.</returns>
122-
public static Point TransformPoint(Matrix matrix, Point point)
23+
public static Matrix ScaleAt2(double scaleX, double scaleY, double centerX, double centerY)
12324
{
124-
return new Point(
125-
(point.X * matrix.M11) + (point.Y * matrix.M21) + matrix.OffsetX,
126-
(point.X * matrix.M12) + (point.Y * matrix.M22) + matrix.OffsetY);
25+
return new Matrix(scaleX, 0, 0, scaleY, 1, 1);
12726
}
12827
}
12928
}

SimpleStateMachineNodeEditor/SimpleStateMachineNodeEditor.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ ReactiveUI 11.4.17</PackageReleaseNotes>
7272
<PackageReference Include="ReactiveUI.WPF" Version="11.4.17" />
7373
<PackageReference Include="Splat" Version="9.4.5" />
7474
<PackageReference Include="Splat.Drawing" Version="9.4.5" />
75-
<PackageReference Include="Wpf.Controls.PanAndZoom" Version="3.0.999-build20200622-01" />
7675
</ItemGroup>
7776

7877
<ItemGroup>

SimpleStateMachineNodeEditor/View/ViewConnect.xaml renamed to SimpleStateMachineNodeEditor/View/Connect.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<UserControl x:Class="SimpleStateMachineNodeEditor.View.ViewConnect"
1+
<UserControl x:Class="SimpleStateMachineNodeEditor.View.Connect"
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

SimpleStateMachineNodeEditor/View/ViewConnect.xaml.cs renamed to SimpleStateMachineNodeEditor/View/Connect.xaml.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,24 @@ namespace SimpleStateMachineNodeEditor.View
2020
/// <summary>
2121
/// Interaction logic for ViewConnect.xaml
2222
/// </summary>
23-
public partial class ViewConnect : UserControl, IViewFor<ViewModelConnect>
23+
public partial class Connect : UserControl, IViewFor<ConnectViewModel>
2424
{
2525
#region ViewModel
26-
public static readonly DependencyProperty ViewModelProperty = DependencyProperty.Register(nameof(ViewModel), typeof(ViewModelConnect), typeof(ViewConnect), new PropertyMetadata(null));
26+
public static readonly DependencyProperty ViewModelProperty = DependencyProperty.Register(nameof(ViewModel), typeof(ConnectViewModel), typeof(Connect), new PropertyMetadata(null));
2727

28-
public ViewModelConnect ViewModel
28+
public ConnectViewModel ViewModel
2929
{
30-
get { return (ViewModelConnect)GetValue(ViewModelProperty); }
30+
get { return (ConnectViewModel)GetValue(ViewModelProperty); }
3131
set { SetValue(ViewModelProperty, value); }
3232
}
3333

3434
object IViewFor.ViewModel
3535
{
3636
get { return ViewModel; }
37-
set { ViewModel = (ViewModelConnect)value; }
37+
set { ViewModel = (ConnectViewModel)value; }
3838
}
3939
#endregion ViewModel
40-
public ViewConnect()
40+
public Connect()
4141
{
4242
InitializeComponent();
4343
SetupBinding();
@@ -62,7 +62,7 @@ private void SetupBinding()
6262

6363
this.OneWayBind(this.ViewModel, x => x.StrokeDashArray, x => x.PathElement.StrokeDashArray).DisposeWith(disposable);
6464

65-
this.OneWayBind(this.ViewModel, x => x.FromConnector.NodesCanvas.Scale.Value, x => x.PathElement.StrokeThickness).DisposeWith(disposable);
65+
//this.OneWayBind(this.ViewModel, x => x.FromConnector.NodesCanvas.Scale.Value, x => x.PathElement.StrokeThickness).DisposeWith(disposable);
6666

6767
this.WhenAnyValue(x => x.ViewModel.ToConnector).Where(x=>x!=null).Subscribe(_ => UpdateZindex()).DisposeWith(disposable);
6868
});

SimpleStateMachineNodeEditor/View/ViewCutter.xaml renamed to SimpleStateMachineNodeEditor/View/Cutter.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<UserControl x:Class="SimpleStateMachineNodeEditor.View.ViewCutter"
1+
<UserControl x:Class="SimpleStateMachineNodeEditor.View.Cutter"
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

SimpleStateMachineNodeEditor/View/ViewCutter.xaml.cs renamed to SimpleStateMachineNodeEditor/View/Cutter.xaml.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,24 @@ namespace SimpleStateMachineNodeEditor.View
2121
/// <summary>
2222
/// Interaction logic for ViewCutter.xaml
2323
/// </summary>
24-
public partial class ViewCutter : UserControl, IViewFor<ViewModelCutter>
24+
public partial class Cutter : UserControl, IViewFor<CutterViewModel>
2525
{
2626
#region ViewModel
27-
public static readonly DependencyProperty ViewModelProperty = DependencyProperty.Register(nameof(ViewModel), typeof(ViewModelCutter), typeof(ViewCutter), new PropertyMetadata(null));
27+
public static readonly DependencyProperty ViewModelProperty = DependencyProperty.Register(nameof(ViewModel), typeof(CutterViewModel), typeof(Cutter), new PropertyMetadata(null));
2828

29-
public ViewModelCutter ViewModel
29+
public CutterViewModel ViewModel
3030
{
31-
get { return (ViewModelCutter)GetValue(ViewModelProperty); }
31+
get { return (CutterViewModel)GetValue(ViewModelProperty); }
3232
set { SetValue(ViewModelProperty, value); }
3333
}
3434

3535
object IViewFor.ViewModel
3636
{
3737
get { return ViewModel; }
38-
set { ViewModel = (ViewModelCutter)value; }
38+
set { ViewModel = (CutterViewModel)value; }
3939
}
4040
#endregion ViewModel
41-
public ViewCutter()
41+
public Cutter()
4242
{
4343
InitializeComponent();
4444
SetupBinding();
@@ -86,9 +86,8 @@ private void SetupEvents()
8686
}
8787
private void OnMouseMoves(MouseEventArgs e)
8888
{
89-
ViewNodesCanvas NodesCanvas = MyUtils.FindParent<ViewNodesCanvas>(this);
90-
91-
ViewModel.EndPoint = e.GetPosition(NodesCanvas.Canvas);
89+
NodesCanvas NodesCanvas = MyUtils.FindParent<NodesCanvas>(this);
90+
ViewModel.EndPoint = e.GetPosition(NodesCanvas.CanvasElement);
9291

9392
e.Handled = true;
9493

SimpleStateMachineNodeEditor/View/ViewDialog.xaml renamed to SimpleStateMachineNodeEditor/View/Dialog.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<UserControl x:Class="SimpleStateMachineNodeEditor.View.ViewDialog"
1+
<UserControl x:Class="SimpleStateMachineNodeEditor.View.Dialog"
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

SimpleStateMachineNodeEditor/View/ViewDialog.xaml.cs renamed to SimpleStateMachineNodeEditor/View/Dialog.xaml.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,24 @@ namespace SimpleStateMachineNodeEditor.View
1313
/// <summary>
1414
/// Interaction logic for ViewDialog.xaml
1515
/// </summary>
16-
public partial class ViewDialog : System.Windows.Controls.UserControl, IViewFor<ViewModelDialog>
16+
public partial class Dialog : System.Windows.Controls.UserControl, IViewFor<DialogViewModel>
1717
{
1818
#region ViewModel
19-
public static readonly DependencyProperty ViewModelProperty = DependencyProperty.Register(nameof(ViewModel), typeof(ViewModelDialog), typeof(ViewDialog), new PropertyMetadata(null));
19+
public static readonly DependencyProperty ViewModelProperty = DependencyProperty.Register(nameof(ViewModel), typeof(DialogViewModel), typeof(Dialog), new PropertyMetadata(null));
2020

21-
public ViewModelDialog ViewModel
21+
public DialogViewModel ViewModel
2222
{
23-
get { return (ViewModelDialog)GetValue(ViewModelProperty); }
23+
get { return (DialogViewModel)GetValue(ViewModelProperty); }
2424
set { SetValue(ViewModelProperty, value); }
2525
}
2626

2727
object IViewFor.ViewModel
2828
{
2929
get { return ViewModel; }
30-
set { ViewModel = (ViewModelDialog)value; }
30+
set { ViewModel = (DialogViewModel)value; }
3131
}
3232
#endregion ViewModel
33-
public ViewDialog()
33+
public Dialog()
3434
{
3535
InitializeComponent();
3636
SetupBinding();

SimpleStateMachineNodeEditor/View/ViewLeftConnector.xaml renamed to SimpleStateMachineNodeEditor/View/LeftConnector.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
<UserControl x:Class="SimpleStateMachineNodeEditor.View.ViewLeftConnector"
1+
<UserControl x:Class="SimpleStateMachineNodeEditor.View.LeftConnector"
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
55
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
66
xmlns:local="clr-namespace:SimpleStateMachineNodeEditor.View"
77
xmlns:styles="clr-namespace:SimpleStateMachineNodeEditor.Styles"
8-
x:Name="LeftConnector" HorizontalAlignment="Stretch" VerticalAlignment="Top" AllowDrop="True" >
8+
x:Name="LeftConnectorElement" HorizontalAlignment="Stretch" VerticalAlignment="Top" AllowDrop="True" >
99
<Grid x:Name="GridElement" Background="#00000000">
1010
<Grid.ColumnDefinitions>
1111
<ColumnDefinition Width="Auto" />

SimpleStateMachineNodeEditor/View/ViewLeftConnector.xaml.cs renamed to SimpleStateMachineNodeEditor/View/LeftConnector.xaml.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,24 @@ namespace SimpleStateMachineNodeEditor.View
2222
/// <summary>
2323
/// Interaction logic for ViewLeftConnector.xaml
2424
/// </summary>
25-
public partial class ViewLeftConnector : UserControl, IViewFor<ViewModelConnector>
25+
public partial class LeftConnector : UserControl, IViewFor<ConnectorViewModel>
2626
{
2727
#region ViewModel
28-
public static readonly DependencyProperty ViewModelProperty = DependencyProperty.Register(nameof(ViewModel), typeof(ViewModelConnector), typeof(ViewLeftConnector), new PropertyMetadata(null));
28+
public static readonly DependencyProperty ViewModelProperty = DependencyProperty.Register(nameof(ViewModel), typeof(ConnectorViewModel), typeof(LeftConnector), new PropertyMetadata(null));
2929

30-
public ViewModelConnector ViewModel
30+
public ConnectorViewModel ViewModel
3131
{
32-
get { return (ViewModelConnector)GetValue(ViewModelProperty); }
32+
get { return (ConnectorViewModel)GetValue(ViewModelProperty); }
3333
set { SetValue(ViewModelProperty, value); }
3434
}
3535

3636
object IViewFor.ViewModel
3737
{
3838
get { return ViewModel; }
39-
set { ViewModel = (ViewModelConnector)value; }
39+
set { ViewModel = (ConnectorViewModel)value; }
4040
}
4141
#endregion ViewModel
42-
public ViewLeftConnector()
42+
public LeftConnector()
4343
{
4444
InitializeComponent();
4545
SetupBinding();
@@ -64,7 +64,7 @@ private void SetupBinding()
6464

6565
this.OneWayBind(this.ViewModel, x => x.FormFill, x => x.EllipseElement.Fill).DisposeWith(disposable);
6666

67-
this.OneWayBind(this.ViewModel, x => x.Visible, x => x.LeftConnector.Visibility).DisposeWith(disposable);
67+
this.OneWayBind(this.ViewModel, x => x.Visible, x => x.LeftConnectorElement.Visibility).DisposeWith(disposable);
6868

6969
});
7070
}
@@ -102,13 +102,14 @@ void UpdatePosition()
102102
{
103103
Point positionConnectPoint = EllipseElement.TranslatePoint(new Point(EllipseElement.Width/2, EllipseElement.Height / 2), this);
104104

105-
ViewNodesCanvas NodesCanvas = MyUtils.FindParent<ViewNodesCanvas>(this);
105+
NodesCanvas NodesCanvas = MyUtils.FindParent<NodesCanvas>(this);
106106
if (NodesCanvas == null)
107107
return;
108108

109109
positionConnectPoint = this.TransformToAncestor(NodesCanvas).Transform(positionConnectPoint);
110110

111-
this.ViewModel.PositionConnectPoint = positionConnectPoint.Division(this.ViewModel.NodesCanvas.Scale.Value);
111+
//this.ViewModel.PositionConnectPoint = positionConnectPoint.Division(this.ViewModel.NodesCanvas.Scale.Value);
112+
this.ViewModel.PositionConnectPoint = positionConnectPoint;
112113
}
113114
}
114115
}

SimpleStateMachineNodeEditor/View/MainWindow.xaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<RowDefinition Height="auto"/>
1616
<RowDefinition Height="auto" x:Name="Fotter" MinHeight="18"/>
1717
</Grid.RowDefinitions>
18-
<view:ViewDialog x:Name="Dialog"/>
18+
<view:Dialog x:Name="Dialog"/>
1919

2020
<!--#region Header-->
2121
<DockPanel x:Name="Header" Grid.Row="0" Background="{DynamicResource ColorWindowHeader}" LastChildFill="False">
@@ -181,7 +181,7 @@
181181
<!--BorderBrush - it's color on IsMouseOver, OpacityMask - it's color on IsPressed-->
182182
<TabControl Grid.Column="0" Background="{x:Null}" BorderBrush="{x:Null}" Foreground="Green" TabStripPlacement="Top" Padding="2,2,2,0" >
183183
<TabItem Header="Node editor" Style="{DynamicResource StyleTabItem}" Background="{DynamicResource ColorWindowHeader}" Foreground="{DynamicResource ColorWindowHeaderTabItemForeground}" BorderBrush="{DynamicResource ColorElementMouseOver}" OpacityMask="{DynamicResource ColorElementMouseOver}">
184-
<view:ViewNodesCanvas x:Name="NodesCanvas" />
184+
<view:NodesCanvas x:Name="NodesCanvas" />
185185
</TabItem>
186186
</TabControl>
187187
<GridSplitter Grid.Column="1" HorizontalAlignment="Center" x:Name="TableOfTransitionsSplitter" VerticalAlignment="Stretch" Background="{DynamicResource ColorWindowHeader}" Width="3" ShowsPreview="False" IsEnabled="False" />
@@ -221,7 +221,7 @@
221221
VirtualizingStackPanel.ScrollUnit="Pixel">
222222
<ListBox.ItemTemplate>
223223
<DataTemplate>
224-
<view:ViewTableOfTransitionsItem ViewModel="{Binding}" />
224+
<view:TableOfTransitionsItem ViewModel="{Binding}" />
225225
</DataTemplate>
226226
</ListBox.ItemTemplate>
227227
</ListBox>
@@ -282,7 +282,7 @@
282282
</ListBox.ContextMenu>
283283
<ListBox.ItemTemplate>
284284
<DataTemplate>
285-
<view:ViewMessage ViewModel="{Binding}" />
285+
<view:Message ViewModel="{Binding}" />
286286
</DataTemplate>
287287
</ListBox.ItemTemplate>
288288
</ListBox>

0 commit comments

Comments
 (0)