using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using Steema.TeeChart.Drawing;
namespace DelftTools.Controls.Swf.Charting
{
public class ChartGraphics
{
private readonly Steema.TeeChart.Chart chart;
public ChartGraphics(Steema.TeeChart.Chart chart)
{
this.chart = chart;
Graphics3D = chart.Graphics3D; // Needed since TeeChart returns a new graphics object each time the get is called!!
}
///
/// Background color used when drawing
///
public Color BackColor
{
get
{
return Graphics3D.BackColor;
}
set
{
Graphics3D.BackColor = value;
}
}
///
/// Pen color used when drawing
///
public Color PenColor
{
get
{
return Graphics3D.Pen.Color;
}
set
{
Graphics3D.Pen.Color = value;
}
}
///
/// Pen width used when drawing
///
public int PenWidth
{
get
{
return Graphics3D.Pen.Width;
}
set
{
Graphics3D.Pen.Width = value;
}
}
///
/// Dash style of the pen used when drawing
///
public DashStyle PenStyle
{
get
{
return Graphics3D.Pen.Style;
}
set
{
Graphics3D.Pen.Style = value;
}
}
///
/// Font to use when drawing text
///
public Font Font
{
get
{
return Graphics3D.Font.DrawingFont;
}
set
{
Graphics3D.Font.DrawingFont = value;
}
}
///
/// Draws an ellipse within the supplied region
///
/// Region to draw the ellipse in
public void Ellipse(Rectangle rectangle)
{
DrawWithPenEnabled(() => Graphics3D.Ellipse(rectangle));
}
///
/// Draws a rectangle within the supplied region
///
/// Region to draw the rectangle in
public void Rectangle(Rectangle rectangle)
{
DrawWithPenEnabled(() => Graphics3D.Rectangle(rectangle));
}
///
/// Draws an image within the supplied region
///
/// Region to draw the image in
/// Image to draw
/// Use transparent color
public void Draw(Rectangle rectangle, Image image, bool transparent)
{
DrawWithPenEnabled(() => Graphics3D.Draw(rectangle, image, transparent));
}
///
/// Sets the position of the pen to provided x and y location (Used in )
///
/// x position
/// y position
public void MoveTo(int x, int y)
{
Graphics3D.MoveTo(x, y);
}
///
/// Draws a line to from the pen position (set by ) to the provided x and y location
///
/// x position
/// y position
public void LineTo(int x, int y)
{
Graphics3D.LineTo(x, y);
}
///
/// Draws a graphics path according to the supplied
///
/// Pen to use for drawing
/// Graphics path to follow
public void DrawPath(Pen pen, GraphicsPath graphicsPath)
{
DrawWithPenEnabled(() => Graphics3D.DrawPath(pen, graphicsPath));
}
///
/// Calculates the size needed to draw the sting
///
/// String to calculate for
public SizeF MeasureString(string label)
{
return Graphics3D.MeasureString(Graphics3D.Font, label);
}
///
/// Draws the provided at the provided location
///
/// X position
/// Y position
/// Text to draw
public void TextOut(int xpos, int ypos, string label)
{
Graphics3D.TextOut(xpos, ypos, label);
}
///
/// Draws a polygon using the provided
///
/// Points that make up the polygon
public void Polygon(Point[] points)
{
DrawWithPenEnabled(() => Graphics3D.Polygon(points));
}
///
/// Graphics object used for drawing.
///
private Graphics3D Graphics3D { get; set; }
private void DrawWithPenEnabled(Action drawAction)
{
var originalPenVisible = Graphics3D.Pen.Visible;
Graphics3D.Pen.Visible = true;
Graphics3D.ClipRectangle(chart.ChartBounds);
drawAction();
Graphics3D.UnClip();
Graphics3D.Pen.Visible = originalPenVisible;
}
}
}