| 1 | module sapp |
| 2 | |
| 3 | import sokol.memory |
| 4 | |
| 5 | const max_touchpoints = 8 |
| 6 | const max_mousebuttons = 3 |
| 7 | const max_keycodes = 512 |
| 8 | const max_iconimages = 8 |
| 9 | |
| 10 | @[typedef] |
| 11 | pub struct C.sapp_allocator { |
| 12 | pub mut: |
| 13 | alloc_fn memory.FnAllocatorAlloc = unsafe { nil } |
| 14 | free_fn memory.FnAllocatorFree = unsafe { nil } |
| 15 | user_data voidptr |
| 16 | } |
| 17 | |
| 18 | pub type Allocator = C.sapp_allocator |
| 19 | |
| 20 | @[typedef] |
| 21 | pub struct C.sapp_logger { |
| 22 | pub mut: |
| 23 | func memory.FnLogCb = unsafe { nil } |
| 24 | user_data voidptr |
| 25 | } |
| 26 | |
| 27 | pub type Logger = C.sapp_logger |
| 28 | |
| 29 | // sapp_range is a general pointer/size-pair struct for passing binary blobs into sokol_app.h |
| 30 | @[typedef] |
| 31 | pub struct C.sapp_range { |
| 32 | pub: |
| 33 | ptr voidptr |
| 34 | size usize |
| 35 | } |
| 36 | |
| 37 | pub type Range = C.sapp_range |
| 38 | |
| 39 | @[typedef] |
| 40 | pub struct C.sapp_image_desc { |
| 41 | pub: |
| 42 | width int |
| 43 | height int |
| 44 | cursor_hotspot_x int |
| 45 | cursor_hotspot_y int |
| 46 | pixels Range |
| 47 | } |
| 48 | |
| 49 | pub type ImageDesc = C.sapp_image_desc |
| 50 | |
| 51 | @[typedef] |
| 52 | pub struct C.sapp_icon_desc { |
| 53 | pub: |
| 54 | sokol_default bool |
| 55 | images [max_iconimages]ImageDesc |
| 56 | } |
| 57 | |
| 58 | pub type IconDesc = C.sapp_icon_desc |
| 59 | |
| 60 | @[typedef] |
| 61 | pub struct C.sapp_gl_desc { |
| 62 | pub mut: |
| 63 | major_version int // override GL/GLES major version |
| 64 | minor_version int // override GL/GLES minor version |
| 65 | } |
| 66 | |
| 67 | pub type GlDesc = C.sapp_gl_desc |
| 68 | |
| 69 | @[typedef] |
| 70 | pub struct C.sapp_win32_desc { |
| 71 | pub: |
| 72 | console_utf8 bool // if true, set the output console codepage to UTF-8 |
| 73 | console_create bool // if true, attach stdout/stderr to a new console window |
| 74 | console_attach bool // if true, attach stdout/stderr to parent process |
| 75 | } |
| 76 | |
| 77 | pub type Win32Desc = C.sapp_win32_desc |
| 78 | |
| 79 | @[typedef] |
| 80 | pub struct C.sapp_html5_desc { |
| 81 | pub: |
| 82 | canvas_selector &char = c'#canvas' // css selector of the HTML5 canvas element, default is "#canvas" |
| 83 | canvas_resize bool // if true, the HTML5 canvas size is set to sapp_desc.width/height |
| 84 | preserve_drawing_buffer bool // HTML5 only: whether to preserve default framebuffer content between frames |
| 85 | premultiplied_alpha bool // HTML5 only: whether the rendered pixels use premultiplied alpha convention |
| 86 | ask_leave_site bool // initial state of the internal html5_ask_leave_site flag |
| 87 | update_document_title bool // if true, update the HTML document.title with sapp_desc.window_title |
| 88 | bubble_mouse_events bool // if true, mouse events will bubble up to the web page |
| 89 | bubble_touch_events bool // same for touch events |
| 90 | bubble_wheel_events bool // same for wheel events |
| 91 | bubble_key_events bool // if true, bubble up *all* key events to browser |
| 92 | bubble_char_events bool // if true, bubble up character events to browser |
| 93 | use_emsc_set_main_loop bool // if true, use emscripten_set_main_loop() instead of emscripten_request_animation_frame_loop() |
| 94 | emsc_set_main_loop_simulate_infinite_loop bool // this will be passed as the simulate_infinite_loop arg to emscripten_set_main_loop() |
| 95 | } |
| 96 | |
| 97 | pub type Html5Desc = C.sapp_html5_desc |
| 98 | |
| 99 | @[typedef] |
| 100 | pub struct C.sapp_ios_desc { |
| 101 | pub: |
| 102 | keyboard_resizes_canvas bool // if true, showing the iOS keyboard shrinks the canvas |
| 103 | } |
| 104 | |
| 105 | pub type IosDesc = C.sapp_ios_desc |
| 106 | |
| 107 | // --- environment structs (returned by sapp_get_environment) --- |
| 108 | |
| 109 | @[typedef] |
| 110 | pub struct C.sapp_environment_defaults { |
| 111 | pub: |
| 112 | color_format int |
| 113 | depth_format int |
| 114 | sample_count int |
| 115 | } |
| 116 | |
| 117 | pub type EnvironmentDefaults = C.sapp_environment_defaults |
| 118 | |
| 119 | @[typedef] |
| 120 | pub struct C.sapp_metal_environment { |
| 121 | pub: |
| 122 | device voidptr |
| 123 | } |
| 124 | |
| 125 | @[typedef] |
| 126 | pub struct C.sapp_d3d11_environment { |
| 127 | pub: |
| 128 | device voidptr |
| 129 | device_context voidptr |
| 130 | } |
| 131 | |
| 132 | @[typedef] |
| 133 | pub struct C.sapp_wgpu_environment { |
| 134 | pub: |
| 135 | device voidptr |
| 136 | } |
| 137 | |
| 138 | @[typedef] |
| 139 | pub struct C.sapp_vulkan_environment { |
| 140 | pub: |
| 141 | instance voidptr |
| 142 | physical_device voidptr |
| 143 | device voidptr |
| 144 | queue voidptr |
| 145 | queue_family_index u32 |
| 146 | } |
| 147 | |
| 148 | pub type MetalEnvironment = C.sapp_metal_environment |
| 149 | pub type D3d11Environment = C.sapp_d3d11_environment |
| 150 | pub type WgpuEnvironment = C.sapp_wgpu_environment |
| 151 | pub type VulkanEnvironment = C.sapp_vulkan_environment |
| 152 | |
| 153 | @[typedef] |
| 154 | pub struct C.sapp_environment { |
| 155 | pub: |
| 156 | defaults EnvironmentDefaults |
| 157 | metal MetalEnvironment |
| 158 | d3d11 D3d11Environment |
| 159 | wgpu WgpuEnvironment |
| 160 | vulkan VulkanEnvironment |
| 161 | } |
| 162 | |
| 163 | pub type Environment = C.sapp_environment |
| 164 | |
| 165 | // --- swapchain structs (returned by sapp_get_swapchain) --- |
| 166 | |
| 167 | @[typedef] |
| 168 | pub struct C.sapp_metal_swapchain { |
| 169 | pub: |
| 170 | current_drawable voidptr |
| 171 | depth_stencil_texture voidptr |
| 172 | msaa_color_texture voidptr |
| 173 | } |
| 174 | |
| 175 | @[typedef] |
| 176 | pub struct C.sapp_d3d11_swapchain { |
| 177 | pub: |
| 178 | render_view voidptr |
| 179 | resolve_view voidptr |
| 180 | depth_stencil_view voidptr |
| 181 | } |
| 182 | |
| 183 | @[typedef] |
| 184 | pub struct C.sapp_wgpu_swapchain { |
| 185 | pub: |
| 186 | render_view voidptr |
| 187 | resolve_view voidptr |
| 188 | depth_stencil_view voidptr |
| 189 | } |
| 190 | |
| 191 | @[typedef] |
| 192 | pub struct C.sapp_vulkan_swapchain { |
| 193 | pub: |
| 194 | render_image voidptr |
| 195 | render_view voidptr |
| 196 | resolve_image voidptr |
| 197 | resolve_view voidptr |
| 198 | depth_stencil_image voidptr |
| 199 | depth_stencil_view voidptr |
| 200 | render_finished_semaphore voidptr |
| 201 | present_complete_semaphore voidptr |
| 202 | } |
| 203 | |
| 204 | @[typedef] |
| 205 | pub struct C.sapp_gl_swapchain { |
| 206 | pub: |
| 207 | framebuffer u32 |
| 208 | } |
| 209 | |
| 210 | pub type MetalSwapchain = C.sapp_metal_swapchain |
| 211 | pub type D3d11Swapchain = C.sapp_d3d11_swapchain |
| 212 | pub type WgpuSwapchain = C.sapp_wgpu_swapchain |
| 213 | pub type VulkanSwapchain = C.sapp_vulkan_swapchain |
| 214 | pub type GlSwapchain = C.sapp_gl_swapchain |
| 215 | |
| 216 | @[typedef] |
| 217 | pub struct C.sapp_swapchain { |
| 218 | pub: |
| 219 | width int |
| 220 | height int |
| 221 | sample_count int |
| 222 | color_format int |
| 223 | depth_format int |
| 224 | metal MetalSwapchain |
| 225 | d3d11 D3d11Swapchain |
| 226 | wgpu WgpuSwapchain |
| 227 | vulkan VulkanSwapchain |
| 228 | gl GlSwapchain |
| 229 | } |
| 230 | |
| 231 | pub type Swapchain = C.sapp_swapchain |
| 232 | |
| 233 | @[typedef] |
| 234 | pub struct C.sapp_desc { |
| 235 | pub mut: |
| 236 | // these are the user-provided callbacks without user data |
| 237 | init_cb fn () = unsafe { nil } |
| 238 | frame_cb fn () = unsafe { nil } |
| 239 | cleanup_cb fn () = unsafe { nil } |
| 240 | event_cb fn (&Event) = unsafe { nil } // &sapp_event |
| 241 | |
| 242 | user_data voidptr // these are the user-provided callbacks with user data |
| 243 | init_userdata_cb fn (voidptr) = unsafe { nil } |
| 244 | frame_userdata_cb fn (voidptr) = unsafe { nil } |
| 245 | cleanup_userdata_cb fn (voidptr) = unsafe { nil } |
| 246 | event_userdata_cb fn (&Event, voidptr) = unsafe { nil } |
| 247 | |
| 248 | width int // the preferred width of the window / canvas |
| 249 | height int // the preferred height of the window / canvas |
| 250 | sample_count int // MSAA sample count |
| 251 | swap_interval int // the preferred swap interval on Windows, macOS, Linux, iOS, and HTML5; Android support is not implemented yet |
| 252 | high_dpi bool // whether the rendering canvas is full-resolution on HighDPI displays |
| 253 | fullscreen bool // whether the window should be created in fullscreen mode |
| 254 | alpha bool // whether the framebuffer should have an alpha channel (ignored on some platforms) |
| 255 | window_title &char // the window title as UTF-8 encoded string |
| 256 | enable_clipboard bool // enable clipboard access, default is false |
| 257 | clipboard_size int // max size of clipboard content in bytes |
| 258 | enable_dragndrop bool // enable file dropping (drag'n'drop), default is false |
| 259 | max_dropped_files int // max number of dropped files to process (default: 1) |
| 260 | max_dropped_file_path_length int // max length in bytes of a dropped UTF-8 file path (default: 2048) |
| 261 | icon IconDesc // the initial window icon to set |
| 262 | allocator Allocator // optional memory allocation overrides (default: malloc/free) |
| 263 | logger Logger // logging callback override (default: NO LOGGING!) |
| 264 | // backend-specific options |
| 265 | gl GlDesc // OpenGL specific options |
| 266 | win32 Win32Desc // Win32 specific options |
| 267 | html5 Html5Desc // HTML5 specific options |
| 268 | ios IosDesc // iOS specific options |
| 269 | // V patches |
| 270 | __v_native_render bool // V patch to allow for native rendering |
| 271 | min_width int // V patch to allow for min window width |
| 272 | min_height int // V patch to allow for min window height |
| 273 | borderless_window bool // V patch to create a window without native decorations when supported |
| 274 | } |
| 275 | |
| 276 | pub type Desc = C.sapp_desc |
| 277 | |
| 278 | @[typedef] |
| 279 | pub struct C.sapp_event { |
| 280 | pub mut: |
| 281 | frame_count u64 // current frame counter, always valid, useful for checking if two events were issued in the same frame |
| 282 | type EventType // the event type, always valid |
| 283 | key_code KeyCode // the virtual key code, only valid in KEY_UP, KEY_DOWN |
| 284 | char_code u32 // the UTF-32 character code, only valid in CHAR events |
| 285 | key_repeat bool // true if this is a key-repeat event, valid in KEY_UP, KEY_DOWN and CHAR |
| 286 | modifiers u32 // current modifier keys, valid in all key-, char- and mouse-events |
| 287 | mouse_button MouseButton // mouse button that was pressed or released, valid in MOUSE_DOWN, MOUSE_UP |
| 288 | mouse_x f32 // current horizontal mouse position in pixels, always valid except during mouse lock |
| 289 | mouse_y f32 // current vertical mouse position in pixels, always valid except during mouse lock |
| 290 | mouse_dx f32 // relative horizontal mouse movement since last frame, always valid |
| 291 | mouse_dy f32 // relative vertical mouse movement since last frame, always valid |
| 292 | scroll_x f32 // horizontal mouse wheel scroll distance, valid in MOUSE_SCROLL events |
| 293 | scroll_y f32 // vertical mouse wheel scroll distance, valid in MOUSE_SCROLL events |
| 294 | num_touches int // number of valid items in the touches[] array |
| 295 | touches [max_touchpoints]TouchPoint // current touch points, valid in TOUCHES_BEGIN, TOUCHES_MOVED, TOUCHES_ENDED |
| 296 | window_width int // current window- and framebuffer width in pixels, always valid |
| 297 | window_height int // current window- and framebuffer height in pixels, always valid |
| 298 | framebuffer_width int // = window_width * dpi_scale |
| 299 | framebuffer_height int // = window_height * dpi_scale |
| 300 | } |
| 301 | |
| 302 | pub type Event = C.sapp_event |
| 303 | |
| 304 | pub fn (e &Event) str() string { |
| 305 | return 'evt: frame_count=${e.frame_count}, type=${EventType(e.type)}' |
| 306 | } |
| 307 | |
| 308 | @[typedef] |
| 309 | pub struct C.sapp_touchpoint { |
| 310 | pub: |
| 311 | identifier u64 |
| 312 | pos_x f32 |
| 313 | pos_y f32 |
| 314 | android_tooltype TouchToolType |
| 315 | changed bool |
| 316 | } |
| 317 | |
| 318 | pub type TouchPoint = C.sapp_touchpoint |
| 319 | |