Skip to content

Commit b294380

Browse files
committed
Add CreatePatternBrush + GradientFill
1 parent 47e8171 commit b294380

File tree

1 file changed

+55
-1
lines changed

1 file changed

+55
-1
lines changed

gdi32.go

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,13 @@ const (
724724
PFD_STEREO_DONTCARE = 0x80000000
725725
)
726726

727+
// GradientFill constants
728+
const (
729+
GRADIENT_FILL_RECT_H = 0x00
730+
GRADIENT_FILL_RECT_V = 0x01
731+
GRADIENT_FILL_TRIANGLE = 0x02
732+
)
733+
727734
type (
728735
COLORREF uint32
729736
HBITMAP HGDIOBJ
@@ -964,9 +971,30 @@ type ENHMETAHEADER struct {
964971
SzlMicrometers SIZE
965972
}
966973

974+
type TRIVERTEX struct {
975+
X int32
976+
Y int32
977+
Red uint16
978+
Green uint16
979+
Blue uint16
980+
Alpha uint16
981+
}
982+
983+
type GRADIENT_RECT struct {
984+
UpperLeft uint32
985+
LowerRight uint32
986+
}
987+
988+
type GRADIENT_TRIANGLE struct {
989+
Vertex1 uint32
990+
Vertex2 uint32
991+
Vertex3 uint32
992+
}
993+
967994
var (
968995
// Library
969-
libgdi32 uintptr
996+
libgdi32 uintptr
997+
libmsimg32 uintptr
970998

971999
// Functions
9721000
abortDoc uintptr
@@ -983,6 +1011,7 @@ var (
9831011
createFontIndirect uintptr
9841012
createEnhMetaFile uintptr
9851013
createIC uintptr
1014+
createPatternBrush uintptr
9861015
deleteDC uintptr
9871016
deleteEnhMetaFile uintptr
9881017
deleteObject uintptr
@@ -1001,6 +1030,7 @@ var (
10011030
getTextExtentPoint32 uintptr
10021031
getTextMetrics uintptr
10031032
getViewportOrgEx uintptr
1033+
gradientFill uintptr
10041034
lineTo uintptr
10051035
moveToEx uintptr
10061036
playEnhMetaFile uintptr
@@ -1028,6 +1058,7 @@ var (
10281058
func init() {
10291059
// Library
10301060
libgdi32 = MustLoadLibrary("gdi32.dll")
1061+
libmsimg32 = MustLoadLibrary("msimg32.dll")
10311062

10321063
// Functions
10331064
abortDoc = MustGetProcAddress(libgdi32, "AbortDoc")
@@ -1044,6 +1075,7 @@ func init() {
10441075
createEnhMetaFile = MustGetProcAddress(libgdi32, "CreateEnhMetaFileW")
10451076
createFontIndirect = MustGetProcAddress(libgdi32, "CreateFontIndirectW")
10461077
createIC = MustGetProcAddress(libgdi32, "CreateICW")
1078+
createPatternBrush = MustGetProcAddress(libgdi32, "CreatePatternBrush")
10471079
deleteDC = MustGetProcAddress(libgdi32, "DeleteDC")
10481080
deleteEnhMetaFile = MustGetProcAddress(libgdi32, "DeleteEnhMetaFile")
10491081
deleteObject = MustGetProcAddress(libgdi32, "DeleteObject")
@@ -1085,6 +1117,7 @@ func init() {
10851117
swapBuffers = MustGetProcAddress(libgdi32, "SwapBuffers")
10861118
textOut = MustGetProcAddress(libgdi32, "TextOutW")
10871119

1120+
gradientFill = MustGetProcAddress(libmsimg32, "GradientFill")
10881121
}
10891122

10901123
func AbortDoc(hdc HDC) int32 {
@@ -1234,6 +1267,15 @@ func CreateIC(lpszDriver, lpszDevice, lpszOutput *uint16, lpdvmInit *DEVMODE) HD
12341267
return HDC(ret)
12351268
}
12361269

1270+
func CreatePatternBrush(hbmp HBITMAP) HBRUSH {
1271+
ret, _, _ := syscall.Syscall(createPatternBrush, 1,
1272+
uintptr(hbmp),
1273+
0,
1274+
0)
1275+
1276+
return HBRUSH(ret)
1277+
}
1278+
12371279
func DeleteDC(hdc HDC) bool {
12381280
ret, _, _ := syscall.Syscall(deleteDC, 1,
12391281
uintptr(hdc),
@@ -1416,6 +1458,18 @@ func GetViewportOrgEx(hdc HDC, lpPoint *POINT) bool {
14161458
return ret != 0
14171459
}
14181460

1461+
func GradientFill(hdc HDC, pVertex *TRIVERTEX, nVertex uint32, pMesh unsafe.Pointer, nMesh, ulMode uint32) bool {
1462+
ret, _, _ := syscall.Syscall6(gradientFill, 6,
1463+
uintptr(hdc),
1464+
uintptr(unsafe.Pointer(pVertex)),
1465+
uintptr(nVertex),
1466+
uintptr(pMesh),
1467+
uintptr(nMesh),
1468+
uintptr(ulMode))
1469+
1470+
return ret != 0
1471+
}
1472+
14191473
func LineTo(hdc HDC, nXEnd, nYEnd int32) bool {
14201474
ret, _, _ := syscall.Syscall(lineTo, 3,
14211475
uintptr(hdc),

0 commit comments

Comments
 (0)