namespace Yw.WinFrmUI.HydroL2d
|
{
|
/// <summary>
|
/// 水泵
|
/// </summary>
|
public class Pump : Link
|
{
|
/// <summary>
|
/// 线色
|
/// </summary>
|
public Color? LineColor { get; set; }
|
|
/// <summary>
|
/// 线宽
|
/// </summary>
|
public float? LineWidth { get; set; }
|
|
/// <summary>
|
/// 图片
|
/// </summary>
|
public Image Image { get; set; }
|
|
/// <summary>
|
/// 宽度
|
/// </summary>
|
public float? Width { get; set; }
|
|
/// <summary>
|
/// 高度
|
/// </summary>
|
public float? Height { get; set; }
|
|
/// <summary>
|
/// 绘制
|
/// </summary>
|
public override void Draw(Graphics g)
|
{
|
var fromCachePen = true;
|
var pen = CacheHelper.PumpLinePen;
|
if (this.LineColor.HasValue && this.LineWidth.HasValue)
|
{
|
pen = new Pen(this.LineColor.Value, this.LineWidth.Value);
|
fromCachePen = false;
|
}
|
g.DrawLine(pen, this.StartPosition, this.EndPosition);
|
if (!fromCachePen)
|
{
|
pen.Dispose();
|
}
|
|
var img = CacheHelper.PumpImage;
|
if (this.Image != null)
|
{
|
img = this.Image;
|
}
|
var width = this.Width.HasValue ? this.Width.Value : CacheHelper.HydroL2d.Pump.Width;
|
var height = this.Height.HasValue ? this.Height.Value : CacheHelper.HydroL2d.Pump.Height;
|
var isNewImage = false;
|
if (img.Width != (int)width || img.Height != (int)height)
|
{
|
img = img.CloneC(width, height);
|
isNewImage = true;
|
}
|
|
g.DrawImage(img, this.StartPosition.GetCenter(this.EndPosition));
|
|
if (isNewImage)
|
{
|
img.Dispose();
|
}
|
|
}
|
|
|
}
|
}
|