-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ClickControl and Connection classes, update Node and Styles
The ClickControl and Connection classes have been added. Changes were made in Node.xaml for visual improvements and to support the new classes. Some color codes and styles have been added to Styles.xaml for the same reason. Additionally, the .NET
- Loading branch information
Showing
6 changed files
with
240 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using System.Windows.Input; | ||
|
||
namespace Editor.NET; | ||
|
||
public class ClickControl : Control { | ||
private bool _leftButtonDown; | ||
|
||
protected ClickControl() { | ||
MouseEnter += MouseEnterHandler; | ||
MouseLeave += MouseEnterHandler; | ||
MouseLeftButtonDown += MouseLeftButtonDownHandler; | ||
MouseLeftButtonUp += MouseLeftButtonUpHandler; | ||
} | ||
|
||
public event MouseButtonEventHandler? LeftButtonClick; | ||
|
||
private void MouseEnterHandler(object? sender, RoutedEventArgs ea) { | ||
_leftButtonDown = false; | ||
|
||
InvalidateVisual(); | ||
} | ||
|
||
private void MouseLeftButtonDownHandler(object? sender, MouseButtonEventArgs ea) { | ||
_leftButtonDown = true; | ||
|
||
InvalidateVisual(); | ||
} | ||
|
||
private void MouseLeftButtonUpHandler(object? sender, MouseButtonEventArgs ea) { | ||
if (_leftButtonDown) { | ||
LeftButtonClick?.Invoke(sender, ea); | ||
} | ||
|
||
_leftButtonDown = false; | ||
|
||
InvalidateVisual(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
using System; | ||
using System.Windows; | ||
using System.Windows.Input; | ||
using System.Windows.Media; | ||
|
||
namespace Editor.NET; | ||
|
||
public class ConnectionEventArgs : RoutedEventArgs { | ||
public ConnectionEventArgs(Connection connection) { | ||
Connection = connection; | ||
} | ||
|
||
public Connection Connection { get; } | ||
} | ||
|
||
public class Connection : ClickControl { | ||
public static readonly DependencyProperty InputPositionDependencyProperty = DependencyProperty.Register( | ||
nameof(InputPosition), | ||
typeof(Point), | ||
typeof(Connection), | ||
new PropertyMetadata(Position_PropertyChangedCallback) | ||
); | ||
|
||
public static readonly DependencyProperty OutputPositionDependencyProperty = DependencyProperty.Register( | ||
nameof(OutputPosition), | ||
typeof(Point), | ||
typeof(Connection), | ||
new PropertyMetadata(Position_PropertyChangedCallback) | ||
); | ||
|
||
public static readonly DependencyProperty HoverBrushDependencyProperty = DependencyProperty.Register( | ||
nameof(HoverBrush), | ||
typeof(Brush), | ||
typeof(Connection), | ||
new PropertyMetadata(Brushes.Coral) | ||
); | ||
|
||
public static readonly DependencyProperty BrushProperty = DependencyProperty.Register( | ||
nameof(Brush), typeof(Brush), | ||
typeof(Connection), | ||
new PropertyMetadata(Brushes.SlateGray) | ||
); | ||
|
||
public Brush Brush { | ||
get { return (Brush)GetValue(BrushProperty); } | ||
set { SetValue(BrushProperty, value); } | ||
} | ||
|
||
public Connection() { | ||
LeftButtonClick += LeftButtonClickHandler; | ||
MouseDoubleClick += MouseButtonEventHandler; | ||
|
||
// Resources.Source = new Uri("/Styles.xaml", UriKind.Relative); | ||
} | ||
|
||
public static readonly DependencyProperty ThicknessProperty = DependencyProperty.Register( | ||
nameof(Thickness), typeof(double), typeof(Connection), new PropertyMetadata(default(double))); | ||
|
||
public double Thickness { | ||
get { return (double)GetValue(ThicknessProperty); } | ||
set { SetValue(ThicknessProperty, value); } | ||
} | ||
|
||
public Point InputPosition { | ||
get => (Point)GetValue(InputPositionDependencyProperty); | ||
set => SetValue(InputPositionDependencyProperty, value); | ||
} | ||
|
||
public Point OutputPosition { | ||
get => (Point)GetValue(OutputPositionDependencyProperty); | ||
set => SetValue(OutputPositionDependencyProperty, value); | ||
} | ||
|
||
public Brush HoverBrush { | ||
get => (Brush)GetValue(HoverBrushDependencyProperty); | ||
set => SetValue(HoverBrushDependencyProperty, value); | ||
} | ||
|
||
private static void Position_PropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e) { | ||
((UIElement)d).InvalidateVisual(); | ||
} | ||
|
||
private void LeftButtonClickHandler(object? sender, MouseButtonEventArgs ea) { | ||
} | ||
|
||
private void MouseButtonEventHandler(object sender, MouseButtonEventArgs e) { | ||
} | ||
|
||
protected override void OnRender(DrawingContext drawingContext) { | ||
base.OnRender(drawingContext); | ||
|
||
Pen pen; | ||
if (IsMouseOver) { | ||
pen = new Pen(HoverBrush, Thickness * 1.5); | ||
} else { | ||
pen = new Pen(Brush, Thickness); | ||
} | ||
|
||
Point[] points = [ | ||
new(InputPosition.X - 5, InputPosition.Y), | ||
new(InputPosition.X - 50, InputPosition.Y), | ||
new(OutputPosition.X + 50, OutputPosition.Y), | ||
new(OutputPosition.X + 5, OutputPosition.Y) | ||
]; | ||
|
||
var pathFigure = new PathFigure { | ||
StartPoint = points[0] | ||
}; | ||
pathFigure.Segments.Add( | ||
new BezierSegment(points[1], points[2], points[3], true)); | ||
pathFigure.IsClosed = false; | ||
|
||
PathGeometry path = new(); | ||
path.Figures.Add(pathFigure); | ||
|
||
drawingContext.DrawGeometry(null, new Pen(Brushes.Transparent, 5), path); | ||
drawingContext.DrawGeometry(null, pen, path); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.