Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a simple API to Nodify #36

Draft
wants to merge 35 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
da478e3
Trying to provide a simpler interface to nodify
miroiu Jul 13, 2022
03e05d6
Add relay node
miroiu Jul 15, 2022
1000ced
Refactoring
miroiu Jul 15, 2022
61484ec
Implemented FocusLocation
miroiu Jul 15, 2022
c8858cf
Rename to Nodifier
miroiu Jul 15, 2022
2a10dd3
Expose editor functionality
miroiu Jul 15, 2022
13fe4aa
Add toolkit
miroiu Jul 15, 2022
ce9c8ec
Expose more editor settings
miroiu Sep 3, 2022
a1b8257
Extract editor settings
miroiu Sep 5, 2022
dadcd57
Fit to screen
miroiu Sep 5, 2022
8e37ac5
Using static resource for brushes
miroiu Sep 23, 2022
e7ac4e8
Merge branch 'master' into feature/new-blueprint
miroiu Sep 30, 2022
f715101
Add decorators
miroiu Sep 30, 2022
b82583a
Merge branch 'master' into feature/new-blueprint
miroiu Oct 1, 2022
083a4bc
Merge branch 'master' into feature/new-blueprint
miroiu Oct 3, 2022
84b3f10
Removed Stylet dependency
miroiu Oct 5, 2022
57c594a
Merge branch 'master' into feature/new-blueprint
miroiu Oct 5, 2022
e7fe8be
Merge branch 'master' into feature/new-blueprint
miroiu Oct 6, 2022
ec21f86
Merge branch 'master' into feature/new-blueprint
miroiu Oct 6, 2022
9c917bf
Merge branch 'master' into feature/new-blueprint
miroiu Oct 12, 2022
c97f42e
Comments and credits
miroiu Oct 12, 2022
b9adc5d
Merge branch 'master' into feature/new-blueprint
miroiu Oct 15, 2022
99a5436
Merge branch 'master' into feature/new-blueprint
miroiu Oct 17, 2022
b54c607
Merge branch 'master' into feature/new-blueprint
miroiu Oct 17, 2022
90a0cb4
Basic undo redo
miroiu Oct 17, 2022
7a6ccef
Refactoring
miroiu Oct 18, 2022
3d38188
Merge branch 'master' into feature/new-blueprint
miroiu Oct 18, 2022
c5eaaf6
Undo redo improvements
miroiu Oct 19, 2022
a919515
Record properties
miroiu Oct 22, 2022
2d0229f
Fix try connect
miroiu Oct 22, 2022
bfe97c8
Merge branch 'master' into feature/new-blueprint
miroiu Mar 30, 2023
34d65bb
Merge branch 'master' into feature/new-blueprint
miroiu May 1, 2023
21d64e5
Refactorings + improved dependency injection
miroiu May 1, 2023
ad1196e
Moving files around
miroiu May 9, 2023
95cf26f
Snapshot/serialization/copy-paste in progress
miroiu May 9, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions Examples/Nodify.MinimalExample/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<Application x:Class="Nodify.MinimalExample.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:nodifier="https://miroiu.github.io/nodifier"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/Nodify;component/Themes/Dark.xaml" />
<ResourceDictionary>
<Style TargetType="CheckBox" BasedOn="{StaticResource {x:Type CheckBox}}">
<Style.Setters>
<Setter Property="Background" Value="LightGray" />
</Style.Setters>
</Style>
<Style TargetType="TextBox" BasedOn="{StaticResource {x:Type TextBox}}">
<Style.Setters>
<Setter Property="Background" Value="LightGray" />
</Style.Setters>
</Style>

<Style TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Button}}">
<Setter Property="Margin"
Value="0,0,5,0" />
<Setter Property="Background"
Value="#393939" />
<Setter Property="Padding"
Value="5 3" />
<Setter Property="BorderBrush"
Value="#696f75" />
<Setter Property="Cursor"
Value="Hand" />
<Setter Property="Foreground"
Value="White" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Margin="{TemplateBinding Margin}"
Padding="{TemplateBinding Padding}">
<ContentPresenter />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver"
Value="True">
<Setter Property="Background"
Value="#404245" />
</Trigger>
</Style.Triggers>
</Style>
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
11 changes: 11 additions & 0 deletions Examples/Nodify.MinimalExample/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Windows;

namespace Nodify.MinimalExample
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}
}
10 changes: 10 additions & 0 deletions Examples/Nodify.MinimalExample/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Windows;

[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]
29 changes: 29 additions & 0 deletions Examples/Nodify.MinimalExample/Bootstrapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Nodifier;

namespace Nodify.MinimalExample
{
public class Bootstrapper
{
public MinimalApp Application { get; }

public Bootstrapper()
{
var services = new ServiceCollection();
ConfigureServices(services);

var serviceProvider = services.BuildServiceProvider();
serviceProvider.UseBlueprints();

Application = serviceProvider.GetRequiredService<MinimalApp>();
}

private static void ConfigureServices(IServiceCollection services)
{
services.AddBlueprints();
services.AddSingleton<MinimalApp>();
services.AddLogging(x => x.SetMinimumLevel(LogLevel.Debug));
}
}
}
54 changes: 54 additions & 0 deletions Examples/Nodify.MinimalExample/MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<Window x:Class="Nodify.MinimalExample.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Nodify.MinimalExample"
xmlns:nodifier="https://miroiu.github.io/nodifier"
xmlns:s="clr-namespace:Nodifier.XAML;assembly=Nodifier"
mc:Ignorable="d"
Background="{StaticResource NodifyEditor.BackgroundBrush}"
Title="MainWindow" Height="450" Width="800">
<Window.Resources>
<local:Bootstrapper x:Key="Bootstrapper" />
</Window.Resources>

<Window.DataContext>
<Binding Path="Application" Source="{StaticResource Bootstrapper}" />
</Window.DataContext>

<Window.InputBindings>
<KeyBinding Gesture="Ctrl+C" Command="{s:Action Copy}" s:View.ActionTarget="{Binding}" />
<KeyBinding Gesture="Ctrl+V" Command="{s:Action Paste}" s:View.ActionTarget="{Binding}" />
</Window.InputBindings>

<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>

<Border VerticalAlignment="Top"
Padding="10"
Background="{StaticResource NodifyEditor.SelectionRectangleBackgroundBrush}">
<Grid>

<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>

<StackPanel Orientation="Horizontal">
<Button Command="{s:Action Undo}" s:View.ActionTarget="{Binding}" Margin="0 0 8 0">Undo</Button>
<Button Command="{s:Action Redo}" s:View.ActionTarget="{Binding}" Margin="0 0 32 0">Redo</Button>
<Button Command="{s:Action Copy}" s:View.ActionTarget="{Binding}" Margin="0 0 8 0">Copy</Button>
<Button Command="{s:Action Paste}" s:View.ActionTarget="{Binding}" Margin="0 0 32 0">Paste</Button>
<Button Command="{s:Action SaveAndReload}" s:View.ActionTarget="{Binding}">Save and Reload</Button>
</StackPanel>
</Grid>
</Border>

<nodifier:NodeGraph DataContext="{Binding Graph.Widget}" Grid.Row="1" />
<!--<nodifier:BlueprintGraph DataContext="{Binding Graph}" />-->
</Grid>
</Window>
15 changes: 15 additions & 0 deletions Examples/Nodify.MinimalExample/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Windows;

namespace Nodify.MinimalExample
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
}
}
122 changes: 122 additions & 0 deletions Examples/Nodify.MinimalExample/MinimalApp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
using Microsoft.Extensions.Logging;
using Nodifier;
using Nodifier.Blueprint;
using System.Text.Json;
using System.Windows;

namespace Nodify.MinimalExample
{
// TODO: AddValueInput is not working for non generic BPNode
public class ToStringNode : BPNode<BPNodeSnapshot>
{
public ValueInput<object> In { get; set; }
public ValueOutput<string> Out { get; set; }

public ToStringNode(IBlueprintGraph graph) : base(graph)
{
In = AddValueInput<object>();
Out = AddValueOutput<string>();

Widget.Content = "To String";
}
}


public class ForLoopSnapshot : BPNodeSnapshot
{
public string? Header { get; set; }
}

public class ForLoopNode : BPNode<ForLoopSnapshot>
{
public FlowInput In { get; }
public FlowOutput Body { get; }
public FlowOutput Completed { get; }
public ValueInput<int> FirstIndex { get; }
public ValueInput<int> LastIndex { get; }
public ValueInput<int> Step { get; }
public ValueOutput<int> Index { get; }

// Dependency injection is possible
public ForLoopNode(IBlueprintGraph graph, ILogger<ForLoopNode> logger) : base(graph)
{
Widget.Header = "For Loop";

In = AddFlowInput();

FirstIndex = AddValueInput<int>("First Index");
LastIndex = AddValueInput<int>("Last Index");
Step = AddValueInput<int>("Step");

Body = AddFlowOutput("Body");
Index = AddValueOutput<int>("Index");
Completed = AddFlowOutput("Completed");
}

protected override void OnSnapshotCreating(ForLoopSnapshot snapshot)
{
base.OnSnapshotCreating(snapshot);

snapshot.Header = Widget.Header?.ToString();
}
}

public class MinimalApp : PropertyChangedBase
{
private readonly IGraphFactory _graphFactory;

private IBlueprintGraph _graph;
public IBlueprintGraph Graph
{
get => _graph;
set => SetAndNotify(ref _graph, value);
}

public MinimalApp(IGraphFactory graphFactory)
{
Graph = graphFactory.Get<IBlueprintGraph>();

Graph.History.IsEnabled = false;

//Editor.AddElement(new CustomGraphNode(Editor) { Location = new Point(100, 50) });
//Editor.AddElement(new CustomGraphNode(Editor) { Location = new Point(200, 150) });
//Editor.AddElement(new CustomGraphNode(Editor) { Location = new Point(100, 250) });
//Editor.AddComment("Generated comment", Editor.Elements);

var forLoop = Graph.AddNode<ForLoopNode>();
var forLoop2 = Graph.AddNode<ForLoopNode>();
forLoop2.Widget.Location = new Point(250, 100);

Graph.AddNode<ToStringNode>().Widget.Location = new Point(250, 50);
//var node = new NodeWidget(Graph.Widget)
//{
// Content = "ADD",
// Location = new Point(300, 300)
//};
//node.AddInput(new BaseConnector(node));
//node.AddInput(new BaseConnector(node));
//node.AddOutput(new BaseConnector(node));
//Graph.Widget.AddElement(node);

Graph.History.IsEnabled = true;
_graphFactory = graphFactory;
}

public void Undo() => Graph.History.Undo();
public void Redo() => Graph.History.Redo();

public void Copy() => BPClipboard.CopySelection(Graph);
public void Paste() => BPClipboard.PasteSelection(Graph);

public void SaveAndReload()
{
var saveSnapshot = ((IGraphMemento)Graph).CreateSnapshot();
var result = JsonSerializer.Serialize(saveSnapshot);

var restoreSnapshot = JsonSerializer.Deserialize<GraphSnapshot>(result)!;

Graph = _graphFactory.Get<BPGraph>();
((IGraphMemento)Graph).RestoreSnapshot(restoreSnapshot);
}
}
}
17 changes: 17 additions & 0 deletions Examples/Nodify.MinimalExample/Nodify.MinimalExample.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFrameworks>net6-windows;netcoreapp3.1</TargetFrameworks>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Nodifier\Nodifier.csproj" />
</ItemGroup>

</Project>
Loading