-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathGraphics.cls
510 lines (450 loc) · 15.3 KB
/
Graphics.cls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "GDIPGraphics"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
Private m_gfx As Long
Private m_lastResult As GpStatus
Private m_DrawStringRect As RECTF 'null layout seems to mean automatic
Private m_DrawStringFormat As Long
Friend Property Get nativeGraphics() As Long
nativeGraphics = m_gfx
End Property
Public Function GetDpiX() As Single
SetStatus GdipGetDpiX(m_gfx, GetDpiX)
End Function
Public Sub FromHDC(ByVal lhDC As Long)
Dispose
SetStatus GdipCreateFromHDC(lhDC, m_gfx), "FromHDC()"
End Sub
Public Sub FromHDCDevice(ByVal lhDC As Long, ByVal hDevice As Long)
Dispose
SetStatus GdipCreateFromHDC2(lhDC, hDevice, m_gfx), "FromHDCDevice()"
End Sub
Public Sub FromHWnd(ByVal lHWnd As Long)
Dispose
SetStatus GdipCreateFromHWND(lHWnd, m_gfx), "FromhWnd()"
End Sub
Public Sub FromImage(Image As GDIPImage)
Dispose
SetStatus GdipGetImageGraphicsContext(Image.nativeImage, m_gfx)
End Sub
Public Sub Flush(ByVal intention As FlushIntention)
GdipFlush m_gfx, intention
End Sub
Public Function GetHDC() As Long
Dim lhDC As Long
m_lastResult = GdipGetDC(m_gfx, lhDC)
GetHDC = lhDC
End Function
Public Function ReleaseHDC(ByVal hdc As Long)
m_lastResult = GdipReleaseDC(m_gfx, hdc)
End Function
Public Function SetRenderingOrigin(ByVal X As Long, ByVal Y As Long) As GpStatus
SetRenderingOrigin = SetStatus( _
GdipSetRenderingOrigin( _
m_gfx, X, Y) _
)
End Function
Public Function GetRenderingOrigin(ByRef X As Long, ByRef Y As Long) As GpStatus
GetRenderingOrigin = SetStatus( _
GdipGetRenderingOrigin( _
m_gfx, X, Y) _
)
End Function
Public Property Let CompositingMode(ByVal Value As CompositingMode)
SetStatus GdipSetCompositingMode(m_gfx, Value)
End Property
Public Property Get CompositingMode() As CompositingMode
Dim mode As CompositingMode
SetStatus GdipGetCompositingMode(m_gfx, mode)
CompositingMode = mode
End Property
Public Property Let CompositingQuality(ByVal Value As CompositingQuality)
SetStatus GdipSetCompositingQuality(m_gfx, Value)
End Property
Public Property Get CompositingQuality() As CompositingQuality
Dim Value As CompositingQuality
SetStatus GdipGetCompositingQuality(m_gfx, Value)
CompositingQuality = Value
End Property
Public Property Let TextRenderingHint(ByVal Value As TextRenderingHint)
SetStatus GdipSetTextRenderingHint(m_gfx, Value)
End Property
Public Property Get TextRenderingHint() As TextRenderingHint
Dim Value As TextRenderingHint
SetStatus GdipGetTextRenderingHint(m_gfx, Value)
TextRenderingHint = Value
End Property
Public Property Let TextContrast(ByVal Value As Long)
SetStatus GdipSetTextContrast(m_gfx, Value)
End Property
Public Property Get TextContrast() As Long
Dim Value As Long
SetStatus GdipGetTextContrast(m_gfx, Value)
TextContrast = Value
End Property
Public Property Let InterpolationMode(ByVal Value As InterpolationMode)
SetStatus GdipSetInterpolationMode(m_gfx, Value)
End Property
Public Property Get InterpolationMode() As InterpolationMode
Dim Value As InterpolationMode
SetStatus GdipGetInterpolationMode(m_gfx, Value)
InterpolationMode = Value
End Property
Public Property Let SmoothingMode(ByVal Value As SmoothingMode)
SetStatus GdipSetSmoothingMode(m_gfx, Value)
End Property
Public Property Get SmoothingMode() As SmoothingMode
Dim Value As SmoothingMode
SetStatus GdipGetSmoothingMode(m_gfx, Value)
SmoothingMode = Value
End Property
Public Property Let PixelOffsetMode(ByVal Value As PixelOffsetMode)
SetStatus GdipSetPixelOffsetMode(m_gfx, Value)
End Property
Public Property Get PixelOffsetMode() As PixelOffsetMode
Dim Value As PixelOffsetMode
SetStatus GdipGetPixelOffsetMode(m_gfx, Value)
PixelOffsetMode = Value
End Property
Public Sub DrawString( _
ByRef s As String, _
ByRef Font As GDIPFont, _
ByRef brush As GDIPBrush, _
ByRef point As POINTF)
m_DrawStringRect.Left = point.X
m_DrawStringRect.Top = point.Y
GdipDrawString m_gfx, s, -1, Font.Value, m_DrawStringRect, m_DrawStringFormat, brush.Value
End Sub
Public Sub DrawImagePointF( _
Image As GDIPImage, _
point As POINTF _
)
DrawImagePointFv Image, point.X, point.Y
End Sub
Public Sub DrawImagePointFv( _
Image As GDIPImage, _
ByVal X As Single, _
ByVal Y As Single _
)
SetStatus GdipDrawImage(m_gfx, Image.nativeImage, X, Y)
End Sub
Public Sub DrawImageRectF( _
Image As GDIPImage, _
RECT As RECTF _
)
DrawImageRectFv Image, RECT.Left, RECT.Top, RECT.Width, RECT.Height
End Sub
Public Sub DrawImageRectFv( _
Image As GDIPImage, _
ByVal X As Single, _
ByVal Y As Single, _
ByVal Width As Single, _
ByVal Height As Single _
)
SetStatus GdipDrawImageRect(m_gfx, _
Image.nativeImage, _
X, _
Y, _
Width, _
Height)
End Sub
Public Sub DrawImagePointL( _
Image As GDIPImage, _
point As gdiplus.POINTL _
)
DrawImagePointLv Image, point.X, point.Y
End Sub
Public Sub DrawImagePointLv( _
Image As GDIPImage, _
ByVal X As Long, _
ByVal Y As Long _
)
SetStatus GdipDrawImageI(m_gfx, _
Image.nativeImage, _
X, _
Y)
End Sub
Public Sub DrawImageRectL( _
Image As GDIPImage, _
RECT As gdiplus.RECTL)
DrawImageRectLv Image, RECT.Left, RECT.Top, RECT.Width, RECT.Height
End Sub
Public Sub DrawImageRectLv( _
Image As GDIPImage, _
ByVal X As Long, _
ByVal Y As Long, _
ByVal Width As Long, _
ByVal Height As Long _
)
SetStatus GdipDrawImageRectI(m_gfx, _
Image.nativeImage, _
X, _
Y, _
Width, _
Height)
End Sub
'
' // Affine Draw Image
' // destPoints.length = 3: rect => parallelogram
' // destPoints[0] <=> top-left corner of the source rectangle
' // destPoints[1] <=> top-right corner
' // destPoints[2] <=> bottom-left corner
' // destPoints.length = 4: rect => quad
' // destPoints[3] <=> bottom-right corner
'
Public Sub DrawImageAffineF( _
Image As GDIPImage, _
destPoints() As POINTF, _
ByVal count As Long _
)
If (count <> 3 And count <> 4) Then
SetStatus InvalidParameter
Else
SetStatus GdipDrawImagePoints(m_gfx, _
Image.nativeImage, _
destPoints(0), count)
End If
End Sub
Public Sub DrawImageAffineL( _
Image As GDIPImage, _
destPoints() As gdiplus.POINTL, _
ByVal count As Long _
)
If (count <> 3 And count <> 4) Then
SetStatus InvalidParameter
Else
SetStatus GdipDrawImagePointsI(m_gfx, _
Image.nativeImage, _
destPoints(0), count)
End If
End Sub
Public Sub DrawImageStretchF( _
Image As GDIPImage, _
ByVal X As Single, _
ByVal Y As Single, _
ByVal srcx As Single, _
ByVal srcy As Single, _
ByVal srcwidth As Single, _
ByVal srcheight As Single, _
ByVal srcUnit As GpUnit)
SetStatus GdipDrawImagePointRect(m_gfx, _
Image.nativeImage, _
X, Y, _
srcx, srcy, _
srcwidth, srcheight, srcUnit)
End Sub
Public Sub DrawImageStretchAttrF( _
Image As GDIPImage, _
destRect As RECTF, _
ByVal srcx As Single, _
ByVal srcy As Single, _
ByVal srcwidth As Single, _
ByVal srcheight As Single, _
ByVal srcUnit As GpUnit, _
ByVal imgAttributes As Long, _
ByVal callback As Long, _
ByVal callbackData As Long _
)
SetStatus GdipDrawImageRectRect(m_gfx, _
Image.nativeImage, _
destRect.Left, _
destRect.Top, _
destRect.Width, _
destRect.Height, _
srcx, srcy, _
srcwidth, srcheight, _
srcUnit, _
imgAttributes, _
callback, _
callbackData)
End Sub
'public sub DrawImage(IN Image* image,
' IN const PointF* destPoints,
' IN INT count,
' IN REAL srcx,
' IN REAL srcy,
' IN REAL srcwidth,
' IN REAL srcheight,
' IN Unit srcUnit,
' IN const ImageAttributes* imageAttributes = NULL,
' IN DrawImageAbort callback = NULL,
' IN VOID* callbackData = NULL)
' {
' return SetStatus(DllExports::GdipDrawImagePointsRect(nativeGraphics,
' image ? image->nativeImage
' : NULL,
' destPoints, count,
' srcx, srcy,
' srcwidth,
' srcheight,
' srcUnit,
' imageAttributes
' ? imageAttributes->nativeImageAttr
' : NULL,
' callback,
' callbackData));
' }
'
Public Sub DrawImageStretchL( _
Image As GDIPImage, _
ByVal X As Long, _
ByVal Y As Long, _
ByVal srcx As Long, _
ByVal srcy As Long, _
ByVal srcwidth As Long, _
ByVal srcheight As Long, _
ByVal srcUnit As GpUnit _
)
SetStatus GdipDrawImagePointRectI(m_gfx, _
Image.nativeImage, _
X, Y, _
srcx, srcy, _
srcwidth, srcheight, _
srcUnit)
End Sub
Public Sub DrawImageStretchAttrL( _
Image As GDIPImage, _
destRect As gdiplus.RECTL, _
ByVal srcx As Long, _
ByVal srcy As Long, _
ByVal srcwidth As Long, _
ByVal srcheight As Long, _
ByVal srcUnit As GpUnit, _
ByVal imgAttributes As Long, _
ByVal callback As Long, _
ByVal callbackData As Long _
)
SetStatus GdipDrawImageRectRectI(m_gfx, _
Image.nativeImage, _
destRect.Left, destRect.Top, _
destRect.Width, destRect.Height, _
srcx, srcy, srcwidth, srcheight, _
srcUnit, _
imgAttributes, _
callback, _
callbackData)
End Sub
Public Sub DrawImage(Image As GDIPImage, _
X As Single, _
Y As Single, _
Width As Single, _
Height As Single, _
Optional ImageAttributes As GDIPImageAttributes)
If ImageAttributes Is Nothing Then
SetStatus GdipDrawImageRect(m_gfx, Image.nativeImage, X, Y, Width, Height), "DrawImage"
Else
SetStatus GdipDrawImageRectRectI(m_gfx, Image.nativeImage, X, Y, Width, Height, 0, 0, Image.Width, Image.Height, UnitPixel, ImageAttributes.nativeAttributes, 0, 0), "DrawImage"
End If
End Sub
Public Sub DrawImageRect(Image As GDIPImage, _
X As Long, _
Y As Long, _
Width As Long, _
Height As Long, _
srcx As Long, _
srcy As Long)
SetStatus GdipDrawImageRectRect(m_gfx, Image.nativeImage, X, Y, Width, Height, srcx, srcy, Width, Height, UnitPixel)
End Sub
Public Sub DrawCachedBitmap(BITMAP As GDIPCachedBitmap, _
X As Long, _
Y As Long)
SetStatus GdipDrawCachedBitmap(m_gfx, BITMAP.nativeImage, X, Y)
End Sub
Public Sub DrawPath( _
pen As GDIPPen, _
GraphicsPath As GDIPGraphicPath _
)
SetStatus GdipDrawPath(m_gfx, pen.Value, GraphicsPath.Value)
End Sub
Public Sub fillPath( _
brush As GDIPBrush, _
Path As GDIPGraphicPath _
)
SetStatus GdipFillPath(m_gfx, brush.Value, Path.Value)
End Sub
Public Sub DrawArc( _
pen As GDIPPen, _
X As Single, _
Y As Single, _
Width As Single, _
Height As Single, _
startAngle As Single, _
sweepAngle As Single)
SetStatus GdipDrawArc(m_gfx, pen.Value, X, Y, Width, Height, startAngle, sweepAngle)
End Sub
Public Function MeasureString( _
ByRef srcString As String, _
ByRef srcFont As GDIPFont) As RECTF
Dim Layout As RECTF
Dim boundingBox As RECTF
Dim codeFitted As Long
Dim linesFilled As Long
SetStatus GdipMeasureString(m_gfx, srcString, -1, srcFont.Value, _
Layout, m_DrawStringFormat, boundingBox, codeFitted, linesFilled)
MeasureString = boundingBox
End Function
'
' Status DrawImage(IN Image* image,
' IN const Point* destPoints,
' IN INT count,
' IN INT srcx,
' IN INT srcy,
' IN INT srcwidth,
' IN INT srcheight,
' IN Unit srcUnit,
' IN const ImageAttributes* imageAttributes = NULL,
' IN DrawImageAbort callback = NULL,
' IN VOID* callbackData = NULL)
' {
' return SetStatus(DllExports::GdipDrawImagePointsRectI(nativeGraphics,
' image ? image->nativeImage
' : NULL,
' destPoints,
' count,
' srcx,
' srcy,
' srcwidth,
' srcheight,
' srcUnit,
' imageAttributes
' ? imageAttributes->nativeImageAttr
' : NULL,
' callback,
' callbackData));
' }
Public Sub Dispose()
If Not (m_gfx = 0) Then
GdipDeleteGraphics m_gfx
GdipDeleteStringFormat m_DrawStringFormat
m_gfx = 0
m_DrawStringFormat = 0
End If
End Sub
Public Function Clear(Optional ByRef r_Colour As Long = -1) As GpStatus
If (r_Colour = -1) Then
'0 is Black
Clear = GdipGraphicsClear(m_gfx, 0)
Else
Clear = GdipGraphicsClear(m_gfx, GetRGB_VB2GDIP(r_Colour))
End If
End Function
Private Function SetStatus(ByVal status As GpStatus, Optional ByRef szRoutine As String) As GpStatus
m_lastResult = SetStatusHelper(status, "GDIPGraphics::" & szRoutine)
End Function
Private Sub Class_Initialize()
GdipCreateStringFormat 0, 0, m_DrawStringFormat
End Sub
Private Sub Class_Terminate()
Dispose
End Sub