| | |
| | | public float? LineWidth { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 悬停线色 |
| | | /// </summary> |
| | | public Color? HoveredLineColor { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 悬停线宽 |
| | | /// </summary> |
| | | public float? HoveredLineWidth { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 选择线色 |
| | | /// </summary> |
| | | public Color? SelectedLineColor { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 选择线宽 |
| | | /// </summary> |
| | | public float? SelectedLineWidth { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 图片 |
| | | /// </summary> |
| | | public Image Image { get; set; } |
| | |
| | | /// 高度 |
| | | /// </summary> |
| | | public float? Height { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 悬停图片 |
| | | /// </summary> |
| | | public Image HoveredImage { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 悬停宽度 |
| | | /// </summary> |
| | | public float? HoveredWidth { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 悬停高度 |
| | | /// </summary> |
| | | public float? HoveredHeight { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 选择图片 |
| | | /// </summary> |
| | | public Image SelectedImage { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 选择宽度 |
| | | /// </summary> |
| | | public float? SelectedWidth { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 选择高度 |
| | | /// </summary> |
| | | public float? SelectedHeight { get; set; } |
| | | |
| | | private Coordinate _coordinate { get; set; }//坐标信息 |
| | | |
| | |
| | | public override void Draw(Graphics g) |
| | | { |
| | | _coordinate = GetCoordinate(g); |
| | | |
| | | #region 画线 |
| | | |
| | | var fromCachePen = true; |
| | | var pen = CacheHelper.ValveLinePen; |
| | | if (this.LineColor.HasValue && this.LineWidth.HasValue) |
| | | if (this.Hovered) |
| | | { |
| | | pen = new Pen(this.LineColor.Value, this.LineWidth.Value); |
| | | fromCachePen = false; |
| | | var fromCachePen = true; |
| | | var pen = CacheHelper.ValveHoveredLinePen; |
| | | if (this.HoveredLineColor.HasValue && this.HoveredLineWidth.HasValue) |
| | | { |
| | | pen = new Pen(this.HoveredLineColor.Value, this.HoveredLineWidth.Value); |
| | | fromCachePen = false; |
| | | } |
| | | var penWidth = pen.Width; |
| | | pen.Width = pen.Width / g.PageScale; |
| | | g.DrawLine(pen, this.StartPosition, this.EndPosition); |
| | | pen.Width = penWidth; |
| | | if (!fromCachePen) |
| | | { |
| | | pen.Dispose(); |
| | | } |
| | | } |
| | | var penWidth = pen.Width; |
| | | pen.Width = pen.Width / g.PageScale; |
| | | g.DrawLine(pen, this.StartPosition, this.EndPosition); |
| | | pen.Width = penWidth; |
| | | if (!fromCachePen) |
| | | else if (this.Selected) |
| | | { |
| | | pen.Dispose(); |
| | | var fromCachePen = true; |
| | | var pen = CacheHelper.ValveSelectedLinePen; |
| | | if (this.SelectedLineColor.HasValue && this.SelectedLineWidth.HasValue) |
| | | { |
| | | pen = new Pen(this.SelectedLineColor.Value, this.SelectedLineWidth.Value); |
| | | fromCachePen = false; |
| | | } |
| | | var penWidth = pen.Width; |
| | | pen.Width = pen.Width / g.PageScale; |
| | | g.DrawLine(pen, this.StartPosition, this.EndPosition); |
| | | pen.Width = penWidth; |
| | | if (!fromCachePen) |
| | | { |
| | | pen.Dispose(); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | var fromCachePen = true; |
| | | var pen = CacheHelper.ValveLinePen; |
| | | if (this.LineColor.HasValue && this.LineWidth.HasValue) |
| | | { |
| | | pen = new Pen(this.LineColor.Value, this.LineWidth.Value); |
| | | fromCachePen = false; |
| | | } |
| | | var penWidth = pen.Width; |
| | | pen.Width = pen.Width / g.PageScale; |
| | | g.DrawLine(pen, this.StartPosition, this.EndPosition); |
| | | pen.Width = penWidth; |
| | | if (!fromCachePen) |
| | | { |
| | | pen.Dispose(); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | #endregion |
| | | |
| | | #region 画图片 |
| | | |
| | | var img = CacheHelper.ValveImage; |
| | | if (this.Image != null) |
| | | if (this.Hovered) |
| | | { |
| | | img = this.Image; |
| | | var img = CacheHelper.ValveHoveredImage; |
| | | if (this.HoveredImage != null) |
| | | { |
| | | img = this.HoveredImage; |
| | | } |
| | | var width = this.HoveredWidth.HasValue ? this.HoveredWidth.Value : CacheHelper.HydroL2d.Valve.HoveredSize.Width; |
| | | var height = this.HoveredHeight.HasValue ? this.HoveredHeight.Value : CacheHelper.HydroL2d.Valve.HoveredSize.Height; |
| | | var isNewImage = false; |
| | | if (img.Width != (int)width || img.Height != (int)height) |
| | | { |
| | | img = img.CloneC(width, height); |
| | | isNewImage = true; |
| | | } |
| | | |
| | | var pt = this.StartPosition.GetCenter(this.EndPosition); |
| | | var dx = width / g.PageScale / 2f; |
| | | var dy = height / g.PageScale / 2f; |
| | | var p0 = new PointF(pt.X - dx, pt.Y - dy); |
| | | |
| | | g.DrawImage(img, p0); |
| | | |
| | | if (isNewImage) |
| | | { |
| | | img.Dispose(); |
| | | } |
| | | } |
| | | var width = this.Width.HasValue ? this.Width.Value : CacheHelper.HydroL2d.Valve.Size.Width; |
| | | var height = this.Height.HasValue ? this.Height.Value : CacheHelper.HydroL2d.Valve.Size.Height; |
| | | var isNewImage = false; |
| | | if (img.Width != (int)width || img.Height != (int)height) |
| | | else if (this.Selected) |
| | | { |
| | | img = img.CloneC(width, height); |
| | | isNewImage = true; |
| | | var img = CacheHelper.ValveSelectedImage; |
| | | if (this.SelectedImage != null) |
| | | { |
| | | img = this.SelectedImage; |
| | | } |
| | | var width = this.SelectedWidth.HasValue ? this.SelectedWidth.Value : CacheHelper.HydroL2d.Valve.SelectedSize.Width; |
| | | var height = this.SelectedHeight.HasValue ? this.SelectedHeight.Value : CacheHelper.HydroL2d.Valve.SelectedSize.Height; |
| | | var isNewImage = false; |
| | | if (img.Width != (int)width || img.Height != (int)height) |
| | | { |
| | | img = img.CloneC(width, height); |
| | | isNewImage = true; |
| | | } |
| | | |
| | | var pt = this.StartPosition.GetCenter(this.EndPosition); |
| | | var dx = width / g.PageScale / 2f; |
| | | var dy = height / g.PageScale / 2f; |
| | | var p0 = new PointF(pt.X - dx, pt.Y - dy); |
| | | |
| | | g.DrawImage(img, p0); |
| | | |
| | | if (isNewImage) |
| | | { |
| | | img.Dispose(); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | var img = CacheHelper.ValveImage; |
| | | if (this.Image != null) |
| | | { |
| | | img = this.Image; |
| | | } |
| | | var width = this.Width.HasValue ? this.Width.Value : CacheHelper.HydroL2d.Valve.Size.Width; |
| | | var height = this.Height.HasValue ? this.Height.Value : CacheHelper.HydroL2d.Valve.Size.Height; |
| | | var isNewImage = false; |
| | | if (img.Width != (int)width || img.Height != (int)height) |
| | | { |
| | | img = img.CloneC(width, height); |
| | | isNewImage = true; |
| | | } |
| | | |
| | | var pt = this.StartPosition.GetCenter(this.EndPosition); |
| | | var dx = width / g.PageScale / 2f; |
| | | var dy = height / g.PageScale / 2f; |
| | | var p0 = new PointF(pt.X - dx, pt.Y - dy); |
| | | |
| | | g.DrawImage(img, p0); |
| | | |
| | | if (isNewImage) |
| | | { |
| | | img.Dispose(); |
| | | } |
| | | } |
| | | |
| | | var pt = this.StartPosition.GetCenter(this.EndPosition); |
| | | var dx = width / g.PageScale / 2f; |
| | | var dy = height / g.PageScale / 2f; |
| | | var p0 = new PointF(pt.X - dx, pt.Y - dy); |
| | | |
| | | g.DrawImage(img, p0); |
| | | |
| | | if (isNewImage) |
| | | { |
| | | img.Dispose(); |
| | | } |
| | | |
| | | #endregion |
| | | |