using System.Drawing;
namespace HeuristicLab.Visualization {
public class LineShape : IShape {
private RectangleD boundingBox;
private double z;
private Color color;
private int thickness;
///
/// Initializes the LineShape.
///
/// x coordinate of left lineEndPoind
/// y coordinate of left lineEndPoind
/// x coordinate of right lineEndPoind
/// y coordinate of right lineEndPoind
/// color for the LineShape
public LineShape(double x1, double y1, double x2, double y2, double z, Color color, int thickness) {
this.boundingBox = new RectangleD(x1, y1, x2, y2);
this.z = z;
this.color = color;
this.thickness = thickness;
}
public RectangleD BoundingBox {
get { return boundingBox; }
}
public double Y1 {
get { return boundingBox.Y1; }
set { boundingBox.Y1 = value; }
}
public double Y2 {
get { return boundingBox.Y2; }
set { boundingBox.Y2 = value; }
}
public double X1 {
get { return boundingBox.X1; }
set { boundingBox.X1 = value; }
}
public double X2 {
get { return boundingBox.X2; }
set { boundingBox.X2 = value; }
}
///
/// Draws the LineShape.
///
/// graphics handle to draw to
/// rectangle in value-coordinates to display
/// rectangle in screen-coordinates to draw
public void Draw(Graphics graphics, Rectangle viewport, RectangleD clippingArea) {
using (Pen pen = new Pen(color, thickness)){
// TODO there seems to be a bug with drawing straight lines.
Rectangle screenRect = Transform.ToScreen(boundingBox, viewport, clippingArea);
graphics.DrawLine(pen,screenRect.Left, screenRect.Bottom, screenRect.Right, screenRect.Top);
}
}
public double Z {
get { return z; }
set { z = value; }
}
}
}