question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question: How to use CompositionPathGeometry and CompositionPath?

See original GitHub issue

Hello,

I try to use CompositionPathGeometry like this:

IGeometrySource2D source = <...>
var pathGeometry = Compositor.CreatePathGeometry(new CompositionPath(source));

But I can’t find how to create the source (IGeometrySource2D).

Can you create an example?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
castorixcommented, Jun 29, 2023

With Windows.UI.Composition, it is done with IGeometrySource2DInterop, like in https://github.com/microsoft/Windows.UI.Composition-Win32-Samples/blob/master/cpp/HelloVectors/HelloVectors_win32.cpp, but not sure if it works with Microsoft.UI.Composition (I could only test in C# and I got 0x80070057 like @tom-huntington )

1reaction
ChewWorkercommented, Jun 27, 2023

I haven’t had a chance to try raw D2D, but it can be done with Win2D. The following example works to use Win2D to build the geometry source. One possible issue with the code you pasted is that there aren’t open/add geometry/close steps being done before creating the composition path. It’s possible the d2d object defaults to a bad/closed state unless the geometry has beeen created. This code was used in a basic UWP/Win2D project:

        var c = Window.Current.Compositor;

        // CanvasGeometry and CanvasPathBuilder are Win2D objects
        CanvasPathBuilder pathBuilder = new CanvasPathBuilder(sender);
        pathBuilder.BeginFigure(1, 1);
        pathBuilder.AddLine(300, 300);
        pathBuilder.AddLine(1, 300);
        pathBuilder.EndFigure(CanvasFigureLoop.Closed);

        CanvasGeometry geometry = CanvasGeometry.CreatePath(pathBuilder);

        // These are Composition Path objects
        var pathGeometry = c.CreatePathGeometry(new CompositionPath(geometry));

        // Need to create a sprite shape from the rounded rect
        var roundedRectSpriteShape              = c.CreateSpriteShape(pathGeometry);
        roundedRectSpriteShape.FillBrush        = c.CreateColorBrush(Colors.Red);

        _shapeContainer.Shapes.Add(roundedRectSpriteShape);
Read more comments on GitHub >

github_iconTop Results From Across the Web

Using complex paths for CompositionClip - uwp
So the questions are: How do we use IGeometrySource2D and CompositionPath to create complex shapes? If it's not feasible, then ...
Read more >
CompositionPathGeometry.Path Property - Windows
Gets or sets the data that defines the lines and curves of the path.
Read more >
Composition - Ratish Philip's Blog
(Thank you, Simeon Cran, for answering my questions). ... You can now use the Win2d Mini Path Language to create CompositionPath , CompositionPathGeometry...
Read more >
CompositionPathGeometry Class (Microsoft.UI.Composition)
Returns an AnimationController for the animation running on the specified property. (Inherited from CompositionObject). Applies to. Product, Versions. Windows ...
Read more >
CompositionDropShadowSource...
Use the Windows.UI.Composition UWP API directly from Node.js. local_offerWindows.UI.Composition, Windows, UI, Composition, CompositionObject, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found