Skip to content

Commit

Permalink
Refactor code and fix indentation in NodeControl and GraphControl
Browse files Browse the repository at this point in the history
Removed unnecessary whitespaces and corrected
  • Loading branch information
xorza committed May 20, 2024
1 parent e68b1ae commit 3046495
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
21 changes: 11 additions & 10 deletions ScenariumEditor.NET/GraphLib/Controls/GraphControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
namespace GraphLib.Controls;

public partial class GraphControl : UserControl {
private MainWindowViewModel _viewModel =null;
private MainWindowViewModel _viewModel = null;

public GraphControl() {
InitializeComponent();
}


private void CanvasgBg_OnLoaded(object sender, RoutedEventArgs e) {
_viewModel = (MainWindowViewModel)DataContext;

var graphCanvas = (UIElement)sender;

graphCanvas.MouseDown += GraphCanvasBg_OnButtonDown;
Expand Down Expand Up @@ -128,7 +128,7 @@ private void GraphCanvasBg_OnButtonUp(object sender, MouseButtonEventArgs e) {
} else {
CancelCuttingConnections();
}

_canvasState = CanvasState.Idle;
return;

Expand Down Expand Up @@ -216,7 +216,7 @@ private void Node_OnPinClick(object sender, Pin e) {
case CanvasState.Idle:
CancelCuttingConnections();
StopCanvasDragging();

_activePin = e;
_tempMousePin = new Pin {
DataType = e.DataType,
Expand All @@ -227,18 +227,19 @@ private void Node_OnPinClick(object sender, Pin e) {

NewConnectionControl.DataContext = new Connection(_activePin, _tempMousePin);
// NewConnectionControl.CaptureMouse();

_canvasState = CanvasState.NewConnection;
return;

case CanvasState.NewConnection:
if (e.DataType == _activePin.DataType && e.PinType.GetOpposite() == _activePin.PinType) {
_viewModel.Connections.Add(new Connection(_activePin, e));
CancelNewConnection();
_canvasState = CanvasState.Idle;
}

return;

default:
throw new ArgumentOutOfRangeException();
}
Expand Down
10 changes: 5 additions & 5 deletions ScenariumEditor.NET/GraphLib/Controls/NodeControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace GraphLib.Controls;

public partial class NodeControl : UserControl {
private Node _viewModel = null!;

public NodeControl() {
InitializeComponent();
}
Expand All @@ -20,8 +20,8 @@ private void Node_OnLoaded(object sender, RoutedEventArgs e) {
}

public event EventHandler<Pin> PinClick = null;
public event EventHandler DeletePressed = null;
public event EventHandler Selected = null;
public event EventHandler DeletePressed = null;
public event EventHandler Selected = null;


#region dragging
Expand Down Expand Up @@ -51,7 +51,7 @@ private void Header_OnMouseMove(object sender, MouseEventArgs e) {
var header = (FrameworkElement)sender!;
var currentPosition = e.GetPosition(header);
var delta = currentPosition - _headerDragMousePosition;

_viewModel.CanvasPosition += delta;
}

Expand All @@ -78,4 +78,4 @@ private void Node_OnMouseDown(object sender, MouseButtonEventArgs e) {
Selected?.Invoke(this, EventArgs.Empty);
e.Handled = true;
}
}
}

0 comments on commit 3046495

Please sign in to comment.