/// <summary> /// 增加一个rectangle /// </summary> /// <param name="button">要增加的Arrow</param> public void AddMySmallRectangle(MySmallRectangle msr) { mySmallRectangles.Add(msr); }
/// <summary> /// 删除一个rectangle /// </summary> /// <param name="button">要删除的Arrow</param> public void RemoveMySmallRectangle(MySmallRectangle msr) { mySmallRectangles.Remove(msr); }
public void updateRectangles(InkCanvas inkCanvas, InkCollector inkCollector) { if (isGlobal) { if (rBorder != null) { inkCanvas.Children.Remove(rBorder); } Rectangle rBorderRectangle = new Rectangle(); rBorderRectangle.HorizontalAlignment = HorizontalAlignment.Left; rBorderRectangle.VerticalAlignment = VerticalAlignment.Top; rBorderRectangle.Margin = new Thickness(Left, Top + Height, 0, 0); rBorderRectangle.Height = 10; rBorderRectangle.Width = Width; rBorderRectangle.Stroke = new SolidColorBrush(Colors.Black); if (this.Button.Visibility == Visibility.Visible) { inkCanvas.Children.Add(rBorderRectangle); } rBorder = rBorderRectangle; List <MySmallRectangle> msrs = new List <MySmallRectangle>(); foreach (MySmallRectangle msr in inkCollector.Sketch.mySmallRectangles) { if (msr.MyButton.VideoPath == this.VideoPath) { msrs.Add(msr); inkCanvas.Children.Remove(msr.Rectangle); } } foreach (MySmallRectangle msr in msrs) { inkCollector.Sketch.mySmallRectangles.Remove(msr); } List <MyButton> strokeCountMyButtonList = new List <MyButton>(); foreach (MyButton mb in inkCollector.Sketch.MyButtons) { if (mb.IsDeleted == false && mb.IsGlobal == false && mb.VideoPath == _videoPath && mb.Button.Visibility == Visibility.Visible) { strokeCountMyButtonList.Add(mb); } } int smallRectangleCount = strokeCountMyButtonList.Count; if (smallRectangleCount > 0) { strokeCountMyButtonList.Sort(new ComparerStrokeCount()); double totalTime = timeEnd; int mostStrokeCount = strokeCountMyButtonList[smallRectangleCount - 1].InkFrame._inkCanvas.Children.Count + strokeCountMyButtonList[smallRectangleCount - 1].InkFrame._inkCanvas.Strokes.Count; //最大的stroke count double rate; if (mostStrokeCount != 0) { for (int i = smallRectangleCount - 1; i >= 0; i--) { Rectangle r = new Rectangle(); r.Stroke = null; r.HorizontalAlignment = HorizontalAlignment.Left; r.VerticalAlignment = VerticalAlignment.Top; int strokeCount = strokeCountMyButtonList[i].InkFrame._inkCanvas.Children.Count + strokeCountMyButtonList[i].InkFrame._inkCanvas.Strokes.Count; r.Margin = new Thickness(rBorder.Margin.Left + 1 + rBorder.Width * (strokeCountMyButtonList[i].TimeStart / totalTime), rBorder.Margin.Top + 1, 0, 0); rate = (double)strokeCount / (double)mostStrokeCount; r.Fill = new SolidColorBrush(Color.FromRgb(255, Convert.ToByte(255 - 255 * rate), Convert.ToByte(255 - 255 * rate))); r.Height = rBorder.Height - 2; r.Width = rBorder.Width * (strokeCountMyButtonList[i].TimeEnd - strokeCountMyButtonList[i].TimeStart) / totalTime; r.MouseLeftButtonUp += new MouseButtonEventHandler(r_MouseLeftButtonUp); MySmallRectangle msr = new MySmallRectangle(r); inkCollector.Sketch.mySmallRectangles.Add(msr); msr.MyButton = strokeCountMyButtonList[i]; msr.ParentMyButton = this; if (this.Button.Visibility == Visibility.Visible) { inkCanvas.Children.Add(r); } } } } } else { foreach (MyButton mb in inkCollector.Sketch.MyButtons) { if (mb.isDeleted == false && mb.isGlobal && mb.VideoPath == VideoPath) { if (mb.rBorder != null) { inkCanvas.Children.Remove(mb.rBorder); } Rectangle rBorderRectangle = new Rectangle(); rBorderRectangle.HorizontalAlignment = HorizontalAlignment.Left; rBorderRectangle.VerticalAlignment = VerticalAlignment.Top; rBorderRectangle.Margin = new Thickness(mb.Left, mb.Top + mb.Height, 0, 0); rBorderRectangle.Height = 10; rBorderRectangle.Width = mb.Width; rBorderRectangle.Stroke = new SolidColorBrush(Colors.Black); if (mb.Button.Visibility == Visibility.Visible) { inkCanvas.Children.Add(rBorderRectangle); } mb.rBorder = rBorderRectangle; List <MySmallRectangle> msrs = new List <MySmallRectangle>(); foreach (MySmallRectangle msr in inkCollector.Sketch.mySmallRectangles) { if (msr.MyButton.VideoPath == this.VideoPath) { msrs.Add(msr); inkCanvas.Children.Remove(msr.Rectangle); } } foreach (MySmallRectangle msr in msrs) { inkCollector.Sketch.mySmallRectangles.Remove(msr); } List <MyButton> strokeCountMyButtonList = new List <MyButton>(); foreach (MyButton m in inkCollector.Sketch.MyButtons) { if (m.IsDeleted == false && m.IsGlobal == false && m.VideoPath == _videoPath && m.Button.Visibility == Visibility.Visible) { strokeCountMyButtonList.Add(m); } } strokeCountMyButtonList.Add(this); int smallRectangleCount = strokeCountMyButtonList.Count; if (smallRectangleCount > 0) { strokeCountMyButtonList.Sort(new ComparerStrokeCount()); double totalTime = mb.TimeEnd; int mostStrokeCount = strokeCountMyButtonList[smallRectangleCount - 1].InkFrame._inkCanvas.Children.Count + strokeCountMyButtonList[smallRectangleCount - 1].InkFrame._inkCanvas.Strokes.Count; //最大的stroke count if (mostStrokeCount != 0) { for (int i = smallRectangleCount - 1; i >= 0; i--) { Rectangle r = new Rectangle(); r.Stroke = null; r.HorizontalAlignment = HorizontalAlignment.Left; r.VerticalAlignment = VerticalAlignment.Top; int strokeCount = strokeCountMyButtonList[i].InkFrame._inkCanvas.Children.Count + strokeCountMyButtonList[i].InkFrame._inkCanvas.Strokes.Count; r.Margin = new Thickness(rBorderRectangle.Margin.Left + 1 + rBorderRectangle.Width * (strokeCountMyButtonList[i].TimeStart / totalTime), rBorderRectangle.Margin.Top + 1, 0, 0); r.Fill = new SolidColorBrush(Color.FromRgb(255, Convert.ToByte(255 - 255 * (double)strokeCount / (double)mostStrokeCount), Convert.ToByte(255 - 255 * (double)strokeCount / (double)mostStrokeCount))); r.Height = rBorderRectangle.Height - 2; r.Width = rBorderRectangle.Width * (strokeCountMyButtonList[i].TimeEnd - strokeCountMyButtonList[i].TimeStart) / totalTime; r.MouseLeftButtonUp += new MouseButtonEventHandler(r_MouseLeftButtonUp); MySmallRectangle msr = new MySmallRectangle(r); inkCollector.Sketch.mySmallRectangles.Add(msr); msr.MyButton = strokeCountMyButtonList[i]; msr.ParentMyButton = mb; if (mb.Button.Visibility == Visibility.Visible) { inkCanvas.Children.Add(r); } } } } break; } } } }