window.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. // Copyright 2016 The G3N 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. // Package window abstracts the OpenGL Window manager
  5. // Currently only "glfw" is supported
  6. package window
  7. import (
  8. "github.com/g3n/engine/core"
  9. "github.com/g3n/engine/gls"
  10. )
  11. // IWindowManager is the interface for all window managers
  12. type IWindowManager interface {
  13. ScreenResolution(interface{}) (width, height int)
  14. CreateWindow(width, height int, title string, full bool) (IWindow, error)
  15. CreateCursor(imgFile string, xhot, yhot int) (int, error)
  16. DisposeCursor(key int)
  17. DisposeAllCursors()
  18. SetSwapInterval(interval int)
  19. PollEvents()
  20. Terminate()
  21. }
  22. // IWindow is the interface for all windows
  23. type IWindow interface {
  24. core.IDispatcher
  25. Gls() *gls.GLS
  26. Manager() IWindowManager
  27. MakeContextCurrent()
  28. FramebufferSize() (width int, height int)
  29. Scale() (x float64, y float64)
  30. Size() (width int, height int)
  31. SetSize(width int, height int)
  32. Pos() (xpos, ypos int)
  33. SetPos(xpos, ypos int)
  34. SetTitle(title string)
  35. SetStandardCursor(cursor StandardCursor)
  36. SetCustomCursor(int)
  37. SetInputMode(mode InputMode, state int)
  38. SetCursorPos(xpos, ypos float64)
  39. ShouldClose() bool
  40. SetShouldClose(bool)
  41. FullScreen() bool
  42. SetFullScreen(bool)
  43. SwapBuffers()
  44. Destroy()
  45. }
  46. // Key corresponds to a keyboard key.
  47. type Key int
  48. // ModifierKey corresponds to a modifier key.
  49. type ModifierKey int
  50. // MouseButton corresponds to a mouse button.
  51. type MouseButton int
  52. // StandardCursor corresponds to a g3n standard cursor icon.
  53. type StandardCursor int
  54. // Action corresponds to a key or button action.
  55. type Action int
  56. // InputMode corresponds to an input mode.
  57. type InputMode int
  58. // InputMode corresponds to an input mode.
  59. type CursorMode int
  60. //
  61. // Window event names using for dispatch and subscribe
  62. //
  63. const (
  64. OnWindowPos = "win.OnWindowPos"
  65. OnWindowSize = "win.OnWindowSize"
  66. OnKeyUp = "win.OnKeyUp"
  67. OnKeyDown = "win.OnKeyDown"
  68. OnKeyRepeat = "win.OnKeyRepeat"
  69. OnChar = "win.OnChar"
  70. OnCursor = "win.OnCursor"
  71. OnMouseUp = "win.OnMouseUp"
  72. OnMouseDown = "win.OnMouseDown"
  73. OnScroll = "win.OnScroll"
  74. OnFrame = "win.OnFrame"
  75. )
  76. // PosEvent describes a windows position changed event
  77. type PosEvent struct {
  78. W IWindow
  79. Xpos int
  80. Ypos int
  81. }
  82. // SizeEvent describers a window size changed event
  83. type SizeEvent struct {
  84. W IWindow
  85. Width int
  86. Height int
  87. }
  88. // KeyEvent describes a window key event
  89. type KeyEvent struct {
  90. W IWindow
  91. Keycode Key
  92. Scancode int
  93. Action Action
  94. Mods ModifierKey
  95. }
  96. // CharEvent describes a window char event
  97. type CharEvent struct {
  98. W IWindow
  99. Char rune
  100. Mods ModifierKey
  101. }
  102. // MouseEvent describes a mouse event over the window
  103. type MouseEvent struct {
  104. W IWindow
  105. Xpos float32
  106. Ypos float32
  107. Button MouseButton
  108. Action Action
  109. Mods ModifierKey
  110. }
  111. // CursorEvent describes a cursor position changed event
  112. type CursorEvent struct {
  113. W IWindow
  114. Xpos float32
  115. Ypos float32
  116. }
  117. // ScrollEvent describes a scroll event
  118. type ScrollEvent struct {
  119. W IWindow
  120. Xoffset float32
  121. Yoffset float32
  122. }