Skip to content

Commit

Permalink
fix issue jingwood#98 by replacing ID2D1PathGeometry by D2DGeometryCo…
Browse files Browse the repository at this point in the history
…ntext where appropriate in Geometry.cpp
  • Loading branch information
MarkhusGenferei committed Jan 2, 2023
1 parent 1e3f692 commit 4960518
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 46 deletions.
22 changes: 17 additions & 5 deletions src/D2DLib.sln
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29020.237
# Visual Studio Version 17
VisualStudioVersion = 17.4.33205.214
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "d2dlib", "d2dlib\d2dlib.vcxproj", "{E0A71FCE-69DD-40A6-87FB-2D63AB5D25C9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "D2DLibExport", "D2DLibExport\D2DLibExport.csproj", "{81DD53D8-FCF0-4384-A931-9370FA8E8E67}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "D2DLibExport", "D2DLibExport\D2DLibExport.csproj", "{81DD53D8-FCF0-4384-A931-9370FA8E8E67}"
ProjectSection(ProjectDependencies) = postProject
{E0A71FCE-69DD-40A6-87FB-2D63AB5D25C9} = {E0A71FCE-69DD-40A6-87FB-2D63AB5D25C9}
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Examples", "Examples\Examples.csproj", "{D653531B-D30C-4A20-8AE5-D46A6F03E274}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Examples", "Examples\Examples.csproj", "{D653531B-D30C-4A20-8AE5-D46A6F03E274}"
ProjectSection(ProjectDependencies) = postProject
{E0A71FCE-69DD-40A6-87FB-2D63AB5D25C9} = {E0A71FCE-69DD-40A6-87FB-2D63AB5D25C9}
EndProjectSection
Expand All @@ -37,11 +37,15 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "snapshots", "snapshots", "{
..\snapshots\whiteboard.png = ..\snapshots\whiteboard.png
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "D2DWinForm", "D2DWinForm\D2DWinForm.csproj", "{40ED2809-ABA2-4655-82DD-E38AD12138BB}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "D2DWinForm", "D2DWinForm\D2DWinForm.csproj", "{40ED2809-ABA2-4655-82DD-E38AD12138BB}"
ProjectSection(ProjectDependencies) = postProject
{E0A71FCE-69DD-40A6-87FB-2D63AB5D25C9} = {E0A71FCE-69DD-40A6-87FB-2D63AB5D25C9}
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Éléments de solution", "Éléments de solution", "{6E37D4A0-DB61-48D6-ADC3-F08557227322}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MTest1", "MTest1\MTest1\MTest1.csproj", "{C179F80B-1BC7-407E-8F8C-E1EE66F45709}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Expand Down Expand Up @@ -82,6 +86,14 @@ Global
{40ED2809-ABA2-4655-82DD-E38AD12138BB}.Release|x64.Build.0 = Release|x64
{40ED2809-ABA2-4655-82DD-E38AD12138BB}.Release|x86.ActiveCfg = Release|x86
{40ED2809-ABA2-4655-82DD-E38AD12138BB}.Release|x86.Build.0 = Release|x86
{C179F80B-1BC7-407E-8F8C-E1EE66F45709}.Debug|x64.ActiveCfg = Debug|x64
{C179F80B-1BC7-407E-8F8C-E1EE66F45709}.Debug|x64.Build.0 = Debug|x64
{C179F80B-1BC7-407E-8F8C-E1EE66F45709}.Debug|x86.ActiveCfg = Debug|x86
{C179F80B-1BC7-407E-8F8C-E1EE66F45709}.Debug|x86.Build.0 = Debug|x86
{C179F80B-1BC7-407E-8F8C-E1EE66F45709}.Release|x64.ActiveCfg = Release|x64
{C179F80B-1BC7-407E-8F8C-E1EE66F45709}.Release|x64.Build.0 = Release|x64
{C179F80B-1BC7-407E-8F8C-E1EE66F45709}.Release|x86.ActiveCfg = Release|x86
{C179F80B-1BC7-407E-8F8C-E1EE66F45709}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
2 changes: 1 addition & 1 deletion src/D2DLibExport/D2DGraphics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ public void FillPath(D2DGeometry path, D2DColor fillColor)
{
D2D.FillPathD(path.Handle, fillColor);
}

public void Clear(D2DColor color)
{
D2D.Clear(Handle, color);
Expand Down
2 changes: 1 addition & 1 deletion src/D2DLibExport/D2DLib.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public static extern void DrawPath(HANDLE path, D2DColor strokeColor, FLOAT stro

[DllImport(DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern void FillPathD(HANDLE path, D2DColor fillColor);

[DllImport(DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern void FillGeometryWithBrush(HANDLE path, HANDLE brush);

Expand Down
4 changes: 4 additions & 0 deletions src/D2DLibExport/D2DLibExport.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@
<PackageReference Include="System.Numerics.Vectors" Version="4.5.0" />
</ItemGroup>

<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>

</Project>
60 changes: 30 additions & 30 deletions src/d2dlib/Geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,10 @@ void AddPathArc(HANDLE ctx, D2D1_POINT_2F endPoint, D2D1_SIZE_F size, FLOAT swee
pathContext->sink->AddArc(&seg);
}

void DrawPath(HANDLE pathCtx, D2D1_COLOR_F strokeColor, FLOAT strokeWidth, D2D1_DASH_STYLE dashStyle)
void DrawPath(HANDLE geoCtx, D2D1_COLOR_F strokeColor, FLOAT strokeWidth, D2D1_DASH_STYLE dashStyle)
{
D2DPathContext* pathContext = reinterpret_cast<D2DPathContext*>(pathCtx);
D2DContext* context = pathContext->d2context;
D2DGeometryContext* geometryContext = reinterpret_cast<D2DGeometryContext*>(geoCtx);
D2DContext* context = geometryContext->d2context;

ID2D1Factory* factory = context->factory;
ID2D1RenderTarget* renderTarget = context->renderTarget;
Expand All @@ -206,35 +206,35 @@ void DrawPath(HANDLE pathCtx, D2D1_COLOR_F strokeColor, FLOAT strokeWidth, D2D1_
0.0f), NULL, 0, &strokeStyle);
}

renderTarget->DrawGeometry(pathContext->path, strokeBrush, strokeWidth, strokeStyle);
renderTarget->DrawGeometry(geometryContext->geometry, strokeBrush, strokeWidth, strokeStyle);

SafeRelease(&strokeBrush);
SafeRelease(&strokeStyle);
}

void DrawPathWithPen(HANDLE pathCtx, HANDLE strokePen, FLOAT strokeWidth)
void DrawPathWithPen(HANDLE geoCtx, HANDLE strokePen, FLOAT strokeWidth)
{
D2DPen* pen = reinterpret_cast<D2DPen*>(strokePen);
D2DPathContext* pathContext = reinterpret_cast<D2DPathContext*>(pathCtx);
ID2D1RenderTarget* renderTarget = pathContext->d2context->renderTarget;
D2DGeometryContext* geometryContext = reinterpret_cast<D2DGeometryContext*>(geoCtx);
ID2D1RenderTarget* renderTarget = geometryContext->d2context->renderTarget;

if (pen->brush != NULL) {
renderTarget->DrawGeometry(pathContext->path, pen->brush, strokeWidth, pen->strokeStyle);
renderTarget->DrawGeometry(geometryContext->geometry, pen->brush, strokeWidth, pen->strokeStyle);
}
}

void FillPathD(HANDLE pathCtx, D2D1_COLOR_F fillColor)
void FillPathD(HANDLE geoCtx, D2D1_COLOR_F fillColor)
{
D2DPathContext* pathContext = reinterpret_cast<D2DPathContext*>(pathCtx);
ID2D1RenderTarget* renderTarget = pathContext->d2context->renderTarget;
D2DGeometryContext* geometryContext = reinterpret_cast<D2DGeometryContext*>(geoCtx);
ID2D1RenderTarget* renderTarget = geometryContext->d2context->renderTarget;

if (fillColor.a > 0)
{
ID2D1SolidColorBrush* fillBrush = NULL;
renderTarget->CreateSolidColorBrush(fillColor, &fillBrush);

if (fillBrush != NULL) {
renderTarget->FillGeometry(pathContext->path, fillBrush);
renderTarget->FillGeometry(geometryContext->geometry, fillBrush);
}

SafeRelease(&fillBrush);
Expand Down Expand Up @@ -376,13 +376,13 @@ void DrawPolygonWithBrush(HANDLE ctx, D2D1_POINT_2F* points, UINT count,

}

void FillPathWithBrush(HANDLE ctx, HANDLE brushHandle)
void FillPathWithBrush(HANDLE geoCtx, HANDLE brushHandle)
{
D2DPathContext* pathContext = reinterpret_cast<D2DPathContext*>(ctx);
D2DGeometryContext* geoContext = reinterpret_cast<D2DGeometryContext*>(geoCtx);
D2DBrushContext* brushContext = reinterpret_cast<D2DBrushContext*>(brushHandle);
D2DContext* context = pathContext->d2context;
D2DContext* context = geoContext->d2context;

context->renderTarget->FillGeometry(pathContext->path, brushContext->brush);
context->renderTarget->FillGeometry(geoContext->geometry, brushContext->brush);
}

void FillGeometryWithBrush(HANDLE ctx, HANDLE geoHandle, _In_ HANDLE brushHandle, _In_opt_ HANDLE opacityBrushHandle)
Expand All @@ -397,21 +397,21 @@ void FillGeometryWithBrush(HANDLE ctx, HANDLE geoHandle, _In_ HANDLE brushHandle
opacityBrushContext == NULL ? NULL : opacityBrushContext->brush);
}

bool PathFillContainsPoint(HANDLE pathCtx, D2D1_POINT_2F point)
bool PathFillContainsPoint(HANDLE geoCtx, D2D1_POINT_2F point)
{
D2DPathContext* pathContext = reinterpret_cast<D2DPathContext*>(pathCtx);
D2DGeometryContext* geoContext = reinterpret_cast<D2DGeometryContext*>(geoCtx);

BOOL contain = FALSE;
pathContext->path->FillContainsPoint(point, NULL, &contain);
geoContext->geometry->FillContainsPoint(point, NULL, &contain);

return contain == TRUE;
}

bool PathStrokeContainsPoint(HANDLE pathCtx, D2D1_POINT_2F point, FLOAT strokeWidth, D2D1_DASH_STYLE dashStyle)
bool PathStrokeContainsPoint(HANDLE geoCtx, D2D1_POINT_2F point, FLOAT strokeWidth, D2D1_DASH_STYLE dashStyle)
{
D2DPathContext* pathContext = reinterpret_cast<D2DPathContext*>(pathCtx);
ID2D1Factory* factory = pathContext->d2context->factory;
D2DGeometryContext* geoContext = reinterpret_cast<D2DGeometryContext*>(geoCtx);

ID2D1Factory* factory = geoContext->d2context->factory;
ID2D1StrokeStyle *strokeStyle = NULL;

if (dashStyle != D2D1_DASH_STYLE_SOLID)
Expand All @@ -427,22 +427,22 @@ bool PathStrokeContainsPoint(HANDLE pathCtx, D2D1_POINT_2F point, FLOAT strokeWi
}

BOOL contain = FALSE;
pathContext->path->StrokeContainsPoint(point, strokeWidth, strokeStyle, NULL, &contain);
geoContext->geometry->StrokeContainsPoint(point, strokeWidth, strokeStyle, NULL, &contain);

SafeRelease(&strokeStyle);

return contain == TRUE;
}


void GetGeometryBounds(HANDLE pathCtx, __out D2D1_RECT_F* rect)
void GetGeometryBounds(HANDLE geoCtx, __out D2D1_RECT_F* rect)
{
D2DPathContext* pathContext = reinterpret_cast<D2DPathContext*>(pathCtx);
pathContext->path->GetBounds(NULL, rect);
D2DGeometryContext* geoContext = reinterpret_cast<D2DGeometryContext*>(geoCtx);
geoContext->geometry->GetBounds(NULL, rect);
}

void GetGeometryTransformedBounds(HANDLE pathCtx, __in D2D1_MATRIX_3X2_F* mat3x2, __out D2D1_RECT_F* rect)
void GetGeometryTransformedBounds(HANDLE geoCtx, __in D2D1_MATRIX_3X2_F* mat3x2, __out D2D1_RECT_F* rect)
{
D2DPathContext* pathContext = reinterpret_cast<D2DPathContext*>(pathCtx);
pathContext->path->GetBounds(mat3x2, rect);
D2DGeometryContext* geoContext = reinterpret_cast<D2DGeometryContext*>(geoCtx);
geoContext->geometry->GetBounds(mat3x2, rect);
}
18 changes: 9 additions & 9 deletions src/d2dlib/Geometry.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* MIT License
*
* Copyright (c) 2009-2021 Jingwood, unvell.com. All right reserved.
Expand Down Expand Up @@ -54,22 +54,22 @@ extern "C"
D2D1_COLOR_F strokeColor, FLOAT strokeWidth = 1,
D2D1_DASH_STYLE dashStyle = D2D1_DASH_STYLE::D2D1_DASH_STYLE_SOLID);

D2DLIB_API void DrawPath(HANDLE pathCtx, D2D1_COLOR_F strokeColor, FLOAT strokeWidth, D2D1_DASH_STYLE dashStyle);
D2DLIB_API void DrawPathWithPen(HANDLE pathCtx, HANDLE strokePen, FLOAT strokeWidth);
D2DLIB_API void FillPathD(HANDLE pathCtx, D2D1_COLOR_F fillColor);
D2DLIB_API void DrawPath(HANDLE geoCtx, D2D1_COLOR_F strokeColor, FLOAT strokeWidth, D2D1_DASH_STYLE dashStyle);
D2DLIB_API void DrawPathWithPen(HANDLE geoCtx, HANDLE strokePen, FLOAT strokeWidth);
D2DLIB_API void FillPathD(HANDLE geoCtx, D2D1_COLOR_F fillColor);

D2DLIB_API void FillGeometryWithBrush(HANDLE ctx, HANDLE geoHandle,
__in HANDLE brushHandle, __in_opt HANDLE opacityBrushHandle = NULL);

D2DLIB_API bool PathFillContainsPoint(HANDLE pathCtx, D2D1_POINT_2F point);
D2DLIB_API bool PathStrokeContainsPoint(HANDLE pathCtx, D2D1_POINT_2F point, FLOAT strokeWidth = 1,
D2DLIB_API bool PathFillContainsPoint(HANDLE geoCtx, D2D1_POINT_2F point);
D2DLIB_API bool PathStrokeContainsPoint(HANDLE geoCtx, D2D1_POINT_2F point, FLOAT strokeWidth = 1,
D2D1_DASH_STYLE dashStyle = D2D1_DASH_STYLE::D2D1_DASH_STYLE_SOLID);

D2DLIB_API void GetGeometryBounds(HANDLE pathCtx, __out D2D1_RECT_F* rect);
D2DLIB_API void GetGeometryTransformedBounds(HANDLE pathCtx, __in D2D1_MATRIX_3X2_F* mat3x2, __out D2D1_RECT_F* rect);
D2DLIB_API void GetGeometryBounds(HANDLE geoCtx, __out D2D1_RECT_F* rect);
D2DLIB_API void GetGeometryTransformedBounds(HANDLE geoCtx, __in D2D1_MATRIX_3X2_F* mat3x2, __out D2D1_RECT_F* rect);

D2DLIB_API void DrawPolygon(HANDLE ctx, D2D1_POINT_2F* points, UINT count,
D2D1_COLOR_F strokeColor, FLOAT strokeWidth, D2D1_DASH_STYLE dashStyle, D2D1_COLOR_F fillColor);
D2DLIB_API void DrawPolygonWithBrush(HANDLE ctx, D2D1_POINT_2F* points, UINT count,
D2D1_COLOR_F strokeColor, FLOAT strokeWidth, D2D1_DASH_STYLE dashStyle, HANDLE brushHandle);
}
}

0 comments on commit 4960518

Please sign in to comment.