| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442 |
- using MuchInfo.Chart.Data.EnumTypes;
- using MuchInfo.Chart.Infrastructure.Helpers;
- using MuchInfo.Chart.WPF.Helpers;
- using MuchInfo.Chart.WPF.Primitives.Drawing;
- using MuchInfo.Chart.WPF.Primitives.Interfaces;
- using System.Collections.Generic;
- using System.Linq;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Media;
- namespace MuchInfo.Chart.WPF.Controls.Drawing
- {
- /// <summary>
- /// ChartDrawingToolbar.xaml 的交互逻辑
- /// </summary>
- public partial class ChartDrawingToolbar : UserControl
- {
- #region Fields
- private IDrawingTool currentDrawingTool;
- private bool flag;
- private bool showNarrow;
- #endregion Fields
- #region Constructors
- internal ChartDrawingToolbar(Chart parentChart)
- {
- this.InitializeComponent();
- this.flag = false;
- this.showNarrow = false;
- this.ParentChart = parentChart;
- this.InitializeToolbars();
- //设成透明色
- this.Background = new SolidColorBrush(Colors.Transparent);
- //this.Background = parentChart.ChartBackground;
- this.FontSize = parentChart.ChartFontSize;
- this.Foreground = parentChart.IsDarkBackground ? new SolidColorBrush(Colors.White) : new SolidColorBrush(Colors.Black);
- }
- #endregion Constructors
- #region Delegates
- public delegate void VisibleChangedEventHandler();
- #endregion Delegates
- #region Events
- public event ChartDrawingToolbar.VisibleChangedEventHandler VisibleChanged;
- #endregion Events
- #region Properties
- #region Public Properties
- public Chart ParentChart
- {
- get;
- set;
- }
- public bool ShowNarrow
- {
- get
- {
- return this.showNarrow;
- }
- set
- {
- this.showNarrow = value;
- this.InitializeToolbars();
- }
- }
- public bool Visible
- {
- get
- {
- return this.borderToolbar.Visibility == Visibility.Visible;
- }
- set
- {
- bool flag = this.borderToolbar.Visibility == Visibility.Visible;
- if (flag != value)
- {
- bool flag3;
- if (value)
- {
- this.borderToolbar.Visibility = Visibility.Visible;
- flag3 = (this.currentDrawingTool != null);
- if (flag3)
- {
- ParentChart.CurrentDrawingTool = this.currentDrawingTool;
- }
- }
- else
- {
- this.currentDrawingTool = ParentChart.CurrentDrawingTool;
- this.borderToolbar.Visibility = Visibility.Collapsed;
- }
- OnVisibleChanged();
- }
- }
- }
- #endregion Public Properties
- #endregion Properties
- #region Methods
- #region Internal Methods
- internal void ButtonPress()
- {
- SetIsNotPressed();
- if (ParentChart.PointerType == PointerType.Drawing)
- {
- this.SetIsPressedByRootName();
- }
- else
- {
- this.SetIsPressedByPointerType();
- }
- }
- internal void ButtonSelectChanged(ChartDrawingToolbarButton aBtn)
- {
- PointerType command = aBtn.Command;
- bool flag = command == PointerType.Drawing;
- if (flag)
- {
- ParentChart.CurrentDrawingTool = aBtn.DrawingTarget;
- }
- else
- {
- ParentChart.PointerType = aBtn.Command;
- }
- this.ButtonPress();
- }
- internal bool CanShowNarrow()
- {
- return this.theStack2.Visibility == Visibility.Collapsed;
- }
- /// <summary>
- /// 根据画图类型找到相应的button
- /// </summary>
- /// <param name="type">The type.</param>
- internal ChartDrawingToolbarButton GetToolbarButton(DrawingToolType type)
- {
- if (this.theStack1 != null && this.theStack1.Children != null && this.theStack1.Children.Count > 0)
- {
- var buttons = this.theStack1.Children.OfType<ChartDrawingToolbarButton>();
- var current = buttons.FirstOrDefault(z => z.DrawingToolType == type);
- if (current != null) return current;
- }
- if (this.theStack2 != null && this.theStack2.Children != null && this.theStack2.Children.Count > 0)
- {
- var buttons = this.theStack2.Children.OfType<ChartDrawingToolbarButton>();
- return buttons.FirstOrDefault(button => button.DrawingToolType == type);
- }
- return null;
- }
- /// <summary>
- /// 根据画线工具位置调整stackpanel的orientation
- /// </summary>
- internal void UpdateLayout(Orientation orientation)
- {
- this.theStack1.Orientation = orientation;
- this.theStack2.Orientation = orientation;
- }
- #endregion Internal Methods
- #region Private Methods
- private void AddDrawingToolbarButton(ImageSource imageSource, PointerType command, string labelText, string toolTip, DrawingToolType toolType, IDrawingTool target = null)
- {
- var button = new ChartDrawingToolbarButton(this)
- {
- ButtonImage = { Source = imageSource },
- Command = command,
- //LabelText = labelText,
- ToolTip = toolTip,
- ToolTipText = toolTip,
- DrawingTarget = target,
- DrawingToolType = toolType
- };
- bool flag = this.flag || this.theStack2.Visibility == Visibility.Collapsed;
- if (flag)
- {
- this.theStack1.Children.Add(button);
- }
- else
- {
- this.theStack2.Children.Add(button);
- }
- flag = (this.theStack2.Visibility == Visibility.Visible || this.showNarrow);
- if (flag)
- {
- button.LabelText = "";
- }
- this.flag = !this.flag;
- }
- private void borderToolbar_SizeChanged(object sender, SizeChangedEventArgs e)
- {
- bool flag = this.theStack2.Visibility == Visibility.Visible;
- if (flag)
- {
- bool flag2 = this.borderToolbar.ActualHeight >= this.theStack1.ActualHeight + this.theStack2.ActualHeight;
- if (flag2)
- {
- this.theStack2.Visibility = Visibility.Collapsed;
- this.InitializeToolbars();
- }
- else
- {
- this.borderToolbar.Height = this.theStack1.ActualHeight + this.theStack2.ActualHeight;
- }
- }
- else
- {
- bool flag2 = this.borderToolbar.ActualHeight < this.theStack1.ActualHeight;
- if (flag2)
- {
- this.theStack2.Visibility = Visibility.Visible;
- this.InitializeToolbars();
- }
- else
- {
- this.borderToolbar.Height = this.theStack1.ActualHeight + this.theStack2.ActualHeight;
- }
- }
- }
- private IEnumerable<IDrawingTool> CreateDrawingTools()
- {
- var list = new List<IDrawingTool>();
- var list2 = new List<IDrawingTool>();
- list.Add(new DrawingTrendLine());
- list.Add(new DrawingText());
- //list.Add(new drawingFibArc());
- list.Add(new DrawingFibFan());
- list.Add(new DrawingFibRetracement());
- list.Add(new DrawingFibTimeZones());
- list2.Add(new DrawingHorizontalLine());
- list2.Add(new DrawingVerticalLine());
- //list2.Add(new drawingRegressionChannel());
- //list2.Add(new drawingRegressionLine());
- list2.Add(new DrawingGannFann());
- list2.Add(new DrawingGannBox());
- //list2.Add(new drawingAndrewsPitchfork());
- list2.Add(new DrawingQuadrantLines());
- //list2.Add(new drawingRaffRegression());
- list2.Add(new DrawingSpeedLines());
- list2.Add(new DrawingTironeLevels());
- list2.Add(new DrawingErrorChannel());
- list2.Sort(new ChartDrawingToolbar.DrawingToolComparer());
- list.AddRange(list2);
- list.Add(new DrawingEllipse());
- list.Add(new DrawingRectangle());
- list.Add(new DrawingArrow());
- return list;
- }
- private void InitializeToolbars()
- {
- this.theStack1.Children.Clear();
- this.theStack2.Children.Clear();
- this.AddDrawingToolbarButton(ImageHelper.GetImage("CrossHair.png"), PointerType.CursorWithData,
- LanguageManager.FindResource(LanguageConst.DrawingTool_Title_Cross),
- LanguageManager.FindResource(LanguageConst.DrawingTool_Title_CrossToolTip),
- DrawingToolType.Cross);
- this.AddDrawingToolbarButton(ImageHelper.GetImage("CrossHair.png"), PointerType.Cursor,
- LanguageManager.FindResource(LanguageConst.DrawingTool_Title_Plain),
- LanguageManager.FindResource(LanguageConst.DrawingTool_Title_PlainToolTip),
- DrawingToolType.Plain);
- this.AddDrawingToolbarButton(ImageHelper.GetImage("HandTransparent.png"), PointerType.Pan,
- LanguageManager.FindResource(LanguageConst.DrawingTool_Title_Pan),
- LanguageManager.FindResource(LanguageConst.DrawingTool_Title_PanToolTip),
- DrawingToolType.Pan);
- this.AddDrawingToolbarButton(ImageHelper.GetImage("Eraser.png"), PointerType.Erase,
- LanguageManager.FindResource(LanguageConst.DrawingTool_Title_Erase),
- LanguageManager.FindResource(LanguageConst.DrawingTool_Title_EraseToolTip),
- DrawingToolType.Erase);
- var drawingTools = CreateDrawingTools();
- foreach (var current in drawingTools)
- {
- this.AddDrawingToolbarButton(current.Icon(), PointerType.Drawing, current.Abbreviation(), current.Description(), current.ToolType(), current);
- }
- this.ButtonPress();
- }
- private void OnVisibleChanged()
- {
- if (VisibleChanged != null)
- {
- VisibleChanged();
- }
- }
- private void SetIsNotPressed()
- {
- if (this.theStack1 != null && this.theStack1.Children != null)
- {
- foreach (var item in this.theStack1.Children)
- {
- var frameworkElement = (FrameworkElement)item;
- if (frameworkElement is ChartDrawingToolbarButton)
- {
- ((ChartDrawingToolbarButton)frameworkElement).IsPressed = false;
- }
- }
- }
- if (this.theStack2 != null && this.theStack2.Children != null)
- {
- foreach (var item in this.theStack1.Children)
- {
- var frameworkElement = (FrameworkElement)item;
- flag = (frameworkElement is ChartDrawingToolbarButton);
- if (frameworkElement is ChartDrawingToolbarButton)
- {
- ((ChartDrawingToolbarButton)frameworkElement).IsPressed = false;
- }
- }
- }
- }
- private void SetIsPressedByPointerType()
- {
- if (this.theStack1 != null && this.theStack1.Children != null)
- {
- foreach (var item in this.theStack1.Children)
- {
- var button = (ChartDrawingToolbarButton)item;
- flag = (button != null && ParentChart != null && button.Command == ParentChart.PointerType);
- if (flag)
- {
- button.IsPressed = true;
- }
- }
- }
- if (this.theStack2 != null && this.theStack2.Children != null)
- {
- foreach (var item in this.theStack2.Children)
- {
- var button = (ChartDrawingToolbarButton)item;
- flag = (button != null && ParentChart != null && button.Command == ParentChart.PointerType);
- if (flag)
- {
- button.IsPressed = true;
- }
- }
- }
- }
- private void SetIsPressedByRootName()
- {
- if (this.theStack1 != null && this.theStack1.Children != null)
- {
- foreach (var item in this.theStack1.Children)
- {
- var button = (ChartDrawingToolbarButton)item;
- flag = button.DrawingTarget != null && ParentChart != null && ParentChart.CurrentDrawingTool != null &&
- button.DrawingTarget != null && System.String.CompareOrdinal(ParentChart.CurrentDrawingTool.RootName, button.DrawingTarget.RootName) == 0;
- if (flag)
- {
- button.IsPressed = true;
- }
- }
- }
- if (this.theStack2 != null && this.theStack2.Children != null)
- {
- foreach (var item in this.theStack2.Children)
- {
- var button = (ChartDrawingToolbarButton)item;
- flag = button.DrawingTarget != null && ParentChart != null && ParentChart.CurrentDrawingTool != null &&
- button.DrawingTarget != null && System.String.CompareOrdinal(ParentChart.CurrentDrawingTool.RootName, button.DrawingTarget.RootName) == 0;
- if (flag)
- {
- button.IsPressed = true;
- }
- }
- }
- }
- #endregion Private Methods
- #endregion Methods
- #region Nested Types
- private class DrawingToolComparer : IComparer<IDrawingTool>
- {
- #region Constructors
- public DrawingToolComparer()
- {
- }
- #endregion Constructors
- #region Methods
- #region Public Methods
- public int Compare(IDrawingTool x, IDrawingTool y)
- {
- return x.Abbreviation().CompareTo(y.Abbreviation());
- }
- #endregion Public Methods
- #endregion Methods
- }
- #endregion Nested Types
- }
- }
|