Skip to content
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

path geometry refactoring, wip #102

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

Conversation

jingwood
Copy link
Owner

@jingwood jingwood commented Jan 2, 2023

fix #98, wip

@jingwood jingwood marked this pull request as draft January 2, 2023 11:36
@MarkhusGenferei
Copy link
Contributor

Hi,

I have noticed the addition of the GeometryType enum and its inclusion in the D2DGeometryContext structure. And also, that it is used in the switch statement of DrawGeometry() in Geometry.cpp to cast the geometry pointer according to the geometry type before drawing.

My understanding is that is is not required because all geometry types inherit from ID2D1Geometry. DrawGeometry() could draw any geometry type from a ID2D1Geometry argument.

Actually, the following functions in Geometry.cpp should work on all geometry types if they were adapted to take a D2DGeometryContext* handle as argument instead of a D2DPathContext* :

void DrawGeometry(HANDLE geometryHandler, D2D1_COLOR_F strokeColor, FLOAT strokeWidth, D2D1_DASH_STYLE dashStyle);
HANDLE CreateCombinedGeometry(HANDLE d2dCtx, HANDLE pathCtx1, HANDLE pathCtx2, D2D1_COMBINE_MODE combineMode, FLOAT flatteningTolerance); sorry :-\
void DrawPathWithPen(HANDLE pathCtx, HANDLE strokePen, FLOAT strokeWidth);
void FillPathD(HANDLE pathCtx, D2D1_COLOR_F fillColor);
void FillPathWithBrush(HANDLE ctx, HANDLE brushHandle);
bool PathFillContainsPoint(HANDLE pathCtx, D2D1_POINT_2F point);
bool PathStrokeContainsPoint(HANDLE pathCtx, D2D1_POINT_2F point, FLOAT strokeWidth, D2D1_DASH_STYLE dashStyle);
void GetGeometryBounds(HANDLE pathCtx, __out D2D1_RECT_F* rect);
void GetGeometryTransformedBounds(HANDLE pathCtx, __in D2D1_MATRIX_3X2_F* mat3x2, __out D2D1_RECT_F* rect);

In these functions, the minimal adaptation consists in replacing

D2DPathContext* pathContext = reinterpret_cast<D2DPathContext*>(pathCtx);

by

D2DGeometryContext* geometryContext = reinterpret_cast<D2DGeometryContext*>(pathCtx);

and

pathContext->path

by

geometryContext->geometry

This will work because D2DPathContext inherits from D2DGeometryContext, and because D2DPathContext's constructor always sets its base class geometryContext member. CreateRectangleGeometry and CreateEllipseGeometry do the same.

Cheers, Markhus

@MarkhusGenferei
Copy link
Contributor

This is what was proposed in #100

@jingwood
Copy link
Owner Author

jingwood commented Jan 4, 2023

Thanks @MarkhusGenferei, I think you are correct!
I am considering merge the #103, which is the rebased branch from #100.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DrawPath and FillPath throw exception
2 participants