desktop.go 17 KB

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