microsoft / Win2D

Win2D is an easy-to-use Windows Runtime API for immediate mode 2D graphics rendering with GPU acceleration. It is available to C#, C++ and VB developers writing apps for the Windows Universal Platform (UWP). It utilizes the power of Direct2D, and integrates seamlessly with XAML and CoreWindow.
http://microsoft.github.io/Win2D
Other
1.8k stars 284 forks source link

Resolving clicked SVG element and outer bounds? #541

Open W0lfw00ds opened 7 years ago

W0lfw00ds commented 7 years ago

It seems that many of the samples are about manipulating the SVG document's contents, but I couldn't find info about handling/accessing the graphical elements created from the parsed SVG.

In a nutshell, I need a feature to determine the outer bounds of any drawn SVG elements with a cursor hittest. This way I could use a mouse to select a specific element and edit it's properties. These features are easily implemented with the Win2D CanvasGeometries.

In the earlier 'beta' version of the SVG support, the elements were drawn by using these CanvasGeometries. Is this still the case, and can I access that data? F.ex, I believe that circle elements in SVG are rendered as CanvasGeometry ellipses. I think it would be ideal to get access to the 'parsed' data for manipulation purposes, before Win2D renders it.

shawnhar commented 7 years ago

You are correct that there is not currently any way to access the individual geometric shapes that make up an SVG document. This is due to the feature set of the Direct2D SVG implementation that Win2D sits on top of - it's not just a limitation of the Win2D layer.

In the earlier 'beta' version of the SVG support

I'm not sure what beta version you are referring to here. The SVG functionality that is now part of Win2D builds on top of a new addition to Direct2D - this is the first time any of this SVG implementation has been released.

W0lfw00ds commented 7 years ago

I'm referring to this project: SvgWin2D. I tested it earlier and it works great.

If I understand correctly: the added SVG support contains basic tools to edit loaded SVG file's structure. Only way to edit the loaded SVG's visuals is to edit the source code before rendering it. The rendering will only result to 'mere image' drawn on the screen? I was hoping to get my hands in the middle of the parsing process. But it's still good news that SVG images can be loaded and rendered with official support..

I think my best chance is to use the project I mentioned earlier, SvgWin2D. It parses the SVG file into individual objects where I can access each SVG element's geometries etc. This way I can add additional hittests and stuff according to the drawn elements. I would still need to convert it to C#...

shawnhar commented 7 years ago

Ah, ok. That SvgWin2D code is unrelated to the implementation that is now part of Direct2D. It was just a prototype that never got turned into an official feature. Great if it works for your needs, but it is not being maintained or supported.