Big changes are coming

This commit is contained in:
XY Wang 2021-09-09 13:12:34 +08:00
parent 25b84533a0
commit 1a2622da58
6 changed files with 294 additions and 30 deletions

View File

@ -2,8 +2,14 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Ink_Canvas"
StartupUri="MainWindow.xaml">
StartupUri="MainWindow.xaml"
xmlns:ui="http://schemas.modernwpf.com/2019">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ui:ThemeResources />
<ui:XamlControlsResources />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>

View File

@ -13,5 +13,24 @@ namespace Ink_Canvas
/// </summary>
public partial class App : Application
{
System.Threading.Mutex mutex;
public App()
{
this.Startup += new StartupEventHandler(App_Startup);
}
void App_Startup(object sender, StartupEventArgs e)
{
bool ret;
mutex = new System.Threading.Mutex(true, "Ink_Canvas", out ret);
if (!ret)
{
MessageBox.Show("已有一个程序实例正在运行");
Environment.Exit(0);
}
}
}
}

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\Microsoft.Windows.SDK.Contracts.10.0.18362.2005\build\Microsoft.Windows.SDK.Contracts.props" Condition="Exists('..\packages\Microsoft.Windows.SDK.Contracts.10.0.18362.2005\build\Microsoft.Windows.SDK.Contracts.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@ -14,6 +15,8 @@
<WarningLevel>4</WarningLevel>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
@ -35,8 +38,18 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="ModernWpf, Version=0.9.4.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\ModernWpfUI.0.9.4\lib\net462\ModernWpf.dll</HintPath>
</Reference>
<Reference Include="ModernWpf.Controls, Version=0.9.4.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\ModernWpfUI.0.9.4\lib\net462\ModernWpf.Controls.dll</HintPath>
</Reference>
<Reference Include="netstandard" />
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll</HintPath>
</Reference>
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Core" />
@ -87,6 +100,7 @@
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
@ -96,4 +110,16 @@
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\System.Runtime.WindowsRuntime.4.6.0\build\net461\System.Runtime.WindowsRuntime.targets" Condition="Exists('..\packages\System.Runtime.WindowsRuntime.4.6.0\build\net461\System.Runtime.WindowsRuntime.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\System.Runtime.WindowsRuntime.4.6.0\build\net461\System.Runtime.WindowsRuntime.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\System.Runtime.WindowsRuntime.4.6.0\build\net461\System.Runtime.WindowsRuntime.targets'))" />
<Error Condition="!Exists('..\packages\System.Runtime.WindowsRuntime.UI.Xaml.4.6.0\build\net461\System.Runtime.WindowsRuntime.UI.Xaml.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\System.Runtime.WindowsRuntime.UI.Xaml.4.6.0\build\net461\System.Runtime.WindowsRuntime.UI.Xaml.targets'))" />
<Error Condition="!Exists('..\packages\Microsoft.Windows.SDK.Contracts.10.0.18362.2005\build\Microsoft.Windows.SDK.Contracts.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Windows.SDK.Contracts.10.0.18362.2005\build\Microsoft.Windows.SDK.Contracts.props'))" />
<Error Condition="!Exists('..\packages\Microsoft.Windows.SDK.Contracts.10.0.18362.2005\build\Microsoft.Windows.SDK.Contracts.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Windows.SDK.Contracts.10.0.18362.2005\build\Microsoft.Windows.SDK.Contracts.targets'))" />
</Target>
<Import Project="..\packages\System.Runtime.WindowsRuntime.UI.Xaml.4.6.0\build\net461\System.Runtime.WindowsRuntime.UI.Xaml.targets" Condition="Exists('..\packages\System.Runtime.WindowsRuntime.UI.Xaml.4.6.0\build\net461\System.Runtime.WindowsRuntime.UI.Xaml.targets')" />
<Import Project="..\packages\Microsoft.Windows.SDK.Contracts.10.0.18362.2005\build\Microsoft.Windows.SDK.Contracts.targets" Condition="Exists('..\packages\Microsoft.Windows.SDK.Contracts.10.0.18362.2005\build\Microsoft.Windows.SDK.Contracts.targets')" />
</Project>

View File

@ -2,16 +2,18 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" Topmost="True"
xmlns:local="clr-namespace:Ink_Canvas" AllowsTransparency="True" WindowStyle="None" ResizeMode="NoResize"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" Topmost="True" KeyDown="Window_KeyDown"
xmlns:local="clr-namespace:Ink_Canvas" xmlns:ui="http://schemas.modernwpf.com/2019" AllowsTransparency="True" WindowStyle="None" ResizeMode="NoResize"
mc:Ignorable="d" WindowState="Maximized" Loaded="Window_Loaded" Background="Transparent" ShowInTaskbar="False"
Title="MainWindow" Height="450" Width="800">
Title="MainWindow" Height="600" Width="800" FontFamily="Microsoft YaHei UI">
<!--资源中添加命令-->
<Window.Resources>
<RoutedUICommand x:Key="KeyExit" Text=" "/>
<RoutedUICommand x:Key="back_HotKey_Command" Text=" "/>
</Window.Resources>
<!--输入命令绑定-->
<Window.InputBindings>
<KeyBinding Gesture="Shift+Esc" Command="{StaticResource KeyExit}"/>
<KeyBinding Modifiers="Ctrl" Key="Z" Command="{StaticResource back_HotKey_Command}"/>
</Window.InputBindings>
<!--命令执行方法绑定-->
@ -19,8 +21,54 @@
<CommandBinding Command="{StaticResource back_HotKey_Command}"
CanExecute="CommandBinding_CanExecute"
Executed="back_HotKey"/>
<CommandBinding Command="{StaticResource KeyExit}"
CanExecute="CommandBinding_CanExecute"
Executed="KeyExit"/>
</Window.CommandBindings>
<Grid x:Name="Main_Grid" Background="#01FFFFFF">
<Grid x:Name="Main_Grid" Background="#01FFFFFF" TouchDown="Main_Grid_TouchDown">
<Grid Name="GridBackgroundCover" Background="Transparent"/>
<Label Name="Label" Content="0"/>
<InkCanvas Name="inkCanvas" Background="Transparent"></InkCanvas>
<StackPanel Name="StackPanelMain" Margin="10" HorizontalAlignment="Right" VerticalAlignment="Center" Width="50">
<StackPanel Name="StackPanelControl">
<Button Name="BtnExit" Content="退出" FontFamily="Microsoft YaHei UI"
Margin="0,0,0,0" Width="{Binding ElementName=StackPanelMain, Path=ActualWidth}"
Click="BtnExit_Click"/>
<StackPanel Name="StackPanelColors" Margin="10,0,10,0">
<Button Name="BtnColorBlack" Content="" FontFamily="Microsoft YaHei UI" Background="Black"
Margin="0,10,0,0" Width="{Binding ElementName=StackPanelMain, Path=ActualWidth}"
Click="BtnColorBlack_Click"/>
<Button Name="BtnColorRed" Content="" FontFamily="Microsoft YaHei UI" Background="Red"
Margin="0,10,0,0" Width="{Binding ElementName=StackPanelMain, Path=ActualWidth}"
Click="BtnColorRed_Click"/>
<Button Name="BtnColorGreen" Content="" FontFamily="Microsoft YaHei UI" Background="#1ED760"
Margin="0,10,0,0" Width="{Binding ElementName=StackPanelMain, Path=ActualWidth}"
Click="BtnColorGreen_Click"/>
<Button Name="BtnColorBlue" Content="" FontFamily="Microsoft YaHei UI" Background="#239AD6"
Margin="0,10,0,0" Width="{Binding ElementName=StackPanelMain, Path=ActualWidth}"
Click="BtnColorBlue_Click"/>
<Button Name="BtnColorYellow" Content="" FontFamily="Microsoft YaHei UI" Background="#FFDC00"
Margin="0,10,0,0" Width="{Binding ElementName=StackPanelMain, Path=ActualWidth}"
Click="BtnColorYellow_Click"/>
</StackPanel>
<Button Name="BtnThickness" Content="粗细" FontFamily="Microsoft YaHei UI"
Margin="0,10,0,0" Width="{Binding ElementName=StackPanelMain, Path=ActualWidth}"
Click="BtnThickness_Click"/>
<Button Name="BtnErase" Content="橡皮" FontFamily="Microsoft YaHei UI"
Margin="0,10,0,0" Width="{Binding ElementName=StackPanelMain, Path=ActualWidth}"
Click="BtnErase_Click"/>
<Button Name="BtnClear" Content="清屏" FontFamily="Microsoft YaHei UI"
Margin="0,10,0,0" Width="{Binding ElementName=StackPanelMain, Path=ActualWidth}"
Click="BtnClear_Click"/>
<Button Name="BtnSwitch" Content="切换" FontFamily="Microsoft YaHei UI"
Margin="0,10,0,0" Width="{Binding ElementName=StackPanelMain, Path=ActualWidth}"
Click="BtnSwitch_Click"/>
<ui:ToggleSwitch Name="ToggleSwitchModeWei" Header="老魏 模式" FontFamily="Microsoft YaHei UI"
Margin="10,10,0,0" OnContent="" OffContent="" Toggled="ToggleSwitchModeWei_Toggled"/>
</StackPanel>
<Button x:Name="BtnHideControl" Content="隐藏" FontFamily="Microsoft YaHei UI"
Margin="0,10,0,0" Width="{Binding ElementName=StackPanelMain, Path=ActualWidth}"
Click="BtnHideControl_Click"/>
</StackPanel>
</Grid>
</Window>

View File

@ -74,30 +74,30 @@ namespace Ink_Canvas
bool isInkCanvasVisible = true;
private void Window_Loaded(object sender, RoutedEventArgs e)
{
MessageBox.Show("Ink Canvas by WXRIW\n" +
"Version 1.0.0_beta\n\n" +
"HotKeys:\n" +
"Alt + 1: Clean the ink and show or hide the canvas.\n" +
"Alt + 2: Show or hide the canvas.\n" +
"Alt + 3: Switch mode (Ink & Eraser)\n" +
"Alt + 4: Exit.\n" +
"Ctrl + Z: Erase the last inking.\n" +
"\n" +
"You can put an unsigned integer in Thinkness.ini to customize the ink's thinkness.\n" +
"\n\n" +
"墨迹画板 by WXRIW\n" +
"版本 1.0.0_beta\n\n" +
"快捷键:\n" +
"Alt + 1: 清除墨迹并显示或隐藏画板\n" +
"Alt + 2: 显示或隐藏画板\n" +
"Alt + 3: 切换模式 (墨迹 & 橡皮擦)\n" +
"Alt + 4: 退出\n" +
"Ctrl + Z: 删除上一笔\n" +
"\n" +
"你可以新建Thinkness.ini文件在里面放一个正整数来自定义墨迹的粗细。\n" +
"\n" +
"GitHub: https://github.com/WXRIW/Ink-Canvas" +
"");
//MessageBox.Show("Ink Canvas by WXRIW\n" +
// "Version 1.0.0_beta\n\n" +
// "HotKeys:\n" +
// "Alt + 1: Clean the ink and show or hide the canvas.\n" +
// "Alt + 2: Show or hide the canvas.\n" +
// "Alt + 3: Switch mode (Ink & Eraser)\n" +
// "Alt + 4: Exit.\n" +
// "Ctrl + Z: Erase the last inking.\n" +
// "\n" +
// "You can put an unsigned integer in Thinkness.ini to customize the ink's thinkness.\n" +
// "\n\n" +
// "墨迹画板 by WXRIW\n" +
// "版本 1.0.0_beta\n\n" +
// "快捷键:\n" +
// "Alt + 1: 清除墨迹并显示或隐藏画板\n" +
// "Alt + 2: 显示或隐藏画板\n" +
// "Alt + 3: 切换模式 (墨迹 & 橡皮擦)\n" +
// "Alt + 4: 退出\n" +
// "Ctrl + Z: 删除上一笔\n" +
// "\n" +
// "你可以新建Thinkness.ini文件在里面放一个正整数来自定义墨迹的粗细。\n" +
// "\n" +
// "GitHub: https://github.com/WXRIW/Ink-Canvas" +
// "");
string failedHotKeys = "";
@ -108,12 +108,14 @@ namespace Ink_Canvas
Main_Grid.Visibility = Visibility.Hidden;
isInkCanvasVisible = false;
//inkCanvas.Strokes.Clear();
WindowState = WindowState.Minimized;
}
else
{
Main_Grid.Visibility = Visibility.Visible;
isInkCanvasVisible = true;
inkCanvas.Strokes.Clear();
WindowState = WindowState.Maximized;
}
}) == false)
{
@ -127,12 +129,14 @@ namespace Ink_Canvas
Main_Grid.Visibility = Visibility.Hidden;
isInkCanvasVisible = false;
//inkCanvas.Strokes.Clear();
WindowState = WindowState.Minimized;
}
else
{
Main_Grid.Visibility = Visibility.Visible;
isInkCanvasVisible = true;
//inkCanvas.Strokes.Clear();
WindowState = WindowState.Maximized;
}
}) == false)
{
@ -173,6 +177,159 @@ namespace Ink_Canvas
}
catch { }
}
private void KeyExit(object sender, ExecutedRoutedEventArgs e)
{
if (isInkCanvasVisible)
{
Main_Grid.Visibility = Visibility.Hidden;
isInkCanvasVisible = false;
//inkCanvas.Strokes.Clear();
WindowState = WindowState.Minimized;
}
else
{
Main_Grid.Visibility = Visibility.Visible;
isInkCanvasVisible = true;
inkCanvas.Strokes.Clear();
WindowState = WindowState.Maximized;
}
}
private void Window_KeyDown(object sender, KeyEventArgs e)
{
if(e.Key == Key.Escape)
{
KeyExit(null, null);
}
}
private void BtnExit_Click(object sender, RoutedEventArgs e)
{
Close();
}
private void BtnThickness_Click(object sender, RoutedEventArgs e)
{
}
private void BtnErase_Click(object sender, RoutedEventArgs e)
{
inkCanvas.EditingMode = InkCanvasEditingMode.EraseByStroke;
}
private void BtnClear_Click(object sender, RoutedEventArgs e)
{
inkCanvas.Strokes.Clear();
}
private void BtnHideControl_Click(object sender, RoutedEventArgs e)
{
if (StackPanelControl.Visibility == Visibility.Visible)
{
StackPanelControl.Visibility = Visibility.Hidden;
}
else
{
StackPanelControl.Visibility = Visibility.Visible;
}
}
private void BtnColorBlack_Click(object sender, RoutedEventArgs e)
{
inkCanvas.DefaultDrawingAttributes.Color = Colors.Black;
}
private void BtnColorRed_Click(object sender, RoutedEventArgs e)
{
inkCanvas.DefaultDrawingAttributes.Color = Colors.Red;
}
private void BtnColorGreen_Click(object sender, RoutedEventArgs e)
{
inkCanvas.DefaultDrawingAttributes.Color = StringToColor("#FF1ED760");
}
private void BtnColorBlue_Click(object sender, RoutedEventArgs e)
{
inkCanvas.DefaultDrawingAttributes.Color = StringToColor("#FF239AD6");
}
private void BtnColorYellow_Click(object sender, RoutedEventArgs e)
{
inkCanvas.DefaultDrawingAttributes.Color = StringToColor("#FFFFDC00");
}
private Color StringToColor(string colorStr)
{
Byte[] argb = new Byte[4];
for (int i = 0; i < 4; i++)
{
char[] charArray = colorStr.Substring(i * 2 + 1, 2).ToCharArray();
//string str = "11";
Byte b1 = toByte(charArray[0]);
Byte b2 = toByte(charArray[1]);
argb[i] = (Byte)(b2 | (b1 << 4));
}
return Color.FromArgb(argb[0], argb[1], argb[2], argb[3]);//#FFFFFFFF
}
private static byte toByte(char c)
{
byte b = (byte)"0123456789ABCDEF".IndexOf(c);
return b;
}
int BoundsWidth = 6;
private void Main_Grid_TouchDown(object sender, TouchEventArgs e)
{
Label.Content = e.GetTouchPoint(null).Bounds.Width.ToString();
if (e.GetTouchPoint(null).Bounds.Width > BoundsWidth)
{
inkCanvas.EditingMode = InkCanvasEditingMode.EraseByStroke;
}
else
{
inkCanvas.EditingMode = InkCanvasEditingMode.Ink;
}
}
int currentMode = 0;
private void BtnSwitch_Click(object sender, RoutedEventArgs e)
{
switch ((++currentMode) % 3)
{
case 0:
GridBackgroundCover.Background = Brushes.Transparent;
break;
case 1:
GridBackgroundCover.Background = Brushes.White;
break;
case 2:
GridBackgroundCover.Background = Brushes.Black;
break;
}
}
private void BtnColorYellow_Click_1(object sender, RoutedEventArgs e)
{
}
private void ToggleSwitchModeWei_Toggled(object sender, RoutedEventArgs e)
{
if (ToggleSwitchModeWei.IsOn)
{
BoundsWidth = 10;
}
else
{
BoundsWidth = 6;
}
}
}
enum HotkeyModifiers

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Windows.SDK.Contracts" version="10.0.18362.2005" targetFramework="net472" />
<package id="ModernWpfUI" version="0.9.4" targetFramework="net472" />
<package id="System.Runtime.WindowsRuntime" version="4.6.0" targetFramework="net472" />
<package id="System.Runtime.WindowsRuntime.UI.Xaml" version="4.6.0" targetFramework="net472" />
<package id="System.ValueTuple" version="4.5.0" targetFramework="net472" />
</packages>