desktop.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  1. //go:build !wasm
  2. package glfw
  3. import (
  4. "io"
  5. "os"
  6. "runtime"
  7. "github.com/go-gl/glfw/v3.3/glfw"
  8. )
  9. const (
  10. True int = glfw.True
  11. False int = glfw.False
  12. DontCare int = glfw.DontCare
  13. )
  14. func init() {
  15. runtime.LockOSThread()
  16. }
  17. var contextWatcher ContextWatcher
  18. // Init initializes the library.
  19. //
  20. // A valid ContextWatcher must be provided. It gets notified when context becomes current or detached.
  21. // It should be provided by the GL bindings you are using, so you can do glfw.Init(gl.ContextWatcher).
  22. func Init(cw ContextWatcher) error {
  23. contextWatcher = cw
  24. return glfw.Init()
  25. }
  26. func Terminate() {
  27. glfw.Terminate()
  28. }
  29. func CreateWindow(width, height int, title string, monitor *Monitor, share *Window) (*Window, error) {
  30. var m *glfw.Monitor
  31. if monitor != nil {
  32. m = monitor.Monitor
  33. }
  34. var s *glfw.Window
  35. if share != nil {
  36. s = share.Window
  37. }
  38. w, err := glfw.CreateWindow(width, height, title, m, s)
  39. if err != nil {
  40. return nil, err
  41. }
  42. window := &Window{Window: w}
  43. return window, err
  44. }
  45. func (w *Window) SetAttrib(attrib Hint, value int) {
  46. w.Window.SetAttrib(glfw.Hint(attrib), value)
  47. }
  48. func SwapInterval(interval int) {
  49. glfw.SwapInterval(interval)
  50. }
  51. func (w *Window) MakeContextCurrent() {
  52. w.Window.MakeContextCurrent()
  53. // In reality, context is available on each platform via GetGLXContext, GetWGLContext, GetNSGLContext, etc.
  54. // Pretend it is not available and pass nil, since it's not actually needed at this time.
  55. contextWatcher.OnMakeCurrent(nil)
  56. }
  57. func DetachCurrentContext() {
  58. glfw.DetachCurrentContext()
  59. contextWatcher.OnDetach()
  60. }
  61. type Window struct {
  62. *glfw.Window
  63. }
  64. type Monitor struct {
  65. *glfw.Monitor
  66. }
  67. func GetPrimaryMonitor() *Monitor {
  68. m := glfw.GetPrimaryMonitor()
  69. return &Monitor{Monitor: m}
  70. }
  71. func (w *Window) SetMonitor(monitor *Monitor, xpos, ypos, width, height, refreshRate int) {
  72. w.Window.SetMonitor(monitor.Monitor, xpos, ypos, width, height, refreshRate)
  73. }
  74. func PollEvents() {
  75. glfw.PollEvents()
  76. }
  77. type CursorPosCallback func(w *Window, xpos float64, ypos float64)
  78. func (w *Window) SetCursorPosCallback(cbfun CursorPosCallback) (previous CursorPosCallback) {
  79. wrappedCbfun := func(_ *glfw.Window, xpos float64, ypos float64) {
  80. cbfun(w, xpos, ypos)
  81. }
  82. p := w.Window.SetCursorPosCallback(wrappedCbfun)
  83. _ = p
  84. // TODO: Handle previous.
  85. return nil
  86. }
  87. type MouseMovementCallback func(w *Window, xpos float64, ypos float64, xdelta float64, ydelta float64)
  88. var lastMousePos [2]float64 // HACK.
  89. // TODO: For now, this overrides SetCursorPosCallback; should support both.
  90. func (w *Window) SetMouseMovementCallback(cbfun MouseMovementCallback) (previous MouseMovementCallback) {
  91. lastMousePos[0], lastMousePos[1] = w.Window.GetCursorPos()
  92. wrappedCbfun := func(_ *glfw.Window, xpos float64, ypos float64) {
  93. xdelta, ydelta := xpos-lastMousePos[0], ypos-lastMousePos[1]
  94. lastMousePos[0], lastMousePos[1] = xpos, ypos
  95. cbfun(w, xpos, ypos, xdelta, ydelta)
  96. }
  97. p := w.Window.SetCursorPosCallback(wrappedCbfun)
  98. _ = p
  99. // TODO: Handle previous.
  100. return nil
  101. }
  102. type KeyCallback func(w *Window, key Key, scancode int, action Action, mods ModifierKey)
  103. func (w *Window) SetKeyCallback(cbfun KeyCallback) (previous KeyCallback) {
  104. wrappedCbfun := func(_ *glfw.Window, key glfw.Key, scancode int, action glfw.Action, mods glfw.ModifierKey) {
  105. cbfun(w, Key(key), scancode, Action(action), ModifierKey(mods))
  106. }
  107. p := w.Window.SetKeyCallback(wrappedCbfun)
  108. _ = p
  109. // TODO: Handle previous.
  110. return nil
  111. }
  112. type CharCallback func(w *Window, char rune)
  113. func (w *Window) SetCharCallback(cbfun CharCallback) (previous CharCallback) {
  114. wrappedCbfun := func(_ *glfw.Window, char rune) {
  115. cbfun(w, char)
  116. }
  117. p := w.Window.SetCharCallback(wrappedCbfun)
  118. _ = p
  119. // TODO: Handle previous.
  120. return nil
  121. }
  122. type ScrollCallback func(w *Window, xoff float64, yoff float64)
  123. func (w *Window) SetScrollCallback(cbfun ScrollCallback) (previous ScrollCallback) {
  124. wrappedCbfun := func(_ *glfw.Window, xoff float64, yoff float64) {
  125. cbfun(w, xoff, yoff)
  126. }
  127. p := w.Window.SetScrollCallback(wrappedCbfun)
  128. _ = p
  129. // TODO: Handle previous.
  130. return nil
  131. }
  132. type MouseButtonCallback func(w *Window, button MouseButton, action Action, mods ModifierKey)
  133. func (w *Window) SetMouseButtonCallback(cbfun MouseButtonCallback) (previous MouseButtonCallback) {
  134. wrappedCbfun := func(_ *glfw.Window, button glfw.MouseButton, action glfw.Action, mods glfw.ModifierKey) {
  135. cbfun(w, MouseButton(button), Action(action), ModifierKey(mods))
  136. }
  137. p := w.Window.SetMouseButtonCallback(wrappedCbfun)
  138. _ = p
  139. // TODO: Handle previous.
  140. return nil
  141. }
  142. type FramebufferSizeCallback func(w *Window, width int, height int)
  143. func (w *Window) SetFramebufferSizeCallback(cbfun FramebufferSizeCallback) (previous FramebufferSizeCallback) {
  144. wrappedCbfun := func(_ *glfw.Window, width int, height int) {
  145. cbfun(w, width, height)
  146. }
  147. p := w.Window.SetFramebufferSizeCallback(wrappedCbfun)
  148. _ = p
  149. // TODO: Handle previous.
  150. return nil
  151. }
  152. func (w *Window) GetKey(key Key) Action {
  153. a := w.Window.GetKey(glfw.Key(key))
  154. return Action(a)
  155. }
  156. func (w *Window) GetMouseButton(button MouseButton) Action {
  157. a := w.Window.GetMouseButton(glfw.MouseButton(button))
  158. return Action(a)
  159. }
  160. func (w *Window) GetInputMode(mode InputMode) int {
  161. return w.Window.GetInputMode(glfw.InputMode(mode))
  162. }
  163. func (w *Window) SetInputMode(mode InputMode, value int) {
  164. w.Window.SetInputMode(glfw.InputMode(mode), value)
  165. }
  166. type Key glfw.Key
  167. const (
  168. KeyUnknown = Key(glfw.KeyUnknown)
  169. KeySpace = Key(glfw.KeySpace)
  170. KeyApostrophe = Key(glfw.KeyApostrophe)
  171. KeyComma = Key(glfw.KeyComma)
  172. KeyMinus = Key(glfw.KeyMinus)
  173. KeyPeriod = Key(glfw.KeyPeriod)
  174. KeySlash = Key(glfw.KeySlash)
  175. Key0 = Key(glfw.Key0)
  176. Key1 = Key(glfw.Key1)
  177. Key2 = Key(glfw.Key2)
  178. Key3 = Key(glfw.Key3)
  179. Key4 = Key(glfw.Key4)
  180. Key5 = Key(glfw.Key5)
  181. Key6 = Key(glfw.Key6)
  182. Key7 = Key(glfw.Key7)
  183. Key8 = Key(glfw.Key8)
  184. Key9 = Key(glfw.Key9)
  185. KeySemicolon = Key(glfw.KeySemicolon)
  186. KeyEqual = Key(glfw.KeyEqual)
  187. KeyA = Key(glfw.KeyA)
  188. KeyB = Key(glfw.KeyB)
  189. KeyC = Key(glfw.KeyC)
  190. KeyD = Key(glfw.KeyD)
  191. KeyE = Key(glfw.KeyE)
  192. KeyF = Key(glfw.KeyF)
  193. KeyG = Key(glfw.KeyG)
  194. KeyH = Key(glfw.KeyH)
  195. KeyI = Key(glfw.KeyI)
  196. KeyJ = Key(glfw.KeyJ)
  197. KeyK = Key(glfw.KeyK)
  198. KeyL = Key(glfw.KeyL)
  199. KeyM = Key(glfw.KeyM)
  200. KeyN = Key(glfw.KeyN)
  201. KeyO = Key(glfw.KeyO)
  202. KeyP = Key(glfw.KeyP)
  203. KeyQ = Key(glfw.KeyQ)
  204. KeyR = Key(glfw.KeyR)
  205. KeyS = Key(glfw.KeyS)
  206. KeyT = Key(glfw.KeyT)
  207. KeyU = Key(glfw.KeyU)
  208. KeyV = Key(glfw.KeyV)
  209. KeyW = Key(glfw.KeyW)
  210. KeyX = Key(glfw.KeyX)
  211. KeyY = Key(glfw.KeyY)
  212. KeyZ = Key(glfw.KeyZ)
  213. KeyLeftBracket = Key(glfw.KeyLeftBracket)
  214. KeyBackslash = Key(glfw.KeyBackslash)
  215. KeyRightBracket = Key(glfw.KeyRightBracket)
  216. KeyGraveAccent = Key(glfw.KeyGraveAccent)
  217. KeyWorld1 = Key(glfw.KeyWorld1)
  218. KeyWorld2 = Key(glfw.KeyWorld2)
  219. KeyEscape = Key(glfw.KeyEscape)
  220. KeyEnter = Key(glfw.KeyEnter)
  221. KeyTab = Key(glfw.KeyTab)
  222. KeyBackspace = Key(glfw.KeyBackspace)
  223. KeyInsert = Key(glfw.KeyInsert)
  224. KeyDelete = Key(glfw.KeyDelete)
  225. KeyRight = Key(glfw.KeyRight)
  226. KeyLeft = Key(glfw.KeyLeft)
  227. KeyDown = Key(glfw.KeyDown)
  228. KeyUp = Key(glfw.KeyUp)
  229. KeyPageUp = Key(glfw.KeyPageUp)
  230. KeyPageDown = Key(glfw.KeyPageDown)
  231. KeyHome = Key(glfw.KeyHome)
  232. KeyEnd = Key(glfw.KeyEnd)
  233. KeyCapsLock = Key(glfw.KeyCapsLock)
  234. KeyScrollLock = Key(glfw.KeyScrollLock)
  235. KeyNumLock = Key(glfw.KeyNumLock)
  236. KeyPrintScreen = Key(glfw.KeyPrintScreen)
  237. KeyPause = Key(glfw.KeyPause)
  238. KeyF1 = Key(glfw.KeyF1)
  239. KeyF2 = Key(glfw.KeyF2)
  240. KeyF3 = Key(glfw.KeyF3)
  241. KeyF4 = Key(glfw.KeyF4)
  242. KeyF5 = Key(glfw.KeyF5)
  243. KeyF6 = Key(glfw.KeyF6)
  244. KeyF7 = Key(glfw.KeyF7)
  245. KeyF8 = Key(glfw.KeyF8)
  246. KeyF9 = Key(glfw.KeyF9)
  247. KeyF10 = Key(glfw.KeyF10)
  248. KeyF11 = Key(glfw.KeyF11)
  249. KeyF12 = Key(glfw.KeyF12)
  250. KeyF13 = Key(glfw.KeyF13)
  251. KeyF14 = Key(glfw.KeyF14)
  252. KeyF15 = Key(glfw.KeyF15)
  253. KeyF16 = Key(glfw.KeyF16)
  254. KeyF17 = Key(glfw.KeyF17)
  255. KeyF18 = Key(glfw.KeyF18)
  256. KeyF19 = Key(glfw.KeyF19)
  257. KeyF20 = Key(glfw.KeyF20)
  258. KeyF21 = Key(glfw.KeyF21)
  259. KeyF22 = Key(glfw.KeyF22)
  260. KeyF23 = Key(glfw.KeyF23)
  261. KeyF24 = Key(glfw.KeyF24)
  262. KeyF25 = Key(glfw.KeyF25)
  263. KeyKP0 = Key(glfw.KeyKP0)
  264. KeyKP1 = Key(glfw.KeyKP1)
  265. KeyKP2 = Key(glfw.KeyKP2)
  266. KeyKP3 = Key(glfw.KeyKP3)
  267. KeyKP4 = Key(glfw.KeyKP4)
  268. KeyKP5 = Key(glfw.KeyKP5)
  269. KeyKP6 = Key(glfw.KeyKP6)
  270. KeyKP7 = Key(glfw.KeyKP7)
  271. KeyKP8 = Key(glfw.KeyKP8)
  272. KeyKP9 = Key(glfw.KeyKP9)
  273. KeyKPDecimal = Key(glfw.KeyKPDecimal)
  274. KeyKPDivide = Key(glfw.KeyKPDivide)
  275. KeyKPMultiply = Key(glfw.KeyKPMultiply)
  276. KeyKPSubtract = Key(glfw.KeyKPSubtract)
  277. KeyKPAdd = Key(glfw.KeyKPAdd)
  278. KeyKPEnter = Key(glfw.KeyKPEnter)
  279. KeyKPEqual = Key(glfw.KeyKPEqual)
  280. KeyLeftShift = Key(glfw.KeyLeftShift)
  281. KeyLeftControl = Key(glfw.KeyLeftControl)
  282. KeyLeftAlt = Key(glfw.KeyLeftAlt)
  283. KeyLeftSuper = Key(glfw.KeyLeftSuper)
  284. KeyRightShift = Key(glfw.KeyRightShift)
  285. KeyRightControl = Key(glfw.KeyRightControl)
  286. KeyRightAlt = Key(glfw.KeyRightAlt)
  287. KeyRightSuper = Key(glfw.KeyRightSuper)
  288. KeyMenu = Key(glfw.KeyMenu)
  289. )
  290. type MouseButton glfw.MouseButton
  291. const (
  292. MouseButton1 = MouseButton(glfw.MouseButton1)
  293. MouseButton2 = MouseButton(glfw.MouseButton2)
  294. MouseButton3 = MouseButton(glfw.MouseButton3)
  295. MouseButtonLeft = MouseButton(glfw.MouseButtonLeft)
  296. MouseButtonRight = MouseButton(glfw.MouseButtonRight)
  297. MouseButtonMiddle = MouseButton(glfw.MouseButtonMiddle)
  298. )
  299. type Joystick glfw.Joystick
  300. const (
  301. Joystick1 = Joystick(glfw.Joystick1)
  302. Joystick2 = Joystick(glfw.Joystick2)
  303. Joystick3 = Joystick(glfw.Joystick3)
  304. Joystick4 = Joystick(glfw.Joystick4)
  305. Joystick5 = Joystick(glfw.Joystick5)
  306. Joystick6 = Joystick(glfw.Joystick6)
  307. Joystick7 = Joystick(glfw.Joystick7)
  308. Joystick8 = Joystick(glfw.Joystick8)
  309. Joystick9 = Joystick(glfw.Joystick9)
  310. Joystick10 = Joystick(glfw.Joystick10)
  311. Joystick11 = Joystick(glfw.Joystick11)
  312. Joystick12 = Joystick(glfw.Joystick12)
  313. Joystick13 = Joystick(glfw.Joystick13)
  314. Joystick14 = Joystick(glfw.Joystick14)
  315. Joystick15 = Joystick(glfw.Joystick15)
  316. Joystick16 = Joystick(glfw.Joystick16)
  317. JoystickLast = Joystick(glfw.JoystickLast)
  318. )
  319. type GamepadAxis glfw.GamepadAxis
  320. const (
  321. AxisLeftX = GamepadAxis(glfw.AxisLeftX)
  322. AxisLeftY = GamepadAxis(glfw.AxisLeftY)
  323. AxisRightX = GamepadAxis(glfw.AxisRightX)
  324. AxisRightY = GamepadAxis(glfw.AxisRightY)
  325. AxisLeftTrigger = GamepadAxis(glfw.AxisLeftTrigger)
  326. AxisRightTrigger = GamepadAxis(glfw.AxisRightTrigger)
  327. AxisLast = GamepadAxis(glfw.AxisLast)
  328. )
  329. type GamepadButton glfw.GamepadButton
  330. const (
  331. ButtonA = GamepadButton(glfw.ButtonA)
  332. ButtonB = GamepadButton(glfw.ButtonB)
  333. ButtonX = GamepadButton(glfw.ButtonX)
  334. ButtonY = GamepadButton(glfw.ButtonY)
  335. ButtonLeftBumper = GamepadButton(glfw.ButtonLeftBumper)
  336. ButtonRightBumper = GamepadButton(glfw.ButtonRightBumper)
  337. ButtonBack = GamepadButton(glfw.ButtonBack)
  338. ButtonStart = GamepadButton(glfw.ButtonStart)
  339. ButtonGuide = GamepadButton(glfw.ButtonGuide)
  340. ButtonLeftThumb = GamepadButton(glfw.ButtonLeftThumb)
  341. ButtonRightThumb = GamepadButton(glfw.ButtonRightThumb)
  342. ButtonDpadUp = GamepadButton(glfw.ButtonDpadUp)
  343. ButtonDpadRight = GamepadButton(glfw.ButtonDpadRight)
  344. ButtonDpadDown = GamepadButton(glfw.ButtonDpadDown)
  345. ButtonDpadLeft = GamepadButton(glfw.ButtonDpadLeft)
  346. ButtonLast = GamepadButton(glfw.ButtonLast)
  347. ButtonCross = GamepadButton(glfw.ButtonCross)
  348. ButtonCircle = GamepadButton(glfw.ButtonCircle)
  349. ButtonSquare = GamepadButton(glfw.ButtonSquare)
  350. ButtonTriangle = GamepadButton(glfw.ButtonTriangle)
  351. )
  352. type Action glfw.Action
  353. const (
  354. Release = Action(glfw.Release)
  355. Press = Action(glfw.Press)
  356. Repeat = Action(glfw.Repeat)
  357. )
  358. type InputMode int
  359. const (
  360. CursorMode = InputMode(glfw.CursorMode)
  361. StickyKeysMode = InputMode(glfw.StickyKeysMode)
  362. StickyMouseButtonsMode = InputMode(glfw.StickyMouseButtonsMode)
  363. LockKeyMods = InputMode(glfw.LockKeyMods)
  364. RawMouseMotion = InputMode(glfw.RawMouseMotion)
  365. )
  366. const (
  367. CursorNormal = int(glfw.CursorNormal)
  368. CursorHidden = int(glfw.CursorHidden)
  369. CursorDisabled = int(glfw.CursorDisabled)
  370. )
  371. type ModifierKey int
  372. const (
  373. ModShift = ModifierKey(glfw.ModShift)
  374. ModControl = ModifierKey(glfw.ModControl)
  375. ModAlt = ModifierKey(glfw.ModAlt)
  376. ModSuper = ModifierKey(glfw.ModSuper)
  377. )
  378. func (joy Joystick) IsPresent() bool {
  379. return glfw.Joystick(joy).Present()
  380. }
  381. func (joy Joystick) GetGamepadName() string {
  382. return glfw.Joystick(joy).GetGamepadName()
  383. }
  384. func (joy Joystick) GetAxes() []float32 {
  385. return glfw.Joystick(joy).GetAxes()
  386. }
  387. func (joy Joystick) GetButtons() []Action {
  388. src := glfw.Joystick(joy).GetButtons()
  389. dst := make([]Action, len(src))
  390. for i, v := range src {
  391. dst[i] = Action(v)
  392. }
  393. return dst
  394. }
  395. // Open opens a named asset. It's the caller's responsibility to close it when done.
  396. //
  397. // For now, assets are read directly from the current working directory.
  398. func Open(name string) (io.ReadCloser, error) {
  399. return os.Open(name)
  400. }
  401. // ---
  402. func WaitEvents() {
  403. glfw.WaitEvents()
  404. }
  405. func PostEmptyEvent() {
  406. glfw.PostEmptyEvent()
  407. }
  408. func DefaultWindowHints() {
  409. glfw.DefaultWindowHints()
  410. }
  411. func (w *Window) SetClipboardString(str string) {
  412. glfw.SetClipboardString(str)
  413. }
  414. func (w *Window) GetClipboardString() (string, error) {
  415. return glfw.GetClipboardString(), nil
  416. }
  417. type CloseCallback func(w *Window)
  418. func (w *Window) SetCloseCallback(cbfun CloseCallback) (previous CloseCallback) {
  419. wrappedCbfun := func(_ *glfw.Window) {
  420. cbfun(w)
  421. }
  422. p := w.Window.SetCloseCallback(wrappedCbfun)
  423. _ = p
  424. // TODO: Handle previous.
  425. return nil
  426. }
  427. type RefreshCallback func(w *Window)
  428. func (w *Window) SetRefreshCallback(cbfun RefreshCallback) (previous RefreshCallback) {
  429. wrappedCbfun := func(_ *glfw.Window) {
  430. cbfun(w)
  431. }
  432. p := w.Window.SetRefreshCallback(wrappedCbfun)
  433. _ = p
  434. // TODO: Handle previous.
  435. return nil
  436. }
  437. type SizeCallback func(w *Window, width int, height int)
  438. func (w *Window) SetSizeCallback(cbfun SizeCallback) (previous SizeCallback) {
  439. wrappedCbfun := func(_ *glfw.Window, width int, height int) {
  440. cbfun(w, width, height)
  441. }
  442. p := w.Window.SetSizeCallback(wrappedCbfun)
  443. _ = p
  444. // TODO: Handle previous.
  445. return nil
  446. }
  447. type CursorEnterCallback func(w *Window, entered bool)
  448. func (w *Window) SetCursorEnterCallback(cbfun CursorEnterCallback) (previous CursorEnterCallback) {
  449. wrappedCbfun := func(_ *glfw.Window, entered bool) {
  450. cbfun(w, entered)
  451. }
  452. p := w.Window.SetCursorEnterCallback(wrappedCbfun)
  453. _ = p
  454. // TODO: Handle previous.
  455. return nil
  456. }
  457. type CharModsCallback func(w *Window, char rune, mods ModifierKey)
  458. // SetCharModsCallback is a wrapper around the GFLW window SetCharModsCallback method.
  459. //
  460. // Deprecated: Scheduled for removal in GLFW version 4.0.
  461. func (w *Window) SetCharModsCallback(cbfun CharModsCallback) (previous CharModsCallback) {
  462. wrappedCbfun := func(_ *glfw.Window, char rune, mods glfw.ModifierKey) {
  463. cbfun(w, char, ModifierKey(mods))
  464. }
  465. p := w.Window.SetCharModsCallback(wrappedCbfun)
  466. _ = p
  467. // TODO: Handle previous.
  468. return nil
  469. }
  470. type PosCallback func(w *Window, xpos int, ypos int)
  471. func (w *Window) SetPosCallback(cbfun PosCallback) (previous PosCallback) {
  472. wrappedCbfun := func(_ *glfw.Window, xpos int, ypos int) {
  473. cbfun(w, xpos, ypos)
  474. }
  475. p := w.Window.SetPosCallback(wrappedCbfun)
  476. _ = p
  477. // TODO: Handle previous.
  478. return nil
  479. }
  480. type FocusCallback func(w *Window, focused bool)
  481. func (w *Window) SetFocusCallback(cbfun FocusCallback) (previous FocusCallback) {
  482. wrappedCbfun := func(_ *glfw.Window, focused bool) {
  483. cbfun(w, focused)
  484. }
  485. p := w.Window.SetFocusCallback(wrappedCbfun)
  486. _ = p
  487. // TODO: Handle previous.
  488. return nil
  489. }
  490. type IconifyCallback func(w *Window, iconified bool)
  491. func (w *Window) SetIconifyCallback(cbfun IconifyCallback) (previous IconifyCallback) {
  492. wrappedCbfun := func(_ *glfw.Window, iconified bool) {
  493. cbfun(w, iconified)
  494. }
  495. p := w.Window.SetIconifyCallback(wrappedCbfun)
  496. _ = p
  497. // TODO: Handle previous.
  498. return nil
  499. }
  500. type DropCallback func(w *Window, names []string)
  501. func (w *Window) SetDropCallback(cbfun DropCallback) (previous DropCallback) {
  502. wrappedCbfun := func(_ *glfw.Window, names []string) {
  503. cbfun(w, names)
  504. }
  505. p := w.Window.SetDropCallback(wrappedCbfun)
  506. _ = p
  507. // TODO: Handle previous.
  508. return nil
  509. }