1 /* 2 * GdiPlusPath.h 3 * 4 * Windows GDI+ 5 * 6 * This file is part of the w32api package. 7 * 8 * THIS SOFTWARE IS NOT COPYRIGHTED 9 * 10 * This source code is offered for use in the public domain. You may 11 * use, modify or distribute it freely. 12 * 13 * This code is distributed in the hope that it will be useful but 14 * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY 15 * DISCLAIMED. This includes but is not limited to warranties of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 17 */ 18 19 #ifndef _GDIPLUSPATH_H 20 #define _GDIPLUSPATH_H 21 22 class GraphicsPath : public GdiplusBase 23 { 24 friend class Region; 25 friend class CustomLineCap; 26 friend class Graphics; 27 28 public: GraphicsPath(const Point * points,const BYTE * types,INT count,FillMode fillMode)29 GraphicsPath(const Point *points, const BYTE *types, INT count, FillMode fillMode) : nativePath(NULL) 30 { 31 lastStatus = DllExports::GdipCreatePath2I(points, types, count, fillMode, &nativePath); 32 } 33 nativePath(NULL)34 GraphicsPath(FillMode fillMode = FillModeAlternate) : nativePath(NULL) 35 { 36 lastStatus = DllExports::GdipCreatePath(fillMode, &nativePath); 37 } 38 39 GraphicsPath(const PointF *points, const BYTE *types, INT count, FillMode fillMode = FillModeAlternate) nativePath(NULL)40 : nativePath(NULL) 41 { 42 lastStatus = DllExports::GdipCreatePath2(points, types, count, fillMode, &nativePath); 43 } 44 ~GraphicsPath()45 ~GraphicsPath() 46 { 47 DllExports::GdipDeletePath(nativePath); 48 } 49 50 Status AddArc(const Rect & rect,REAL startAngle,REAL sweepAngle)51 AddArc(const Rect &rect, REAL startAngle, REAL sweepAngle) 52 { 53 return AddArc(rect.X, rect.Y, rect.Width, rect.Height, startAngle, sweepAngle); 54 } 55 56 Status AddArc(const RectF & rect,REAL startAngle,REAL sweepAngle)57 AddArc(const RectF &rect, REAL startAngle, REAL sweepAngle) 58 { 59 return AddArc(rect.X, rect.Y, rect.Width, rect.Height, startAngle, sweepAngle); 60 } 61 62 Status AddArc(INT x,INT y,INT width,INT height,REAL startAngle,REAL sweepAngle)63 AddArc(INT x, INT y, INT width, INT height, REAL startAngle, REAL sweepAngle) 64 { 65 return SetStatus(DllExports::GdipAddPathArcI(nativePath, x, y, width, height, startAngle, sweepAngle)); 66 } 67 68 Status AddArc(REAL x,REAL y,REAL width,REAL height,REAL startAngle,REAL sweepAngle)69 AddArc(REAL x, REAL y, REAL width, REAL height, REAL startAngle, REAL sweepAngle) 70 { 71 return SetStatus(DllExports::GdipAddPathArc(nativePath, x, y, width, height, startAngle, sweepAngle)); 72 } 73 74 Status AddBezier(const Point & pt1,const Point & pt2,const Point & pt3,const Point & pt4)75 AddBezier(const Point &pt1, const Point &pt2, const Point &pt3, const Point &pt4) 76 { 77 return AddBezier(pt1.X, pt1.Y, pt2.X, pt2.Y, pt3.X, pt3.Y, pt4.X, pt4.Y); 78 } 79 80 Status AddBezier(REAL x1,REAL y1,REAL x2,REAL y2,REAL x3,REAL y3,REAL x4,REAL y4)81 AddBezier(REAL x1, REAL y1, REAL x2, REAL y2, REAL x3, REAL y3, REAL x4, REAL y4) 82 { 83 return SetStatus(DllExports::GdipAddPathBezier(nativePath, x1, y1, x2, y2, x3, y3, x4, y4)); 84 } 85 86 Status AddBezier(const PointF & pt1,const PointF & pt2,const PointF & pt3,const PointF & pt4)87 AddBezier(const PointF &pt1, const PointF &pt2, const PointF &pt3, const PointF &pt4) 88 { 89 return AddBezier(pt1.X, pt1.Y, pt2.X, pt2.Y, pt3.X, pt3.Y, pt4.X, pt4.Y); 90 } 91 92 Status AddBezier(INT x1,INT y1,INT x2,INT y2,INT x3,INT y3,INT x4,INT y4)93 AddBezier(INT x1, INT y1, INT x2, INT y2, INT x3, INT y3, INT x4, INT y4) 94 { 95 return SetStatus(DllExports::GdipAddPathBezierI(nativePath, x1, y1, x2, y2, x3, y3, x4, y4)); 96 } 97 98 Status AddBeziers(const Point * points,INT count)99 AddBeziers(const Point *points, INT count) 100 { 101 return SetStatus(DllExports::GdipAddPathBeziersI(nativePath, points, count)); 102 } 103 104 Status AddBeziers(const PointF * points,INT count)105 AddBeziers(const PointF *points, INT count) 106 { 107 return SetStatus(DllExports::GdipAddPathBeziers(nativePath, points, count)); 108 } 109 110 Status AddClosedCurve(const Point * points,INT count)111 AddClosedCurve(const Point *points, INT count) 112 { 113 return SetStatus(DllExports::GdipAddPathClosedCurveI(nativePath, points, count)); 114 } 115 116 Status AddClosedCurve(const Point * points,INT count,REAL tension)117 AddClosedCurve(const Point *points, INT count, REAL tension) 118 { 119 return SetStatus(DllExports::GdipAddPathClosedCurve2I(nativePath, points, count, tension)); 120 } 121 122 Status AddClosedCurve(const PointF * points,INT count,REAL tension)123 AddClosedCurve(const PointF *points, INT count, REAL tension) 124 { 125 return SetStatus(DllExports::GdipAddPathClosedCurve2(nativePath, points, count, tension)); 126 } 127 128 Status AddClosedCurve(const PointF * points,INT count)129 AddClosedCurve(const PointF *points, INT count) 130 { 131 return SetStatus(DllExports::GdipAddPathClosedCurve(nativePath, points, count)); 132 } 133 134 Status AddCurve(const Point * points,INT count)135 AddCurve(const Point *points, INT count) 136 { 137 return SetStatus(DllExports::GdipAddPathCurveI(nativePath, points, count)); 138 } 139 140 Status AddCurve(const PointF * points,INT count,REAL tension)141 AddCurve(const PointF *points, INT count, REAL tension) 142 { 143 return SetStatus(DllExports::GdipAddPathCurve2(nativePath, points, count, tension)); 144 } 145 146 Status AddCurve(const PointF * points,INT count)147 AddCurve(const PointF *points, INT count) 148 { 149 return SetStatus(DllExports::GdipAddPathCurve(nativePath, points, count)); 150 } 151 152 Status AddCurve(const Point * points,INT count,INT offset,INT numberOfSegments,REAL tension)153 AddCurve(const Point *points, INT count, INT offset, INT numberOfSegments, REAL tension) 154 { 155 return SetStatus(DllExports::GdipAddPathCurve3I(nativePath, points, count, offset, numberOfSegments, tension)); 156 } 157 158 Status AddCurve(const Point * points,INT count,REAL tension)159 AddCurve(const Point *points, INT count, REAL tension) 160 { 161 return SetStatus(DllExports::GdipAddPathCurve2I(nativePath, points, count, tension)); 162 } 163 164 Status AddCurve(const PointF * points,INT count,INT offset,INT numberOfSegments,REAL tension)165 AddCurve(const PointF *points, INT count, INT offset, INT numberOfSegments, REAL tension) 166 { 167 return SetStatus(DllExports::GdipAddPathCurve3(nativePath, points, count, offset, numberOfSegments, tension)); 168 } 169 170 Status AddEllipse(const Rect & rect)171 AddEllipse(const Rect &rect) 172 { 173 return AddEllipse(rect.X, rect.Y, rect.Width, rect.Height); 174 } 175 176 Status AddEllipse(const RectF & rect)177 AddEllipse(const RectF &rect) 178 { 179 return AddEllipse(rect.X, rect.Y, rect.Width, rect.Height); 180 } 181 182 Status AddEllipse(INT x,INT y,INT width,INT height)183 AddEllipse(INT x, INT y, INT width, INT height) 184 { 185 return SetStatus(DllExports::GdipAddPathEllipseI(nativePath, x, y, width, height)); 186 } 187 188 Status AddEllipse(REAL x,REAL y,REAL width,REAL height)189 AddEllipse(REAL x, REAL y, REAL width, REAL height) 190 { 191 return SetStatus(DllExports::GdipAddPathEllipse(nativePath, x, y, width, height)); 192 } 193 194 Status AddLine(const Point & pt1,const Point & pt2)195 AddLine(const Point &pt1, const Point &pt2) 196 { 197 return AddLine(pt1.X, pt1.Y, pt2.X, pt2.Y); 198 } 199 200 Status AddLine(const PointF & pt1,const PointF & pt2)201 AddLine(const PointF &pt1, const PointF &pt2) 202 { 203 return AddLine(pt1.X, pt1.Y, pt2.X, pt2.Y); 204 } 205 206 Status AddLine(REAL x1,REAL y1,REAL x2,REAL y2)207 AddLine(REAL x1, REAL y1, REAL x2, REAL y2) 208 { 209 return SetStatus(DllExports::GdipAddPathLine(nativePath, x1, y1, x2, y2)); 210 } 211 212 Status AddLine(INT x1,INT y1,INT x2,INT y2)213 AddLine(INT x1, INT y1, INT x2, INT y2) 214 { 215 return SetStatus(DllExports::GdipAddPathLineI(nativePath, x1, y1, x2, y2)); 216 } 217 218 Status AddLines(const Point * points,INT count)219 AddLines(const Point *points, INT count) 220 { 221 return SetStatus(DllExports::GdipAddPathLine2I(nativePath, points, count)); 222 } 223 224 Status AddLines(const PointF * points,INT count)225 AddLines(const PointF *points, INT count) 226 { 227 return SetStatus(DllExports::GdipAddPathLine2(nativePath, points, count)); 228 } 229 230 Status AddPath(const GraphicsPath * addingPath,BOOL connect)231 AddPath(const GraphicsPath *addingPath, BOOL connect) 232 { 233 GpPath *nativePath2 = addingPath ? getNat(addingPath) : NULL; 234 return SetStatus(DllExports::GdipAddPathPath(nativePath, nativePath2, connect)); 235 } 236 237 Status AddPie(const Rect & rect,REAL startAngle,REAL sweepAngle)238 AddPie(const Rect &rect, REAL startAngle, REAL sweepAngle) 239 { 240 return AddPie(rect.X, rect.Y, rect.Width, rect.Height, startAngle, sweepAngle); 241 } 242 243 Status AddPie(INT x,INT y,INT width,INT height,REAL startAngle,REAL sweepAngle)244 AddPie(INT x, INT y, INT width, INT height, REAL startAngle, REAL sweepAngle) 245 { 246 return SetStatus(DllExports::GdipAddPathPieI(nativePath, x, y, width, height, startAngle, sweepAngle)); 247 } 248 249 Status AddPie(REAL x,REAL y,REAL width,REAL height,REAL startAngle,REAL sweepAngle)250 AddPie(REAL x, REAL y, REAL width, REAL height, REAL startAngle, REAL sweepAngle) 251 { 252 return SetStatus(DllExports::GdipAddPathPie(nativePath, x, y, width, height, startAngle, sweepAngle)); 253 } 254 255 Status AddPie(const RectF & rect,REAL startAngle,REAL sweepAngle)256 AddPie(const RectF &rect, REAL startAngle, REAL sweepAngle) 257 { 258 return AddPie(rect.X, rect.Y, rect.Width, rect.Height, startAngle, sweepAngle); 259 } 260 261 Status AddPolygon(const Point * points,INT count)262 AddPolygon(const Point *points, INT count) 263 { 264 return SetStatus(DllExports::GdipAddPathPolygonI(nativePath, points, count)); 265 } 266 267 Status AddPolygon(const PointF * points,INT count)268 AddPolygon(const PointF *points, INT count) 269 { 270 return SetStatus(DllExports::GdipAddPathPolygon(nativePath, points, count)); 271 } 272 273 Status AddRectangle(const Rect & rect)274 AddRectangle(const Rect &rect) 275 { 276 return SetStatus(DllExports::GdipAddPathRectangleI(nativePath, rect.X, rect.Y, rect.Width, rect.Height)); 277 } 278 279 Status AddRectangle(const RectF & rect)280 AddRectangle(const RectF &rect) 281 { 282 return SetStatus(DllExports::GdipAddPathRectangle(nativePath, rect.X, rect.Y, rect.Width, rect.Height)); 283 } 284 285 Status AddRectangles(const Rect * rects,INT count)286 AddRectangles(const Rect *rects, INT count) 287 { 288 return SetStatus(DllExports::GdipAddPathRectanglesI(nativePath, rects, count)); 289 } 290 291 Status AddRectangles(const RectF * rects,INT count)292 AddRectangles(const RectF *rects, INT count) 293 { 294 return SetStatus(DllExports::GdipAddPathRectangles(nativePath, rects, count)); 295 } 296 297 Status AddString(const WCHAR * string,INT length,const FontFamily * family,INT style,REAL emSize,const Rect & layoutRect,const StringFormat * format)298 AddString( 299 const WCHAR *string, 300 INT length, 301 const FontFamily *family, 302 INT style, 303 REAL emSize, 304 const Rect &layoutRect, 305 const StringFormat *format) 306 { 307 return SetStatus(DllExports::GdipAddPathStringI( 308 nativePath, string, length, family ? getNat(family) : NULL, style, emSize, &layoutRect, 309 format ? getNat(format) : NULL)); 310 } 311 312 Status AddString(const WCHAR * string,INT length,const FontFamily * family,INT style,REAL emSize,const PointF & origin,const StringFormat * format)313 AddString( 314 const WCHAR *string, 315 INT length, 316 const FontFamily *family, 317 INT style, 318 REAL emSize, 319 const PointF &origin, 320 const StringFormat *format) 321 { 322 RectF rect(origin.X, origin.Y, 0.0f, 0.0f); 323 return SetStatus(DllExports::GdipAddPathString( 324 nativePath, string, length, family ? getNat(family) : NULL, style, emSize, &rect, 325 format ? getNat(format) : NULL)); 326 } 327 328 Status AddString(const WCHAR * string,INT length,const FontFamily * family,INT style,REAL emSize,const Point & origin,const StringFormat * format)329 AddString( 330 const WCHAR *string, 331 INT length, 332 const FontFamily *family, 333 INT style, 334 REAL emSize, 335 const Point &origin, 336 const StringFormat *format) 337 { 338 Rect rect(origin.X, origin.Y, 0, 0); 339 return SetStatus(DllExports::GdipAddPathStringI( 340 nativePath, string, length, family ? getNat(family) : NULL, style, emSize, &rect, 341 format ? getNat(format) : NULL)); 342 } 343 344 Status AddString(const WCHAR * string,INT length,const FontFamily * family,INT style,REAL emSize,const RectF & layoutRect,const StringFormat * format)345 AddString( 346 const WCHAR *string, 347 INT length, 348 const FontFamily *family, 349 INT style, 350 REAL emSize, 351 const RectF &layoutRect, 352 const StringFormat *format) 353 { 354 return SetStatus(DllExports::GdipAddPathString( 355 nativePath, string, length, family ? getNat(family) : NULL, style, emSize, &layoutRect, 356 format ? getNat(format) : NULL)); 357 } 358 359 Status ClearMarkers()360 ClearMarkers() 361 { 362 return SetStatus(DllExports::GdipClearPathMarkers(nativePath)); 363 } 364 365 GraphicsPath * Clone()366 Clone() 367 { 368 GpPath *clonepath = NULL; 369 SetStatus(DllExports::GdipClonePath(nativePath, &clonepath)); 370 if (lastStatus != Ok) 371 return NULL; 372 return new GraphicsPath(clonepath); 373 } 374 375 Status CloseAllFigures()376 CloseAllFigures() 377 { 378 return SetStatus(DllExports::GdipClosePathFigures(nativePath)); 379 } 380 381 Status CloseFigure()382 CloseFigure() 383 { 384 return SetStatus(DllExports::GdipClosePathFigure(nativePath)); 385 } 386 387 Status Flatten(const Matrix * matrix,REAL flatness)388 Flatten(const Matrix *matrix, REAL flatness) 389 { 390 GpMatrix *nativeMatrix = matrix ? getNat(matrix) : NULL; 391 return SetStatus(DllExports::GdipFlattenPath(nativePath, nativeMatrix, flatness)); 392 } 393 394 Status GetBounds(Rect * bounds,const Matrix * matrix,const Pen * pen)395 GetBounds(Rect *bounds, const Matrix *matrix, const Pen *pen) 396 { 397 return SetStatus(NotImplemented); 398 } 399 400 Status GetBounds(RectF * bounds,const Matrix * matrix,const Pen * pen)401 GetBounds(RectF *bounds, const Matrix *matrix, const Pen *pen) 402 { 403 return SetStatus(NotImplemented); 404 } 405 406 FillMode GetFillMode()407 GetFillMode() 408 { 409 FillMode fillmode = FillModeAlternate; 410 SetStatus(DllExports::GdipGetPathFillMode(nativePath, &fillmode)); 411 return fillmode; 412 } 413 414 Status GetLastPoint(PointF * lastPoint)415 GetLastPoint(PointF *lastPoint) const 416 { 417 return SetStatus(DllExports::GdipGetPathLastPoint(nativePath, lastPoint)); 418 } 419 420 Status GetLastStatus()421 GetLastStatus() const 422 { 423 return lastStatus; 424 } 425 426 Status GetPathData(PathData * pathData)427 GetPathData(PathData *pathData) 428 { 429 return NotImplemented; 430 } 431 432 Status GetPathPoints(Point * points,INT count)433 GetPathPoints(Point *points, INT count) const 434 { 435 return SetStatus(DllExports::GdipGetPathPointsI(nativePath, points, count)); 436 } 437 438 Status GetPathPoints(PointF * points,INT count)439 GetPathPoints(PointF *points, INT count) const 440 { 441 return SetStatus(DllExports::GdipGetPathPoints(nativePath, points, count)); 442 } 443 444 Status GetPathTypes(BYTE * types,INT count)445 GetPathTypes(BYTE *types, INT count) const 446 { 447 return SetStatus(DllExports::GdipGetPathTypes(nativePath, types, count)); 448 } 449 450 INT GetPointCount()451 GetPointCount() const 452 { 453 INT count = 0; 454 SetStatus(DllExports::GdipGetPointCount(nativePath, &count)); 455 return count; 456 } 457 458 BOOL IsOutlineVisible(const Point & point,const Pen * pen,const Graphics * g)459 IsOutlineVisible(const Point &point, const Pen *pen, const Graphics *g) const 460 { 461 return IsOutlineVisible(point.X, point.Y, pen, g); 462 } 463 464 BOOL IsOutlineVisible(REAL x,REAL y,const Pen * pen,const Graphics * g)465 IsOutlineVisible(REAL x, REAL y, const Pen *pen, const Graphics *g) const 466 { 467 GpGraphics *nativeGraphics = g ? getNat(g) : NULL; 468 GpPen *nativePen = pen ? getNat(pen) : NULL; 469 BOOL flag = FALSE; 470 SetStatus(DllExports::GdipIsOutlineVisiblePathPoint(nativePath, x, y, nativePen, nativeGraphics, &flag)); 471 return flag; 472 } 473 474 BOOL IsOutlineVisible(INT x,INT y,const Pen * pen,const Graphics * g)475 IsOutlineVisible(INT x, INT y, const Pen *pen, const Graphics *g) const 476 { 477 GpGraphics *nativeGraphics = g ? getNat(g) : NULL; 478 GpPen *nativePen = pen ? getNat(pen) : NULL; 479 BOOL flag = FALSE; 480 SetStatus(DllExports::GdipIsOutlineVisiblePathPointI(nativePath, x, y, nativePen, nativeGraphics, &flag)); 481 return flag; 482 } 483 484 BOOL IsOutlineVisible(const PointF & point,const Pen * pen,const Graphics * g)485 IsOutlineVisible(const PointF &point, const Pen *pen, const Graphics *g) const 486 { 487 return IsOutlineVisible(point.X, point.Y, pen, g); 488 } 489 490 BOOL IsVisible(REAL x,REAL y,const Graphics * g)491 IsVisible(REAL x, REAL y, const Graphics *g) const 492 { 493 GpGraphics *nativeGraphics = g ? getNat(g) : NULL; 494 BOOL flag = FALSE; 495 SetStatus(DllExports::GdipIsVisiblePathPoint(nativePath, x, y, nativeGraphics, &flag)); 496 return flag; 497 } 498 499 BOOL IsVisible(const PointF & point,const Graphics * g)500 IsVisible(const PointF &point, const Graphics *g) const 501 { 502 return IsVisible(point.X, point.Y, g); 503 } 504 505 BOOL IsVisible(INT x,INT y,const Graphics * g)506 IsVisible(INT x, INT y, const Graphics *g) const 507 { 508 GpGraphics *nativeGraphics = g ? getNat(g) : NULL; 509 BOOL flag = FALSE; 510 SetStatus(DllExports::GdipIsVisiblePathPointI(nativePath, x, y, nativeGraphics, &flag)); 511 return flag; 512 } 513 514 BOOL IsVisible(const Point & point,const Graphics * g)515 IsVisible(const Point &point, const Graphics *g) const 516 { 517 return IsVisible(point.X, point.Y, g); 518 } 519 520 Status Outline(const Matrix * matrix,REAL flatness)521 Outline(const Matrix *matrix, REAL flatness) 522 { 523 GpMatrix *nativeMatrix = matrix ? getNat(matrix) : NULL; 524 return SetStatus(DllExports::GdipWindingModeOutline(nativePath, nativeMatrix, flatness)); 525 } 526 527 Status Reset()528 Reset() 529 { 530 return SetStatus(DllExports::GdipResetPath(nativePath)); 531 } 532 533 Status Reverse()534 Reverse() 535 { 536 return SetStatus(DllExports::GdipReversePath(nativePath)); 537 } 538 539 Status SetFillMode(FillMode fillmode)540 SetFillMode(FillMode fillmode) 541 { 542 return SetStatus(DllExports::GdipSetPathFillMode(nativePath, fillmode)); 543 } 544 545 Status SetMarker()546 SetMarker() 547 { 548 return SetStatus(DllExports::GdipSetPathMarker(nativePath)); 549 } 550 551 Status StartFigure()552 StartFigure() 553 { 554 return SetStatus(DllExports::GdipStartPathFigure(nativePath)); 555 } 556 557 Status Transform(const Matrix * matrix)558 Transform(const Matrix *matrix) 559 { 560 if (!matrix) 561 return Ok; 562 return SetStatus(DllExports::GdipTransformPath(nativePath, matrix->nativeMatrix)); 563 } 564 565 Status Warp(const PointF * destPoints,INT count,const RectF & srcRect,const Matrix * matrix,WarpMode warpMode,REAL flatness)566 Warp( 567 const PointF *destPoints, 568 INT count, 569 const RectF &srcRect, 570 const Matrix *matrix, 571 WarpMode warpMode, 572 REAL flatness) 573 { 574 GpMatrix *nativeMatrix = matrix ? getNat(matrix) : NULL; 575 return SetStatus(DllExports::GdipWarpPath( 576 nativePath, nativeMatrix, destPoints, count, srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height, warpMode, 577 flatness)); 578 } 579 580 Status Widen(const Pen * pen,const Matrix * matrix,REAL flatness)581 Widen(const Pen *pen, const Matrix *matrix, REAL flatness) 582 { 583 return SetStatus(NotImplemented); 584 } 585 586 protected: 587 GpPath *nativePath; 588 mutable Status lastStatus; 589 GraphicsPath()590 GraphicsPath() 591 { 592 } 593 GraphicsPath(GpPath * path)594 GraphicsPath(GpPath *path) : nativePath(path), lastStatus(Ok) 595 { 596 } 597 598 Status SetStatus(Status status)599 SetStatus(Status status) const 600 { 601 if (status != Ok) 602 lastStatus = status; 603 return status; 604 } 605 606 void SetNativePath(GpPath * path)607 SetNativePath(GpPath *path) 608 { 609 nativePath = path; 610 } 611 612 private: 613 // GraphicsPath is not copyable 614 GraphicsPath(const GraphicsPath &); 615 GraphicsPath & 616 operator=(const GraphicsPath &); 617 618 // get native 619 friend inline GpPath *& getNat(const GraphicsPath * path)620 getNat(const GraphicsPath *path) 621 { 622 return const_cast<GraphicsPath *>(path)->nativePath; 623 } 624 }; 625 626 class GraphicsPathIterator : public GdiplusBase 627 { 628 public: GraphicsPathIterator(GraphicsPath * path)629 GraphicsPathIterator(GraphicsPath *path) 630 { 631 GpPathIterator *it = NULL; 632 GpPath *nativePath = path ? getNat(path) : NULL; 633 lastStatus = DllExports::GdipCreatePathIter(&it, nativePath); 634 nativeIterator = it; 635 } 636 ~GraphicsPathIterator()637 ~GraphicsPathIterator() 638 { 639 DllExports::GdipDeletePathIter(nativeIterator); 640 } 641 642 INT CopyData(PointF * points,BYTE * types,INT startIndex,INT endIndex)643 CopyData(PointF *points, BYTE *types, INT startIndex, INT endIndex) 644 { 645 INT resultCount; 646 SetStatus(DllExports::GdipPathIterCopyData(nativeIterator, &resultCount, points, types, startIndex, endIndex)); 647 return resultCount; 648 } 649 650 INT Enumerate(PointF * points,BYTE * types,INT count)651 Enumerate(PointF *points, BYTE *types, INT count) 652 { 653 INT resultCount; 654 SetStatus(DllExports::GdipPathIterEnumerate(nativeIterator, &resultCount, points, types, count)); 655 return resultCount; 656 } 657 658 INT GetCount()659 GetCount() const 660 { 661 INT resultCount; 662 SetStatus(DllExports::GdipPathIterGetCount(nativeIterator, &resultCount)); 663 return resultCount; 664 } 665 666 Status GetLastStatus()667 GetLastStatus() const 668 { 669 return lastStatus; 670 } 671 672 INT GetSubpathCount()673 GetSubpathCount() const 674 { 675 INT resultCount; 676 SetStatus(DllExports::GdipPathIterGetSubpathCount(nativeIterator, &resultCount)); 677 return resultCount; 678 } 679 680 BOOL HasCurve()681 HasCurve() const 682 { 683 BOOL hasCurve; 684 SetStatus(DllExports::GdipPathIterHasCurve(nativeIterator, &hasCurve)); 685 return hasCurve; 686 } 687 688 INT NextMarker(GraphicsPath * path)689 NextMarker(GraphicsPath *path) 690 { 691 INT resultCount; 692 GpPath *nativePath = path ? getNat(path) : NULL; 693 SetStatus(DllExports::GdipPathIterNextMarkerPath(nativeIterator, &resultCount, nativePath)); 694 return resultCount; 695 } 696 697 INT NextMarker(INT * startIndex,INT * endIndex)698 NextMarker(INT *startIndex, INT *endIndex) 699 { 700 INT resultCount; 701 SetStatus(DllExports::GdipPathIterNextMarker(nativeIterator, &resultCount, startIndex, endIndex)); 702 return resultCount; 703 } 704 705 INT NextPathType(BYTE * pathType,INT * startIndex,INT * endIndex)706 NextPathType(BYTE *pathType, INT *startIndex, INT *endIndex) 707 { 708 INT resultCount; 709 SetStatus(DllExports::GdipPathIterNextPathType(nativeIterator, &resultCount, pathType, startIndex, endIndex)); 710 return resultCount; 711 } 712 713 INT NextSubpath(GraphicsPath * path,BOOL * isClosed)714 NextSubpath(GraphicsPath *path, BOOL *isClosed) 715 { 716 GpPath *nativePath = path ? getNat(path) : NULL; 717 INT resultCount; 718 SetStatus(DllExports::GdipPathIterNextSubpathPath(nativeIterator, &resultCount, nativePath, isClosed)); 719 return resultCount; 720 } 721 722 INT NextSubpath(INT * startIndex,INT * endIndex,BOOL * isClosed)723 NextSubpath(INT *startIndex, INT *endIndex, BOOL *isClosed) 724 { 725 INT resultCount; 726 SetStatus(DllExports::GdipPathIterNextSubpath(nativeIterator, &resultCount, startIndex, endIndex, isClosed)); 727 return resultCount; 728 } 729 730 VOID Rewind()731 Rewind() 732 { 733 SetStatus(DllExports::GdipPathIterRewind(nativeIterator)); 734 } 735 736 protected: 737 GpPathIterator *nativeIterator; 738 mutable Status lastStatus; 739 740 Status SetStatus(Status status)741 SetStatus(Status status) const 742 { 743 if (status != Ok) 744 lastStatus = status; 745 return status; 746 } 747 }; 748 749 class PathGradientBrush : public Brush 750 { 751 public: 752 friend class Pen; 753 754 PathGradientBrush(const Point *points, INT count, WrapMode wrapMode = WrapModeClamp) 755 { 756 GpPathGradient *brush = NULL; 757 lastStatus = DllExports::GdipCreatePathGradientI(points, count, wrapMode, &brush); 758 SetNativeBrush(brush); 759 } 760 761 PathGradientBrush(const PointF *points, INT count, WrapMode wrapMode = WrapModeClamp) 762 { 763 GpPathGradient *brush = NULL; 764 lastStatus = DllExports::GdipCreatePathGradient(points, count, wrapMode, &brush); 765 SetNativeBrush(brush); 766 } 767 PathGradientBrush(const GraphicsPath * path)768 PathGradientBrush(const GraphicsPath *path) 769 { 770 GpPathGradient *brush = NULL; 771 lastStatus = DllExports::GdipCreatePathGradientFromPath(getNat(path), &brush); 772 SetNativeBrush(brush); 773 } 774 775 INT GetBlendCount()776 GetBlendCount() const 777 { 778 INT count = 0; 779 SetStatus(DllExports::GdipGetPathGradientBlendCount(GetNativeGradient(), &count)); 780 return count; 781 } 782 783 Status GetBlend(REAL * blendFactors,REAL * blendPositions,INT count)784 GetBlend(REAL *blendFactors, REAL *blendPositions, INT count) const 785 { 786 return SetStatus( 787 DllExports::GdipGetPathGradientBlend(GetNativeGradient(), blendFactors, blendPositions, count)); 788 } 789 790 Status GetCenterColor(Color * color)791 GetCenterColor(Color *color) const 792 { 793 if (color != NULL) 794 return SetStatus(InvalidParameter); 795 796 ARGB argb; 797 SetStatus(DllExports::GdipGetPathGradientCenterColor(GetNativeGradient(), &argb)); 798 color->SetValue(argb); 799 return GetLastStatus(); 800 } 801 802 Status GetCenterPoint(Point * point)803 GetCenterPoint(Point *point) const 804 { 805 return SetStatus(DllExports::GdipGetPathGradientCenterPointI(GetNativeGradient(), point)); 806 } 807 808 Status GetCenterPoint(PointF * point)809 GetCenterPoint(PointF *point) const 810 { 811 return SetStatus(DllExports::GdipGetPathGradientCenterPoint(GetNativeGradient(), point)); 812 } 813 814 Status GetFocusScales(REAL * xScale,REAL * yScale)815 GetFocusScales(REAL *xScale, REAL *yScale) const 816 { 817 return SetStatus(DllExports::GdipGetPathGradientFocusScales(GetNativeGradient(), xScale, yScale)); 818 } 819 820 BOOL GetGammaCorrection()821 GetGammaCorrection() const 822 { 823 BOOL useGammaCorrection; 824 SetStatus(DllExports::GdipGetPathGradientGammaCorrection(GetNativeGradient(), &useGammaCorrection)); 825 return useGammaCorrection; 826 } 827 828 Status GetGraphicsPath(GraphicsPath * path)829 GetGraphicsPath(GraphicsPath *path) const 830 { 831 if (!path) 832 return SetStatus(InvalidParameter); 833 834 return SetStatus(DllExports::GdipGetPathGradientPath(GetNativeGradient(), getNat(path))); 835 } 836 837 INT GetInterpolationColorCount()838 GetInterpolationColorCount() const 839 { 840 INT count = 0; 841 SetStatus(DllExports::GdipGetPathGradientPresetBlendCount(GetNativeGradient(), &count)); 842 return count; 843 } 844 845 Status GetInterpolationColors(Color * presetColors,REAL * blendPositions,INT count)846 GetInterpolationColors(Color *presetColors, REAL *blendPositions, INT count) const 847 { 848 return NotImplemented; 849 } 850 851 INT GetPointCount()852 GetPointCount() const 853 { 854 INT count; 855 SetStatus(DllExports::GdipGetPathGradientPointCount(GetNativeGradient(), &count)); 856 return count; 857 } 858 859 Status GetRectangle(RectF * rect)860 GetRectangle(RectF *rect) const 861 { 862 return SetStatus(DllExports::GdipGetPathGradientRect(GetNativeGradient(), rect)); 863 } 864 865 Status GetRectangle(Rect * rect)866 GetRectangle(Rect *rect) const 867 { 868 return SetStatus(DllExports::GdipGetPathGradientRectI(GetNativeGradient(), rect)); 869 } 870 871 INT GetSurroundColorCount()872 GetSurroundColorCount() const 873 { 874 INT count; 875 SetStatus(DllExports::GdipGetPathGradientSurroundColorCount(GetNativeGradient(), &count)); 876 return count; 877 } 878 879 Status GetSurroundColors(Color * colors,INT * count)880 GetSurroundColors(Color *colors, INT *count) const 881 { 882 return NotImplemented; 883 } 884 885 Status GetTransform(Matrix * matrix)886 GetTransform(Matrix *matrix) const 887 { 888 return SetStatus(DllExports::GdipGetPathGradientTransform(GetNativeGradient(), getNat(matrix))); 889 } 890 891 WrapMode GetWrapMode()892 GetWrapMode() const 893 { 894 WrapMode wrapMode; 895 SetStatus(DllExports::GdipGetPathGradientWrapMode(GetNativeGradient(), &wrapMode)); 896 return wrapMode; 897 } 898 899 Status 900 MultiplyTransform(Matrix *matrix, MatrixOrder order = MatrixOrderPrepend) 901 { 902 return SetStatus(DllExports::GdipMultiplyPathGradientTransform(GetNativeGradient(), getNat(matrix), order)); 903 } 904 905 Status ResetTransform()906 ResetTransform() 907 { 908 return SetStatus(DllExports::GdipResetPathGradientTransform(GetNativeGradient())); 909 } 910 911 Status 912 RotateTransform(REAL angle, MatrixOrder order = MatrixOrderPrepend) 913 { 914 return SetStatus(DllExports::GdipRotatePathGradientTransform(GetNativeGradient(), angle, order)); 915 } 916 917 Status 918 ScaleTransform(REAL sx, REAL sy, MatrixOrder order = MatrixOrderPrepend) 919 { 920 return SetStatus(DllExports::GdipScalePathGradientTransform(GetNativeGradient(), sx, sy, order)); 921 } 922 923 Status SetBlend(REAL * blendFactors,REAL * blendPositions,INT count)924 SetBlend(REAL *blendFactors, REAL *blendPositions, INT count) 925 { 926 return SetStatus( 927 DllExports::GdipSetPathGradientBlend(GetNativeGradient(), blendFactors, blendPositions, count)); 928 } 929 930 Status SetBlendBellShape(REAL focus,REAL scale)931 SetBlendBellShape(REAL focus, REAL scale) 932 { 933 return SetStatus(DllExports::GdipSetPathGradientSigmaBlend(GetNativeGradient(), focus, scale)); 934 } 935 936 Status 937 SetBlendTriangularShape(REAL focus, REAL scale = 1.0f) 938 { 939 return SetStatus(DllExports::GdipSetPathGradientLinearBlend(GetNativeGradient(), focus, scale)); 940 } 941 942 Status SetCenterColor(const Color & color)943 SetCenterColor(const Color &color) 944 { 945 return SetStatus(DllExports::GdipSetPathGradientCenterColor(GetNativeGradient(), color.GetValue())); 946 } 947 948 Status SetCenterPoint(const Point & point)949 SetCenterPoint(const Point &point) 950 { 951 return SetStatus(DllExports::GdipSetPathGradientCenterPointI(GetNativeGradient(), const_cast<Point *>(&point))); 952 } 953 954 Status SetCenterPoint(const PointF & point)955 SetCenterPoint(const PointF &point) 956 { 957 return SetStatus(DllExports::GdipSetPathGradientCenterPoint(GetNativeGradient(), const_cast<PointF *>(&point))); 958 } 959 960 Status SetFocusScales(REAL xScale,REAL yScale)961 SetFocusScales(REAL xScale, REAL yScale) 962 { 963 return SetStatus(DllExports::GdipSetPathGradientFocusScales(GetNativeGradient(), xScale, yScale)); 964 } 965 966 Status SetGammaCorrection(BOOL useGammaCorrection)967 SetGammaCorrection(BOOL useGammaCorrection) 968 { 969 return SetStatus(DllExports::GdipSetPathGradientGammaCorrection(GetNativeGradient(), useGammaCorrection)); 970 } 971 972 Status SetGraphicsPath(const GraphicsPath * path)973 SetGraphicsPath(const GraphicsPath *path) 974 { 975 if (!path) 976 return SetStatus(InvalidParameter); 977 return SetStatus(DllExports::GdipSetPathGradientPath(GetNativeGradient(), getNat(path))); 978 } 979 980 Status SetInterpolationColors(const Color * presetColors,REAL * blendPositions,INT count)981 SetInterpolationColors(const Color *presetColors, REAL *blendPositions, INT count) 982 { 983 return NotImplemented; 984 } 985 986 Status SetSurroundColors(const Color * colors,INT * count)987 SetSurroundColors(const Color *colors, INT *count) 988 { 989 return NotImplemented; 990 } 991 992 Status SetTransform(const Matrix * matrix)993 SetTransform(const Matrix *matrix) 994 { 995 return SetStatus(DllExports::GdipSetPathGradientTransform(GetNativeGradient(), getNat(matrix))); 996 } 997 998 Status SetWrapMode(WrapMode wrapMode)999 SetWrapMode(WrapMode wrapMode) 1000 { 1001 return SetStatus(DllExports::GdipSetPathGradientWrapMode(GetNativeGradient(), wrapMode)); 1002 } 1003 1004 Status 1005 TranslateTransform(REAL dx, REAL dy, MatrixOrder order = MatrixOrderPrepend) 1006 { 1007 return SetStatus(DllExports::GdipTranslatePathGradientTransform(GetNativeGradient(), dx, dy, order)); 1008 } 1009 1010 protected: 1011 GpPathGradient * GetNativeGradient()1012 GetNativeGradient() const 1013 { 1014 return static_cast<GpPathGradient *>(nativeBrush); 1015 } 1016 PathGradientBrush()1017 PathGradientBrush() 1018 { 1019 } 1020 }; 1021 1022 #endif /* _GDIPLUSPATH_H */ 1023