-
Notifications
You must be signed in to change notification settings - Fork 683
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: How to use CompositionPathGeometry and CompositionPath? #3609
Comments
@jesbis @jeffstall could one of you weigh in here? |
@duncanmacmichael do we have a sample for this or should we update the docs? @zed220 I believe you can use the Win2D CanvasGeometry as a concrete implementation: http://microsoft.github.io/Win2D/html/T_Microsoft_Graphics_Canvas_Geometry_CanvasGeometry.htm e.g.: var pathBuilder = new CanvasPathBuilder(new CanvasDevice());
pathBuilder...
var pathGeometry = CanvasGeometry.CreatePath(pathBuilder);
var path = new CompositionPath(pathGeometry); |
@jesbis As I can see, the CanvasPathBuilder is a part of the nuget package Win2d.uwp. In my opinion, it shouldn't be used in WinUI? |
There are a couple issues tracking enabling WinUI support: |
@jesbis Can Direct2D implement ID2D1PathGeometry* m_pPathGeometry;
...
auto iGeometrySource2D = Windows::Graphics::IGeometrySource2D{ m_pPathGeometry, winrt::take_ownership_from_abi };
auto compositionPath = Microsoft::UI::Composition::CompositionPath{ iGeometrySource2D };
// 0x80070057 : 'Invalid argument to parameter source. Object parameter must not be null.'. but maybe there is some |
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:
|
[like] Duncan MacMichael reacted to your message:
…________________________________
From: Chris Raubacher ***@***.***>
Sent: Tuesday, June 27, 2023 10:40:16 PM
To: microsoft/microsoft-ui-xaml ***@***.***>
Cc: Duncan MacMichael ***@***.***>; Mention ***@***.***>
Subject: Re: [microsoft/microsoft-ui-xaml] Question: How to use CompositionPathGeometry and CompositionPath? (#3609)
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);
—
Reply to this email directly, view it on GitHub<#3609 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AEMILZNIBGF57XV4PXUL5CTXNNONBANCNFSM4TVRUURQ>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
expects I guess |
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, |
@castorix Thanks! I managed create the |
Currently, Win2d is supported in Winui3. You could check the document-Overview of Win2D - Windows apps | Microsoft Learn. You could use CompositionPathGeometry and CompositionPath just like @jesbis shows. |
Closing as completed, as this appears to have been answered with no activity since June (other than Roy's comment). |
Hello,
I try to use CompositionPathGeometry like this:
But I can't find how to create the source (IGeometrySource2D).
Can you create an example?
The text was updated successfully, but these errors were encountered: