Commits

Mark Heath committed 972bd02

added a new commit node control

Comments (0)

Files changed (5)

GraphPad/GraphPad.csproj

     </Reference>
     <Reference Include="System" />
     <Reference Include="System.Data" />
+    <Reference Include="System.Drawing" />
     <Reference Include="System.Windows.Forms" />
     <Reference Include="System.Xml" />
     <Reference Include="Microsoft.CSharp" />
       <Generator>MSBuild:Compile</Generator>
       <SubType>Designer</SubType>
     </ApplicationDefinition>
+    <Compile Include="CommitNodeControl.xaml.cs">
+      <DependentUpon>CommitNodeControl.xaml</DependentUpon>
+    </Compile>
     <Compile Include="ConnectionDirection.cs" />
     <Compile Include="Gui\ArrowLine.cs" />
     <Compile Include="Gui\ArrowLineBase.cs" />
       <DependentUpon>CircularNodeControl.xaml</DependentUpon>
     </Compile>
     <Compile Include="Logic\Tokenizer.cs" />
+    <Page Include="CommitNodeControl.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
     <Page Include="MainWindow.xaml">
       <Generator>MSBuild:Compile</Generator>
       <SubType>Designer</SubType>

GraphPad/Logic/GraphRenderer.cs

     class GraphRenderer
     {
         private Canvas canvas;
+        private readonly Func<Node, UserControl> controlBuilder;
+        private readonly double nodeWidth;
+        private readonly double nodeHeight;
         private const double nodePadding = 10.0;
-        private const double nodeWidth = 40.0;
-        private const double nodeHeight = 40.0;
 
-        public GraphRenderer(Canvas canvas)
+        public GraphRenderer(Canvas canvas, Func<Node,UserControl> controlBuilder, double nodeWidth, double nodeHeight)
         {
             this.canvas = canvas;
+            this.controlBuilder = controlBuilder;
+            this.nodeWidth = nodeWidth;
+            this.nodeHeight = nodeHeight;
         }
 
         public void Render(Graph graph)
             {
                 var left = node.GetColumn() * (nodePadding + nodeWidth);
                 var top = node.GetRow() * (nodePadding + nodeHeight);
-                var nodeControl = CreateNodeControl(left, top, node.Name);
+                var nodeControl = controlBuilder(node);
+                nodeControl.SetValue(Canvas.LeftProperty, left);
+                nodeControl.SetValue(Canvas.TopProperty, top);
                 canvas.Children.Add(nodeControl);
                 node.MetaData["Control"] = nodeControl;
             }
             return line;
         }
 
-        private static UserControl CreateNodeControl(double left, double top, string name)
-        {
-            var nodeControl = new CircularNodeControl();
-            nodeControl.SetValue(Canvas.LeftProperty, left);
-            nodeControl.SetValue(Canvas.TopProperty, top);
-            nodeControl.NodeName = name;
-            return nodeControl;
-        }
+
     }
 }

GraphPad/MainWindow.xaml.cs

         public MainWindow()
         {
             InitializeComponent();
-            this.graphText.TextChanged += new TextChangedEventHandler(graphText_TextChanged);
-            this.buttonGit.Click += new RoutedEventHandler(buttonGit_Click);
-            this.buttonMercurial.Click += new RoutedEventHandler(buttonMercurial_Click);
+            graphText.TextChanged += graphText_TextChanged;
+            buttonGit.Click += buttonGit_Click;
+            buttonMercurial.Click += buttonMercurial_Click;
         }
 
         void buttonMercurial_Click(object sender, RoutedEventArgs e)
 
         private void RedrawGraph(Graph graph)
         {
-            GraphRenderer renderer = new GraphRenderer(graphCanvas);
+            GraphRenderer renderer = new GraphRenderer(graphCanvas, CreateCircleNodeControl, 40, 40);
             GraphLayoutEngine layout = new GraphLayoutEngine();
             layout.Layout(graph);
             renderer.Render(graph);
         }
+
+        private static UserControl CreateCircleNodeControl(Node node)
+        {
+            var nodeControl = new CircularNodeControl();
+            nodeControl.NodeName = node.Name;
+            return nodeControl;
+        }
     }
 }

graphpad/CommitNodeControl.xaml

+<UserControl x:Class="GraphPad.CommitNodeControl"
+             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" 
+             mc:Ignorable="d" 
+             d:DesignHeight="100" d:DesignWidth="300" x:Name="root">
+    <Border  CornerRadius="5" BorderThickness="2" BorderBrush="Black">
+        <Border.Background>
+            <LinearGradientBrush EndPoint="0,1">
+                <GradientStop Offset="0" Color="#60FF60"></GradientStop>
+                <GradientStop Offset="1" Color="#009F00"></GradientStop>
+            </LinearGradientBrush>
+        </Border.Background>
+        <StackPanel>
+            <TextBlock FontWeight="Bold" Text="{Binding Path=UserName, ElementName=root}" FontSize="20"  />
+            <TextBlock Text="{Binding Path=UserName, ElementName=root}" FontSize="20"  />
+        </StackPanel>
+    </Border>
+
+</UserControl>

graphpad/CommitNodeControl.xaml.cs

+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+
+namespace GraphPad
+{
+    /// <summary>
+    /// Interaction logic for CommitNodeControl.xaml
+    /// </summary>
+    public partial class CommitNodeControl : UserControl
+    {
+        public CommitNodeControl()
+        {
+            InitializeComponent();
+        }
+        public string CommitId
+        {
+            get { return (string)GetValue(CommitIdProperty); }
+            set { SetValue(CommitIdProperty, value); }
+        }
+
+        public static readonly DependencyProperty CommitIdProperty =
+            DependencyProperty.Register("CommitId", typeof(string), typeof(CommitNodeControl), new UIPropertyMetadata("f178a4234"));
+
+        public string UserName
+        {
+            get { return (string)GetValue(UserNameProperty); }
+            set { SetValue(UserNameProperty, value); }
+        }
+
+        public static readonly DependencyProperty UserNameProperty =
+            DependencyProperty.Register("UserName", typeof(string), typeof(CommitNodeControl), new UIPropertyMetadata("Mark Heath"));
+
+
+
+    }
+}