PageRenderTime 61ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 1ms

/binding/win32/gdiplusgraphics.d

http://github.com/wilkie/djehuty
D | 2335 lines | 1996 code | 291 blank | 48 comment | 22 complexity | a3dcf82dac6e4451f872aa9db2317a02 MD5 | raw file
  1. /*
  2. * gdiplusgraphics.d
  3. *
  4. * This module implements GdiPlusGraphics.h for D. The original
  5. * copyright info is given below.
  6. *
  7. * Author: Dave Wilkinson
  8. * Originated: November 25th, 2009
  9. *
  10. */
  11. module binding.win32.gdiplusgraphics;
  12. import binding.win32.windef;
  13. import binding.win32.winbase;
  14. import binding.win32.winnt;
  15. import binding.win32.wingdi;
  16. import binding.win32.guiddef;
  17. import binding.win32.gdiplusbase;
  18. import binding.win32.gdiplustypes;
  19. import binding.win32.gdiplusenums;
  20. import binding.win32.gdipluspixelformats;
  21. import binding.win32.gdiplusgpstubs;
  22. import binding.win32.gdiplusmetaheader;
  23. import binding.win32.gdipluspixelformats;
  24. import binding.win32.gdipluscolor;
  25. import binding.win32.gdipluscolormatrix;
  26. import binding.win32.gdiplusflat;
  27. import binding.win32.gdiplusimaging;
  28. import binding.win32.gdiplusbitmap;
  29. import binding.win32.gdiplusimageattributes;
  30. import binding.win32.gdiplusmatrix;
  31. import binding.win32.gdiplusregion;
  32. import binding.win32.gdiplusbrush;
  33. import binding.win32.gdipluspen;
  34. import binding.win32.gdiplusfont;
  35. import binding.win32.gdipluspath;
  36. import binding.win32.gdiplusstringformat;
  37. import binding.win32.gdipluscachedbitmap;
  38. import binding.win32.gdipluseffects;
  39. import binding.win32.gdiplusmetafile;
  40. /**************************************************************************\
  41. *
  42. * Copyright (c) 1998-2001, Microsoft Corp. All Rights Reserved.
  43. *
  44. * Module Name:
  45. *
  46. * GdiplusGraphics.h
  47. *
  48. * Abstract:
  49. *
  50. * GDI+ Graphics Object
  51. *
  52. \**************************************************************************/
  53. extern(System):
  54. class Graphics : GdiplusBase {
  55. static Graphics FromHDC(in HDC hdc) {
  56. return new Graphics(hdc);
  57. }
  58. static Graphics FromHDC(in HDC hdc, in HANDLE hdevice) {
  59. return new Graphics(hdc, hdevice);
  60. }
  61. static Graphics FromHWND(in HWND hwnd, in BOOL icm = FALSE) {
  62. return new Graphics(hwnd, icm);
  63. }
  64. static Graphics FromImage(in Image image) {
  65. return new Graphics(image);
  66. }
  67. this(in HDC hdc) {
  68. GpGraphics *graphics = null;
  69. lastResult = GdipCreateFromHDC(hdc, &graphics);
  70. SetNativeGraphics(graphics);
  71. }
  72. this(in HDC hdc, in HANDLE hdevice) {
  73. GpGraphics *graphics = null;
  74. lastResult = GdipCreateFromHDC2(hdc, hdevice, &graphics);
  75. SetNativeGraphics(graphics);
  76. }
  77. this(in HWND hwnd, in BOOL icm) {
  78. GpGraphics *graphics = null;
  79. if (icm) {
  80. lastResult = GdipCreateFromHWNDICM(hwnd, &graphics);
  81. }
  82. else {
  83. lastResult = GdipCreateFromHWND(hwnd, &graphics);
  84. }
  85. SetNativeGraphics(graphics);
  86. }
  87. this(in Image image) {
  88. GpGraphics *graphics = null;
  89. if (image !is null) {
  90. lastResult = GdipGetImageGraphicsContext(
  91. image.nativeImage, &graphics);
  92. }
  93. SetNativeGraphics(graphics);
  94. }
  95. ~this() {
  96. GdipDeleteGraphics(nativeGraphics);
  97. }
  98. VOID Flush(in FlushIntention intention = FlushIntention.FlushIntentionFlush) {
  99. GdipFlush(nativeGraphics, intention);
  100. }
  101. //------------------------------------------------------------------------
  102. // GDI Interop methods
  103. //------------------------------------------------------------------------
  104. // Locks the graphics until ReleaseDC is called
  105. HDC GetHDC() {
  106. HDC hdc = null;
  107. SetStatus(GdipGetDC(nativeGraphics, &hdc));
  108. return hdc;
  109. }
  110. VOID ReleaseHDC(in HDC hdc) {
  111. SetStatus(GdipReleaseDC(nativeGraphics, hdc));
  112. }
  113. //------------------------------------------------------------------------
  114. // Rendering modes
  115. //------------------------------------------------------------------------
  116. Status SetRenderingOrigin(in INT x, in INT y) {
  117. return SetStatus(
  118. GdipSetRenderingOrigin(
  119. nativeGraphics, x, y
  120. )
  121. );
  122. }
  123. Status GetRenderingOrigin(ref INT x, ref INT y) {
  124. return SetStatus(
  125. GdipGetRenderingOrigin(
  126. nativeGraphics, &x, &y
  127. )
  128. );
  129. }
  130. Status SetCompositingMode(in CompositingMode compositingMode) {
  131. return SetStatus(GdipSetCompositingMode(nativeGraphics, compositingMode));
  132. }
  133. CompositingMode GetCompositingMode() {
  134. CompositingMode mode;
  135. SetStatus(GdipGetCompositingMode(nativeGraphics,
  136. &mode));
  137. return mode;
  138. }
  139. Status SetCompositingQuality(in CompositingQuality compositingQuality) {
  140. return SetStatus(GdipSetCompositingQuality(
  141. nativeGraphics,
  142. compositingQuality));
  143. }
  144. CompositingQuality GetCompositingQuality() {
  145. CompositingQuality quality;
  146. SetStatus(GdipGetCompositingQuality(
  147. nativeGraphics,
  148. &quality));
  149. return quality;
  150. }
  151. Status SetTextRenderingHint(in TextRenderingHint newMode) {
  152. return SetStatus(GdipSetTextRenderingHint(nativeGraphics,
  153. newMode));
  154. }
  155. TextRenderingHint GetTextRenderingHint() {
  156. TextRenderingHint hint;
  157. SetStatus(GdipGetTextRenderingHint(nativeGraphics,
  158. &hint));
  159. return hint;
  160. }
  161. Status SetTextContrast(in UINT contrast) {
  162. return SetStatus(GdipSetTextContrast(nativeGraphics, contrast));
  163. }
  164. UINT GetTextContrast() {
  165. UINT contrast;
  166. SetStatus(GdipGetTextContrast(nativeGraphics, &contrast));
  167. return contrast;
  168. }
  169. InterpolationMode GetInterpolationMode() {
  170. InterpolationMode mode = InterpolationMode.InterpolationModeInvalid;
  171. SetStatus(GdipGetInterpolationMode(nativeGraphics, &mode));
  172. return mode;
  173. }
  174. Status SetInterpolationMode(in InterpolationMode interpolationMode) {
  175. return SetStatus(GdipSetInterpolationMode(nativeGraphics, interpolationMode));
  176. }
  177. version(GDIPLUS6) {
  178. Status SetAbort(GdiplusAbort *pIAbort) {
  179. return SetStatus(GdipGraphicsSetAbort(
  180. nativeGraphics,
  181. pIAbort
  182. ));
  183. }
  184. }
  185. SmoothingMode GetSmoothingMode() {
  186. SmoothingMode smoothingMode = SmoothingMode.SmoothingModeInvalid;
  187. SetStatus(GdipGetSmoothingMode(nativeGraphics,
  188. &smoothingMode));
  189. return smoothingMode;
  190. }
  191. Status SetSmoothingMode(in SmoothingMode smoothingMode) {
  192. return SetStatus(GdipSetSmoothingMode(nativeGraphics,
  193. smoothingMode));
  194. }
  195. PixelOffsetMode GetPixelOffsetMode() {
  196. PixelOffsetMode pixelOffsetMode = PixelOffsetMode.PixelOffsetModeInvalid;
  197. SetStatus(GdipGetPixelOffsetMode(nativeGraphics,
  198. &pixelOffsetMode));
  199. return pixelOffsetMode;
  200. }
  201. Status SetPixelOffsetMode(in PixelOffsetMode pixelOffsetMode) {
  202. return SetStatus(GdipSetPixelOffsetMode(nativeGraphics,
  203. pixelOffsetMode));
  204. }
  205. //------------------------------------------------------------------------
  206. // Manipulate current world transform
  207. //------------------------------------------------------------------------
  208. Status SetTransform(in Matrix matrix) {
  209. return SetStatus(GdipSetWorldTransform(nativeGraphics,
  210. matrix.nativeMatrix));
  211. }
  212. Status ResetTransform() {
  213. return SetStatus(GdipResetWorldTransform(nativeGraphics));
  214. }
  215. Status MultiplyTransform(in Matrix matrix, in MatrixOrder order = MatrixOrder.MatrixOrderPrepend) {
  216. return SetStatus(GdipMultiplyWorldTransform(nativeGraphics,
  217. matrix.nativeMatrix,
  218. order));
  219. }
  220. Status TranslateTransform(in REAL dx, in REAL dy, in MatrixOrder order = MatrixOrder.MatrixOrderPrepend) {
  221. return SetStatus(GdipTranslateWorldTransform(nativeGraphics, dx, dy, order));
  222. }
  223. Status ScaleTransform(in REAL sx, in REAL sy, in MatrixOrder order = MatrixOrder.MatrixOrderPrepend) {
  224. return SetStatus(GdipScaleWorldTransform(nativeGraphics, sx, sy, order));
  225. }
  226. Status RotateTransform(in REAL angle, in MatrixOrder order = MatrixOrder.MatrixOrderPrepend) {
  227. return SetStatus(GdipRotateWorldTransform(nativeGraphics, angle, order));
  228. }
  229. Status GetTransform(Matrix* matrix) {
  230. return SetStatus(GdipGetWorldTransform(nativeGraphics, matrix.nativeMatrix));
  231. }
  232. Status SetPageUnit(in Unit unit) {
  233. return SetStatus(GdipSetPageUnit(nativeGraphics, unit));
  234. }
  235. Status SetPageScale(in REAL scale) {
  236. return SetStatus(GdipSetPageScale(nativeGraphics, scale));
  237. }
  238. Unit GetPageUnit() {
  239. Unit unit;
  240. SetStatus(GdipGetPageUnit(nativeGraphics, &unit));
  241. return unit;
  242. }
  243. REAL GetPageScale() {
  244. REAL scale;
  245. SetStatus(GdipGetPageScale(nativeGraphics, &scale));
  246. return scale;
  247. }
  248. REAL GetDpiX() {
  249. REAL dpi;
  250. SetStatus(GdipGetDpiX(nativeGraphics, &dpi));
  251. return dpi;
  252. }
  253. REAL GetDpiY() {
  254. REAL dpi;
  255. SetStatus(GdipGetDpiY(nativeGraphics, &dpi));
  256. return dpi;
  257. }
  258. Status TransformPoints(in CoordinateSpace destSpace, in CoordinateSpace srcSpace, PointF* pts, in INT count) {
  259. return SetStatus(GdipTransformPoints(nativeGraphics, destSpace, srcSpace, pts, count));
  260. }
  261. Status TransformPoints(in CoordinateSpace destSpace, in CoordinateSpace srcSpace, in Point* pts, in INT count) {
  262. return SetStatus(GdipTransformPointsI(nativeGraphics, destSpace, srcSpace, pts, count));
  263. }
  264. //------------------------------------------------------------------------
  265. // GetNearestColor (for <= 8bpp surfaces). Note: Alpha is ignored.
  266. //------------------------------------------------------------------------
  267. Status GetNearestColor(in Color color) {
  268. if (color is null) {
  269. return SetStatus(Status.InvalidParameter);
  270. }
  271. ARGB argb = color.GetValue();
  272. Status status = SetStatus(GdipGetNearestColor(nativeGraphics, &argb));
  273. color.SetValue(argb);
  274. return status;
  275. }
  276. Status DrawLine(in Pen pen, in REAL x1, in REAL y1, in REAL x2, in REAL y2) {
  277. return SetStatus(GdipDrawLine(nativeGraphics,
  278. pen.nativePen, x1, y1, x2,
  279. y2));
  280. }
  281. Status DrawLine(in Pen pen, in PointF pt1, in PointF pt2) {
  282. return DrawLine(pen, pt1.X, pt1.Y, pt2.X, pt2.Y);
  283. }
  284. Status DrawLines(in Pen pen,
  285. in PointF* points,
  286. in INT count)
  287. {
  288. return SetStatus(GdipDrawLines(nativeGraphics,
  289. pen.nativePen,
  290. points, count));
  291. }
  292. Status DrawLine(in Pen pen,
  293. in INT x1,
  294. in INT y1,
  295. in INT x2,
  296. in INT y2)
  297. {
  298. return SetStatus(GdipDrawLineI(nativeGraphics,
  299. pen.nativePen,
  300. x1,
  301. y1,
  302. x2,
  303. y2));
  304. }
  305. Status DrawLine(in Pen pen,
  306. in Point pt1,
  307. in Point pt2)
  308. {
  309. return DrawLine(pen,
  310. pt1.X,
  311. pt1.Y,
  312. pt2.X,
  313. pt2.Y);
  314. }
  315. Status DrawLines(in Pen pen,
  316. in Point* points,
  317. in INT count)
  318. {
  319. return SetStatus(GdipDrawLinesI(nativeGraphics,
  320. pen.nativePen,
  321. points,
  322. count));
  323. }
  324. Status DrawArc(in Pen pen,
  325. in REAL x,
  326. in REAL y,
  327. in REAL width,
  328. in REAL height,
  329. in REAL startAngle,
  330. in REAL sweepAngle)
  331. {
  332. return SetStatus(GdipDrawArc(nativeGraphics,
  333. pen.nativePen,
  334. x,
  335. y,
  336. width,
  337. height,
  338. startAngle,
  339. sweepAngle));
  340. }
  341. Status DrawArc(in Pen pen,
  342. in RectF rect,
  343. in REAL startAngle,
  344. in REAL sweepAngle)
  345. {
  346. return DrawArc(pen, rect.X, rect.Y, rect.Width, rect.Height,
  347. startAngle, sweepAngle);
  348. }
  349. Status DrawArc(in Pen pen,
  350. in INT x,
  351. in INT y,
  352. in INT width,
  353. in INT height,
  354. in REAL startAngle,
  355. in REAL sweepAngle)
  356. {
  357. return SetStatus(GdipDrawArcI(nativeGraphics,
  358. pen.nativePen,
  359. x,
  360. y,
  361. width,
  362. height,
  363. startAngle,
  364. sweepAngle));
  365. }
  366. Status DrawArc(in Pen pen,
  367. in Rect rect,
  368. in REAL startAngle,
  369. in REAL sweepAngle)
  370. {
  371. return DrawArc(pen,
  372. rect.X,
  373. rect.Y,
  374. rect.Width,
  375. rect.Height,
  376. startAngle,
  377. sweepAngle);
  378. }
  379. Status DrawBezier(in Pen pen,
  380. in REAL x1,
  381. in REAL y1,
  382. in REAL x2,
  383. in REAL y2,
  384. in REAL x3,
  385. in REAL y3,
  386. in REAL x4,
  387. in REAL y4)
  388. {
  389. return SetStatus(GdipDrawBezier(nativeGraphics,
  390. pen.nativePen, x1, y1,
  391. x2, y2, x3, y3, x4, y4));
  392. }
  393. Status DrawBezier(in Pen pen,
  394. in PointF pt1,
  395. in PointF pt2,
  396. in PointF pt3,
  397. in PointF pt4)
  398. {
  399. return DrawBezier(pen,
  400. pt1.X,
  401. pt1.Y,
  402. pt2.X,
  403. pt2.Y,
  404. pt3.X,
  405. pt3.Y,
  406. pt4.X,
  407. pt4.Y);
  408. }
  409. Status DrawBeziers(in Pen pen,
  410. in PointF* points,
  411. in INT count)
  412. {
  413. return SetStatus(GdipDrawBeziers(nativeGraphics,
  414. pen.nativePen,
  415. points,
  416. count));
  417. }
  418. Status DrawBezier(in Pen pen,
  419. in INT x1,
  420. in INT y1,
  421. in INT x2,
  422. in INT y2,
  423. in INT x3,
  424. in INT y3,
  425. in INT x4,
  426. in INT y4)
  427. {
  428. return SetStatus(GdipDrawBezierI(nativeGraphics,
  429. pen.nativePen,
  430. x1,
  431. y1,
  432. x2,
  433. y2,
  434. x3,
  435. y3,
  436. x4,
  437. y4));
  438. }
  439. Status DrawBezier(in Pen pen,
  440. in Point pt1,
  441. in Point pt2,
  442. in Point pt3,
  443. in Point pt4)
  444. {
  445. return DrawBezier(pen,
  446. pt1.X,
  447. pt1.Y,
  448. pt2.X,
  449. pt2.Y,
  450. pt3.X,
  451. pt3.Y,
  452. pt4.X,
  453. pt4.Y);
  454. }
  455. Status DrawBeziers(in Pen pen,
  456. in Point* points,
  457. in INT count)
  458. {
  459. return SetStatus(GdipDrawBeziersI(nativeGraphics,
  460. pen.nativePen,
  461. points,
  462. count));
  463. }
  464. Status DrawRectangle(in Pen pen,
  465. in RectF rect)
  466. {
  467. return DrawRectangle(pen, rect.X, rect.Y, rect.Width, rect.Height);
  468. }
  469. Status DrawRectangle(in Pen pen,
  470. in REAL x,
  471. in REAL y,
  472. in REAL width,
  473. in REAL height)
  474. {
  475. return SetStatus(GdipDrawRectangle(nativeGraphics,
  476. pen.nativePen, x, y,
  477. width, height));
  478. }
  479. Status DrawRectangles(in Pen pen,
  480. in RectF* rects,
  481. in INT count)
  482. {
  483. return SetStatus(GdipDrawRectangles(nativeGraphics,
  484. pen.nativePen,
  485. rects, count));
  486. }
  487. Status DrawRectangle(in Pen pen,
  488. in Rect rect)
  489. {
  490. return DrawRectangle(pen,
  491. rect.X,
  492. rect.Y,
  493. rect.Width,
  494. rect.Height);
  495. }
  496. Status DrawRectangle(in Pen pen,
  497. in INT x,
  498. in INT y,
  499. in INT width,
  500. in INT height)
  501. {
  502. return SetStatus(GdipDrawRectangleI(nativeGraphics,
  503. pen.nativePen,
  504. x,
  505. y,
  506. width,
  507. height));
  508. }
  509. Status DrawRectangles(in Pen pen,
  510. in Rect* rects,
  511. in INT count)
  512. {
  513. return SetStatus(GdipDrawRectanglesI(nativeGraphics,
  514. pen.nativePen,
  515. rects,
  516. count));
  517. }
  518. Status DrawEllipse(in Pen pen,
  519. in RectF rect)
  520. {
  521. return DrawEllipse(pen, rect.X, rect.Y, rect.Width, rect.Height);
  522. }
  523. Status DrawEllipse(in Pen pen,
  524. in REAL x,
  525. in REAL y,
  526. in REAL width,
  527. in REAL height)
  528. {
  529. return SetStatus(GdipDrawEllipse(nativeGraphics,
  530. pen.nativePen,
  531. x,
  532. y,
  533. width,
  534. height));
  535. }
  536. Status DrawEllipse(in Pen pen,
  537. in Rect rect)
  538. {
  539. return DrawEllipse(pen,
  540. rect.X,
  541. rect.Y,
  542. rect.Width,
  543. rect.Height);
  544. }
  545. Status DrawEllipse(in Pen pen,
  546. in INT x,
  547. in INT y,
  548. in INT width,
  549. in INT height)
  550. {
  551. return SetStatus(GdipDrawEllipseI(nativeGraphics,
  552. pen.nativePen,
  553. x,
  554. y,
  555. width,
  556. height));
  557. }
  558. Status DrawPie(in Pen pen,
  559. in RectF rect,
  560. in REAL startAngle,
  561. in REAL sweepAngle)
  562. {
  563. return DrawPie(pen,
  564. rect.X,
  565. rect.Y,
  566. rect.Width,
  567. rect.Height,
  568. startAngle,
  569. sweepAngle);
  570. }
  571. Status DrawPie(in Pen pen,
  572. in REAL x,
  573. in REAL y,
  574. in REAL width,
  575. in REAL height,
  576. in REAL startAngle,
  577. in REAL sweepAngle)
  578. {
  579. return SetStatus(GdipDrawPie(nativeGraphics,
  580. pen.nativePen,
  581. x,
  582. y,
  583. width,
  584. height,
  585. startAngle,
  586. sweepAngle));
  587. }
  588. Status DrawPie(in Pen pen,
  589. in Rect rect,
  590. in REAL startAngle,
  591. in REAL sweepAngle)
  592. {
  593. return DrawPie(pen,
  594. rect.X,
  595. rect.Y,
  596. rect.Width,
  597. rect.Height,
  598. startAngle,
  599. sweepAngle);
  600. }
  601. Status DrawPie(in Pen pen,
  602. in INT x,
  603. in INT y,
  604. in INT width,
  605. in INT height,
  606. in REAL startAngle,
  607. in REAL sweepAngle)
  608. {
  609. return SetStatus(GdipDrawPieI(nativeGraphics,
  610. pen.nativePen,
  611. x,
  612. y,
  613. width,
  614. height,
  615. startAngle,
  616. sweepAngle));
  617. }
  618. Status DrawPolygon(in Pen pen,
  619. in PointF* points,
  620. in INT count)
  621. {
  622. return SetStatus(GdipDrawPolygon(nativeGraphics,
  623. pen.nativePen,
  624. points,
  625. count));
  626. }
  627. Status DrawPolygon(in Pen pen,
  628. in Point* points,
  629. in INT count)
  630. {
  631. return SetStatus(GdipDrawPolygonI(nativeGraphics,
  632. pen.nativePen,
  633. points,
  634. count));
  635. }
  636. Status DrawPath(in Pen pen,
  637. in GraphicsPath* path)
  638. {
  639. return SetStatus(GdipDrawPath(nativeGraphics,
  640. pen ? pen.nativePen : null,
  641. path ? path.nativePath : null));
  642. }
  643. Status DrawCurve(in Pen pen,
  644. in PointF* points,
  645. in INT count)
  646. {
  647. return SetStatus(GdipDrawCurve(nativeGraphics,
  648. pen.nativePen, points,
  649. count));
  650. }
  651. Status DrawCurve(in Pen pen,
  652. in PointF* points,
  653. in INT count,
  654. in REAL tension)
  655. {
  656. return SetStatus(GdipDrawCurve2(nativeGraphics,
  657. pen.nativePen, points,
  658. count, tension));
  659. }
  660. Status DrawCurve(in Pen pen,
  661. in PointF* points,
  662. in INT count,
  663. in INT offset,
  664. in INT numberOfSegments,
  665. in REAL tension = 0.5f)
  666. {
  667. return SetStatus(GdipDrawCurve3(nativeGraphics,
  668. pen.nativePen, points,
  669. count, offset,
  670. numberOfSegments, tension));
  671. }
  672. Status DrawCurve(in Pen pen,
  673. in Point* points,
  674. in INT count)
  675. {
  676. return SetStatus(GdipDrawCurveI(nativeGraphics,
  677. pen.nativePen,
  678. points,
  679. count));
  680. }
  681. Status DrawCurve(in Pen pen,
  682. in Point* points,
  683. in INT count,
  684. in REAL tension)
  685. {
  686. return SetStatus(GdipDrawCurve2I(nativeGraphics,
  687. pen.nativePen,
  688. points,
  689. count,
  690. tension));
  691. }
  692. Status DrawCurve(in Pen pen,
  693. in Point* points,
  694. in INT count,
  695. in INT offset,
  696. in INT numberOfSegments,
  697. in REAL tension = 0.5f)
  698. {
  699. return SetStatus(GdipDrawCurve3I(nativeGraphics,
  700. pen.nativePen,
  701. points,
  702. count,
  703. offset,
  704. numberOfSegments,
  705. tension));
  706. }
  707. Status DrawClosedCurve(in Pen pen,
  708. in PointF* points,
  709. in INT count)
  710. {
  711. return SetStatus(GdipDrawClosedCurve(nativeGraphics,
  712. pen.nativePen,
  713. points, count));
  714. }
  715. Status DrawClosedCurve(in Pen *pen,
  716. in PointF* points,
  717. in INT count,
  718. in REAL tension)
  719. {
  720. return SetStatus(GdipDrawClosedCurve2(nativeGraphics,
  721. pen.nativePen,
  722. points, count,
  723. tension));
  724. }
  725. Status DrawClosedCurve(in Pen pen,
  726. in Point* points,
  727. in INT count)
  728. {
  729. return SetStatus(GdipDrawClosedCurveI(nativeGraphics,
  730. pen.nativePen,
  731. points,
  732. count));
  733. }
  734. Status DrawClosedCurve(in Pen *pen,
  735. in Point* points,
  736. in INT count,
  737. in REAL tension)
  738. {
  739. return SetStatus(GdipDrawClosedCurve2I(nativeGraphics,
  740. pen.nativePen,
  741. points,
  742. count,
  743. tension));
  744. }
  745. Status Clear(in Color color)
  746. {
  747. return SetStatus(GdipGraphicsClear(
  748. nativeGraphics,
  749. color.GetValue()));
  750. }
  751. Status FillRectangle(in Brush* brush,
  752. in RectF rect)
  753. {
  754. return FillRectangle(brush, rect.X, rect.Y, rect.Width, rect.Height);
  755. }
  756. Status FillRectangle(in Brush* brush,
  757. in REAL x,
  758. in REAL y,
  759. in REAL width,
  760. in REAL height)
  761. {
  762. return SetStatus(GdipFillRectangle(nativeGraphics, brush.nativeBrush, x, y, width, height));
  763. }
  764. Status FillRectangles(in Brush* brush,
  765. in RectF* rects,
  766. in INT count)
  767. {
  768. return SetStatus(GdipFillRectangles(nativeGraphics,
  769. brush.nativeBrush,
  770. rects, count));
  771. }
  772. Status FillRectangle(in Brush* brush,
  773. in Rect rect)
  774. {
  775. return FillRectangle(brush,
  776. rect.X,
  777. rect.Y,
  778. rect.Width,
  779. rect.Height);
  780. }
  781. Status FillRectangle(in Brush* brush,
  782. in INT x,
  783. in INT y,
  784. in INT width,
  785. in INT height)
  786. {
  787. return SetStatus(GdipFillRectangleI(nativeGraphics,
  788. brush.nativeBrush,
  789. x,
  790. y,
  791. width,
  792. height));
  793. }
  794. Status FillRectangles(in Brush* brush,
  795. in Rect* rects,
  796. in INT count)
  797. {
  798. return SetStatus(GdipFillRectanglesI(nativeGraphics,
  799. brush.nativeBrush,
  800. rects,
  801. count));
  802. }
  803. Status FillPolygon(in Brush* brush,
  804. in PointF* points,
  805. in INT count)
  806. {
  807. return FillPolygon(brush, points, count, FillMode.FillModeAlternate);
  808. }
  809. Status FillPolygon(in Brush* brush,
  810. in PointF* points,
  811. in INT count,
  812. in FillMode fillMode)
  813. {
  814. return SetStatus(GdipFillPolygon(nativeGraphics,
  815. brush.nativeBrush,
  816. points, count, fillMode));
  817. }
  818. Status FillPolygon(in Brush* brush,
  819. in Point* points,
  820. in INT count)
  821. {
  822. return FillPolygon(brush, points, count, FillMode.FillModeAlternate);
  823. }
  824. Status FillPolygon(in Brush* brush,
  825. in Point* points,
  826. in INT count,
  827. in FillMode fillMode)
  828. {
  829. return SetStatus(GdipFillPolygonI(nativeGraphics,
  830. brush.nativeBrush,
  831. points, count,
  832. fillMode));
  833. }
  834. Status FillEllipse(in Brush* brush,
  835. in RectF rect)
  836. {
  837. return FillEllipse(brush, rect.X, rect.Y, rect.Width, rect.Height);
  838. }
  839. Status FillEllipse(in Brush* brush,
  840. in REAL x,
  841. in REAL y,
  842. in REAL width,
  843. in REAL height)
  844. {
  845. return SetStatus(GdipFillEllipse(nativeGraphics,
  846. brush.nativeBrush, x, y,
  847. width, height));
  848. }
  849. Status FillEllipse(in Brush* brush,
  850. in Rect rect)
  851. {
  852. return FillEllipse(brush, rect.X, rect.Y, rect.Width, rect.Height);
  853. }
  854. Status FillEllipse(in Brush* brush,
  855. in INT x,
  856. in INT y,
  857. in INT width,
  858. in INT height)
  859. {
  860. return SetStatus(GdipFillEllipseI(nativeGraphics,
  861. brush.nativeBrush,
  862. x,
  863. y,
  864. width,
  865. height));
  866. }
  867. Status FillPie(in Brush* brush,
  868. in RectF rect,
  869. in REAL startAngle,
  870. in REAL sweepAngle)
  871. {
  872. return FillPie(brush, rect.X, rect.Y, rect.Width, rect.Height,
  873. startAngle, sweepAngle);
  874. }
  875. Status FillPie(in Brush* brush,
  876. in REAL x,
  877. in REAL y,
  878. in REAL width,
  879. in REAL height,
  880. in REAL startAngle,
  881. in REAL sweepAngle)
  882. {
  883. return SetStatus(GdipFillPie(nativeGraphics,
  884. brush.nativeBrush, x, y,
  885. width, height, startAngle,
  886. sweepAngle));
  887. }
  888. Status FillPie(in Brush* brush,
  889. in Rect rect,
  890. in REAL startAngle,
  891. in REAL sweepAngle)
  892. {
  893. return FillPie(brush, rect.X, rect.Y, rect.Width, rect.Height,
  894. startAngle, sweepAngle);
  895. }
  896. Status FillPie(in Brush* brush,
  897. in INT x,
  898. in INT y,
  899. in INT width,
  900. in INT height,
  901. in REAL startAngle,
  902. in REAL sweepAngle)
  903. {
  904. return SetStatus(GdipFillPieI(nativeGraphics,
  905. brush.nativeBrush,
  906. x,
  907. y,
  908. width,
  909. height,
  910. startAngle,
  911. sweepAngle));
  912. }
  913. Status FillPath(in Brush* brush,
  914. in GraphicsPath* path)
  915. {
  916. return SetStatus(GdipFillPath(nativeGraphics,
  917. brush.nativeBrush,
  918. path.nativePath));
  919. }
  920. Status FillClosedCurve(in Brush* brush,
  921. in PointF* points,
  922. in INT count)
  923. {
  924. return SetStatus(GdipFillClosedCurve(nativeGraphics,
  925. brush.nativeBrush,
  926. points, count));
  927. }
  928. Status FillClosedCurve(in Brush* brush,
  929. in PointF* points,
  930. in INT count,
  931. in FillMode fillMode,
  932. in REAL tension = 0.5f)
  933. {
  934. return SetStatus(GdipFillClosedCurve2(nativeGraphics,
  935. brush.nativeBrush,
  936. points, count,
  937. tension, fillMode));
  938. }
  939. Status FillClosedCurve(in Brush* brush,
  940. in Point* points,
  941. in INT count)
  942. {
  943. return SetStatus(GdipFillClosedCurveI(nativeGraphics,
  944. brush.nativeBrush,
  945. points,
  946. count));
  947. }
  948. Status FillClosedCurve(in Brush* brush,
  949. in Point* points,
  950. in INT count,
  951. in FillMode fillMode,
  952. in REAL tension = 0.5f)
  953. {
  954. return SetStatus(GdipFillClosedCurve2I(nativeGraphics,
  955. brush.nativeBrush,
  956. points, count,
  957. tension, fillMode));
  958. }
  959. Status FillRegion(in Brush* brush,
  960. in Region* region)
  961. {
  962. return SetStatus(GdipFillRegion(nativeGraphics,
  963. brush.nativeBrush,
  964. region.nativeRegion));
  965. }
  966. Status DrawString(in WCHAR* string, in INT length, in Font font,
  967. in RectF layoutRect, in StringFormat stringFormat, in Brush brush) {
  968. return SetStatus(GdipDrawString(
  969. nativeGraphics,
  970. string,
  971. length,
  972. font ? font.nativeFont : null,
  973. &layoutRect,
  974. stringFormat ? stringFormat.nativeFormat : null,
  975. brush ? brush.nativeBrush : null
  976. ));
  977. }
  978. Status
  979. DrawString(
  980. WCHAR *string,
  981. INT length,
  982. Font font,
  983. PointF origin,
  984. Brush brush
  985. )
  986. {
  987. RectF rect;
  988. rect.init(origin.X, origin.Y, 0.0f, 0.0f);
  989. return SetStatus(GdipDrawString(
  990. nativeGraphics,
  991. string,
  992. length,
  993. font ? font.nativeFont : null,
  994. &rect,
  995. null,
  996. brush ? brush.nativeBrush : null
  997. ));
  998. }
  999. Status
  1000. DrawString(
  1001. WCHAR *string,
  1002. INT length,
  1003. Font font,
  1004. PointF origin,
  1005. StringFormat stringFormat,
  1006. Brush brush
  1007. )
  1008. {
  1009. RectF rect;
  1010. rect.init(origin.X, origin.Y, 0.0f, 0.0f);
  1011. return SetStatus(GdipDrawString(
  1012. nativeGraphics,
  1013. string,
  1014. length,
  1015. font ? font.nativeFont : null,
  1016. &rect,
  1017. stringFormat ? stringFormat.nativeFormat : null,
  1018. brush ? brush.nativeBrush : null
  1019. ));
  1020. }
  1021. Status
  1022. MeasureString(
  1023. in WCHAR *string,
  1024. in INT length,
  1025. in Font font,
  1026. in RectF layoutRect,
  1027. in StringFormat stringFormat,
  1028. RectF *boundingBox,
  1029. INT *codepointsFitted = null,
  1030. INT *linesFilled = null
  1031. ) {
  1032. return SetStatus(GdipMeasureString(
  1033. nativeGraphics,
  1034. string,
  1035. length,
  1036. font ? font.nativeFont : null,
  1037. &layoutRect,
  1038. stringFormat ? stringFormat.nativeFormat : null,
  1039. boundingBox,
  1040. codepointsFitted,
  1041. linesFilled
  1042. ));
  1043. }
  1044. Status
  1045. MeasureString(
  1046. in WCHAR *string,
  1047. in INT length,
  1048. in Font font,
  1049. in SizeF *layoutRectSize,
  1050. in StringFormat stringFormat,
  1051. SizeF *size,
  1052. INT *codepointsFitted = null,
  1053. INT *linesFilled = null
  1054. )
  1055. {
  1056. RectF layoutRect;
  1057. layoutRect.init(0, 0, layoutRectSize.Width, layoutRectSize.Height);
  1058. RectF boundingBox;
  1059. Status status;
  1060. if (size is null) {
  1061. return SetStatus(Status.InvalidParameter);
  1062. }
  1063. status = SetStatus(GdipMeasureString(
  1064. nativeGraphics,
  1065. string,
  1066. length,
  1067. font ? font.nativeFont : null,
  1068. &layoutRect,
  1069. stringFormat ? stringFormat.nativeFormat : null,
  1070. size ? &boundingBox : null,
  1071. codepointsFitted,
  1072. linesFilled
  1073. ));
  1074. if (size && status == Status.Ok)
  1075. {
  1076. size.Width = boundingBox.Width;
  1077. size.Height = boundingBox.Height;
  1078. }
  1079. return status;
  1080. }
  1081. Status
  1082. MeasureString(
  1083. in WCHAR *string,
  1084. in INT length,
  1085. in Font font,
  1086. in PointF origin,
  1087. in StringFormat stringFormat,
  1088. RectF *boundingBox
  1089. )
  1090. {
  1091. RectF rect;
  1092. rect.init(origin.X, origin.Y, 0.0f, 0.0f);
  1093. return SetStatus(GdipMeasureString(
  1094. nativeGraphics,
  1095. string,
  1096. length,
  1097. font ? font.nativeFont : null,
  1098. &rect,
  1099. stringFormat ? stringFormat.nativeFormat : null,
  1100. boundingBox,
  1101. null,
  1102. null
  1103. ));
  1104. }
  1105. Status
  1106. MeasureString(
  1107. in WCHAR *string,
  1108. in INT length,
  1109. in Font font,
  1110. in RectF layoutRect,
  1111. RectF *boundingBox
  1112. )
  1113. {
  1114. return SetStatus(GdipMeasureString(
  1115. nativeGraphics,
  1116. string,
  1117. length,
  1118. font ? font.nativeFont : null,
  1119. &layoutRect,
  1120. null,
  1121. boundingBox,
  1122. null,
  1123. null
  1124. ));
  1125. }
  1126. Status
  1127. MeasureString(
  1128. in WCHAR *string,
  1129. in INT length,
  1130. in Font font,
  1131. in PointF origin,
  1132. RectF *boundingBox
  1133. )
  1134. {
  1135. RectF rect;
  1136. rect.init(origin.X, origin.Y, 0.0f, 0.0f);
  1137. return SetStatus(GdipMeasureString(
  1138. nativeGraphics,
  1139. string,
  1140. length,
  1141. font ? font.nativeFont : null,
  1142. &rect,
  1143. null,
  1144. boundingBox,
  1145. null,
  1146. null
  1147. ));
  1148. }
  1149. Status
  1150. MeasureCharacterRanges(
  1151. in WCHAR *string,
  1152. in INT length,
  1153. in Font font,
  1154. in RectF layoutRect,
  1155. in StringFormat stringFormat,
  1156. in INT regionCount,
  1157. Region *regions
  1158. )
  1159. {
  1160. if (!regions || regionCount <= 0)
  1161. {
  1162. return Status.InvalidParameter;
  1163. }
  1164. GpRegion*[] nativeRegions = new GpRegion* [regionCount];
  1165. if (!nativeRegions) {
  1166. return Status.OutOfMemory;
  1167. }
  1168. for (INT i = 0; i < regionCount; i++) {
  1169. nativeRegions[i] = regions[i].nativeRegion;
  1170. }
  1171. Status status = SetStatus(GdipMeasureCharacterRanges(
  1172. nativeGraphics,
  1173. string,
  1174. length,
  1175. font ? font.nativeFont : null,
  1176. layoutRect,
  1177. stringFormat ? stringFormat.nativeFormat : null,
  1178. regionCount,
  1179. nativeRegions.ptr
  1180. ));
  1181. return status;
  1182. }
  1183. Status DrawDriverString(
  1184. in UINT16 *text,
  1185. in INT length,
  1186. in Font font,
  1187. in Brush brush,
  1188. in PointF *positions,
  1189. in INT flags,
  1190. in Matrix matrix
  1191. )
  1192. {
  1193. return SetStatus(GdipDrawDriverString(
  1194. nativeGraphics,
  1195. text,
  1196. length,
  1197. font ? font.nativeFont : null,
  1198. brush ? brush.nativeBrush : null,
  1199. positions,
  1200. flags,
  1201. matrix ? matrix.nativeMatrix : null
  1202. ));
  1203. }
  1204. Status MeasureDriverString(
  1205. in UINT16 *text,
  1206. in INT length,
  1207. in Font font,
  1208. in PointF *positions,
  1209. in INT flags,
  1210. in Matrix matrix,
  1211. RectF *boundingBox
  1212. )
  1213. {
  1214. return SetStatus(GdipMeasureDriverString(
  1215. nativeGraphics,
  1216. text,
  1217. length,
  1218. font ? font.nativeFont : null,
  1219. positions,
  1220. flags,
  1221. matrix ? matrix.nativeMatrix : null,
  1222. boundingBox
  1223. ));
  1224. }
  1225. // Draw a cached bitmap on this graphics destination offset by
  1226. // x, y. Note this will fail with WrongState if the CachedBitmap
  1227. // native format differs from this Graphics.
  1228. Status DrawCachedBitmap(in CachedBitmap cb,
  1229. in INT x,
  1230. in INT y)
  1231. {
  1232. return SetStatus(GdipDrawCachedBitmap(
  1233. nativeGraphics,
  1234. cb.nativeCachedBitmap,
  1235. x, y
  1236. ));
  1237. }
  1238. Status DrawImage(in Image image,
  1239. in PointF point)
  1240. {
  1241. return DrawImage(image, point.X, point.Y);
  1242. }
  1243. Status DrawImage(in Image image,
  1244. in REAL x,
  1245. in REAL y)
  1246. {
  1247. return SetStatus(GdipDrawImage(nativeGraphics,
  1248. image ? image.nativeImage
  1249. : null,
  1250. x,
  1251. y));
  1252. }
  1253. Status DrawImage(in Image image, in RectF rect) {
  1254. return DrawImage(image, rect.X, rect.Y, rect.Width, rect.Height);
  1255. }
  1256. Status DrawImage(in Image image,
  1257. in REAL x,
  1258. in REAL y,
  1259. in REAL width,
  1260. in REAL height)
  1261. {
  1262. return SetStatus(GdipDrawImageRect(nativeGraphics,
  1263. image ? image.nativeImage
  1264. : null,
  1265. x,
  1266. y,
  1267. width,
  1268. height));
  1269. }
  1270. Status DrawImage(in Image image,
  1271. in Point point)
  1272. {
  1273. return DrawImage(image, point.X, point.Y);
  1274. }
  1275. Status DrawImage(in Image image,
  1276. in INT x,
  1277. in INT y)
  1278. {
  1279. return SetStatus(GdipDrawImageI(nativeGraphics,
  1280. image ? image.nativeImage
  1281. : null,
  1282. x,
  1283. y));
  1284. }
  1285. Status DrawImage(in Image image,
  1286. in Rect rect)
  1287. {
  1288. return DrawImage(image,
  1289. rect.X,
  1290. rect.Y,
  1291. rect.Width,
  1292. rect.Height);
  1293. }
  1294. Status DrawImage(in Image image,
  1295. in INT x,
  1296. in INT y,
  1297. in INT width,
  1298. in INT height) {
  1299. return SetStatus(GdipDrawImageRectI(nativeGraphics,
  1300. image ? image.nativeImage
  1301. : null,
  1302. x,
  1303. y,
  1304. width,
  1305. height));
  1306. }
  1307. Status DrawImage(in Image image,
  1308. in PointF* destPoints,
  1309. in INT count)
  1310. {
  1311. if (count != 3 && count != 4)
  1312. return SetStatus(Status.InvalidParameter);
  1313. return SetStatus(GdipDrawImagePoints(nativeGraphics,
  1314. image ? image.nativeImage
  1315. : null,
  1316. destPoints, count));
  1317. }
  1318. Status DrawImage(in Image image,
  1319. in Point* destPoints,
  1320. in INT count)
  1321. {
  1322. if (count != 3 && count != 4)
  1323. return SetStatus(Status.InvalidParameter);
  1324. return SetStatus(GdipDrawImagePointsI(nativeGraphics,
  1325. image ? image.nativeImage
  1326. : null,
  1327. destPoints,
  1328. count));
  1329. }
  1330. Status DrawImage(in Image image,
  1331. in REAL x,
  1332. in REAL y,
  1333. in REAL srcx,
  1334. in REAL srcy,
  1335. in REAL srcwidth,
  1336. in REAL srcheight,
  1337. in Unit srcUnit)
  1338. {
  1339. return SetStatus(GdipDrawImagePointRect(nativeGraphics,
  1340. image ? image.nativeImage
  1341. : null,
  1342. x, y,
  1343. srcx, srcy,
  1344. srcwidth, srcheight, srcUnit));
  1345. }
  1346. Status DrawImage(in Image image,
  1347. in RectF destRect,
  1348. in REAL srcx,
  1349. in REAL srcy,
  1350. in REAL srcwidth,
  1351. in REAL srcheight,
  1352. in Unit srcUnit,
  1353. in ImageAttributes imageAttributes = null,
  1354. in DrawImageAbort callback = null,
  1355. in VOID* callbackData = null)
  1356. {
  1357. return SetStatus(GdipDrawImageRectRect(nativeGraphics,
  1358. image ? image.nativeImage
  1359. : null,
  1360. destRect.X,
  1361. destRect.Y,
  1362. destRect.Width,
  1363. destRect.Height,
  1364. srcx, srcy,
  1365. srcwidth, srcheight,
  1366. srcUnit,
  1367. imageAttributes
  1368. ? imageAttributes.nativeImageAttr
  1369. : null,
  1370. callback,
  1371. callbackData));
  1372. }
  1373. Status DrawImage(in Image image,
  1374. in PointF* destPoints,
  1375. in INT count,
  1376. in REAL srcx,
  1377. in REAL srcy,
  1378. in REAL srcwidth,
  1379. in REAL srcheight,
  1380. in Unit srcUnit,
  1381. in ImageAttributes imageAttributes = null,
  1382. in DrawImageAbort callback = null,
  1383. in VOID* callbackData = null)
  1384. {
  1385. return SetStatus(GdipDrawImagePointsRect(nativeGraphics,
  1386. image ? image.nativeImage
  1387. : null,
  1388. destPoints, count,
  1389. srcx, srcy,
  1390. srcwidth,
  1391. srcheight,
  1392. srcUnit,
  1393. imageAttributes
  1394. ? imageAttributes.nativeImageAttr
  1395. : null,
  1396. callback,
  1397. callbackData));
  1398. }
  1399. Status DrawImage(in Image image,
  1400. in INT x,
  1401. in INT y,
  1402. in INT srcx,
  1403. in INT srcy,
  1404. in INT srcwidth,
  1405. in INT srcheight,
  1406. in Unit srcUnit)
  1407. {
  1408. return SetStatus(GdipDrawImagePointRectI(nativeGraphics,
  1409. image ? image.nativeImage
  1410. : null,
  1411. x,
  1412. y,
  1413. srcx,
  1414. srcy,
  1415. srcwidth,
  1416. srcheight,
  1417. srcUnit));
  1418. }
  1419. Status DrawImage(in Image image,
  1420. in Rect destRect,
  1421. in INT srcx,
  1422. in INT srcy,
  1423. in INT srcwidth,
  1424. in INT srcheight,
  1425. in Unit srcUnit,
  1426. in ImageAttributes imageAttributes = null,
  1427. in DrawImageAbort callback = null,
  1428. in VOID* callbackData = null)
  1429. {
  1430. return SetStatus(GdipDrawImageRectRectI(nativeGraphics,
  1431. image ? image.nativeImage
  1432. : null,
  1433. destRect.X,
  1434. destRect.Y,
  1435. destRect.Width,
  1436. destRect.Height,
  1437. srcx,
  1438. srcy,
  1439. srcwidth,
  1440. srcheight,
  1441. srcUnit,
  1442. imageAttributes
  1443. ? imageAttributes.nativeImageAttr
  1444. : null,
  1445. callback,
  1446. callbackData));
  1447. }
  1448. Status DrawImage(in Image image,
  1449. in Point* destPoints,
  1450. in INT count,
  1451. in INT srcx,
  1452. in INT srcy,
  1453. in INT srcwidth,
  1454. in INT srcheight,
  1455. in Unit srcUnit,
  1456. in ImageAttributes imageAttributes = null,
  1457. in DrawImageAbort callback = null,
  1458. in VOID* callbackData = null)
  1459. {
  1460. return SetStatus(GdipDrawImagePointsRectI(nativeGraphics,
  1461. image ? image.nativeImage
  1462. : null,
  1463. destPoints,
  1464. count,
  1465. srcx,
  1466. srcy,
  1467. srcwidth,
  1468. srcheight,
  1469. srcUnit,
  1470. imageAttributes
  1471. ? imageAttributes.nativeImageAttr
  1472. : null,
  1473. callback,
  1474. callbackData));
  1475. }
  1476. Status DrawImage(
  1477. in Image image,
  1478. in RectF destRect,
  1479. in RectF sourceRect,
  1480. in Unit srcUnit,
  1481. in ImageAttributes *imageAttributes = null
  1482. )
  1483. {
  1484. return SetStatus(GdipDrawImageRectRect(
  1485. nativeGraphics,
  1486. image.nativeImage,
  1487. destRect.X,
  1488. destRect.Y,
  1489. destRect.Width,
  1490. destRect.Height,
  1491. sourceRect.X,
  1492. sourceRect.Y,
  1493. sourceRect.Width,
  1494. sourceRect.Height,
  1495. srcUnit,
  1496. imageAttributes ? imageAttributes.nativeImageAttr : null,
  1497. null,
  1498. null
  1499. ));
  1500. }
  1501. version(GDIPLUS6) {
  1502. Status DrawImage(
  1503. in Image image,
  1504. in RectF *sourceRect,
  1505. in Matrix xForm,
  1506. in Effect effect,
  1507. in ImageAttributes imageAttributes,
  1508. in Unit srcUnit
  1509. )
  1510. {
  1511. return SetStatus(GdipDrawImageFX(
  1512. nativeGraphics,
  1513. image.nativeImage,
  1514. sourceRect,
  1515. xForm ? xForm.nativeMatrix : null,
  1516. effect ? effect.nativeEffect : null,
  1517. imageAttributes ? imageAttributes.nativeImageAttr : null,
  1518. srcUnit
  1519. ));
  1520. }
  1521. }
  1522. // The following methods are for playing an EMF+ to a graphics
  1523. // via the enumeration interface. Each record of the EMF+ is
  1524. // sent to the callback (along with the callbackData). Then
  1525. // the callback can invoke the Metafile::PlayRecord method
  1526. // to play the particular record.
  1527. Status
  1528. EnumerateMetafile(
  1529. in Metafile * metafile,
  1530. in PointF destPoint,
  1531. in EnumerateMetafileProc callback,
  1532. in VOID * callbackData = null,
  1533. in ImageAttributes * imageAttributes = null
  1534. )
  1535. {
  1536. return SetStatus(GdipEnumerateMetafileDestPoint(
  1537. nativeGraphics,
  1538. cast( GpMetafile *)(metafile ? metafile.nativeImage:null),
  1539. destPoint,
  1540. callback,
  1541. callbackData,
  1542. imageAttributes ? imageAttributes.nativeImageAttr : null));
  1543. }
  1544. Status
  1545. EnumerateMetafile(
  1546. in Metafile * metafile,
  1547. in Point destPoint,
  1548. in EnumerateMetafileProc callback,
  1549. in VOID * callbackData = null,
  1550. in ImageAttributes * imageAttributes = null
  1551. )
  1552. {
  1553. return SetStatus(GdipEnumerateMetafileDestPointI(
  1554. nativeGraphics,
  1555. cast( GpMetafile *)(metafile ? metafile.nativeImage:null),
  1556. destPoint,
  1557. callback,
  1558. callbackData,
  1559. imageAttributes ? imageAttributes.nativeImageAttr : null));
  1560. }
  1561. Status
  1562. EnumerateMetafile(
  1563. in Metafile * metafile,
  1564. in RectF destRect,
  1565. in EnumerateMetafileProc callback,
  1566. in VOID * callbackData = null,
  1567. in ImageAttributes * imageAttributes = null
  1568. )
  1569. {
  1570. return SetStatus(GdipEnumerateMetafileDestRect(
  1571. nativeGraphics,
  1572. cast(GpMetafile *)(metafile ? metafile.nativeImage:null),
  1573. destRect,
  1574. callback,
  1575. callbackData,
  1576. imageAttributes ? imageAttributes.nativeImageAttr : null));
  1577. }
  1578. Status
  1579. EnumerateMetafile(
  1580. in Metafile * metafile,
  1581. in Rect destRect,
  1582. in EnumerateMetafileProc callback,
  1583. in VOID * callbackData = null,
  1584. in ImageAttributes * imageAttributes = null
  1585. )
  1586. {
  1587. return SetStatus(GdipEnumerateMetafileDestRectI(
  1588. nativeGraphics,
  1589. cast(GpMetafile *)(metafile ? metafile.nativeImage:null),
  1590. destRect,
  1591. callback,
  1592. callbackData,
  1593. imageAttributes ? imageAttributes.nativeImageAttr : null));
  1594. }
  1595. Status
  1596. EnumerateMetafile(
  1597. in Metafile * metafile,
  1598. in PointF * destPoints,
  1599. in INT count,
  1600. in EnumerateMetafileProc callback,
  1601. in VOID * callbackData = null,
  1602. in ImageAttributes * imageAttributes = null
  1603. )
  1604. {
  1605. return SetStatus(GdipEnumerateMetafileDestPoints(
  1606. nativeGraphics,
  1607. cast(GpMetafile *)(metafile ? metafile.nativeImage:null),
  1608. destPoints,
  1609. count,
  1610. callback,
  1611. callbackData,
  1612. imageAttributes ? imageAttributes.nativeImageAttr : null));
  1613. }
  1614. Status
  1615. EnumerateMetafile(
  1616. in Metafile * metafile,
  1617. in Point * destPoints,
  1618. in INT count,
  1619. in EnumerateMetafileProc callback,
  1620. in VOID * callbackData = null,
  1621. in ImageAttributes * imageAttributes = null
  1622. )
  1623. {
  1624. return SetStatus(GdipEnumerateMetafileDestPointsI(
  1625. nativeGraphics,
  1626. cast(GpMetafile *)(metafile ? metafile.nativeImage:null),
  1627. destPoints,
  1628. count,
  1629. callback,
  1630. callbackData,
  1631. imageAttributes ? imageAttributes.nativeImageAttr : null));
  1632. }
  1633. Status
  1634. EnumerateMetafile(
  1635. in Metafile * metafile,
  1636. in PointF destPoint,
  1637. in RectF srcRect,
  1638. in Unit srcUnit,
  1639. in EnumerateMetafileProc callback,
  1640. in VOID * callbackData = null,
  1641. in ImageAttributes * imageAttributes = null
  1642. )
  1643. {
  1644. return SetStatus(GdipEnumerateMetafileSrcRectDestPoint(
  1645. nativeGraphics,
  1646. cast(GpMetafile *)(metafile ? metafile.nativeImage:null),
  1647. destPoint,
  1648. srcRect,
  1649. srcUnit,
  1650. callback,
  1651. callbackData,
  1652. imageAttributes ? imageAttributes.nativeImageAttr : null));
  1653. }
  1654. Status
  1655. EnumerateMetafile(
  1656. in Metafile * metafile,
  1657. in Point destPoint,
  1658. in Rect srcRect,
  1659. in Unit srcUnit,
  1660. in EnumerateMetafileProc callback,
  1661. in VOID * callbackData = null,
  1662. in ImageAttributes * imageAttributes = null
  1663. )
  1664. {
  1665. return SetStatus(GdipEnumerateMetafileSrcRectDestPointI(
  1666. nativeGraphics,
  1667. cast(GpMetafile *)(metafile ? metafile.nativeImage:null),
  1668. destPoint,
  1669. srcRect,
  1670. srcUnit,
  1671. callback,
  1672. callbackData,
  1673. imageAttributes ? imageAttributes.nativeImageAttr : null));
  1674. }
  1675. Status
  1676. EnumerateMetafile(
  1677. in Metafile * metafile,
  1678. in RectF destRect,
  1679. in RectF srcRect,
  1680. in Unit srcUnit,
  1681. in EnumerateMetafileProc callback,
  1682. in VOID * callbackData = null,
  1683. in ImageAttributes * imageAttributes = null
  1684. )
  1685. {
  1686. return SetStatus(GdipEnumerateMetafileSrcRectDestRect(
  1687. nativeGraphics,
  1688. cast(GpMetafile *)(metafile ? metafile.nativeImage:null),
  1689. destRect,
  1690. srcRect,
  1691. srcUnit,
  1692. callback,
  1693. callbackData,
  1694. imageAttributes ? imageAttributes.nativeImageAttr : null));
  1695. }
  1696. Status
  1697. EnumerateMetafile(
  1698. in Metafile metafile,
  1699. in Rect destRect,
  1700. in Rect srcRect,
  1701. in Unit srcUnit,
  1702. in EnumerateMetafileProc callback,
  1703. in VOID * callbackData = null,
  1704. in ImageAttributes imageAttributes = null
  1705. )
  1706. {
  1707. return SetStatus(GdipEnumerateMetafileSrcRectDestRectI(
  1708. nativeGraphics,
  1709. cast(GpMetafile *)(metafile ? metafile.nativeImage:null),
  1710. destRect,
  1711. srcRect,
  1712. srcUnit,
  1713. callback,
  1714. callbackData,
  1715. imageAttributes ? imageAttributes.nativeImageAttr : null));
  1716. }
  1717. Status
  1718. EnumerateMetafile(
  1719. in Metafile metafile,
  1720. in PointF * destPoints,
  1721. in INT count,
  1722. in RectF srcRect,
  1723. in Unit srcUnit,
  1724. in EnumerateMetafileProc callback,
  1725. in VOID * callbackData = null,
  1726. in ImageAttributes imageAttributes = null
  1727. )
  1728. {
  1729. return SetStatus(GdipEnumerateMetafileSrcRectDestPoints(
  1730. nativeGraphics,
  1731. cast(GpMetafile *)(metafile ? metafile.nativeImage:null),
  1732. destPoints,
  1733. count,
  1734. srcRect,
  1735. srcUnit,
  1736. callback,
  1737. callbackData,
  1738. imageAttributes ? imageAttributes.nativeImageAttr : null));
  1739. }
  1740. Status
  1741. EnumerateMetafile(
  1742. in Metafile metafile,
  1743. in Point[] destPoints,
  1744. in INT count,
  1745. in Rect srcRect,
  1746. in Unit srcUnit,
  1747. in EnumerateMetafileProc callback,
  1748. in VOID * callbackData = null,
  1749. in ImageAttributes imageAttributes = null
  1750. )
  1751. {
  1752. return SetStatus(GdipEnumerateMetafileSrcRectDestPointsI(
  1753. nativeGraphics,
  1754. cast(GpMetafile *)(metafile ? metafile.nativeImage:null),
  1755. destPoints.ptr,
  1756. count,
  1757. srcRect,
  1758. srcUnit,
  1759. callback,
  1760. callbackData,
  1761. imageAttributes ? imageAttributes.nativeImageAttr : null));
  1762. }
  1763. Status SetClip(in Graphics g,
  1764. in CombineMode combineMode = CombineMode.CombineModeReplace)
  1765. {
  1766. return SetStatus(GdipSetClipGraphics(nativeGraphics,
  1767. g.nativeGraphics,
  1768. combineMode));
  1769. }
  1770. Status SetClip(in RectF rect,
  1771. in CombineMode combineMode = CombineMode.CombineModeReplace)
  1772. {
  1773. return SetStatus(GdipSetClipRect(nativeGraphics,
  1774. rect.X, rect.Y,
  1775. rect.Width, rect.Height,
  1776. combineMode));
  1777. }
  1778. Status SetClip(in Rect rect,
  1779. in CombineMode combineMode = CombineMode.CombineModeReplace)
  1780. {
  1781. return SetStatus(GdipSetClipRectI(nativeGraphics,
  1782. rect.X, rect.Y,
  1783. rect.Width, rect.Height,
  1784. combineMode));
  1785. }
  1786. Status SetClip(in GraphicsPath path,
  1787. in CombineMode combineMode = CombineMode.CombineModeReplace)
  1788. {
  1789. return SetStatus(GdipSetClipPath(nativeGraphics,
  1790. path.nativePath,
  1791. combineMode));
  1792. }
  1793. Status SetClip(in Region region,
  1794. in CombineMode combineMode = CombineMode.CombineModeReplace)
  1795. {
  1796. return SetStatus(GdipSetClipRegion(nativeGraphics,
  1797. region.nativeRegion,
  1798. combineMode));
  1799. }
  1800. // This is different than the other SetClip methods because it assumes
  1801. // that the HRGN is already in device units, so it doesn't transform
  1802. // the coordinates in the HRGN.
  1803. Status SetClip(in HRGN hRgn,
  1804. in CombineMode combineMode = CombineMode.CombineModeReplace)
  1805. {
  1806. return SetStatus(GdipSetClipHrgn(nativeGraphics, hRgn,
  1807. combineMode));
  1808. }
  1809. Status IntersectClip(in RectF rect)
  1810. {
  1811. return SetStatus(GdipSetClipRect(nativeGraphics,
  1812. rect.X, rect.Y,
  1813. rect.Width, rect.Height,
  1814. CombineMode.CombineModeIntersect));
  1815. }
  1816. Status IntersectClip(in Rect rect)
  1817. {
  1818. return SetStatus(GdipSetClipRectI(nativeGraphics,
  1819. rect.X, rect.Y,
  1820. rect.Width, rect.Height,
  1821. CombineMode.CombineModeIntersect));
  1822. }
  1823. Status IntersectClip(in Region* region)
  1824. {
  1825. return SetStatus(GdipSetClipRegion(nativeGraphics,
  1826. region.nativeRegion,
  1827. CombineMode.CombineModeIntersect));
  1828. }
  1829. Status ExcludeClip(in RectF rect)
  1830. {
  1831. return SetStatus(GdipSetClipRect(nativeGraphics,
  1832. rect.X, rect.Y,
  1833. rect.Width, rect.Height,
  1834. CombineMode.CombineModeExclude));
  1835. }
  1836. Status ExcludeClip(in Rect rect)
  1837. {
  1838. return SetStatus(GdipSetClipRectI(nativeGraphics,
  1839. rect.X, rect.Y,
  1840. rect.Width, rect.Height,
  1841. CombineMode.CombineModeExclude));
  1842. }
  1843. Status ExcludeClip(in Region* region)
  1844. {
  1845. return SetStatus(GdipSetClipRegion(nativeGraphics,
  1846. region.nativeRegion,
  1847. CombineMode.CombineModeExclude));
  1848. }
  1849. Status ResetClip()
  1850. {
  1851. return SetStatus(GdipResetClip(nativeGraphics));
  1852. }
  1853. Status TranslateClip(in REAL dx,
  1854. in REAL dy)
  1855. {
  1856. return SetStatus(GdipTranslateClip(nativeGraphics, dx, dy));
  1857. }
  1858. Status TranslateClip(in INT dx,
  1859. in INT dy)
  1860. {
  1861. return SetStatus(GdipTranslateClipI(nativeGraphics,
  1862. dx, dy));
  1863. }
  1864. Status GetClip(Region* region)
  1865. {
  1866. return SetStatus(GdipGetClip(nativeGraphics,
  1867. region.nativeRegion));
  1868. }
  1869. Status GetClipBounds(RectF* rect)
  1870. {
  1871. return SetStatus(GdipGetClipBounds(nativeGraphics, rect));
  1872. }
  1873. Status GetClipBounds(Rect* rect)
  1874. {
  1875. return SetStatus(GdipGetClipBoundsI(nativeGraphics, rect));
  1876. }
  1877. BOOL IsClipEmpty()
  1878. {
  1879. BOOL booln = FALSE;
  1880. SetStatus(GdipIsClipEmpty(nativeGraphics, &booln));
  1881. return booln;
  1882. }
  1883. Status GetVisibleClipBounds(RectF *rect)
  1884. {
  1885. return SetStatus(GdipGetVisibleClipBounds(nativeGraphics,
  1886. rect));
  1887. }
  1888. Status GetVisibleClipBounds(Rect *rect)
  1889. {
  1890. return SetStatus(GdipGetVisibleClipBoundsI(nativeGraphics,
  1891. rect));
  1892. }
  1893. BOOL IsVisibleClipEmpty()
  1894. {
  1895. BOOL booln = FALSE;
  1896. SetStatus(GdipIsVisibleClipEmpty(nativeGraphics, &booln));
  1897. return booln;
  1898. }
  1899. BOOL IsVisible(in INT x,
  1900. in INT y)
  1901. {
  1902. return IsVisible(Point(x,y));
  1903. }
  1904. BOOL IsVisible(in Point point)
  1905. {
  1906. BOOL booln = FALSE;
  1907. SetStatus(GdipIsVisiblePointI(nativeGraphics,
  1908. point.X,
  1909. point.Y,
  1910. &booln));
  1911. return booln;
  1912. }
  1913. BOOL IsVisible(in INT x,
  1914. in INT y,
  1915. in INT width,
  1916. in INT height)
  1917. {
  1918. return IsVisible(Rect(x, y, width, height));
  1919. }
  1920. BOOL IsVisible(in Rect rect)
  1921. {
  1922. BOOL booln = TRUE;
  1923. SetStatus(GdipIsVisibleRectI(nativeGraphics,
  1924. rect.X,
  1925. rect.Y,
  1926. rect.Width,
  1927. rect.Height,
  1928. &booln));
  1929. return booln;
  1930. }
  1931. BOOL IsVisible(in REAL x,
  1932. in REAL y)
  1933. {
  1934. return IsVisible(PointF(x, y));
  1935. }
  1936. BOOL IsVisible(in PointF point)
  1937. {
  1938. BOOL booln = FALSE;
  1939. SetStatus(GdipIsVisiblePoint(nativeGraphics,
  1940. point.X,
  1941. point.Y,
  1942. &booln));
  1943. return booln;
  1944. }
  1945. BOOL IsVisible(in REAL x,
  1946. in REAL y,
  1947. in REAL width,
  1948. in REAL height) {
  1949. RectF rect;
  1950. rect.init(x, y, width, height);
  1951. return IsVisible(rect);
  1952. }
  1953. BOOL IsVisible(in RectF rect) {
  1954. BOOL booln = TRUE;
  1955. SetStatus(GdipIsVisibleRect(nativeGraphics,
  1956. rect.X,
  1957. rect.Y,
  1958. rect.Width,
  1959. rect.Height,
  1960. &booln));
  1961. return booln;
  1962. }
  1963. GraphicsState Save()
  1964. {
  1965. GraphicsState gstate;
  1966. SetStatus(GdipSaveGraphics(nativeGraphics, &gstate));
  1967. return gstate;
  1968. }
  1969. Status Restore(in GraphicsState gstate)
  1970. {
  1971. return SetStatus(GdipRestoreGraphics(nativeGraphics,
  1972. gstate));
  1973. }
  1974. GraphicsContainer BeginContainer(in RectF dstrect,
  1975. in RectF srcrect,
  1976. in Unit unit)
  1977. {
  1978. GraphicsContainer state;
  1979. SetStatus(GdipBeginContainer(nativeGraphics, &dstrect,
  1980. &srcrect, unit, &state));
  1981. return state;
  1982. }
  1983. GraphicsContainer BeginContainer(in Rect dstrect,
  1984. in Rect srcrect,
  1985. in Unit unit)
  1986. {
  1987. GraphicsContainer state;
  1988. SetStatus(GdipBeginContainerI(nativeGraphics, &dstrect,
  1989. &srcrect, unit, &state));
  1990. return state;
  1991. }
  1992. GraphicsContainer BeginContainer()
  1993. {
  1994. GraphicsContainer state;
  1995. SetStatus(GdipBeginContainer2(nativeGraphics, &state));
  1996. return state;
  1997. }
  1998. Status EndContainer(in GraphicsContainer state)
  1999. {
  2000. return SetStatus(GdipEndContainer(nativeGraphics, state));
  2001. }
  2002. // Only valid when recording metafiles.
  2003. Status AddMetafileComment(in BYTE * data,
  2004. in UINT sizeData)
  2005. {
  2006. return SetStatus(GdipComment(nativeGraphics, sizeData, data));
  2007. }
  2008. static HPALETTE GetHalftonePalette()
  2009. {
  2010. return GdipCreateHalftonePalette();
  2011. }
  2012. Status GetLastStatus()
  2013. {
  2014. Status lastStatus = lastResult;
  2015. lastResult = Status.Ok;
  2016. return lastStatus;
  2017. }
  2018. protected:
  2019. package this(GpGraphics* graphics) {
  2020. lastResult = Status.Ok;
  2021. SetNativeGraphics(graphics);
  2022. }
  2023. VOID SetNativeGraphics(GpGraphics *graphics)
  2024. {
  2025. this.nativeGraphics = graphics;
  2026. }
  2027. Status SetStatus(Status status)
  2028. {
  2029. if (status != Status.Ok)
  2030. return (lastResult = status);
  2031. else
  2032. return status;
  2033. }
  2034. GpGraphics* GetNativeGraphics()
  2035. {
  2036. return this.nativeGraphics;
  2037. }
  2038. GpPen* GetNativePen(Pen pen) {
  2039. return pen.nativePen;
  2040. }
  2041. protected:
  2042. package GpGraphics* nativeGraphics;
  2043. package Status lastResult;
  2044. }