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 DrawingEllipse : Drawing2PointBase { #region Fields private bool _doFill; private ExtendableLine _extendableLine; private Color _fillColor; private double _fillOpacity; private Ellipse _ellipse; #endregion #region Constructors public DrawingEllipse() { this._doFill = true; this._fillOpacity = 30; this._fillColor = Colors.Gray; } #endregion #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 "DrawEllipse"; } } #endregion #endregion #region Methods #region Public Methods #endregion public override string Abbreviation() { return "Ellipse"; } public override List AdditionalEditors() { var Rlt = new List(); Rlt = new List() { new ControlPair() { ControlLeft = new TextBlock() {Text="Ellipse"}, ControlRight = new ColorOpacityEditor(this, "FillColor", "FillOpacity", "DoFill") } }; return Rlt; } public override IDrawingTool Clone() { return new DrawingEllipse { mColor = Colors.White }; } public override string Description() { return this.MenuDescription(); } public override ImageSource Icon() { ImageSource result; try { result = ImageHelper.GetImage("Ellipse.png"); } catch (Exception expr_3A) { ProjectData.SetProjectError(expr_3A); result = null; ProjectData.ClearProjectError(); } return result; } public override string MenuDescription() { return LanguageManager.FindResource(LanguageConst.DrawingTool_Abbreviation_Ellipse); } public override DrawingToolType ToolType() { return DrawingToolType.Ellipse; } #region Protected Methods protected override void AddFromInfo(DrawingToolInfo info) { base.AddFromInfo(info); try { XElement xElement = XElement.Parse(info.XML); bool flag = xElement.Name == "Root"; if (flag) { bool flag2 = xElement.Attribute("Color1") != null; if (flag2) { this._fillColor = ColorHelper.ColorFromInt(int.Parse(xElement.Attribute("Color1").Value)); } flag2 = (xElement.Attribute("IntValue1") != null); if (flag2) { this._doFill = (int.Parse(xElement.Attribute("IntValue1").Value) == 1); } flag2 = (xElement.Attribute("IntValue2") != null); if (flag2) { this._fillOpacity = double.Parse(xElement.Attribute("IntValue2").Value); } } } catch (Exception expr_155) { ProjectData.SetProjectError(expr_155); ProjectData.ClearProjectError(); } } protected override void AddFromXml(XElement xml) { bool flag = xml.Attribute("Fil") != null; if (flag) { this._fillColor = ColorHelper.ColorFromString(xml.Attribute("Fil").Value); } flag = (xml.Attribute("DF") != null); if (flag) { this._doFill = bool.Parse(xml.Attribute("DF").Value); } flag = (xml.Attribute("FO") != null); if (flag) { this._fillOpacity = int.Parse(xml.Attribute("FO").Value); } } protected override void AddToInfo(DrawingToolInfo info) { base.AddToInfo(info); XElement xElement = new XElement("Root"); xElement.Add(new XAttribute("Color1", ColorHelper.ColorToInt(this._fillColor).ToString())); xElement.Add(new XAttribute("IntValue1", RuntimeHelpers.GetObjectValue(Interaction.IIf(this._doFill, "1", "0")))); xElement.Add(new XAttribute("IntValue2", this._fillOpacity.ToString())); info.XML = xElement.ToString(); } protected override void AddToXml(XElement xml, List args) { xml.Add(new XAttribute("Fil", this._fillColor.ToString())); xml.Add(new XAttribute("DF", this._doFill.ToString())); xml.Add(new XAttribute("FO", this._fillOpacity.ToString())); } protected override bool CanExtendLeft() { return false; } protected override bool CanExtendRight() { return false; } protected override void ColorChanged() { bool flag = this._ellipse != null; checked { if (flag) { this._ellipse.Stroke = (new SolidColorBrush(this.mColor)); flag = !this._doFill; if (flag) { this._ellipse.Fill = (null); } else { int num = (int)Math.Round(unchecked(2.55 * (double)this._fillOpacity)); flag = (num < 0); if (flag) { num = 0; } flag = (num > 255); if (flag) { num = 255; } this._ellipse.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 Rlt = new List(); if (this._extendableLine == null) { this._extendableLine = new ExtendableLine(this, owner); this._extendableLine.Stroke = new SolidColorBrush(Colors.Transparent); } this._ellipse = new Ellipse() { StrokeThickness = 1.4, IsHitTestVisible = false, }; //this._ellipse.SetValue(Canvas.ZIndexProperty,-100); this.MoveDrawingToNewLocations(aRect); this.ColorChanged(); Rlt.Add(this._ellipse); Rlt.Add(this._extendableLine); return Rlt; } protected override void MoveDrawingToNewLocations(Rect aRect) { if (this._extendableLine != null) { this._extendableLine.SetPosition(this.mDrawP1, this.mDrawP2, false, false, aRect); } if (this._ellipse != null) { bool flag2 = this.mDrawP1.X < this.mDrawP2.X; if (flag2) { this._ellipse.SetValue(Canvas.LeftProperty, this.mDrawP1.X); this._ellipse.Width = (this.mDrawP2.X - this.mDrawP1.X); } else { this._ellipse.SetValue(Canvas.LeftProperty, this.mDrawP2.X); this._ellipse.Width = (this.mDrawP1.X - this.mDrawP2.X); } flag2 = (this.mDrawP1.Y < this.mDrawP2.Y); if (flag2) { this._ellipse.SetValue(Canvas.TopProperty, this.mDrawP1.Y); this._ellipse.Height = (this.mDrawP2.Y - this.mDrawP1.Y); } else { this._ellipse.SetValue(Canvas.TopProperty, this.mDrawP2.Y); this._ellipse.Height = (this.mDrawP1.Y - this.mDrawP2.Y); } } } #endregion #endregion } }