Skip to content

Commit

Permalink
Created GraphLib project and moved functionality from ScenariumEditor…
Browse files Browse the repository at this point in the history
….NET

Extracted various UI elements and their functionality from ScenariumEditor.NET into a new project named GraphLib. The Node, controls, and Util classes now reside in GraphLib under corresponding namespaces. The movement also included xaml style files and adjustments in namespaces and ProjectReferences in csproj files where necessary.
  • Loading branch information
xorza committed May 20, 2024
1 parent 9054c23 commit 5c04304
Show file tree
Hide file tree
Showing 17 changed files with 100 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Windows.Controls;
using System.Windows.Input;

namespace ScenariumEditor.NET;
namespace GraphLib.Controls;

public class ClickControl : Control {
private bool _leftButtonDown;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Windows.Controls;
using System.Windows.Media;

namespace ScenariumEditor.NET.Controls;
namespace GraphLib.Controls;

public class ClippingBorder : Border {
private readonly RectangleGeometry _clipRect = new RectangleGeometry();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Windows.Input;
using System.Windows.Media;

namespace ScenariumEditor.NET;
namespace GraphLib.Controls;

public class ConnectionEventArgs : RoutedEventArgs {
public ConnectionEventArgs(ConnectionControl connectionControl) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<UserControl x:Class="ScenariumEditor.NET.Node"
<UserControl x:Class="GraphLib.Controls.NodeControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:local="clr-namespace:ScenariumEditor.NET"
xmlns:viewModel="clr-namespace:ScenariumEditor.NET.ViewModel"
xmlns:controls="clr-namespace:ScenariumEditor.NET.Controls"
xmlns:local="clr-namespace:GraphLib"
xmlns:viewModel="clr-namespace:GraphLib.ViewModel"
xmlns:controls="clr-namespace:GraphLib.Controls"
d:DataContext="{d:DesignInstance Type=viewModel:DesignNode}"
mc:Ignorable="d"
Width="Auto"
Expand All @@ -17,6 +17,10 @@
MouseDown="Node_OnMouseDown">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Styles/Styles.xaml"></ResourceDictionary>
</ResourceDictionary.MergedDictionaries>

<sys:Double x:Key="PinSize">10</sys:Double>

<Style x:Key="PinButton"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using ScenariumEditor.NET.ViewModel;
using GraphLib.ViewModel;

namespace ScenariumEditor.NET;
namespace GraphLib.Controls;

public partial class Node : UserControl {
public Node() {
public partial class NodeControl : UserControl {
public NodeControl() {
InitializeComponent();
}

Expand All @@ -23,13 +23,13 @@ private void Node_OnLoaded(object sender, RoutedEventArgs e) {
public static readonly DependencyProperty NodeDataContextProperty = DependencyProperty.Register(
nameof(NodeDataContext),
typeof(ViewModel.Node),
typeof(Node),
typeof(NodeControl),
new PropertyMetadata(default(ViewModel.Node), NodeDataContextPropertyChangedCallback)
);

private static void
NodeDataContextPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e) {
((Node)d).DataContext = e.NewValue;
((NodeControl)d).DataContext = e.NewValue;
}

public ViewModel.Node NodeDataContext {
Expand Down
29 changes: 29 additions & 0 deletions ScenariumEditor.NET/GraphLib/GraphLib.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<LangVersion>latest</LangVersion>
<UseWPF>true</UseWPF>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>disable</Nullable>
<RootNamespace>GraphLib</RootNamespace>
</PropertyGroup>

<ItemGroup>
<Page Update="Styles\Basic.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Update="Styles\Styles.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Update="Styles\Button.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Update="Controls\NodeControl.xaml">
<Generator>MSBuild:Compile</Generator>
<XamlRuntime>Wpf</XamlRuntime>
<SubType>Designer</SubType>
</Page>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Windows;

namespace ScenariumEditor.NET.Utils;
namespace GraphLib.Utils;

public class BindingProxy : Freezable {
public static readonly DependencyProperty DataContextProperty = DependencyProperty.Register (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Windows;

namespace ScenariumEditor.NET.Utils;
namespace GraphLib.Utils;

public static class Xtensions {
public static Vector ToVector(this Point point) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Runtime.CompilerServices;
using System.Windows;

namespace ScenariumEditor.NET.ViewModel;
namespace GraphLib.ViewModel;

public class MainWindowViewModel : INotifyPropertyChanged {
public MainWindowViewModel() {
Expand Down Expand Up @@ -101,7 +101,7 @@ public enum PinType {
Trigger
}

static class PinTypeExtensions {
public static class PinTypeExtensions {
public static PinType GetOpposite(this PinType pinType) {
return pinType switch {
PinType.Input => PinType.Output,
Expand Down
6 changes: 6 additions & 0 deletions ScenariumEditor.NET/ScenariumEditor.NET.sln
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ScenariumEditor.NET", "ScenariumEditor.NET\ScenariumEditor.NET.csproj", "{346482BC-E92E-4E4C-BF00-F382DF4B54DA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GraphLib", "GraphLib\GraphLib.csproj", "{5BC19293-C026-4B79-AFF5-24D2EE911B77}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -12,5 +14,9 @@ Global
{346482BC-E92E-4E4C-BF00-F382DF4B54DA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{346482BC-E92E-4E4C-BF00-F382DF4B54DA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{346482BC-E92E-4E4C-BF00-F382DF4B54DA}.Release|Any CPU.Build.0 = Release|Any CPU
{5BC19293-C026-4B79-AFF5-24D2EE911B77}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5BC19293-C026-4B79-AFF5-24D2EE911B77}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5BC19293-C026-4B79-AFF5-24D2EE911B77}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5BC19293-C026-4B79-AFF5-24D2EE911B77}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
42 changes: 21 additions & 21 deletions ScenariumEditor.NET/ScenariumEditor.NET/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

xmlns:local="clr-namespace:ScenariumEditor.NET"
xmlns:viewModel="clr-namespace:ScenariumEditor.NET.ViewModel"
xmlns:controls="clr-namespace:ScenariumEditor.NET.Controls"
xmlns:utils="clr-namespace:ScenariumEditor.NET.Utils"
xmlns:viewModel="clr-namespace:GraphLib.ViewModel;assembly=GraphLib"
xmlns:controls="clr-namespace:GraphLib.Controls;assembly=GraphLib"
xmlns:utils="clr-namespace:GraphLib.Utils;assembly=GraphLib"

d:DataContext="{d:DesignInstance Type=viewModel:DesignMainWindowViewModel}"
mc:Ignorable="d"
Expand Down Expand Up @@ -63,13 +63,13 @@
ItemsSource="{Binding Connections}">
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type viewModel:Connection}">
<local:ConnectionControl Pin1Position="{Binding Input.CanvasPosition}"
Pin2Position="{Binding Output.CanvasPosition}"
BorderBrush="{StaticResource Blue}"
HoverBrush="{StaticResource HighlightOverlayBrush}"
DeletedBrush="{StaticResource Yellow}"
Loaded="ConnectionControl_OnLoaded"
Unloaded="ConnectionControl_OnUnloaded" />
<controls:ConnectionControl Pin1Position="{Binding Input.CanvasPosition}"
Pin2Position="{Binding Output.CanvasPosition}"
BorderBrush="{StaticResource Blue}"
HoverBrush="{StaticResource HighlightOverlayBrush}"
DeletedBrush="{StaticResource Yellow}"
Loaded="ConnectionControl_OnLoaded"
Unloaded="ConnectionControl_OnUnloaded" />
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
Expand Down Expand Up @@ -105,13 +105,13 @@
</TransformGroup>
</Canvas.RenderTransform>

<local:ConnectionControl x:Name="NewConnectionControl"
Visibility="Collapsed"
Pin1Position="{Binding Input.CanvasPosition}"
Pin2Position="{Binding Output.CanvasPosition}"
BorderBrush="{StaticResource Blue}"
HoverBrush="{StaticResource Blue}"
HoverThickness="2" />
<controls:ConnectionControl x:Name="NewConnectionControl"
Visibility="Collapsed"
Pin1Position="{Binding Input.CanvasPosition}"
Pin2Position="{Binding Output.CanvasPosition}"
BorderBrush="{StaticResource Blue}"
HoverBrush="{StaticResource Blue}"
HoverThickness="2" />

<Path x:Name="CuttingPath"
Visibility="Collapsed"
Expand All @@ -127,10 +127,10 @@
DataContext="{Binding}">
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type viewModel:Node}">
<local:Node NodeDataContext="{Binding}"
PinClick="Node_OnPinClick"
DeletePressed="Node_OnDeletePressed"
Selected="Node_OnSelected" />
<controls:NodeControl NodeDataContext="{Binding}"
PinClick="Node_OnPinClick"
DeletePressed="Node_OnDeletePressed"
Selected="Node_OnSelected" />
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
Expand Down
9 changes: 5 additions & 4 deletions ScenariumEditor.NET/ScenariumEditor.NET/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ScenariumEditor.NET.Utils;
using ScenariumEditor.NET.ViewModel;
using GraphLib.Controls;
using GraphLib.Utils;
using GraphLib.ViewModel;

namespace ScenariumEditor.NET;

Expand Down Expand Up @@ -386,13 +387,13 @@ private void ConnectionControl_OnUnloaded(object sender, RoutedEventArgs e) {
#endregion

private void Node_OnDeletePressed(object sender, EventArgs e) {
var nodeControl = (Node)sender;
var nodeControl = (NodeControl)sender;
var node = nodeControl.NodeDataContext;
_viewModel.Remove(node);
}

private void Node_OnSelected(object sender, EventArgs e) {
var nodeControl = (Node)sender;
var nodeControl = (NodeControl)sender;
var node = nodeControl.NodeDataContext;
_viewModel.SelectedNode = node;
}
Expand Down
13 changes: 13 additions & 0 deletions ScenariumEditor.NET/ScenariumEditor.NET/ScenariumEditor.NET.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,22 @@
<Nullable>disable</Nullable>
<UseWPF>true</UseWPF>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>latest</LangVersion>
<RootNamespace>ScenariumEditor.NET</RootNamespace>
</PropertyGroup>

<ItemGroup>
<Page Update="Styles\Window.xaml">
<Generator>MSBuild:Compile</Generator>
<XamlRuntime>Wpf</XamlRuntime>
<SubType>Designer</SubType>
</Page>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\GraphLib\GraphLib.csproj" />
</ItemGroup>



</Project>
61 changes: 3 additions & 58 deletions ScenariumEditor.NET/ScenariumEditor.NET/Styles/Basic.xaml
Original file line number Diff line number Diff line change
@@ -1,59 +1,4 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=System.Runtime">

<BooleanToVisibilityConverter x:Key="BoolToVis" />
<Brush x:Key="HighlightOverlayBrush">#6FFF</Brush>

<Brush x:Key="Yellow">#E9BB35</Brush>
<Brush x:Key="Green">#53A957</Brush>
<Brush x:Key="Blue">#34A0F6</Brush>
<Brush x:Key="Red">#ED5353</Brush>

<Brush x:Key="LiteYellow">#FFDD80</Brush>
<Brush x:Key="LiteGreen">#80FF84</Brush>
<Brush x:Key="LiteBlue">#80C8FF</Brush>
<Brush x:Key="LiteRed">#FF8080</Brush>

<Brush x:Key="DarkYellow">#996A34</Brush>
<Brush x:Key="DarkGreen">#376E37</Brush>
<Brush x:Key="DarkBlue">#2A68A9</Brush>
<Brush x:Key="DarkRed">#A32A2A</Brush>

<Brush x:Key="DarkWhite">#BCBCBC</Brush>
<Brush x:Key="Gray">#333333</Brush>

<Brush x:Key="DarkerGray">#222</Brush>
<Brush x:Key="DarkGray">#131313</Brush>


<CornerRadius x:Key="CornerRadius">5</CornerRadius>

<Style TargetType="Border" >
<Setter Property="SnapsToDevicePixels" Value="True" />
</Style>


<Style TargetType="Label">
<Setter Property="Margin" Value="2"></Setter>
<Setter Property="Padding" Value="0"></Setter>
<Setter Property="Foreground" Value="#D5D5D5"></Setter>
</Style>



<Style TargetType="Path" x:Key="DefaultPath">
<Setter Property="Stretch" Value="Fill" />
<Setter Property="StrokeThickness" Value="1.5" />
<Setter Property="Stroke" Value="MediumVioletRed" />
</Style>


<Style TargetType="Path" x:Key="CrossPath" BasedOn="{StaticResource DefaultPath}">
<Setter Property="Data" Value="M 0,0 L 1,1 M 0,1 L 1,0" />
</Style>

<Style TargetType="Path" BasedOn="{StaticResource DefaultPath}" />


</ResourceDictionary>
Source="pack://application:,,,/GraphLib;component/Styles/Styles.xaml" />

3 changes: 1 addition & 2 deletions ScenariumEditor.NET/ScenariumEditor.NET/Styles/Styles.xaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Basic.xaml" />
<ResourceDictionary Source="Button.xaml" />
<ResourceDictionary Source="Window.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
3 changes: 1 addition & 2 deletions ScenariumEditor.NET/ScenariumEditor.NET/Styles/Window.xaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:ScenariumEditor.NET.Controls"
xmlns:controls="clr-namespace:GraphLib.Controls;assembly=GraphLib"
x:Class="ScenariumEditor.NET.Styles.WindowResourceDictionary">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Basic.xaml" />
<ResourceDictionary Source="Button.xaml" />
</ResourceDictionary.MergedDictionaries>

<Style x:Key="BorderRect" TargetType="Rectangle">
Expand Down

0 comments on commit 5c04304

Please sign in to comment.