Skip to content

Commit c5ccc30

Browse files
committed
[Add] Clone strokes to Board, Save Selected strokes to Image, change the color of selected strokes
[UI] SelectionControl
1 parent b57ad70 commit c5ccc30

File tree

6 files changed

+687
-303
lines changed

6 files changed

+687
-303
lines changed

AutomaticUpdateVersionControl.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4.9.3
1+
4.9.4

Ink Canvas/MainWindow.xaml

Lines changed: 469 additions & 147 deletions
Large diffs are not rendered by default.

Ink Canvas/MainWindow_cs/MW_AutoTheme.cs

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Windows.Media;
66
using Application = System.Windows.Application;
77
using System.Windows.Controls;
8+
using System.Linq;
89

910
namespace Ink_Canvas
1011
{
@@ -22,58 +23,65 @@ public string GetMainWindowTheme()
2223
}
2324
}
2425

26+
void RemoveResourceDictionary(Uri uri)
27+
{
28+
var dictionaries = Application.Current.Resources.MergedDictionaries;
29+
var dictionaryToRemove = dictionaries.FirstOrDefault(d => d.Source == uri);
30+
31+
if (dictionaryToRemove != null)
32+
{
33+
dictionaries.Remove(dictionaryToRemove);
34+
}
35+
}
36+
2537
private void ComboBoxTheme_SelectionChanged(object sender, SelectionChangedEventArgs e)
2638
{
2739
if (!isLoaded) return;
2840
Settings.Appearance.Theme = ComboBoxTheme.SelectedIndex;
2941
SystemEvents_UserPreferenceChanged(null, null);
3042
SaveSettingsToFile();
3143
}
32-
Color FloatBarForegroundColor = Color.FromRgb(102, 102, 102);
33-
Color BoardBarForegroundColor = Color.FromRgb(102, 102, 102);
34-
private void SetTheme(string theme)
44+
45+
private void SetBoardTheme()
3546
{
36-
if (theme == "Light")
47+
var lightBoardUri = new Uri("Resources/Styles/Light-Board.xaml", UriKind.Relative);
48+
var darkBoardUri = new Uri("Resources/Styles/Dark-Board.xaml", UriKind.Relative);
49+
if (Settings.Canvas.UsingWhiteboard)
50+
{
51+
ResourceDictionary rd = new ResourceDictionary { Source = lightBoardUri };
52+
Application.Current.Resources.MergedDictionaries.Add(rd);
53+
RemoveResourceDictionary(darkBoardUri);
54+
}
55+
else
3756
{
38-
ResourceDictionary rd = new ResourceDictionary() { Source = new Uri("Resources/Styles/Light.xaml", UriKind.Relative) };
57+
ResourceDictionary rd = new ResourceDictionary { Source = darkBoardUri };
3958
Application.Current.Resources.MergedDictionaries.Add(rd);
59+
RemoveResourceDictionary(lightBoardUri);
60+
}
61+
}
4062

41-
if (Settings.Canvas.UsingWhiteboard)
42-
{
43-
rd = new ResourceDictionary() { Source = new Uri("Resources/Styles/Light-Board.xaml", UriKind.Relative) };
44-
Application.Current.Resources.MergedDictionaries.Add(rd);
45-
}
46-
else
47-
{
48-
rd = new ResourceDictionary() { Source = new Uri("Resources/Styles/Dark-Board.xaml", UriKind.Relative) };
49-
Application.Current.Resources.MergedDictionaries.Add(rd);
50-
}
63+
private void SetTheme(string theme)
64+
{
65+
var lightUri = new Uri("Resources/Styles/Light.xaml", UriKind.Relative);
66+
var darkUri = new Uri("Resources/Styles/Dark.xaml", UriKind.Relative);
67+
68+
SetBoardTheme();
5169

70+
if (theme == "Light")
71+
{
72+
ResourceDictionary rd = new ResourceDictionary { Source = lightUri };
73+
Application.Current.Resources.MergedDictionaries.Add(rd);
74+
RemoveResourceDictionary(darkUri);
5275
ThemeManager.SetRequestedTheme(window, ElementTheme.Light);
5376
ThemeManager.Current.ApplicationTheme = ApplicationTheme.Light;
54-
FloatBarForegroundColor = (Color)Application.Current.FindResource("FloatBarForegroundColor");
55-
BoardBarForegroundColor = (Color)Application.Current.FindResource("BoardBarForegroundColor");
5677
}
5778
else if (theme == "Dark")
5879
{
59-
ResourceDictionary rd = new ResourceDictionary() { Source = new Uri("Resources/Styles/Dark.xaml", UriKind.Relative) };
80+
ResourceDictionary rd = new ResourceDictionary { Source = darkUri };
6081
Application.Current.Resources.MergedDictionaries.Add(rd);
61-
62-
if (Settings.Canvas.UsingWhiteboard)
63-
{
64-
rd = new ResourceDictionary() { Source = new Uri("Resources/Styles/Light-Board.xaml", UriKind.Relative) };
65-
Application.Current.Resources.MergedDictionaries.Add(rd);
66-
}
67-
else
68-
{
69-
rd = new ResourceDictionary() { Source = new Uri("Resources/Styles/Dark-Board.xaml", UriKind.Relative) };
70-
Application.Current.Resources.MergedDictionaries.Add(rd);
71-
}
72-
82+
RemoveResourceDictionary(lightUri);
7383
ThemeManager.SetRequestedTheme(window, ElementTheme.Dark);
7484
ThemeManager.Current.ApplicationTheme = ApplicationTheme.Dark;
75-
FloatBarForegroundColor = (Color)Application.Current.FindResource("FloatBarForegroundColor");
76-
BoardBarForegroundColor = (Color)Application.Current.FindResource("BoardBarForegroundColor");
7785
}
7886

7987
if (!Settings.Appearance.IsColorfulViewboxFloatingBar) // 还原浮动工具栏背景色

Ink Canvas/MainWindow_cs/MW_PenColors.cs

Lines changed: 46 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using Ink_Canvas.Helpers;
22
using System;
33
using System.Collections.Generic;
4-
using System.Threading.Tasks;
54
using System.Windows;
65
using System.Windows.Controls;
76
using System.Windows.Ink;
@@ -85,6 +84,30 @@ private void ColorSwitchCheck()
8584

8685
bool isUselightThemeColor = false, isDesktopUselightThemeColor = false;
8786
int lastDesktopInkColor = 1, lastBoardInkColor = 5;
87+
Dictionary<int, Color> inkColorLightThemeMapping = new Dictionary<int, Color>
88+
{
89+
{ 0, Colors.Black }, // Black
90+
{ 1, Color.FromRgb(239, 68, 68) }, // Red
91+
{ 2, Color.FromRgb(34, 197, 94) }, // Green
92+
{ 3, Color.FromRgb(59, 130, 246) }, // Blue
93+
{ 4, Color.FromRgb(250, 204, 21) }, // Yellow
94+
{ 5, Colors.White }, // White
95+
{ 6, Color.FromRgb(236, 72, 153) }, // Pink
96+
{ 7, Color.FromRgb(20, 184, 166) }, // Teal
97+
{ 8, Color.FromRgb(249, 115, 22) }, // Orange
98+
};
99+
Dictionary<int, Color> inkColorDarkThemeMapping = new Dictionary<int, Color>
100+
{
101+
{ 0, Colors.Black }, // Black
102+
{ 1, Color.FromRgb(220, 38, 38) }, // Red
103+
{ 2, Color.FromRgb(22, 163, 74) }, // Green
104+
{ 3, Color.FromRgb(37, 99, 235) }, // Blue
105+
{ 4, Color.FromRgb(234, 179, 8) }, // Yellow
106+
{ 5, Colors.White }, // White
107+
{ 6, Color.FromRgb(147, 51, 234) }, // Pink (Purple)
108+
{ 7, Color.FromRgb(13, 148, 136) }, // Teal
109+
{ 8, Color.FromRgb(234, 88, 12) } // Orange
110+
};
88111

89112
private void CheckColorTheme(bool changeColorTheme = false)
90113
{
@@ -139,75 +162,13 @@ private void CheckColorTheme(bool changeColorTheme = false)
139162
{ // Highlighter Purple
140163
inkCanvas.DefaultDrawingAttributes.Color = Color.FromRgb(147, 51, 234);
141164
}
142-
else if (inkColor == 0)
143-
{ // Black
144-
inkCanvas.DefaultDrawingAttributes.Color = Colors.Black;
145-
}
146-
else if (inkColor == 5)
147-
{ // White
148-
inkCanvas.DefaultDrawingAttributes.Color = Colors.White;
149-
}
150165
else if (isUselightThemeColor)
151166
{
152-
if (inkColor == 1)
153-
{ // Red
154-
inkCanvas.DefaultDrawingAttributes.Color = Color.FromRgb(239, 68, 68);
155-
}
156-
else if (inkColor == 2)
157-
{ // Green
158-
inkCanvas.DefaultDrawingAttributes.Color = Color.FromRgb(34, 197, 94);
159-
}
160-
else if (inkColor == 3)
161-
{ // Blue
162-
inkCanvas.DefaultDrawingAttributes.Color = Color.FromRgb(59, 130, 246);
163-
}
164-
else if (inkColor == 4)
165-
{ // Yellow
166-
inkCanvas.DefaultDrawingAttributes.Color = Color.FromRgb(250, 204, 21);
167-
}
168-
else if (inkColor == 6)
169-
{ // Pink
170-
inkCanvas.DefaultDrawingAttributes.Color = Color.FromRgb(236, 72, 153);
171-
}
172-
else if (inkColor == 7)
173-
{ // Teal
174-
inkCanvas.DefaultDrawingAttributes.Color = Color.FromRgb(20, 184, 166);
175-
}
176-
else if (inkColor == 8)
177-
{ // Orange
178-
inkCanvas.DefaultDrawingAttributes.Color = Color.FromRgb(249, 115, 22);
179-
}
167+
inkCanvas.DefaultDrawingAttributes.Color = inkColorLightThemeMapping[inkColor];
180168
}
181169
else
182170
{
183-
if (inkColor == 1)
184-
{ // Red
185-
inkCanvas.DefaultDrawingAttributes.Color = Color.FromRgb(220, 38, 38);
186-
}
187-
else if (inkColor == 2)
188-
{ // Green
189-
inkCanvas.DefaultDrawingAttributes.Color = Color.FromRgb(22, 163, 74);
190-
}
191-
else if (inkColor == 3)
192-
{ // Blue
193-
inkCanvas.DefaultDrawingAttributes.Color = Color.FromRgb(37, 99, 235);
194-
}
195-
else if (inkColor == 4)
196-
{ // Yellow
197-
inkCanvas.DefaultDrawingAttributes.Color = Color.FromRgb(234, 179, 8);
198-
}
199-
else if (inkColor == 6)
200-
{ // Pink ( Purple )
201-
inkCanvas.DefaultDrawingAttributes.Color = Color.FromRgb(147, 51, 234);
202-
}
203-
else if (inkColor == 7)
204-
{ // Teal
205-
inkCanvas.DefaultDrawingAttributes.Color = Color.FromRgb(13, 148, 136);
206-
}
207-
else if (inkColor == 8)
208-
{ // Orange
209-
inkCanvas.DefaultDrawingAttributes.Color = Color.FromRgb(234, 88, 12);
210-
}
171+
inkCanvas.DefaultDrawingAttributes.Color = inkColorDarkThemeMapping[inkColor];
211172
}
212173
if (isUselightThemeColor)
213174
{ // 亮系
@@ -385,68 +346,76 @@ private void CheckColorTheme(bool changeColorTheme = false)
385346

386347
private void CheckLastColor(int inkColor)
387348
{
388-
if (currentMode == 0)
349+
StrokeCollection strokes = inkCanvas.GetSelectedStrokes();
350+
if (strokes.Count > 0)
389351
{
390-
lastDesktopInkColor = inkColor;
352+
Color targetedColor = inkColorLightThemeMapping[inkColor];
353+
if (!isUselightThemeColor)
354+
{
355+
inkCanvas.DefaultDrawingAttributes.Color = inkColorDarkThemeMapping[inkColor];
356+
}
357+
foreach (Stroke stroke in strokes)
358+
{
359+
stroke.DrawingAttributes.Color = targetedColor;
360+
}
391361
}
392362
else
393363
{
394-
lastBoardInkColor = inkColor;
364+
if (currentMode == 0)
365+
{
366+
lastDesktopInkColor = inkColor;
367+
}
368+
else
369+
{
370+
lastBoardInkColor = inkColor;
371+
}
372+
ColorSwitchCheck();
395373
}
396374
}
397375

398376
private void BtnColorBlack_Click(object sender, RoutedEventArgs e)
399377
{
400378
CheckLastColor(0);
401-
ColorSwitchCheck();
402379
}
403380

404381
private void BtnColorRed_Click(object sender, RoutedEventArgs e)
405382
{
406383
CheckLastColor(1);
407-
ColorSwitchCheck();
408384
}
409385

410386
private void BtnColorGreen_Click(object sender, RoutedEventArgs e)
411387
{
412388
CheckLastColor(2);
413-
ColorSwitchCheck();
414389
}
415390

416391
private void BtnColorBlue_Click(object sender, RoutedEventArgs e)
417392
{
418393
CheckLastColor(3);
419-
ColorSwitchCheck();
420394
}
421395

422396
private void BtnColorYellow_Click(object sender, RoutedEventArgs e)
423397
{
424398
CheckLastColor(4);
425-
ColorSwitchCheck();
426399
}
427400

428401
private void BtnColorWhite_Click(object sender, RoutedEventArgs e)
429402
{
430403
CheckLastColor(5);
431-
ColorSwitchCheck();
432404
}
433405

434406
private void BtnColorPink_Click(object sender, RoutedEventArgs e)
435407
{
436408
CheckLastColor(6);
437-
ColorSwitchCheck();
438409
}
439410

440411
private void BtnColorTeal_Click(object sender, RoutedEventArgs e)
441412
{
442413
CheckLastColor(7);
443-
ColorSwitchCheck();
444414
}
445415

446416
private void BtnColorOrange_Click(object sender, RoutedEventArgs e)
447417
{
448418
CheckLastColor(8);
449-
ColorSwitchCheck();
450419
}
451420

452421
private Color StringToColor(string colorStr)

Ink Canvas/MainWindow_cs/MW_PenHighlighterColors.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,36 +20,30 @@ private void InkAlphaSlider_ValueChanged(object sender, RoutedPropertyChangedEve
2020
private void BtnHighlighterColorRed_Click(object sender, RoutedEventArgs e)
2121
{
2222
CheckLastColor(101);
23-
ColorSwitchCheck();
2423
}
2524

2625
private void BtnHighlighterColorOrange_Click(object sender, RoutedEventArgs e)
2726
{
2827
CheckLastColor(102);
29-
ColorSwitchCheck();
3028
}
3129

3230
private void BtnHighlighterColorYellow_Click(object sender, RoutedEventArgs e)
3331
{
3432
CheckLastColor(103);
35-
ColorSwitchCheck();
3633
}
3734

3835
private void BtnHighlighterColorTeal_Click(object sender, RoutedEventArgs e)
3936
{
4037
CheckLastColor(104);
41-
ColorSwitchCheck();
4238
}
4339
private void BtnHighlighterColorBlue_Click(object sender, RoutedEventArgs e)
4440
{
4541
CheckLastColor(105);
46-
ColorSwitchCheck();
4742
}
4843

4944
private void BtnHighlighterColorPurple_Click(object sender, RoutedEventArgs e)
5045
{
5146
CheckLastColor(106);
52-
ColorSwitchCheck();
5347
}
5448
}
5549
}

0 commit comments

Comments
 (0)