AvaloniaUI / Avalonia

Develop Desktop, Embedded, Mobile and WebAssembly apps with C# and XAML. The most popular .NET UI client technology
https://avaloniaui.net
MIT License
25.16k stars 2.18k forks source link

Add Ink support #1477

Open lindexi opened 6 years ago

lindexi commented 6 years ago

I cant find Ink in Avalonia and me working on an Ink app.

I want to add Ink support to Avalonia. At least, copy the dot net framework code to Avalonia.

https://referencesource.microsoft.com/#PresentationFramework/src/Framework/System/Windows/Controls/InkCanvas.cs

jkoritzinsky commented 6 years ago

We can't copy the .NET Framework Reference Source since it is not correctly licensed. We have to do a clean-room implementation or we can be sued.

jkoritzinsky commented 6 years ago

I've been looking through the support for InkPresenter, and it looks like it we might be able to directly render to a D2DRenderContext, but I think we might need a DirectComposition Visual to render to (See the InkDesktopHost class).

lindexi commented 6 years ago

@jkoritzinsky For dot net framework it converts the Stylus to geometry and then renders the geometry that we should only render the geometry.

jkoritzinsky commented 6 years ago

I was looking at hooking into the OS support so we can get handwriting and shape recognition automatically.

We could always just manually capture the input and draw as a first step. Though, I'd definitely prefer eventually adding OS native support.

lindexi commented 6 years ago

@jkoritzinsky I dont think all the os can do it.

jkoritzinsky commented 6 years ago

That's all supported within the UWP classes which are also available on Desktop as far as I can tell. They all work through the UWP InkPresenter class (and related classes which rely on data stored in an InkPresenter), which can be hosted in a UWP canvas, a DirectComposition visual, or a Windows.UI.Composition visual: https://docs.microsoft.com/en-us/uwp/api/windows.ui.input.inking.inkpresenter.activatecustomdrying#Windows_UI_Input_Inking_InkPresenter_ActivateCustomDrying.

lindexi commented 6 years ago

@jkoritzinsky Thx for your docs but I mean that some OS like Gentoo cant do it.

jkoritzinsky commented 6 years ago

Yeah we'd need to have fallback support for a basic ink canvas without hooking into OS support.

lindexi commented 6 years ago

@jkoritzinsky May we should provide two systems that the one run in win32(win10) use UWP api and another run in other systems render the geometry.

jkoritzinsky commented 6 years ago

That works for me! We can push back the Windows 10 based one for a while since we'd need to add native layer (DirectComposition) support into Avalonia, which might take a bit.

lindexi commented 6 years ago

@jkoritzinsky by the way how can we use UWP api in WPF without package to store.

jkoritzinsky commented 6 years ago

Some UWP APIs can be used by traditional desktop applications. Docs used to say which ones, but I can't find the support tables in the new docs system.

Also, please don't copy the WPF source code. Please do a clean room implementation without looking at their code. If you copy their code we'll have to decline the pull request for legal reasons. We had to do that a while back for some Grid speed improvements.

lindexi commented 6 years ago

@jkoritzinsky Thx. Now I am discussing with my partner to open our code to Avalonia. But I dont think my Ink render scheme is superior.

lindexi commented 2 years ago

Now wpf is open source with MIT license. Can we copy the code from WPF ? @jkoritzinsky

maxkatz6 commented 1 year ago

We have pen and touch input support including pressure and tilt parameters. PointerMoved even has GetIntermediatePoints() information. All of this is necessary to create a custom ink control. Like we have oversimplified version here https://github.com/AvaloniaUI/Avalonia/blob/master/samples/ControlCatalog/Pages/PointerCanvas.cs

Saying that, I wouldn't expect specialized Ink Control to be part of the core avalonia framework.

ivoryguard commented 1 year ago

Great work! Does it work on Android as well as Windows?

AtomKing commented 1 year ago

so ,any update for this?

timunie commented 1 year ago

@AtomKing as written above, this control will most likely not a control that we ship via Avalonia. Either search for a 3rd party control (I've not seen any yet) or develop such a control on your own.

lindexi commented 1 month ago

@AtomKing I am currently returning to this project, where I have recently successfully added touch pressure support for Avalonia, see https://github.com/AvaloniaUI/Avalonia/pull/15283 and https://github.com/AvaloniaUI/Avalonia/pull/15297 . The support for touch pressure is a fundamental prerequisite for writing applications.

I still believe that the Ink module requires built-in support from the UI framework, as the entire UI framework must be adjusted around the goals of high performance and responsiveness during the implementation of Ink. This will enhance the capabilities of the Avalonia framework, making Avalonia more powerful. I have been working on writing applications for the past decade, especially on large-size touch screen devices. Writing applications encompass a wealth of professional knowledge. I am acutely aware that to create a competent writing application, the support of the UI framework is indispensable.