using Microsoft.VisualBasic; using Microsoft.VisualBasic.CompilerServices; using MuchInfo.Chart.Data; using MuchInfo.Chart.Data.EnumTypes; using MuchInfo.Chart.Infrastructure.Helpers; using MuchInfo.Chart.Infrastructure.Utilities; using MuchInfo.Chart.WPF.Controls.Drawing; using MuchInfo.Chart.WPF.Controls.Editors; using MuchInfo.Chart.WPF.Helpers; using MuchInfo.Chart.WPF.Primitives.Interfaces; using System; using System.Collections.Generic; using System.Runtime.CompilerServices; using System.Windows; using System.Windows.Controls; using System.Windows.Media; using System.Windows.Shapes; using System.Xml.Linq; namespace MuchInfo.Chart.WPF.Primitives.Drawing { public class DrawingRectangle : Drawing2PointBase { #region Fields private bool _doFill; private ExtendableLine _extendableLine; private Color _fillColor; private double _fillOpacity; private Rectangle _rectangle; #endregion Fields #region Constructors public DrawingRectangle() { this._doFill = true; this._fillOpacity = 0.3; this._fillColor = Colors.Gray; } #endregion Constructors #region Properties #region Public Properties public Color FillColor { get { return this._fillColor; } set { if (_fillColor.Equals(value)) { this._fillColor = value; this.ColorChanged(); this.PropertyChanged(); } } } public bool DoFill { get { return this._doFill; } set { bool flag = this._doFill != value; if (flag) { this._doFill = value; this.ColorChanged(); this.PropertyChanged(); } } } public double FillOpacity { get { return this._fillOpacity; } set { bool flag = this._fillOpacity.Equals(value); if (flag) { this._fillOpacity = value; this.ColorChanged(); this.PropertyChanged(); } } } public override string RootName { get { return "DrawRectangle"; } } #endregion Public Properties #endregion Properties #region Methods #region Public Methods public override string Abbreviation() { return LanguageManager.FindResource(LanguageConst.DrawingTool_Abbreviation_Rectangle); } public override List AdditionalEditors() { var list = new List() { new ControlPair() { ControlLeft = new TextBlock {Text = LanguageManager.FindResource(LanguageConst.DrawingTool_Edit_Fill)}, ControlRight = new ColorOpacityEditor(this, "FillColor", "FillOpacity", "DoFill") } }; return list; } public override IDrawingTool Clone() { return new DrawingRectangle { mColor = Colors.White }; } public override string Description() { return this.MenuDescription(); } public override ImageSource Icon() { ImageSource result; try { result = ImageHelper.GetImage("Rectangle.png"); } catch (Exception expr_3A) { ProjectData.SetProjectError(expr_3A); result = null; ProjectData.ClearProjectError(); } return result; } public override string MenuDescription() { return LanguageManager.FindResource(LanguageConst.DrawingTool_Edit_Description_Rectangle); } public override DrawingToolType ToolType() { return DrawingToolType.Rectangle; } #endregion Public Methods #region Protected Methods protected override void AddFromInfo(DrawingToolInfo info) { base.AddFromInfo(info); } protected override void AddFromXml(XElement xml) { } protected override void AddToInfo(DrawingToolInfo info) { base.AddToInfo(info); } protected override void AddToXml(XElement xml, List args) { } protected override bool CanExtendLeft() { return false; } protected override bool CanExtendRight() { return false; } protected override void ColorChanged() { bool flag = this._rectangle != null; checked { if (flag) { this._rectangle.Stroke = (new SolidColorBrush(this.mColor)); flag = !this._doFill; if (flag) { this._rectangle.Fill = null; } else { var num = (int)Math.Round(unchecked(2.55 * this._fillOpacity) * 100); flag = (num < 0); if (flag) { num = 0; } flag = (num > 255); if (flag) { num = 255; } this._rectangle.Fill = (new SolidColorBrush(Color.FromArgb((byte)num, this._fillColor.R, this._fillColor.G, this._fillColor.B))); } } } } protected override List GetDrawingPlots(Chart owner, ScaleLayer aScale, Rect aRect) { var list = new List(); bool flag = this._extendableLine == null; if (flag) { this._extendableLine = new ExtendableLine(this, owner); this._extendableLine.Stroke = new SolidColorBrush(Colors.Transparent); } this._rectangle = new Rectangle { StrokeThickness = (1.4), IsHitTestVisible = (false) }; this.MoveDrawingToNewLocations(aRect); this.ColorChanged(); list.Add(this._rectangle); list.Add(this._extendableLine); return list; } protected override void MoveDrawingToNewLocations(Rect aRect) { if (this._extendableLine != null) { this._extendableLine.SetPosition(this.mDrawP1, this.mDrawP2, false, false, aRect); //this._extendableLine.SetPosition(this.mDrawP1, this.mDrawP2, this.ExtendLeft, this.ExtendRight, aRect); } if (this._rectangle != null) { ////ÏÞÖÆp1,p2λÖà //var p1X = this.mDrawP1.X < 0 ? 0 : (this.mDrawP1.X > aRect.Width ? aRect.Width : this.mDrawP1.X); //var p1Y = this.mDrawP1.Y < 0 ? 0 : (this.mDrawP1.Y > aRect.Height ? aRect.Height : this.mDrawP1.Y); //var p2X = this.mDrawP2.X < 0 ? 0 : (this.mDrawP2.X > aRect.Width ? aRect.Width : this.mDrawP2.X); //var p2Y = this.mDrawP2.Y < 0 ? 0 : (this.mDrawP2.Y > aRect.Height ? aRect.Height : this.mDrawP2.Y); var p1X = this.mDrawP1.X; var p1Y = this.mDrawP1.Y; var p2X = this.mDrawP2.X; var p2Y = this.mDrawP2.Y; if (p1X < p2X) { this._rectangle.SetValue(Canvas.LeftProperty, p1X); this._rectangle.Width = (p2X - p1X); } else { this._rectangle.SetValue(Canvas.LeftProperty, p2X); this._rectangle.Width = (p1X - p2X); } if (p1Y < p2Y) { this._rectangle.SetValue(Canvas.TopProperty, p1Y); this._rectangle.Height = (p2Y - p1Y); } else { this._rectangle.SetValue(Canvas.TopProperty, p2Y); this._rectangle.Height = (p1Y - p2Y); } } } #endregion Protected Methods #endregion Methods } }