1     object Glfw =
2         val no_api : int = 0
3         val false : int = 0
4         val client_api : int = 0x00022001
5         val resizable : int = 0x00020003
6         val true "GLFW_TRUE" : int
7         val context_version_major "GLFW_CONTEXT_VERSION_MAJOR" : int
8         val context_version_minor "GLFW_CONTEXT_VERSION_MINOR" : int
9         val opengl_forward_compat "GLFW_OPENGL_FORWARD_COMPAT" : int
10        val opengl_profile "GLFW_OPENGL_PROFILE" : int
11        val opengl_core_profile "GLFW_OPENGL_CORE_PROFILE" : int
12        val stencil_bits "GLFW_STENCIL_BITS" : int
13        val alpha_bits "GLFW_ALPHA_BITS" : int
14        val depth_bits "GLFW_DEPTH_BITS" : int
15        val dont_care "GLFW_DONT_CARE" : int
16        val floating "GLFW_FLOATING" : int
17    
18    type MouseButton =
19        | Left = 0
20        | Right = 1
21        | Middle = 2
22        | Button4 = 3
23        | Button5 = 4
24        | Button6 = 5
25        | Button7 = 6
26        | Button8 = 7
27    
28    type MouseAction =
29        | Release = 0
30        | Press = 1
31    
32        def is_press = self == Press
33        def is_release = self == Release
34    
35    type KeyState =
36        | Release = 0
37        | Press = 1
38    
39    type MouseShape @[repr int] =
40        | Arrow = 0x00036001
41        | ResizeEw = 0x00036005
42    
43    type GLFWwindow @c
44    type GlfwWindow = MutPtr<GLFWwindow>
45    type GLFWmonitor @c
46    type GlfwMonitor = MutPtr<GLFWmonitor>
47    type GLFWcursor @c
48    type GlfwCursor = MutPtr<GLFWcursor>
49    
50    typealias KeyFun = fn
51        (window : GlfwWindow) * (key : Key) * (scancode : int)
52        * (action : KeyAction) * (mods : KeyModifiers) -> Unit
53    
54    typealias CharFun = fn (window : GlfwWindow) * (codepoint : uint) -> Unit
55    typealias CursorPosFun = fn (window : GlfwWindow) * (x : f64) * (y : f64) -> Unit
56    typealias ScrollFun = fn (window : GlfwWindow) * (x : f64) * (y : f64) -> Unit
57    typealias ErrorFun = fn (error_code : int) * (description : CString) -> Unit
58    
59    typealias MouseButtonFun = fn
60        (window : GlfwWindow) * (button : MouseButton)
61        * (action : MouseAction) * (mods : KeyModifiers) -> Unit
62    
63    typealias WindowSizeFun = fn
64        (window : GlfwWindow) * (width : int) * (height : int) -> Unit
65    
66    typealias WindowIconifyFun = fn (window : GlfwWindow) * (iconified : int) -> Unit
67    typealias WindowMaximizeFun = fn (window : GlfwWindow) * (maximized : int) -> Unit
68    
69    type VideoMode "GLFWvidmode" = struct
70        width : int
71        height : int
72        red_bits : int
73        green_bits : int
74        blue_bits : int
75        refresh_rate : int
76    
77    object Glfw
78        def init "glfwInit" : int
79        def window_hint "glfwWindowHint" (hint : int) (value : int)
80        def create_window "glfwCreateWindow" (width : int
81                                              height : int
82                                              title : CString
83                                              monitor : GlfwMonitor
84                                              share : GlfwWindow) : GlfwWindow
85    
86        def window_should_close "glfwWindowShouldClose" (window : GlfwWindow) : int
87        def poll_events "glfwPollEvents"
88        def destroy_window "glfwDestroyWindow" (window : GlfwWindow)
89        def terminate "glfwTerminate"
90        def get_primary_monitor "glfwGetPrimaryMonitor" : GlfwMonitor
91        def get_video_mode "glfwGetVideoMode" (monitor : GlfwMonitor) : ptr VideoMode
92        def set_window_size_limits "glfwSetWindowSizeLimits" (window : GlfwWindow
93                                                              min_width : int
94                                                              min_height : int
95                                                              max_width : int
96                                                              max_height : int)
97    
98        def set_key_callback "glfwSetKeyCallback"
99            (window : GlfwWindow
100            callback : KeyFun) : KeyFun
101   
102       def set_char_callback "glfwSetCharCallback"
103           (window : GlfwWindow
104            callback : CharFun) : CharFun
105   
106       def set_cursor_pos_callback "glfwSetCursorPosCallback"
107           (window : GlfwWindow
108            callback : CursorPosFun) : CursorPosFun
109   
110       def set_mouse_button_callback "glfwSetMouseButtonCallback"
111           (window : GlfwWindow
112            callback : MouseButtonFun) : MouseButtonFun
113   
114       def set_window_size_callback "glfwSetWindowSizeCallback"
115           (window : GlfwWindow
116            callback : WindowSizeFun) : WindowSizeFun
117   
118       def set_window_iconify_callback "glfwSetWindowIconifyCallback"
119           (window : GlfwWindow
120            callback : WindowIconifyFun) : WindowIconifyFun
121   
122       def set_window_maximize_callback "glfwSetWindowMaximizeCallback"
123           (window : GlfwWindow
124            callback : WindowMaximizeFun) : WindowMaximizeFun
125   
126       def set_scroll_callback "glfwSetScrollCallback"
127           (window : GlfwWindow
128            callback : ScrollFun) : ScrollFun
129   
130       def set_error_callback "glfwSetErrorCallback" (callback : ErrorFun)
131       def get_cursor_pos "glfwGetCursorPos" (window : GlfwWindow
132                                              x : mut ptr f64
133                                              y : mut ptr f64)
134   
135       def get_mouse_button "glfwGetMouseButton"
136           (window : GlfwWindow
137            button : MouseButton) : MouseAction
138   
139       def get_key "glfwGetKey" (window : GlfwWindow) (key : Key) : KeyState
140       def create_standard_cursor "glfwCreateStandardCursor"
141           (shape : MouseShape) : GlfwCursor
142   
143       def set_cursor "glfwSetCursor" (window : GlfwWindow) (cursor : GlfwCursor)
144       def get_clipboard_string "glfwGetClipboardString"
145           (window : GlfwWindow) : CString
146   
147       def set_clipboard_string "glfwSetClipboardString"
148           (window : GlfwWindow
149            string : CString)
150   
151       def create_window_surface "glfwCreateWindowSurface"
152           (instance : VkInstance
153            window : GlfwWindow
154            allocator : VkAllocator
155            surface : mut ptr VkSurface) : VkResult
156   
157       def swap_buffers "glfwSwapBuffers" (window : GlfwWindow)
158       def swap_interval "glfwSwapInterval" (interval : int)
159       def make_context_current "glfwMakeContextCurrent" (window : GlfwWindow)
160       def wait_events "glfwWaitEvents"
161