CustomLineCap.cs 4.7 KB

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