[update] 寫了一點ICCX的代碼
This commit is contained in:
parent
8a400e6b68
commit
63d95c935c
@ -1,98 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{26F0E9DD-A9DC-45D1-97B9-337C63863837}</ProjectGuid>
|
||||
<TargetFramework>net472</TargetFramework>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<RootNamespace>CvtePaintDemo</RootNamespace>
|
||||
<AssemblyName>CvtePaintDemo</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<Deterministic>true</Deterministic>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
<UseWPF>true</UseWPF>
|
||||
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xaml">
|
||||
<RequiredTargetFramework>4.0</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="WindowsBase" />
|
||||
<Reference Include="PresentationCore" />
|
||||
<Reference Include="PresentationFramework" />
|
||||
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
|
||||
<PackageReference Include="System.Data.DataSetExtensions" Version="4.5.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ApplicationDefinition Include="App.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</ApplicationDefinition>
|
||||
<Page Include="MainWindow.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
<Compile Include="App.xaml.cs">
|
||||
<DependentUpon>App.xaml</DependentUpon>
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="MainWindow.xaml.cs">
|
||||
<DependentUpon>MainWindow.xaml</DependentUpon>
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Properties\AssemblyInfo.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Properties\Resources.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTime>True</DesignTime>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Properties\Settings.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Settings.settings</DependentUpon>
|
||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
</Compile>
|
||||
<EmbeddedResource Include="Properties\Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
<None Include="Properties\Settings.settings">
|
||||
<Generator>SettingsSingleFileGenerator</Generator>
|
||||
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
@ -1,98 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{98DF6AA1-DD4D-4C70-A0A2-4B2974D97D51}</ProjectGuid>
|
||||
<TargetFramework>net472</TargetFramework>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<RootNamespace>InkCanvasForClassX</RootNamespace>
|
||||
<AssemblyName>InkCanvasForClassX</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<Deterministic>true</Deterministic>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
<UseWPF>true</UseWPF>
|
||||
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xaml">
|
||||
<RequiredTargetFramework>4.0</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="WindowsBase" />
|
||||
<Reference Include="PresentationCore" />
|
||||
<Reference Include="PresentationFramework" />
|
||||
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
|
||||
<PackageReference Include="System.Data.DataSetExtensions" Version="4.5.0" />
|
||||
<PackageReference Include="System.Runtime" Version="4.3.1" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ApplicationDefinition Include="App.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</ApplicationDefinition>
|
||||
<Page Include="MainWindow.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
<Compile Include="App.xaml.cs">
|
||||
<DependentUpon>App.xaml</DependentUpon>
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="MainWindow.xaml.cs">
|
||||
<DependentUpon>MainWindow.xaml</DependentUpon>
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Folder Include="Windows\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Properties\AssemblyInfo.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Properties\Resources.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTime>True</DesignTime>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Properties\Settings.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Settings.settings</DependentUpon>
|
||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
</Compile>
|
||||
<EmbeddedResource Include="Properties\Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
<None Include="Properties\Settings.settings">
|
||||
<Generator>SettingsSingleFileGenerator</Generator>
|
||||
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
45
InkCanvasForClassX/Libraries/InkProjector.cs
Normal file
45
InkCanvasForClassX/Libraries/InkProjector.cs
Normal file
@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Ink;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace InkCanvasForClassX.Libraries
|
||||
{
|
||||
/// <summary>
|
||||
/// 該控件提供一個基於<c>DrawingVisual</c>的最小的<c>StrokeCollection</c>渲染控件,用以替代重量級的<c>InkCanvas</c>控件
|
||||
/// </summary>
|
||||
public class InkProjector : FrameworkElement {
|
||||
private VisualCollection _children;
|
||||
private DrawingVisual _layer = new DrawingVisual();
|
||||
private StrokeCollection _strokes;
|
||||
|
||||
public InkProjector()
|
||||
{
|
||||
_children = new VisualCollection(this) {
|
||||
_layer // 初始化DrawingVisual
|
||||
};
|
||||
}
|
||||
|
||||
public StrokeCollection Strokes {
|
||||
get => _strokes;
|
||||
set {
|
||||
_strokes = value;
|
||||
DrawInk();
|
||||
}
|
||||
}
|
||||
|
||||
protected override int VisualChildrenCount => _children.Count;
|
||||
|
||||
protected override Visual GetVisualChild(int index) {
|
||||
if (index < 0 || index >= _children.Count) throw new ArgumentOutOfRangeException();
|
||||
return _children[index];
|
||||
}
|
||||
|
||||
private void DrawInk() {
|
||||
DrawingContext context = _layer.RenderOpen();
|
||||
_strokes.Draw(context);
|
||||
context.Close();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
15
InkCanvasForClassX/Libraries/PerfectFreehand.cs
Normal file
15
InkCanvasForClassX/Libraries/PerfectFreehand.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace InkCanvasForClassX.Libraries
|
||||
{
|
||||
/// <summary>
|
||||
/// 提供對<c>steveruizok/perfect-freehand</c>的C#包裝
|
||||
/// </summary>
|
||||
public class PerfectFreehand {
|
||||
|
||||
}
|
||||
}
|
137
InkCanvasForClassX/Libraries/Vector.cs
Normal file
137
InkCanvasForClassX/Libraries/Vector.cs
Normal file
@ -0,0 +1,137 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace InkCanvasForClassX.Libraries
|
||||
{
|
||||
/// <summary>
|
||||
/// 提供了對平面向量的坐標運算
|
||||
/// </summary>
|
||||
public class Vector {
|
||||
|
||||
private double _x = 0;
|
||||
private double _y = 0;
|
||||
|
||||
public Vector(double x, double y) {
|
||||
_x = x;
|
||||
_y = y;
|
||||
}
|
||||
|
||||
public double X {
|
||||
get => _x;
|
||||
set => _x = value;
|
||||
}
|
||||
|
||||
public double Y {
|
||||
get => _y;
|
||||
set => _y = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 將該向量改變為其相反向量
|
||||
/// </summary>
|
||||
public void Negate() {
|
||||
_x = -_x;
|
||||
_y = -_y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 提供一個<c>Vector</c>,返回該<c>Vector</c>的相反向量
|
||||
/// </summary>
|
||||
public static Vector NegateVector(Vector vec) {
|
||||
return new Vector(-vec.X, -vec.Y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Csharp中的<c>Math.Hypot</c>實現
|
||||
/// </summary>
|
||||
private static double Hypot(params double[] values)
|
||||
{
|
||||
double sum = 0;
|
||||
foreach (var value in values) {
|
||||
sum += Math.Pow(value, 2);
|
||||
}
|
||||
return Math.Sqrt(sum);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 獲取該向量的長度
|
||||
/// </summary>
|
||||
public double Length => Vector.Hypot(_x,_y);
|
||||
|
||||
/// <summary>
|
||||
/// 獲取該向量的未開平方的長度
|
||||
/// </summary>
|
||||
public double LengthSquared => _x * _x + _y * _y;
|
||||
|
||||
/// <summary>
|
||||
/// 將該向量和另一個向量相加
|
||||
/// </summary>
|
||||
public void Add(Vector vec)
|
||||
{
|
||||
_x = _x + vec.X;
|
||||
_y = _y + vec.Y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 提供兩個<c>Vector</c>,返回相加後的<c>Vector</c>
|
||||
/// </summary>
|
||||
public static Vector AddVectors(Vector vec1, Vector vec2)
|
||||
{
|
||||
return new Vector(vec1.X + vec2.X, vec1.Y + vec2.Y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 將該向量減去另一個向量
|
||||
/// </summary>
|
||||
public void Subtract(Vector vec)
|
||||
{
|
||||
_x = _x - vec.X;
|
||||
_y = _y - vec.Y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 提供兩個<c>Vector</c>,返回<c><paramref name="vec1"/>-<paramref name="vec2"/></c>後的<c>Vector</c>
|
||||
/// </summary>
|
||||
public static Vector SubtractVectors(Vector vec1, Vector vec2)
|
||||
{
|
||||
return new Vector(vec1.X - vec2.X, vec1.Y - vec2.Y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 將該向量除以一個數值
|
||||
/// </summary>
|
||||
public void DivideBy(double n)
|
||||
{
|
||||
_x = _x / n;
|
||||
_y = _y / n;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 提供兩個<c>Vector</c>,返回<c><paramref name="vec"/>/<paramref name="n"/></c>後的<c>Vector</c>
|
||||
/// </summary>
|
||||
public static Vector DivideByVector(Vector vec, double n)
|
||||
{
|
||||
return new Vector(vec.X / n, vec.Y / n);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 將該向量乘以一個數值
|
||||
/// </summary>
|
||||
public void Multiply(double n)
|
||||
{
|
||||
_x = _x * n;
|
||||
_y = _y * n;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 提供兩個<c>Vector</c>,返回<c><paramref name="vec"/>*<paramref name="n"/></c>後的<c>Vector</c>
|
||||
/// </summary>
|
||||
public static Vector MultiplyVector(Vector vec, double n)
|
||||
{
|
||||
return new Vector(vec.X * n, vec.Y * n);
|
||||
}
|
||||
}
|
||||
}
|
@ -4,9 +4,11 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:InkCanvasForClassX"
|
||||
xmlns:libraries="clr-namespace:InkCanvasForClassX.Libraries"
|
||||
mc:Ignorable="d"
|
||||
Title="MainWindow" Height="450" Width="800">
|
||||
Title="MainWindow" Height="1300" Width="1300">
|
||||
<Grid>
|
||||
|
||||
<libraries:InkProjector Width="600" Height="600" x:Name="InkP" Margin="0,0,0,600"/>
|
||||
<InkCanvas Height="600" Width="600" Name="InkC" Margin="0,600,0,0" Background="Wheat"></InkCanvas>
|
||||
</Grid>
|
||||
</Window>
|
||||
|
@ -23,6 +23,9 @@ namespace InkCanvasForClassX
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
InkC.StrokeCollected += (object sender, InkCanvasStrokeCollectedEventArgs e) => {
|
||||
InkP.Strokes = InkC.Strokes;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user