private void ascSort(System.Collections.Generic.IComparer<MyButton> comp) { List<MyButton> myButtonListNoArrow = new List<MyButton>(); List<MyButton> myButtonListHaveArrow = new List<MyButton>(); double _thumbInterval = _videoAnnotation.ThumbInterval; double _thumbWidth = _videoAnnotation.ThumbWidth; foreach (MyButton mb in _inkFrame.InkCollector.Sketch.MyButtons) { foreach (MyArrow ma in _inkFrame.InkCollector.Sketch.MyArrows) { if (ma.IsDeleted == false && (ma.PreMyButton == mb || ma.NextMyButton == mb) && mb.IsDeleted == false) { myButtonListHaveArrow.Add(mb); } } } double maxTop = 0; double maxHeight = 0; if (myButtonListHaveArrow.Count > 0) { maxTop = myButtonListHaveArrow[0].Top; maxHeight = myButtonListHaveArrow[0].Height; } foreach (MyButton mb in myButtonListHaveArrow) { maxTop = Math.Max(maxTop, mb.Top); maxHeight = Math.Max(maxHeight, mb.Height); } foreach (MyButton mb in _inkFrame.InkCollector.Sketch.MyButtons) { if (mb.IsDeleted == false && mb.Button.Visibility == Visibility.Collapsed) { Command vmbc = new VisibleMyButtonCommand(_inkFrame.InkCollector, mb); vmbc.execute(); } if (myButtonListHaveArrow.IndexOf(mb) == -1 && mb.IsDeleted == false) { myButtonListNoArrow.Add(mb); } } myButtonListNoArrow.Sort(comp); int ThumbIndex = 0; double _thumbVerticalInterval = _videoAnnotation.ThumbVerticalInterval; //foreach (MyButton mb in myButtonListNoArrow) int _thumbCountPerLine = _videoAnnotation.ThumbCountPerLine; for (int i = 0; i < myButtonListNoArrow.Count; i++) { double Left = _thumbInterval + (_thumbWidth + _thumbInterval) * (i % _thumbCountPerLine); double Top; if (i < _thumbCountPerLine) { Top = _thumbVerticalInterval; } else { if (i % _thumbCountPerLine == 0) { double maxTopButtonListNoArrow = myButtonListNoArrow[i - _thumbCountPerLine].Top + myButtonListNoArrow[i - _thumbCountPerLine].Height; for (int j = i - 5; j < i; j++) { double newTop = myButtonListNoArrow[j].Top + myButtonListNoArrow[j].Height; if (newTop > maxTopButtonListNoArrow) { maxTopButtonListNoArrow = newTop; } } Top = _thumbVerticalInterval + maxTopButtonListNoArrow; } else { Top = myButtonListNoArrow[(i / _thumbCountPerLine) * _thumbCountPerLine].Top; } } //double Top = _thumbInterval + maxTop + maxHeight + (_thumbWidth * (mb.Height / mb.Width) + _thumbInterval) * (ThumbIndex / 6); ButtonMoveCommand bmc = new ButtonMoveCommand(myButtonListNoArrow[i], Left - myButtonListNoArrow[i].Left, Top - myButtonListNoArrow[i].Top, _inkFrame.InkCollector); bmc.execute(); _inkFrame.InkCollector.CommandStack.Push(bmc); ThumbIndex++; } }
private void DescByVideoPathButton_Click(object sender, System.Windows.RoutedEventArgs e) { List<MyButton> myButtonListNoArrow = new List<MyButton>(); List<MyButton> myButtonListHaveArrow = new List<MyButton>(); double _thumbInterval = 80; double _thumbWidth = 120; foreach (MyButton mb in _inkFrame.InkCollector.Sketch.MyButtons) { foreach (MyArrow ma in _inkFrame.InkCollector.Sketch.MyArrows) { if (ma.IsDeleted == false && (ma.PreMyButton == mb || ma.NextMyButton == mb) && mb.IsDeleted == false) { myButtonListHaveArrow.Add(mb); } } } double maxTop = 0; double maxHeight = 0; if (myButtonListHaveArrow.Count > 0) { maxTop = myButtonListHaveArrow[0].Top; maxHeight = myButtonListHaveArrow[0].Height; } foreach (MyButton mb in myButtonListHaveArrow) { maxTop = Math.Max(maxTop, mb.Top); maxHeight = Math.Max(maxHeight, mb.Height); } foreach (MyButton mb in _inkFrame.InkCollector.Sketch.MyButtons) { if (mb.IsDeleted == false && mb.Button.Visibility == Visibility.Collapsed) { Command vmbc = new VisibleMyButtonCommand(_inkFrame.InkCollector, mb); vmbc.execute(); } if (myButtonListHaveArrow.IndexOf(mb) == -1 && mb.IsDeleted == false) { myButtonListNoArrow.Add(mb); } } myButtonListNoArrow.Sort(new ComparerVideoPath()); for (int k = myButtonListNoArrow.Count - 1; k >= 0; k--) { double Left = _thumbInterval + (_thumbWidth + _thumbInterval) * ((myButtonListNoArrow.Count-1-k) % 6); int i = myButtonListNoArrow.Count-k-1; //double Top = _thumbInterval + maxTop + maxHeight + (_thumbWidth * (myButtonListNoArrow[i].Height / myButtonListNoArrow[i].Width) + _thumbInterval) * ((myButtonListNoArrow.Count-1 - i) / 6); double Top; if (i < 6) { Top = _thumbInterval + maxTop + maxHeight; } else { if (i % 6 == 0) { double maxTopButtonListNoArrow = myButtonListNoArrow[myButtonListNoArrow.Count - i].Top + myButtonListNoArrow[myButtonListNoArrow.Count - i].Height; for (int j = myButtonListNoArrow.Count - i + 1; j < myButtonListNoArrow.Count - i+5; j++) { double newTop = myButtonListNoArrow[j].Top + myButtonListNoArrow[j].Height; if (newTop > maxTopButtonListNoArrow) { maxTopButtonListNoArrow = newTop; } } Top = _thumbInterval + maxTopButtonListNoArrow; } else { Top = myButtonListNoArrow[myButtonListNoArrow.Count-1-(i / 6) * 6].Top; } } ButtonMoveCommand bmc = new ButtonMoveCommand(myButtonListNoArrow[k], Left - myButtonListNoArrow[k].Left, Top - myButtonListNoArrow[k].Top, _inkFrame.InkCollector); bmc.execute(); _inkFrame.InkCollector.CommandStack.Push(bmc); } }
private void KeyWordsSentence_KeyDown(object sender, System.Windows.Input.KeyEventArgs e) { if (e.Key == Key.Enter) { String keyWordsSentence = KeyWordsSentence.Text; keyWordsSentence.Trim(); //显示所有的mybutton foreach (MyButton mb in _inkCollector.Sketch.MyButtons) { if (mb.IsDeleted == false) { Command vmbc = new VisibleMyButtonCommand(_inkCollector, mb); vmbc.execute(); _inkCollector.CommandStack.Push(vmbc); } } //MessageBox.Show(keyWordsSentence.Length.ToString()); List <MyButton> myButtonList = new List <MyButton>(); string[] strArray = autoStoryBoardByString(keyWordsSentence); for (int i = 0; i < strArray.Length; i++) { string CharString = strArray[i]; string otherWords = "的了吗,,。.着"; if (otherWords.IndexOf(CharString) == -1) { foreach (MyButton myButton in _inkCollector.Sketch.MyButtons) { bool findFlag = false; //第一步:检测文本 foreach (MyRichTextBox myRichTextBox in myButton.InkFrame.InkCollector.Sketch.MyRichTextBoxs) { TextRange textRange = new TextRange(myRichTextBox.RichTextBox.Document.ContentStart, myRichTextBox.RichTextBox.Document.ContentEnd); if (textRange.Text.IndexOf(CharString) > -1 && myButtonList.IndexOf(myButton) == -1) { myButtonList.Add(myButton); MessageBox.Show("MyRichTextBox:" + CharString); findFlag = true; break; } } if (findFlag) { break; } //第二步:检测图片名称 foreach (MyImage mi in myButton.InkFrame.InkCollector.Sketch.Images) { if (mi.SafeFileName.IndexOf(CharString) > -1 && myButtonList.IndexOf(myButton) == -1) { myButtonList.Add(myButton); MessageBox.Show("MyImage:" + CharString); findFlag = true; break; } } if (findFlag) { break; } //第三步:检测视频名称,全局Mybutton较优先 if (myButton.VideoFileName.IndexOf(CharString) > -1 && myButtonList.IndexOf(myButton) == -1 && myButton.IsGlobal) { myButtonList.Add(myButton); MessageBox.Show("VideoFileName:" + CharString); break; } } } } //第一步:删除不需要的Mybutton List <MyButton> myButtonOtherList = new List <MyButton>(); foreach (MyButton mb in _inkCollector.Sketch.MyButtons) { if (myButtonList.IndexOf(mb) == -1) { myButtonOtherList.Add(mb); } } //MessageBox.Show(Thumb_InkFrame._inkCanvas.Children.Count.ToString()); foreach (MyButton mb in myButtonOtherList) { Command hmbc = new HiddenMyButtonCommand(_inkCollector, mb); hmbc.execute(); _inkCollector.CommandStack.Push(hmbc); } //MessageBox.Show(Thumb_InkFrame._inkCanvas.Children.Count.ToString()); foreach (MyArrow ma in _inkCollector.Sketch.MyArrows) { DeleteArrowCommand dac = new DeleteArrowCommand(_inkCollector, ma); dac.execute(); _inkCollector.CommandStack.Push(dac); } //第二步:移动需要的Mybutton并添加连线 int ThumbIndex = 0; foreach (MyButton mb in myButtonList) { double Left = _thumbInterval + (_thumbWidth + _thumbInterval) * (ThumbIndex % 6); double Top = _thumbInterval + (_thumbWidth * (mb.Height / mb.Width) + _thumbInterval) * (ThumbIndex / 6); ButtonMoveCommand bmc = new ButtonMoveCommand(mb, Left - mb.Left, Top - mb.Top, _inkCollector); bmc.execute(); _inkCollector.CommandStack.Push(bmc); if (ThumbIndex != myButtonList.Count - 1) { ThumbConnector thumbConnector = new ThumbConnector(myButtonList[ThumbIndex], myButtonList[ThumbIndex + 1]); MyArrow ma = new MyArrow(thumbConnector.arrow); ma.PreMyButton = myButtonList[ThumbIndex]; ma.NextMyButton = myButtonList[ThumbIndex + 1]; ma.StartPoint = thumbConnector.startPoint; ma.EndPoint = thumbConnector.endPoint; Command aac = new AddArrowCommand(_inkCollector, ma); aac.execute(); _inkCollector.CommandStack.Push(aac); } ThumbIndex++; } } }