Skip to content

Commit 18246e0

Browse files
committed
[Add] GridInkCanvasSelectionCover_MouseDown, MouseMove, MouseUp
1 parent c5ccc30 commit 18246e0

File tree

5 files changed

+126
-47
lines changed

5 files changed

+126
-47
lines changed

Ink Canvas/Helpers/InkCanvasImageHelper.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,19 @@ namespace Ink_Canvas.Helpers
88
{
99
public static class InkCanvasImageHelper
1010
{
11+
public static bool IsNotCanvasElementSelected(InkCanvas inkCanvas)
12+
{
13+
if (inkCanvas.GetSelectedStrokes().Count > 0) return false;
14+
foreach (UIElement element in inkCanvas.GetSelectedElements())
15+
{
16+
if (element is Image selectedImage)
17+
{
18+
return false;
19+
}
20+
}
21+
return true;
22+
}
23+
1124
public static List<Image> GetSelectedImages(InkCanvas inkCanvas)
1225
{
1326
List<Image> selectedImages = new List<Image>();

Ink Canvas/MainWindow.xaml

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
ManipulationDelta="GridInkCanvasSelectionCover_ManipulationDelta"
106106
ManipulationStarting="GridInkCanvasSelectionCover_ManipulationStarting"
107107
MouseDown="GridInkCanvasSelectionCover_MouseDown"
108+
MouseMove="GridInkCanvasSelectionCover_MouseMove"
108109
MouseUp="GridInkCanvasSelectionCover_MouseUp"
109110
Opacity="0.01"
110111
PreviewTouchDown="GridInkCanvasSelectionCover_PreviewTouchDown"
@@ -149,7 +150,7 @@
149150
Height="35"
150151
Padding="0"
151152
Background="{DynamicResource FloatBarBackground}"
152-
Click="BorderStrokeSelectionCloneToNewBoard_Click">
153+
Click="BorderStrokeSelectionCloneToBoardOrNewPage_Click">
153154
<ikw:SimpleStackPanel HorizontalAlignment="Center" VerticalAlignment="Center" Orientation="Horizontal" Spacing="2">
154155
<ui:FontIcon
155156
Width="18"
@@ -523,11 +524,11 @@
523524
Height="30"
524525
Padding="0"
525526
Background="{DynamicResource FloatBarBackground}"
526-
Click="BtnColorPink_Click">
527+
Click="BtnColorOrange_Click">
527528
<Border
528529
Width="16"
529530
Height="16"
530-
Background="#c72ec7"
531+
Background="#ea580c"
531532
BorderBrush="{DynamicResource FloatBarBorderBrush}"
532533
BorderThickness="1.5"
533534
CornerRadius="100" />
@@ -537,11 +538,11 @@
537538
Height="30"
538539
Padding="0"
539540
Background="{DynamicResource FloatBarBackground}"
540-
Click="BtnColorOrange_Click">
541+
Click="BtnColorYellow_Click">
541542
<Border
542543
Width="16"
543544
Height="16"
544-
Background="#ea580c"
545+
Background="#eab308"
545546
BorderBrush="{DynamicResource FloatBarBorderBrush}"
546547
BorderThickness="1.5"
547548
CornerRadius="100" />
@@ -551,11 +552,11 @@
551552
Height="30"
552553
Padding="0"
553554
Background="{DynamicResource FloatBarBackground}"
554-
Click="BtnColorYellow_Click">
555+
Click="BtnColorGreen_Click">
555556
<Border
556557
Width="16"
557558
Height="16"
558-
Background="#eab308"
559+
Background="#16a34a"
559560
BorderBrush="{DynamicResource FloatBarBorderBrush}"
560561
BorderThickness="1.5"
561562
CornerRadius="100" />
@@ -565,11 +566,11 @@
565566
Height="30"
566567
Padding="0"
567568
Background="{DynamicResource FloatBarBackground}"
568-
Click="BtnColorGreen_Click">
569+
Click="BtnColorTeal_Click">
569570
<Border
570571
Width="16"
571572
Height="16"
572-
Background="#16a34a"
573+
Background="#0d9488"
573574
BorderBrush="{DynamicResource FloatBarBorderBrush}"
574575
BorderThickness="1.5"
575576
CornerRadius="100" />
@@ -579,11 +580,11 @@
579580
Height="30"
580581
Padding="0"
581582
Background="{DynamicResource FloatBarBackground}"
582-
Click="BtnColorTeal_Click">
583+
Click="BtnColorBlue_Click">
583584
<Border
584585
Width="16"
585586
Height="16"
586-
Background="#0d9488"
587+
Background="#2563eb"
587588
BorderBrush="{DynamicResource FloatBarBorderBrush}"
588589
BorderThickness="1.5"
589590
CornerRadius="100" />
@@ -593,11 +594,11 @@
593594
Height="30"
594595
Padding="0"
595596
Background="{DynamicResource FloatBarBackground}"
596-
Click="BtnColorBlue_Click">
597+
Click="BtnColorPink_Click">
597598
<Border
598599
Width="16"
599600
Height="16"
600-
Background="#2563eb"
601+
Background="#c72ec7"
601602
BorderBrush="{DynamicResource FloatBarBorderBrush}"
602603
BorderThickness="1.5"
603604
CornerRadius="100" />
@@ -5593,8 +5594,8 @@
55935594
</Border>
55945595
<!-- 202407
55955596
<Button
5596-
Width="62"
5597-
Height="30"
5597+
Width="70"
5598+
Height="36"
55985599
Margin="2,0,0,0"
55995600
Padding="0"
56005601
Background="{DynamicResource FloatBarBackground}"

Ink Canvas/MainWindow_cs/MW_PPT.cs

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using Ink_Canvas.Helpers;
22
using Microsoft.Office.Interop.PowerPoint;
3-
using iNKORE.UI.WPF.Modern;
43
using System;
54
using System.Diagnostics;
65
using System.IO;
@@ -14,7 +13,6 @@
1413
using System.Windows.Media;
1514
using Application = System.Windows.Application;
1615
using File = System.IO.File;
17-
using MessageBox = System.Windows.MessageBox;
1816
using Microsoft.Office.Core;
1917

2018
namespace Ink_Canvas
@@ -264,13 +262,13 @@ private void PptApplication_PresentationClose(Presentation Pres)
264262
pptApplication.SlideShowEnd -= PptApplication_SlideShowEnd;
265263
pptApplication = null;
266264
timerCheckPPT.Start();
267-
265+
268266
Application.Current.Dispatcher.Invoke(() =>
269267
{
270268
//BtnPPTSlideShow.Visibility = Visibility.Collapsed;
271269
BtnPPTSlideShowEnd.Visibility = Visibility.Collapsed;
272270
});
273-
271+
274272
}
275273

276274
bool isPresentationHaveBlackSpace = false;
@@ -587,14 +585,7 @@ private void BtnPPTSlidesUp_Click(object sender, RoutedEventArgs e)
587585
catch { } // Without this catch{}, app will crash when click the pre-page button in the fir page in some special env.
588586
})).Start();
589587
}
590-
catch
591-
{
592-
BtnPPTSlideShowEnd.Visibility = Visibility.Collapsed;
593-
PPTNavigationBottomLeft.Visibility = Visibility.Collapsed;
594-
PPTNavigationBottomRight.Visibility = Visibility.Collapsed;
595-
PPTNavigationSidesLeft.Visibility = Visibility.Collapsed;
596-
PPTNavigationSidesRight.Visibility = Visibility.Collapsed;
597-
}
588+
catch { }
598589
}
599590

600591
private void BtnPPTSlidesDown_Click(object sender, RoutedEventArgs e)
@@ -627,14 +618,7 @@ private void BtnPPTSlidesDown_Click(object sender, RoutedEventArgs e)
627618
catch { }
628619
})).Start();
629620
}
630-
catch
631-
{
632-
BtnPPTSlideShowEnd.Visibility = Visibility.Collapsed;
633-
PPTNavigationBottomLeft.Visibility = Visibility.Collapsed;
634-
PPTNavigationBottomRight.Visibility = Visibility.Collapsed;
635-
PPTNavigationSidesLeft.Visibility = Visibility.Collapsed;
636-
PPTNavigationSidesRight.Visibility = Visibility.Collapsed;
637-
}
621+
catch { }
638622
}
639623

640624

Ink Canvas/MainWindow_cs/MW_SelectionGestures.cs

Lines changed: 86 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ private void BorderStrokeSelectionClone_Click(object sender, RoutedEventArgs e)
4040
}
4141
}
4242

43-
private void BorderStrokeSelectionCloneToNewBoard_Click(object sender, RoutedEventArgs e)
43+
private void BorderStrokeSelectionCloneToBoardOrNewPage_Click(object sender, RoutedEventArgs e)
4444
{
4545
if (currentMode == 0)
4646
{
@@ -268,18 +268,96 @@ private void BtnClockwiseRotate90_Click(object sender, RoutedEventArgs e)
268268
#endregion
269269

270270
bool isGridInkCanvasSelectionCoverMouseDown = false;
271+
private Point lastMousePoint;
271272

272273
private void GridInkCanvasSelectionCover_MouseDown(object sender, MouseButtonEventArgs e)
273274
{
275+
lastMousePoint = e.GetPosition(inkCanvas);
274276
isGridInkCanvasSelectionCoverMouseDown = true;
277+
if (isStrokeSelectionCloneOn)
278+
{
279+
StrokeCollection strokes = inkCanvas.GetSelectedStrokes();
280+
List<Image> imageList = InkCanvasImageHelper.GetSelectedImages(inkCanvas);
281+
isProgramChangeStrokeSelection = true;
282+
ImagesSelectionClone = InkCanvasImageHelper.CloneSelectedImages(inkCanvas);
283+
inkCanvas.Select(new StrokeCollection());
284+
StrokesSelectionClone = strokes.Clone();
285+
inkCanvas.Strokes.Add(StrokesSelectionClone);
286+
inkCanvas.Select(strokes, imageList);
287+
isProgramChangeStrokeSelection = false;
288+
}
289+
else if (lastMousePoint.X < inkCanvas.GetSelectionBounds().Left ||
290+
lastMousePoint.Y < inkCanvas.GetSelectionBounds().Top ||
291+
lastMousePoint.X > inkCanvas.GetSelectionBounds().Right ||
292+
lastMousePoint.Y > inkCanvas.GetSelectionBounds().Bottom)
293+
{
294+
isGridInkCanvasSelectionCoverMouseDown = false;
295+
inkCanvas.Select(new StrokeCollection());
296+
StrokesSelectionClone = new StrokeCollection();
297+
ImagesSelectionClone = new List<Image>();
298+
}
299+
}
300+
301+
private void GridInkCanvasSelectionCover_MouseMove(object sender, MouseEventArgs e)
302+
{
303+
if (isGridInkCanvasSelectionCoverMouseDown == false) return;
304+
Point mousePoint = e.GetPosition(inkCanvas);
305+
Vector trans = new Vector(mousePoint.X - lastMousePoint.X, mousePoint.Y - lastMousePoint.Y);
306+
lastMousePoint = mousePoint;
307+
Rect bounds = inkCanvas.GetSelectionBounds();
308+
Point center = new Point(bounds.Left + bounds.Width / 2, bounds.Top + bounds.Height / 2);
309+
Matrix m = new Matrix();
310+
// handle images
311+
List<Image> images = new List<Image>();
312+
if (ImagesSelectionClone.Count != 0)
313+
{
314+
images = ImagesSelectionClone;
315+
}
316+
else
317+
{
318+
images = InkCanvasImageHelper.GetSelectedImages(inkCanvas);
319+
}
320+
foreach (Image image in images)
321+
{
322+
ApplyImageMatrixTransform(image, m, center, trans.X, trans.Y);
323+
}
324+
// add Translate
325+
m.Translate(trans.X, trans.Y);
326+
// handle strokes
327+
StrokeCollection strokes = inkCanvas.GetSelectedStrokes();
328+
if (StrokesSelectionClone.Count != 0)
329+
{
330+
strokes = StrokesSelectionClone;
331+
}
332+
foreach (Stroke stroke in strokes)
333+
{
334+
stroke.Transform(m, false);
335+
}
336+
updateBorderStrokeSelectionControlLocation();
275337
}
276338

277339
private void GridInkCanvasSelectionCover_MouseUp(object sender, MouseButtonEventArgs e)
278340
{
279-
if (isGridInkCanvasSelectionCoverMouseDown)
341+
isGridInkCanvasSelectionCoverMouseDown = false;
342+
if (InkCanvasImageHelper.IsNotCanvasElementSelected(inkCanvas))
280343
{
281-
isGridInkCanvasSelectionCoverMouseDown = false;
282344
GridInkCanvasSelectionCover.Visibility = Visibility.Collapsed;
345+
StrokesSelectionClone = new StrokeCollection();
346+
ImagesSelectionClone = new List<Image>();
347+
}
348+
else
349+
{
350+
if (currentMode == 0)
351+
{
352+
TextSelectionCloneToNewBoard.Text = "衍至画板";
353+
}
354+
else
355+
{
356+
TextSelectionCloneToNewBoard.Text = "衍至新页";
357+
}
358+
GridInkCanvasSelectionCover.Visibility = Visibility.Visible;
359+
StrokesSelectionClone = new StrokeCollection();
360+
ImagesSelectionClone = new List<Image>();
283361
}
284362
}
285363

@@ -329,7 +407,7 @@ private void BtnSelect_Click(object sender, RoutedEventArgs e)
329407
private void inkCanvas_SelectionChanged(object sender, EventArgs e)
330408
{
331409
if (isProgramChangeStrokeSelection) return;
332-
if (inkCanvas.GetSelectedStrokes().Count == 0 && InkCanvasImageHelper.GetSelectedImages(inkCanvas).Count == 0)
410+
if (InkCanvasImageHelper.IsNotCanvasElementSelected(inkCanvas))
333411
{
334412
GridInkCanvasSelectionCover.Visibility = Visibility.Collapsed;
335413
}
@@ -492,12 +570,14 @@ private void GridInkCanvasSelectionCover_PreviewTouchUp(object sender, TouchEven
492570
{
493571
inkCanvas.Select(new StrokeCollection());
494572
StrokesSelectionClone = new StrokeCollection();
573+
ImagesSelectionClone = new List<Image>();
495574
}
496575
}
497-
else if (inkCanvas.GetSelectedStrokes().Count == 0)
576+
else if (InkCanvasImageHelper.IsNotCanvasElementSelected(inkCanvas))
498577
{
499578
GridInkCanvasSelectionCover.Visibility = Visibility.Collapsed;
500579
StrokesSelectionClone = new StrokeCollection();
580+
ImagesSelectionClone = new List<Image>();
501581
}
502582
else
503583
{
@@ -511,6 +591,7 @@ private void GridInkCanvasSelectionCover_PreviewTouchUp(object sender, TouchEven
511591
}
512592
GridInkCanvasSelectionCover.Visibility = Visibility.Visible;
513593
StrokesSelectionClone = new StrokeCollection();
594+
ImagesSelectionClone = new List<Image>();
514595
}
515596
}
516597
}

Ink Canvas/MainWindow_cs/MW_TouchEvents.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System;
33
using System.Collections.Generic;
44
using System.Linq;
5-
using System.Threading;
65
using System.Threading.Tasks;
76
using System.Windows;
87
using System.Windows.Controls;
@@ -107,16 +106,17 @@ private async void MainWindow_StylusUp(object sender, StylusEventArgs e)
107106
try
108107
{
109108
if (e.StylusDevice.TabletDevice.Type == TabletDeviceType.Stylus)
110-
{ // 数位板 TabletDeviceType.Stylus
109+
{
110+
// 数位板 TabletDeviceType.Stylus
111111
}
112112
else
113-
{ // 触摸屏 TabletDeviceType.Touch
113+
{
114+
// 触摸屏 TabletDeviceType.Touch
114115
inkCanvas.Strokes.Add(GetStrokeVisual(e.StylusDevice.Id).Stroke);
116+
await Task.Delay(5); // 避免渲染墨迹完成前预览墨迹被删除导致墨迹闪烁
117+
inkCanvas.Children.Remove(GetVisualCanvas(e.StylusDevice.Id));
118+
inkCanvas_StrokeCollected(inkCanvas, new InkCanvasStrokeCollectedEventArgs(GetStrokeVisual(e.StylusDevice.Id).Stroke));
115119
}
116-
await Task.Delay(5); // 避免渲染墨迹完成前预览墨迹被删除导致墨迹闪烁
117-
inkCanvas.Children.Remove(GetVisualCanvas(e.StylusDevice.Id));
118-
119-
inkCanvas_StrokeCollected(inkCanvas, new InkCanvasStrokeCollectedEventArgs(GetStrokeVisual(e.StylusDevice.Id).Stroke));
120120
}
121121
catch (Exception ex)
122122
{

0 commit comments

Comments
 (0)