-
-
Notifications
You must be signed in to change notification settings - Fork 234
/
Copy pathMainWindow.xaml.cs
84 lines (73 loc) · 2.38 KB
/
MainWindow.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using System;
using System.Windows;
using System.Windows.Media;
namespace Nodify.Playground
{
public static class CompositionTargetEx
{
private static TimeSpan _last = TimeSpan.Zero;
private static event Action<double>? FrameUpdating;
public static event Action<double> Rendering
{
add
{
if (FrameUpdating == null)
{
CompositionTarget.Rendering += OnRendering;
}
FrameUpdating += value;
}
remove
{
FrameUpdating -= value;
if (FrameUpdating == null)
{
CompositionTarget.Rendering -= OnRendering;
}
}
}
private static void OnRendering(object? sender, EventArgs e)
{
RenderingEventArgs args = (RenderingEventArgs)e;
var renderingTime = args.RenderingTime;
if (renderingTime == _last)
return;
double fps = 1000 / (renderingTime - _last).TotalMilliseconds;
_last = renderingTime;
FrameUpdating?.Invoke(fps);
}
}
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private readonly Random _rand = new Random();
public MainWindow()
{
InitializeComponent();
CompositionTargetEx.Rendering += OnRendering;
}
private void OnRendering(double fps)
{
FPSText.Text = fps.ToString("0");
}
private void BringIntoView_Click(object sender, RoutedEventArgs e)
{
if (DataContext is PlaygroundViewModel model)
{
NodifyObservableCollection<NodeViewModel> nodes = model.GraphViewModel.Nodes;
int index = _rand.Next(nodes.Count);
if (nodes.Count > index)
{
NodeViewModel node = nodes[index];
EditorCommands.BringIntoView.Execute(node.Location, EditorView.Editor);
}
}
}
private void AnimateConnections_Click(object sender, RoutedEventArgs e)
{
EditorSettings.Instance.IsAnimatingConnections = !EditorSettings.Instance.IsAnimatingConnections;
}
}
}