1 type WindowEvent = 2 | Iconified 3 | Deiconified 4 | Maximized 5 | Unmaximized 6 7 type GlfwWindow 8 def mouse_position = 9 let mut x = 0 10 let mut y = 0 11 Glfw.get_cursor_pos self x@mut_ptr y@mut_ptr 12 13 (x.max 0 as u32, y.max 0 as u32) 14 15 object GlfwWindow = 16 def create (width : u32 17 height : u32 18 header : String 19 is_resizable : bool) = 20 let c_header @owner = header.to_c_string 21 if not is_resizable then 22 Glfw.window_hint Glfw.resizable Glfw.false 23 24 Glfw.create_window width.as<int> height.as<int> c_header 25 null null 26 27 begin@ window 28 29 type OsWindow @[mut local] = 30 val window : GlfwWindow 31 let mut mouse_x : u32 32 let mut mouse_y : u32 33 var width : u32 34 var height : u32 35 val is_resizable : bool 36 val keys = Stream<(Key, KeyAction, KeyModifiers)>.new 37 val chars = Stream<Char>.new 38 val mouse_positions = Stream<(u32, u32)>.new 39 val mouse_buttons = Stream<(MouseButton, MouseAction, KeyModifiers)>.new 40 val mouse_scrolls = Stream<(f32, f32)>.new 41 val events = Stream<WindowEvent>.new 42 val sizes = Stream<(u32, u32)>.new 43 44 def discard = 45 Glfw.destroy_window window 46 47 def update = 48 let (x, y) = window.mouse_position 49 50 if x <> mouse_x || y <> mouse_y then 51 mouse_x = x 52 mouse_y = y 53 mouse_positions.push (x, y) 54 55 def get_mouse_position = (mouse_x, mouse_y) 56 def key_state (key : Key) = Glfw.get_key window key 57 def mouse_state (button : MouseButton) = Glfw.get_mouse_button window button 58 59 def is_shift_pressed = key_state Key/LeftShift == KeyState/Press 60 || key_state Key/RightShift == KeyState/Press 61 62 def is_control_pressed = key_state Key/LeftControl == KeyState/Press 63 || key_state Key/RightControl == KeyState/Press 64 65 def should_close = case Glfw.window_should_close window of 66 0 -> false 67 else -> true 68 69 def set_clipboard (s : String) = 70 let c_s @owner = s.to_c_string 71 Glfw.set_clipboard_string window c_s 72 73 def get_clipboard = Glfw.get_clipboard_string window 74 |> to_string 75 76 local windows @mut = Map<GlfwWindow, OsWindow>.new 77