-
Notifications
You must be signed in to change notification settings - Fork 3
/
gdipluspen.go
317 lines (264 loc) · 7.82 KB
/
gdipluspen.go
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
package gdiplus
import (
. "github.com/tryor/winapi"
)
type Pen struct {
GdiplusBase
nativePen *GpPen
}
func NewPen(color Color, width ...REAL) (*Pen, error) {
var w REAL
if len(width) > 0 {
w = width[0]
} else {
w = 1.0
}
var unit Unit = UnitWorld
var nativePen *GpPen
lastResult, err := GdipCreatePen1(color.GetValue(), w, GpUnit(unit), &nativePen)
return &Pen{nativePen: nativePen, GdiplusBase: GdiplusBase{LastResult: Status(lastResult), LastError: err}}, err
}
func NewPen2(brush IBrush, width ...REAL) (*Pen, error) {
var w REAL
if len(width) > 0 {
w = width[0]
} else {
w = 1.0
}
pen := &Pen{}
pen.setStatus(GdipCreatePen2(brush.GetNativeBrush(),
w, UnitWorld, &pen.nativePen))
return pen, pen.LastError
}
func (this *Pen) Release() {
if this.nativePen != nil {
this.setStatus(GdipDeletePen(this.nativePen))
this.nativePen = nil
}
}
func (this *Pen) Clone() *Pen {
pen := &Pen{}
pen.setStatus(GdipClonePen(this.nativePen, &pen.nativePen))
return pen
}
func (this *Pen) SetWidth(width REAL) Status {
return this.setStatus(GdipSetPenWidth(this.nativePen, width))
}
func (this *Pen) GetWidth() (width REAL) {
this.setStatus(GdipGetPenWidth(this.nativePen, &width))
return
}
func (this *Pen) SetLineCap(startCap, endCap LineCap,
dashCap DashCap) Status {
return this.setStatus(GdipSetPenLineCap197819(this.nativePen,
startCap, endCap, dashCap))
}
func (this *Pen) SetStartCap(startCap LineCap) Status {
return this.setStatus(GdipSetPenStartCap(this.nativePen, startCap))
}
func (this *Pen) SetEndCap(endCap LineCap) Status {
return this.setStatus(GdipSetPenEndCap(this.nativePen, endCap))
}
func (this *Pen) SetDashCap(dashCap DashCap) Status {
return this.setStatus(GdipSetPenDashCap197819(this.nativePen,
dashCap))
}
func (this *Pen) GetStartCap() (startCap LineCap) {
this.setStatus(GdipGetPenStartCap(this.nativePen, &startCap))
return
}
func (this *Pen) GetEndCap() (endCap LineCap) {
this.setStatus(GdipGetPenEndCap(this.nativePen, &endCap))
return
}
func (this *Pen) GetDashCap() (dashCap DashCap) {
this.setStatus(GdipGetPenDashCap197819(this.nativePen,
&dashCap))
return
}
func (this *Pen) SetLineJoin(lineJoin LineJoin) Status {
return this.setStatus(GdipSetPenLineJoin(this.nativePen, lineJoin))
}
func (this *Pen) GetLineJoin() (lineJoin LineJoin) {
this.setStatus(GdipGetPenLineJoin(this.nativePen, &lineJoin))
return
}
func (this *Pen) SetCustomStartCap(customCap ICustomLineCap) Status {
var nativeCap *GpCustomLineCap
if customCap != nil {
nativeCap = customCap.GetNativeCap()
}
return this.setStatus(GdipSetPenCustomStartCap(this.nativePen,
nativeCap))
}
func (this *Pen) GetCustomStartCap() (customCap *CustomLineCap, status Status) {
var nativeCap *GpCustomLineCap
status = this.setStatus(GdipGetPenCustomStartCap(this.nativePen,
&nativeCap))
if status == Ok && nativeCap != nil {
customCap = &CustomLineCap{nativeCap: nativeCap}
}
return
}
func (this *Pen) SetCustomEndCap(customCap ICustomLineCap) Status {
var nativeCap *GpCustomLineCap
if customCap != nil {
nativeCap = customCap.GetNativeCap()
}
return this.setStatus(GdipSetPenCustomEndCap(this.nativePen,
nativeCap))
}
func (this *Pen) GetCustomEndCap() (customCap *CustomLineCap, status Status) {
var nativeCap *GpCustomLineCap
status = this.setStatus(GdipGetPenCustomEndCap(this.nativePen, &nativeCap))
if status == Ok && nativeCap != nil {
customCap = &CustomLineCap{nativeCap: nativeCap}
}
return
}
func (this *Pen) SetMiterLimit(miterLimit REAL) Status {
return this.setStatus(GdipSetPenMiterLimit(this.nativePen,
miterLimit))
}
func (this *Pen) GetMiterLimit() (miterLimit REAL) {
this.setStatus(GdipGetPenMiterLimit(this.nativePen, &miterLimit))
return
}
func (this *Pen) SetAlignment(penAlignment PenAlignment) Status {
return this.setStatus(GdipSetPenMode(this.nativePen, penAlignment))
}
func (this *Pen) GetAlignment() (penAlignment PenAlignment) {
this.setStatus(GdipGetPenMode(this.nativePen, &penAlignment))
return
}
func (this *Pen) SetTransform(matrix *Matrix) Status {
return this.setStatus(GdipSetPenTransform(this.nativePen,
matrix.nativeMatrix))
}
//OUT Matrix* matrix
func (this *Pen) GetTransform(matrix *Matrix) Status {
return this.setStatus(GdipGetPenTransform(this.nativePen,
matrix.nativeMatrix))
}
func (this *Pen) ResetTransform() Status {
return this.setStatus(GdipResetPenTransform(this.nativePen))
}
//order = MatrixOrderPrepend
func (this *Pen) MultiplyTransform(matrix *Matrix,
order MatrixOrder) Status {
return this.setStatus(GdipMultiplyPenTransform(this.nativePen,
matrix.nativeMatrix, order))
}
//order = MatrixOrderPrepend
func (this *Pen) TranslateTransform(dx, dy REAL, order MatrixOrder) Status {
return this.setStatus(GdipTranslatePenTransform(
this.nativePen,
dx, dy, order))
}
//order = MatrixOrderPrepend
func (this *Pen) ScaleTransform(sx, sy REAL, order MatrixOrder) Status {
return this.setStatus(GdipScalePenTransform(
this.nativePen,
sx, sy, order))
}
//order = MatrixOrderPrepend
func (this *Pen) RotateTransform(angle REAL, order MatrixOrder) Status {
return this.setStatus(GdipRotatePenTransform(
this.nativePen, angle, order))
}
func (this *Pen) GetPenType() (typ PenType) {
this.setStatus(GdipGetPenFillType(this.nativePen, &typ))
return
}
func (this *Pen) SetColor(color Color) Status {
return this.setStatus(GdipSetPenColor(this.nativePen,
color.GetValue()))
}
func (this *Pen) GetColor() (color Color, status Status) {
typ := this.GetPenType()
if typ != PenTypeSolidColor {
status = WrongState
return
}
status = this.setStatus(GdipGetPenColor(this.nativePen, &color.Argb))
return
}
func (this *Pen) SetBrush(brush IBrush) Status {
return this.setStatus(GdipSetPenBrushFill(this.nativePen,
brush.GetNativeBrush()))
}
func (this *Pen) GetBrush() IBrush {
typ := this.GetPenType()
var brush IBrush
switch typ {
case PenTypeSolidColor:
brush = &SolidBrush{}
case PenTypeHatchFill:
brush = &HatchBrush{}
case PenTypeTextureFill:
brush = &TextureBrush{}
case PenTypePathGradient:
brush = &Brush{}
case PenTypeLinearGradient:
brush = &LinearGradientBrush{}
}
if brush != nil {
var nativeBrush *GpBrush
this.setStatus(GdipGetPenBrushFill(this.nativePen,
&nativeBrush))
brush.SetNativeBrush(nativeBrush)
}
return brush
}
func (this *Pen) GetDashStyle() (dashStyle DashStyle) {
this.setStatus(GdipGetPenDashStyle(this.nativePen, &dashStyle))
return
}
func (this *Pen) SetDashStyle(dashStyle DashStyle) Status {
return this.setStatus(GdipSetPenDashStyle(this.nativePen,
dashStyle))
}
func (this *Pen) GetDashOffset() (dashOffset REAL) {
this.setStatus(GdipGetPenDashOffset(this.nativePen, &dashOffset))
return
}
func (this *Pen) SetDashOffset(dashOffset REAL) Status {
return this.setStatus(GdipSetPenDashOffset(this.nativePen,
dashOffset))
}
func (this *Pen) SetDashPattern(dashArray []REAL) Status {
return this.setStatus(GdipSetPenDashArray(this.nativePen,
dashArray))
}
func (this *Pen) GetDashPatternCount() (count INT) {
this.setStatus(GdipGetPenDashCount(this.nativePen, &count))
return
}
func (this *Pen) GetDashPattern(count INT) (dashArray []REAL, status Status) {
if count <= 0 {
status = this.setStatus(InvalidParameter, nil)
return
}
dashArray = make([]REAL, count)
status = this.setStatus(GdipGetPenDashArray(this.nativePen,
dashArray))
return
}
func (this *Pen) SetCompoundArray(compoundArray []REAL) Status {
return this.setStatus(GdipSetPenCompoundArray(this.nativePen,
compoundArray))
}
func (this *Pen) GetCompoundArrayCount() (count INT) {
this.setStatus(GdipGetPenCompoundCount(this.nativePen, &count))
return
}
func (this *Pen) GetCompoundArray(count INT) (compoundArray []REAL, status Status) {
if count <= 0 {
status = this.setStatus(InvalidParameter, nil)
return
}
compoundArray = make([]REAL, count)
status = this.setStatus(GdipGetPenCompoundArray(this.nativePen,
compoundArray))
return
}