Browse Source

RectangleCorners

pull/478/head
Peter Forstmeier 12 years ago
parent
commit
6c506d4382
  1. 119
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/DesignableItems/BaseRectangleItem.cs
  2. 4
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/TypeProvider/RectangleItemTypeProvider.cs
  3. 5
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Items/Graphics/BaseRectangleItem.cs
  4. 1
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/PageBuilder/ExportColumns/ExportRectangle.cs
  5. 1
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Wpf/Visitor/WpfVisitor.cs

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

@ -9,6 +9,7 @@ @@ -9,6 +9,7 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using ICSharpCode.Reporting.Addin.DesignableItems;
using ICSharpCode.Reporting.Addin.Designer;
using ICSharpCode.Reporting.Addin.TypeProvider;
@ -22,6 +23,8 @@ namespace ICSharpCode.Reporting.Addin.DesignableItems @@ -22,6 +23,8 @@ namespace ICSharpCode.Reporting.Addin.DesignableItems
[Designer(typeof(ContainerDesigner))]
class BaseRectangleItem:AbstractGraphicItem
{
int cornerRadius = 1;
public BaseRectangleItem()
{
TypeDescriptor.AddProvider(new RectangleItemTypeProvider(), typeof(BaseRectangleItem));
@ -38,10 +41,122 @@ namespace ICSharpCode.Reporting.Addin.DesignableItems @@ -38,10 +41,122 @@ namespace ICSharpCode.Reporting.Addin.DesignableItems
ClientRectangle.Right -1,
ClientRectangle.Bottom -1);
using (var pen = new Pen(ForeColor,Thickness)) {
graphics.DrawRectangle(pen,rect);
var path = RoundedRectangle.Create(rect,CornerRadius,
RoundedRectangle.RectangleCorners.All);
using (var pen = new Pen(this.ForeColor,Thickness)) {
graphics.DrawPath(pen, path);
}
}
[Category("Appearance")]
public int CornerRadius {
get { return cornerRadius; }
set {
cornerRadius = value;
Invalidate();
}
}
}
static class RoundedRectangle
{
public enum RectangleCorners
{
None = 0, TopLeft = 1, TopRight = 2, BottomLeft = 4, BottomRight = 8,
All = TopLeft | TopRight | BottomLeft | BottomRight
}
public static GraphicsPath Create(int x, int y, int width, int height,
int radius, RectangleCorners corners)
{
int xw = x + width;
int yh = y + height;
int xwr = xw - radius;
int yhr = yh - radius;
int xr = x + radius;
int yr = y + radius;
int r2 = radius * 2;
int xwr2 = xw - r2;
int yhr2 = yh - r2;
var p = new GraphicsPath();
p.StartFigure();
//Top Left Corner
if ((RectangleCorners.TopLeft & corners) == RectangleCorners.TopLeft)
{
p.AddArc(x, y, r2, r2, 180, 90);
}
else
{
p.AddLine(x, yr, x, y);
p.AddLine(x, y, xr, y);
}
//Top Edge
p.AddLine(xr, y, xwr, y);
//Top Right Corner
if ((RectangleCorners.TopRight & corners) == RectangleCorners.TopRight)
{
p.AddArc(xwr2, y, r2, r2, 270, 90);
}
else
{
p.AddLine(xwr, y, xw, y);
p.AddLine(xw, y, xw, yr);
}
//Right Edge
p.AddLine(xw, yr, xw, yhr);
//Bottom Right Corner
if ((RectangleCorners.BottomRight & corners) == RectangleCorners.BottomRight)
{
p.AddArc(xwr2, yhr2, r2, r2, 0, 90);
}
else
{
p.AddLine(xw, yhr, xw, yh);
p.AddLine(xw, yh, xwr, yh);
}
//Bottom Edge
p.AddLine(xwr, yh, xr, yh);
//Bottom Left Corner
if ((RectangleCorners.BottomLeft & corners) == RectangleCorners.BottomLeft)
{
p.AddArc(x, yhr2, r2, r2, 90, 90);
}
else
{
p.AddLine(xr, yh, x, yh);
p.AddLine(x, yh, x, yhr);
}
//Left Edge
p.AddLine(x, yhr, x, yr);
p.CloseFigure();
return p;
}
public static GraphicsPath Create(Rectangle rect, int radius, RectangleCorners c)
{ return Create(rect.X, rect.Y, rect.Width, rect.Height, radius, c); }
public static GraphicsPath Create(int x, int y, int width, int height, int radius)
{ return Create(x, y, width, height, radius, RectangleCorners.All); }
public static GraphicsPath Create(Rectangle rect, int radius)
{ return Create(rect.X, rect.Y, rect.Width, rect.Height, radius); }
public static GraphicsPath Create(int x, int y, int width, int height)
{ return Create(x, y, width, height, 5); }
public static GraphicsPath Create(Rectangle rect)
{ return Create(rect.X, rect.Y, rect.Width, rect.Height); }
}
}

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

@ -55,8 +55,8 @@ namespace ICSharpCode.Reporting.Addin.TypeProvider @@ -55,8 +55,8 @@ namespace ICSharpCode.Reporting.Addin.TypeProvider
PropertyDescriptor prop = null;
// prop = props.Find("CornerRadius",true);
// allProperties.Add(prop);
prop = props.Find("CornerRadius",true);
allProperties.Add(prop);
prop = props.Find("Controls",true);
allProperties.Add(prop);

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

@ -31,6 +31,7 @@ namespace ICSharpCode.Reporting.Items @@ -31,6 +31,7 @@ namespace ICSharpCode.Reporting.Items
public BaseRectangleItem()
{
Items = new List<IPrintableObject>();
CornerRadius = 0;
}
@ -43,13 +44,15 @@ namespace ICSharpCode.Reporting.Items @@ -43,13 +44,15 @@ namespace ICSharpCode.Reporting.Items
ex.Size = Size;
ex.DesiredSize = Size;
ex.Thickness = Thickness;
ex.CornerRadius = CornerRadius;
ex.DashStyle = DashStyle;
ex.StartLineCap = StartLineCap;
ex.EndLineCap = EndLineCap;
return ex;
}
public int CornerRadius { get; set; }
public List<IPrintableObject> Items {get;private set;}
}

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

@ -26,6 +26,7 @@ namespace ICSharpCode.Reporting.PageBuilder.ExportColumns @@ -26,6 +26,7 @@ namespace ICSharpCode.Reporting.PageBuilder.ExportColumns
/// </summary>
public class ExportRectangle:GraphicsContainer,IExportGraphics
{
public int CornerRadius { get; set; }
public DashStyle DashStyle {get;set;}

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

@ -138,6 +138,7 @@ namespace ICSharpCode.Reporting.WpfReportViewer.Visitor @@ -138,6 +138,7 @@ namespace ICSharpCode.Reporting.WpfReportViewer.Visitor
public override void Visit(ExportRectangle exportRectangle)
{
var border = CreateBorder(exportRectangle);
border.CornerRadius = new CornerRadius(Convert.ToDouble(exportRectangle.CornerRadius));
CanvasHelper.SetPosition(border, new Point(0,0));
var panel = new StackPanel();
panel.Orientation = Orientation.Horizontal;

Loading…
Cancel
Save