callback_windows.go (2229B)
1 // Copyright 2021 The Ebiten Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package glfw 16 17 import ( 18 "golang.org/x/sys/windows" 19 ) 20 21 func ToCharModsCallback(cb func(window *Window, char rune, mods ModifierKey)) CharModsCallback { 22 if cb == nil { 23 return 0 24 } 25 return CharModsCallback(windows.NewCallbackCDecl(func(window uintptr, char rune, mods ModifierKey) uintptr { 26 cb(theGLFWWindows.get(window), char, mods) 27 return 0 28 })) 29 } 30 31 func ToCloseCallback(cb func(window *Window)) CloseCallback { 32 if cb == nil { 33 return 0 34 } 35 return CloseCallback(windows.NewCallbackCDecl(func(window uintptr) uintptr { 36 cb(theGLFWWindows.get(window)) 37 return 0 38 })) 39 } 40 41 func ToFramebufferSizeCallback(cb func(window *Window, width int, height int)) FramebufferSizeCallback { 42 if cb == nil { 43 return 0 44 } 45 return FramebufferSizeCallback(windows.NewCallbackCDecl(func(window uintptr, width int, height int) uintptr { 46 cb(theGLFWWindows.get(window), width, height) 47 return 0 48 })) 49 } 50 51 func ToScrollCallback(cb func(window *Window, xoff float64, yoff float64)) ScrollCallback { 52 if cb == nil { 53 return 0 54 } 55 return ScrollCallback(windows.NewCallbackCDecl(func(window uintptr, xoff *float64, yoff *float64) uintptr { 56 // xoff and yoff were originally float64, but there is no good way to pass them on 32bit 57 // machines via NewCallback. We've fixed GLFW side to use pointer values. 58 cb(theGLFWWindows.get(window), *xoff, *yoff) 59 return 0 60 })) 61 } 62 63 func ToSizeCallback(cb func(window *Window, width int, height int)) SizeCallback { 64 if cb == nil { 65 return 0 66 } 67 return SizeCallback(windows.NewCallbackCDecl(func(window uintptr, width int, height int) uintptr { 68 cb(theGLFWWindows.get(window), width, height) 69 return 0 70 })) 71 }