Skip to content

Commit

Permalink
[Add] GridInkCanvasSelectionCover_MouseDown, MouseMove, MouseUp
Browse files Browse the repository at this point in the history
  • Loading branch information
ChangSakura committed Jul 21, 2024
1 parent c5ccc30 commit 18246e0
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 47 deletions.
13 changes: 13 additions & 0 deletions Ink Canvas/Helpers/InkCanvasImageHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@ namespace Ink_Canvas.Helpers
{
public static class InkCanvasImageHelper
{
public static bool IsNotCanvasElementSelected(InkCanvas inkCanvas)
{
if (inkCanvas.GetSelectedStrokes().Count > 0) return false;
foreach (UIElement element in inkCanvas.GetSelectedElements())
{
if (element is Image selectedImage)
{
return false;
}
}
return true;
}

public static List<Image> GetSelectedImages(InkCanvas inkCanvas)
{
List<Image> selectedImages = new List<Image>();
Expand Down
31 changes: 16 additions & 15 deletions Ink Canvas/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
ManipulationDelta="GridInkCanvasSelectionCover_ManipulationDelta"
ManipulationStarting="GridInkCanvasSelectionCover_ManipulationStarting"
MouseDown="GridInkCanvasSelectionCover_MouseDown"
MouseMove="GridInkCanvasSelectionCover_MouseMove"
MouseUp="GridInkCanvasSelectionCover_MouseUp"
Opacity="0.01"
PreviewTouchDown="GridInkCanvasSelectionCover_PreviewTouchDown"
Expand Down Expand Up @@ -149,7 +150,7 @@
Height="35"
Padding="0"
Background="{DynamicResource FloatBarBackground}"
Click="BorderStrokeSelectionCloneToNewBoard_Click">
Click="BorderStrokeSelectionCloneToBoardOrNewPage_Click">
<ikw:SimpleStackPanel HorizontalAlignment="Center" VerticalAlignment="Center" Orientation="Horizontal" Spacing="2">
<ui:FontIcon
Width="18"
Expand Down Expand Up @@ -523,11 +524,11 @@
Height="30"
Padding="0"
Background="{DynamicResource FloatBarBackground}"
Click="BtnColorPink_Click">
Click="BtnColorOrange_Click">
<Border
Width="16"
Height="16"
Background="#c72ec7"
Background="#ea580c"
BorderBrush="{DynamicResource FloatBarBorderBrush}"
BorderThickness="1.5"
CornerRadius="100" />
Expand All @@ -537,11 +538,11 @@
Height="30"
Padding="0"
Background="{DynamicResource FloatBarBackground}"
Click="BtnColorOrange_Click">
Click="BtnColorYellow_Click">
<Border
Width="16"
Height="16"
Background="#ea580c"
Background="#eab308"
BorderBrush="{DynamicResource FloatBarBorderBrush}"
BorderThickness="1.5"
CornerRadius="100" />
Expand All @@ -551,11 +552,11 @@
Height="30"
Padding="0"
Background="{DynamicResource FloatBarBackground}"
Click="BtnColorYellow_Click">
Click="BtnColorGreen_Click">
<Border
Width="16"
Height="16"
Background="#eab308"
Background="#16a34a"
BorderBrush="{DynamicResource FloatBarBorderBrush}"
BorderThickness="1.5"
CornerRadius="100" />
Expand All @@ -565,11 +566,11 @@
Height="30"
Padding="0"
Background="{DynamicResource FloatBarBackground}"
Click="BtnColorGreen_Click">
Click="BtnColorTeal_Click">
<Border
Width="16"
Height="16"
Background="#16a34a"
Background="#0d9488"
BorderBrush="{DynamicResource FloatBarBorderBrush}"
BorderThickness="1.5"
CornerRadius="100" />
Expand All @@ -579,11 +580,11 @@
Height="30"
Padding="0"
Background="{DynamicResource FloatBarBackground}"
Click="BtnColorTeal_Click">
Click="BtnColorBlue_Click">
<Border
Width="16"
Height="16"
Background="#0d9488"
Background="#2563eb"
BorderBrush="{DynamicResource FloatBarBorderBrush}"
BorderThickness="1.5"
CornerRadius="100" />
Expand All @@ -593,11 +594,11 @@
Height="30"
Padding="0"
Background="{DynamicResource FloatBarBackground}"
Click="BtnColorBlue_Click">
Click="BtnColorPink_Click">
<Border
Width="16"
Height="16"
Background="#2563eb"
Background="#c72ec7"
BorderBrush="{DynamicResource FloatBarBorderBrush}"
BorderThickness="1.5"
CornerRadius="100" />
Expand Down Expand Up @@ -5593,8 +5594,8 @@
</Border>
<!-- 202407
<Button
Width="62"
Height="30"
Width="70"
Height="36"
Margin="2,0,0,0"
Padding="0"
Background="{DynamicResource FloatBarBackground}"
Expand Down
24 changes: 4 additions & 20 deletions Ink Canvas/MainWindow_cs/MW_PPT.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Ink_Canvas.Helpers;
using Microsoft.Office.Interop.PowerPoint;
using iNKORE.UI.WPF.Modern;
using System;
using System.Diagnostics;
using System.IO;
Expand All @@ -14,7 +13,6 @@
using System.Windows.Media;
using Application = System.Windows.Application;
using File = System.IO.File;
using MessageBox = System.Windows.MessageBox;
using Microsoft.Office.Core;

namespace Ink_Canvas
Expand Down Expand Up @@ -264,13 +262,13 @@ private void PptApplication_PresentationClose(Presentation Pres)
pptApplication.SlideShowEnd -= PptApplication_SlideShowEnd;
pptApplication = null;
timerCheckPPT.Start();

Application.Current.Dispatcher.Invoke(() =>
{
//BtnPPTSlideShow.Visibility = Visibility.Collapsed;
BtnPPTSlideShowEnd.Visibility = Visibility.Collapsed;
});

}

bool isPresentationHaveBlackSpace = false;

Check warning on line 274 in Ink Canvas/MainWindow_cs/MW_PPT.cs

View workflow job for this annotation

GitHub Actions / build

The field 'MainWindow.isPresentationHaveBlackSpace' is assigned but its value is never used

Check warning on line 274 in Ink Canvas/MainWindow_cs/MW_PPT.cs

View workflow job for this annotation

GitHub Actions / build

The field 'MainWindow.isPresentationHaveBlackSpace' is assigned but its value is never used

Check warning on line 274 in Ink Canvas/MainWindow_cs/MW_PPT.cs

View workflow job for this annotation

GitHub Actions / build

The field 'MainWindow.isPresentationHaveBlackSpace' is assigned but its value is never used

Check warning on line 274 in Ink Canvas/MainWindow_cs/MW_PPT.cs

View workflow job for this annotation

GitHub Actions / build

The field 'MainWindow.isPresentationHaveBlackSpace' is assigned but its value is never used

Check warning on line 274 in Ink Canvas/MainWindow_cs/MW_PPT.cs

View workflow job for this annotation

GitHub Actions / build

The field 'MainWindow.isPresentationHaveBlackSpace' is assigned but its value is never used

Check warning on line 274 in Ink Canvas/MainWindow_cs/MW_PPT.cs

View workflow job for this annotation

GitHub Actions / build

The field 'MainWindow.isPresentationHaveBlackSpace' is assigned but its value is never used
Expand Down Expand Up @@ -587,14 +585,7 @@ private void BtnPPTSlidesUp_Click(object sender, RoutedEventArgs e)
catch { } // Without this catch{}, app will crash when click the pre-page button in the fir page in some special env.
})).Start();
}
catch
{
BtnPPTSlideShowEnd.Visibility = Visibility.Collapsed;
PPTNavigationBottomLeft.Visibility = Visibility.Collapsed;
PPTNavigationBottomRight.Visibility = Visibility.Collapsed;
PPTNavigationSidesLeft.Visibility = Visibility.Collapsed;
PPTNavigationSidesRight.Visibility = Visibility.Collapsed;
}
catch { }
}

private void BtnPPTSlidesDown_Click(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -627,14 +618,7 @@ private void BtnPPTSlidesDown_Click(object sender, RoutedEventArgs e)
catch { }
})).Start();
}
catch
{
BtnPPTSlideShowEnd.Visibility = Visibility.Collapsed;
PPTNavigationBottomLeft.Visibility = Visibility.Collapsed;
PPTNavigationBottomRight.Visibility = Visibility.Collapsed;
PPTNavigationSidesLeft.Visibility = Visibility.Collapsed;
PPTNavigationSidesRight.Visibility = Visibility.Collapsed;
}
catch { }
}


Expand Down
91 changes: 86 additions & 5 deletions Ink Canvas/MainWindow_cs/MW_SelectionGestures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ private void BorderStrokeSelectionClone_Click(object sender, RoutedEventArgs e)
}
}

private void BorderStrokeSelectionCloneToNewBoard_Click(object sender, RoutedEventArgs e)
private void BorderStrokeSelectionCloneToBoardOrNewPage_Click(object sender, RoutedEventArgs e)
{
if (currentMode == 0)
{
Expand Down Expand Up @@ -268,18 +268,96 @@ private void BtnClockwiseRotate90_Click(object sender, RoutedEventArgs e)
#endregion

bool isGridInkCanvasSelectionCoverMouseDown = false;
private Point lastMousePoint;

private void GridInkCanvasSelectionCover_MouseDown(object sender, MouseButtonEventArgs e)
{
lastMousePoint = e.GetPosition(inkCanvas);
isGridInkCanvasSelectionCoverMouseDown = true;
if (isStrokeSelectionCloneOn)
{
StrokeCollection strokes = inkCanvas.GetSelectedStrokes();
List<Image> imageList = InkCanvasImageHelper.GetSelectedImages(inkCanvas);
isProgramChangeStrokeSelection = true;
ImagesSelectionClone = InkCanvasImageHelper.CloneSelectedImages(inkCanvas);
inkCanvas.Select(new StrokeCollection());
StrokesSelectionClone = strokes.Clone();
inkCanvas.Strokes.Add(StrokesSelectionClone);
inkCanvas.Select(strokes, imageList);
isProgramChangeStrokeSelection = false;
}
else if (lastMousePoint.X < inkCanvas.GetSelectionBounds().Left ||
lastMousePoint.Y < inkCanvas.GetSelectionBounds().Top ||
lastMousePoint.X > inkCanvas.GetSelectionBounds().Right ||
lastMousePoint.Y > inkCanvas.GetSelectionBounds().Bottom)
{
isGridInkCanvasSelectionCoverMouseDown = false;
inkCanvas.Select(new StrokeCollection());
StrokesSelectionClone = new StrokeCollection();
ImagesSelectionClone = new List<Image>();
}
}

private void GridInkCanvasSelectionCover_MouseMove(object sender, MouseEventArgs e)
{
if (isGridInkCanvasSelectionCoverMouseDown == false) return;
Point mousePoint = e.GetPosition(inkCanvas);
Vector trans = new Vector(mousePoint.X - lastMousePoint.X, mousePoint.Y - lastMousePoint.Y);
lastMousePoint = mousePoint;
Rect bounds = inkCanvas.GetSelectionBounds();
Point center = new Point(bounds.Left + bounds.Width / 2, bounds.Top + bounds.Height / 2);
Matrix m = new Matrix();
// handle images
List<Image> images = new List<Image>();
if (ImagesSelectionClone.Count != 0)
{
images = ImagesSelectionClone;
}
else
{
images = InkCanvasImageHelper.GetSelectedImages(inkCanvas);
}
foreach (Image image in images)
{
ApplyImageMatrixTransform(image, m, center, trans.X, trans.Y);
}
// add Translate
m.Translate(trans.X, trans.Y);
// handle strokes
StrokeCollection strokes = inkCanvas.GetSelectedStrokes();
if (StrokesSelectionClone.Count != 0)
{
strokes = StrokesSelectionClone;
}
foreach (Stroke stroke in strokes)
{
stroke.Transform(m, false);
}
updateBorderStrokeSelectionControlLocation();
}

private void GridInkCanvasSelectionCover_MouseUp(object sender, MouseButtonEventArgs e)
{
if (isGridInkCanvasSelectionCoverMouseDown)
isGridInkCanvasSelectionCoverMouseDown = false;
if (InkCanvasImageHelper.IsNotCanvasElementSelected(inkCanvas))
{
isGridInkCanvasSelectionCoverMouseDown = false;
GridInkCanvasSelectionCover.Visibility = Visibility.Collapsed;
StrokesSelectionClone = new StrokeCollection();
ImagesSelectionClone = new List<Image>();
}
else
{
if (currentMode == 0)
{
TextSelectionCloneToNewBoard.Text = "衍至画板";
}
else
{
TextSelectionCloneToNewBoard.Text = "衍至新页";
}
GridInkCanvasSelectionCover.Visibility = Visibility.Visible;
StrokesSelectionClone = new StrokeCollection();
ImagesSelectionClone = new List<Image>();
}
}

Expand Down Expand Up @@ -329,7 +407,7 @@ private void BtnSelect_Click(object sender, RoutedEventArgs e)
private void inkCanvas_SelectionChanged(object sender, EventArgs e)
{
if (isProgramChangeStrokeSelection) return;
if (inkCanvas.GetSelectedStrokes().Count == 0 && InkCanvasImageHelper.GetSelectedImages(inkCanvas).Count == 0)
if (InkCanvasImageHelper.IsNotCanvasElementSelected(inkCanvas))
{
GridInkCanvasSelectionCover.Visibility = Visibility.Collapsed;
}
Expand Down Expand Up @@ -492,12 +570,14 @@ private void GridInkCanvasSelectionCover_PreviewTouchUp(object sender, TouchEven
{
inkCanvas.Select(new StrokeCollection());
StrokesSelectionClone = new StrokeCollection();
ImagesSelectionClone = new List<Image>();
}
}
else if (inkCanvas.GetSelectedStrokes().Count == 0)
else if (InkCanvasImageHelper.IsNotCanvasElementSelected(inkCanvas))
{
GridInkCanvasSelectionCover.Visibility = Visibility.Collapsed;
StrokesSelectionClone = new StrokeCollection();
ImagesSelectionClone = new List<Image>();
}
else
{
Expand All @@ -511,6 +591,7 @@ private void GridInkCanvasSelectionCover_PreviewTouchUp(object sender, TouchEven
}
GridInkCanvasSelectionCover.Visibility = Visibility.Visible;
StrokesSelectionClone = new StrokeCollection();
ImagesSelectionClone = new List<Image>();
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions Ink Canvas/MainWindow_cs/MW_TouchEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
Expand Down Expand Up @@ -107,16 +106,17 @@ private async void MainWindow_StylusUp(object sender, StylusEventArgs e)
try
{
if (e.StylusDevice.TabletDevice.Type == TabletDeviceType.Stylus)
{ // 数位板 TabletDeviceType.Stylus
{
// 数位板 TabletDeviceType.Stylus
}
else
{ // 触摸屏 TabletDeviceType.Touch
{
// 触摸屏 TabletDeviceType.Touch
inkCanvas.Strokes.Add(GetStrokeVisual(e.StylusDevice.Id).Stroke);
await Task.Delay(5); // 避免渲染墨迹完成前预览墨迹被删除导致墨迹闪烁
inkCanvas.Children.Remove(GetVisualCanvas(e.StylusDevice.Id));
inkCanvas_StrokeCollected(inkCanvas, new InkCanvasStrokeCollectedEventArgs(GetStrokeVisual(e.StylusDevice.Id).Stroke));
}
await Task.Delay(5); // 避免渲染墨迹完成前预览墨迹被删除导致墨迹闪烁
inkCanvas.Children.Remove(GetVisualCanvas(e.StylusDevice.Id));

inkCanvas_StrokeCollected(inkCanvas, new InkCanvasStrokeCollectedEventArgs(GetStrokeVisual(e.StylusDevice.Id).Stroke));
}
catch (Exception ex)
{
Expand Down

0 comments on commit 18246e0

Please sign in to comment.