Skip to content

Commit 7058cf7

Browse files
committed
Simplified some code
1 parent 454caac commit 7058cf7

16 files changed

+144
-397
lines changed

Graph/Graph.csproj

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
</PropertyGroup>
3333
<ItemGroup>
3434
<Reference Include="System" />
35-
<Reference Include="System.ComponentModel.Composition" />
3635
<Reference Include="System.Core" />
3736
<Reference Include="System.Drawing" />
3837
<Reference Include="System.Windows.Forms" />
@@ -50,8 +49,6 @@
5049
<Compile Include="GraphControl.Designer.cs">
5150
<DependentUpon>GraphControl.cs</DependentUpon>
5251
</Compile>
53-
<Compile Include="INodeItemDescription.cs" />
54-
<Compile Include="INodeItemRenderer.cs" />
5552
<Compile Include="Items\NodeCheckboxItem.cs" />
5653
<Compile Include="Items\NodeColorItem.cs" />
5754
<Compile Include="Items\NodeImageItem.cs" />
@@ -62,8 +59,6 @@
6259
<Compile Include="NodeConnection.cs" />
6360
<Compile Include="NodeConnector.cs" />
6461
<Compile Include="NodeItem.cs" />
65-
<Compile Include="NodeItemDescriptionAttribute.cs" />
66-
<Compile Include="NodeItemRenderer.cs" />
6762
<Compile Include="NodeUtility.cs" />
6863
<Compile Include="Properties\AssemblyInfo.cs" />
6964
<Compile Include="RenderState.cs" />

Graph/INodeItemDescription.cs

Lines changed: 0 additions & 34 deletions
This file was deleted.

Graph/INodeItemRenderer.cs

Lines changed: 0 additions & 39 deletions
This file was deleted.

Graph/Items/NodeCheckboxItem.cs

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -72,46 +72,39 @@ public override bool OnClick()
7272
}
7373

7474
internal SizeF TextSize;
75-
}
7675

77-
[NodeItemDescription(typeof(NodeCheckboxItem))]
78-
public class NodeCheckboxRenderer : NodeItemRenderer<NodeCheckboxItem>
79-
{
80-
public override SizeF Measure(IDeviceContext context, SizeF minimumSize, NodeCheckboxItem item)
76+
77+
internal override SizeF Measure(IDeviceContext context)
8178
{
82-
if (!string.IsNullOrWhiteSpace(item.Text))
79+
if (!string.IsNullOrWhiteSpace(this.Text))
8380
{
84-
if (item.TextSize.IsEmpty)
81+
if (this.TextSize.IsEmpty)
8582
{
8683
var size = new Size(GraphConstants.MinimumItemWidth, GraphConstants.MinimumItemHeight);
8784

88-
item.TextSize = TextRenderer.MeasureText(context, item.Text, SystemFonts.MenuFont, size, GraphConstants.CenterTextFlags);
85+
this.TextSize = TextRenderer.MeasureText(context, this.Text, SystemFonts.MenuFont, size, GraphConstants.CenterTextFlags);
8986

90-
item.TextSize.Width = Math.Max(size.Width, item.TextSize.Width);
91-
item.TextSize.Height = Math.Max(size.Height, item.TextSize.Height);
87+
this.TextSize.Width = Math.Max(size.Width, this.TextSize.Width);
88+
this.TextSize.Height = Math.Max(size.Height, this.TextSize.Height);
9289
}
9390

94-
var measuredSize = item.TextSize;
95-
measuredSize.Width = Math.Max(minimumSize.Width, measuredSize.Width);
96-
measuredSize.Height = Math.Max(minimumSize.Height, measuredSize.Height);
97-
return measuredSize;
91+
return this.TextSize;
9892
} else
9993
{
100-
var measuredSize = new SizeF(GraphConstants.MinimumItemWidth, GraphConstants.TitleHeight + GraphConstants.TopHeight);
101-
measuredSize.Width = Math.Max(minimumSize.Width, measuredSize.Width);
102-
measuredSize.Height = Math.Max(minimumSize.Height, measuredSize.Height);
103-
return measuredSize;
94+
return new SizeF(GraphConstants.MinimumItemWidth, GraphConstants.TitleHeight + GraphConstants.TopHeight);
10495
}
10596
}
10697

107-
public override void Render(Graphics graphics, SizeF minimumSize, NodeCheckboxItem item, PointF location)
98+
internal override void Render(Graphics graphics, SizeF minimumSize, PointF location)
10899
{
109-
var size = Measure(graphics, minimumSize, item);
100+
var size = Measure(graphics);
101+
size.Width = Math.Max(minimumSize.Width, size.Width);
102+
size.Height = Math.Max(minimumSize.Height, size.Height);
110103

111104
using (var path = NodeUtility.CreateRoundedRectangle(size, location))
112105
{
113106
var rect = new RectangleF(location, size);
114-
if (item.Checked)
107+
if (this.Checked)
115108
{
116109
using (var brush = new SolidBrush(Color.FromArgb(128+32, Color.White)))
117110
{
@@ -124,9 +117,9 @@ public override void Render(Graphics graphics, SizeF minimumSize, NodeCheckboxIt
124117
graphics.FillPath(brush, path);
125118
}
126119
}
127-
graphics.DrawString(item.Text, SystemFonts.MenuFont, Brushes.Black, rect, GraphConstants.CenterTextStringFormat);
120+
graphics.DrawString(this.Text, SystemFonts.MenuFont, Brushes.Black, rect, GraphConstants.CenterTextStringFormat);
128121

129-
if (item.Hover)
122+
if (this.Hover)
130123
graphics.DrawPath(Pens.White, path);
131124
else
132125
graphics.DrawPath(Pens.Black, path);

Graph/Items/NodeColorItem.cs

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -63,55 +63,49 @@ public override bool OnClick()
6363
Clicked(this, new NodeItemEventArgs(this));
6464
return true;
6565
}
66-
}
6766

68-
[NodeItemDescription(typeof(NodeColorItem))]
69-
public class NodeColorRenderer : NodeItemRenderer<NodeColorItem>
70-
{
67+
7168
const int ColorBoxSize = 16;
7269
const int Spacing = 2;
73-
public override SizeF Measure(IDeviceContext context, SizeF minimumSize, NodeColorItem item)
70+
71+
internal override SizeF Measure(IDeviceContext context)
7472
{
75-
if (!string.IsNullOrWhiteSpace(item.Text))
73+
if (!string.IsNullOrWhiteSpace(this.Text))
7674
{
77-
if (item.TextSize.IsEmpty)
75+
if (this.TextSize.IsEmpty)
7876
{
7977
var size = new Size(GraphConstants.MinimumItemWidth, GraphConstants.MinimumItemHeight);
8078

81-
if (item.Input.Enabled != item.Output.Enabled)
79+
if (this.Input.Enabled != this.Output.Enabled)
8280
{
83-
if (item.Input.Enabled)
84-
item.TextSize = TextRenderer.MeasureText(context, item.Text, SystemFonts.MenuFont, size, GraphConstants.LeftTextFlags);
81+
if (this.Input.Enabled)
82+
this.TextSize = TextRenderer.MeasureText(context, this.Text, SystemFonts.MenuFont, size, GraphConstants.LeftTextFlags);
8583
else
86-
item.TextSize = TextRenderer.MeasureText(context, item.Text, SystemFonts.MenuFont, size, GraphConstants.RightTextFlags);
84+
this.TextSize = TextRenderer.MeasureText(context, this.Text, SystemFonts.MenuFont, size, GraphConstants.RightTextFlags);
8785
} else
88-
item.TextSize = TextRenderer.MeasureText(context, item.Text, SystemFonts.MenuFont, size, GraphConstants.CenterTextFlags);
86+
this.TextSize = TextRenderer.MeasureText(context, this.Text, SystemFonts.MenuFont, size, GraphConstants.CenterTextFlags);
8987

90-
item.TextSize.Width = Math.Max(size.Width, item.TextSize.Width + ColorBoxSize + Spacing);
91-
item.TextSize.Height = Math.Max(size.Height, item.TextSize.Height);
88+
this.TextSize.Width = Math.Max(size.Width, this.TextSize.Width + ColorBoxSize + Spacing);
89+
this.TextSize.Height = Math.Max(size.Height, this.TextSize.Height);
9290
}
93-
var measuredSize = item.TextSize;
94-
measuredSize.Width = Math.Max(minimumSize.Width, measuredSize.Width);
95-
measuredSize.Height = Math.Max(minimumSize.Height, measuredSize.Height);
96-
return measuredSize;
91+
return this.TextSize;
9792
} else
9893
{
99-
var measuredSize = new SizeF(GraphConstants.MinimumItemWidth, GraphConstants.TitleHeight + GraphConstants.TopHeight);
100-
measuredSize.Width = Math.Max(minimumSize.Width, measuredSize.Width);
101-
measuredSize.Height = Math.Max(minimumSize.Height, measuredSize.Height);
102-
return measuredSize;
94+
return new SizeF(GraphConstants.MinimumItemWidth, GraphConstants.TitleHeight + GraphConstants.TopHeight);
10395
}
10496
}
10597

106-
public override void Render(Graphics graphics, SizeF minimumSize, NodeColorItem item, PointF location)
98+
internal override void Render(Graphics graphics, SizeF minimumSize, PointF location)
10799
{
108-
var size = Measure(graphics, minimumSize, item);
100+
var size = Measure(graphics);
101+
size.Width = Math.Max(minimumSize.Width, size.Width);
102+
size.Height = Math.Max(minimumSize.Height, size.Height);
109103

110104
var alignment = HorizontalAlignment.Center;
111105
var format = GraphConstants.CenterTextStringFormat;
112-
if (item.Input.Enabled != item.Output.Enabled)
106+
if (this.Input.Enabled != this.Output.Enabled)
113107
{
114-
if (item.Input.Enabled)
108+
if (this.Input.Enabled)
115109
{
116110
alignment = HorizontalAlignment.Left;
117111
format = GraphConstants.LeftTextStringFormat;
@@ -141,26 +135,24 @@ public override void Render(Graphics graphics, SizeF minimumSize, NodeColorItem
141135
break;
142136
}
143137

144-
graphics.DrawString(item.Text, SystemFonts.MenuFont, Brushes.Black, rect, format);
138+
graphics.DrawString(this.Text, SystemFonts.MenuFont, Brushes.Black, rect, format);
145139

146140
using (var path = NodeUtility.CreateRoundedRectangle(colorBox.Size, colorBox.Location))
147141
{
148-
using (var brush = new SolidBrush(item.Color))
142+
using (var brush = new SolidBrush(this.Color))
149143
{
150144
graphics.FillPath(brush, path);
151145
}
152-
if (item.Hover)
146+
if (this.Hover)
153147
graphics.DrawPath(Pens.White, path);
154148
else
155149
graphics.DrawPath(Pens.Black, path);
156150
}
157-
/*
158-
using (var brush = new SolidBrush(item.Color))
159-
{
160-
graphics.FillRectangle(brush, colorBox.X, colorBox.Y, colorBox.Width, colorBox.Height);
161-
}
162-
graphics.DrawRectangle(Pens.Black, colorBox.X, colorBox.Y, colorBox.Width, colorBox.Height);
163-
*/
151+
//using (var brush = new SolidBrush(this.Color))
152+
//{
153+
// graphics.FillRectangle(brush, colorBox.X, colorBox.Y, colorBox.Width, colorBox.Height);
154+
//}
155+
//graphics.DrawRectangle(Pens.Black, colorBox.X, colorBox.Y, colorBox.Width, colorBox.Height);
164156
}
165157
}
166158
}

Graph/Items/NodeImageItem.cs

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -51,73 +51,66 @@ public override bool OnClick()
5151
Clicked(this, new NodeItemEventArgs(this));
5252
return true;
5353
}
54-
}
5554

56-
[NodeItemDescription(typeof(NodeImageItem))]
57-
public class NodeImageRenderer : NodeItemRenderer<NodeImageItem>
58-
{
59-
public override SizeF Measure(IDeviceContext context, SizeF minimumSize, NodeImageItem item)
55+
56+
internal override SizeF Measure(IDeviceContext context)
6057
{
61-
if (item.Image != null)
58+
if (this.Image != null)
6259
{
6360
SizeF size = new Size(GraphConstants.MinimumItemWidth, GraphConstants.MinimumItemHeight);
6461

65-
if (item.Width.HasValue)
66-
size.Width = Math.Max(size.Width, item.Width.Value + 2);
62+
if (this.Width.HasValue)
63+
size.Width = Math.Max(size.Width, this.Width.Value + 2);
6764
else
68-
size.Width = Math.Max(size.Width, item.Image.Width + 2);
65+
size.Width = Math.Max(size.Width, this.Image.Width + 2);
6966

70-
if (item.Height.HasValue)
71-
size.Height = Math.Max(size.Height, item.Height.Value + 2);
67+
if (this.Height.HasValue)
68+
size.Height = Math.Max(size.Height, this.Height.Value + 2);
7269
else
73-
size.Height = Math.Max(size.Height, item.Image.Height + 2);
70+
size.Height = Math.Max(size.Height, this.Image.Height + 2);
7471

75-
var measuredSize = size;
76-
measuredSize.Width = Math.Max(minimumSize.Width, measuredSize.Width);
77-
measuredSize.Height = Math.Max(minimumSize.Height, measuredSize.Height);
78-
return measuredSize;
72+
return size;
7973
} else
8074
{
8175
var size = new SizeF(GraphConstants.MinimumItemWidth, GraphConstants.MinimumItemHeight);
82-
if (item.Width.HasValue)
83-
size.Width = Math.Max(size.Width, item.Width.Value + 2);
76+
if (this.Width.HasValue)
77+
size.Width = Math.Max(size.Width, this.Width.Value + 2);
8478

85-
if (item.Height.HasValue)
86-
size.Height = Math.Max(size.Height, item.Height.Value + 2);
79+
if (this.Height.HasValue)
80+
size.Height = Math.Max(size.Height, this.Height.Value + 2);
8781

88-
var measuredSize = size;
89-
measuredSize.Width = Math.Max(minimumSize.Width, measuredSize.Width);
90-
measuredSize.Height = Math.Max(minimumSize.Height, measuredSize.Height);
91-
return measuredSize;
82+
return size;
9283
}
9384
}
9485

95-
public override void Render(Graphics graphics, SizeF minimumSize, NodeImageItem item, PointF location)
86+
internal override void Render(Graphics graphics, SizeF minimumSize, PointF location)
9687
{
97-
var size = Measure(graphics, minimumSize, item);
88+
var size = Measure(graphics);
89+
size.Width = Math.Max(minimumSize.Width, size.Width);
90+
size.Height = Math.Max(minimumSize.Height, size.Height);
9891

99-
if (item.Width.HasValue &&
100-
size.Width > item.Width.Value)
92+
if (this.Width.HasValue &&
93+
size.Width > this.Width.Value)
10194
{
102-
location.X += (size.Width - (item.Width.Value + 2)) / 2.0f;
103-
size.Width = (item.Width.Value + 2);
95+
location.X += (size.Width - (this.Width.Value + 2)) / 2.0f;
96+
size.Width = (this.Width.Value + 2);
10497
}
10598
var rect = new RectangleF(location, size);
10699

107-
if (item.Image != null)
100+
if (this.Image != null)
108101
{
109102
rect.Width -= 2;
110103
rect.Height -= 2;
111104
rect.X++;
112105
rect.Y++;
113-
graphics.DrawImage(item.Image, rect);
106+
graphics.DrawImage(this.Image, rect);
114107
rect.Width += 2;
115108
rect.Height += 2;
116109
rect.X--;
117110
rect.Y--;
118111
}
119112

120-
if (item.Hover)
113+
if (this.Hover)
121114
graphics.DrawRectangle(Pens.White, rect.Left, rect.Top, rect.Width, rect.Height);
122115
else
123116
graphics.DrawRectangle(Pens.Black, rect.Left, rect.Top, rect.Width, rect.Height);

0 commit comments

Comments
 (0)