| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346 |
- 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<ControlPair> AdditionalEditors()
- {
- var Rlt = new List<ControlPair>();
- Rlt = new List<ControlPair>()
- {
- 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<object> 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<FrameworkElement> GetDrawingPlots(Chart owner, ScaleLayer aScale, Rect aRect)
- {
- var Rlt = new List<FrameworkElement>();
- 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
- }
- }
|