Skip to content

Commit

Permalink
Update UI controls and add IsEvent property
Browse files Browse the repository at this point in the history
Updated NodeControl and ConnectionControl UI, modifying colors for better visibility. Added IsEvent property to ConnectionControl to highlight event-driven connections. Also, few minor white-space and
  • Loading branch information
xorza committed May 20, 2024
1 parent 35f9133 commit e68b1ae
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 25 deletions.
50 changes: 32 additions & 18 deletions ScenariumEditor.NET/GraphLib/Controls/ConnectionControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@

namespace GraphLib.Controls;

public class ConnectionEventArgs : RoutedEventArgs {
public ConnectionEventArgs(ConnectionControl connectionControl) {
ConnectionControl = connectionControl;
}

public ConnectionControl ConnectionControl { get; }
}

public class ConnectionControl : ClickControl {
public static readonly DependencyProperty InputPositionDependencyProperty = DependencyProperty.Register(
nameof(Pin1Position),
Expand Down Expand Up @@ -55,6 +47,36 @@ public double Thickness {
new PropertyMetadata(3.0, OnPropertyChangedCallback_InvalidateVisual)
);

public static readonly DependencyProperty DeletedBrushProperty = DependencyProperty.Register(
nameof(DeletedBrush), typeof(Brush), typeof(ConnectionControl),
new PropertyMetadata(Brushes.IndianRed, OnPropertyChangedCallback_InvalidateVisual)
);

public static readonly DependencyProperty IsDeletedProperty = DependencyProperty.Register(
nameof(IsDeleted), typeof(bool), typeof(ConnectionControl),
new PropertyMetadata(default(bool), OnPropertyChangedCallback_InvalidateVisual)
);

public static readonly DependencyProperty EventBrushProperty = DependencyProperty.Register(
nameof(EventBrush), typeof(Brush), typeof(ConnectionControl),
new PropertyMetadata(default(Brush), OnPropertyChangedCallback_InvalidateVisual)
);

public static readonly DependencyProperty IsEventProperty = DependencyProperty.Register(
nameof(IsEvent), typeof(bool), typeof(ConnectionControl),
new PropertyMetadata(default(bool), OnPropertyChangedCallback_InvalidateVisual)
);

public bool IsEvent {
get { return (bool)GetValue(IsEventProperty); }
set { SetValue(IsEventProperty, value); }
}

public Brush EventBrush {
get { return (Brush)GetValue(EventBrushProperty); }
set { SetValue(EventBrushProperty, value); }
}

public double HoverThickness {
get { return (double)GetValue(HoverThicknessProperty); }
set { SetValue(HoverThicknessProperty, value); }
Expand All @@ -75,21 +97,11 @@ public Brush HoverBrush {
set => SetValue(HoverBrushDependencyProperty, value);
}

public static readonly DependencyProperty DeletedBrushProperty = DependencyProperty.Register(
nameof(DeletedBrush), typeof(Brush), typeof(ConnectionControl),
new PropertyMetadata(Brushes.IndianRed, OnPropertyChangedCallback_InvalidateVisual)
);

public Brush DeletedBrush {
get { return (Brush)GetValue(DeletedBrushProperty); }
set { SetValue(DeletedBrushProperty, value); }
}

public static readonly DependencyProperty IsDeletedProperty = DependencyProperty.Register(
nameof(IsDeleted), typeof(bool), typeof(ConnectionControl),
new PropertyMetadata(default(bool), OnPropertyChangedCallback_InvalidateVisual)
);

public bool IsDeleted {
get { return (bool)GetValue(IsDeletedProperty); }
set { SetValue(IsDeletedProperty, value); }
Expand Down Expand Up @@ -135,6 +147,8 @@ [new BezierSegment(points[1], points[2], points[3], true)],
drawingContext.DrawGeometry(null, new Pen(DeletedBrush, Thickness), Geometry);
} else if (IsMouseOver) {
drawingContext.DrawGeometry(null, new Pen(HoverBrush, HoverThickness), Geometry);
} else if (IsEvent) {
drawingContext.DrawGeometry(null, new Pen(EventBrush, Thickness), Geometry);
} else {
drawingContext.DrawGeometry(null, new Pen(BorderBrush, Thickness), Geometry);
}
Expand Down
8 changes: 6 additions & 2 deletions ScenariumEditor.NET/GraphLib/Controls/GraphControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@
<DataTemplate DataType="{x:Type viewModel:Connection}">
<local:ConnectionControl Pin1Position="{Binding Input.CanvasPosition}"
Pin2Position="{Binding Output.CanvasPosition}"
IsEvent="{Binding IsEvent}"
BorderBrush="{StaticResource Blue}"
HoverBrush="{StaticResource HighlightOverlayBrush}"
DeletedBrush="{StaticResource Yellow}"
DeletedBrush="{StaticResource Red}"
EventBrush="{StaticResource Yellow}"
Loaded="ConnectionControl_OnLoaded"
Unloaded="ConnectionControl_OnUnloaded" />
</DataTemplate>
Expand Down Expand Up @@ -79,13 +81,15 @@
Visibility="Collapsed"
Pin1Position="{Binding Input.CanvasPosition}"
Pin2Position="{Binding Output.CanvasPosition}"
IsEvent="{Binding IsEvent}"
EventBrush="{StaticResource Yellow}"
BorderBrush="{StaticResource Blue}"
HoverBrush="{StaticResource Blue}"
HoverThickness="2" />

<Path x:Name="CuttingPath"
Visibility="Collapsed"
StrokeThickness="3"
StrokeThickness="1"
Stroke="{StaticResource Red}" />

</Canvas>
Expand Down
10 changes: 6 additions & 4 deletions ScenariumEditor.NET/GraphLib/Controls/NodeControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
Background="{x:Null}"

Loaded="Node_OnLoaded"
MouseDown="Node_OnMouseDown">
<!-- d:DataContext="{d:DesignInstance Type=viewModel:DesignNode}" -->
MouseDown="Node_OnMouseDown"

d:DataContext="{d:DesignInstance Type=viewModel:DesignNode}">

<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
Expand Down Expand Up @@ -81,7 +83,7 @@
VerticalAlignment="Top"
HorizontalAlignment="Left"
Margin="-6 1 0 0"
Background="{StaticResource Red}"
Background="{StaticResource Yellow}"
DataContext="{Binding Trigger}"
Loaded="PinButton_OnLoaded"
Click="PinButton_OnClick" />
Expand Down Expand Up @@ -149,7 +151,7 @@

<Button Style="{StaticResource PinButton}"
Margin="0 0 -6 0"
Background="{StaticResource Red}"
Background="{StaticResource Yellow}"
Loaded="PinButton_OnLoaded"
Click="PinButton_OnClick" />
</StackPanel>
Expand Down
5 changes: 4 additions & 1 deletion ScenariumEditor.NET/GraphLib/ViewModel/ViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public Node SelectedNode {
}

_selectedNode = value;

if (_selectedNode != null) {
_selectedNode.IsSelected = true;
}
Expand Down Expand Up @@ -347,11 +347,14 @@ protected bool SetField<T>(ref T field, T value, [CallerMemberName] string prope
public Pin Output { get; init; }
public Pin Input { get; init; }

public bool IsEvent { get; private init; }

public Connection(Pin pin1, Pin pin2) {
Debug.Assert(!ReferenceEquals(pin1, pin2));
var (input, output) = Pin.Sort(pin1, pin2);
Input = input;
Output = output;
IsEvent = input.PinType == PinType.Trigger;
}
}

Expand Down

0 comments on commit e68b1ae

Please sign in to comment.