source: trunk/ab5.0/ablib/src/Classes/System/Drawing/Brush.ab@ 701

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

BrushとStringFormatを追加
(#241)

File size: 16.7 KB
Line 
1' Classes/System/Drawing/Brush.ab
2
3Namespace System
4Namespace Drawing
5
6Class Brush
7 Implements IDisposable, ICloneable
8Public
9 Sub Dispose()
10 GdipDeleteBrush(nativeBrush)
11 nativeBrush = 0
12 End Sub
13
14 Sub ~Brush()
15 Dispose()
16 End Sub
17
18 Function Clone() As Brush
19 Dim brush As *GpBrush
20 SetStatus(GdipCloneBrush(nativeBrush, brush))
21 Try
22 Clone = New Brush(brush)
23 Catch e As Exception
24 GdipDeleteBrush(brush)
25 Throw e
26 End Try
27 End Function
28
29 Function GetType() As BrushType
30 GetType = -1 As BrushType
31 SetStatus(GdipGetBrushType(nativeBrush, GetType))
32 End Function
33
34 Function NativeBrush() As *GpBrush
35 NativeBrush = nativeBrush
36 End Function
37
38 Sub Brush(native As *GpBrush)
39 nativeBrush = native
40 End Sub
41
42Private
43 nativeBrush As *GpBrush
44End Class
45
46Class SolidBrush
47 Inherits Brush
48Public
49
50 Sub SolidBrush(c As Color)
51 Brush(CreateSolidBrush(c))
52 End Sub
53
54 Function Color() As Color
55 SetStatus(GdipGetSolidFillColor(nativeBrush As *GpSolidFill, Color))
56 End Function
57
58 Sub SetColor(c As Color)
59 SetStatus(GdipSetSolidFillColor(nativeBrush As *GpSolidFill, c))
60 End Sub
61
62Private
63 Static Function CreateSolidBrush(c As Color) As *GpBrush
64 SetStatus(GdipCreateSolidFill(c, CreateSolidBrush))
65 End Function
66End Class
67
68Class TextureBrush
69 Inherits Brush
70Public
71 Sub TextureBrush(image As Image) '暫定
72 Brush(CreateTexture(image.NativeImage, System.Drawing.Drawing2D.WrapMode.Tile) As *GpBrush)
73 End Sub
74
75 Sub TextureBrush(image As Image, wrapMode /*= WrapMode.Tile*/ As Drawing2D.WrapMode)
76 Brush(CreateTexture(image.NativeImage, wrapMode) As *GpBrush)
77 End Sub
78
79 Static Function CreateTexture(image As *GpImage, wrapMode As Drawing2D.WrapMode) As *GpTexture
80 SetStatus(GdipCreateTexture(image, wrapMode, CreateTexture))
81 End Function
82
83 Sub TextureBrush(image As Image, wrapMode As Drawing2D.WrapMode, ByRef dstRect As Rectangle)
84 Brush(CreateTexture2I(image.NativeImage, wrapMode, dstRect) As *GpBrush)
85 End Sub
86
87 Static Function CreateTexture2I(image As *GpImage, wrapMode As Drawing2D.WrapMode, ByRef rc As Rectangle) As *GpTexture
88 SetStatus(GdipCreateTexture2I(image, wrapMode, rc.X, rc.Y, rc.Width, rc.Height, CreateTexture2I))
89 End Function
90
91 Sub TextureBrush(image As Image, wrapMode As Drawing2D.WrapMode, ByRef dstRect As RectangleF)
92 Brush(CreateTexture2(image.NativeImage, wrapMode, dstRect) As *GpBrush)
93 End Sub
94
95 Static Function CreateTexture2(image As *GpImage, wrapMode As Drawing2D.WrapMode, ByRef rc As RectangleF) As *GpTexture
96 SetStatus(GdipCreateTexture2(image, wrapMode, rc.X, rc.Y, rc.Width, rc.Height, CreateTexture2))
97 End Function
98
99 Sub TextureBrush(image As Image, ByRef dstRect As Rectangle, imageAttributes = Nothing As ImageAttributes)
100 Brush(CreateTextureIAI(image.NativeImage, dstRect, getNativeImageAttributes(imageAttributes)) As *GpBrush)
101 End Sub
102
103 Static Function CreateTextureIAI(image As *GpImage, ByRef rc As Rectangle, imageAttr = 0 As *GpImageAttributes) As *GpTexture
104 SetStatus(GdipCreateTextureIAI(image, imageAttr, rc.X, rc.Y, rc.Width, rc.Height, CreateTextureIAI))
105 End Function
106
107 Sub TextureBrush(image As Image, ByRef dstRect As RectangleF, imageAttributes = Nothing As ImageAttributes)
108 Brush(CreateTextureIA(image.NativeImage, dstRect, getNativeImageAttributes(imageAttributes)) As *GpBrush)
109 End Sub
110
111 Static Function CreateTextureIA(image As *GpImage, ByRef rc As RectangleF, imageAttr = 0 As *GpImageAttributes) As *GpTexture
112 SetStatus(GdipCreateTextureIA(image, imageAttr, rc.X, rc.Y, rc.Width, rc.Height, CreateTextureIA))
113 End Function
114
115 Sub Transform(matrix As Drawing2D.Matrix)
116 SetStatus(GdipSetTextureTransform(nativeBrush As *GpTexture, matrix.NativeMatrix))
117 End Sub
118
119 Function Transform() As Drawing2D.Matrix
120 Dim matrix As *GpMatrix
121 SetStatus(GdipGetTextureTransform(nativeBrush As *GpTexture, matrix))
122 Transform = New Matrix(matrix)
123 End Function
124
125 Sub ResetTransform()
126 SetStatus(GdipResetTextureTransform(nativeBrush As *GpTexture))
127 End Sub
128
129 Sub MultiplyTransform(matrix As Drawing2D.Matrix, order /*= Drawing2D.MatrixOrder.Prepend*/ As Drawing2D.MatrixOrder)
130 SetStatus(GdipMultiplyTextureTransform(nativeBrush As *GpTexture, matrix.NativeMatrix, order))
131 End Sub
132
133 Sub TranslateTransform(dx As Single, dy As Single, order /*= Drawing2D.MatrixOrder.Prepend*/ As Drawing2D.MatrixOrder)
134 SetStatus(GdipTranslateTextureTransform(nativeBrush As *GpTexture, dx, dy, order))
135 End Sub
136
137 Sub ScaleTransform(sx As Single, sy As Single, order /*= Drawing2D.MatrixOrder.Prepend*/ As Drawing2D.MatrixOrder)
138 SetStatus(GdipScaleTextureTransform(nativeBrush As *GpTexture, sx, sy, order))
139 End Sub
140
141 Sub RotateTransform(angle As Single, order /*= Drawing2D.MatrixOrder.Prepend*/ As Drawing2D.MatrixOrder)
142 SetStatus(GdipRotateTextureTransform(nativeBrush As *GpTexture, angle, order))
143 End Sub
144
145 Sub WrapMode(wrapMode As Drawing2D.WrapMode)
146 SetStatus(GdipSetTextureWrapMode(nativeBrush As *GpTexture, wrapMode))
147 End Sub
148/*
149 Function WrapMode() As Drawing2D.WrapMode
150 SetStatus(GdipGetTextureWrapMode(nativeBrush As *GpTexture, WrapMode))
151 End Function
152*/
153 Function GetImage() As Image
154 Dim image As *GpImage
155 SetStatus(GdipGetTextureImage(nativeBrush As *GpTexture, image))
156 GetImage = New Image(image)
157 End Function
158
159Private
160 Static Function getNativeImageAttributes(imageAttr As ImageAttributes) As *GpImageAttributes
161 If ActiveBasic.IsNothing(imageAttr) Then
162 getNativeImageAttributes = 0
163 Else
164 getNativeImageAttributes = imageAttr.nativeImage
165 End If
166 End Function
167End Class
168
169Namespace Drawing2D
170
171Class HatchBrush
172 Inherits Brush
173Public
174 Sub HatchBrush(hatchStyle As HatchStyle, foreColor As Color, backColor = 0 As Color)
175 Brush(CreateHatchBrush(hatchStyle, foreColor, backColor) As *GpBrush)
176 End Sub
177/*
178 Function HatchStyle() As HatchStyle
179 SetStatus(GdipGetHatchStyle(NativeBrush As *GpHatch, HatchStyle))
180 End Function
181*/
182 Function ForegroundColor() As Color
183 SetStatus(GdipGetHatchForegroundColor(NativeBrush As *GpHatch, ForegroundColor))
184 End Function
185
186 Function BackgroundColor() As Color
187 SetStatus(GdipGetHatchBackgroundColor(NativeBrush As *GpHatch, BackgroundColor))
188 End Function
189
190Private
191 Static Function CreateHatchBrush(hatchStyle As HatchStyle, foreColor As ARGB, backColor As ARGB) As *GpHatch
192 SetStatus(GdipCreateHatchBrush(hatchStyle, foreColor, backColor, CreateHatchBrush))
193 End Function
194End Class
195
196Class LinearGradientBrush
197 Inherits Brush
198Public
199
200 Sub LinearGradientBrush(ByRef pt1 As Point, ByRef pt2 As Point, c1 As Color, c2 As Color)
201 Brush(CreateLineBrush(pt1, pt2, c1, c2) As *GpBrush)
202 End Sub
203
204 Sub LinearGradientBrush(ByRef pt1 As PointF, ByRef pt2 As PointF, c1 As Color, c2 As Color)
205 Brush(CreateLineBrush(pt1, pt2, c1, c2) As *GpBrush)
206 End Sub
207
208 Sub LinearGradientBrush(ByRef rc As Rectangle, c1 As Color, c2 As Color, mode As LinearGradientMode)
209 Brush(CreateLineBrushFromRect(rc, c1, c2, mode) As *GpBrush)
210 End Sub
211
212 Sub LinearGradientBrush(ByRef rc As RectangleF, c1 As Color, c2 As Color, mode As LinearGradientMode)
213 Brush(CreateLineBrushFromRect(rc, c1, c2, mode) As *GpBrush)
214 End Sub
215
216 Sub LinearGradientBrush(ByRef rc As Rectangle, c1 As Color, c2 As Color, angle As Single, isAngleScalable = False As Boolean)
217 Brush(CreateLineBrushFromRectWithAngle(rc, c1, c2, angle, isAngleScalable) As *GpBrush)
218 End Sub
219
220 Sub LinearGradientBrush(ByRef rc As RectangleF, c1 As Color, c2 As Color, angle As Single, isAngleScalable = False As Boolean)
221 Brush(CreateLineBrushFromRectWithAngle(rc, c1, c2, angle, isAngleScalable) As *GpBrush)
222 End Sub
223
224 Static Function CreateLineBrush(ByRef pt1 As Point, ByRef pt2 As Point, c1 As ARGB, c2 As ARGB) As *GpLineGradient
225 SetStatus(GdipCreateLineBrushI(pt1, pt2, c1, c2, WrapMode.Tile, CreateLineBrush))
226 End Function
227
228 Static Function CreateLineBrush(ByRef pt1 As PointF, ByRef pt2 As PointF, c1 As ARGB, c2 As ARGB) As *GpLineGradient
229 SetStatus(GdipCreateLineBrush(pt1, pt2, c1, c2, WrapMode.Tile, CreateLineBrush))
230 End Function
231
232 Static Function CreateLineBrushFromRect(ByRef rc As Rectangle, c1 As ARGB, c2 As ARGB, mode As LinearGradientMode) As *GpLineGradient
233 SetStatus(GdipCreateLineBrushFromRectI(rc, c1, c2, mode, 0 /*WrapMode.Tile*/, CreateLineBrushFromRect))
234 End Function
235
236 Static Function CreateLineBrushFromRect(ByRef rc As RectangleF, c1 As ARGB, c2 As ARGB, mode As LinearGradientMode) As *GpLineGradient
237 SetStatus(GdipCreateLineBrushFromRect(rc, c1, c2, mode, 0 /*WrapMode.Tile*/, CreateLineBrushFromRect))
238 End Function
239
240 Static Function CreateLineBrushFromRectWithAngle(ByRef rc As Rectangle, c1 As ARGB, c2 As ARGB, angle As Single, isAngleScalable As Boolean) As *GpLineGradient
241 SetStatus(GdipCreateLineBrushFromRectWithAngleI(rc, c1, c2, angle, isAngleScalable, 0 /*WrapMode.Tile*/ , CreateLineBrushFromRectWithAngle))
242 End Function
243
244 Static Function CreateLineBrushFromRectWithAngle(ByRef rc As RectangleF, c1 As ARGB, c2 As ARGB, angle As Single, isAngleScalable As Boolean) As *GpLineGradient
245 SetStatus(GdipCreateLineBrushFromRectWithAngle(rc, c1, c2, angle, isAngleScalable, 0 /*WrapMode.Tile*/, CreateLineBrushFromRectWithAngle))
246 End Function
247
248 'LinearColors - GdipGetLineColors/GdipSetLineColors
249
250 Function Rectangle() As RectangleF
251 SetStatus(GdipGetLineRect(nativeBrush As *GpLineGradient, Rectangle))
252 End Function
253
254 Sub GammaCorrection(gammaCorrection As Boolean)
255 SetStatus(GdipSetLineGammaCorrection(nativeBrush As *GpLineGradient, gammaCorrection))
256 End Sub
257
258 Function GammaCorrection() As Boolean
259 Dim gammaCorrection As BOOL
260 SetStatus(GdipGetLineGammaCorrection(nativeBrush As *GpLineGradient, gammaCorrection))
261 GammaCorrection = gammaCorrection As Boolean
262 End Function
263
264 'Blend - GdipGetLineBlend/GdipSetLineBlend
265 'InterpolationColors - GdipGetLinePresetBlend/GdipSetLinePresetBlend
266
267 Sub SetBlendBellShape(focus As Single, scale = 1.0 As Single)
268 SetStatus(GdipSetLineSigmaBlend(nativeBrush As *GpLineGradient, focus, scale))
269 End Sub
270
271 Sub SetBlendTriangularShape(focus As Single, scale = 1.0 As Single)
272 SetStatus(GdipSetLineLinearBlend(nativeBrush As *GpLineGradient, focus, scale))
273 End Sub
274
275 Sub Transform(matrix As Matrix)
276 SetStatus(GdipSetLineTransform(nativeBrush As *GpLineGradient, matrix.NativeMatrix))
277 End Sub
278
279 Function Transform() As Matrix
280 Dim matrix As *GpMatrix
281 SetStatus(GdipGetLineTransform(nativeBrush As *GpLineGradient, matrix))
282 Transform = New Matrix(matrix)
283 End Function
284
285 Sub ResetTransform()
286 SetStatus(GdipResetLineTransform(nativeBrush As *GpLineGradient))
287 End Sub
288
289 Sub MultiplyTransform(matrix As Drawing2D.Matrix, order /*= MatrixOrder.Prepend*/ As MatrixOrder)
290 SetStatus(GdipMultiplyLineTransform(nativeBrush As *GpLineGradient, matrix.NativeMatrix, order))
291 End Sub
292
293 Sub TranslateTransform(dx As Single, dy As Single, order /*= MatrixOrder.Prepend*/ As MatrixOrder)
294 SetStatus(GdipTranslateLineTransform(nativeBrush As *GpLineGradient, dx, dy, order))
295 End Sub
296
297 Sub ScaleTransform(sx As Single, sy As Single, order /*= MatrixOrder.Prepend*/ As MatrixOrder)
298 SetStatus(GdipScaleLineTransform(nativeBrush As *GpLineGradient, sx, sy, order))
299 End Sub
300
301 Sub RotateTransform(angle As Single, order /*= MatrixOrder.Prepend*/ As MatrixOrder)
302 SetStatus(GdipRotateLineTransform(nativeBrush As *GpLineGradient, angle, order))
303 End Sub
304
305 Sub WrapMode(wrapMode As WrapMode)
306 SetStatus(GdipSetLineWrapMode(nativeBrush As *GpLineGradient, wrapMode))
307 End Sub
308/*
309 Function WrapMode() As WrapMode
310 SetStatus(GdipGetLineWrapMode(nativeBrush As *GpLineGradient, WrapMode))
311 End Function
312*/
313End Class
314
315Class PathGradientBrush
316 Inherits Brush
317Public
318 Sub PathGradientBrush(points As *PointF, count As Long, wrapMode /*= WrapMode.Clamp*/ As WrapMode)
319 Brush(CreatePathGradient(points, count, wrapMode))
320 End Sub
321
322 Sub PathGradientBrush(points As *Point, count As Long, wrapMode /*= WrapMode.Clamp*/ As WrapMode)
323 Brush(CreatePathGradientI(points, count, wrapMode))
324 End Sub
325
326 Sub PathGradientBrush(path As GraphicsPath)
327 Brush(CreatePathGradientFromPath(path.NativePath As *GpBrush))
328 End Sub
329
330 Sub CenterColor(c As Color)
331 SetStatus(GdipSetPathGradientCenterColor(nativeBrush As *GpPathGradient, c))
332 End Sub
333
334 Function CenterColor() As Color
335 SetStatus(GdipGetPathGradientCenterColor(nativeBrush As *GpPathGradient, CenterColor))
336 End Function
337
338 'SurroundColors - GdipGetPathGradientSurroundColorsWithCount/GdipSetPathGradientSurroundColorsWithCount/GdipGetPathGradientSurroundColorCount
339
340 Sub GraphicsPath(path As GraphicsPath)
341 If ActiveBasic.IsNothing(path) Then
342 Throw New System.ArgumentNullException("path")
343 End If
344 SetStatus(GdipSetPathGradientPath(nativeBrush As *GpPathGradient, path.NativePath))
345 End Sub
346
347 Function GraphicsPath() As GraphicsPath
348 Dim path As *GpPath
349 SetStatus(GdipGetPathGradientPath(nativeBrush As *GpPathGradient, path))
350 GraphicsPath = New GraphicsPath(path)
351 End Function
352
353 Sub CenterPoint(ByRef pt As PointF)
354 SetStatus(GdipSetPathGradientCenterPoint(nativeBrush As *GpPathGradient, pt))
355 End Sub
356
357 Function CenterPoint() As PointF
358 SetStatus(GdipSetPathGradientCenterPoint(nativeBrush As *GpPathGradient, CenterPoint))
359 End Function
360
361 Function Rectangle() As RectangleF
362 SetStatus(GdipGetPathGradientRect(nativeBrush As *GpPathGradient, Rectangle))
363 End Function
364
365 Sub GammaCorrection(gammaCorrection As Boolean)
366 SetStatus(GdipSetPathGradientGammaCorrection(nativeBrush As *GpPathGradient, gammaCorrection))
367 End Sub
368
369 Function GammaCorrection() As Boolean
370 Dim gammaCorrection As BOOL
371 SetStatus(GdipGetPathGradientGammaCorrection(nativeBrush As *GpPathGradient, gammaCorrection))
372 GammaCorrection = gammaCorrection As Boolean
373 End Function
374
375 ' Blend - GdipGetPathGradientBlend/GdipSetPathGradientBlend/GdipGetPathGradientBlendCount
376 ' InterpolationColors - GdipGetPathGradientPresetBlend/GdipSetPathGradientPresetBlend/GdipGetPathGradientPresetBlendCount
377
378 Sub SetBlendBellShape(focus As Single, scale = 1.0 As Single)
379 SetStatus(GdipSetPathGradientSigmaBlend(nativeBrush As *GpPathGradient, focus, scale))
380 End Sub
381
382 Sub SetBlendTriangularShape(focus As Single, scale = 1.0 As Single)
383 SetStatus(GdipSetPathGradientLinearBlend(nativeBrush As *GpPathGradient, focus, scale))
384 End Sub
385
386 Sub Transform(matrix As Matrix)
387 SetStatus(GdipSetPathGradientTransform(nativeBrush As *GpPathGradient, matrix.NativeMatrix))
388 End Sub
389
390 Function Transform() As Matrix
391 Dim matrix As *GpMatrix
392 SetStatus(GdipGetPathGradientTransform(nativeBrush As *GpPathGradient, matrix))
393 Transform = New Matrix(matrix)
394 End Function
395
396 Sub ResetTransform()
397 SetStatus(GdipResetPathGradientTransform(nativeBrush As *GpPathGradient))
398 End Sub
399
400 Sub MultiplyTransform(matrix As Drawing2D.Matrix, order /*= MatrixOrder.Prepend*/ As MatrixOrder)
401 SetStatus(GdipMultiplyPathGradientTransform(nativeBrush As *GpPathGradient, matrix.NativeMatrix, order))
402 End Sub
403
404 Sub TranslateTransform(dx As Single, dy As Single, order /*= MatrixOrder.Prepend*/ As MatrixOrder)
405 SetStatus(GdipTranslatePathGradientTransform(nativeBrush As *GpPathGradient, dx, dy, order))
406 End Sub
407
408 Sub ScaleTransform(sx As Single, sy As Single, order /*= MatrixOrder.Prepend*/ As MatrixOrder)
409 SetStatus(GdipScalePathGradientTransform(nativeBrush As *GpPathGradient, sx, sy, order))
410 End Sub
411
412 Sub RotateTransform(angle As Single, order /*= MatrixOrder.Prepend*/ As MatrixOrder)
413 SetStatus(GdipRotatePathGradientTransform(nativeBrush As *GpPathGradient, angle, order))
414 End Sub
415
416 Function FocusScales() As PointF
417 SetStatus(GdipGetPathGradientFocusScales(nativeBrush As *GpPathGradient, FocusScales.X, FocusScales.Y))
418 End Function
419
420 Sub FocusScales(scale As PointF)
421 SetStatus(GdipSetPathGradientFocusScales(nativeBrush As *GpPathGradient, scale.X, scale.Y))
422 End Sub
423
424 Sub WrapMode(wrapMode As WrapMode)
425 SetStatus(GdipSetPathGradientWrapMode(nativeBrush As *GpPathGradient, wrapMode))
426 End Sub
427/*
428 Function WrapMode() As WrapMode
429 SetStatus(GdipGetPathGradientWrapMode(nativeBrush As *GpPathGradient, WrapMode))
430 End Function
431*/
432Private
433 Static Function CreatePathGradient(points As *PointF, count As Long, wrapMode As WrapMode) As *GpPathGradient
434 SetStatus(GdipCreatePathGradient(points, count, wrapMode, CreatePathGradient))
435 End Function
436
437 Static Function CreatePathGradientI(points As *Point, count As Long, wrapMode As WrapMode) As *GpPathGradient
438 SetStatus(GdipCreatePathGradientI(points, count, wrapMode, CreatePathGradientI))
439 End Function
440
441 Static Function CreatePathGradientFromPath(path As *GpPath) As *GpPathGradient
442 SetStatus(GdipCreatePathGradientFromPath(path, CreatePathGradientFromPath))
443 End Function
444End Class
445
446End Namespace
447
448End Namespace
449End Namespace
Note: See TracBrowser for help on using the repository browser.