glfwmonitor.bmx 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. ' Copyright (c) 2022 Bruce A Henderson
  2. '
  3. ' This software is provided 'as-is', without any express or implied
  4. ' warranty. In no event will the authors be held liable for any damages
  5. ' arising from the use of this software.
  6. '
  7. ' Permission is granted to anyone to use this software for any purpose,
  8. ' including commercial applications, and to alter it and redistribute it
  9. ' freely, subject to the following restrictions:
  10. '
  11. ' 1. The origin of this software must not be misrepresented; you must not
  12. ' claim that you wrote the original software. If you use this software
  13. ' in a product, an acknowledgment in the product documentation would be
  14. ' appreciated but is not required.
  15. '
  16. ' 2. Altered source versions must be plainly marked as such, and must not be
  17. ' misrepresented as being the original software.
  18. '
  19. ' 3. This notice may not be removed or altered from any source
  20. ' distribution.
  21. '
  22. SuperStrict
  23. Rem
  24. bbdoc: GLFW Monitor
  25. End Rem
  26. Module GLFW.GLFWMonitor
  27. Import "common.bmx"
  28. Rem
  29. bbdoc: A GLFW Monitor
  30. End Rem
  31. Type TGLFWMonitor
  32. Field monitorPtr:Byte Ptr
  33. Global monitorCallback(monitor:TGLFWMonitor, event:Int)
  34. Function _create:TGLFWMonitor(monitorPtr:Byte Ptr)
  35. If monitorPtr Then
  36. Local this:TGLFWMonitor = New TGLFWMonitor
  37. this.monitorPtr = monitorPtr
  38. Return this
  39. End If
  40. End Function
  41. Rem
  42. bbdoc: Returns an array of handles for all currently connected monitors.
  43. about: The primary monitor is always first in the returned array. If no monitors were found, this function returns #Null.
  44. End Rem
  45. Function GetMonitors:TGLFWMonitor[]()
  46. Local count:Int
  47. Local mptrs:Byte Ptr Ptr = bmx_glfw_glfwGetMonitors(count)
  48. Local monitors:TGLFWMonitor[count]
  49. For Local i:Int = 0 Until count
  50. monitors[i] = _create(mptrs[i])
  51. Next
  52. Return monitors
  53. End Function
  54. Rem
  55. bbdoc: Returns the primary monitor.
  56. about: This is usually the monitor where elements like the task bar or global menu bar are located.
  57. End Rem
  58. Function GetPrimaryMonitor:TGLFWMonitor()
  59. Return _create(bmx_glfw_glfwGetPrimaryMonitor())
  60. End Function
  61. Rem
  62. bbdoc: Returns the position, in screen coordinates, of the upper-left corner of the monitor.
  63. End Rem
  64. Method GetPos(x:Int Var, y:Int Var)
  65. bmx_glfw_glfwGetMonitorPos(monitorPtr, x, y)
  66. End Method
  67. Rem
  68. bbdoc: Returns the position, in screen coordinates, of the upper-left corner of the work area of the monitor along with the work area size in screen coordinates.
  69. about: The work area is defined as the area of the monitor not occluded by the operating system task bar where present.
  70. If no task bar exists then the work area is the monitor resolution in screen coordinates.
  71. End Rem
  72. Method GetWorkarea(x:Int Var, y:Int Var, width:Int Var, height:Int Var)
  73. bmx_glfw_glfwGetMonitorWorkarea(monitorPtr, x, y, width, height)
  74. End Method
  75. Rem
  76. bbdoc: Returns the size, in millimetres, of the display area of the monitor.
  77. about: Some systems do not provide accurate monitor size information, either because the monitor EDID data is incorrect
  78. or because the driver does not report it accurately.
  79. End Rem
  80. Method GetPhysicalSize(widthMM:Int Var, heightMM:Int Var)
  81. bmx_glfw_glfwGetMonitorPhysicalSize(monitorPtr, widthMM, heightMM)
  82. End Method
  83. Rem
  84. bbdoc: Retrieves the content scale for the monitor.
  85. about: The content scale is the ratio between the current DPI and the platform's default DPI. This is especially
  86. important for text and any UI elements. If the pixel dimensions of your UI scaled by this look appropriate on your
  87. machine then it should appear at a reasonable size on other machines regardless of their DPI and scaling settings.
  88. This relies on the system DPI and scaling settings being somewhat correct.
  89. The content scale may depend on both the monitor resolution and pixel density and on user settings. It may be very
  90. different from the raw DPI calculated from the physical size and current resolution.
  91. End Rem
  92. Method GetContentScale(xscale:Float Var, yscale:Float Var)
  93. bmx_glfw_glfwGetMonitorContentScale(monitorPtr, xscale, yscale)
  94. End Method
  95. Rem
  96. bbdoc: Returns a human-readable name of the monitor.
  97. about: The name typically reflects the make and model of the monitor and is not guaranteed to be unique among the connected monitors.
  98. End Rem
  99. Method GetName:String()
  100. Local b:Byte Ptr = bmx_glfw_glfwGetMonitorName(monitorPtr)
  101. Return String.FromUTF8String(b)
  102. End Method
  103. Rem
  104. bbdoc: Returns an array of all video modes supported by the monitor.
  105. about: The returned array is sorted in ascending order, first by color bit depth (the sum of all channel depths) and
  106. then by resolution area (the product of width and height).
  107. End Rem
  108. Method GetVideoModes:SGLFWvidmode[]()
  109. Local count:Int
  110. Local mptrs:SGLFWvidmode Ptr= bmx_glfw_glfwGetVideoModes(monitorPtr, count)
  111. Local modes:SGLFWvidmode[count]
  112. For Local i:Int = 0 Until count
  113. modes[i] = mptrs[i]
  114. Next
  115. Return modes
  116. End Method
  117. Rem
  118. bbdoc: Returns the current video mode of the monitor.
  119. about: If you have created a full screen window for that monitor, the return value will depend on whether that window is iconified.
  120. End Rem
  121. Method GetVideoMode:SGLFWvidmode()
  122. Local mptr:SGLFWvidmode Ptr= bmx_glfw_glfwGetVideoMode(monitorPtr)
  123. Return mptr[0]
  124. End Method
  125. Rem
  126. bbdoc: Generates an appropriately sized gamma ramp from the specified exponent and then calls #SetGammaRamp with it.
  127. about: The value must be a finite number greater than zero.
  128. The software controlled gamma ramp is applied in addition to the hardware gamma correction, which today is usually
  129. an approximation of sRGB gamma. This means that setting a perfectly linear ramp, or gamma 1.0, will produce the
  130. default (usually sRGB-like) behavior.
  131. For gamma correct rendering with OpenGL or OpenGL ES, see the #GLFW_SRGB_CAPABLE hint.
  132. End Rem
  133. Method SetGamma(Gamma:Float)
  134. bmx_glfw_glfwSetGamma(monitorPtr, Gamma)
  135. End Method
  136. Rem
  137. bbdoc: Returns the current gamma ramp of the monitor.
  138. End Rem
  139. Method GetGammaRamp:SGLFWgammaramp()
  140. Return bmx_glfw_glfwGetGammaRamp(monitorPtr)[0]
  141. End Method
  142. Rem
  143. bbdoc: Sets the current gamma ramp for the monitor.
  144. about: The original gamma ramp for that monitor is saved by GLFW the first time this method is called and is restored by glfwTerminate.
  145. The software controlled gamma ramp is applied in addition to the hardware gamma correction, which today is usually an approximation
  146. of sRGB gamma. This means that setting a perfectly linear ramp, or gamma 1.0, will produce the default (usually sRGB-like) behavior.
  147. For gamma correct rendering with OpenGL or OpenGL ES, see the GLFW_SRGB_CAPABLE hint.
  148. End Rem
  149. Method SetGammaRamp(ramp:SGLFWgammaramp)
  150. bmx_glfw_glfwSetGammaRamp(monitorPtr, Varptr ramp)
  151. End Method
  152. Rem
  153. bbdoc: Sets the monitor configuration callback, or removes the currently set callback.
  154. about: This is called when a monitor is connected to or disconnected from the system.
  155. End Rem
  156. Method SetMonitorCallback(callback(monitor:TGLFWMonitor, event:Int))
  157. monitorCallback = callback
  158. If callback = Null Then
  159. bmx_glfw_glfwSetMonitorCallback(Null)
  160. Else
  161. bmx_glfw_glfwSetMonitorCallback(_monitorCallback)
  162. End If
  163. End Method
  164. Function _monitorCallback(handle:Byte Ptr, event:Int)
  165. monitorCallback(_create(handle), event)
  166. End Function
  167. End Type
  168. Rem
  169. bbdoc: Video mode type.
  170. End Rem
  171. Struct SGLFWvidmode
  172. Rem
  173. bbdoc: The width, in screen coordinates, of the video mode.
  174. End Rem
  175. Field width:Int
  176. Rem
  177. bbdoc: The height, in screen coordinates, of the video mode.
  178. End Rem
  179. Field height:Int
  180. Rem
  181. bbdoc: The bit depth of the red channel of the video mode.
  182. End Rem
  183. Field redBits:Int
  184. Rem
  185. bbdoc: The bit depth of the green channel of the video mode.
  186. End Rem
  187. Field greenBits:Int
  188. Rem
  189. bbdoc: The bit depth of the blue channel of the video mode.
  190. End Rem
  191. Field blueBits:Int
  192. Rem
  193. bbdoc: The refresh rate, in Hz, of the video mode.
  194. End Rem
  195. Field refreshRate:Int
  196. End Struct
  197. Rem
  198. bbdoc: Gamma ramp.
  199. End Rem
  200. Struct SGLFWgammaramp
  201. Rem
  202. bbdoc: An array of value describing the response of the red channel.
  203. End Rem
  204. Field red:Short Ptr
  205. Rem
  206. bbdoc: An array of value describing the response of the green channel.
  207. End Rem
  208. Field green:Short Ptr
  209. Rem
  210. bbdoc: An array of value describing the response of the blue channel.
  211. End Rem
  212. Field blue:Short Ptr
  213. Rem
  214. bbdoc: The number of elements in each array.
  215. End Rem
  216. Field size:UInt
  217. End Struct
  218. Private
  219. Extern
  220. Function bmx_glfw_glfwGetVideoModes:SGLFWvidmode Ptr(monitor:Byte Ptr, count:Int Var)="glfwGetVideoModes"
  221. Function bmx_glfw_glfwGetVideoMode:SGLFWvidmode Ptr(monitor:Byte Ptr)="glfwGetVideoMode"
  222. Function bmx_glfw_glfwGetGammaRamp:SGLFWgammaramp Ptr(monitor:Byte Ptr)="glfwGetGammaRamp"
  223. Function bmx_glfw_glfwSetGammaRamp(monitorPtr:Byte Ptr, ramp:SGLFWgammaramp Ptr)="glfwSetGammaRamp"
  224. End Extern