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