Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit 6c506d4

Browse files
RectangleCorners
1 parent 6f0ac58 commit 6c506d4

5 files changed

Lines changed: 125 additions & 5 deletions

File tree

src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/DesignableItems/BaseRectangleItem.cs

Lines changed: 117 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System;
1010
using System.ComponentModel;
1111
using System.Drawing;
12+
using System.Drawing.Drawing2D;
1213
using ICSharpCode.Reporting.Addin.DesignableItems;
1314
using ICSharpCode.Reporting.Addin.Designer;
1415
using ICSharpCode.Reporting.Addin.TypeProvider;
@@ -22,6 +23,8 @@ namespace ICSharpCode.Reporting.Addin.DesignableItems
2223
[Designer(typeof(ContainerDesigner))]
2324
class BaseRectangleItem:AbstractGraphicItem
2425
{
26+
int cornerRadius = 1;
27+
2528
public BaseRectangleItem()
2629
{
2730
TypeDescriptor.AddProvider(new RectangleItemTypeProvider(), typeof(BaseRectangleItem));
@@ -38,10 +41,122 @@ public override void Draw(Graphics graphics)
3841
ClientRectangle.Right -1,
3942
ClientRectangle.Bottom -1);
4043

41-
using (var pen = new Pen(ForeColor,Thickness)) {
42-
graphics.DrawRectangle(pen,rect);
44+
var path = RoundedRectangle.Create(rect,CornerRadius,
45+
RoundedRectangle.RectangleCorners.All);
46+
47+
using (var pen = new Pen(this.ForeColor,Thickness)) {
48+
graphics.DrawPath(pen, path);
49+
}
50+
}
51+
52+
53+
[Category("Appearance")]
54+
public int CornerRadius {
55+
get { return cornerRadius; }
56+
set {
57+
cornerRadius = value;
58+
Invalidate();
59+
}
60+
}
61+
}
62+
63+
static class RoundedRectangle
64+
{
65+
public enum RectangleCorners
66+
{
67+
None = 0, TopLeft = 1, TopRight = 2, BottomLeft = 4, BottomRight = 8,
68+
All = TopLeft | TopRight | BottomLeft | BottomRight
69+
}
70+
71+
public static GraphicsPath Create(int x, int y, int width, int height,
72+
int radius, RectangleCorners corners)
73+
{
74+
int xw = x + width;
75+
int yh = y + height;
76+
int xwr = xw - radius;
77+
int yhr = yh - radius;
78+
int xr = x + radius;
79+
int yr = y + radius;
80+
int r2 = radius * 2;
81+
int xwr2 = xw - r2;
82+
int yhr2 = yh - r2;
83+
84+
var p = new GraphicsPath();
85+
p.StartFigure();
86+
87+
//Top Left Corner
88+
if ((RectangleCorners.TopLeft & corners) == RectangleCorners.TopLeft)
89+
{
90+
p.AddArc(x, y, r2, r2, 180, 90);
4391
}
92+
else
93+
{
94+
p.AddLine(x, yr, x, y);
95+
p.AddLine(x, y, xr, y);
96+
}
97+
98+
//Top Edge
99+
p.AddLine(xr, y, xwr, y);
44100

101+
//Top Right Corner
102+
if ((RectangleCorners.TopRight & corners) == RectangleCorners.TopRight)
103+
{
104+
p.AddArc(xwr2, y, r2, r2, 270, 90);
105+
}
106+
else
107+
{
108+
p.AddLine(xwr, y, xw, y);
109+
p.AddLine(xw, y, xw, yr);
110+
}
111+
112+
//Right Edge
113+
p.AddLine(xw, yr, xw, yhr);
114+
115+
//Bottom Right Corner
116+
if ((RectangleCorners.BottomRight & corners) == RectangleCorners.BottomRight)
117+
{
118+
p.AddArc(xwr2, yhr2, r2, r2, 0, 90);
119+
}
120+
else
121+
{
122+
p.AddLine(xw, yhr, xw, yh);
123+
p.AddLine(xw, yh, xwr, yh);
124+
}
125+
126+
//Bottom Edge
127+
p.AddLine(xwr, yh, xr, yh);
128+
129+
//Bottom Left Corner
130+
if ((RectangleCorners.BottomLeft & corners) == RectangleCorners.BottomLeft)
131+
{
132+
p.AddArc(x, yhr2, r2, r2, 90, 90);
133+
}
134+
else
135+
{
136+
p.AddLine(xr, yh, x, yh);
137+
p.AddLine(x, yh, x, yhr);
138+
}
139+
140+
//Left Edge
141+
p.AddLine(x, yhr, x, yr);
142+
143+
p.CloseFigure();
144+
return p;
45145
}
146+
147+
public static GraphicsPath Create(Rectangle rect, int radius, RectangleCorners c)
148+
{ return Create(rect.X, rect.Y, rect.Width, rect.Height, radius, c); }
149+
150+
public static GraphicsPath Create(int x, int y, int width, int height, int radius)
151+
{ return Create(x, y, width, height, radius, RectangleCorners.All); }
152+
153+
public static GraphicsPath Create(Rectangle rect, int radius)
154+
{ return Create(rect.X, rect.Y, rect.Width, rect.Height, radius); }
155+
156+
public static GraphicsPath Create(int x, int y, int width, int height)
157+
{ return Create(x, y, width, height, 5); }
158+
159+
public static GraphicsPath Create(Rectangle rect)
160+
{ return Create(rect.X, rect.Y, rect.Width, rect.Height); }
46161
}
47162
}

src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/TypeProvider/RectangleItemTypeProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ public override PropertyDescriptorCollection GetProperties(Attribute[] attribute
5555

5656
PropertyDescriptor prop = null;
5757

58-
// prop = props.Find("CornerRadius",true);
59-
// allProperties.Add(prop);
58+
prop = props.Find("CornerRadius",true);
59+
allProperties.Add(prop);
6060

6161
prop = props.Find("Controls",true);
6262
allProperties.Add(prop);

src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Items/Graphics/BaseRectangleItem.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public class BaseRectangleItem:BaseGraphics,IReportContainer
3131
public BaseRectangleItem()
3232
{
3333
Items = new List<IPrintableObject>();
34+
CornerRadius = 0;
3435
}
3536

3637

@@ -43,13 +44,15 @@ public override IExportColumn CreateExportColumn()
4344
ex.Size = Size;
4445
ex.DesiredSize = Size;
4546
ex.Thickness = Thickness;
47+
ex.CornerRadius = CornerRadius;
4648
ex.DashStyle = DashStyle;
4749
ex.StartLineCap = StartLineCap;
4850
ex.EndLineCap = EndLineCap;
4951
return ex;
5052
}
5153

52-
54+
public int CornerRadius { get; set; }
55+
5356
public List<IPrintableObject> Items {get;private set;}
5457

5558
}

src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/PageBuilder/ExportColumns/ExportRectangle.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ namespace ICSharpCode.Reporting.PageBuilder.ExportColumns
2626
/// </summary>
2727
public class ExportRectangle:GraphicsContainer,IExportGraphics
2828
{
29+
public int CornerRadius { get; set; }
2930

3031
public DashStyle DashStyle {get;set;}
3132

src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Wpf/Visitor/WpfVisitor.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ public override void Visit(ExportLine exportGraphics)
138138
public override void Visit(ExportRectangle exportRectangle)
139139
{
140140
var border = CreateBorder(exportRectangle);
141+
border.CornerRadius = new CornerRadius(Convert.ToDouble(exportRectangle.CornerRadius));
141142
CanvasHelper.SetPosition(border, new Point(0,0));
142143
var panel = new StackPanel();
143144
panel.Orientation = Orientation.Horizontal;

0 commit comments

Comments
 (0)