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

Add 2 missing geometry related methods #104

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -286,3 +286,4 @@ __pycache__/
*.btm.cs
*.odx.cs
*.xsd.cs
/src/D2DLib.sln
95 changes: 0 additions & 95 deletions src/D2DLib.sln

This file was deleted.

5 changes: 5 additions & 0 deletions src/D2DLibExport/D2DDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ public D2DGeometry CreateEllipseGeometry(D2DPoint origin, D2DSize size)
return new D2DGeometry(this, D2D.CreateEllipseGeometry(this.Handle, ref ellipse));
}

public D2DGeometry CreateEllipseGeometry(D2DEllipse ellipse)
{
return new D2DGeometry(this, D2D.CreateEllipseGeometry(this.Handle, ref ellipse));
}

public D2DGeometry CreatePieGeometry(D2DPoint origin, D2DSize size, float startAngle, float endAngle)
{
var path = this.CreatePathGeometry();
Expand Down
5 changes: 5 additions & 0 deletions src/D2DLibExport/D2DGraphics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,11 @@ public void FillPath(D2DGeometry path, D2DColor fillColor)
D2D.FillPathD(path.Handle, fillColor);
}

public void FillPath(D2DGeometry path, D2DBrush fillBrush)
{
D2D.FillPathWithBrush(path.Handle, fillBrush.Handle);
}

public void Clear(D2DColor color)
{
D2D.Clear(Handle, color);
Expand Down
3 changes: 3 additions & 0 deletions src/D2DLibExport/D2DLib.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,9 @@ public static void AddPathBeziers(HANDLE ctx, D2DBezierSegment[] bezierSegments)

[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 FillPathWithBrush(HANDLE path, HANDLE fillBrush);

[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);
}
20 changes: 10 additions & 10 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 FillPathWithBrush(HANDLE geoCtx, HANDLE brushHandle);
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);
}
}