Commits

Mark Heath  committed 3c117e9

Colour background for circular node control

  • Participants
  • Parent commits 26a34ef

Comments (0)

Files changed (6)

File GraphPad/CircularNodeControl.xaml

+<UserControl x:Class="GraphPad.CircularNodeControl"
+             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" 
+             Width="40" Height="40"
+             d:DesignHeight="40" d:DesignWidth="40">
+    <Grid ToolTip="This is a node">
+        <Ellipse Stroke="Black" StrokeThickness="2" x:Name="ellipse">
+            <Ellipse.Fill>
+                <LinearGradientBrush EndPoint="0,1">
+                    <GradientStop Offset="0" Color="#60FF60"></GradientStop>
+                    <GradientStop Offset="1" Color="#009F00"></GradientStop>
+                </LinearGradientBrush>
+            </Ellipse.Fill>
+        </Ellipse>
+        <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" FontWeight="Bold" Text="A" FontSize="20" x:Name="nodeNameTextBlock" />
+    </Grid>
+</UserControl>

File GraphPad/CircularNodeControl.xaml.cs

+using System;
+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;
+using System.ComponentModel;
+
+namespace GraphPad
+{
+    public interface INodeControl
+    {
+        Point GetConnectionPoint(ConnectionDirection connectionDirection);
+    }
+
+    /// <summary>
+    /// Interaction logic for Node.xaml
+    /// </summary>
+    public partial class CircularNodeControl : UserControl, INodeControl
+    {
+        public CircularNodeControl()
+        {
+            InitializeComponent();
+        }
+
+        public string NodeName
+        {
+            get { return (string)GetValue(NodeNameProperty); }
+            set { SetValue(NodeNameProperty, value); }
+        }
+
+        // Using a DependencyProperty as the backing store for NodeName.  This enables animation, styling, binding, etc...
+        public static readonly DependencyProperty NodeNameProperty =
+            DependencyProperty.Register("NodeName", typeof(string), typeof(CircularNodeControl), new UIPropertyMetadata("A", new PropertyChangedCallback(OnNodeNameChanged)));
+
+        private static void OnNodeNameChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args)
+        {
+            var node = (CircularNodeControl)sender;
+            node.nodeNameTextBlock.Text = (string)args.NewValue;
+        }
+
+        public Point GetConnectionPoint(ConnectionDirection connectionDirection)
+        {
+            var from = this;
+            var fromPosition = new Point((double)from.GetValue(Canvas.LeftProperty), (double)from.GetValue(Canvas.TopProperty));
+            
+            var radius = this.Width/2;
+            var corner = radius - Math.Sqrt((radius*radius)/2);
+
+            switch (connectionDirection)
+            {
+                case ConnectionDirection.West:
+                    return new Point(fromPosition.X, fromPosition.Y + from.Height / 2);
+                case ConnectionDirection.East:
+                    return new Point(fromPosition.X + from.Width, fromPosition.Y + from.Height/2);
+                case ConnectionDirection.North:
+                    return new Point(fromPosition.X + from.Width / 2, fromPosition.Y);
+                case ConnectionDirection.South:
+                    return new Point(fromPosition.X + from.Width / 2, fromPosition.Y + from.Height);
+                case ConnectionDirection.NorthWest:
+                    return new Point(fromPosition.X + corner, fromPosition.Y + corner);
+                case ConnectionDirection.SouthWest:
+                    return new Point(fromPosition.X + corner, fromPosition.Y + from.Height - corner);
+                case ConnectionDirection.NorthEast:
+                    return new Point(fromPosition.X + from.Width - corner, fromPosition.Y + corner);
+                case ConnectionDirection.SouthEast:
+                    return new Point(fromPosition.X + from.Width - corner, fromPosition.Y + from.Height - corner);
+                default:
+                    throw new ArgumentException("Invalid connection direction");
+            }
+        }
+    }
+}

File GraphPad/GraphPad.csproj

     <Compile Include="Logic\IDictionary.cs" />
     <Compile Include="Logic\Node.cs" />
     <Compile Include="Logic\RelationshipType.cs" />
-    <Compile Include="NodeControl.xaml.cs">
-      <DependentUpon>NodeControl.xaml</DependentUpon>
+    <Compile Include="CircularNodeControl.xaml.cs">
+      <DependentUpon>CircularNodeControl.xaml</DependentUpon>
     </Compile>
     <Compile Include="Logic\Tokenizer.cs" />
     <Page Include="MainWindow.xaml">
       <DependentUpon>MainWindow.xaml</DependentUpon>
       <SubType>Code</SubType>
     </Compile>
-    <Page Include="NodeControl.xaml">
+    <Page Include="CircularNodeControl.xaml">
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
     </Page>

File GraphPad/Logic/GraphRenderer.cs

 
         private static UserControl CreateNodeControl(double left, double top, string name)
         {
-            var nodeControl = new NodeControl();
+            var nodeControl = new CircularNodeControl();
             nodeControl.SetValue(Canvas.LeftProperty, left);
             nodeControl.SetValue(Canvas.TopProperty, top);
             nodeControl.NodeName = name;

File GraphPad/NodeControl.xaml

-<UserControl x:Class="GraphPad.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" 
-             mc:Ignorable="d" 
-             Width="40" Height="40"
-             d:DesignHeight="40" d:DesignWidth="40">
-    <Grid ToolTip="This is a node">
-        <Ellipse Stroke="Black" StrokeThickness="2" x:Name="ellipse" Fill="White" />
-        <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" FontWeight="Bold" Text="A" FontSize="20" x:Name="nodeNameTextBlock" />
-    </Grid>
-</UserControl>

File GraphPad/NodeControl.xaml.cs

-using System;
-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;
-using System.ComponentModel;
-
-namespace GraphPad
-{
-    public interface INodeControl
-    {
-        Point GetConnectionPoint(ConnectionDirection connectionDirection);
-    }
-
-    /// <summary>
-    /// Interaction logic for Node.xaml
-    /// </summary>
-    public partial class NodeControl : UserControl, INodeControl
-    {
-        public NodeControl()
-        {
-            InitializeComponent();
-        }
-
-        public string NodeName
-        {
-            get { return (string)GetValue(NodeNameProperty); }
-            set { SetValue(NodeNameProperty, value); }
-        }
-
-        // Using a DependencyProperty as the backing store for NodeName.  This enables animation, styling, binding, etc...
-        public static readonly DependencyProperty NodeNameProperty =
-            DependencyProperty.Register("NodeName", typeof(string), typeof(NodeControl), new UIPropertyMetadata("A", new PropertyChangedCallback(OnNodeNameChanged)));
-
-        private static void OnNodeNameChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args)
-        {
-            var node = (NodeControl)sender;
-            node.nodeNameTextBlock.Text = (string)args.NewValue;
-        }
-
-        public Point GetConnectionPoint(ConnectionDirection connectionDirection)
-        {
-            var from = this;
-            var fromPosition = new Point((double)from.GetValue(Canvas.LeftProperty), (double)from.GetValue(Canvas.TopProperty));
-            
-            var radius = this.Width/2;
-            var corner = radius - Math.Sqrt((radius*radius)/2);
-
-            switch (connectionDirection)
-            {
-                case ConnectionDirection.West:
-                    return new Point(fromPosition.X, fromPosition.Y + from.Height / 2);
-                case ConnectionDirection.East:
-                    return new Point(fromPosition.X + from.Width, fromPosition.Y + from.Height/2);
-                case ConnectionDirection.North:
-                    return new Point(fromPosition.X + from.Width / 2, fromPosition.Y);
-                case ConnectionDirection.South:
-                    return new Point(fromPosition.X + from.Width / 2, fromPosition.Y + from.Height);
-                case ConnectionDirection.NorthWest:
-                    return new Point(fromPosition.X + corner, fromPosition.Y + corner);
-                case ConnectionDirection.SouthWest:
-                    return new Point(fromPosition.X + corner, fromPosition.Y + from.Height - corner);
-                case ConnectionDirection.NorthEast:
-                    return new Point(fromPosition.X + from.Width - corner, fromPosition.Y + corner);
-                case ConnectionDirection.SouthEast:
-                    return new Point(fromPosition.X + from.Width - corner, fromPosition.Y + from.Height - corner);
-                default:
-                    throw new ArgumentException("Invalid connection direction");
-            }
-        }
-    }
-}