v / vlib / sokol / sapp / sapp_structs.c.v
318 lines · 270 sloc · 10.81 KB · 0c40641367b719800137f3d72706aba1b2020205
Raw
1module sapp
2
3import sokol.memory
4
5const max_touchpoints = 8
6const max_mousebuttons = 3
7const max_keycodes = 512
8const max_iconimages = 8
9
10@[typedef]
11pub struct C.sapp_allocator {
12pub mut:
13 alloc_fn memory.FnAllocatorAlloc = unsafe { nil }
14 free_fn memory.FnAllocatorFree = unsafe { nil }
15 user_data voidptr
16}
17
18pub type Allocator = C.sapp_allocator
19
20@[typedef]
21pub struct C.sapp_logger {
22pub mut:
23 func memory.FnLogCb = unsafe { nil }
24 user_data voidptr
25}
26
27pub 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]
31pub struct C.sapp_range {
32pub:
33 ptr voidptr
34 size usize
35}
36
37pub type Range = C.sapp_range
38
39@[typedef]
40pub struct C.sapp_image_desc {
41pub:
42 width int
43 height int
44 cursor_hotspot_x int
45 cursor_hotspot_y int
46 pixels Range
47}
48
49pub type ImageDesc = C.sapp_image_desc
50
51@[typedef]
52pub struct C.sapp_icon_desc {
53pub:
54 sokol_default bool
55 images [max_iconimages]ImageDesc
56}
57
58pub type IconDesc = C.sapp_icon_desc
59
60@[typedef]
61pub struct C.sapp_gl_desc {
62pub mut:
63 major_version int // override GL/GLES major version
64 minor_version int // override GL/GLES minor version
65}
66
67pub type GlDesc = C.sapp_gl_desc
68
69@[typedef]
70pub struct C.sapp_win32_desc {
71pub:
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
77pub type Win32Desc = C.sapp_win32_desc
78
79@[typedef]
80pub struct C.sapp_html5_desc {
81pub:
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
97pub type Html5Desc = C.sapp_html5_desc
98
99@[typedef]
100pub struct C.sapp_ios_desc {
101pub:
102 keyboard_resizes_canvas bool // if true, showing the iOS keyboard shrinks the canvas
103}
104
105pub type IosDesc = C.sapp_ios_desc
106
107// --- environment structs (returned by sapp_get_environment) ---
108
109@[typedef]
110pub struct C.sapp_environment_defaults {
111pub:
112 color_format int
113 depth_format int
114 sample_count int
115}
116
117pub type EnvironmentDefaults = C.sapp_environment_defaults
118
119@[typedef]
120pub struct C.sapp_metal_environment {
121pub:
122 device voidptr
123}
124
125@[typedef]
126pub struct C.sapp_d3d11_environment {
127pub:
128 device voidptr
129 device_context voidptr
130}
131
132@[typedef]
133pub struct C.sapp_wgpu_environment {
134pub:
135 device voidptr
136}
137
138@[typedef]
139pub struct C.sapp_vulkan_environment {
140pub:
141 instance voidptr
142 physical_device voidptr
143 device voidptr
144 queue voidptr
145 queue_family_index u32
146}
147
148pub type MetalEnvironment = C.sapp_metal_environment
149pub type D3d11Environment = C.sapp_d3d11_environment
150pub type WgpuEnvironment = C.sapp_wgpu_environment
151pub type VulkanEnvironment = C.sapp_vulkan_environment
152
153@[typedef]
154pub struct C.sapp_environment {
155pub:
156 defaults EnvironmentDefaults
157 metal MetalEnvironment
158 d3d11 D3d11Environment
159 wgpu WgpuEnvironment
160 vulkan VulkanEnvironment
161}
162
163pub type Environment = C.sapp_environment
164
165// --- swapchain structs (returned by sapp_get_swapchain) ---
166
167@[typedef]
168pub struct C.sapp_metal_swapchain {
169pub:
170 current_drawable voidptr
171 depth_stencil_texture voidptr
172 msaa_color_texture voidptr
173}
174
175@[typedef]
176pub struct C.sapp_d3d11_swapchain {
177pub:
178 render_view voidptr
179 resolve_view voidptr
180 depth_stencil_view voidptr
181}
182
183@[typedef]
184pub struct C.sapp_wgpu_swapchain {
185pub:
186 render_view voidptr
187 resolve_view voidptr
188 depth_stencil_view voidptr
189}
190
191@[typedef]
192pub struct C.sapp_vulkan_swapchain {
193pub:
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]
205pub struct C.sapp_gl_swapchain {
206pub:
207 framebuffer u32
208}
209
210pub type MetalSwapchain = C.sapp_metal_swapchain
211pub type D3d11Swapchain = C.sapp_d3d11_swapchain
212pub type WgpuSwapchain = C.sapp_wgpu_swapchain
213pub type VulkanSwapchain = C.sapp_vulkan_swapchain
214pub type GlSwapchain = C.sapp_gl_swapchain
215
216@[typedef]
217pub struct C.sapp_swapchain {
218pub:
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
231pub type Swapchain = C.sapp_swapchain
232
233@[typedef]
234pub struct C.sapp_desc {
235pub 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
276pub type Desc = C.sapp_desc
277
278@[typedef]
279pub struct C.sapp_event {
280pub 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
302pub type Event = C.sapp_event
303
304pub fn (e &Event) str() string {
305 return 'evt: frame_count=${e.frame_count}, type=${EventType(e.type)}'
306}
307
308@[typedef]
309pub struct C.sapp_touchpoint {
310pub:
311 identifier u64
312 pos_x f32
313 pos_y f32
314 android_tooltype TouchToolType
315 changed bool
316}
317
318pub type TouchPoint = C.sapp_touchpoint
319