Skip to content

Commit ace665b

Browse files
author
Popog
committed
Updates and fixes necessary for glml
This selfish update adds the necessary bindings and constants for glml to stop using cgo. Also some fixes.
1 parent 6550729 commit ace665b

File tree

5 files changed

+530
-79
lines changed

5 files changed

+530
-79
lines changed

constants.go

+139
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,13 @@ const (
511511
WM_CLIPBOARDUPDATE = 0x031D
512512
)
513513

514+
// WM_ACTIVATE
515+
const (
516+
WA_INACTIVE = 0
517+
WA_ACTIVE = 1
518+
WA_CLICKACTIVE = 2
519+
)
520+
514521
const LF_FACESIZE = 32
515522

516523
// Font weight constants
@@ -1256,6 +1263,14 @@ const (
12561263
DISPID_COLLECT = -8
12571264
)
12581265

1266+
const (
1267+
MONITOR_DEFAULTTONULL = 0x00000000
1268+
MONITOR_DEFAULTTOPRIMARY = 0x00000001
1269+
MONITOR_DEFAULTTONEAREST = 0x00000002
1270+
1271+
MONITORINFOF_PRIMARY = 0x00000001
1272+
)
1273+
12591274
const (
12601275
CCHDEVICENAME = 32
12611276
CCHFORMNAME = 32
@@ -1694,6 +1709,16 @@ const (
16941709
ILC_HIGHQUALITYSCALE = 0x00020000
16951710
)
16961711

1712+
// Keystroke Message Flags
1713+
const (
1714+
KF_EXTENDED = 0x0100
1715+
KF_DLGMODE = 0x0800
1716+
KF_MENUMODE = 0x1000
1717+
KF_ALTDOWN = 0x2000
1718+
KF_REPEAT = 0x4000
1719+
KF_UP = 0x8000
1720+
)
1721+
16971722
// Virtual-Key Codes
16981723
const (
16991724
VK_LBUTTON = 0x01
@@ -2473,3 +2498,117 @@ const (
24732498
GT_TOUCH_PRESSANDHOLDABORT = 9
24742499
GT_TOUCH_PRESSANDTAP = 10
24752500
)
2501+
2502+
// Icons
2503+
const (
2504+
ICON_SMALL = 0
2505+
ICON_BIG = 1
2506+
ICON_SMALL2 = 2
2507+
)
2508+
2509+
const (
2510+
SIZE_RESTORED = 0
2511+
SIZE_MINIMIZED = 1
2512+
SIZE_MAXIMIZED = 2
2513+
SIZE_MAXSHOW = 3
2514+
SIZE_MAXHIDE = 4
2515+
)
2516+
2517+
// XButton values
2518+
const (
2519+
XBUTTON1 = 1
2520+
XBUTTON2 = 2
2521+
)
2522+
2523+
// Devmode
2524+
const (
2525+
DM_SPECVERSION = 0x0401
2526+
2527+
DM_ORIENTATION = 0x00000001
2528+
DM_PAPERSIZE = 0x00000002
2529+
DM_PAPERLENGTH = 0x00000004
2530+
DM_PAPERWIDTH = 0x00000008
2531+
DM_SCALE = 0x00000010
2532+
DM_POSITION = 0x00000020
2533+
DM_NUP = 0x00000040
2534+
DM_DISPLAYORIENTATION = 0x00000080
2535+
DM_COPIES = 0x00000100
2536+
DM_DEFAULTSOURCE = 0x00000200
2537+
DM_PRINTQUALITY = 0x00000400
2538+
DM_COLOR = 0x00000800
2539+
DM_DUPLEX = 0x00001000
2540+
DM_YRESOLUTION = 0x00002000
2541+
DM_TTOPTION = 0x00004000
2542+
DM_COLLATE = 0x00008000
2543+
DM_FORMNAME = 0x00010000
2544+
DM_LOGPIXELS = 0x00020000
2545+
DM_BITSPERPEL = 0x00040000
2546+
DM_PELSWIDTH = 0x00080000
2547+
DM_PELSHEIGHT = 0x00100000
2548+
DM_DISPLAYFLAGS = 0x00200000
2549+
DM_DISPLAYFREQUENCY = 0x00400000
2550+
DM_ICMMETHOD = 0x00800000
2551+
DM_ICMINTENT = 0x01000000
2552+
DM_MEDIATYPE = 0x02000000
2553+
DM_DITHERTYPE = 0x04000000
2554+
DM_PANNINGWIDTH = 0x08000000
2555+
DM_PANNINGHEIGHT = 0x10000000
2556+
DM_DISPLAYFIXEDOUTPUT = 0x20000000
2557+
)
2558+
2559+
// ChangeDisplaySettings
2560+
const (
2561+
CDS_UPDATEREGISTRY = 0x00000001
2562+
CDS_TEST = 0x00000002
2563+
CDS_FULLSCREEN = 0x00000004
2564+
CDS_GLOBAL = 0x00000008
2565+
CDS_SET_PRIMARY = 0x00000010
2566+
CDS_VIDEOPARAMETERS = 0x00000020
2567+
CDS_RESET = 0x40000000
2568+
CDS_NORESET = 0x10000000
2569+
2570+
DISP_CHANGE_SUCCESSFUL = 0
2571+
DISP_CHANGE_RESTART = 1
2572+
DISP_CHANGE_FAILED = -1
2573+
DISP_CHANGE_BADMODE = -2
2574+
DISP_CHANGE_NOTUPDATED = -3
2575+
DISP_CHANGE_BADFLAGS = -4
2576+
DISP_CHANGE_BADPARAM = -5
2577+
DISP_CHANGE_BADDUALVIEW = -6
2578+
)
2579+
2580+
const (
2581+
ENUM_CURRENT_SETTINGS = 0xFFFFFFFF
2582+
ENUM_REGISTRY_SETTINGS = 0xFFFFFFFE
2583+
)
2584+
2585+
// PIXELFORMATDESCRIPTOR
2586+
const (
2587+
PFD_TYPE_RGBA = 0
2588+
PFD_TYPE_COLORINDEX = 1
2589+
2590+
PFD_MAIN_PLANE = 0
2591+
PFD_OVERLAY_PLANE = 1
2592+
PFD_UNDERLAY_PLANE = -1
2593+
2594+
PFD_DOUBLEBUFFER = 0x00000001
2595+
PFD_STEREO = 0x00000002
2596+
PFD_DRAW_TO_WINDOW = 0x00000004
2597+
PFD_DRAW_TO_BITMAP = 0x00000008
2598+
PFD_SUPPORT_GDI = 0x00000010
2599+
PFD_SUPPORT_OPENGL = 0x00000020
2600+
PFD_GENERIC_FORMAT = 0x00000040
2601+
PFD_NEED_PALETTE = 0x00000080
2602+
PFD_NEED_SYSTEM_PALETTE = 0x00000100
2603+
PFD_SWAP_EXCHANGE = 0x00000200
2604+
PFD_SWAP_COPY = 0x00000400
2605+
PFD_SWAP_LAYER_BUFFERS = 0x00000800
2606+
PFD_GENERIC_ACCELERATED = 0x00001000
2607+
PFD_SUPPORT_DIRECTDRAW = 0x00002000
2608+
PFD_DIRECT3D_ACCELERATED = 0x00004000
2609+
PFD_SUPPORT_COMPOSITION = 0x00008000
2610+
2611+
PFD_DEPTH_DONTCARE = 0x20000000
2612+
PFD_DOUBLEBUFFER_DONTCARE = 0x40000000
2613+
PFD_STEREO_DONTCARE = 0x80000000
2614+
)

gdi32.go

+95-41
Original file line numberDiff line numberDiff line change
@@ -12,47 +12,53 @@ import (
1212
var (
1313
modgdi32 = syscall.NewLazyDLL("gdi32.dll")
1414

15-
procGetDeviceCaps = modgdi32.NewProc("GetDeviceCaps")
16-
procDeleteObject = modgdi32.NewProc("DeleteObject")
17-
procCreateFontIndirect = modgdi32.NewProc("CreateFontIndirectW")
18-
procAbortDoc = modgdi32.NewProc("AbortDoc")
19-
procBitBlt = modgdi32.NewProc("BitBlt")
20-
procCloseEnhMetaFile = modgdi32.NewProc("CloseEnhMetaFile")
21-
procCopyEnhMetaFile = modgdi32.NewProc("CopyEnhMetaFileW")
22-
procCreateBrushIndirect = modgdi32.NewProc("CreateBrushIndirect")
23-
procCreateCompatibleDC = modgdi32.NewProc("CreateCompatibleDC")
24-
procCreateDC = modgdi32.NewProc("CreateDCW")
25-
procCreateDIBSection = modgdi32.NewProc("CreateDIBSection")
26-
procCreateEnhMetaFile = modgdi32.NewProc("CreateEnhMetaFileW")
27-
procCreateIC = modgdi32.NewProc("CreateICW")
28-
procDeleteDC = modgdi32.NewProc("DeleteDC")
29-
procDeleteEnhMetaFile = modgdi32.NewProc("DeleteEnhMetaFile")
30-
procEllipse = modgdi32.NewProc("Ellipse")
31-
procEndDoc = modgdi32.NewProc("EndDoc")
32-
procEndPage = modgdi32.NewProc("EndPage")
33-
procExtCreatePen = modgdi32.NewProc("ExtCreatePen")
34-
procGetEnhMetaFile = modgdi32.NewProc("GetEnhMetaFileW")
35-
procGetEnhMetaFileHeader = modgdi32.NewProc("GetEnhMetaFileHeader")
36-
procGetObject = modgdi32.NewProc("GetObjectW")
37-
procGetStockObject = modgdi32.NewProc("GetStockObject")
38-
procGetTextExtentExPoint = modgdi32.NewProc("GetTextExtentExPointW")
39-
procGetTextExtentPoint32 = modgdi32.NewProc("GetTextExtentPoint32W")
40-
procGetTextMetrics = modgdi32.NewProc("GetTextMetricsW")
41-
procLineTo = modgdi32.NewProc("LineTo")
42-
procMoveToEx = modgdi32.NewProc("MoveToEx")
43-
procPlayEnhMetaFile = modgdi32.NewProc("PlayEnhMetaFile")
44-
procRectangle = modgdi32.NewProc("Rectangle")
45-
procResetDC = modgdi32.NewProc("ResetDCW")
46-
procSelectObject = modgdi32.NewProc("SelectObject")
47-
procSetBkMode = modgdi32.NewProc("SetBkMode")
48-
procSetBrushOrgEx = modgdi32.NewProc("SetBrushOrgEx")
49-
procSetStretchBltMode = modgdi32.NewProc("SetStretchBltMode")
50-
procSetTextColor = modgdi32.NewProc("SetTextColor")
51-
procSetBkColor = modgdi32.NewProc("SetBkColor")
52-
procStartDoc = modgdi32.NewProc("StartDocW")
53-
procStartPage = modgdi32.NewProc("StartPage")
54-
procStretchBlt = modgdi32.NewProc("StretchBlt")
55-
procSetDIBitsToDevice = modgdi32.NewProc("SetDIBitsToDevice")
15+
procGetDeviceCaps = modgdi32.NewProc("GetDeviceCaps")
16+
procDeleteObject = modgdi32.NewProc("DeleteObject")
17+
procCreateFontIndirect = modgdi32.NewProc("CreateFontIndirectW")
18+
procAbortDoc = modgdi32.NewProc("AbortDoc")
19+
procBitBlt = modgdi32.NewProc("BitBlt")
20+
procCloseEnhMetaFile = modgdi32.NewProc("CloseEnhMetaFile")
21+
procCopyEnhMetaFile = modgdi32.NewProc("CopyEnhMetaFileW")
22+
procCreateBrushIndirect = modgdi32.NewProc("CreateBrushIndirect")
23+
procCreateCompatibleDC = modgdi32.NewProc("CreateCompatibleDC")
24+
procCreateDC = modgdi32.NewProc("CreateDCW")
25+
procCreateDIBSection = modgdi32.NewProc("CreateDIBSection")
26+
procCreateEnhMetaFile = modgdi32.NewProc("CreateEnhMetaFileW")
27+
procCreateIC = modgdi32.NewProc("CreateICW")
28+
procDeleteDC = modgdi32.NewProc("DeleteDC")
29+
procDeleteEnhMetaFile = modgdi32.NewProc("DeleteEnhMetaFile")
30+
procEllipse = modgdi32.NewProc("Ellipse")
31+
procEndDoc = modgdi32.NewProc("EndDoc")
32+
procEndPage = modgdi32.NewProc("EndPage")
33+
procExtCreatePen = modgdi32.NewProc("ExtCreatePen")
34+
procGetEnhMetaFile = modgdi32.NewProc("GetEnhMetaFileW")
35+
procGetEnhMetaFileHeader = modgdi32.NewProc("GetEnhMetaFileHeader")
36+
procGetObject = modgdi32.NewProc("GetObjectW")
37+
procGetStockObject = modgdi32.NewProc("GetStockObject")
38+
procGetTextExtentExPoint = modgdi32.NewProc("GetTextExtentExPointW")
39+
procGetTextExtentPoint32 = modgdi32.NewProc("GetTextExtentPoint32W")
40+
procGetTextMetrics = modgdi32.NewProc("GetTextMetricsW")
41+
procLineTo = modgdi32.NewProc("LineTo")
42+
procMoveToEx = modgdi32.NewProc("MoveToEx")
43+
procPlayEnhMetaFile = modgdi32.NewProc("PlayEnhMetaFile")
44+
procRectangle = modgdi32.NewProc("Rectangle")
45+
procResetDC = modgdi32.NewProc("ResetDCW")
46+
procSelectObject = modgdi32.NewProc("SelectObject")
47+
procSetBkMode = modgdi32.NewProc("SetBkMode")
48+
procSetBrushOrgEx = modgdi32.NewProc("SetBrushOrgEx")
49+
procSetStretchBltMode = modgdi32.NewProc("SetStretchBltMode")
50+
procSetTextColor = modgdi32.NewProc("SetTextColor")
51+
procSetBkColor = modgdi32.NewProc("SetBkColor")
52+
procStartDoc = modgdi32.NewProc("StartDocW")
53+
procStartPage = modgdi32.NewProc("StartPage")
54+
procStretchBlt = modgdi32.NewProc("StretchBlt")
55+
procSetDIBitsToDevice = modgdi32.NewProc("SetDIBitsToDevice")
56+
procChoosePixelFormat = modgdi32.NewProc("ChoosePixelFormat")
57+
procDescribePixelFormat = modgdi32.NewProc("DescribePixelFormat")
58+
procGetEnhMetaFilePixelFormat = modgdi32.NewProc("GetEnhMetaFilePixelFormat")
59+
procGetPixelFormat = modgdi32.NewProc("GetPixelFormat")
60+
procSetPixelFormat = modgdi32.NewProc("SetPixelFormat")
61+
procSwapBuffers = modgdi32.NewProc("SwapBuffers")
5662
)
5763

5864
func GetDeviceCaps(hdc HDC, index int) int {
@@ -453,3 +459,51 @@ func SetDIBitsToDevice(hdc HDC, xDest, yDest, dwWidth, dwHeight, xSrc, ySrc int,
453459

454460
return int(ret)
455461
}
462+
463+
func ChoosePixelFormat(hdc HDC, pfd *PIXELFORMATDESCRIPTOR) int {
464+
ret, _, _ := procChoosePixelFormat.Call(
465+
uintptr(hdc),
466+
uintptr(unsafe.Pointer(pfd)),
467+
)
468+
return int(ret)
469+
}
470+
471+
func DescribePixelFormat(hdc HDC, iPixelFormat int, nBytes uint, pfd *PIXELFORMATDESCRIPTOR) int {
472+
ret, _, _ := procDescribePixelFormat.Call(
473+
uintptr(hdc),
474+
uintptr(iPixelFormat),
475+
uintptr(nBytes),
476+
uintptr(unsafe.Pointer(pfd)),
477+
)
478+
return int(ret)
479+
}
480+
481+
func GetEnhMetaFilePixelFormat(hemf HENHMETAFILE, cbBuffer uint32, pfd *PIXELFORMATDESCRIPTOR) uint {
482+
ret, _, _ := procGetEnhMetaFilePixelFormat.Call(
483+
uintptr(hemf),
484+
uintptr(cbBuffer),
485+
uintptr(unsafe.Pointer(pfd)),
486+
)
487+
return uint(ret)
488+
}
489+
490+
func GetPixelFormat(hdc HDC) int {
491+
ret, _, _ := procGetPixelFormat.Call(
492+
uintptr(hdc),
493+
)
494+
return int(ret)
495+
}
496+
497+
func SetPixelFormat(hdc HDC, iPixelFormat int, pfd *PIXELFORMATDESCRIPTOR) bool {
498+
ret, _, _ := procSetPixelFormat.Call(
499+
uintptr(hdc),
500+
uintptr(iPixelFormat),
501+
uintptr(unsafe.Pointer(pfd)),
502+
)
503+
return ret == TRUE
504+
}
505+
506+
func SwapBuffers(hdc HDC) bool {
507+
ret, _, _ := procSwapBuffers.Call(uintptr(hdc))
508+
return ret == TRUE
509+
}

opengl32.go

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Copyright 2010-2012 The W32 Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package w32
6+
7+
import (
8+
"syscall"
9+
"unsafe"
10+
)
11+
12+
var (
13+
modopengl32 = syscall.NewLazyDLL("opengl32.dll")
14+
15+
procwglCreateContext = modopengl32.NewProc("wglCreateContext")
16+
procwglCreateLayerContext = modopengl32.NewProc("wglCreateLayerContext")
17+
procwglDeleteContext = modopengl32.NewProc("wglDeleteContext")
18+
procwglGetProcAddress = modopengl32.NewProc("wglGetProcAddress")
19+
procwglMakeCurrent = modopengl32.NewProc("wglMakeCurrent")
20+
procwglShareLists = modopengl32.NewProc("wglShareLists")
21+
)
22+
23+
func WglCreateContext(hdc HDC) HGLRC {
24+
ret, _, _ := procwglCreateContext.Call(
25+
uintptr(hdc),
26+
)
27+
28+
return HGLRC(ret)
29+
}
30+
31+
func WglCreateLayerContext(hdc HDC, iLayerPlane int) HGLRC {
32+
ret, _, _ := procwglCreateLayerContext.Call(
33+
uintptr(hdc),
34+
uintptr(iLayerPlane),
35+
)
36+
37+
return HGLRC(ret)
38+
}
39+
40+
func WglDeleteContext(hglrc HGLRC) bool {
41+
ret, _, _ := procwglDeleteContext.Call(
42+
uintptr(hglrc),
43+
)
44+
45+
return ret == TRUE
46+
}
47+
48+
func WglGetProcAddress(szProc string) uintptr {
49+
ret, _, _ := procwglGetProcAddress.Call(
50+
uintptr(unsafe.Pointer(syscall.StringBytePtr(szProc))),
51+
)
52+
53+
return ret
54+
}
55+
56+
func WglMakeCurrent(hdc HDC, hglrc HGLRC) bool {
57+
ret, _, _ := procwglMakeCurrent.Call(
58+
uintptr(hdc),
59+
uintptr(hglrc),
60+
)
61+
62+
return ret == TRUE
63+
}
64+
65+
func WglShareLists(hglrc1, hglrc2 HGLRC) bool {
66+
ret, _, _ := procwglShareLists.Call(
67+
uintptr(hglrc1),
68+
uintptr(hglrc2),
69+
)
70+
71+
return ret == TRUE
72+
}

0 commit comments

Comments
 (0)