InkCanvasForClass/Ink Canvas/MainWindow_cs/MW_FloatingBarIcons.cs

1839 lines
71 KiB
C#
Raw Normal View History

2024-05-01 18:23:32 +08:00
using Ink_Canvas.Helpers;
using System;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Threading;
using System.Windows.Interop;
using System.Windows.Media.Imaging;
using iNKORE.UI.WPF.Modern;
using System.Threading;
using Application = System.Windows.Application;
using Point = System.Windows.Point;
using System.Diagnostics;
using iNKORE.UI.WPF.Modern.Controls;
using System.IO;
using System.Windows.Media.Effects;
using static System.Net.Mime.MediaTypeNames;
using System.Text;
using System.Globalization;
using System.Windows.Data;
using System.Xml.Linq;
2024-05-01 18:23:32 +08:00
namespace Ink_Canvas
{
public partial class MainWindow : Window
{
2024-05-01 18:23:32 +08:00
#region TwoFingZoomBtn
private void TwoFingerGestureBorder_MouseUp(object sender, RoutedEventArgs e)
{
if (TwoFingerGestureBorder.Visibility == Visibility.Visible)
{
2024-05-01 18:23:32 +08:00
AnimationsHelper.HideWithSlideAndFade(TwoFingerGestureBorder);
AnimationsHelper.HideWithSlideAndFade(BoardTwoFingerGestureBorder);
}
else
{
2024-05-01 18:23:32 +08:00
AnimationsHelper.ShowWithSlideFromBottomAndFade(TwoFingerGestureBorder);
AnimationsHelper.ShowWithSlideFromBottomAndFade(BoardTwoFingerGestureBorder);
}
}
private void CheckEnableTwoFingerGestureBtnColorPrompt()
{
if (ToggleSwitchEnableMultiTouchMode.IsOn)
{
2024-05-01 22:48:28 +08:00
TwoFingerGestureSimpleStackPanel.Opacity = 0.5;
TwoFingerGestureSimpleStackPanel.IsHitTestVisible = false;
2024-05-02 15:49:23 +08:00
EnableTwoFingerGestureBtn.Source = new BitmapImage(new Uri("/Resources/new-icons/gesture.png", UriKind.Relative));
BoardEnableTwoFingerGestureBtn.Source = new BitmapImage(new Uri("/Resources/new-icons/gesture.png", UriKind.Relative));
}
else
{
2024-05-01 22:48:28 +08:00
TwoFingerGestureSimpleStackPanel.Opacity = 1;
TwoFingerGestureSimpleStackPanel.IsHitTestVisible = true;
if (Settings.Gesture.IsEnableTwoFingerGesture)
{
2024-05-02 15:49:23 +08:00
EnableTwoFingerGestureBtn.Source = new BitmapImage(new Uri("/Resources/new-icons/gesture-enabled.png", UriKind.Relative));
BoardEnableTwoFingerGestureBtn.Source = new BitmapImage(new Uri("/Resources/new-icons/gesture-enabled.png", UriKind.Relative));
}
else
{
2024-05-02 15:49:23 +08:00
EnableTwoFingerGestureBtn.Source = new BitmapImage(new Uri("/Resources/new-icons/gesture.png", UriKind.Relative));
BoardEnableTwoFingerGestureBtn.Source = new BitmapImage(new Uri("/Resources/new-icons/gesture.png", UriKind.Relative));
2024-05-01 22:48:28 +08:00
}
}
2024-05-01 18:23:32 +08:00
}
private void CheckEnableTwoFingerGestureBtnVisibility(bool isVisible)
{
2024-05-01 18:23:32 +08:00
if (StackPanelCanvasControls.Visibility != Visibility.Visible
|| BorderFloatingBarMainControls.Visibility != Visibility.Visible)
{
2024-05-01 18:23:32 +08:00
EnableTwoFingerGestureBorder.Visibility = Visibility.Collapsed;
}
else if (isVisible == true)
{
2024-05-01 18:23:32 +08:00
if (BtnPPTSlideShowEnd.Visibility == Visibility.Visible) EnableTwoFingerGestureBorder.Visibility = Visibility.Collapsed;
else EnableTwoFingerGestureBorder.Visibility = Visibility.Visible;
}
else EnableTwoFingerGestureBorder.Visibility = Visibility.Collapsed;
2024-05-01 18:23:32 +08:00
}
#endregion TwoFingZoomBtn
#region Drag
bool isDragDropInEffect = false;
Point pos = new Point();
Point downPos = new Point();
Point pointDesktop = new Point(-1, -1); //用于记录上次在桌面时的坐标
Point pointPPT = new Point(-1, -1); //用于记录上次在PPT中的坐标
void SymbolIconEmoji_MouseMove(object sender, MouseEventArgs e)
{
if (isDragDropInEffect)
{
2024-05-01 18:23:32 +08:00
double xPos = e.GetPosition(null).X - pos.X + ViewboxFloatingBar.Margin.Left;
double yPos = e.GetPosition(null).Y - pos.Y + ViewboxFloatingBar.Margin.Top;
ViewboxFloatingBar.Margin = new Thickness(xPos, yPos, -2000, -200);
pos = e.GetPosition(null);
if (BtnPPTSlideShowEnd.Visibility == Visibility.Visible)
{
2024-05-01 18:23:32 +08:00
pointPPT = new Point(xPos, yPos);
}
else
{
2024-05-01 18:23:32 +08:00
pointDesktop = new Point(xPos, yPos);
}
}
}
void SymbolIconEmoji_MouseDown(object sender, MouseButtonEventArgs e)
{
if (isViewboxFloatingBarMarginAnimationRunning)
{
2024-05-01 18:23:32 +08:00
ViewboxFloatingBar.BeginAnimation(FrameworkElement.MarginProperty, null);
isViewboxFloatingBarMarginAnimationRunning = false;
}
isDragDropInEffect = true;
pos = e.GetPosition(null);
downPos = e.GetPosition(null);
GridForFloatingBarDraging.Visibility = Visibility.Visible;
}
void SymbolIconEmoji_MouseUp(object sender, MouseButtonEventArgs e)
{
2024-05-01 18:23:32 +08:00
isDragDropInEffect = false;
if (e is null || Math.Abs(downPos.X - e.GetPosition(null).X) <= 10 && Math.Abs(downPos.Y - e.GetPosition(null).Y) <= 10)
{
if (BorderFloatingBarMainControls.Visibility == Visibility.Visible)
{
2024-05-01 18:23:32 +08:00
BorderFloatingBarMainControls.Visibility = Visibility.Collapsed;
CheckEnableTwoFingerGestureBtnVisibility(false);
}
else
{
2024-05-01 18:23:32 +08:00
BorderFloatingBarMainControls.Visibility = Visibility.Visible;
CheckEnableTwoFingerGestureBtnVisibility(true);
}
}
GridForFloatingBarDraging.Visibility = Visibility.Collapsed;
}
#endregion
private void HideSubPanelsImmediately()
{
2024-05-01 18:23:32 +08:00
BorderTools.Visibility = Visibility.Collapsed;
BorderTools.Visibility = Visibility.Collapsed;
BoardBorderTools.Visibility = Visibility.Collapsed;
PenPalette.Visibility = Visibility.Collapsed;
BoardPenPalette.Visibility = Visibility.Collapsed;
BoardDeleteIcon.Visibility = Visibility.Collapsed;
BorderSettings.Visibility = Visibility.Collapsed;
}
#region
private async void HideSubPanels(String mode = null, bool autoAlignCenter = false, bool isAutoUpdateToolbarSelection = true)
{
2024-05-01 18:23:32 +08:00
AnimationsHelper.HideWithSlideAndFade(BorderTools);
AnimationsHelper.HideWithSlideAndFade(BoardBorderTools);
AnimationsHelper.HideWithSlideAndFade(PenPalette);
AnimationsHelper.HideWithSlideAndFade(BoardPenPalette);
AnimationsHelper.HideWithSlideAndFade(BoardDeleteIcon);
if (BorderSettings.Visibility == Visibility.Visible)
{
BorderSettingsMask.IsHitTestVisible = false;
BorderSettingsMask.Background = null;
var sb = new Storyboard();
// 滑动动画
var slideAnimation = new DoubleAnimation
{
From = 0, // 滑动距离
To = BorderSettings.RenderTransform.Value.OffsetX - 440,
Duration = TimeSpan.FromSeconds(0.6)
};
slideAnimation.EasingFunction = new CubicEase() { EasingMode = EasingMode.EaseOut };
Storyboard.SetTargetProperty(slideAnimation, new PropertyPath("(UIElement.RenderTransform).(TranslateTransform.X)"));
sb.Children.Add(slideAnimation);
sb.Completed += (s, _) =>
{
BorderSettings.Visibility = Visibility.Collapsed;
isOpeningOrHidingSettingsPane = false;
};
BorderSettings.Visibility = Visibility.Visible;
BorderSettings.RenderTransform = new TranslateTransform();
isOpeningOrHidingSettingsPane = true;
sb.Begin((FrameworkElement)BorderSettings);
}
2024-05-01 18:23:32 +08:00
AnimationsHelper.HideWithSlideAndFade(TwoFingerGestureBorder);
AnimationsHelper.HideWithSlideAndFade(EraserSizePanel);
2024-05-01 18:23:32 +08:00
AnimationsHelper.HideWithSlideAndFade(BoardTwoFingerGestureBorder);
if (ToggleSwitchDrawShapeBorderAutoHide.IsOn)
{
2024-05-01 18:23:32 +08:00
AnimationsHelper.HideWithSlideAndFade(BorderDrawShape);
AnimationsHelper.HideWithSlideAndFade(BoardBorderDrawShape);
}
if (mode != null && isAutoUpdateToolbarSelection==true)
{
if (mode != "clear")
{
CursorIconGeometry.Brush = new SolidColorBrush(Color.FromRgb(27, 27, 27));
CursorIconGeometry.Geometry = Geometry.Parse(XamlGraphicsIconGeometries.LinedCursorIcon);
PenIconGeometry.Brush = new SolidColorBrush(Color.FromRgb(27, 27, 27));
PenIconGeometry.Geometry = Geometry.Parse(XamlGraphicsIconGeometries.LinedPenIcon);
StrokeEraserIconGeometry.Brush = new SolidColorBrush(Color.FromRgb(27, 27, 27));
StrokeEraserIconGeometry.Geometry = Geometry.Parse(XamlGraphicsIconGeometries.LinedEraserStrokeIcon);
CircleEraserIconGeometry.Brush = new SolidColorBrush(Color.FromRgb(27, 27, 27));
CircleEraserIconGeometry.Geometry = Geometry.Parse(XamlGraphicsIconGeometries.LinedEraserCircleIcon);
LassoSelectIconGeometry.Brush = new SolidColorBrush(Color.FromRgb(27, 27, 27));
LassoSelectIconGeometry.Geometry = Geometry.Parse(XamlGraphicsIconGeometries.LinedLassoSelectIcon);
2024-05-01 18:23:32 +08:00
}
switch (mode)
{
case "pen":
case "color":
{
PenIconGeometry.Brush = new SolidColorBrush(Color.FromRgb(30, 58, 138));
PenIconGeometry.Geometry = Geometry.Parse(XamlGraphicsIconGeometries.SolidPenIcon);
break;
}
case "eraser":
{
CircleEraserIconGeometry.Brush = new SolidColorBrush(Color.FromRgb(30, 58, 138));
CircleEraserIconGeometry.Geometry = Geometry.Parse(XamlGraphicsIconGeometries.SolidEraserCircleIcon);
break;
}
case "eraserByStrokes":
{
StrokeEraserIconGeometry.Brush = new SolidColorBrush(Color.FromRgb(30, 58, 138));
StrokeEraserIconGeometry.Geometry = Geometry.Parse(XamlGraphicsIconGeometries.SolidEraserStrokeIcon);
break;
}
case "select":
{
LassoSelectIconGeometry.Brush = new SolidColorBrush(Color.FromRgb(30, 58, 138));
LassoSelectIconGeometry.Geometry = Geometry.Parse(XamlGraphicsIconGeometries.SolidLassoSelectIcon);
break;
}
2024-05-01 18:23:32 +08:00
}
if (autoAlignCenter) // 控制居中
{
if (BtnPPTSlideShowEnd.Visibility == Visibility.Visible)
{
2024-05-01 18:23:32 +08:00
await Task.Delay(50);
ViewboxFloatingBarMarginAnimation(60);
}
else if (Topmost == true) //非黑板
{
2024-05-01 18:23:32 +08:00
await Task.Delay(50);
ViewboxFloatingBarMarginAnimation(100, true);
}
else //黑板
{
2024-05-01 18:23:32 +08:00
await Task.Delay(50);
ViewboxFloatingBarMarginAnimation(60);
}
}
}
2024-05-01 18:23:32 +08:00
await Task.Delay(150);
isHidingSubPanelsWhenInking = false;
}
#endregion
2024-05-01 18:23:32 +08:00
private void BorderPenColorBlack_MouseUp(object sender, MouseButtonEventArgs e)
{
2024-05-01 18:23:32 +08:00
BtnColorBlack_Click(null, null);
HideSubPanels();
}
private void BorderPenColorRed_MouseUp(object sender, MouseButtonEventArgs e)
{
2024-05-01 18:23:32 +08:00
BtnColorRed_Click(null, null);
HideSubPanels();
}
private void BorderPenColorGreen_MouseUp(object sender, MouseButtonEventArgs e)
{
2024-05-01 18:23:32 +08:00
BtnColorGreen_Click(null, null);
HideSubPanels();
}
private void BorderPenColorBlue_MouseUp(object sender, MouseButtonEventArgs e)
{
2024-05-01 18:23:32 +08:00
BtnColorBlue_Click(null, null);
HideSubPanels();
}
private void BorderPenColorYellow_MouseUp(object sender, MouseButtonEventArgs e)
{
2024-05-01 18:23:32 +08:00
BtnColorYellow_Click(null, null);
HideSubPanels();
}
private void BorderPenColorWhite_MouseUp(object sender, MouseButtonEventArgs e)
{
2024-05-01 18:23:32 +08:00
inkCanvas.DefaultDrawingAttributes.Color = StringToColor("#FFFEFEFE");
inkColor = 5;
ColorSwitchCheck();
HideSubPanels();
}
private void SymbolIconUndo_MouseUp(object sender, MouseButtonEventArgs e)
{
//if (lastBorderMouseDownObject != sender) return;
2024-05-01 18:23:32 +08:00
if (!BtnUndo.IsEnabled) return;
BtnUndo_Click(BtnUndo, null);
HideSubPanels();
}
private void SymbolIconRedo_MouseUp(object sender, MouseButtonEventArgs e)
{
//if (lastBorderMouseDownObject != sender) return;
2024-05-01 18:23:32 +08:00
if (!BtnRedo.IsEnabled) return;
BtnRedo_Click(BtnRedo, null);
HideSubPanels();
}
private async void SymbolIconCursor_Click(object sender, RoutedEventArgs e)
{
if (currentMode != 0)
{
2024-05-01 18:23:32 +08:00
ImageBlackboard_MouseUp(null, null);
}
else
{
2024-05-01 18:23:32 +08:00
BtnHideInkCanvas_Click(BtnHideInkCanvas, null);
if (BtnPPTSlideShowEnd.Visibility == Visibility.Visible)
{
2024-05-01 18:23:32 +08:00
await Task.Delay(100);
ViewboxFloatingBarMarginAnimation(60);
}
}
}
private void SymbolIconDelete_MouseUp(object sender, MouseButtonEventArgs e)
{
if (inkCanvas.GetSelectedStrokes().Count > 0)
{
2024-05-01 18:23:32 +08:00
inkCanvas.Strokes.Remove(inkCanvas.GetSelectedStrokes());
GridInkCanvasSelectionCover.Visibility = Visibility.Collapsed;
}
else if (inkCanvas.Strokes.Count > 0)
{
if (Settings.Automation.IsAutoSaveStrokesAtClear && inkCanvas.Strokes.Count > Settings.Automation.MinimumAutomationStrokeNumber)
{
2024-05-01 18:23:32 +08:00
if (BtnPPTSlideShowEnd.Visibility == Visibility.Visible)
SaveScreenShot(true, $"{pptName}/{previousSlideID}_{DateTime.Now:HH-mm-ss}");
else
SaveScreenShot(true);
}
BtnClear_Click(null, null);
}
}
private void SymbolIconSettings_Click(object sender, RoutedEventArgs e)
{
if (isOpeningOrHidingSettingsPane != false) return;
2024-05-01 18:23:32 +08:00
HideSubPanels();
BtnSettings_Click(null, null);
}
private void SymbolIconSelect_MouseUp(object sender, MouseButtonEventArgs e)
{
FloatingbarSelectionBG.Visibility = Visibility.Visible;
System.Windows.Controls.Canvas.SetLeft(FloatingbarSelectionBG, 140);
2024-05-01 18:23:32 +08:00
BtnSelect_Click(null, null);
HideSubPanels("select");
}
private async void SymbolIconScreenshot_MouseUp(object sender, MouseButtonEventArgs e)
{
2024-05-01 18:23:32 +08:00
HideSubPanelsImmediately();
await Task.Delay(50);
SaveScreenShotToDesktop();
}
bool Not_Enter_Blackboard_fir_Mouse_Click = true;
bool isDisplayingOrHidingBlackboard = false;
private void ImageBlackboard_MouseUp(object sender, MouseButtonEventArgs e)
{
2024-05-12 16:12:15 +08:00
LeftUnFoldButtonQuickPanel.Visibility = Visibility.Collapsed;
RightUnFoldButtonQuickPanel.Visibility = Visibility.Collapsed;
2024-05-01 18:23:32 +08:00
if (isDisplayingOrHidingBlackboard) return;
isDisplayingOrHidingBlackboard = true;
UnFoldFloatingBar_MouseUp(null, null);
2024-05-01 18:23:32 +08:00
if (inkCanvas.EditingMode == InkCanvasEditingMode.Select) PenIcon_Click(null, null);
if (currentMode == 0)
{
2024-05-01 18:23:32 +08:00
BottomViewboxPPTSidesControl.Visibility = Visibility.Collapsed;
LeftSidePanelForPPTNavigation.Visibility = Visibility.Collapsed;
RightSidePanelForPPTNavigation.Visibility = Visibility.Collapsed;
//进入黑板
/*
if (Not_Enter_Blackboard_fir_Mouse_Click) {// BUG-Fixed_tmp程序启动后直接进入白板会导致后续撤销功能、退出白板无法恢复墨迹
BtnColorRed_Click(BorderPenColorRed, null);
await Task.Delay(200);
SimulateMouseClick.SimulateMouseClickAtTopLeft();
await Task.Delay(10);
Not_Enter_Blackboard_fir_Mouse_Click = false;
}
*/
new Thread(new ThreadStart(() => {
Thread.Sleep(100);
Application.Current.Dispatcher.Invoke(() => {
ViewboxFloatingBarMarginAnimation(60);
});
})).Start();
2024-05-14 02:10:21 +08:00
if (Settings.Canvas.UsingWhiteboard)
{
2024-05-01 18:23:32 +08:00
BorderPenColorBlack_MouseUp(BorderPenColorBlack, null);
2024-05-14 02:10:21 +08:00
}
else
{
2024-05-01 18:23:32 +08:00
BorderPenColorWhite_MouseUp(BorderPenColorWhite, null);
}
if (Settings.Gesture.AutoSwitchTwoFingerGesture) // 自动关闭多指书写、开启双指移动
{
ToggleSwitchEnableTwoFingerTranslate.IsOn = true;
if (isInMultiTouchMode) ToggleSwitchEnableMultiTouchMode.IsOn = false;
}
if (Settings.Appearance.EnableTimeDisplayInWhiteboardMode == true)
{
WaterMarkTime.Visibility = Visibility.Visible;
WaterMarkDate.Visibility = Visibility.Visible;
}
BlackBoardWaterMark.Visibility = Visibility.Visible;
}
else
{
2024-05-01 18:23:32 +08:00
//关闭黑板
HideSubPanelsImmediately();
if (StackPanelPPTControls.Visibility == Visibility.Visible)
{
if (Settings.PowerPointSettings.IsShowBottomPPTNavigationPanel)
{
2024-05-01 18:23:32 +08:00
AnimationsHelper.ShowWithSlideFromBottomAndFade(BottomViewboxPPTSidesControl);
}
if (Settings.PowerPointSettings.IsShowSidePPTNavigationPanel)
{
2024-05-01 18:23:32 +08:00
AnimationsHelper.ShowWithScaleFromLeft(LeftSidePanelForPPTNavigation);
AnimationsHelper.ShowWithScaleFromRight(RightSidePanelForPPTNavigation);
}
}
if (Settings.Automation.IsAutoSaveStrokesAtClear && inkCanvas.Strokes.Count > Settings.Automation.MinimumAutomationStrokeNumber)
{
2024-05-01 18:23:32 +08:00
SaveScreenShot(true);
}
if (BtnPPTSlideShowEnd.Visibility == Visibility.Collapsed)
{
2024-05-01 18:23:32 +08:00
new Thread(new ThreadStart(() => {
Thread.Sleep(100);
Application.Current.Dispatcher.Invoke(() => {
ViewboxFloatingBarMarginAnimation(100, true);
2024-05-01 18:23:32 +08:00
});
})).Start();
}
else
{
2024-05-01 18:23:32 +08:00
new Thread(new ThreadStart(() => {
Thread.Sleep(100);
Application.Current.Dispatcher.Invoke(() => {
ViewboxFloatingBarMarginAnimation(60);
});
})).Start();
}
if (Pen_Icon.Background == null)
{
2024-05-01 18:23:32 +08:00
PenIcon_Click(null, null);
}
if (Settings.Gesture.AutoSwitchTwoFingerGesture) // 自动启用多指书写
{
ToggleSwitchEnableTwoFingerTranslate.IsOn = false;
2024-05-02 15:49:23 +08:00
// 2024.5.2 need to be tested
// if (!isInMultiTouchMode) ToggleSwitchEnableMultiTouchMode.IsOn = true;
}
WaterMarkTime.Visibility = Visibility.Collapsed;
WaterMarkDate.Visibility = Visibility.Collapsed;
BlackBoardWaterMark.Visibility = Visibility.Collapsed;
2024-05-01 18:23:32 +08:00
}
BtnSwitch_Click(BtnSwitch, null);
if (currentMode == 0 && inkCanvas.Strokes.Count == 0 && BtnPPTSlideShowEnd.Visibility != Visibility.Visible)
{
2024-05-01 18:23:32 +08:00
CursorIcon_Click(null, null);
}
BtnExit.Foreground = Brushes.White;
ThemeManager.Current.ApplicationTheme = ApplicationTheme.Dark;
new Thread(new ThreadStart(() => {
Thread.Sleep(200);
Application.Current.Dispatcher.Invoke(() => {
isDisplayingOrHidingBlackboard = false;
});
})).Start();
SwitchToDefaultPen(null, null);
2024-05-01 18:23:32 +08:00
CheckColorTheme(true);
}
private void ImageCountdownTimer_MouseUp(object sender, MouseButtonEventArgs e)
{
2024-05-12 16:12:15 +08:00
LeftUnFoldButtonQuickPanel.Visibility = Visibility.Collapsed;
RightUnFoldButtonQuickPanel.Visibility = Visibility.Collapsed;
2024-05-01 18:23:32 +08:00
AnimationsHelper.HideWithSlideAndFade(BorderTools);
AnimationsHelper.HideWithSlideAndFade(BoardBorderTools);
new CountdownTimerWindow().Show();
}
private void OperatingGuideWindowIcon_MouseUp(object sender, MouseButtonEventArgs e)
{
2024-05-01 18:23:32 +08:00
AnimationsHelper.HideWithSlideAndFade(BorderTools);
AnimationsHelper.HideWithSlideAndFade(BoardBorderTools);
new OperatingGuideWindow().Show();
}
private void SymbolIconRand_MouseUp(object sender, MouseButtonEventArgs e)
{
2024-05-12 16:12:15 +08:00
LeftUnFoldButtonQuickPanel.Visibility = Visibility.Collapsed;
RightUnFoldButtonQuickPanel.Visibility = Visibility.Collapsed;
2024-05-01 18:23:32 +08:00
if (lastBorderMouseDownObject != sender) return;
AnimationsHelper.HideWithSlideAndFade(BorderTools);
AnimationsHelper.HideWithSlideAndFade(BoardBorderTools);
new RandWindow().Show();
}
public void CheckEraserTypeTab()
{
if (Settings.Canvas.EraserShapeType == 0)
{
CircleEraserTabButton.Background = new SolidColorBrush(Color.FromArgb(85, 59, 130, 246));
CircleEraserTabButton.Opacity = 1;
CircleEraserTabButtonText.FontWeight = FontWeights.Bold;
CircleEraserTabButtonText.Margin = new Thickness(2, 0.5, 0, 0);
CircleEraserTabButtonText.FontSize = 9.5;
CircleEraserTabButtonIndicator.Visibility = Visibility.Visible;
RectangleEraserTabButton.Background = new SolidColorBrush(Colors.Transparent);
RectangleEraserTabButton.Opacity = 0.75;
RectangleEraserTabButtonText.FontWeight = FontWeights.Normal;
RectangleEraserTabButtonText.FontSize = 9;
RectangleEraserTabButtonText.Margin = new Thickness(2, 1, 0, 0);
RectangleEraserTabButtonIndicator.Visibility = Visibility.Collapsed;
}
else
{
RectangleEraserTabButton.Background = new SolidColorBrush(Color.FromArgb(85, 59, 130, 246));
RectangleEraserTabButton.Opacity = 1;
RectangleEraserTabButtonText.FontWeight = FontWeights.Bold;
RectangleEraserTabButtonText.Margin = new Thickness(2, 0.5, 0, 0);
RectangleEraserTabButtonText.FontSize = 9.5;
RectangleEraserTabButtonIndicator.Visibility = Visibility.Visible;
CircleEraserTabButton.Background = new SolidColorBrush(Colors.Transparent);
CircleEraserTabButton.Opacity = 0.75;
CircleEraserTabButtonText.FontWeight = FontWeights.Normal;
CircleEraserTabButtonText.FontSize = 9;
CircleEraserTabButtonText.Margin = new Thickness(2, 1, 0, 0);
CircleEraserTabButtonIndicator.Visibility = Visibility.Collapsed;
}
}
private void SymbolIconRandOne_MouseUp(object sender, MouseButtonEventArgs e)
{
2024-05-12 16:12:15 +08:00
LeftUnFoldButtonQuickPanel.Visibility = Visibility.Collapsed;
RightUnFoldButtonQuickPanel.Visibility = Visibility.Collapsed;
2024-05-01 18:23:32 +08:00
if (lastBorderMouseDownObject != sender) return;
AnimationsHelper.HideWithSlideAndFade(BorderTools);
AnimationsHelper.HideWithSlideAndFade(BoardBorderTools);
new RandWindow(true).ShowDialog();
}
private void GridInkReplayButton_MouseUp(object sender, MouseButtonEventArgs e)
{
2024-05-01 18:23:32 +08:00
if (lastBorderMouseDownObject != sender) return;
AnimationsHelper.HideWithSlideAndFade(BorderTools);
AnimationsHelper.HideWithSlideAndFade(BoardBorderTools);
CollapseBorderDrawShape();
InkCanvasForInkReplay.Visibility = Visibility.Visible;
inkCanvas.Visibility = Visibility.Collapsed;
isStopInkReplay = false;
InkCanvasForInkReplay.Strokes.Clear();
StrokeCollection strokes = inkCanvas.Strokes.Clone();
if (inkCanvas.GetSelectedStrokes().Count != 0)
{
2024-05-01 18:23:32 +08:00
strokes = inkCanvas.GetSelectedStrokes().Clone();
}
int k = 1, i = 0;
new Thread(new ThreadStart(() => {
foreach (Stroke stroke in strokes)
{
2024-05-01 18:23:32 +08:00
StylusPointCollection stylusPoints = new StylusPointCollection();
if (stroke.StylusPoints.Count == 629) //圆或椭圆
{
Stroke s = null;
foreach (StylusPoint stylusPoint in stroke.StylusPoints)
{
if (i++ >= 50)
{
2024-05-01 18:23:32 +08:00
i = 0;
Thread.Sleep(10);
if (isStopInkReplay) return;
}
Application.Current.Dispatcher.Invoke(() => {
try
{
2024-05-01 18:23:32 +08:00
InkCanvasForInkReplay.Strokes.Remove(s);
}
catch { }
2024-05-01 18:23:32 +08:00
stylusPoints.Add(stylusPoint);
s = new Stroke(stylusPoints.Clone());
s.DrawingAttributes = stroke.DrawingAttributes;
InkCanvasForInkReplay.Strokes.Add(s);
});
}
}
else
{
2024-05-01 18:23:32 +08:00
Stroke s = null;
foreach (StylusPoint stylusPoint in stroke.StylusPoints)
{
if (i++ >= k)
{
2024-05-01 18:23:32 +08:00
i = 0;
Thread.Sleep(10);
if (isStopInkReplay) return;
}
Application.Current.Dispatcher.Invoke(() => {
try
{
2024-05-01 18:23:32 +08:00
InkCanvasForInkReplay.Strokes.Remove(s);
}
catch { }
2024-05-01 18:23:32 +08:00
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;
inkCanvas.Visibility = Visibility.Visible;
});
})).Start();
}
bool isStopInkReplay = false;
private void InkCanvasForInkReplay_MouseDown(object sender, MouseButtonEventArgs e)
{
if (e.ClickCount == 2)
{
2024-05-01 18:23:32 +08:00
InkCanvasForInkReplay.Visibility = Visibility.Collapsed;
inkCanvas.Visibility = Visibility.Visible;
isStopInkReplay = true;
}
}
private void SymbolIconTools_MouseUp(object sender, MouseButtonEventArgs e)
{
if (BorderTools.Visibility == Visibility.Visible)
{
2024-05-01 18:23:32 +08:00
AnimationsHelper.HideWithSlideAndFade(BorderTools);
AnimationsHelper.HideWithSlideAndFade(BoardBorderTools);
}
else
{
2024-05-01 18:23:32 +08:00
AnimationsHelper.ShowWithSlideFromBottomAndFade(BorderTools);
AnimationsHelper.ShowWithSlideFromBottomAndFade(BoardBorderTools);
}
}
bool isViewboxFloatingBarMarginAnimationRunning = false;
private async void ViewboxFloatingBarMarginAnimation(int MarginFromEdge, bool PosXCaculatedWithTaskbarHeight = false)
{
if (MarginFromEdge == 60)
{
MarginFromEdge = 55;
2024-05-01 18:23:32 +08:00
}
await Dispatcher.InvokeAsync(() => {
if (Topmost == false)
{
MarginFromEdge = -60;
}
else
{
2024-05-01 18:23:32 +08:00
ViewboxFloatingBar.Visibility = Visibility.Visible;
}
isViewboxFloatingBarMarginAnimationRunning = true;
double dpiScaleX = 1, dpiScaleY = 1;
PresentationSource source = PresentationSource.FromVisual(this);
if (source != null)
{
2024-05-01 18:23:32 +08:00
dpiScaleX = source.CompositionTarget.TransformToDevice.M11;
dpiScaleY = source.CompositionTarget.TransformToDevice.M22;
}
IntPtr windowHandle = new WindowInteropHelper(this).Handle;
System.Windows.Forms.Screen screen = System.Windows.Forms.Screen.FromHandle(windowHandle);
double screenWidth = screen.Bounds.Width / dpiScaleX, screenHeight = screen.Bounds.Height / dpiScaleY;
double toolbarHeight = SystemParameters.PrimaryScreenHeight - SystemParameters.FullPrimaryScreenHeight - SystemParameters.WindowCaptionHeight;
2024-05-01 18:23:32 +08:00
pos.X = (screenWidth - ViewboxFloatingBar.ActualWidth * ViewboxFloatingBarScaleTransform.ScaleX) / 2;
if (PosXCaculatedWithTaskbarHeight == false)
{
pos.Y = screenHeight - MarginFromEdge * ViewboxFloatingBarScaleTransform.ScaleY;
}
else if (PosXCaculatedWithTaskbarHeight == true)
{
pos.Y = screenHeight - ViewboxFloatingBar.ActualHeight * ViewboxFloatingBarScaleTransform.ScaleY - toolbarHeight - ViewboxFloatingBarScaleTransform.ScaleY * 3;
}
2024-05-01 18:23:32 +08:00
if (MarginFromEdge != -60)
{
if (BtnPPTSlideShowEnd.Visibility == Visibility.Visible)
{
if (pointPPT.X != -1 || pointPPT.Y != -1)
{
if (Math.Abs(pointPPT.Y - pos.Y) > 50)
{
2024-05-01 18:23:32 +08:00
pos = pointPPT;
}
else
{
2024-05-01 18:23:32 +08:00
pointPPT = pos;
}
}
}
else
{
if (pointDesktop.X != -1 || pointDesktop.Y != -1)
{
if (Math.Abs(pointDesktop.Y - pos.Y) > 50)
{
2024-05-01 18:23:32 +08:00
pos = pointDesktop;
}
else
{
2024-05-01 18:23:32 +08:00
pointDesktop = pos;
}
}
}
}
ThicknessAnimation marginAnimation = new ThicknessAnimation
{
Duration = TimeSpan.FromSeconds(0.3),
2024-05-01 18:23:32 +08:00
From = ViewboxFloatingBar.Margin,
To = new Thickness(pos.X, pos.Y, -2000, -200)
};
marginAnimation.EasingFunction = new CircleEase();
2024-05-01 18:23:32 +08:00
ViewboxFloatingBar.BeginAnimation(FrameworkElement.MarginProperty, marginAnimation);
});
await Task.Delay(200);
await Dispatcher.InvokeAsync(() => {
ViewboxFloatingBar.Margin = new Thickness(pos.X, pos.Y, -2000, -200);
if (Topmost == false) ViewboxFloatingBar.Visibility = Visibility.Hidden;
});
}
private async void CursorIcon_Click(object sender, RoutedEventArgs e)
{
// 隱藏高亮
FloatingbarSelectionBG.Visibility = Visibility.Hidden;
2024-05-01 18:23:32 +08:00
// 切换前自动截图保存墨迹
if (inkCanvas.Strokes.Count > 0 && inkCanvas.Strokes.Count > Settings.Automation.MinimumAutomationStrokeNumber)
{
2024-05-01 18:23:32 +08:00
if (BtnPPTSlideShowEnd.Visibility == Visibility.Visible) SaveScreenShot(true, $"{pptName}/{previousSlideID}_{DateTime.Now:HH-mm-ss}");
else SaveScreenShot(true);
}
if (BtnPPTSlideShowEnd.Visibility != Visibility.Visible)
{
2024-05-01 18:23:32 +08:00
if (Settings.Canvas.HideStrokeWhenSelecting)
inkCanvas.Visibility = Visibility.Collapsed;
else
{
2024-05-01 18:23:32 +08:00
inkCanvas.IsHitTestVisible = false;
inkCanvas.Visibility = Visibility.Visible;
}
}
else
{
if (Settings.PowerPointSettings.IsShowStrokeOnSelectInPowerPoint)
{
2024-05-01 18:23:32 +08:00
inkCanvas.Visibility = Visibility.Visible;
inkCanvas.IsHitTestVisible = true;
}
else
{
2024-05-01 18:23:32 +08:00
if (Settings.Canvas.HideStrokeWhenSelecting)
inkCanvas.Visibility = Visibility.Collapsed;
else
{
2024-05-01 18:23:32 +08:00
inkCanvas.IsHitTestVisible = false;
inkCanvas.Visibility = Visibility.Visible;
}
}
}
GridTransparencyFakeBackground.Opacity = 0;
GridTransparencyFakeBackground.Background = Brushes.Transparent;
2024-05-01 18:23:32 +08:00
GridBackgroundCoverHolder.Visibility = Visibility.Collapsed;
inkCanvas.Select(new StrokeCollection());
GridInkCanvasSelectionCover.Visibility = Visibility.Collapsed;
if (currentMode != 0)
{
2024-05-01 18:23:32 +08:00
SaveStrokes();
RestoreStrokes(true);
}
if (BtnSwitchTheme.Content.ToString() == "浅色")
{
2024-05-01 18:23:32 +08:00
BtnSwitch.Content = "黑板";
}
else
{
2024-05-01 18:23:32 +08:00
BtnSwitch.Content = "白板";
}
StackPanelPPTButtons.Visibility = Visibility.Visible;
BtnHideInkCanvas.Content = "显示\n画板";
CheckEnableTwoFingerGestureBtnVisibility(false);
StackPanelCanvasControls.Visibility = Visibility.Collapsed;
if (!isFloatingBarFolded)
{
2024-05-01 18:23:32 +08:00
HideSubPanels("cursor", true);
await Task.Delay(50);
if (BtnPPTSlideShowEnd.Visibility == Visibility.Visible)
{
2024-05-01 18:23:32 +08:00
ViewboxFloatingBarMarginAnimation(60);
}
else
{
ViewboxFloatingBarMarginAnimation(100, true);
2024-05-01 18:23:32 +08:00
}
}
}
private void PenIcon_Click(object sender, RoutedEventArgs e)
{
FloatingbarSelectionBG.Visibility = Visibility.Visible;
System.Windows.Controls.Canvas.SetLeft(FloatingbarSelectionBG, 28);
if (Pen_Icon.Background == null || StackPanelCanvasControls.Visibility == Visibility.Collapsed)
{
2024-05-01 18:23:32 +08:00
inkCanvas.EditingMode = InkCanvasEditingMode.Ink;
GridTransparencyFakeBackground.Opacity = 1;
GridTransparencyFakeBackground.Background = new SolidColorBrush(StringToColor("#01FFFFFF"));
2024-05-01 18:23:32 +08:00
inkCanvas.IsHitTestVisible = true;
inkCanvas.Visibility = Visibility.Visible;
GridBackgroundCoverHolder.Visibility = Visibility.Visible;
GridInkCanvasSelectionCover.Visibility = Visibility.Collapsed;
/*if (forceEraser && currentMode == 0)
BtnColorRed_Click(sender, null);*/
if (GridBackgroundCover.Visibility == Visibility.Collapsed)
{
if (BtnSwitchTheme.Content.ToString() == "浅色")
{
2024-05-01 18:23:32 +08:00
BtnSwitch.Content = "黑板";
}
else
{
2024-05-01 18:23:32 +08:00
BtnSwitch.Content = "白板";
}
StackPanelPPTButtons.Visibility = Visibility.Visible;
}
else
{
2024-05-01 18:23:32 +08:00
BtnSwitch.Content = "屏幕";
StackPanelPPTButtons.Visibility = Visibility.Collapsed;
}
BtnHideInkCanvas.Content = "隐藏\n画板";
StackPanelCanvasControls.Visibility = Visibility.Visible;
//AnimationsHelper.ShowWithSlideFromLeftAndFade(StackPanelCanvasControls);
CheckEnableTwoFingerGestureBtnVisibility(true);
inkCanvas.EditingMode = InkCanvasEditingMode.Ink;
ColorSwitchCheck();
HideSubPanels("pen", true);
}
else
{
if (inkCanvas.EditingMode == InkCanvasEditingMode.Ink)
{
if (PenPalette.Visibility == Visibility.Visible)
{
AnimationsHelper.HideWithSlideAndFade(PenPalette);
AnimationsHelper.HideWithSlideAndFade(BoardPenPalette);
}
else
{
AnimationsHelper.ShowWithSlideFromBottomAndFade(PenPalette);
AnimationsHelper.ShowWithSlideFromBottomAndFade(BoardPenPalette);
}
}
else
{
inkCanvas.EditingMode = InkCanvasEditingMode.Ink;
ColorSwitchCheck();
HideSubPanels("pen", true);
2024-05-01 18:23:32 +08:00
}
2024-05-01 18:23:32 +08:00
}
}
private void ColorThemeSwitch_MouseUp(object sender, RoutedEventArgs e)
{
2024-05-01 18:23:32 +08:00
isUselightThemeColor = !isUselightThemeColor;
if (currentMode == 0)
{
2024-05-01 18:23:32 +08:00
isDesktopUselightThemeColor = isUselightThemeColor;
}
CheckColorTheme();
}
private void EraserIcon_Click(object sender, RoutedEventArgs e)
{
FloatingbarSelectionBG.Visibility = Visibility.Visible;
System.Windows.Controls.Canvas.SetLeft(FloatingbarSelectionBG, 84);
2024-05-01 18:23:32 +08:00
forceEraser = true;
forcePointEraser = true;
if (Settings.Canvas.EraserShapeType == 0)
{
double k = 1;
switch (Settings.Canvas.EraserSize)
{
case 0:
k = 0.5;
break;
case 1:
k = 0.8;
break;
case 3:
k = 1.25;
break;
case 4:
k = 1.8;
break;
}
inkCanvas.EraserShape = new EllipseStylusShape(k * 90, k * 90);
}
else if (Settings.Canvas.EraserShapeType == 1)
{
double k = 1;
switch (Settings.Canvas.EraserSize)
{
case 0:
k = 0.7;
break;
case 1:
k = 0.9;
break;
case 3:
k = 1.2;
break;
case 4:
k = 1.6;
break;
}
inkCanvas.EraserShape = new RectangleStylusShape(k * 90 * 0.6, k * 90);
2024-05-01 18:23:32 +08:00
}
if (inkCanvas.EditingMode == InkCanvasEditingMode.EraseByPoint)
{
HideSubPanels();
HideSubPanelsImmediately();
AnimationsHelper.ShowWithSlideFromBottomAndFade(EraserSizePanel);
}
else
{
HideSubPanels("eraser");
}
2024-05-01 18:23:32 +08:00
inkCanvas.EditingMode = InkCanvasEditingMode.EraseByPoint;
drawingShapeMode = 0;
inkCanvas_EditingModeChanged(inkCanvas, null);
CancelSingleFingerDragMode();
}
private void EraserIconByStrokes_Click(object sender, RoutedEventArgs e)
{
FloatingbarSelectionBG.Visibility = Visibility.Visible;
System.Windows.Controls.Canvas.SetLeft(FloatingbarSelectionBG, 112);
2024-05-01 18:23:32 +08:00
forceEraser = true;
forcePointEraser = false;
inkCanvas.EraserShape = new EllipseStylusShape(5, 5);
inkCanvas.EditingMode = InkCanvasEditingMode.EraseByStroke;
drawingShapeMode = 0;
inkCanvas_EditingModeChanged(inkCanvas, null);
CancelSingleFingerDragMode();
HideSubPanels("eraserByStrokes");
}
private void CursorWithDelIcon_Click(object sender, RoutedEventArgs e)
{
2024-05-01 18:23:32 +08:00
SymbolIconDelete_MouseUp(sender, null);
CursorIcon_Click(null, null);
}
private void SelectIcon_MouseUp(object sender, RoutedEvent e)
{
2024-05-01 18:23:32 +08:00
forceEraser = true;
drawingShapeMode = 0;
inkCanvas.IsManipulationEnabled = false;
if (inkCanvas.EditingMode == InkCanvasEditingMode.Select)
{
2024-05-01 18:23:32 +08:00
StrokeCollection selectedStrokes = new StrokeCollection();
foreach (Stroke stroke in inkCanvas.Strokes)
{
if (stroke.GetBounds().Width > 0 && stroke.GetBounds().Height > 0)
{
2024-05-01 18:23:32 +08:00
selectedStrokes.Add(stroke);
}
}
inkCanvas.Select(selectedStrokes);
}
else
{
2024-05-01 18:23:32 +08:00
inkCanvas.EditingMode = InkCanvasEditingMode.Select;
}
}
private void CollapseBorderDrawShape(bool isLongPressSelected = false)
{
2024-05-01 18:23:32 +08:00
AnimationsHelper.HideWithSlideAndFade(BorderDrawShape);
AnimationsHelper.HideWithSlideAndFade(BoardBorderDrawShape);
}
private void DrawShapePromptToPen()
{
if (isLongPressSelected == true)
{
2024-05-01 18:23:32 +08:00
HideSubPanels("pen");
}
else
{
if (StackPanelCanvasControls.Visibility == Visibility.Visible)
{
2024-05-01 18:23:32 +08:00
HideSubPanels("pen");
}
else
{
2024-05-01 18:23:32 +08:00
HideSubPanels("cursor");
}
}
}
private void CloseBordertools_MouseUp(object sender, MouseButtonEventArgs e)
{
2024-05-01 18:23:32 +08:00
HideSubPanels();
}
#region Left Side Panel
private void BtnFingerDragMode_Click(object sender, RoutedEventArgs e)
{
if (isSingleFingerDragMode)
{
2024-05-01 18:23:32 +08:00
isSingleFingerDragMode = false;
BtnFingerDragMode.Content = "单指\n拖动";
}
else
{
2024-05-01 18:23:32 +08:00
isSingleFingerDragMode = true;
BtnFingerDragMode.Content = "多指\n拖动";
}
}
private void BtnUndo_Click(object sender, RoutedEventArgs e)
{
if (inkCanvas.GetSelectedStrokes().Count != 0)
{
2024-05-01 18:23:32 +08:00
GridInkCanvasSelectionCover.Visibility = Visibility.Collapsed;
inkCanvas.Select(new StrokeCollection());
}
_currentCommitType = CommitReason.CodeInput;
var item = timeMachine.Undo();
if (item.CommitType == TimeMachineHistoryType.UserInput)
{
if (!item.StrokeHasBeenCleared)
{
foreach (var strokes in item.CurrentStroke)
{
2024-05-01 18:23:32 +08:00
if (!inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Add(strokes);
}
}
else
{
foreach (var strokes in item.CurrentStroke)
{
2024-05-01 18:23:32 +08:00
if (inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Remove(strokes);
}
}
}
else if (item.CommitType == TimeMachineHistoryType.ShapeRecognition)
{
if (item.StrokeHasBeenCleared)
{
2024-05-01 18:23:32 +08:00
foreach (var strokes in item.CurrentStroke)
{
2024-05-01 18:23:32 +08:00
if (inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Remove(strokes);
}
foreach (var strokes in item.ReplacedStroke)
{
2024-05-01 18:23:32 +08:00
if (!inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Add(strokes);
}
}
else
{
foreach (var strokes in item.CurrentStroke)
{
2024-05-01 18:23:32 +08:00
if (!inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Add(strokes);
}
foreach (var strokes in item.ReplacedStroke)
{
2024-05-01 18:23:32 +08:00
if (inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Remove(strokes);
}
}
}
else if (item.CommitType == TimeMachineHistoryType.Manipulation)
{
if (item.StrokeHasBeenCleared)
{
2024-05-01 18:23:32 +08:00
foreach (var strokes in item.CurrentStroke)
{
2024-05-01 18:23:32 +08:00
if (inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Remove(strokes);
}
foreach (var strokes in item.ReplacedStroke)
{
2024-05-01 18:23:32 +08:00
if (!inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Add(strokes);
}
}
else
{
foreach (var strokes in item.CurrentStroke)
{
2024-05-01 18:23:32 +08:00
if (!inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Add(strokes);
}
foreach (var strokes in item.ReplacedStroke)
{
2024-05-01 18:23:32 +08:00
if (inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Remove(strokes);
}
}
}
else if (item.CommitType == TimeMachineHistoryType.Clear)
{
if (!item.StrokeHasBeenCleared)
{
if (item.CurrentStroke != null)
{
foreach (var currentStroke in item.CurrentStroke)
{
2024-05-01 18:23:32 +08:00
if (!inkCanvas.Strokes.Contains(currentStroke)) inkCanvas.Strokes.Add(currentStroke);
}
}
if (item.ReplacedStroke != null)
{
foreach (var replacedStroke in item.ReplacedStroke)
{
2024-05-01 18:23:32 +08:00
if (inkCanvas.Strokes.Contains(replacedStroke)) inkCanvas.Strokes.Remove(replacedStroke);
}
}
}
else
{
if (item.ReplacedStroke != null)
{
foreach (var replacedStroke in item.ReplacedStroke)
{
2024-05-01 18:23:32 +08:00
if (!inkCanvas.Strokes.Contains(replacedStroke)) inkCanvas.Strokes.Add(replacedStroke);
}
}
if (item.CurrentStroke != null)
{
foreach (var currentStroke in item.CurrentStroke)
{
2024-05-01 18:23:32 +08:00
if (inkCanvas.Strokes.Contains(currentStroke)) inkCanvas.Strokes.Remove(currentStroke);
}
}
}
}
_currentCommitType = CommitReason.UserInput;
}
private void BtnRedo_Click(object sender, RoutedEventArgs e)
{
if (inkCanvas.GetSelectedStrokes().Count != 0)
{
2024-05-01 18:23:32 +08:00
GridInkCanvasSelectionCover.Visibility = Visibility.Collapsed;
inkCanvas.Select(new StrokeCollection());
}
_currentCommitType = CommitReason.CodeInput;
var item = timeMachine.Redo();
if (item.CommitType == TimeMachineHistoryType.UserInput)
{
if (!item.StrokeHasBeenCleared)
{
foreach (var strokes in item.CurrentStroke)
{
2024-05-01 18:23:32 +08:00
if (!inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Add(strokes);
}
}
else
{
foreach (var strokes in item.CurrentStroke)
{
2024-05-01 18:23:32 +08:00
if (inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Remove(strokes);
}
}
}
else if (item.CommitType == TimeMachineHistoryType.ShapeRecognition)
{
if (item.StrokeHasBeenCleared)
{
2024-05-01 18:23:32 +08:00
foreach (var strokes in item.CurrentStroke)
{
2024-05-01 18:23:32 +08:00
if (inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Remove(strokes);
}
foreach (var strokes in item.ReplacedStroke)
{
2024-05-01 18:23:32 +08:00
if (!inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Add(strokes);
}
}
else
{
foreach (var strokes in item.CurrentStroke)
{
2024-05-01 18:23:32 +08:00
if (!inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Add(strokes);
}
foreach (var strokes in item.ReplacedStroke)
{
2024-05-01 18:23:32 +08:00
if (inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Remove(strokes);
}
}
}
else if (item.CommitType == TimeMachineHistoryType.Manipulation)
{
if (item.StrokeHasBeenCleared)
{
2024-05-01 18:23:32 +08:00
foreach (var strokes in item.CurrentStroke)
{
2024-05-01 18:23:32 +08:00
if (inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Remove(strokes);
}
foreach (var strokes in item.ReplacedStroke)
{
2024-05-01 18:23:32 +08:00
if (!inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Add(strokes);
}
}
else
{
foreach (var strokes in item.CurrentStroke)
{
2024-05-01 18:23:32 +08:00
if (!inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Add(strokes);
}
foreach (var strokes in item.ReplacedStroke)
{
2024-05-01 18:23:32 +08:00
if (inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Remove(strokes);
}
}
}
else if (item.CommitType == TimeMachineHistoryType.Clear)
{
if (!item.StrokeHasBeenCleared)
{
if (item.CurrentStroke != null)
{
foreach (var currentStroke in item.CurrentStroke)
{
2024-05-01 18:23:32 +08:00
if (!inkCanvas.Strokes.Contains(currentStroke)) inkCanvas.Strokes.Add(currentStroke);
}
}
if (item.ReplacedStroke != null)
{
foreach (var replacedStroke in item.ReplacedStroke)
{
2024-05-01 18:23:32 +08:00
if (inkCanvas.Strokes.Contains(replacedStroke)) inkCanvas.Strokes.Remove(replacedStroke);
}
}
}
else
{
if (item.ReplacedStroke != null)
{
foreach (var replacedStroke in item.ReplacedStroke)
{
2024-05-01 18:23:32 +08:00
if (!inkCanvas.Strokes.Contains(replacedStroke)) inkCanvas.Strokes.Add(replacedStroke);
}
}
if (item.CurrentStroke != null)
{
foreach (var currentStroke in item.CurrentStroke)
{
2024-05-01 18:23:32 +08:00
if (inkCanvas.Strokes.Contains(currentStroke)) inkCanvas.Strokes.Remove(currentStroke);
}
}
}
}
_currentCommitType = CommitReason.UserInput;
}
private void Btn_IsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e)
{
2024-05-01 18:23:32 +08:00
if (!isLoaded) return;
try
{
if (((Button)sender).IsEnabled)
{
2024-05-01 18:23:32 +08:00
((UIElement)((Button)sender).Content).Opacity = 1;
}
else
{
2024-05-01 18:23:32 +08:00
((UIElement)((Button)sender).Content).Opacity = 0.25;
}
}
catch { }
2024-05-01 18:23:32 +08:00
}
#endregion Left Side Panel
#region Right Side Panel
public static bool CloseIsFromButton = false;
private void BtnExit_Click(object sender, RoutedEventArgs e)
{
2024-05-01 18:23:32 +08:00
CloseIsFromButton = true;
Close();
}
private void BtnRestart_Click(object sender, RoutedEventArgs e)
{
2024-05-01 18:23:32 +08:00
Process.Start(System.Windows.Forms.Application.ExecutablePath, "-m");
CloseIsFromButton = true;
Application.Current.Shutdown();
}
private void SettingsOverlayClick(object sender, MouseButtonEventArgs e)
{
if (isOpeningOrHidingSettingsPane==true) return;
BtnSettings_Click(null, null);
}
private bool isOpeningOrHidingSettingsPane = false;
private void BtnSettings_Click(object sender, RoutedEventArgs e)
{
if (BorderSettings.Visibility == Visibility.Visible)
{
HideSubPanels();
}
else
{
BorderSettingsMask.IsHitTestVisible = true;
BorderSettingsMask.Background = new SolidColorBrush(Color.FromArgb(1, 0, 0, 0));
SettingsPanelScrollViewer.ScrollToTop();
var sb = new Storyboard();
// 滑动动画
var slideAnimation = new DoubleAnimation
{
From = BorderSettings.RenderTransform.Value.OffsetX - 440, // 滑动距离
To = 0,
Duration = TimeSpan.FromSeconds(0.6)
};
slideAnimation.EasingFunction = new CubicEase() { EasingMode = EasingMode.EaseOut };
Storyboard.SetTargetProperty(slideAnimation, new PropertyPath("(UIElement.RenderTransform).(TranslateTransform.X)"));
sb.Children.Add(slideAnimation);
sb.Completed += (s, _) =>
{
isOpeningOrHidingSettingsPane = false;
};
BorderSettings.Visibility = Visibility.Visible;
BorderSettings.RenderTransform = new TranslateTransform();
isOpeningOrHidingSettingsPane = true;
sb.Begin((FrameworkElement)BorderSettings);
2024-05-01 18:23:32 +08:00
}
}
private void BtnThickness_Click(object sender, RoutedEventArgs e)
{
2024-05-01 18:23:32 +08:00
}
bool forceEraser = false;
private void BtnClear_Click(object sender, RoutedEventArgs e)
{
2024-05-01 18:23:32 +08:00
forceEraser = false;
//BorderClearInDelete.Visibility = Visibility.Collapsed;
if (currentMode == 0)
{ // 先回到画笔再清屏,避免 TimeMachine 的相关 bug 影响
if (Pen_Icon.Background == null && StackPanelCanvasControls.Visibility == Visibility.Visible)
{
2024-05-01 18:23:32 +08:00
PenIcon_Click(null, null);
}
}
else
{
if (Pen_Icon.Background == null)
{
2024-05-01 18:23:32 +08:00
PenIcon_Click(null, null);
}
}
if (inkCanvas.Strokes.Count != 0)
{
2024-05-01 18:23:32 +08:00
int whiteboardIndex = CurrentWhiteboardIndex;
if (currentMode == 0)
{
2024-05-01 18:23:32 +08:00
whiteboardIndex = 0;
}
strokeCollections[whiteboardIndex] = inkCanvas.Strokes.Clone();
}
ClearStrokes(false);
inkCanvas.Children.Clear();
CancelSingleFingerDragMode();
if (Settings.Canvas.ClearCanvasAndClearTimeMachine)
{
timeMachine.ClearStrokeHistory();
}
}
bool lastIsInMultiTouchMode = false;
private void CancelSingleFingerDragMode()
{
if (ToggleSwitchDrawShapeBorderAutoHide.IsOn)
{
2024-05-01 18:23:32 +08:00
CollapseBorderDrawShape();
}
GridInkCanvasSelectionCover.Visibility = Visibility.Collapsed;
if (isSingleFingerDragMode)
{
2024-05-01 18:23:32 +08:00
BtnFingerDragMode_Click(BtnFingerDragMode, null);
}
isLongPressSelected = false;
}
2024-05-01 18:23:32 +08:00
private void BtnHideControl_Click(object sender, RoutedEventArgs e)
{
if (StackPanelControl.Visibility == Visibility.Visible)
{
2024-05-01 18:23:32 +08:00
StackPanelControl.Visibility = Visibility.Hidden;
}
else
{
2024-05-01 18:23:32 +08:00
StackPanelControl.Visibility = Visibility.Visible;
}
}
int currentMode = 0;
private void BtnSwitch_Click(object sender, RoutedEventArgs e)
{
if (GridTransparencyFakeBackground.Background == Brushes.Transparent)
{
if (currentMode == 0)
{
2024-05-01 18:23:32 +08:00
currentMode++;
GridBackgroundCover.Visibility = Visibility.Collapsed;
AnimationsHelper.HideWithSlideAndFade(BlackboardLeftSide);
AnimationsHelper.HideWithSlideAndFade(BlackboardCenterSide);
AnimationsHelper.HideWithSlideAndFade(BlackboardRightSide);
SaveStrokes(true);
ClearStrokes(true);
RestoreStrokes();
if (BtnSwitchTheme.Content.ToString() == "浅色")
{
2024-05-01 18:23:32 +08:00
BtnSwitch.Content = "黑板";
BtnExit.Foreground = Brushes.White;
}
else
{
2024-05-01 18:23:32 +08:00
BtnSwitch.Content = "白板";
if (isPresentationHaveBlackSpace)
{
2024-05-01 18:23:32 +08:00
BtnExit.Foreground = Brushes.White;
//SymbolIconBtnColorBlackContent.Foreground = Brushes.White;
ThemeManager.Current.ApplicationTheme = ApplicationTheme.Dark;
}
else
{
2024-05-01 18:23:32 +08:00
BtnExit.Foreground = Brushes.Black;
//SymbolIconBtnColorBlackContent.Foreground = Brushes.White;
ThemeManager.Current.ApplicationTheme = ApplicationTheme.Light;
}
}
StackPanelPPTButtons.Visibility = Visibility.Visible;
}
Topmost = true;
BtnHideInkCanvas_Click(BtnHideInkCanvas, e);
}
else
{
switch ((++currentMode) % 2)
{
2024-05-01 18:23:32 +08:00
case 0: //屏幕模式
currentMode = 0;
GridBackgroundCover.Visibility = Visibility.Collapsed;
AnimationsHelper.HideWithSlideAndFade(BlackboardLeftSide);
AnimationsHelper.HideWithSlideAndFade(BlackboardCenterSide);
AnimationsHelper.HideWithSlideAndFade(BlackboardRightSide);
SaveStrokes();
ClearStrokes(true);
RestoreStrokes(true);
if (BtnSwitchTheme.Content.ToString() == "浅色")
{
2024-05-01 18:23:32 +08:00
BtnSwitch.Content = "黑板";
BtnExit.Foreground = Brushes.White;
//SymbolIconBtnColorBlackContent.Foreground = Brushes.Black;
ThemeManager.Current.ApplicationTheme = ApplicationTheme.Dark;
}
else
{
2024-05-01 18:23:32 +08:00
BtnSwitch.Content = "白板";
if (isPresentationHaveBlackSpace)
{
2024-05-01 18:23:32 +08:00
BtnExit.Foreground = Brushes.White;
//SymbolIconBtnColorBlackContent.Foreground = Brushes.White;
ThemeManager.Current.ApplicationTheme = ApplicationTheme.Dark;
}
else
{
2024-05-01 18:23:32 +08:00
BtnExit.Foreground = Brushes.Black;
//SymbolIconBtnColorBlackContent.Foreground = Brushes.White;
ThemeManager.Current.ApplicationTheme = ApplicationTheme.Light;
}
}
StackPanelPPTButtons.Visibility = Visibility.Visible;
Topmost = true;
break;
case 1: //黑板或白板模式
currentMode = 1;
GridBackgroundCover.Visibility = Visibility.Visible;
AnimationsHelper.ShowWithSlideFromBottomAndFade(BlackboardLeftSide);
AnimationsHelper.ShowWithSlideFromBottomAndFade(BlackboardCenterSide);
AnimationsHelper.ShowWithSlideFromBottomAndFade(BlackboardRightSide);
SaveStrokes(true);
ClearStrokes(true);
RestoreStrokes();
BtnSwitch.Content = "屏幕";
if (BtnSwitchTheme.Content.ToString() == "浅色")
{
2024-05-01 18:23:32 +08:00
BtnExit.Foreground = Brushes.White;
//SymbolIconBtnColorBlackContent.Foreground = Brushes.Black;
ThemeManager.Current.ApplicationTheme = ApplicationTheme.Dark;
}
else
{
2024-05-01 18:23:32 +08:00
BtnExit.Foreground = Brushes.Black;
//SymbolIconBtnColorBlackContent.Foreground = Brushes.White;
ThemeManager.Current.ApplicationTheme = ApplicationTheme.Light;
}
StackPanelPPTButtons.Visibility = Visibility.Collapsed;
Topmost = false;
break;
}
}
}
int BoundsWidth = 5;
private void BtnHideInkCanvas_Click(object sender, RoutedEventArgs e)
{
if (GridTransparencyFakeBackground.Background == Brushes.Transparent)
{
GridTransparencyFakeBackground.Opacity = 1;
GridTransparencyFakeBackground.Background = new SolidColorBrush(StringToColor("#01FFFFFF"));
2024-05-01 18:23:32 +08:00
inkCanvas.IsHitTestVisible = true;
inkCanvas.Visibility = Visibility.Visible;
GridBackgroundCoverHolder.Visibility = Visibility.Visible;
GridInkCanvasSelectionCover.Visibility = Visibility.Collapsed;
if (GridBackgroundCover.Visibility == Visibility.Collapsed)
{
if (BtnSwitchTheme.Content.ToString() == "浅色")
{
2024-05-01 18:23:32 +08:00
BtnSwitch.Content = "黑板";
}
else
{
2024-05-01 18:23:32 +08:00
BtnSwitch.Content = "白板";
}
StackPanelPPTButtons.Visibility = Visibility.Visible;
}
else
{
2024-05-01 18:23:32 +08:00
BtnSwitch.Content = "屏幕";
StackPanelPPTButtons.Visibility = Visibility.Collapsed;
}
BtnHideInkCanvas.Content = "隐藏\n画板";
}
else
{
2024-05-01 18:23:32 +08:00
// Auto-clear Strokes 要等待截图完成再清理笔记
if (BtnPPTSlideShowEnd.Visibility != Visibility.Visible)
{
if (isLoaded && Settings.Automation.IsAutoClearWhenExitingWritingMode)
{
if (inkCanvas.Strokes.Count > 0)
{
2024-05-01 18:23:32 +08:00
if (Settings.Automation.IsAutoSaveStrokesAtClear && inkCanvas.Strokes.Count >
Settings.Automation.MinimumAutomationStrokeNumber)
{
2024-05-01 18:23:32 +08:00
SaveScreenShot(true);
}
BtnClear_Click(null, null);
}
}
inkCanvas.IsHitTestVisible = true;
inkCanvas.Visibility = Visibility.Visible;
}
else
{
if (isLoaded && Settings.Automation.IsAutoClearWhenExitingWritingMode && !Settings.PowerPointSettings.IsNoClearStrokeOnSelectWhenInPowerPoint)
{
if (inkCanvas.Strokes.Count > 0)
{
2024-05-01 18:23:32 +08:00
if (Settings.Automation.IsAutoSaveStrokesAtClear && inkCanvas.Strokes.Count >
Settings.Automation.MinimumAutomationStrokeNumber)
{
2024-05-01 18:23:32 +08:00
SaveScreenShot(true);
}
BtnClear_Click(null, null);
}
}
if (Settings.PowerPointSettings.IsShowStrokeOnSelectInPowerPoint)
{
2024-05-01 18:23:32 +08:00
inkCanvas.Visibility = Visibility.Visible;
inkCanvas.IsHitTestVisible = true;
}
else
{
2024-05-01 18:23:32 +08:00
inkCanvas.IsHitTestVisible = true;
inkCanvas.Visibility = Visibility.Visible;
}
}
GridTransparencyFakeBackground.Opacity = 0;
GridTransparencyFakeBackground.Background = Brushes.Transparent;
2024-05-01 18:23:32 +08:00
GridBackgroundCoverHolder.Visibility = Visibility.Collapsed;
if (currentMode != 0)
{
2024-05-01 18:23:32 +08:00
SaveStrokes();
RestoreStrokes(true);
}
if (BtnSwitchTheme.Content.ToString() == "浅色")
{
2024-05-01 18:23:32 +08:00
BtnSwitch.Content = "黑板";
}
else
{
2024-05-01 18:23:32 +08:00
BtnSwitch.Content = "白板";
}
StackPanelPPTButtons.Visibility = Visibility.Visible;
BtnHideInkCanvas.Content = "显示\n画板";
}
if (GridTransparencyFakeBackground.Background == Brushes.Transparent)
{
2024-05-01 18:23:32 +08:00
StackPanelCanvasControls.Visibility = Visibility.Collapsed;
CheckEnableTwoFingerGestureBtnVisibility(false);
HideSubPanels("cursor");
}
else
{
2024-05-01 18:23:32 +08:00
AnimationsHelper.ShowWithSlideFromLeftAndFade(StackPanelCanvasControls);
CheckEnableTwoFingerGestureBtnVisibility(true);
}
}
private void BtnSwitchSide_Click(object sender, RoutedEventArgs e)
{
if (ViewBoxStackPanelMain.HorizontalAlignment == HorizontalAlignment.Right)
{
2024-05-01 18:23:32 +08:00
ViewBoxStackPanelMain.HorizontalAlignment = HorizontalAlignment.Left;
ViewBoxStackPanelShapes.HorizontalAlignment = HorizontalAlignment.Right;
}
else
{
2024-05-01 18:23:32 +08:00
ViewBoxStackPanelMain.HorizontalAlignment = HorizontalAlignment.Right;
ViewBoxStackPanelShapes.HorizontalAlignment = HorizontalAlignment.Left;
}
}
private void StackPanel_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
{
if (((StackPanel)sender).Visibility == Visibility.Visible)
{
2024-05-01 18:23:32 +08:00
GridForLeftSideReservedSpace.Visibility = Visibility.Collapsed;
}
else
{
2024-05-01 18:23:32 +08:00
GridForLeftSideReservedSpace.Visibility = Visibility.Visible;
}
}
#endregion
}
}