window.go 3.0 KB

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