224 lines
10 KiB
C#
224 lines
10 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading;
|
||
using System.Threading.Tasks;
|
||
using System.Windows;
|
||
using System.Windows.Ink;
|
||
using System.Windows.Input;
|
||
using System.Windows.Media;
|
||
using Ink_Canvas.Helpers;
|
||
|
||
namespace Ink_Canvas {
|
||
public partial class MainWindow : PerformanceTransparentWin {
|
||
|
||
private void GridInkReplayButton_MouseUp(object sender, MouseButtonEventArgs e) {
|
||
if (lastBorderMouseDownObject != sender) return;
|
||
if (inkCanvas.Strokes.Count == 0) {
|
||
HideSubPanels();
|
||
return;
|
||
};
|
||
|
||
AnimationsHelper.HideWithSlideAndFade(BorderTools);
|
||
AnimationsHelper.HideWithSlideAndFade(BoardBorderTools);
|
||
|
||
CollapseBorderDrawShape();
|
||
|
||
InkCanvasForInkReplay.Visibility = Visibility.Visible;
|
||
InkCanvasGridForInkReplay.Visibility = Visibility.Hidden;
|
||
InkCanvasGridForInkReplay.IsHitTestVisible = false;
|
||
FloatingbarUIForInkReplay.Visibility = Visibility.Hidden;
|
||
FloatingbarUIForInkReplay.IsHitTestVisible = false;
|
||
BlackboardUIGridForInkReplay.Visibility = Visibility.Hidden;
|
||
BlackboardUIGridForInkReplay.IsHitTestVisible = false;
|
||
|
||
AnimationsHelper.ShowWithFadeIn(BorderInkReplayToolBox);
|
||
InkReplayPanelStatusText.Text = "正在重播墨迹...";
|
||
InkReplayPlayPauseBorder.Background = new SolidColorBrush(Colors.Transparent);
|
||
InkReplayPlayButtonImage.Visibility = Visibility.Collapsed;
|
||
InkReplayPauseButtonImage.Visibility = Visibility.Visible;
|
||
|
||
isStopInkReplay = false;
|
||
isPauseInkReplay = false;
|
||
isRestartInkReplay = false;
|
||
inkReplaySpeed = 1;
|
||
InkCanvasForInkReplay.Strokes.Clear();
|
||
var strokes = inkCanvas.Strokes.Clone();
|
||
if (inkCanvas.GetSelectedStrokes().Count != 0) strokes = inkCanvas.GetSelectedStrokes().Clone();
|
||
int k = 1, i = 0;
|
||
new Thread(() => {
|
||
isRestartInkReplay = true;
|
||
while (isRestartInkReplay) {
|
||
isRestartInkReplay = false;
|
||
Application.Current.Dispatcher.Invoke(() => {
|
||
InkCanvasForInkReplay.Strokes.Clear();
|
||
});
|
||
foreach (var stroke in strokes) {
|
||
|
||
if (isRestartInkReplay) break;
|
||
|
||
var stylusPoints = new StylusPointCollection();
|
||
if (stroke.StylusPoints.Count == 629) //圆或椭圆
|
||
{
|
||
Stroke s = null;
|
||
foreach (var stylusPoint in stroke.StylusPoints) {
|
||
|
||
if (isRestartInkReplay) break;
|
||
|
||
while (isPauseInkReplay) {
|
||
Thread.Sleep(10);
|
||
}
|
||
|
||
if (i++ >= 50) {
|
||
i = 0;
|
||
Thread.Sleep((int)(10 / inkReplaySpeed));
|
||
if (isStopInkReplay) return;
|
||
}
|
||
|
||
Application.Current.Dispatcher.Invoke(() => {
|
||
try {
|
||
InkCanvasForInkReplay.Strokes.Remove(s);
|
||
}
|
||
catch { }
|
||
|
||
stylusPoints.Add(stylusPoint);
|
||
s = new Stroke(stylusPoints.Clone());
|
||
s.DrawingAttributes = stroke.DrawingAttributes;
|
||
InkCanvasForInkReplay.Strokes.Add(s);
|
||
});
|
||
}
|
||
} else {
|
||
Stroke s = null;
|
||
foreach (var stylusPoint in stroke.StylusPoints) {
|
||
|
||
if (isRestartInkReplay) break;
|
||
|
||
while (isPauseInkReplay) {
|
||
Thread.Sleep(10);
|
||
}
|
||
|
||
if (i++ >= k) {
|
||
i = 0;
|
||
Thread.Sleep((int)(10 / inkReplaySpeed));
|
||
if (isStopInkReplay) return;
|
||
}
|
||
|
||
Application.Current.Dispatcher.Invoke(() => {
|
||
try {
|
||
InkCanvasForInkReplay.Strokes.Remove(s);
|
||
}
|
||
catch { }
|
||
|
||
stylusPoints.Add(stylusPoint);
|
||
s = new Stroke(stylusPoints.Clone());
|
||
s.DrawingAttributes = stroke.DrawingAttributes;
|
||
InkCanvasForInkReplay.Strokes.Add(s);
|
||
});
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
Thread.Sleep(100);
|
||
Application.Current.Dispatcher.Invoke(() => {
|
||
InkCanvasForInkReplay.Visibility = Visibility.Collapsed;
|
||
InkCanvasGridForInkReplay.Visibility = Visibility.Visible;
|
||
InkCanvasGridForInkReplay.IsHitTestVisible = true;
|
||
AnimationsHelper.HideWithFadeOut(BorderInkReplayToolBox);
|
||
FloatingbarUIForInkReplay.Visibility = Visibility.Visible;
|
||
FloatingbarUIForInkReplay.IsHitTestVisible = true;
|
||
BlackboardUIGridForInkReplay.Visibility = Visibility.Visible;
|
||
BlackboardUIGridForInkReplay.IsHitTestVisible = true;
|
||
});
|
||
}).Start();
|
||
}
|
||
|
||
#region 墨迹回放(旧版,等待重构)
|
||
|
||
private bool isStopInkReplay = false;
|
||
private bool isPauseInkReplay = false;
|
||
private bool isRestartInkReplay = false;
|
||
private double inkReplaySpeed = 1;
|
||
|
||
private void InkCanvasForInkReplay_MouseDown(object sender, MouseButtonEventArgs e) {
|
||
if (e.ClickCount == 2) {
|
||
InkCanvasForInkReplay.Visibility = Visibility.Collapsed;
|
||
InkCanvasGridForInkReplay.Visibility = Visibility.Visible;
|
||
InkCanvasGridForInkReplay.IsHitTestVisible = true;
|
||
FloatingbarUIForInkReplay.Visibility = Visibility.Visible;
|
||
FloatingbarUIForInkReplay.IsHitTestVisible = true;
|
||
BlackboardUIGridForInkReplay.Visibility = Visibility.Visible;
|
||
BlackboardUIGridForInkReplay.IsHitTestVisible = true;
|
||
AnimationsHelper.HideWithFadeOut(BorderInkReplayToolBox);
|
||
isStopInkReplay = true;
|
||
}
|
||
}
|
||
|
||
private void InkReplayPlayPauseBorder_OnMouseDown(object sender, MouseButtonEventArgs e) {
|
||
InkReplayPlayPauseBorder.Background = new SolidColorBrush(Color.FromArgb(34, 9, 9, 11));
|
||
}
|
||
|
||
private void InkReplayPlayPauseBorder_OnMouseUp(object sender, MouseButtonEventArgs e)
|
||
{
|
||
InkReplayPlayPauseBorder.Background = new SolidColorBrush(Colors.Transparent);
|
||
isPauseInkReplay = !isPauseInkReplay;
|
||
InkReplayPanelStatusText.Text = isPauseInkReplay?"已暂停!":"正在重播墨迹...";
|
||
InkReplayPlayButtonImage.Visibility = isPauseInkReplay ? Visibility.Visible: Visibility.Collapsed;
|
||
InkReplayPauseButtonImage.Visibility = !isPauseInkReplay ? Visibility.Visible : Visibility.Collapsed;
|
||
}
|
||
|
||
private void InkReplayStopButtonBorder_OnMouseDown(object sender, MouseButtonEventArgs e)
|
||
{
|
||
InkReplayStopButtonBorder.Background = new SolidColorBrush(Color.FromArgb(34, 9, 9, 11));
|
||
}
|
||
|
||
private void InkReplayStopButtonBorder_OnMouseUp(object sender, MouseButtonEventArgs e)
|
||
{
|
||
InkReplayStopButtonBorder.Background = new SolidColorBrush(Colors.Transparent);
|
||
InkCanvasForInkReplay.Visibility = Visibility.Collapsed;
|
||
InkCanvasGridForInkReplay.Visibility = Visibility.Visible;
|
||
InkCanvasGridForInkReplay.IsHitTestVisible = true;
|
||
FloatingbarUIForInkReplay.Visibility = Visibility.Visible;
|
||
FloatingbarUIForInkReplay.IsHitTestVisible = true;
|
||
BlackboardUIGridForInkReplay.Visibility = Visibility.Visible;
|
||
BlackboardUIGridForInkReplay.IsHitTestVisible = true;
|
||
AnimationsHelper.HideWithFadeOut(BorderInkReplayToolBox);
|
||
isStopInkReplay = true;
|
||
}
|
||
|
||
private void InkReplayReplayButtonBorder_OnMouseDown(object sender, MouseButtonEventArgs e)
|
||
{
|
||
InkReplayReplayButtonBorder.Background = new SolidColorBrush(Color.FromArgb(34, 9, 9, 11));
|
||
}
|
||
|
||
private void InkReplayReplayButtonBorder_OnMouseUp(object sender, MouseButtonEventArgs e)
|
||
{
|
||
InkReplayReplayButtonBorder.Background = new SolidColorBrush(Colors.Transparent);
|
||
isRestartInkReplay = true;
|
||
isPauseInkReplay = false;
|
||
InkReplayPanelStatusText.Text = "正在重播墨迹...";
|
||
InkReplayPlayButtonImage.Visibility = Visibility.Collapsed;
|
||
InkReplayPauseButtonImage.Visibility = Visibility.Visible;
|
||
}
|
||
|
||
private void InkReplaySpeedButtonBorder_OnMouseDown(object sender, MouseButtonEventArgs e)
|
||
{
|
||
InkReplaySpeedButtonBorder.Background = new SolidColorBrush(Color.FromArgb(34, 9, 9, 11));
|
||
}
|
||
|
||
private void InkReplaySpeedButtonBorder_OnMouseUp(object sender, MouseButtonEventArgs e)
|
||
{
|
||
InkReplaySpeedButtonBorder.Background = new SolidColorBrush(Colors.Transparent);
|
||
inkReplaySpeed = inkReplaySpeed == 0.5 ? 1 :
|
||
inkReplaySpeed == 1 ? 2 :
|
||
inkReplaySpeed == 2 ? 4 :
|
||
inkReplaySpeed == 4 ? 8 : 0.5;
|
||
InkReplaySpeedTextBlock.Text = inkReplaySpeed + "x";
|
||
}
|
||
|
||
#endregion
|
||
|
||
}
|
||
}
|