source: trunk/ab5.0/ablib/src/Classes/System/Drawing/Pen.ab@ 698

Last change on this file since 698 was 698, checked in by イグトランス (egtra), 15 years ago

GDI+をコンパイルできるように修正。FontFamily, Penの追加。サンプルとして、Step 32のGDI+版を制作。
(#56)

File size: 7.7 KB
Line 
1' Classes/System/Drawing/Pen.ab
2
3Namespace System
4Namespace Drawing
5
6Namespace Drawing2D
7Class CustomLineCap
8Public
9 Function NativeCap() As *GpCustomLineCap
10 End Function
11End Class
12End Namespace
13
14Class Pen
15 Implements IDisposable, ICloneable
16Public
17 Sub Pen(native As *GpPen)
18 nativePen = native
19 End Sub
20
21 Sub Pen(color As Color, width = 1.0 As Single)
22 SetStatus(GdipCreatePen1(color, width, 0 /*GraphicsUnit.World As GpUnit*/, nativePen))
23 End Sub
24
25 Sub Pen(brush As Brush, width = 1.0 As Single)
26 If ActiveBasic.IsNothing(brush) Then
27 Throw New ArgumentNullException("brush")
28 End If
29 SetStatus(GdipCreatePen2(brush.nativeBrush, width, 0 /*GraphicsUnit.World As GpUnit*/, nativePen))
30 End Sub
31
32 Sub Dispose()
33 If nativePen <> 0 Then
34 GdipDeletePen(nativePen)
35 End If
36 nativePen = 0
37 End Sub
38
39 Sub ~Pen()
40 Dispose()
41 End Sub
42
43 Function Clone() As Pen
44 Dim cloned As *GpPen
45 SetStatus(GdipClonePen(nativePen, cloned))
46 Clone = New Pen(cloned)
47 End Function
48
49 Function NativePen() As *GpPen
50 NativePen = nativePen
51 End Function
52
53 '=========================================================================
54 ' Properties
55 '=========================================================================
56
57 Sub Width(width As Single)
58 SetStatus(GdipSetPenWidth(nativePen, width))
59 End Sub
60
61 Function Width() As Single
62 SetStatus(GdipGetPenWidth(nativePen, Width))
63 End Function
64
65 Sub StartCap(cap As Drawing2D.LineCap)
66 SetStatus(GdipSetPenStartCap(nativePen, cap))
67 End Sub
68/*
69 Function StartCap() As Drawing2D.LineCap
70 SetStatus(GdipGetPenStartCap(nativePen, StartCap))
71 End Function
72*/
73 Sub EndCap(cap As Drawing2D.LineCap)
74 SetStatus(GdipSetPenEndCap(nativePen, cap))
75 End Sub
76/*
77 Function EndCap() As Drawing2D.LineCap
78 SetStatus(GdipGetPenEndCap(nativePen, EndCap))
79 End Function
80*/
81 Sub DashCap(cap As Drawing2D.DashCap)
82 SetStatus(GdipSetPenDashCap197819(nativePen, cap))
83 End Sub
84/*
85 Function DashCap() As Drawing2D.DashCap
86 SetStatus(GdipGetPenDashCap197819(nativePen, DashCap))
87 End Function
88*/
89 Sub LineJoin(lineJoin As Drawing2D.LineJoin)
90 SetStatus(GdipSetPenLineJoin(nativePen, lineJoin))
91 End Sub
92/*
93 Function LineJoin() As Drawing2D.LineJoin
94 SetStatus(GdipGetPenLineJoin(nativePen, LineJoin))
95 End Function
96*/
97 Sub CustomStartCap(cap As Drawing2D.CustomLineCap)
98 SetStatus(GdipSetPenCustomStartCap(nativePen, getNativeCustomCap(cap)))
99 End Sub
100/*
101 Function CustomStartCap() As Drawing2D.CustomLineCap
102 Dim native As *GpCustomLineCap
103 SetStatus(GdipGetPenCustomStartCap(nativePen, native))
104 CustomStartCap = New Drawing2D.CustomStartCap(native)
105 End Function
106*/
107 Sub CustomEndCap(cap As Drawing2D.CustomLineCap)
108 SetStatus(GdipSetPenCustomEndCap(nativePen, getNativeCustomCap(cap)))
109 End Sub
110/*
111 Function CustomEndCap() As Drawing2D.CustomLineCap
112 Dim nativeCustomCap As *GpCustomLineCap
113 SetStatus(GdipGetPenCustomEndCap(nativePen, nativeCustomCap))
114 CustomStartCap = New CustomStartCap(nativeCustomCap)
115 End Function
116*/
117 Sub MiterLimit(miterLimit As Single)
118 SetStatus(GdipSetPenMiterLimit(nativePen, miterLimit))
119 End Sub
120
121 Function MiterLimit() As Single
122 SetStatus(GdipGetPenMiterLimit(nativePen, MiterLimit))
123 End Function
124
125 Sub Alignment(alignment As Drawing2D.PenAlignment)
126 SetStatus(GdipSetPenMode(nativePen, alignment))
127 End Sub
128/*
129 Function Alignment() As Drawing2D.PenAlignment
130 SetStatus(GdipGetPenMode(nativePen, Alignment))
131 End Function
132*/
133 Sub Transform(m As Drawing2D.Matrix)
134 SetStatus(GdipSetPenTransform(nativePen, m.NativeMatrix))
135 End Sub
136
137 Function Transform() As Drawing2D.Matrix
138 Dim native As *GpMatrix
139 SetStatus(GdipGetPenTransform(nativePen, native))
140 Transform = New Matrix(native)
141 End Function
142/*
143 Function PenType() As Drawing2D.PenType
144 SetStatus(GdipGetPenFillType(nativePen, PenType))
145 End Function
146*/
147 Sub Color(color As Color)
148 SetStatus(GdipSetPenColor(nativePen, color))
149 End Sub
150/*
151 Function Color() As Color
152 If This.PenType <> Drawing2D.PenType.SolidColor Then
153 SetStatus(State.WrongState)
154 End If
155 SetStatus(GdipGetPenColor(nativePen, Color))
156 End Function
157*/
158 Sub Brush(brush As Brush)
159 SetStatus(GdipSetPenBrushFill(nativePen, getNativeBrush(brush)))
160 End Sub
161/*
162 Function Brush() As Brush
163 Imports Drawing2D
164 Dim penType = PenType
165 Dim native As *GpBrush
166 Select Case penType
167 Case PenType.SolidColor
168 SetStatus(GdipGetPenBrushFill(nativePen, native))
169 Brush = New SolidBrush(native)
170 Case PenType.HatchFill
171 SetStatus(GdipGetPenBrushFill(nativePen, native))
172 Brush = New HatchBrush(native)
173 Case PenType.TextureFill
174 SetStatus(GdipGetPenBrushFill(nativePen, native))
175 Brush = New TextureBrush(native)
176 Case PenType.Gradient
177 SetStatus(GdipGetPenBrushFill(nativePen, native))
178 Brush = New Brush(native)
179 Case PenType.LinearGradient
180 SetStatus(GdipGetPenBrushFill(nativePen, native))
181 Brush = New LinearGradientBrush(native)
182 Case Else
183 Brush = Nothing
184 End Select
185 End Function
186*/
187 Sub DashStyle(dashStyle As Drawing2D.DashStyle)
188 SetStatus(GdipSetPenDashStyle(nativePen, dashStyle))
189 End Sub
190/*
191 Function DashStyle() As Drawing2D.DashStyle
192 SetStatus(GdipGetPenDashStyle(nativePen, DashStyle))
193 End Function
194*/
195 Sub DashOffset(dashOffset As Single)
196 SetStatus(GdipSetPenDashOffset(nativePen, dashOffset))
197 End Sub
198
199 Function DashOffset() As Single
200 SetStatus(GdipGetPenDashOffset(nativePen, DashOffset))
201 End Function
202
203 'DashPattern
204 'CompoundArray
205
206 '=========================================================================
207 ' Functions
208 '=========================================================================
209
210 Sub SetLineCap(startCap As Drawing2D.LineCap, endCap As Drawing2D.LineCap, dashCap As Drawing2D.DashCap)
211 SetStatus(GdipSetPenLineCap197819(nativePen, startCap, endCap, dashCap))
212 End Sub
213
214 Sub ResetTransform()
215 SetStatus(GdipResetPenTransform(nativePen))
216 End Sub
217
218 Sub MultiplyTransform(m As Drawing2D.Matrix)
219 Imports System.Drawing.Drawing2D
220 MultiplyTransform(m, MatrixOrder.Prepend)
221 End Sub
222
223 Sub MultiplyTransform(m As Drawing2D.Matrix, order As Drawing2D.MatrixOrder)
224 SetStatus(GdipMultiplyPenTransform(nativePen, m.nativeMatrix, order))
225 End Sub
226
227 Sub TranslateTransform(dx As Single, dy As Single)
228 Imports System.Drawing.Drawing2D
229 TranslateTransform(dx, dy, MatrixOrder.Prepend)
230 End Sub
231
232 Sub TranslateTransform(dx As Single, dy As Single, order As Drawing2D.MatrixOrder)
233 SetStatus(GdipTranslatePenTransform(nativePen, dx, dy, order))
234 End Sub
235
236 Sub ScaleTransform(sx As Single, sy As Single)
237 Imports System.Drawing.Drawing2D
238 ScaleTransform(sx, sy, MatrixOrder.Prepend)
239 End Sub
240
241 Sub ScaleTransform(sx As Single, sy As Single, order As Drawing2D.MatrixOrder)
242 SetStatus(GdipScalePenTransform(nativePen, sx, sy, order))
243 End Sub
244
245 Sub RotateTransform(angle As Single)
246 Imports System.Drawing.Drawing2D
247 RotateTransform(angle, MatrixOrder.Prepend)
248 End Sub
249
250 Sub RotateTransform(angle As Single, order As Drawing2D.MatrixOrder)
251 SetStatus(GdipRotatePenTransform(nativePen, angle, order))
252 End Sub
253
254Private
255
256 nativePen As *GpPen
257
258 Static Function getNativeCustomCap(cap As Drawing2D.CustomLineCap) As *GpCustomLineCap
259 If ActiveBasic.IsNothing(cap) Then
260 getNativeCustomCap = 0
261 Else
262 getNativeCustomCap = cap.NativeCap
263 End If
264 End Function
265
266 Static Function getNativeBrush(br As Brush) As *GpBrush
267 If ActiveBasic.IsNothing(br) Then
268 getNativeBrush = 0
269 Else
270 getNativeBrush = br.nativeBrush
271 End If
272 End Function
273
274End Class
275
276End Namespace
277End Namespace
Note: See TracBrowser for help on using the repository browser.