Skip to content
Draft
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
60 changes: 30 additions & 30 deletions src/d2dlib/Geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,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 @@ -221,35 +221,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 @@ -391,13 +391,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 @@ -412,21 +412,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 @@ -442,22 +442,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);
}
14 changes: 7 additions & 7 deletions src/d2dlib/Geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,19 @@ 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);
Expand Down