github.com/rajveermalviya/gamen@v0.1.2-0.20220930195403-9be15877c1aa/display/display.go (about) 1 package display 2 3 import ( 4 "time" 5 6 "github.com/rajveermalviya/gamen/cursors" 7 "github.com/rajveermalviya/gamen/dpi" 8 "github.com/rajveermalviya/gamen/events" 9 ) 10 11 // Display is the main event loop handle. 12 // It provides a way to poll window events from the system 13 type Display interface { 14 // Destroy destroys all the windows associated with this display 15 // and the underlying system event loop 16 // 17 // Can be called multiple times, but subsequent calls are ignored. 18 // Can be called from any goroutine. 19 Destroy() 20 21 // Wait blocks until there is a new event, it returns after dispatching 22 // all the pending events in the queue. 23 // 24 // Return value of false indicates Display is destroyed and you must 25 // exit the loop. 26 // 27 // Can only be called from main goroutine 28 Wait() bool 29 30 // Poll dispatches all the pending events in the queue and returns immediately 31 // 32 // Return value of false indicates Display is destroyed and you must 33 // exit the loop. 34 // 35 // Can only be called from main goroutine 36 Poll() bool 37 38 // WaitTimeout blocks until there is a new event or until the specified timeout 39 // whichever happens first 40 // 41 // Return value of false indicates Display is destroyed and you must 42 // exit the loop. 43 // 44 // Can only be called from main goroutine 45 WaitTimeout(time.Duration) bool 46 } 47 48 type Window interface { 49 // Destroys the window, it must not be used after this point. 50 // 51 // Can be called multiple times, but subsequent calls are ignored. 52 Destroy() 53 54 // SetTitle sets the title for the window 55 // 56 // Unsupported backends: android 57 SetTitle(string) 58 59 // InnerSize returns the current size of the drawable surface 60 // 61 InnerSize() dpi.PhysicalSize[uint32] 62 63 // SetInnerSize sets the size of the drawable surface 64 // 65 // Unsupported backends: android 66 SetInnerSize(dpi.Size[uint32]) 67 68 // SetMinInnerSize sets the minimum size window can be resized 69 // 70 // Unsupported backends: android 71 SetMinInnerSize(dpi.Size[uint32]) 72 73 // SetMaxInnerSize sets the maximum size window can be resized 74 // 75 // Unsupported backends: android 76 SetMaxInnerSize(dpi.Size[uint32]) 77 78 // Maximized returns if window is currently maximized 79 // 80 // Unsupported backends: android, web 81 Maximized() bool 82 83 // SetMinimized minimizes or iconifies the window 84 // 85 // Unsupported backends: android, web 86 SetMinimized() 87 88 // SetMinimized maximizes or un-maximizes the window 89 // 90 // Unsupported backends: android, web 91 SetMaximized(bool) 92 93 // SetCursorIcon changes the cursor icon for this window 94 // 95 // Unsupported backends: android 96 SetCursorIcon(cursors.Icon) 97 98 // SetCursorVisible hides or un-hides the cursor for this window 99 // 100 // Unsupported backends: android 101 SetCursorVisible(bool) 102 103 // SetFullscreen sets window to fullscreen or normal mode 104 // 105 // Unsupported backends: android 106 SetFullscreen(bool) 107 108 // Fullscreen returns if window is currently in fullscreen mode 109 // 110 // Unsupported backends: android 111 Fullscreen() bool 112 113 // DragWindow starts an interactive move of window. 114 // Window follows the mouse cursor until mouse button is released. 115 // 116 // Unsupported backends: android, web 117 DragWindow() 118 119 // SetDecorations enables or disables window decorations 120 // 121 // Unsupported backends: android, web 122 SetDecorations(bool) 123 124 // Decorated returns if window currently has decorations 125 // 126 // Unsupported backends: android, web 127 Decorated() bool 128 129 // Callbacks 130 131 // SetResizedCallback registers a callback to receive resize events for the window 132 // It also fires when scale factor for the window changes 133 // 134 SetResizedCallback(events.WindowResizedCallback) 135 136 // SetCloseRequestedCallback registers a callback to receive close event for the window 137 // 138 // Unsupported backends: android 139 SetCloseRequestedCallback(events.WindowCloseRequestedCallback) 140 141 // SetCursorEnteredCallback registers a callback to receive an event when cursor enters the window 142 // 143 // Unsupported backends: android 144 SetCursorEnteredCallback(events.WindowCursorEnteredCallback) 145 146 // SetCursorLeftCallback registers a callback to receive an event when cursor leaves the window 147 // 148 // Unsupported backends: android 149 SetCursorLeftCallback(events.WindowCursorLeftCallback) 150 151 // SetCursorLeftCallback registers a callback to receive an event when cursor moves inside the window 152 // 153 // Unsupported backends: android 154 SetCursorMovedCallback(events.WindowCursorMovedCallback) 155 156 // SetMouseScrollCallback registers a callback to receive mouse scroll event for the window 157 // 158 // Unsupported backends: android 159 SetMouseScrollCallback(events.WindowMouseScrollCallback) 160 161 // SetMouseInputCallback registers a callback to receive mouse input event for the window 162 // 163 // Unsupported backends: android 164 SetMouseInputCallback(events.WindowMouseInputCallback) 165 166 // SetMouseInputCallback registers a callback to receive mouse input event for the window 167 // 168 // Unsupported backends: wayland, web, win32, xcb 169 SetTouchInputCallback(events.WindowTouchInputCallback) 170 171 // SetFocusedCallback registers a callback to receive focus event for the window 172 // 173 SetFocusedCallback(events.WindowFocusedCallback) 174 175 // SetUnfocusedCallback registers a callback to receive un-focus event for the window 176 // 177 SetUnfocusedCallback(events.WindowUnfocusedCallback) 178 179 // SetModifiersChangedCallback registers a callback to receive an event when modifiers change for the window 180 // 181 // Unsupported backends: android 182 SetModifiersChangedCallback(events.WindowModifiersChangedCallback) 183 184 // SetKeyboardInputCallback registers a callback to receive keyboard events for the window 185 // 186 SetKeyboardInputCallback(events.WindowKeyboardInputCallback) 187 188 // SetReceivedCharacterCallback registers a callback to receive a UTF-8 character 189 // for the corresponding key press inside the window 190 // 191 SetReceivedCharacterCallback(events.WindowReceivedCharacterCallback) 192 } 193 194 // Extension methods for android backend 195 type AndroidWindowExt interface { 196 // SetSurfaceCreatedCallback registers a callback to receive an event when 197 // ANativeWindow is ready for use 198 // 199 SetSurfaceCreatedCallback(events.WindowSurfaceCreatedCallback) 200 201 // SetSurfaceDestroyedCallback registers a callback to receive an event when 202 // ANativeWindow is no longer usable 203 // 204 SetSurfaceDestroyedCallback(events.WindowSurfaceDestroyedCallback) 205 206 // EnableIme shows the software keyboard 207 // 208 EnableIme() 209 210 // DisableIme hides the software keyboard 211 // 212 DisableIme() 213 }