mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-23 17:32:02 +01:00
parent
4a00bbc299
commit
abcacc26d8
@ -175,6 +175,7 @@ func (g *nativeGamepadsDesktop) init(gamepads *gamepads) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if g.dinput8 != 0 {
|
if g.dinput8 != 0 {
|
||||||
|
// TODO: Use _GetModuleHandleExW to align with GLFW v3.3.8.
|
||||||
m, err := _GetModuleHandleW()
|
m, err := _GetModuleHandleW()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -64,6 +64,8 @@ const (
|
|||||||
_ENUM_CURRENT_SETTINGS uint32 = 0xffffffff
|
_ENUM_CURRENT_SETTINGS uint32 = 0xffffffff
|
||||||
_GCLP_HICON = -14
|
_GCLP_HICON = -14
|
||||||
_GCLP_HICONSM = -34
|
_GCLP_HICONSM = -34
|
||||||
|
_GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS = 0x00000004
|
||||||
|
_GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT = 0x00000002
|
||||||
_GWL_EXSTYLE = -20
|
_GWL_EXSTYLE = -20
|
||||||
_GWL_STYLE = -16
|
_GWL_STYLE = -16
|
||||||
_HTCLIENT = 1
|
_HTCLIENT = 1
|
||||||
@ -735,7 +737,7 @@ var (
|
|||||||
procSetPixelFormat = gdi32.NewProc("SetPixelFormat")
|
procSetPixelFormat = gdi32.NewProc("SetPixelFormat")
|
||||||
procSwapBuffers = gdi32.NewProc("SwapBuffers")
|
procSwapBuffers = gdi32.NewProc("SwapBuffers")
|
||||||
|
|
||||||
procGetModuleHandleW = kernel32.NewProc("GetModuleHandleW")
|
procGetModuleHandleExW = kernel32.NewProc("GetModuleHandleExW")
|
||||||
procSetThreadExecutionState = kernel32.NewProc("SetThreadExecutionState")
|
procSetThreadExecutionState = kernel32.NewProc("SetThreadExecutionState")
|
||||||
procTlsAlloc = kernel32.NewProc("TlsAlloc")
|
procTlsAlloc = kernel32.NewProc("TlsAlloc")
|
||||||
procTlsFree = kernel32.NewProc("TlsFree")
|
procTlsFree = kernel32.NewProc("TlsFree")
|
||||||
@ -1260,23 +1262,31 @@ func _GetMessageTime() int32 {
|
|||||||
return int32(r)
|
return int32(r)
|
||||||
}
|
}
|
||||||
|
|
||||||
func _GetModuleHandleW(moduleName string) (_HMODULE, error) {
|
func _GetModuleHandleExW(dwFlags uint32, lpModuleName interface{}) (_HMODULE, error) {
|
||||||
var lpModuleName *uint16
|
var ptr unsafe.Pointer
|
||||||
|
switch moduleName := lpModuleName.(type) {
|
||||||
|
case string:
|
||||||
if moduleName != "" {
|
if moduleName != "" {
|
||||||
var err error
|
p, err := windows.UTF16PtrFromString(moduleName)
|
||||||
lpModuleName, err = windows.UTF16PtrFromString(moduleName)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic("glfwwin: module name must not include a NUL character")
|
panic("glfwwin: module name must not include a NUL character")
|
||||||
}
|
}
|
||||||
|
ptr = unsafe.Pointer(p)
|
||||||
|
}
|
||||||
|
case unsafe.Pointer:
|
||||||
|
ptr = moduleName
|
||||||
|
default:
|
||||||
|
return 0, fmt.Errorf("glfwwin: GetModuleHandleExW: lpModuleName must be a string or an unsafe.Pointer but %T", moduleName)
|
||||||
}
|
}
|
||||||
|
|
||||||
r, _, e := procGetModuleHandleW.Call(uintptr(unsafe.Pointer(lpModuleName)))
|
var module _HMODULE
|
||||||
runtime.KeepAlive(lpModuleName)
|
r, _, e := procGetModuleHandleExW.Call(uintptr(dwFlags), uintptr(ptr), uintptr(unsafe.Pointer(&module)))
|
||||||
|
runtime.KeepAlive(ptr)
|
||||||
|
|
||||||
if _HMODULE(r) == 0 {
|
if int32(r) != 1 {
|
||||||
return 0, fmt.Errorf("glfwwin: GetModuleHandleW failed: %w", e)
|
return 0, fmt.Errorf("glfwwin: GetModuleHandleExW failed: %w", e)
|
||||||
}
|
}
|
||||||
return _HMODULE(r), nil
|
return module, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func _GetMonitorInfoW(hMonitor _HMONITOR) (_MONITORINFO, bool) {
|
func _GetMonitorInfoW(hMonitor _HMONITOR) (_MONITORINFO, bool) {
|
||||||
|
@ -254,6 +254,7 @@ type library struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
win32 struct {
|
win32 struct {
|
||||||
|
instance _HINSTANCE
|
||||||
helperWindowHandle windows.HWND
|
helperWindowHandle windows.HWND
|
||||||
deviceNotificationHandle _HDEVNOTIFY
|
deviceNotificationHandle _HDEVNOTIFY
|
||||||
acquiredMonitorCount int
|
acquiredMonitorCount int
|
||||||
|
@ -83,7 +83,6 @@ func createKeyTables() {
|
|||||||
_glfw.win32.keycodes[0x151] = KeyPageDown
|
_glfw.win32.keycodes[0x151] = KeyPageDown
|
||||||
_glfw.win32.keycodes[0x149] = KeyPageUp
|
_glfw.win32.keycodes[0x149] = KeyPageUp
|
||||||
_glfw.win32.keycodes[0x045] = KeyPause
|
_glfw.win32.keycodes[0x045] = KeyPause
|
||||||
_glfw.win32.keycodes[0x146] = KeyPause
|
|
||||||
_glfw.win32.keycodes[0x039] = KeySpace
|
_glfw.win32.keycodes[0x039] = KeySpace
|
||||||
_glfw.win32.keycodes[0x00F] = KeyTab
|
_glfw.win32.keycodes[0x00F] = KeyTab
|
||||||
_glfw.win32.keycodes[0x03A] = KeyCapsLock
|
_glfw.win32.keycodes[0x03A] = KeyCapsLock
|
||||||
@ -153,12 +152,7 @@ func createKeyTables() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func createHelperWindow() error {
|
func createHelperWindow() error {
|
||||||
m, err := _GetModuleHandleW("")
|
h, err := _CreateWindowExW(_WS_EX_OVERLAPPEDWINDOW, _GLFW_WNDCLASSNAME, "GLFW message window", _WS_CLIPSIBLINGS|_WS_CLIPCHILDREN, 0, 0, 1, 1, 0, 0, _glfw.win32.instance, nil)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
h, err := _CreateWindowExW(_WS_EX_OVERLAPPEDWINDOW, _GLFW_WNDCLASSNAME, "GLFW message window", _WS_CLIPSIBLINGS|_WS_CLIPCHILDREN, 0, 0, 1, 1, 0, 0, _HINSTANCE(m), nil)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -237,6 +231,12 @@ func platformInit() error {
|
|||||||
// Changing the foreground lock timeout was removed from the original code.
|
// Changing the foreground lock timeout was removed from the original code.
|
||||||
// See https://github.com/glfw/glfw/commit/58b48a3a00d9c2a5ca10cc23069a71d8773cc7a4
|
// See https://github.com/glfw/glfw/commit/58b48a3a00d9c2a5ca10cc23069a71d8773cc7a4
|
||||||
|
|
||||||
|
m, err := _GetModuleHandleExW(_GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS|_GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, unsafe.Pointer(&_glfw))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_glfw.win32.instance = _HINSTANCE(m)
|
||||||
|
|
||||||
createKeyTables()
|
createKeyTables()
|
||||||
|
|
||||||
if isWindows10CreatorsUpdateOrGreaterWin32() {
|
if isWindows10CreatorsUpdateOrGreaterWin32() {
|
||||||
|
@ -738,6 +738,21 @@ func windowProc(hWnd windows.HWND, uMsg uint32, wParam _WPARAM, lParam _LPARAM)
|
|||||||
scancode = _MapVirtualKeyW(uint32(wParam), _MAPVK_VK_TO_VSC)
|
scancode = _MapVirtualKeyW(uint32(wParam), _MAPVK_VK_TO_VSC)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HACK: Alt+PrtSc has a different scancode than just PrtSc
|
||||||
|
if scancode == 0x54 {
|
||||||
|
scancode = 0x137
|
||||||
|
}
|
||||||
|
|
||||||
|
// HACK: Ctrl+Pause has a different scancode than just Pause
|
||||||
|
if scancode == 0x146 {
|
||||||
|
scancode = 0x45
|
||||||
|
}
|
||||||
|
|
||||||
|
// HACK: CJK IME sets the extended bit for right Shift
|
||||||
|
if scancode == 0x136 {
|
||||||
|
scancode = 0x36
|
||||||
|
}
|
||||||
|
|
||||||
key := _glfw.win32.keycodes[scancode]
|
key := _glfw.win32.keycodes[scancode]
|
||||||
|
|
||||||
// The Ctrl keys require special handling
|
// The Ctrl keys require special handling
|
||||||
@ -1186,15 +1201,17 @@ func (w *Window) createNativeWindow(wndconfig *wndconfig, fbconfig *fbconfig) er
|
|||||||
|
|
||||||
var xpos, ypos, fullWidth, fullHeight int32
|
var xpos, ypos, fullWidth, fullHeight int32
|
||||||
if w.monitor != nil {
|
if w.monitor != nil {
|
||||||
|
mi, ok := _GetMonitorInfoW(w.monitor.win32.handle)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("glfwwin: GetMonitorInfoW failed")
|
||||||
|
}
|
||||||
// NOTE: This window placement is temporary and approximate, as the
|
// NOTE: This window placement is temporary and approximate, as the
|
||||||
// correct position and size cannot be known until the monitor
|
// correct position and size cannot be known until the monitor
|
||||||
// video mode has been picked in _glfwSetVideoModeWin32
|
// video mode has been picked in _glfwSetVideoModeWin32
|
||||||
x, y, _ := w.monitor.platformGetMonitorPos()
|
xpos = mi.rcMonitor.left
|
||||||
xpos, ypos = int32(x), int32(y)
|
ypos = mi.rcMonitor.top
|
||||||
|
fullWidth = mi.rcMonitor.right - mi.rcMonitor.left
|
||||||
mode := w.monitor.platformGetVideoMode()
|
fullHeight = mi.rcMonitor.bottom - mi.rcMonitor.top
|
||||||
fullWidth = int32(mode.Width)
|
|
||||||
fullHeight = int32(mode.Height)
|
|
||||||
} else {
|
} else {
|
||||||
xpos = _CW_USEDEFAULT
|
xpos = _CW_USEDEFAULT
|
||||||
ypos = _CW_USEDEFAULT
|
ypos = _CW_USEDEFAULT
|
||||||
@ -1211,15 +1228,10 @@ func (w *Window) createNativeWindow(wndconfig *wndconfig, fbconfig *fbconfig) er
|
|||||||
fullWidth, fullHeight = int32(w), int32(h)
|
fullWidth, fullHeight = int32(w), int32(h)
|
||||||
}
|
}
|
||||||
|
|
||||||
m, err := _GetModuleHandleW("")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
h, err := _CreateWindowExW(exStyle, _GLFW_WNDCLASSNAME, wndconfig.title, style, xpos, ypos, fullWidth, fullHeight,
|
h, err := _CreateWindowExW(exStyle, _GLFW_WNDCLASSNAME, wndconfig.title, style, xpos, ypos, fullWidth, fullHeight,
|
||||||
0, // No parent window
|
0, // No parent window
|
||||||
0, // No window menu
|
0, // No window menu
|
||||||
_HINSTANCE(m), unsafe.Pointer(wndconfig))
|
_glfw.win32.instance, unsafe.Pointer(wndconfig))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -1335,11 +1347,7 @@ func registerWindowClassWin32() error {
|
|||||||
wc.cbSize = uint32(unsafe.Sizeof(wc))
|
wc.cbSize = uint32(unsafe.Sizeof(wc))
|
||||||
wc.style = _CS_HREDRAW | _CS_VREDRAW | _CS_OWNDC
|
wc.style = _CS_HREDRAW | _CS_VREDRAW | _CS_OWNDC
|
||||||
wc.lpfnWndProc = _WNDPROC(windowProcPtr)
|
wc.lpfnWndProc = _WNDPROC(windowProcPtr)
|
||||||
module, err := _GetModuleHandleW("")
|
wc.hInstance = _glfw.win32.instance
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
wc.hInstance = _HINSTANCE(module)
|
|
||||||
cursor, err := _LoadCursorW(0, _IDC_ARROW)
|
cursor, err := _LoadCursorW(0, _IDC_ARROW)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -1370,11 +1378,7 @@ func registerWindowClassWin32() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func unregisterWindowClassWin32() error {
|
func unregisterWindowClassWin32() error {
|
||||||
m, err := _GetModuleHandleW("")
|
if err := _UnregisterClassW(_GLFW_WNDCLASSNAME, _glfw.win32.instance); err != nil {
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := _UnregisterClassW(_GLFW_WNDCLASSNAME, _HINSTANCE(m)); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@ -1394,6 +1398,9 @@ func (w *Window) platformCreateWindow(wndconfig *wndconfig, ctxconfig *ctxconfig
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if err := w.refreshContextAttribs(ctxconfig); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if w.monitor != nil {
|
if w.monitor != nil {
|
||||||
@ -1407,6 +1414,20 @@ func (w *Window) platformCreateWindow(wndconfig *wndconfig, ctxconfig *ctxconfig
|
|||||||
if err := w.fitToMonitor(); err != nil {
|
if err := w.fitToMonitor(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if wndconfig.centerCursor {
|
||||||
|
if err := w.centerCursorInContentArea(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if wndconfig.visible {
|
||||||
|
w.platformShowWindow()
|
||||||
|
if wndconfig.focused {
|
||||||
|
if err := w.platformFocusWindow(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -146,29 +146,6 @@ func CreateWindow(width, height int, title string, monitor *Monitor, share *Wind
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctxconfig.client != NoAPI {
|
|
||||||
if err := window.refreshContextAttribs(&ctxconfig); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if window.monitor != nil {
|
|
||||||
if wndconfig.centerCursor {
|
|
||||||
if err := window.centerCursorInContentArea(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if wndconfig.visible {
|
|
||||||
window.platformShowWindow()
|
|
||||||
if wndconfig.focused {
|
|
||||||
if err := window.platformFocusWindow(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return window, nil
|
return window, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user