¶Ô±ÈÐÂÎļþ |
| | |
| | | namespace Yw.WinFrmUI.HydroL2d |
| | | { |
| | | /// <summary> |
| | | /// æ°´åº |
| | | /// </summary> |
| | | public class Reservoir : Source |
| | | { |
| | | /// <summary> |
| | | /// å¾ç |
| | | /// </summary> |
| | | public Image Image { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 宽度 |
| | | /// </summary> |
| | | public float? Width { get; set; } |
| | | |
| | | /// <summary> |
| | | /// é«åº¦ |
| | | /// </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; }//åæ ä¿¡æ¯ |
| | | |
| | | //è·ååæ ä½ç½® |
| | | private Coordinate GetCoordinate(Graphics g) |
| | | { |
| | | var ps = this.Position;//åå§ç¹ |
| | | var ws = this.Width.HasValue ? this.Width.Value : CacheHelper.HydroL2d.Reservoir.Size.Width; //åå§å®½åº¦ |
| | | var hs = this.Height.HasValue ? this.Height.Value : CacheHelper.HydroL2d.Reservoir.Size.Height;//åå§é«åº¦ |
| | | var wz = ws / g.PageScale;//缩æ¾å®½åº¦ |
| | | var hz = hs / g.PageScale;//缩æ¾é«åº¦ |
| | | return Coordinate.GetCoordinate(ps, 0, new SizeF(wz, hz), StringAlignment.Center, StringAlignment.Center); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// ç»å¶ |
| | | /// </summary> |
| | | public override void Draw(Graphics g) |
| | | { |
| | | _coordinate = GetCoordinate(g); |
| | | |
| | | if (this.Hovered) |
| | | { |
| | | var hoveredImg = CacheHelper.ReservoirHoveredImage; |
| | | if (this.HoveredImage != null) |
| | | { |
| | | hoveredImg = this.HoveredImage; |
| | | } |
| | | var hoveredWidth = this.HoveredWidth.HasValue ? this.HoveredWidth.Value : CacheHelper.HydroL2d.Reservoir.HoveredSize.Width; |
| | | var hoveredHeight = this.HoveredHeight.HasValue ? this.HoveredHeight.Value : CacheHelper.HydroL2d.Reservoir.HoveredSize.Height; |
| | | var isNewImage = false; |
| | | if (hoveredImg.Width != (int)hoveredWidth || hoveredImg.Height != (int)hoveredHeight) |
| | | { |
| | | hoveredImg = hoveredImg.CloneC(hoveredWidth, hoveredHeight); |
| | | isNewImage = true; |
| | | } |
| | | |
| | | var dx = hoveredWidth / g.PageScale / 2f; |
| | | var dy = hoveredHeight / g.PageScale / 2f; |
| | | var p0 = new PointF(this.Position.X - dx, this.Position.Y - dy); |
| | | |
| | | g.DrawImage(hoveredImg, p0); |
| | | |
| | | if (isNewImage) |
| | | { |
| | | hoveredImg.Dispose(); |
| | | } |
| | | } |
| | | else if (this.Selected) |
| | | { |
| | | var selectedImg = CacheHelper.ReservoirSelectedImage; |
| | | if (this.SelectedImage != null) |
| | | { |
| | | selectedImg = this.SelectedImage; |
| | | } |
| | | var selectedWidth = this.SelectedWidth.HasValue ? this.SelectedWidth.Value : CacheHelper.HydroL2d.Reservoir.SelectedSize.Width; |
| | | var selectedHeight = this.SelectedHeight.HasValue ? this.SelectedHeight.Value : CacheHelper.HydroL2d.Reservoir.SelectedSize.Height; |
| | | var isNewImage = false; |
| | | if (selectedImg.Width != (int)selectedWidth || selectedImg.Height != (int)selectedHeight) |
| | | { |
| | | selectedImg = selectedImg.CloneC(selectedWidth, selectedHeight); |
| | | isNewImage = true; |
| | | } |
| | | |
| | | var dx = selectedWidth / g.PageScale / 2f; |
| | | var dy = selectedHeight / g.PageScale / 2f; |
| | | var p0 = new PointF(this.Position.X - dx, this.Position.Y - dy); |
| | | |
| | | g.DrawImage(selectedImg, p0); |
| | | |
| | | if (isNewImage) |
| | | { |
| | | selectedImg.Dispose(); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | var img = CacheHelper.ReservoirImage; |
| | | if (this.Image != null) |
| | | { |
| | | img = this.Image; |
| | | } |
| | | var width = this.Width.HasValue ? this.Width.Value : CacheHelper.HydroL2d.Reservoir.Size.Width; |
| | | var height = this.Height.HasValue ? this.Height.Value : CacheHelper.HydroL2d.Reservoir.Size.Height; |
| | | var isNewImage = false; |
| | | if (img.Width != (int)width || img.Height != (int)height) |
| | | { |
| | | img = img.CloneC(width, height); |
| | | isNewImage = true; |
| | | } |
| | | |
| | | var dx = width / g.PageScale / 2f; |
| | | var dy = height / g.PageScale / 2f; |
| | | var p0 = new PointF(this.Position.X - dx, this.Position.Y - dy); |
| | | |
| | | g.DrawImage(img, p0); |
| | | |
| | | if (isNewImage) |
| | | { |
| | | img.Dispose(); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å
å« |
| | | /// </summary> |
| | | public override bool Contains(PointF pt) |
| | | { |
| | | if (_coordinate == null) |
| | | { |
| | | return false; |
| | | } |
| | | return _coordinate.BeforeRectf.Contains(pt); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// ç¸äº¤ |
| | | /// </summary> |
| | | public override bool Intersect(RectangleF rectf) |
| | | { |
| | | if (rectf.Contains(this.Position)) |
| | | { |
| | | return true; |
| | | } |
| | | return false; |
| | | |
| | | } |
| | | |
| | | } |
| | | } |