Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2175 lines
54 KiB

  1. /**************************************************************************\
  2. *
  3. * Copyright (c) 1998 Microsoft Corporation
  4. *
  5. * Module Name:
  6. *
  7. * GDI+ private enumsruntime
  8. *
  9. * Abstract:
  10. *
  11. * Enums moved from sdkinc because we don't want them public.
  12. *
  13. * Revision History:
  14. *
  15. * 2/15/2k ericvan
  16. * Created it.
  17. *
  18. \**************************************************************************/
  19. #include "..\..\sdkinc\gdiplusenums.h"
  20. enum EnumerationType
  21. {
  22. LinesAndBeziers = 0,
  23. Flattened = 1,
  24. Widened = 2
  25. };
  26. const UINT MAX_TEXT_CONTRAST_VALUE = 12;
  27. const UINT DEFAULT_TEXT_CONTRAST = 4;
  28. // UnitWorld and UnitDisplay are NOT valid as a srcUnit
  29. inline BOOL
  30. SrcUnitIsValid(
  31. Unit unit
  32. )
  33. {
  34. return ((unit >= UnitPixel) && (unit <= UnitMillimeter));
  35. }
  36. inline BOOL
  37. MetafileFrameUnitIsValid(
  38. MetafileFrameUnit frameUnit
  39. )
  40. {
  41. return ((frameUnit >= MetafileFrameUnitPixel) && (frameUnit <= MetafileFrameUnitGdi));
  42. }
  43. inline BOOL
  44. WrapModeIsValid(
  45. WrapMode mode
  46. )
  47. {
  48. return ((mode >= WrapModeTile) && (mode <= WrapModeClamp));
  49. }
  50. inline BOOL
  51. CombineModeIsValid(
  52. CombineMode combineMode
  53. )
  54. {
  55. return ((combineMode >= CombineModeReplace) &&
  56. (combineMode <= CombineModeComplement));
  57. }
  58. inline BOOL
  59. MatrixOrderIsValid(
  60. MatrixOrder order
  61. )
  62. {
  63. return ((order == MatrixOrderPrepend) || (order == MatrixOrderAppend));
  64. }
  65. inline BOOL
  66. EmfTypeIsValid(
  67. EmfType type
  68. )
  69. {
  70. return ((type >= EmfTypeEmfOnly) && (type <= EmfTypeEmfPlusDual));
  71. }
  72. inline BOOL
  73. ColorAdjustTypeIsValid(
  74. ColorAdjustType type
  75. )
  76. {
  77. return ((type >= ColorAdjustTypeDefault) && (type < ColorAdjustTypeCount));
  78. }
  79. #if 0
  80. GpStatus
  81. WINGDIPAPI
  82. GdipCreateRectGradient(
  83. REAL x,
  84. REAL y,
  85. REAL width,
  86. REAL height,
  87. ARGB* colors,
  88. GpWrapMode wrapMode,
  89. GpRectGradient **rectgrad
  90. )
  91. {
  92. CheckParameter(rectgrad && colors);
  93. GpRectF rect(x, y, width, height);
  94. GpColor gpcolor[4];
  95. gpcolor[0].SetColor(colors[0]);
  96. gpcolor[1].SetColor(colors[1]);
  97. gpcolor[2].SetColor(colors[2]);
  98. gpcolor[3].SetColor(colors[3]);
  99. *rectgrad = new GpRectGradient(rect, gpcolor, wrapMode);
  100. if (CheckValid(*rectgrad))
  101. return Ok;
  102. else
  103. return OutOfMemory;
  104. }
  105. GpStatus
  106. WINGDIPAPI
  107. GdipCreateRectGradientI(
  108. INT x,
  109. INT y,
  110. INT width,
  111. INT height,
  112. ARGB* colors,
  113. GpWrapMode wrapMode,
  114. GpRectGradient **rectgrad
  115. )
  116. {
  117. return GdipCreateRectGradient(TOREAL(x),
  118. TOREAL(y),
  119. TOREAL(width),
  120. TOREAL(height),
  121. colors,
  122. wrapMode,
  123. rectgrad);
  124. }
  125. GpStatus
  126. WINGDIPAPI
  127. GdipGetRectGradientColor(
  128. GpRectGradient *brush,
  129. ARGB* colors
  130. )
  131. {
  132. CheckParameter(colors);
  133. CheckParameterValid(brush);
  134. CheckObjectBusy(brush);
  135. GpColor gpcolor[4];
  136. brush->GetColors(gpcolor);
  137. colors[0] = gpcolor[0].GetValue();
  138. colors[1] = gpcolor[1].GetValue();
  139. colors[2] = gpcolor[2].GetValue();
  140. colors[3] = gpcolor[3].GetValue();
  141. return Ok;
  142. }
  143. GpStatus
  144. WINGDIPAPI
  145. GdipSetRectGradientColor(
  146. GpRectGradient *brush,
  147. ARGB* colors
  148. )
  149. {
  150. CheckParameter(colors);
  151. CheckParameterValid(brush);
  152. CheckObjectBusy(brush);
  153. GpColor gpcolor[4];
  154. gpcolor[0].SetColor(colors[0]);
  155. gpcolor[1].SetColor(colors[1]);
  156. gpcolor[2].SetColor(colors[2]);
  157. gpcolor[3].SetColor(colors[3]);
  158. brush->SetColors(gpcolor);
  159. return Ok;
  160. }
  161. GpStatus
  162. WINGDIPAPI
  163. GdipGetRectGradientRect(
  164. GpRectGradient *brush,
  165. GpRectF *rect
  166. )
  167. {
  168. CheckParameter(rect);
  169. CheckParameterValid(brush);
  170. CheckObjectBusy(brush);
  171. brush->GetRect(*rect);
  172. return Ok;
  173. }
  174. GpStatus
  175. WINGDIPAPI
  176. GdipGetRectGradientRectI(
  177. GpRectGradient *brush,
  178. GpRect *rect
  179. )
  180. {
  181. CheckParameter(rect);
  182. GpRectF rectF;
  183. GpStatus status = GdipGetRectGradientRect(brush, &rectF);
  184. if (status == Ok)
  185. {
  186. FPUStateSaver fpuState;
  187. rect->X = GpRound(rectF.X);
  188. rect->Y = GpRound(rectF.Y);
  189. rect->Width = GpRound(rectF.Width);
  190. rect->Height = GpRound(rectF.Height);
  191. }
  192. return status;
  193. }
  194. GpStatus
  195. WINGDIPAPI
  196. GdipGetRectGradientBlendCountH(
  197. GpRectGradient *brush,
  198. INT *count
  199. )
  200. {
  201. CheckParameter(count);
  202. CheckParameterValid(brush);
  203. CheckObjectBusy(brush);
  204. *count = brush->GetHorizontalBlendCount();
  205. return Ok;
  206. }
  207. GpStatus
  208. WINGDIPAPI
  209. GdipGetRectGradientBlendH(
  210. GpRectGradient *brush,
  211. REAL *blend,
  212. REAL *positions,
  213. INT count
  214. )
  215. {
  216. CheckParameter(blend);
  217. CheckParameter(positions);
  218. CheckParameterValid(brush);
  219. CheckObjectBusy(brush);
  220. return brush->GetHorizontalBlend(blend, positions, count);
  221. }
  222. GpStatus
  223. WINGDIPAPI
  224. GdipSetRectGradientBlendH(
  225. GpRectGradient *brush,
  226. REAL *blend,
  227. REAL *positions,
  228. INT count
  229. )
  230. {
  231. CheckParameter(blend);
  232. CheckParameter(positions);
  233. CheckParameterValid(brush);
  234. CheckObjectBusy(brush);
  235. return brush->SetHorizontalBlend(blend, positions, count);
  236. }
  237. GpStatus
  238. WINGDIPAPI
  239. GdipGetRectGradientBlendCountV(
  240. GpRectGradient *brush,
  241. INT *count
  242. )
  243. {
  244. CheckParameter(count > 0);
  245. CheckParameterValid(brush);
  246. CheckObjectBusy(brush);
  247. *count = brush->GetVerticalBlendCount();
  248. return Ok;
  249. }
  250. GpStatus
  251. WINGDIPAPI
  252. GdipGetRectGradientBlendV(
  253. GpRectGradient *brush,
  254. REAL *blend,
  255. REAL *positions,
  256. INT count
  257. )
  258. {
  259. CheckParameter(blend);
  260. CheckParameter(positions);
  261. CheckParameterValid(brush);
  262. CheckObjectBusy(brush);
  263. return brush->GetVerticalBlend(blend, positions, count);
  264. }
  265. GpStatus
  266. WINGDIPAPI
  267. GdipSetRectGradientBlendV(
  268. GpRectGradient *brush,
  269. REAL *blend,
  270. REAL *positions,
  271. INT count
  272. )
  273. {
  274. CheckParameter(blend);
  275. CheckParameter(positions);
  276. CheckParameterValid(brush);
  277. CheckObjectBusy(brush);
  278. return brush->SetVerticalBlend(blend, positions, count);
  279. }
  280. GpStatus
  281. WINGDIPAPI
  282. GdipSetRectGradientWrapMode(
  283. GpRectGradient *brush,
  284. GpWrapMode wrapmode
  285. )
  286. {
  287. CheckParameterValid(brush);
  288. CheckObjectBusy(brush);
  289. brush->SetWrapMode(wrapmode);
  290. return Ok;
  291. }
  292. GpStatus
  293. WINGDIPAPI
  294. GdipGetRectGradientWrapMode(
  295. GpRectGradient *brush,
  296. GpWrapMode *wrapmode
  297. )
  298. {
  299. CheckParameter(wrapmode);
  300. CheckParameterValid(brush);
  301. CheckObjectBusy(brush);
  302. *wrapmode = (GpWrapMode)brush->GetWrapMode();
  303. return Ok;
  304. }
  305. GpStatus
  306. WINGDIPAPI
  307. GdipSetRectGradientTransform(
  308. GpRectGradient *brush,
  309. GpMatrix *matrix
  310. )
  311. {
  312. CheckParameterValid(brush);
  313. CheckObjectBusy(brush);
  314. CheckParameterValid(matrix);
  315. CheckObjectBusy(matrix);
  316. brush->SetTransform(*matrix);
  317. return Ok;
  318. }
  319. GpStatus
  320. WINGDIPAPI
  321. GdipGetRectGradientTransform(
  322. GpRectGradient *brush,
  323. GpMatrix *matrix
  324. )
  325. {
  326. CheckParameterValid(brush);
  327. CheckObjectBusy(brush);
  328. CheckParameterValid(matrix);
  329. CheckObjectBusy(matrix);
  330. brush->GetTransform(matrix);
  331. return Ok;
  332. }
  333. GpStatus
  334. WINGDIPAPI
  335. GdipCreateRadialBrush(
  336. GpRectF *gprect,
  337. ARGB centercol,
  338. ARGB boundarycol,
  339. GpWrapMode wrapmode,
  340. GpRadialGradient **radgrad
  341. )
  342. {
  343. CheckParameter(radgrad && gprect);
  344. GpColor center(centercol);
  345. GpColor boundary(boundarycol);
  346. *radgrad = new GpRadialGradient(*gprect, center, boundary, wrapmode);
  347. if (CheckValid(*radgrad))
  348. return Ok;
  349. else
  350. return OutOfMemory;
  351. }
  352. GpStatus
  353. WINGDIPAPI
  354. GdipCreateRadialBrushI(
  355. GpRect *gprect,
  356. ARGB centercol,
  357. ARGB boundarycol,
  358. GpWrapMode wrapmode,
  359. GpRadialGradient **radgrad
  360. )
  361. {
  362. CheckParameter(gprect);
  363. GpRectF rectF(TOREAL(gprect->X),
  364. TOREAL(gprect->Y),
  365. TOREAL(gprect->Width),
  366. TOREAL(gprect->Height));
  367. return GdipCreateRadialBrush(&rectF,
  368. centercol,
  369. boundarycol,
  370. wrapmode,
  371. radgrad);
  372. }
  373. GpStatus
  374. WINGDIPAPI
  375. GdipSetRadialCenterColor(
  376. GpRadialGradient *brush,
  377. ARGB argb
  378. )
  379. {
  380. CheckParameterValid(brush);
  381. CheckObjectBusy(brush);
  382. GpColor center(argb);
  383. brush->SetCenterColor(center);
  384. return Ok;
  385. }
  386. GpStatus
  387. WINGDIPAPI
  388. GdipSetRadialBoundaryColor(
  389. GpRadialGradient *brush,
  390. ARGB argb
  391. )
  392. {
  393. CheckParameterValid(brush);
  394. CheckObjectBusy(brush);
  395. GpColor boundary(argb);
  396. brush->SetBoundaryColor(boundary);
  397. return Ok;
  398. }
  399. GpStatus
  400. WINGDIPAPI
  401. GdipGetRadialCenterColor(
  402. GpRadialGradient *brush,
  403. ARGB *argb
  404. )
  405. {
  406. CheckParameter(argb);
  407. CheckParameterValid(brush);
  408. CheckObjectBusy(brush);
  409. GpColor center = brush->GetCenterColor();
  410. *argb = center.GetValue();
  411. return Ok;
  412. }
  413. GpStatus
  414. WINGDIPAPI
  415. GdipGetRadialBoundaryColor(
  416. GpRadialGradient *brush,
  417. ARGB *argb
  418. )
  419. {
  420. CheckParameter(argb);
  421. CheckParameterValid(brush);
  422. CheckObjectBusy(brush);
  423. GpColor boundary = brush->GetBoundaryColor();
  424. *argb = boundary.GetValue();
  425. return Ok;
  426. }
  427. GpStatus
  428. WINGDIPAPI
  429. GdipGetRadialRect(
  430. GpRadialGradient *brush,
  431. GpRectF *rect
  432. )
  433. {
  434. CheckParameter(rect);
  435. CheckParameterValid(brush);
  436. CheckObjectBusy(brush);
  437. brush->GetRect(*rect);
  438. return Ok;
  439. }
  440. GpStatus
  441. WINGDIPAPI
  442. GdipGetRadialRectI(
  443. GpRadialGradient *brush,
  444. GpRect *rect
  445. )
  446. {
  447. CheckParameter(rect);
  448. GpRectF rectF;
  449. GpStatus status = GdipGetRadialRect(brush, &rectF);
  450. if (status == Ok)
  451. {
  452. FPUStateSaver fpuState;
  453. rect->X = GpRound(rectF.X);
  454. rect->Y = GpRound(rectF.Y);
  455. rect->Width = GpRound(rectF.Width);
  456. rect->Height = GpRound(rectF.Height);
  457. }
  458. return status;
  459. }
  460. GpStatus
  461. WINGDIPAPI
  462. GdipGetRadialBlendCount(
  463. GpRadialGradient *brush,
  464. INT *count
  465. )
  466. {
  467. CheckParameter(count);
  468. CheckParameterValid(brush);
  469. CheckObjectBusy(brush);
  470. *count = brush->GetBlendCount();
  471. return Ok;
  472. }
  473. GpStatus
  474. WINGDIPAPI
  475. GdipGetRadialBlend(
  476. GpRadialGradient *brush,
  477. REAL *blend,
  478. REAL *positions,
  479. INT count
  480. )
  481. {
  482. CheckParameter(blend);
  483. CheckParameter(positions);
  484. CheckParameterValid(brush);
  485. CheckObjectBusy(brush);
  486. return brush->GetBlend(blend, positions, count);
  487. }
  488. GpStatus
  489. WINGDIPAPI
  490. GdipSetRadialBlend(
  491. GpRadialGradient *brush,
  492. REAL *blend,
  493. REAL *positions,
  494. INT count
  495. )
  496. {
  497. CheckParameter(blend);
  498. CheckParameter(positions);
  499. CheckParameterValid(brush);
  500. CheckObjectBusy(brush);
  501. return brush->SetBlend(blend, positions, count);
  502. }
  503. GpStatus
  504. WINGDIPAPI
  505. GdipGetRadialPresetBlendCount(
  506. GpRadialGradient *brush,
  507. INT *count
  508. )
  509. {
  510. CheckParameter(count);
  511. CheckParameterValid(brush);
  512. CheckObjectBusy(brush);
  513. *count = brush->GetPresetBlendCount();
  514. return Ok;
  515. }
  516. GpStatus
  517. WINGDIPAPI
  518. GdipGetRadialPresetBlend(
  519. GpRadialGradient *brush,
  520. ARGB *blend,
  521. REAL *blendPositions,
  522. INT count
  523. )
  524. {
  525. CheckParameter(blend);
  526. CheckParameterValid(brush);
  527. CheckObjectBusy(brush);
  528. StackBuffer buffer;
  529. GpColor* gpcolors = (GpColor*) buffer.GetBuffer(count*sizeof(GpColor));
  530. if(!gpcolors) return OutOfMemory;
  531. if (gpcolors)
  532. {
  533. GpStatus status = brush->GetPresetBlend(gpcolors, blendPositions, count);
  534. for(INT i = 0; i < count; i++)
  535. {
  536. blend[i] = gpcolors[i].GetValue();
  537. }
  538. return status;
  539. }
  540. else
  541. return OutOfMemory;
  542. }
  543. GpStatus
  544. WINGDIPAPI
  545. GdipSetRadialPresetBlend(
  546. GpRadialGradient *brush,
  547. ARGB *blend,
  548. REAL* blendPositions, INT count )
  549. {
  550. CheckParameter(blend);
  551. CheckParameterValid(brush);
  552. CheckObjectBusy(brush);
  553. StackBuffer buffer;
  554. GpColor* gpcolors = (GpColor*) buffer.GetBuffer(count*sizeof(GpColor));
  555. if(!gpcolors) return OutOfMemory;
  556. if (gpcolors)
  557. {
  558. for(INT i = 0; i < count; i++)
  559. {
  560. gpcolors[i].SetColor(blend[i]);
  561. }
  562. GpStatus status = brush->SetPresetBlend(gpcolors, blendPositions, count);
  563. return status;
  564. }
  565. else
  566. return OutOfMemory;
  567. }
  568. GpStatus
  569. WINGDIPAPI
  570. GdipSetRadialSigmaBlend(
  571. GpRadialGradient *brush,
  572. REAL focus,
  573. REAL scale
  574. )
  575. {
  576. CheckParameterValid(brush);
  577. CheckObjectBusy(brush);
  578. return brush->SetSigmaBlend(focus, scale);
  579. }
  580. GpStatus
  581. WINGDIPAPI
  582. GdipSetRadialLinearBlend(
  583. GpRadialGradient *brush,
  584. REAL focus,
  585. REAL scale
  586. )
  587. {
  588. CheckParameterValid(brush);
  589. CheckObjectBusy(brush);
  590. return brush->SetLinearBlend(focus, scale);
  591. }
  592. GpStatus
  593. WINGDIPAPI
  594. GdipSetRadialWrapMode(
  595. GpRadialGradient *brush,
  596. GpWrapMode wrapmode
  597. )
  598. {
  599. CheckParameterValid(brush);
  600. CheckObjectBusy(brush);
  601. brush->SetWrapMode(wrapmode);
  602. return Ok;
  603. }
  604. GpStatus
  605. WINGDIPAPI
  606. GdipGetRadialWrapMode(
  607. GpRadialGradient *brush,
  608. GpWrapMode *wrapmode
  609. )
  610. {
  611. CheckParameter(wrapmode);
  612. CheckParameterValid(brush);
  613. CheckObjectBusy(brush);
  614. *wrapmode = (GpWrapMode)brush->GetWrapMode();
  615. return Ok;
  616. }
  617. GpStatus
  618. WINGDIPAPI
  619. GdipSetRadialTransform(
  620. GpRadialGradient *brush,
  621. GpMatrix *matrix
  622. )
  623. {
  624. CheckParameterValid(brush);
  625. CheckObjectBusy(brush);
  626. CheckParameterValid(matrix);
  627. CheckObjectBusy(matrix);
  628. brush->SetTransform(*matrix);
  629. return Ok;
  630. }
  631. GpStatus
  632. WINGDIPAPI
  633. GdipGetRadialTransform(
  634. GpRadialGradient *brush,
  635. GpMatrix *matrix
  636. )
  637. {
  638. CheckParameterValid(brush);
  639. CheckObjectBusy(brush);
  640. CheckParameterValid(matrix);
  641. CheckObjectBusy(matrix);
  642. brush->GetTransform(matrix);
  643. return Ok;
  644. }
  645. GpStatus
  646. WINGDIPAPI
  647. GdipCreateTriangleGradient(
  648. GpPointF* points,
  649. ARGB* colors,
  650. GpWrapMode wrapMode,
  651. GpTriangleGradient **trigrad
  652. )
  653. {
  654. CheckParameter(points && trigrad && colors);
  655. GpColor gpcolor[3];
  656. gpcolor[0].SetColor(colors[0]);
  657. gpcolor[1].SetColor(colors[1]);
  658. gpcolor[2].SetColor(colors[2]);
  659. *trigrad = new GpTriangleGradient(points, gpcolor, wrapMode);
  660. if (CheckValid(*trigrad))
  661. return Ok;
  662. else
  663. return OutOfMemory;
  664. }
  665. GpStatus
  666. WINGDIPAPI
  667. GdipCreateTriangleGradientI(
  668. GpPoint* points,
  669. ARGB* colors,
  670. GpWrapMode wrapMode,
  671. GpTriangleGradient **trigrad
  672. )
  673. {
  674. CheckParameter(points);
  675. GpPointF pointsF[3];
  676. pointsF[0].X = TOREAL(points[0].X);
  677. pointsF[0].Y = TOREAL(points[0].Y);
  678. pointsF[1].X = TOREAL(points[1].X);
  679. pointsF[1].Y = TOREAL(points[1].Y);
  680. pointsF[2].X = TOREAL(points[2].X);
  681. pointsF[2].Y = TOREAL(points[2].Y);
  682. return GdipCreateTriangleGradient(&pointsF[0], colors, wrapMode, trigrad);
  683. }
  684. GpStatus
  685. GdipGetTriangleGradientColor(
  686. GpTriangleGradient *brush,
  687. ARGB* colors
  688. )
  689. {
  690. CheckParameter(colors);
  691. CheckParameterValid(brush);
  692. CheckObjectBusy(brush);
  693. GpColor gpcolor[3];
  694. brush->GetColors(gpcolor);
  695. colors[0] = gpcolor[0].GetValue();
  696. colors[1] = gpcolor[1].GetValue();
  697. colors[2] = gpcolor[2].GetValue();
  698. return Ok;
  699. }
  700. GpStatus
  701. GdipSetTriangleGradientColor(
  702. GpTriangleGradient *brush,
  703. ARGB* colors
  704. )
  705. {
  706. CheckParameter(colors);
  707. CheckParameterValid(brush);
  708. CheckObjectBusy(brush);
  709. GpColor gpcolor[3];
  710. gpcolor[0].SetColor(colors[0]);
  711. gpcolor[1].SetColor(colors[1]);
  712. gpcolor[2].SetColor(colors[2]);
  713. brush->SetColors(gpcolor);
  714. return Ok;
  715. }
  716. GpStatus
  717. GdipGetTriangleGradientTriangle(
  718. GpTriangleGradient *brush,
  719. GpPointF* points
  720. )
  721. {
  722. CheckParameter(points);
  723. CheckParameterValid(brush);
  724. CheckObjectBusy(brush);
  725. brush->GetTriangle(points);
  726. return Ok;
  727. }
  728. GpStatus
  729. GdipGetTriangleGradientTriangleI(
  730. GpTriangleGradient *brush,
  731. GpPoint* points
  732. )
  733. {
  734. CheckParameter(points);
  735. GpPointF pointsF[3];
  736. GpStatus status = GdipGetTriangleGradientTriangle(brush, &pointsF[0]);
  737. if (status == Ok)
  738. {
  739. FPUStateSaver fpuState;
  740. points[0].X = GpRound(pointsF[0].X);
  741. points[0].Y = GpRound(pointsF[0].Y);
  742. points[1].X = GpRound(pointsF[1].X);
  743. points[1].Y = GpRound(pointsF[1].Y);
  744. points[2].X = GpRound(pointsF[2].X);
  745. points[2].Y = GpRound(pointsF[2].Y);
  746. }
  747. return status;
  748. }
  749. GpStatus
  750. GdipSetTriangleGradientTriangle(
  751. GpTriangleGradient *brush,
  752. GpPointF* points
  753. )
  754. {
  755. CheckParameter(points);
  756. CheckParameterValid(brush);
  757. CheckObjectBusy(brush);
  758. brush->SetTriangle(points);
  759. return Ok;
  760. }
  761. GpStatus
  762. GdipSetTriangleGradientTriangleI(
  763. GpTriangleGradient *brush,
  764. GpPoint* points
  765. )
  766. {
  767. CheckParameter(points);
  768. GpPointF pointsF[3];
  769. pointsF[0].X = TOREAL(points[0].X);
  770. pointsF[0].Y = TOREAL(points[0].Y);
  771. pointsF[1].X = TOREAL(points[1].X);
  772. pointsF[1].Y = TOREAL(points[1].Y);
  773. pointsF[2].X = TOREAL(points[2].X);
  774. pointsF[2].Y = TOREAL(points[2].Y);
  775. return GdipSetTriangleGradientTriangle(brush, &pointsF[0]);
  776. }
  777. GpStatus
  778. GdipGetTriangleGradientRect(
  779. GpTriangleGradient *brush,
  780. GpRectF *rect
  781. )
  782. {
  783. CheckParameter(rect);
  784. CheckParameterValid(brush);
  785. CheckObjectBusy(brush);
  786. brush->GetRect(*rect);
  787. return Ok;
  788. }
  789. GpStatus
  790. GdipGetTriangleGradientRectI(
  791. GpTriangleGradient *brush,
  792. GpRect *rect
  793. )
  794. {
  795. CheckParameter(rect);
  796. GpRectF rectf;
  797. GpStatus status = GdipGetTriangleGradientRect(brush, &rectf);
  798. if (status == Ok)
  799. {
  800. FPUStateSaver fpuState;
  801. rect->X = GpRound(rectf.X);
  802. rect->Y = GpRound(rectf.Y);
  803. rect->Width = GpRound(rectf.Width);
  804. rect->Height = GpRound(rectf.Height);
  805. }
  806. return status;
  807. }
  808. GpStatus
  809. GdipGetTriangleGradientBlendCount0(
  810. GpTriangleGradient *brush,
  811. INT *count
  812. )
  813. {
  814. CheckParameter(count);
  815. CheckParameterValid(brush);
  816. CheckObjectBusy(brush);
  817. *count = brush->GetBlendCount0();
  818. return Ok;
  819. }
  820. GpStatus
  821. GdipGetTriangleGradientBlend0(
  822. GpTriangleGradient *brush,
  823. REAL *blend,
  824. REAL *positions,
  825. INT count
  826. )
  827. {
  828. CheckParameter(blend);
  829. CheckParameter(positions);
  830. CheckParameterValid(brush);
  831. CheckObjectBusy(brush);
  832. return brush->GetBlend0(blend, positions, count);
  833. }
  834. GpStatus
  835. GdipSetTriangleGradientBlend0(
  836. GpTriangleGradient *brush,
  837. REAL *blend,
  838. REAL *positions,
  839. INT count
  840. )
  841. {
  842. CheckParameter(blend);
  843. CheckParameter(positions);
  844. CheckParameterValid(brush);
  845. CheckObjectBusy(brush);
  846. return brush->SetBlend0(blend, positions, count);
  847. }
  848. GpStatus
  849. GdipGetTriangleGradientBlendCount1(
  850. GpTriangleGradient *brush,
  851. INT *count
  852. )
  853. {
  854. CheckParameter(count);
  855. CheckParameterValid(brush);
  856. CheckObjectBusy(brush);
  857. *count = brush->GetBlendCount1();
  858. return Ok;
  859. }
  860. GpStatus
  861. GdipGetTriangleGradientBlend1(
  862. GpTriangleGradient *brush,
  863. REAL *blend,
  864. REAL *positions,
  865. INT count
  866. )
  867. {
  868. CheckParameter(blend);
  869. CheckParameter(positions);
  870. CheckParameterValid(brush);
  871. CheckObjectBusy(brush);
  872. return brush->GetBlend1(blend, positions, count);
  873. }
  874. GpStatus
  875. GdipSetTriangleGradientBlend1(
  876. GpTriangleGradient *brush,
  877. REAL *blend,
  878. REAL *positions,
  879. INT count
  880. )
  881. {
  882. CheckParameter(blend);
  883. CheckParameter(positions);
  884. CheckParameterValid(brush);
  885. CheckObjectBusy(brush);
  886. return brush->SetBlend1(blend, positions, count);
  887. }
  888. GpStatus
  889. GdipGetTriangleGradientBlendCount2(
  890. GpTriangleGradient *brush,
  891. INT *count
  892. )
  893. {
  894. CheckParameter(count);
  895. CheckParameterValid(brush);
  896. CheckObjectBusy(brush);
  897. *count = brush->GetBlendCount2();
  898. return Ok;
  899. }
  900. GpStatus
  901. GdipGetTriangleGradientBlend2(
  902. GpTriangleGradient *brush,
  903. REAL *blend,
  904. REAL *positions,
  905. INT count
  906. )
  907. {
  908. CheckParameter(blend);
  909. CheckParameter(positions);
  910. CheckParameterValid(brush);
  911. CheckObjectBusy(brush);
  912. return brush->GetBlend2(blend, positions, count);
  913. }
  914. GpStatus
  915. GdipSetTriangleGradientBlend2(
  916. GpTriangleGradient *brush,
  917. REAL *blend,
  918. REAL *positions,
  919. INT count
  920. )
  921. {
  922. CheckParameter(blend);
  923. CheckParameter(positions);
  924. CheckParameterValid(brush);
  925. CheckObjectBusy(brush);
  926. return brush->SetBlend2(blend, positions, count);
  927. }
  928. GpStatus
  929. GdipGetTriangleGradientWrapMode(
  930. GpTriangleGradient *brush,
  931. GpWrapMode *wrapmode
  932. )
  933. {
  934. CheckParameter(wrapmode);
  935. CheckParameterValid(brush);
  936. CheckObjectBusy(brush);
  937. *wrapmode = (GpWrapMode)brush->GetWrapMode();
  938. return Ok;
  939. }
  940. GpStatus
  941. GdipSetTriangleGradientWrapMode(
  942. GpTriangleGradient *brush,
  943. GpWrapMode wrapmode
  944. )
  945. {
  946. CheckParameterValid(brush);
  947. CheckObjectBusy(brush);
  948. brush->SetWrapMode(wrapmode);
  949. return Ok;
  950. }
  951. GpStatus
  952. GdipGetTriangleGradientTransform(
  953. GpTriangleGradient *brush,
  954. GpMatrix *matrix
  955. )
  956. {
  957. CheckParameterValid(brush);
  958. CheckObjectBusy(brush);
  959. CheckParameterValid(matrix);
  960. CheckObjectBusy(matrix);
  961. brush->GetTransform(matrix);
  962. return Ok;
  963. }
  964. GpStatus
  965. GdipSetTriangleGradientTransform(
  966. GpTriangleGradient *brush,
  967. GpMatrix *matrix
  968. )
  969. {
  970. CheckParameterValid(brush);
  971. CheckObjectBusy(brush);
  972. CheckParameterValid(matrix);
  973. CheckObjectBusy(matrix);
  974. brush->SetTransform(*matrix);
  975. return Ok;
  976. }
  977. // For reference in V2
  978. /**
  979. * Represent line texture objects
  980. */
  981. class LineTexture
  982. {
  983. public:
  984. friend class Pen;
  985. /**
  986. * Create a new line texture object
  987. */
  988. // !! Take Image* instead?
  989. LineTexture(const Bitmap* bitmap,
  990. REAL length)
  991. {
  992. GpLineTexture *lineTexture = NULL;
  993. lastResult = DllExports::GdipCreateLineTexture((GpBitmap*)
  994. bitmap->nativeImage,
  995. length,
  996. 0,
  997. &lineTexture);
  998. SetNativeLineTexture(lineTexture);
  999. }
  1000. LineTexture(const Bitmap* bitmap,
  1001. REAL length,
  1002. REAL offset)
  1003. {
  1004. GpLineTexture *lineTexture = NULL;
  1005. lastResult = DllExports::GdipCreateLineTexture((GpBitmap*)
  1006. bitmap->nativeImage,
  1007. length,
  1008. offset,
  1009. &lineTexture);
  1010. SetNativeLineTexture(lineTexture);
  1011. }
  1012. LineTexture* Clone() const
  1013. {
  1014. GpLineTexture *cloneLineTexture = NULL;
  1015. SetStatus(DllExports::GdipCloneLineTexture(nativeLineTexture,
  1016. &cloneLineTexture));
  1017. return new LineTexture(cloneLineTexture, lastResult);
  1018. }
  1019. /**
  1020. * Dispose of resources associated with the line texture
  1021. */
  1022. ~LineTexture()
  1023. {
  1024. DllExports::GdipDeleteLineTexture(nativeLineTexture);
  1025. }
  1026. /**
  1027. * Get line texture attributes
  1028. */
  1029. Bitmap* GetBitmap() const
  1030. {
  1031. SetStatus(NotImplemented);
  1032. return NULL;
  1033. }
  1034. REAL GetLength() const
  1035. {
  1036. REAL len = 0;
  1037. SetStatus(DllExports::GdipGetLineTextureLength(nativeLineTexture,
  1038. &len));
  1039. return len;
  1040. }
  1041. REAL GetOffset() const
  1042. {
  1043. REAL offset = 0;
  1044. SetStatus(DllExports::GdipGetLineTextureOffset(nativeLineTexture,
  1045. &offset));
  1046. return offset;
  1047. }
  1048. Status GetLastStatus() const
  1049. {
  1050. Status lastStatus = lastResult;
  1051. lastResult = Ok;
  1052. return lastStatus;
  1053. }
  1054. protected:
  1055. LineTexture(GpLineTexture* lineTexture, Status status)
  1056. {
  1057. lastResult = status;
  1058. SetNativeLineTexture(lineTexture);
  1059. }
  1060. VOID SetNativeLineTexture(GpLineTexture *lineTexture)
  1061. {
  1062. nativeLineTexture = lineTexture;
  1063. }
  1064. Status SetStatus(Status status) const
  1065. {
  1066. if (status != Ok)
  1067. return (lastResult = status);
  1068. else
  1069. return status;
  1070. }
  1071. private:
  1072. /*
  1073. * handle to native line texture object
  1074. */
  1075. GpLineTexture* nativeLineTexture;
  1076. mutable Status lastResult;
  1077. };
  1078. //--------------------------------------------------------------------------
  1079. // Represent triangular gradient brush object
  1080. //--------------------------------------------------------------------------
  1081. class TriangleGradientBrush : public Brush
  1082. {
  1083. public:
  1084. friend class Pen;
  1085. // Constructors
  1086. TriangleGradientBrush(
  1087. const PointF* points,
  1088. const Color* colors,
  1089. WrapMode wrapMode = WrapModeClamp)
  1090. {
  1091. ARGB argb[3];
  1092. argb[0] = colors[0].GetValue();
  1093. argb[1] = colors[1].GetValue();
  1094. argb[2] = colors[2].GetValue();
  1095. GpTriangleGradient *brush = NULL;
  1096. lastResult = DllExports::GdipCreateTriangleGradient(
  1097. points, argb,
  1098. wrapMode, &brush);
  1099. SetNativeBrush(brush);
  1100. }
  1101. TriangleGradientBrush(
  1102. const Point* points,
  1103. const Color* colors,
  1104. WrapMode wrapMode = WrapModeClamp)
  1105. {
  1106. ARGB argb[3];
  1107. argb[0] = colors[0].GetValue();
  1108. argb[1] = colors[1].GetValue();
  1109. argb[2] = colors[2].GetValue();
  1110. GpTriangleGradient *brush = NULL;
  1111. lastResult = DllExports::GdipCreateTriangleGradientI(
  1112. points, argb,
  1113. wrapMode, &brush);
  1114. SetNativeBrush(brush);
  1115. }
  1116. // Get/set colors
  1117. Status GetColors(Color colors[]) const
  1118. {
  1119. ARGB argb[3];
  1120. SetStatus(DllExports::GdipGetTriangleGradientColor(
  1121. (GpTriangleGradient*) nativeBrush, argb));
  1122. if (lastResult == Ok)
  1123. {
  1124. // use bitwise copy operator for Color copy
  1125. colors[0] = Color(argb[0]);
  1126. colors[1] = Color(argb[1]);
  1127. colors[2] = Color(argb[2]);
  1128. }
  1129. return lastResult;
  1130. }
  1131. Status SetColors(Color colors[])
  1132. {
  1133. ARGB argb[3];
  1134. argb[0] = colors[0].GetValue();
  1135. argb[1] = colors[1].GetValue();
  1136. argb[2] = colors[2].GetValue();
  1137. return SetStatus(DllExports::GdipSetTriangleGradientColor(
  1138. (GpTriangleGradient*)nativeBrush, argb));
  1139. }
  1140. // Get/set triangle
  1141. Status GetTriangle(PointF* points) const
  1142. {
  1143. return SetStatus(DllExports::GdipGetTriangleGradientTriangle(
  1144. (GpTriangleGradient*)nativeBrush, points));
  1145. }
  1146. Status GetTriangle(Point* points) const
  1147. {
  1148. return SetStatus(DllExports::GdipGetTriangleGradientTriangleI(
  1149. (GpTriangleGradient*)nativeBrush, points));
  1150. }
  1151. Status SetTriangle(PointF* points)
  1152. {
  1153. return SetStatus(DllExports::GdipSetTriangleGradientTriangle(
  1154. (GpTriangleGradient*)nativeBrush, points));
  1155. }
  1156. Status SetTriangle(Point* points)
  1157. {
  1158. return SetStatus(DllExports::GdipSetTriangleGradientTriangleI(
  1159. (GpTriangleGradient*)nativeBrush, points));
  1160. }
  1161. Status GetRectangle(RectF& rect) const
  1162. {
  1163. return SetStatus(DllExports::GdipGetTriangleGradientRect(
  1164. (GpTriangleGradient*)nativeBrush, &rect));
  1165. }
  1166. Status GetRectangle(Rect& rect) const
  1167. {
  1168. return SetStatus(DllExports::GdipGetTriangleGradientRectI(
  1169. (GpTriangleGradient*)nativeBrush, &rect));
  1170. }
  1171. // Get/set blend factors
  1172. //
  1173. // If the blendFactors.length = 1, then it's treated
  1174. // as the falloff parameter. Otherwise, it's the array
  1175. // of blend factors.
  1176. // NOTE: Differing semantics from COM+ version where we return
  1177. // an array containing the implicit length value.
  1178. INT GetBlendCount0() const
  1179. {
  1180. INT count = 0;
  1181. SetStatus(DllExports::GdipGetTriangleGradientBlendCount0(
  1182. (GpTriangleGradient*) nativeBrush, &count));
  1183. return count;
  1184. }
  1185. Status GetBlend0(REAL** blendFactors, REAL** blendPositions, INT count) const
  1186. {
  1187. if (!blendFactors || !blendPositions || count <= 0)
  1188. return SetStatus(InvalidParameter);
  1189. *blendFactors = new REAL[count];
  1190. *blendPositions = new REAL[count];
  1191. if (!*blendFactors || !*blendPositions)
  1192. {
  1193. if (*blendFactors)
  1194. delete[] *blendFactors;
  1195. if (*blendPositions)
  1196. delete[] *blendPositions;
  1197. return SetStatus(OutOfMemory);
  1198. }
  1199. Status status = SetStatus(DllExports::GdipGetTriangleGradientBlend0(
  1200. (GpTriangleGradient*)nativeBrush,
  1201. *blendFactors, *blendPositions, count));
  1202. if (status != Ok)
  1203. {
  1204. delete[] *blendFactors;
  1205. *blendFactors = NULL;
  1206. delete[] *blendPositions;
  1207. *blendPositions = NULL;
  1208. }
  1209. return status;
  1210. }
  1211. Status SetBlend0(REAL* blendFactors, REAL* blendPositions, INT count)
  1212. {
  1213. return SetStatus(DllExports::GdipSetTriangleGradientBlend0(
  1214. (GpTriangleGradient*)nativeBrush,
  1215. blendFactors, blendPositions, count));
  1216. }
  1217. INT GetBlendCount1() const
  1218. {
  1219. INT count = 0;
  1220. SetStatus(DllExports::GdipGetTriangleGradientBlendCount1(
  1221. (GpTriangleGradient*) nativeBrush, &count));
  1222. return count;
  1223. }
  1224. Status GetBlend1(REAL** blendFactors, REAL** blendPositions, INT count) const
  1225. {
  1226. if (!blendFactors || !blendPositions || count <= 0)
  1227. return SetStatus(InvalidParameter);
  1228. *blendFactors = new REAL[count];
  1229. *blendPositions = new REAL[count];
  1230. if (!*blendFactors || !*blendPositions)
  1231. {
  1232. if (*blendFactors)
  1233. delete[] *blendFactors;
  1234. if (*blendPositions)
  1235. delete[] *blendPositions;
  1236. return SetStatus(OutOfMemory);
  1237. }
  1238. Status status = SetStatus(DllExports::GdipGetTriangleGradientBlend1(
  1239. (GpTriangleGradient*)nativeBrush,
  1240. *blendFactors, *blendPositions, count));
  1241. if (status != Ok)
  1242. {
  1243. delete[] *blendFactors;
  1244. *blendFactors = NULL;
  1245. delete[] *blendPositions;
  1246. *blendPositions = NULL;
  1247. }
  1248. return status;
  1249. }
  1250. Status SetBlend1(REAL* blendFactors, REAL* blendPositions, INT count)
  1251. {
  1252. return SetStatus(DllExports::GdipSetTriangleGradientBlend1(
  1253. (GpTriangleGradient*)nativeBrush,
  1254. blendFactors, blendPositions, count));
  1255. }
  1256. INT GetBlendCount2() const
  1257. {
  1258. INT count = 0;
  1259. SetStatus(DllExports::GdipGetTriangleGradientBlendCount2(
  1260. (GpTriangleGradient*) nativeBrush, &count));
  1261. return count;
  1262. }
  1263. Status GetBlend2(REAL** blendFactors, REAL** blendPositions, INT count) const
  1264. {
  1265. if (!blendFactors || !blendPositions || count <= 0)
  1266. return SetStatus(InvalidParameter);
  1267. *blendFactors = new REAL[count];
  1268. *blendPositions = new REAL[count];
  1269. if (!*blendFactors || !*blendPositions)
  1270. {
  1271. if (*blendFactors)
  1272. delete[] *blendFactors;
  1273. if (*blendPositions)
  1274. delete[] *blendPositions;
  1275. return SetStatus(OutOfMemory);
  1276. }
  1277. Status status = SetStatus(DllExports::GdipGetTriangleGradientBlend2(
  1278. (GpTriangleGradient*)nativeBrush,
  1279. *blendFactors, *blendPositions, count));
  1280. if (status != Ok)
  1281. {
  1282. delete[] *blendFactors;
  1283. *blendFactors = NULL;
  1284. delete[] *blendPositions;
  1285. *blendPositions = NULL;
  1286. }
  1287. return status;
  1288. }
  1289. Status SetBlend2(REAL* blendFactors, REAL* blendPositions, INT count)
  1290. {
  1291. return SetStatus(DllExports::GdipSetTriangleGradientBlend2(
  1292. (GpTriangleGradient*)nativeBrush,
  1293. blendFactors, blendPositions, count));
  1294. }
  1295. // Check the opacity of this brush element.
  1296. /**
  1297. * Get/set brush transform
  1298. */
  1299. Status GetTransform(Matrix *matrix) const
  1300. {
  1301. return SetStatus(DllExports::GdipGetTriangleGradientTransform(
  1302. (GpTriangleGradient*) nativeBrush, matrix->nativeMatrix));
  1303. }
  1304. Status SetTransform(const Matrix* matrix)
  1305. {
  1306. return SetStatus(DllExports::GdipSetTriangleGradientTransform(
  1307. (GpTriangleGradient*) nativeBrush, matrix->nativeMatrix));
  1308. }
  1309. /**
  1310. * Get/set brush wrapping mode
  1311. */
  1312. WrapMode GetWrapMode() const
  1313. {
  1314. WrapMode wrapMode;
  1315. SetStatus(DllExports::GdipGetTriangleGradientWrapMode(
  1316. (GpTriangleGradient*) nativeBrush, &wrapMode));
  1317. return wrapMode;
  1318. }
  1319. Status SetWrapMode(WrapMode wrapMode)
  1320. {
  1321. return SetStatus(DllExports::GdipSetTriangleGradientWrapMode(
  1322. (GpTriangleGradient*) nativeBrush, wrapMode));
  1323. }
  1324. protected:
  1325. TriangleGradientBrush()
  1326. {
  1327. }
  1328. };
  1329. //--------------------------------------------------------------------------
  1330. // Represent rectangular gradient brush object
  1331. //--------------------------------------------------------------------------
  1332. class RectangleGradientBrush : public Brush
  1333. {
  1334. public:
  1335. friend class Pen;
  1336. // Constructors
  1337. RectangleGradientBrush(const RectF& rect,
  1338. const Color* colors,
  1339. WrapMode wrapMode = WrapModeTile)
  1340. {
  1341. ARGB argb[4];
  1342. argb[0] = colors[0].GetValue();
  1343. argb[1] = colors[1].GetValue();
  1344. argb[2] = colors[2].GetValue();
  1345. argb[3] = colors[3].GetValue();
  1346. GpRectGradient *brush = NULL;
  1347. lastResult = DllExports::GdipCreateRectGradient(rect.X,
  1348. rect.Y,
  1349. rect.Width,
  1350. rect.Height,
  1351. argb,
  1352. wrapMode,
  1353. &brush);
  1354. SetNativeBrush(brush);
  1355. }
  1356. // integer version
  1357. RectangleGradientBrush(const Rect& rect,
  1358. const Color* colors,
  1359. WrapMode wrapMode = WrapModeTile)
  1360. {
  1361. ARGB argb[4];
  1362. argb[0] = colors[0].GetValue();
  1363. argb[1] = colors[1].GetValue();
  1364. argb[2] = colors[2].GetValue();
  1365. argb[3] = colors[3].GetValue();
  1366. GpRectGradient *brush = NULL;
  1367. lastResult = DllExports::GdipCreateRectGradientI(rect.X,
  1368. rect.Y,
  1369. rect.Width,
  1370. rect.Height,
  1371. argb,
  1372. wrapMode,
  1373. &brush);
  1374. SetNativeBrush(brush);
  1375. }
  1376. // Get/set colors
  1377. Status SetColors(const Color colors[])
  1378. {
  1379. ARGB argb[4];
  1380. argb[0] = colors[0].GetValue();
  1381. argb[1] = colors[1].GetValue();
  1382. argb[2] = colors[2].GetValue();
  1383. argb[3] = colors[3].GetValue();
  1384. return SetStatus(DllExports::GdipSetRectGradientColor(
  1385. (GpRectGradient*)nativeBrush,
  1386. argb));
  1387. }
  1388. Status GetColors(Color colors[]) const
  1389. {
  1390. ARGB argb[4];
  1391. SetStatus(DllExports::GdipGetRectGradientColor((GpRectGradient*)
  1392. nativeBrush,
  1393. argb));
  1394. if (lastResult == Ok)
  1395. {
  1396. // use bitwise copy operator for Color copy
  1397. colors[0] = Color(argb[0]);
  1398. colors[1] = Color(argb[1]);
  1399. colors[2] = Color(argb[2]);
  1400. colors[3] = Color(argb[3]);
  1401. }
  1402. return lastResult;
  1403. }
  1404. Status GetRectangle(RectF& rect) const
  1405. {
  1406. return SetStatus(DllExports::GdipGetRectGradientRect((GpRectGradient*)nativeBrush,
  1407. &rect));
  1408. }
  1409. Status GetRectangle(Rect& rect) const
  1410. {
  1411. return SetStatus(DllExports::GdipGetRectGradientRectI((GpRectGradient*)nativeBrush,
  1412. &rect));
  1413. }
  1414. // Get/set blend factors
  1415. //
  1416. // If the blendFactors.length = 1, then it's treated
  1417. // as the falloff parameter. Otherwise, it's the array
  1418. // of blend factors.
  1419. // NOTE: Differing semantics from COM+ version where we return
  1420. // an array containing the implicit length value.
  1421. INT GetHorizontalBlendCount() const
  1422. {
  1423. INT count = 0;
  1424. SetStatus(DllExports::GdipGetRectGradientBlendCountH((GpRectGradient*)
  1425. nativeBrush,
  1426. &count));
  1427. return count;
  1428. }
  1429. Status GetHorizontalBlend(REAL** blendFactors, REAL** blendPositions, INT count) const
  1430. {
  1431. if (!blendFactors || !blendPositions || count <= 0)
  1432. return SetStatus(InvalidParameter);
  1433. *blendFactors = new REAL[count];
  1434. *blendPositions = new REAL[count];
  1435. if (!*blendFactors || !*blendPositions)
  1436. {
  1437. if (*blendFactors)
  1438. delete *blendFactors;
  1439. if (*blendPositions)
  1440. delete *blendPositions;
  1441. return SetStatus(OutOfMemory);
  1442. }
  1443. Status status = SetStatus(DllExports::GdipGetRectGradientBlendH((GpRectGradient*)nativeBrush,
  1444. *blendFactors, *blendPositions, count));
  1445. if (status != Ok)
  1446. {
  1447. delete[] *blendFactors;
  1448. *blendFactors = NULL;
  1449. delete[] *blendPositions;
  1450. *blendPositions = NULL;
  1451. }
  1452. return status;
  1453. }
  1454. Status SetHorizontalBlend(const REAL* blendFactors, const REAL* blendPositions, INT count)
  1455. {
  1456. return SetStatus(DllExports::GdipSetRectGradientBlendH((GpRectGradient*)nativeBrush,
  1457. blendFactors, blendPositions, count));
  1458. }
  1459. INT GetVerticalBlendCount() const
  1460. {
  1461. INT count = 0;
  1462. SetStatus(DllExports::GdipGetRectGradientBlendCountV((GpRectGradient*)
  1463. nativeBrush,
  1464. &count));
  1465. return count;
  1466. }
  1467. Status GetVerticalBlend(REAL** blendFactors, REAL** blendPositions, INT count) const
  1468. {
  1469. if (!blendFactors || !blendPositions || count <= 0)
  1470. return SetStatus(OutOfMemory);
  1471. *blendFactors = new REAL[count];
  1472. *blendPositions = new REAL[count];
  1473. if (!*blendFactors || !*blendPositions)
  1474. {
  1475. if (*blendFactors)
  1476. delete[] *blendFactors;
  1477. if (*blendPositions)
  1478. delete[] *blendPositions;
  1479. return SetStatus(OutOfMemory);
  1480. }
  1481. Status status = SetStatus(DllExports::GdipGetRectGradientBlendV((GpRectGradient*)nativeBrush,
  1482. *blendFactors, *blendPositions, count));
  1483. if (status != Ok)
  1484. {
  1485. delete[] *blendFactors;
  1486. *blendFactors = NULL;
  1487. delete[] *blendPositions;
  1488. *blendPositions = NULL;
  1489. }
  1490. return status;
  1491. }
  1492. Status SetVerticalBlend(const REAL* blendFactors, const REAL* blendPositions, INT count)
  1493. {
  1494. return SetStatus(DllExports::GdipSetRectGradientBlendV((GpRectGradient*)nativeBrush,
  1495. blendFactors, blendPositions, count));
  1496. }
  1497. // Check the opacity of this brush element.
  1498. /**
  1499. * Set/get brush transform
  1500. */
  1501. Status SetTransform(const Matrix* matrix)
  1502. {
  1503. return SetStatus(DllExports::GdipSetRectGradientTransform((GpRectGradient*)
  1504. nativeBrush,
  1505. matrix->nativeMatrix));
  1506. }
  1507. Status GetTransform(Matrix *matrix) const
  1508. {
  1509. return SetStatus(DllExports::GdipGetRectGradientTransform((GpRectGradient*)
  1510. nativeBrush,
  1511. matrix->nativeMatrix));
  1512. }
  1513. /**
  1514. * Set/get brush wrapping mode
  1515. */
  1516. Status SetWrapMode(WrapMode wrapMode)
  1517. {
  1518. return SetStatus(DllExports::GdipSetRectGradientWrapMode((GpRectGradient*)
  1519. nativeBrush,
  1520. wrapMode));
  1521. }
  1522. WrapMode GetWrapMode() const
  1523. {
  1524. WrapMode wrapMode;
  1525. SetStatus(DllExports::GdipGetRectGradientWrapMode((GpRectGradient*)
  1526. nativeBrush,
  1527. &wrapMode));
  1528. return wrapMode;
  1529. }
  1530. protected:
  1531. RectangleGradientBrush()
  1532. {
  1533. }
  1534. };
  1535. class RadialGradientBrush : public Brush
  1536. {
  1537. public:
  1538. friend class Pen;
  1539. RadialGradientBrush(
  1540. const RectF& rect,
  1541. const Color& centerColor,
  1542. const Color& boundaryColor,
  1543. WrapMode wrapMode = WrapModeClamp
  1544. )
  1545. {
  1546. GpRadialGradient *brush = NULL;
  1547. lastResult = DllExports::GdipCreateRadialBrush(&rect,
  1548. centerColor.GetValue(),
  1549. boundaryColor.GetValue(),
  1550. wrapMode, &brush);
  1551. SetNativeBrush(brush);
  1552. }
  1553. RadialGradientBrush(
  1554. const Rect& rect,
  1555. const Color& centerColor,
  1556. const Color& boundaryColor,
  1557. WrapMode wrapMode = WrapModeClamp
  1558. )
  1559. {
  1560. GpRadialGradient *brush = NULL;
  1561. lastResult = DllExports::GdipCreateRadialBrushI(&rect,
  1562. centerColor.GetValue(),
  1563. boundaryColor.GetValue(),
  1564. wrapMode, &brush);
  1565. SetNativeBrush(brush);
  1566. }
  1567. // Get/set color attributes
  1568. Status SetCenterColor(const Color& color)
  1569. {
  1570. return SetStatus(DllExports::GdipSetRadialCenterColor((GpRadialGradient*)nativeBrush,
  1571. color.GetValue()));
  1572. }
  1573. Status SetBoundaryColor(const Color& color)
  1574. {
  1575. return SetStatus(DllExports::GdipSetRadialBoundaryColor((GpRadialGradient*)nativeBrush,
  1576. color.GetValue()));
  1577. }
  1578. Status GetCenterColor(Color& centerColor)
  1579. {
  1580. ARGB argb;
  1581. SetStatus(DllExports::GdipGetRadialCenterColor((GpRadialGradient*)
  1582. nativeBrush, &argb));
  1583. centerColor = Color(argb);
  1584. return lastResult;
  1585. }
  1586. Status GetBoundaryColor(Color& boundaryColor)
  1587. {
  1588. ARGB argb = 0;
  1589. SetStatus(DllExports::GdipGetRadialBoundaryColor((GpRadialGradient*)
  1590. nativeBrush, &argb));
  1591. boundaryColor = Color(argb);
  1592. return lastResult;
  1593. }
  1594. Status GetRectangle(RectF& rect) const
  1595. {
  1596. return SetStatus(DllExports::GdipGetRadialRect(
  1597. (GpRadialGradient*)nativeBrush, &rect));
  1598. }
  1599. Status GetRectangle(Rect& rect) const
  1600. {
  1601. return SetStatus(DllExports::GdipGetRadialRectI(
  1602. (GpRadialGradient*)nativeBrush, &rect));
  1603. }
  1604. // !!! This diverges from COM+ implemention in that we give
  1605. // them all blend values instead of upto 'count' of them.
  1606. Status SetBlend(const REAL* blendFactors, const REAL* blendPositions, INT count)
  1607. {
  1608. return SetStatus(DllExports::GdipSetRadialBlend((GpRadialGradient*)
  1609. nativeBrush,
  1610. blendFactors,
  1611. blendPositions,
  1612. count));
  1613. }
  1614. INT GetBlendCount() const
  1615. {
  1616. INT count = 0;
  1617. SetStatus(DllExports::GdipGetRadialBlendCount((GpRadialGradient*)
  1618. nativeBrush,
  1619. &count));
  1620. return count;
  1621. }
  1622. Status GetBlend(REAL** blendFactors, REAL** blendPositions, INT count) const
  1623. {
  1624. if (!blendFactors || !blendPositions || count <= 0)
  1625. return SetStatus(InvalidParameter);
  1626. *blendFactors = new REAL[count];
  1627. *blendPositions = new REAL[count];
  1628. if (!*blendFactors || !*blendPositions)
  1629. {
  1630. if (*blendFactors)
  1631. delete[] *blendFactors;
  1632. if (*blendPositions)
  1633. delete[] *blendPositions;
  1634. return SetStatus(OutOfMemory);
  1635. }
  1636. Status status = SetStatus(DllExports::GdipGetRadialBlend((GpRadialGradient*)nativeBrush,
  1637. *blendFactors,
  1638. *blendPositions,
  1639. count));
  1640. if (status != Ok)
  1641. {
  1642. delete[] *blendFactors;
  1643. *blendFactors = NULL;
  1644. delete[] *blendPositions;
  1645. *blendPositions = NULL;
  1646. }
  1647. return status;
  1648. }
  1649. INT GetPresetBlendCount() const
  1650. {
  1651. INT count = 0;
  1652. SetStatus(DllExports::GdipGetRadialPresetBlendCount((GpRadialGradient*)
  1653. nativeBrush,
  1654. &count));
  1655. return count;
  1656. }
  1657. Status SetPresetBlend(const Color* presetColors,
  1658. const REAL* blendPositions, INT count)
  1659. {
  1660. if (!presetColors || !blendPositions || count <= 0)
  1661. return SetStatus(InvalidParameter);
  1662. ARGB* argbs = (ARGB*) malloc(count*sizeof(ARGB));
  1663. if (argbs)
  1664. {
  1665. for (INT i = 0; i < count; i++)
  1666. {
  1667. argbs[i] = presetColors[i].GetValue();
  1668. }
  1669. Status status = SetStatus(DllExports::GdipSetRadialPresetBlend(
  1670. (GpRadialGradient*) nativeBrush,
  1671. argbs,
  1672. blendPositions,
  1673. count));
  1674. free(argbs);
  1675. return status;
  1676. }
  1677. else
  1678. {
  1679. return SetStatus(OutOfMemory);
  1680. }
  1681. }
  1682. Status GetPresetBlend(Color** presetColors, REAL** blendPositions, INT count) const
  1683. {
  1684. if (!presetColors || !blendPositions || count <= 0)
  1685. return SetStatus(InvalidParameter);
  1686. *presetColors = new Color[count];
  1687. *blendPositions = new REAL[count];
  1688. ARGB* argbs = (ARGB*) malloc(count*sizeof(ARGB));
  1689. if (!*presetColors || !*blendPositions || !argbs)
  1690. {
  1691. if (*presetColors)
  1692. delete[] *presetColors;
  1693. if (*blendPositions)
  1694. delete[] *blendPositions;
  1695. free(argbs);
  1696. return SetStatus(OutOfMemory);
  1697. }
  1698. Status status = SetStatus(DllExports::GdipGetRadialPresetBlend(
  1699. (GpRadialGradient*)nativeBrush,
  1700. argbs,
  1701. *blendPositions,
  1702. count));
  1703. if (status == Ok)
  1704. {
  1705. for (INT i = 0; i < count; i++)
  1706. {
  1707. *presetColors[i] = Color(argbs[i]);
  1708. }
  1709. }
  1710. else
  1711. {
  1712. delete[] *presetColors;
  1713. *presetColors = NULL;
  1714. delete[] *blendPositions;
  1715. *blendPositions = NULL;
  1716. }
  1717. free(argbs);
  1718. return status;
  1719. }
  1720. Status SetSigmaBlend(REAL focus, REAL scale = 1.0)
  1721. {
  1722. return SetStatus(DllExports::GdipSetRadialSigmaBlend(
  1723. (GpRadialGradient*)nativeBrush, focus, scale));
  1724. }
  1725. Status SetLinearBlend(REAL focus, REAL scale = 1.0)
  1726. {
  1727. return SetStatus(DllExports::GdipSetRadialLinearBlend(
  1728. (GpRadialGradient*)nativeBrush, focus, scale));
  1729. }
  1730. /**
  1731. * Set/get brush transform
  1732. */
  1733. Status SetTransform(const Matrix* matrix)
  1734. {
  1735. return SetStatus(DllExports::GdipSetRadialTransform((GpRadialGradient*)nativeBrush,
  1736. matrix->nativeMatrix));
  1737. }
  1738. Status GetTransform(Matrix *matrix) const
  1739. {
  1740. return SetStatus(DllExports::GdipGetRadialTransform((GpRadialGradient*)nativeBrush,
  1741. matrix->nativeMatrix));
  1742. }
  1743. /**
  1744. * Set/get brush wrapping mode
  1745. */
  1746. Status SetWrapMode(WrapMode wrapMode)
  1747. {
  1748. return SetStatus(DllExports::GdipSetRadialWrapMode((GpRadialGradient*)nativeBrush,
  1749. wrapMode));
  1750. }
  1751. WrapMode GetWrapMode() const
  1752. {
  1753. WrapMode wrapMode;
  1754. SetStatus(DllExports::GdipGetRadialWrapMode((GpRadialGradient*)
  1755. nativeBrush,
  1756. &wrapMode));
  1757. return wrapMode;
  1758. }
  1759. protected:
  1760. RadialGradientBrush()
  1761. {
  1762. }
  1763. };
  1764. #endif