Browse Source

Rectangle with rounded corners.

pull/14/head
peterforstmeier 15 years ago
parent
commit
df7f687ebd
  1. 9
      src/AddIns/Misc/Reports/ICSharpCode.Reports.Addin/Project/ReportItems/BaseCircleItem.cs
  2. 65
      src/AddIns/Misc/Reports/ICSharpCode.Reports.Addin/Project/ReportItems/BaseRectangleItem.cs
  3. 8
      src/AddIns/Misc/Reports/ICSharpCode.Reports.Addin/Project/ReportItems/RectangleItemTypeProvider.cs
  4. 1
      src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/ICSharpCode.Reports.Core.csproj
  5. 52
      src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/BaseItems/BaseGraphicItem.cs
  6. 20
      src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/BaseItems/Graphics/BaseLineItem.cs
  7. 26
      src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/BaseItems/Graphics/BaseRectangleItem.cs
  8. 35
      src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/Exporter/Decorators/RectangleDecorator.cs
  9. 1
      src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/Exporter/ExportColumns/BaseExportColumn.cs
  10. 14
      src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/Exporter/ExportColumns/ExportGraphic.cs
  11. 1
      src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/Printing/Graphics/BaseLine.cs
  12. 3
      src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/Printing/Graphics/BaseShape.cs
  13. 65
      src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/Printing/Graphics/RectangleShape.cs

9
src/AddIns/Misc/Reports/ICSharpCode.Reports.Addin/Project/ReportItems/BaseCircleItem.cs

@ -62,15 +62,6 @@ namespace ICSharpCode.Reports.Addin @@ -62,15 +62,6 @@ namespace ICSharpCode.Reports.Addin
}
private BaseLine Baseline()
{
if (this.BackColor == GlobalValues.DefaultBackColor) {
return new BaseLine (this.ForeColor,this.DashStyle,this.Thickness);
} else {
return new BaseLine (this.BackColor,this.DashStyle,this.Thickness);
}
}
[Browsable(true),
Category("Appearance"),

65
src/AddIns/Misc/Reports/ICSharpCode.Reports.Addin/Project/ReportItems/BaseRectangleItem.cs

@ -22,13 +22,14 @@ namespace ICSharpCode.Reports.Addin @@ -22,13 +22,14 @@ namespace ICSharpCode.Reports.Addin
private DashStyle dashStyle;
private float thickness;
private int cornerRadius;
public BaseRectangleItem()
{
this.thickness = 1;
this.dashStyle = DashStyle.Solid;
this.Size = new Size(GlobalValues.PreferedSize.Width,2* GlobalValues.PreferedSize.Height);
cornerRadius = 1;
TypeDescriptor.AddProvider(new RectangleItemTypeProvider(), typeof(BaseRectangleItem));
}
@ -49,54 +50,62 @@ namespace ICSharpCode.Reports.Addin @@ -49,54 +50,62 @@ namespace ICSharpCode.Reports.Addin
}
Rectangle rect = new Rectangle(this.ClientRectangle.Left,this.ClientRectangle.Top,
this.ClientRectangle.Right -1,
this.ClientRectangle.Bottom -1);
backgroundShape.FillShape(graphics,
new SolidFillPattern(this.BackColor),
rect);
this.ClientRectangle.Right -1,
this.ClientRectangle.Bottom -1);
// backgroundShape.FillShape(graphics,
// new SolidFillPattern(this.BackColor),
// rect);
Border b = new Border(new BaseLine (this.ForeColor,System.Drawing.Drawing2D.DashStyle.Solid,1));
DrawFrame(graphics,b);
// DrawFrame(graphics,b);
BaseLine line = new BaseLine(base.ForeColor,DashStyle,Thickness,LineCap.Round,LineCap.Round,DashCap.Round);
using (Pen pen = line.CreatePen(line.Thickness)){
shape.CornerRadius = this.CornerRadius;
GraphicsPath path1 = shape.CreatePath(rect);
graphics.DrawPath(pen, path1);
}
shape.DrawShape (graphics,
this.Baseline(),
rect);
// shape.DrawShape (graphics,
// this.Baseline(),
// rect);
}
protected void DrawFrame (Graphics graphics,Border border) {
if (this.DrawBorder == true) {
border.DrawBorder(graphics,this.ClientRectangle);
}
}
private BaseLine Baseline()
{
if (this.BackColor == GlobalValues.DefaultBackColor) {
return new BaseLine (this.ForeColor,this.DashStyle,this.Thickness);
} else {
return new BaseLine (this.BackColor,this.DashStyle,this.Thickness);
}
}
[Browsable(true),
Category("Appearance"),
Description("Linestyle")]
public DashStyle DashStyle {
get { return dashStyle; }
set { dashStyle = value; }
set { dashStyle = value;
this.Invalidate();
}
}
[Browsable(true),
Category("Appearance"),
Description("Thickness of Line")]
public float Thickness {
get { return thickness; }
set { thickness = value; }
set { thickness = value;
this.Invalidate();
}
}
[Browsable(true),
Category("Appearance"),
Description("Radius of Corners")]
public int CornerRadius
{
get{return this.cornerRadius;}
set{this.cornerRadius = value;
this.Invalidate();
}
}
}
}

8
src/AddIns/Misc/Reports/ICSharpCode.Reports.Addin/Project/ReportItems/RectangleItemTypeProvider.cs

@ -57,15 +57,17 @@ namespace ICSharpCode.Reports.Addin @@ -57,15 +57,17 @@ namespace ICSharpCode.Reports.Addin
prop = props.Find("ForeColor",true);
allProperties.Add(prop);
prop = props.Find("DrawBorder",true);
allProperties.Add(prop);
// prop = props.Find("DrawBorder",true);
// allProperties.Add(prop);
//
prop = props.Find("DashStyle",true);
allProperties.Add(prop);
prop = props.Find("Thickness",true);
allProperties.Add(prop);
prop = props.Find("CornerRadius",true);
allProperties.Add(prop);
return new PropertyDescriptorCollection(allProperties.ToArray());
}
}

1
src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/ICSharpCode.Reports.Core.csproj

@ -137,6 +137,7 @@ @@ -137,6 +137,7 @@
<Compile Include="Project\Exceptions\WrongColumnException.cs" />
<Compile Include="Project\Exceptions\WrongSectionException.cs" />
<Compile Include="Project\Exporter\Converters\GroupedTableConverter.cs" />
<Compile Include="Project\Exporter\Decorators\RectangleDecorator.cs" />
<Compile Include="Project\Expressions\SimpleExpressionEvaluator\Compilation\Functions\ReportingService\FieldReference.cs" />
<Compile Include="Project\Exporter\BasePager.cs" />
<Compile Include="Project\Exporter\Converters\BaseConverter.cs" />

52
src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/BaseItems/BaseGraphicItem.cs

@ -19,12 +19,13 @@ namespace ICSharpCode.Reports.Core { @@ -19,12 +19,13 @@ namespace ICSharpCode.Reports.Core {
/// </remarks>
public class BaseGraphicItem : BaseReportItem {
private int thickness = 1;
private DashStyle dashStyle = DashStyle.Solid;
public BaseGraphicItem():base() {
public BaseGraphicItem():base()
{
this.Thickness = 1;
DashStyle = DashStyle.Solid;
}
protected IGraphicStyleDecorator CreateItemStyle (BaseShape shape) {
GraphicStyleDecorator style = new GraphicStyleDecorator(shape);
@ -34,8 +35,8 @@ namespace ICSharpCode.Reports.Core { @@ -34,8 +35,8 @@ namespace ICSharpCode.Reports.Core {
style.ForeColor = this.ForeColor;
style.FrameColor = this.FrameColor;
style.Thickness = this.thickness;
style.DashStyle = this.dashStyle;
style.Thickness = this.Thickness;
style.DashStyle = this.DashStyle;
return style;
}
@ -54,7 +55,8 @@ namespace ICSharpCode.Reports.Core { @@ -54,7 +55,8 @@ namespace ICSharpCode.Reports.Core {
return new BaseLine (this.BackColor,this.DashStyle,this.Thickness);
}
}
#region Overrides
public override string ToString()
@ -70,41 +72,9 @@ namespace ICSharpCode.Reports.Core { @@ -70,41 +72,9 @@ namespace ICSharpCode.Reports.Core {
/// Line Thickness of graphical Element
/// </summary>
public virtual int Thickness {
get {
return thickness;
}
set {
thickness = value;
}
}
public virtual DashStyle DashStyle {
get {
return dashStyle;
}
set {
dashStyle = value;
}
}
[XmlIgnoreAttribute]
[Browsable(false)]
public override bool DrawBorder {
get { return base.DrawBorder; }
set { base.DrawBorder = value; }
}
[XmlIgnoreAttribute]
[Browsable(false)]
public override Font Font {
get { return base.Font; }
set { base.Font = value; }
}
public virtual int Thickness {get;set;}
public virtual DashStyle DashStyle {get;set;}
#endregion
}

20
src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/BaseItems/Graphics/BaseLineItem.cs

@ -46,17 +46,17 @@ namespace ICSharpCode.Reports.Core { @@ -46,17 +46,17 @@ namespace ICSharpCode.Reports.Core {
private LineDecorator CreateLineShape ()
{
LineDecorator ld = new LineDecorator(this.shape);
ld.Size = this.Size;
ld.Location = this.Location;
ld.BackColor = this.BackColor;
ld.ForeColor = this.ForeColor;
LineDecorator decorator = new LineDecorator(this.shape);
decorator.Size = this.Size;
decorator.Location = this.Location;
decorator.BackColor = this.BackColor;
decorator.ForeColor = this.ForeColor;
ld.Thickness = base.Thickness;
ld.DashStyle = base.DashStyle;
ld.From = this.fromPoint;
ld.To = this.toPoint;
return ld;
decorator.Thickness = base.Thickness;
decorator.DashStyle = base.DashStyle;
decorator.From = this.fromPoint;
decorator.To = this.toPoint;
return decorator;
}

26
src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/BaseItems/Graphics/BaseRectangleItem.cs

@ -3,9 +3,12 @@ @@ -3,9 +3,12 @@
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using ICSharpCode.Reports.Core.BaseClasses.Printing;
using ICSharpCode.Reports.Core.Exporter;
/// <summary>
/// This class draws a Rectangle
/// </summary>
@ -14,7 +17,9 @@ using ICSharpCode.Reports.Core.Exporter; @@ -14,7 +17,9 @@ using ICSharpCode.Reports.Core.Exporter;
/// created on - 29.09.2005 11:57:30
/// </remarks>
namespace ICSharpCode.Reports.Core {
public class BaseRectangleItem : BaseGraphicItem,IExportColumnBuilder {
public class BaseRectangleItem : BaseGraphicItem,IExportColumnBuilder
{
RectangleShape shape = new RectangleShape();
@ -29,11 +34,13 @@ namespace ICSharpCode.Reports.Core { @@ -29,11 +34,13 @@ namespace ICSharpCode.Reports.Core {
#region IExportColumnBuilder
public BaseExportColumn CreateExportColumn(){
shape.CornerRadius = CornerRadius;
IGraphicStyleDecorator style = base.CreateItemStyle(this.shape);
ExportGraphic item = new ExportGraphic(style,false);
return item as ExportGraphic;
}
#endregion
public override void Render(ReportPageEventArgs rpea) {
@ -42,14 +49,23 @@ namespace ICSharpCode.Reports.Core { @@ -42,14 +49,23 @@ namespace ICSharpCode.Reports.Core {
}
base.Render(rpea);
Rectangle rect = base.DisplayRectangle;
StandardPrinter.FillBackground(rpea.PrintPageEventArgs.Graphics,this.BaseStyleDecorator);
shape.DrawShape (rpea.PrintPageEventArgs.Graphics,
base.Baseline(),
rect);
BaseLine line = new BaseLine(base.ForeColor,base.DashStyle,base.Thickness,LineCap.Round,LineCap.Round,DashCap.Round);
using (Pen pen = line.CreatePen(line.Thickness)){
if (pen != null)
{
shape.CornerRadius = this.CornerRadius;
GraphicsPath path1 = shape.CreatePath(rect);
rpea.PrintPageEventArgs.Graphics.DrawPath(pen, path1);
}
}
}
public int CornerRadius {get;set;}
public override string ToString() {
return "BaseRectangleItem";
}

35
src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/Exporter/Decorators/RectangleDecorator.cs

@ -0,0 +1,35 @@ @@ -0,0 +1,35 @@
/*
* Created by SharpDevelop.
* User: Peter Forstmeier
* Date: 30.12.2010
* Time: 19:41
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using ICSharpCode.Reports.Core.Exporter;
namespace ICSharpCode.Reports.Core.Exporter
{
/// <summary>
/// Description of RectangleDecorator.
/// </summary>
public class aaRectangleDecorator: GraphicStyleDecorator
{
public aaRectangleDecorator(BaseShape shape):base(shape)
{
}
private int corner;
public int CornerRadius {
get {
return corner;
}
set { corner = value; }
}
}
}

1
src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/Exporter/ExportColumns/BaseExportColumn.cs

@ -123,6 +123,7 @@ namespace ICSharpCode.Reports.Core.Exporter @@ -123,6 +123,7 @@ namespace ICSharpCode.Reports.Core.Exporter
iTextSharp.text.Rectangle r = (iTextSharp.text.Rectangle)rectangleConverter.ConvertTo(null,System.Globalization.CultureInfo.InvariantCulture,
this.styleDecorator.DisplayRectangle,
typeof(iTextSharp.text.Rectangle));
iTextSharp.text.Rectangle rr = new iTextSharp.text.Rectangle(r.Left,r.Bottom -2,
r.Left + r.Width,r.Bottom + r.Height);

14
src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/Exporter/ExportColumns/ExportGraphic.cs

@ -105,14 +105,14 @@ namespace ICSharpCode.Reports.Core.Exporter @@ -105,14 +105,14 @@ namespace ICSharpCode.Reports.Core.Exporter
if (lineDecorator != null) {
PdfLineDrawer ();
}
else {
else
{
// http://www.mikesdotnetting.com/Article/88/iTextSharp-Drawing-shapes-and-Graphics
IGraphicStyleDecorator style = base.StyleDecorator as GraphicStyleDecorator;
if (style != null) {
style.Shape.DrawShape(base.PdfWriter.DirectContent,
new BaseLine (style.ForeColor,style.DashStyle,style.Thickness),
style,
base.ConvertToPdfRectangle());
}
style.Shape.DrawShape(base.PdfWriter.DirectContent,
new BaseLine (style.ForeColor,style.DashStyle,style.Thickness),
style,
base.ConvertToPdfRectangle());
}
}

1
src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/Printing/Graphics/BaseLine.cs

@ -33,6 +33,7 @@ namespace ICSharpCode.Reports.Core @@ -33,6 +33,7 @@ namespace ICSharpCode.Reports.Core
{
}
public BaseLine(Color color, DashStyle dashStyle,float thickness, LineCap startLineCap, LineCap endLineCap, DashCap dashLineCap)
{
if (color == Color.White) {

3
src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/Printing/Graphics/BaseShape.cs

@ -86,7 +86,7 @@ namespace ICSharpCode.Reports.Core { @@ -86,7 +86,7 @@ namespace ICSharpCode.Reports.Core {
}
public void DrawShape(Graphics graphics, BaseLine line, Rectangle rectangle)
public virtual void DrawShape(Graphics graphics, BaseLine line, Rectangle rectangle)
{
if (graphics == null) {
throw new ArgumentNullException("graphics");
@ -114,6 +114,7 @@ namespace ICSharpCode.Reports.Core { @@ -114,6 +114,7 @@ namespace ICSharpCode.Reports.Core {
cb.SetColorFill(style.PdfBackColor);
}
protected static void FillBackGround (iTextSharp.text.pdf.PdfContentByte contentByte,
IBaseStyleDecorator style,
iTextSharp.text.Rectangle rectangle)

65
src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/Printing/Graphics/RectangleShape.cs

@ -15,9 +15,11 @@ using ICSharpCode.Reports.Core.Exporter; @@ -15,9 +15,11 @@ using ICSharpCode.Reports.Core.Exporter;
/// created on - 09.10.2005 18:20:51
/// </remarks>
namespace ICSharpCode.Reports.Core {
public class RectangleShape : BaseShape {
public RectangleShape() {
public RectangleShape()
{
}
@ -27,22 +29,46 @@ namespace ICSharpCode.Reports.Core { @@ -27,22 +29,46 @@ namespace ICSharpCode.Reports.Core {
}
public override GraphicsPath CreatePath(Rectangle rectangle){
GraphicsPath path1 = new GraphicsPath();
path1.AddRectangle(rectangle);
return path1;
public override GraphicsPath CreatePath(Rectangle rectangle )
{
//http://stackoverflow.com/questions/628261/how-to-draw-rounded-rectangle-with-variable-width-border-inside-of-specific-bound
//http://www.switchonthecode.com/tutorials/csharp-creating-rounded-rectangles-using-a-graphics-path
//http://www.codeproject.com/KB/GDI-plus/ExtendedGraphics.aspx
GraphicsPath gfxPath = new GraphicsPath();
if (CornerRadius == 0)
{
gfxPath.AddRectangle(rectangle);
}
else
{
gfxPath.AddArc(rectangle.X, rectangle.Y,CornerRadius , CornerRadius, 180, 90);
gfxPath.AddArc(rectangle.X + rectangle.Width - CornerRadius, rectangle.Y, CornerRadius, CornerRadius, 270, 90);
gfxPath.AddArc(rectangle.X + rectangle.Width - CornerRadius, rectangle.Y + rectangle.Height - CornerRadius, CornerRadius, CornerRadius, 0, 90);
gfxPath.AddArc(rectangle.X, rectangle.Y + rectangle.Height - CornerRadius, CornerRadius, CornerRadius, 90, 90);
}
gfxPath.CloseAllFigures();
return gfxPath;
}
public override void DrawShape(Graphics graphics, BaseLine line, Rectangle rectangle)
{
base.DrawShape(graphics, line, rectangle);
}
public override void CreatePath(iTextSharp.text.pdf.PdfContentByte contentByte,
BaseLine line,
IBaseStyleDecorator style,
IBaseStyleDecorator style,
Point from,Point to)
{
throw new NotImplementedException();
}
// http://www.mikesdotnetting.com/Article/88/iTextSharp-Drawing-shapes-and-Graphics
public override void CreatePath(iTextSharp.text.pdf.PdfContentByte contentByte,
BaseLine line,
@ -52,6 +78,9 @@ namespace ICSharpCode.Reports.Core { @@ -52,6 +78,9 @@ namespace ICSharpCode.Reports.Core {
if (contentByte == null) {
throw new ArgumentNullException("contentByte");
}
if (line == null) {
throw new ArgumentNullException("line");
}
if (style == null) {
throw new ArgumentNullException("style");
}
@ -59,21 +88,13 @@ namespace ICSharpCode.Reports.Core { @@ -59,21 +88,13 @@ namespace ICSharpCode.Reports.Core {
throw new ArgumentNullException("rectangle");
}
if ((line == null)||(line.Thickness < 1)) {
BaseShape.FillBackGround(contentByte,style,rectangle);
}
else if ((style.BackColor == GlobalValues.DefaultBackColor)) {
BaseShape.SetupShape(contentByte,style);
contentByte.SetLineWidth(UnitConverter.FromPixel(line.Thickness).Point);
contentByte.MoveTo(rectangle.Left ,rectangle.Top );
contentByte.LineTo(rectangle.Left, rectangle.Top - rectangle.Height);
contentByte.LineTo(rectangle.Left + rectangle.Width, rectangle.Top - rectangle.Height);
contentByte.LineTo(rectangle.Left + rectangle.Width, rectangle.Top);
contentByte.LineTo(rectangle.Left, rectangle.Top);
BaseShape.FinishShape(contentByte);
} else {
BaseShape.FillBackGround(contentByte,style,rectangle);
}
BaseShape.SetupShape(contentByte,style);
contentByte.SetLineWidth(UnitConverter.FromPixel(line.Thickness).Point);
contentByte.RoundRectangle(rectangle.Left, rectangle.Bottom, rectangle.Width, rectangle.Height, CornerRadius);
BaseShape.FinishShape(contentByte);
}
public int CornerRadius {get;set;}
}
}

Loading…
Cancel
Save