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