protected override void HandleMouseMove(object sender, MouseEventArgs e)
{
if (mouseMode == MouseMode.PreSelectionRectangle || mouseMode == MouseMode.SelectionRectangle)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
mouseMode = MouseMode.SelectionRectangle;
if (selectionRectangle == null)
{
selectionRectangle = new Border
{
// Move to WPF style
Background = Brushes.Transparent,
BorderBrush =
new SolidColorBrush(Application.Current.Resources["ColorBlue"] is Color
? (Color) Application.Current.Resources["ColorBlue"]
: new Color()),
CornerRadius = new CornerRadius(5),
BorderThickness = new Thickness(2)
};
SetLeft(selectionRectangle, startSelectionRectanglePoint.X);
SetTop(selectionRectangle, startSelectionRectanglePoint.Y);
Children.Add(selectionRectangle);
}
var currentPosition = Mouse.GetPosition(this);
var delta = Point.Subtract(currentPosition, startSelectionRectanglePoint);
if (delta.X < 0)
SetLeft(selectionRectangle, currentPosition.X);
if (delta.Y < 0)
SetTop(selectionRectangle, currentPosition.Y);
selectionRectangle.Width = Math.Abs(delta.X);
selectionRectangle.Height = Math.Abs(delta.Y);
foreach (var node in NodeCollection)
{
SelectedNodes.Remove(node);
if (node.Left >= GetLeft(selectionRectangle) &&
node.Left + node.ActualWidth <= GetLeft(selectionRectangle) + selectionRectangle.Width &&
node.Top >= GetTop(selectionRectangle) &&
node.Top + node.ActualHeight <= GetTop(selectionRectangle) + selectionRectangle.Height)
{
node.IsSelected = true;
SelectedNodes.Add(node);
}
else
node.IsSelected = false;
}
}
}
else if (mouseMode == MouseMode.Panning)
{
var v = start - e.GetPosition(this);
TranslateTransform.X = origin.X - v.X;
TranslateTransform.Y = origin.Y - v.Y;
}
switch (SplineMode)
{
case SplineModes.Nothing:
ClearTempLine();
break;
case SplineModes.First:
break;
case SplineModes.Second:
if (TempLine == null)
{
TempLine = new Line {Style = FindResource("VplLineStyle") as Style};
Children.Add(TempLine);
}
TempLine.X1 = TempStartPort.Origin.X;
TempLine.Y1 = TempStartPort.Origin.Y;
TempLine.X2 = Mouse.GetPosition(this).X;
TempLine.Y2 = Mouse.GetPosition(this).Y;
break;
default:
throw new ArgumentOutOfRangeException();
}
}