CustomLineCap.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. //
  2. // System.Drawing.Drawing2D.CustomLineCap.cs
  3. //
  4. // Authors:
  5. // Dennis Hayes ([email protected])
  6. // Andreas Nahr ([email protected])
  7. // Ravindra ([email protected])
  8. //
  9. // Copyright (C) 2002/3 Ximian, Inc. http://www.ximian.com
  10. // Copyright (C) 2004 Novell, Inc. http://www.novell.com
  11. //
  12. //
  13. // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
  14. //
  15. // Permission is hereby granted, free of charge, to any person obtaining
  16. // a copy of this software and associated documentation files (the
  17. // "Software"), to deal in the Software without restriction, including
  18. // without limitation the rights to use, copy, modify, merge, publish,
  19. // distribute, sublicense, and/or sell copies of the Software, and to
  20. // permit persons to whom the Software is furnished to do so, subject to
  21. // the following conditions:
  22. //
  23. // The above copyright notice and this permission notice shall be
  24. // included in all copies or substantial portions of the Software.
  25. //
  26. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  27. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  28. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  29. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  30. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  31. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  32. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  33. //
  34. using System;
  35. namespace System.Drawing.Drawing2D
  36. {
  37. /// <summary>
  38. /// Summary description for CustomLineCap.
  39. /// </summary>
  40. public class CustomLineCap : MarshalByRefObject, ICloneable, IDisposable
  41. {
  42. private bool disposed;
  43. internal IntPtr nativeObject;
  44. // Constructors
  45. internal CustomLineCap () { }
  46. internal CustomLineCap (IntPtr ptr)
  47. {
  48. nativeObject = ptr;
  49. }
  50. public CustomLineCap (GraphicsPath fillPath, GraphicsPath strokePath) : this (fillPath, strokePath, LineCap.Flat, 0)
  51. {
  52. }
  53. public CustomLineCap (GraphicsPath fillPath, GraphicsPath strokePath, LineCap baseCap) : this (fillPath, strokePath, baseCap, 0)
  54. {
  55. }
  56. public CustomLineCap(GraphicsPath fillPath, GraphicsPath strokePath, LineCap baseCap, float baseInset)
  57. {
  58. IntPtr fill = IntPtr.Zero;
  59. IntPtr stroke = IntPtr.Zero;
  60. if (fillPath != null)
  61. fill = fillPath.nativePath;
  62. if (strokePath != null)
  63. stroke = strokePath.nativePath;
  64. Status status = GDIPlus.GdipCreateCustomLineCap (fill, stroke, baseCap, baseInset, out nativeObject);
  65. GDIPlus.CheckStatus (status);
  66. }
  67. public LineCap BaseCap {
  68. get {
  69. LineCap baseCap;
  70. Status status = GDIPlus.GdipGetCustomLineCapBaseCap (nativeObject, out baseCap);
  71. GDIPlus.CheckStatus (status);
  72. return baseCap;
  73. }
  74. set {
  75. Status status = GDIPlus.GdipSetCustomLineCapBaseCap (nativeObject, value);
  76. GDIPlus.CheckStatus (status);
  77. }
  78. }
  79. public LineJoin StrokeJoin {
  80. get {
  81. LineJoin strokeJoin;
  82. Status status = GDIPlus.GdipGetCustomLineCapStrokeJoin (nativeObject, out strokeJoin);
  83. GDIPlus.CheckStatus (status);
  84. return strokeJoin;
  85. }
  86. set {
  87. Status status = GDIPlus.GdipSetCustomLineCapStrokeJoin (nativeObject, value);
  88. GDIPlus.CheckStatus (status);
  89. }
  90. }
  91. public float BaseInset {
  92. get {
  93. float baseInset;
  94. Status status = GDIPlus.GdipGetCustomLineCapBaseInset (nativeObject, out baseInset);
  95. GDIPlus.CheckStatus (status);
  96. return baseInset;
  97. }
  98. set {
  99. Status status = GDIPlus.GdipSetCustomLineCapBaseInset (nativeObject, value);
  100. GDIPlus.CheckStatus (status);
  101. }
  102. }
  103. public float WidthScale {
  104. get {
  105. float widthScale;
  106. Status status = GDIPlus.GdipGetCustomLineCapWidthScale (nativeObject, out widthScale);
  107. GDIPlus.CheckStatus (status);
  108. return widthScale;
  109. }
  110. set {
  111. Status status = GDIPlus.GdipSetCustomLineCapWidthScale (nativeObject, value);
  112. GDIPlus.CheckStatus (status);
  113. }
  114. }
  115. // Public Methods
  116. public virtual object Clone ()
  117. {
  118. IntPtr clonePtr;
  119. Status status = GDIPlus.GdipCloneCustomLineCap (nativeObject, out clonePtr);
  120. GDIPlus.CheckStatus (status);
  121. return new CustomLineCap (clonePtr);
  122. }
  123. public virtual void Dispose ()
  124. {
  125. Dispose (true);
  126. System.GC.SuppressFinalize (this);
  127. }
  128. protected virtual void Dispose (bool disposing)
  129. {
  130. if (! disposed) {
  131. Status status = GDIPlus.GdipDeleteCustomLineCap (nativeObject);
  132. GDIPlus.CheckStatus (status);
  133. disposed = true;
  134. nativeObject = IntPtr.Zero;
  135. }
  136. }
  137. ~CustomLineCap ()
  138. {
  139. Dispose (false);
  140. }
  141. public void GetStrokeCaps (out LineCap startCap, out LineCap endCap)
  142. {
  143. Status status = GDIPlus.GdipGetCustomLineCapStrokeCaps (nativeObject, out startCap, out endCap);
  144. GDIPlus.CheckStatus (status);
  145. }
  146. public void SetStrokeCaps(LineCap startCap, LineCap endCap)
  147. {
  148. Status status = GDIPlus.GdipSetCustomLineCapStrokeCaps (nativeObject, startCap, endCap);
  149. GDIPlus.CheckStatus (status);
  150. }
  151. }
  152. }