Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
ProcessSnapshotControl.xaml.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Windows;
6 using System.Windows.Controls;
7 using System.Windows.Data;
8 using System.Windows.Documents;
9 using System.Windows.Input;
10 using System.Windows.Media;
11 using System.Windows.Media.Imaging;
12 using System.Windows.Navigation;
13 using System.Windows.Shapes;
15 using SiliconStudio.Paradox.DebugTools.DataStructures;
16 using SiliconStudio.Presentation.Controls;
17 
18 namespace SiliconStudio.Paradox.DebugTools
19 {
20  /// <summary>
21  /// Interaction logic for ProcessSnapshotControl.xaml
22  /// </summary>
23  public partial class ProcessSnapshotControl : UserControl
24  {
25  private ProcessInfo processInfo;
26 
27  public ProcessSnapshotControl(ProcessInfo processInfo)
28  {
29  InitializeComponent();
30 
31  if (processInfo == null || processInfo.Frames.Count == 0)
32  return;
33 
34  this.DataContext = this;
35 
36  this.processInfo = processInfo;
37  this.Loaded += OnLoaded;
38 
39  timebar.BeforeTicksRender += new CustomRenderRoutedEventHandler(timebar_Layer0CustomRender);
40 
41  CreateTreeView();
42  }
43 
44  private Pen pen = new Pen(Brushes.Red, 1.0);
45 
46  private void timebar_Layer0CustomRender(object sender, CustomRenderRoutedEventArgs e)
47  {
48  double pixel = processInfo.TimeLength * processInfoRenderer.PixelsPerSecond;
49  e.DrawingContext.DrawLine(pen, new Point(pixel, 0.0), new Point(pixel, timebar.ActualHeight));
50  }
51 
52  private void CreateTreeView()
53  {
54  if (processInfo == null)
55  return;
56 
57  foreach (FrameInfo frame in processInfo.Frames)
58  {
59  TreeViewItem tviFrame = new TreeViewItem { Header = string.Format("Frame {0} ({1} - {2})", frame.FrameNumber, frame.BeginTime, frame.EndTime) };
60 
61  foreach (ThreadInfo thread in frame.ThreadItems)
62  {
63  TreeViewItem tviThread = new TreeViewItem { Header = string.Format("Thread {0}", thread.Id) };
64 
65  foreach (MicroThreadInfo mt in thread.MicroThreadItems)
66  {
67  TreeViewItem tviMicroThread = new TreeViewItem { Header = string.Format("MicroThread {0} ({1} - {2})", mt.Id, mt.BeginTime, mt.EndTime) };
68  tviThread.Items.Add(tviMicroThread);
69  }
70 
71  tviFrame.Items.Add(tviThread);
72  }
73 
74  treeView.Items.Add(tviFrame);
75  }
76  }
77 
78  private void OnLoaded(object sender, RoutedEventArgs e)
79  {
80  if (processInfo == null)
81  return;
82 
83  FrameInfo lastFrame = processInfo.Frames.Last();
84 
85  processInfoRenderer.SizeChanged += (ss, ee) => timebar.SetUnitAt(lastFrame.EndTime, processInfoRenderer.ActualWidth);
86 
87  timebar.BeforeRender += (ss, ee) =>
88  {
89  processInfoRenderer.Width = processInfo.TimeLength * timebar.PixelsPerUnit;
90  processInfoRenderer.PixelsPerSecond = timebar.PixelsPerUnit;
91  processInfoRenderer.RenderAllFrames(processInfo);
92  };
93 
94  processInfoRenderer.RenderAllFrames(processInfo);
95 
96  scrollViewer.ScrollToRightEnd();
97  }
98 
99  private void timebar_MouseMove(object sender, MouseEventArgs e)
100  {
101  Point pos = e.GetPosition(timebar);
102  Window.GetWindow(this).Title = timebar.GetUnitAt(pos.X).ToString();
103  }
104  }
105 }
delegate void CustomRenderRoutedEventHandler(object sender, CustomRenderRoutedEventArgs e)
Interaction logic for ProcessSnapshotControl.xaml
System.Windows.Point Point
Definition: ColorPicker.cs:15