PathGradientBrush.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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
  10. // (C) 2004, Novell, Inc.
  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. // IntPtr rect;
  39. status = GDIPlus.GdipGetPathGradientRect (nativeObject, out rectangle);
  40. GDIPlus.CheckStatus (status);
  41. // rectangle = (RectangleF) Marshal.PtrToStructure (rect, typeof (RectangleF));
  42. }
  43. public PathGradientBrush (Point[] points) : this (points, WrapMode.Clamp)
  44. {
  45. }
  46. public PathGradientBrush (PointF[] points) : this (points, WrapMode.Clamp)
  47. {
  48. }
  49. public PathGradientBrush (Point[] points, WrapMode wrapMode)
  50. {
  51. Status status = GDIPlus.GdipCreatePathGradientI (points, points.Length, wrapMode, out nativeObject);
  52. GDIPlus.CheckStatus (status);
  53. // IntPtr rect;
  54. status = GDIPlus.GdipGetPathGradientRect (nativeObject, out rectangle);
  55. GDIPlus.CheckStatus (status);
  56. // rectangle = (RectangleF) Marshal.PtrToStructure (rect, typeof (RectangleF));
  57. }
  58. public PathGradientBrush (PointF[] points, WrapMode wrapMode)
  59. {
  60. Status status = GDIPlus.GdipCreatePathGradient (points, points.Length, wrapMode, out nativeObject);
  61. GDIPlus.CheckStatus (status);
  62. // IntPtr rect;
  63. status = GDIPlus.GdipGetPathGradientRect (nativeObject, out rectangle);
  64. GDIPlus.CheckStatus (status);
  65. // rectangle = (RectangleF) Marshal.PtrToStructure (rect, typeof (RectangleF));
  66. }
  67. // properties
  68. public Blend Blend {
  69. get {
  70. return blend;
  71. }
  72. set {
  73. Status status = GDIPlus.GdipSetPathGradientBlend (nativeObject, value.Factors, value.Positions, value.Factors.Length);
  74. GDIPlus.CheckStatus (status);
  75. blend = value;
  76. }
  77. }
  78. public Color CenterColor {
  79. get {
  80. return centerColor;
  81. }
  82. set {
  83. Status status = GDIPlus.GdipSetPathGradientCenterColor (nativeObject, value.ToArgb ());
  84. GDIPlus.CheckStatus (status);
  85. centerColor = value;
  86. }
  87. }
  88. public PointF CenterPoint {
  89. get {
  90. return center;
  91. }
  92. set {
  93. Status status = GDIPlus.GdipSetPathGradientCenterPoint (nativeObject, value);
  94. GDIPlus.CheckStatus (status);
  95. center = value;
  96. }
  97. }
  98. public PointF FocusScales {
  99. get {
  100. return focus;
  101. }
  102. set {
  103. Status status = GDIPlus.GdipSetPathGradientFocusScales (nativeObject, value.X, value.Y);
  104. GDIPlus.CheckStatus (status);
  105. focus = value;
  106. }
  107. }
  108. public ColorBlend InterpolationColors {
  109. get {
  110. return interpolationColors;
  111. }
  112. set {
  113. Color[] colors = value.Colors;
  114. int[] blend = new int [colors.Length];
  115. for (int i = 0; i < colors.Length; i++)
  116. blend [i] = colors [i].ToArgb ();
  117. Status status = GDIPlus.GdipSetPathGradientPresetBlend (nativeObject, blend, value.Positions, blend.Length);
  118. GDIPlus.CheckStatus (status);
  119. interpolationColors = value;
  120. }
  121. }
  122. public RectangleF Rectangle {
  123. get {
  124. return rectangle;
  125. }
  126. }
  127. public Color[] SurroundColors {
  128. get {
  129. return surroundColors;
  130. }
  131. set {
  132. int[] colors = new int [value.Length];
  133. for (int i = 0; i < value.Length; i++)
  134. colors [i] = value [i].ToArgb ();
  135. Status status = GDIPlus.GdipSetPathGradientSurroundColorsWithCount (nativeObject, colors, colors.Length);
  136. GDIPlus.CheckStatus (status);
  137. surroundColors = value;
  138. }
  139. }
  140. public Matrix Transform {
  141. get {
  142. return transform;
  143. }
  144. set {
  145. Status status = GDIPlus.GdipSetPathGradientTransform (nativeObject, value.nativeMatrix);
  146. GDIPlus.CheckStatus (status);
  147. transform = value;
  148. }
  149. }
  150. public WrapMode WrapMode {
  151. get {
  152. return wrapMode;
  153. }
  154. set {
  155. Status status = GDIPlus.GdipSetPathGradientWrapMode (nativeObject, value);
  156. GDIPlus.CheckStatus (status);
  157. wrapMode = value;
  158. }
  159. }
  160. //methods
  161. public override object Clone ()
  162. {
  163. PathGradientBrush clone = new PathGradientBrush (nativeObject);
  164. clone.blend = this.blend;
  165. clone.centerColor = this.centerColor;
  166. clone.center = this.center;
  167. clone.focus = this.focus;
  168. clone.rectangle = this.rectangle;
  169. clone.surroundColors = this.surroundColors;
  170. clone.interpolationColors = this.interpolationColors;
  171. clone.transform = this.transform;
  172. clone.wrapMode = this.wrapMode;
  173. return clone;
  174. }
  175. }
  176. }