PathGradientBrush.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. //
  2. // System.Drawing.Drawing2D.PathGradientBrush.cs
  3. //
  4. // Authors:
  5. // Dennis Hayes ([email protected])
  6. // Andreas Nahr ([email protected])
  7. // Ravindra ([email protected])
  8. //
  9. // (C) 2002/3 Ximian, Inc. http://www.ximian.com
  10. // (C) 2004, Novell, Inc. http://www.novell.com
  11. //
  12. using System;
  13. using System.Drawing;
  14. using System.Runtime.InteropServices;
  15. namespace System.Drawing.Drawing2D
  16. {
  17. /// <summary>
  18. /// Summary description for PathGradientBrush.
  19. /// </summary>
  20. public sealed class PathGradientBrush : Brush
  21. {
  22. Blend blend;
  23. Color centerColor;
  24. PointF center;
  25. PointF focus;
  26. RectangleF rectangle;
  27. Color [] surroundColors;
  28. ColorBlend interpolationColors;
  29. Matrix transform;
  30. WrapMode wrapMode;
  31. internal PathGradientBrush (IntPtr native) : base (native)
  32. {
  33. }
  34. public PathGradientBrush (GraphicsPath path)
  35. {
  36. Status status = GDIPlus.GdipCreatePathGradientFromPath (path.NativeObject, out nativeObject);
  37. GDIPlus.CheckStatus (status);
  38. status = GDIPlus.GdipGetPathGradientRect (nativeObject, out rectangle);
  39. GDIPlus.CheckStatus (status);
  40. }
  41. public PathGradientBrush (Point [] points) : this (points, WrapMode.Clamp)
  42. {
  43. }
  44. public PathGradientBrush (PointF [] points) : this (points, WrapMode.Clamp)
  45. {
  46. }
  47. public PathGradientBrush (Point [] points, WrapMode wrapMode)
  48. {
  49. Status status = GDIPlus.GdipCreatePathGradientI (points, points.Length, wrapMode, out nativeObject);
  50. GDIPlus.CheckStatus (status);
  51. Rectangle rect;
  52. status = GDIPlus.GdipGetPathGradientRectI (nativeObject, out rect);
  53. GDIPlus.CheckStatus (status);
  54. rectangle = (RectangleF) rect;
  55. }
  56. public PathGradientBrush (PointF [] points, WrapMode wrapMode)
  57. {
  58. Status status = GDIPlus.GdipCreatePathGradient (points, points.Length, wrapMode, out nativeObject);
  59. GDIPlus.CheckStatus (status);
  60. status = GDIPlus.GdipGetPathGradientRect (nativeObject, out rectangle);
  61. GDIPlus.CheckStatus (status);
  62. }
  63. // Properties
  64. public Blend Blend {
  65. get {
  66. return blend;
  67. }
  68. set {
  69. Status status = GDIPlus.GdipSetPathGradientBlend (nativeObject, value.Factors, value.Positions, value.Factors.Length);
  70. GDIPlus.CheckStatus (status);
  71. blend = value;
  72. }
  73. }
  74. public Color CenterColor {
  75. get {
  76. return centerColor;
  77. }
  78. set {
  79. Status status = GDIPlus.GdipSetPathGradientCenterColor (nativeObject, value.ToArgb ());
  80. GDIPlus.CheckStatus (status);
  81. centerColor = value;
  82. }
  83. }
  84. public PointF CenterPoint {
  85. get {
  86. return center;
  87. }
  88. set {
  89. Status status = GDIPlus.GdipSetPathGradientCenterPoint (nativeObject, ref value);
  90. GDIPlus.CheckStatus (status);
  91. center = value;
  92. }
  93. }
  94. public PointF FocusScales {
  95. get {
  96. return focus;
  97. }
  98. set {
  99. Status status = GDIPlus.GdipSetPathGradientFocusScales (nativeObject, value.X, value.Y);
  100. GDIPlus.CheckStatus (status);
  101. focus = value;
  102. }
  103. }
  104. public ColorBlend InterpolationColors {
  105. get {
  106. return interpolationColors;
  107. }
  108. set {
  109. Color [] colors = value.Colors;
  110. int [] blend = new int [colors.Length];
  111. for (int i = 0; i < colors.Length; i++)
  112. blend [i] = colors [i].ToArgb ();
  113. Status status = GDIPlus.GdipSetPathGradientPresetBlend (nativeObject, blend, value.Positions, blend.Length);
  114. GDIPlus.CheckStatus (status);
  115. interpolationColors = value;
  116. }
  117. }
  118. public RectangleF Rectangle {
  119. get {
  120. return rectangle;
  121. }
  122. }
  123. public Color [] SurroundColors {
  124. get {
  125. return surroundColors;
  126. }
  127. set {
  128. int length = value.Length;
  129. int [] colors = new int [length];
  130. for (int i = 0; i < length; i++)
  131. colors [i] = value [i].ToArgb ();
  132. Status status = GDIPlus.GdipSetPathGradientSurroundColorsWithCount (nativeObject, colors, ref length);
  133. GDIPlus.CheckStatus (status);
  134. surroundColors = value;
  135. }
  136. }
  137. public Matrix Transform {
  138. get {
  139. return transform;
  140. }
  141. set {
  142. Status status = GDIPlus.GdipSetPathGradientTransform (nativeObject, value.nativeMatrix);
  143. GDIPlus.CheckStatus (status);
  144. transform = value;
  145. }
  146. }
  147. public WrapMode WrapMode {
  148. get {
  149. return wrapMode;
  150. }
  151. set {
  152. Status status = GDIPlus.GdipSetPathGradientWrapMode (nativeObject, value);
  153. GDIPlus.CheckStatus (status);
  154. wrapMode = value;
  155. }
  156. }
  157. // Methods
  158. public void MultiplyTransform (Matrix matrix)
  159. {
  160. MultiplyTransform (matrix, MatrixOrder.Prepend);
  161. }
  162. public void MultiplyTransform (Matrix matrix, MatrixOrder order)
  163. {
  164. Status status = GDIPlus.GdipMultiplyPathGradientTransform (nativeObject, matrix.nativeMatrix, order);
  165. GDIPlus.CheckStatus (status);
  166. }
  167. public void ResetTransform ()
  168. {
  169. Status status = GDIPlus.GdipResetPathGradientTransform (nativeObject);
  170. GDIPlus.CheckStatus (status);
  171. }
  172. public void RotateTransform (float angle)
  173. {
  174. RotateTransform (angle, MatrixOrder.Prepend);
  175. }
  176. public void RotateTransform (float angle, MatrixOrder order)
  177. {
  178. Status status = GDIPlus.GdipRotatePathGradientTransform (nativeObject, angle, order);
  179. GDIPlus.CheckStatus (status);
  180. }
  181. public void ScaleTransform (float sx, float sy)
  182. {
  183. ScaleTransform (sx, sy, MatrixOrder.Prepend);
  184. }
  185. public void ScaleTransform (float sx, float sy, MatrixOrder order)
  186. {
  187. Status status = GDIPlus.GdipScalePathGradientTransform (nativeObject, sx, sy, order);
  188. GDIPlus.CheckStatus (status);
  189. }
  190. public void SetBlendTriangularShape (float focus)
  191. {
  192. SetBlendTriangularShape (focus, 1.0F);
  193. }
  194. public void SetBlendTriangularShape (float focus, float scale)
  195. {
  196. Status status = GDIPlus.GdipSetPathGradientLinearBlend (nativeObject, focus, scale);
  197. GDIPlus.CheckStatus (status);
  198. }
  199. public void SetSigmaBellShape (float focus)
  200. {
  201. SetSigmaBellShape (focus, 1.0F);
  202. }
  203. public void SetSigmaBellShape (float focus, float scale)
  204. {
  205. Status status = GDIPlus.GdipSetPathGradientSigmaBlend (nativeObject, focus, scale);
  206. GDIPlus.CheckStatus (status);
  207. }
  208. public void TranslateTransform (float dx, float dy)
  209. {
  210. TranslateTransform (dx, dy, MatrixOrder.Prepend);
  211. }
  212. public void TranslateTransform (float dx, float dy, MatrixOrder order)
  213. {
  214. Status status = GDIPlus.GdipTranslatePathGradientTransform (nativeObject, dx, dy, order);
  215. GDIPlus.CheckStatus (status);
  216. }
  217. public override object Clone ()
  218. {
  219. IntPtr clonePtr;
  220. Status status = GDIPlus.GdipCloneBrush (nativeObject, out clonePtr);
  221. GDIPlus.CheckStatus (status);
  222. PathGradientBrush clone = new PathGradientBrush (clonePtr);
  223. return clone;
  224. }
  225. }
  226. }