CustomLineCap.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. using System;
  13. namespace System.Drawing.Drawing2D
  14. {
  15. /// <summary>
  16. /// Summary description for CustomLineCap.
  17. /// </summary>
  18. public class CustomLineCap : MarshalByRefObject, ICloneable, IDisposable
  19. {
  20. private bool disposed;
  21. internal IntPtr nativeObject;
  22. // Constructors
  23. internal CustomLineCap () { }
  24. internal CustomLineCap (IntPtr ptr)
  25. {
  26. nativeObject = ptr;
  27. }
  28. public CustomLineCap (GraphicsPath fillPath, GraphicsPath strokePath) : this (fillPath, strokePath, LineCap.Flat, 0)
  29. {
  30. }
  31. public CustomLineCap (GraphicsPath fillPath, GraphicsPath strokePath, LineCap baseCap) : this (fillPath, strokePath, baseCap, 0)
  32. {
  33. }
  34. public CustomLineCap(GraphicsPath fillPath, GraphicsPath strokePath, LineCap baseCap, float baseInset)
  35. {
  36. IntPtr fill = IntPtr.Zero;
  37. IntPtr stroke = IntPtr.Zero;
  38. if (fillPath != null)
  39. fill = fillPath.nativePath;
  40. if (strokePath != null)
  41. stroke = strokePath.nativePath;
  42. Status status = GDIPlus.GdipCreateCustomLineCap (fill, stroke, baseCap, baseInset, out nativeObject);
  43. GDIPlus.CheckStatus (status);
  44. }
  45. public LineCap BaseCap {
  46. get {
  47. LineCap baseCap;
  48. Status status = GDIPlus.GdipGetCustomLineCapBaseCap (nativeObject, out baseCap);
  49. GDIPlus.CheckStatus (status);
  50. return baseCap;
  51. }
  52. set {
  53. Status status = GDIPlus.GdipSetCustomLineCapBaseCap (nativeObject, value);
  54. GDIPlus.CheckStatus (status);
  55. }
  56. }
  57. public LineJoin StrokeJoin {
  58. get {
  59. LineJoin strokeJoin;
  60. Status status = GDIPlus.GdipGetCustomLineCapStrokeJoin (nativeObject, out strokeJoin);
  61. GDIPlus.CheckStatus (status);
  62. return strokeJoin;
  63. }
  64. set {
  65. Status status = GDIPlus.GdipSetCustomLineCapStrokeJoin (nativeObject, value);
  66. GDIPlus.CheckStatus (status);
  67. }
  68. }
  69. public float BaseInset {
  70. get {
  71. float baseInset;
  72. Status status = GDIPlus.GdipGetCustomLineCapBaseInset (nativeObject, out baseInset);
  73. GDIPlus.CheckStatus (status);
  74. return baseInset;
  75. }
  76. set {
  77. Status status = GDIPlus.GdipSetCustomLineCapBaseInset (nativeObject, value);
  78. GDIPlus.CheckStatus (status);
  79. }
  80. }
  81. public float WidthScale {
  82. get {
  83. float widthScale;
  84. Status status = GDIPlus.GdipGetCustomLineCapWidthScale (nativeObject, out widthScale);
  85. GDIPlus.CheckStatus (status);
  86. return widthScale;
  87. }
  88. set {
  89. Status status = GDIPlus.GdipSetCustomLineCapWidthScale (nativeObject, value);
  90. GDIPlus.CheckStatus (status);
  91. }
  92. }
  93. // Public Methods
  94. public virtual object Clone ()
  95. {
  96. IntPtr clonePtr;
  97. Status status = GDIPlus.GdipCloneCustomLineCap (nativeObject, out clonePtr);
  98. GDIPlus.CheckStatus (status);
  99. return new CustomLineCap (clonePtr);
  100. }
  101. public virtual void Dispose ()
  102. {
  103. Dispose (true);
  104. System.GC.SuppressFinalize (this);
  105. }
  106. protected virtual void Dispose (bool disposing)
  107. {
  108. if (! disposed) {
  109. Status status = GDIPlus.GdipDeleteCustomLineCap (nativeObject);
  110. GDIPlus.CheckStatus (status);
  111. disposed = true;
  112. nativeObject = IntPtr.Zero;
  113. }
  114. }
  115. ~CustomLineCap ()
  116. {
  117. Dispose (false);
  118. }
  119. public void GetStrokeCaps (out LineCap startCap, out LineCap endCap)
  120. {
  121. Status status = GDIPlus.GdipGetCustomLineCapStrokeCaps (nativeObject, out startCap, out endCap);
  122. GDIPlus.CheckStatus (status);
  123. }
  124. public void SetStrokeCaps(LineCap startCap, LineCap endCap)
  125. {
  126. Status status = GDIPlus.GdipSetCustomLineCapStrokeCaps (nativeObject, startCap, endCap);
  127. GDIPlus.CheckStatus (status);
  128. }
  129. }
  130. }