rustyray_sys/
ffi.rs

1/**********************************************************************************************
2*
3*   raylib v5.5 - A simple and easy-to-use library to enjoy videogames programming (www.raylib.com)
4*
5*   FEATURES:
6*       - NO external dependencies, all required libraries included with raylib
7*       - Multiplatform: Windows, Linux, FreeBSD, OpenBSD, NetBSD, DragonFly,
8*                        MacOS, Haiku, Android, Raspberry Pi, DRM native, HTML5.
9*       - Written in plain C code (C99) in PascalCase/camelCase notation
10*       - Hardware accelerated with OpenGL (1.1, 2.1, 3.3, 4.3, ES2, ES3 - choose at compile)
11*       - Unique OpenGL abstraction layer (usable as standalone module): [rlgl]
12*       - Multiple Fonts formats supported (TTF, OTF, FNT, BDF, Sprite fonts)
13*       - Outstanding texture formats support, including compressed formats (DXT, ETC, ASTC)
14*       - Full 3d support for 3d Shapes, Models, Billboards, Heightmaps and more!
15*       - Flexible Materials system, supporting classic maps and PBR maps
16*       - Animated 3D models supported (skeletal bones animation) (IQM, M3D, GLTF)
17*       - Shaders support, including Model shaders and Postprocessing shaders
18*       - Powerful math module for Vector, Matrix and Quaternion operations: [raymath]
19*       - Audio loading and playing with streaming support (WAV, OGG, MP3, FLAC, QOA, XM, MOD)
20*       - VR stereo rendering with configurable HMD device parameters
21*       - Bindings to multiple programming languages available!
22*
23*   NOTES:
24*       - One default Font is loaded on InitWindow()->LoadFontDefault() [core, text]
25*       - One default Texture2D is loaded on rlglInit(), 1x1 white pixel R8G8B8A8 [rlgl] (OpenGL 3.3 or ES2)
26*       - One default Shader is loaded on rlglInit()->rlLoadShaderDefault() [rlgl] (OpenGL 3.3 or ES2)
27*       - One default RenderBatch is loaded on rlglInit()->rlLoadRenderBatch() [rlgl] (OpenGL 3.3 or ES2)
28*
29*   DEPENDENCIES (included):
30*       [rcore][GLFW] rglfw (Camilla Löwy - github.com/glfw/glfw) for window/context management and input
31*       [rcore][RGFW] rgfw (ColleagueRiley - github.com/ColleagueRiley/RGFW) for window/context management and input
32*       [rlgl] glad/glad_gles2 (David Herberth - github.com/Dav1dde/glad) for OpenGL 3.3 extensions loading
33*       [raudio] miniaudio (David Reid - github.com/mackron/miniaudio) for audio device/context management
34*
35*   OPTIONAL DEPENDENCIES (included):
36*       [rcore] msf_gif (Miles Fogle) for GIF recording
37*       [rcore] sinfl (Micha Mettke) for DEFLATE decompression algorithm
38*       [rcore] sdefl (Micha Mettke) for DEFLATE compression algorithm
39*       [rcore] rprand (Ramon Snatamaria) for pseudo-random numbers generation
40*       [rtextures] qoi (Dominic Szablewski - https://phoboslab.org) for QOI image manage
41*       [rtextures] stb_image (Sean Barret) for images loading (BMP, TGA, PNG, JPEG, HDR...)
42*       [rtextures] stb_image_write (Sean Barret) for image writing (BMP, TGA, PNG, JPG)
43*       [rtextures] stb_image_resize2 (Sean Barret) for image resizing algorithms
44*       [rtextures] stb_perlin (Sean Barret) for Perlin Noise image generation
45*       [rtext] stb_truetype (Sean Barret) for ttf fonts loading
46*       [rtext] stb_rect_pack (Sean Barret) for rectangles packing
47*       [rmodels] par_shapes (Philip Rideout) for parametric 3d shapes generation
48*       [rmodels] tinyobj_loader_c (Syoyo Fujita) for models loading (OBJ, MTL)
49*       [rmodels] cgltf (Johannes Kuhlmann) for models loading (glTF)
50*       [rmodels] m3d (bzt) for models loading (M3D, https://bztsrc.gitlab.io/model3d)
51*       [rmodels] vox_loader (Johann Nadalutti) for models loading (VOX)
52*       [raudio] dr_wav (David Reid) for WAV audio file loading
53*       [raudio] dr_flac (David Reid) for FLAC audio file loading
54*       [raudio] dr_mp3 (David Reid) for MP3 audio file loading
55*       [raudio] stb_vorbis (Sean Barret) for OGG audio loading
56*       [raudio] jar_xm (Joshua Reisenauer) for XM audio module loading
57*       [raudio] jar_mod (Joshua Reisenauer) for MOD audio module loading
58*       [raudio] qoa (Dominic Szablewski - https://phoboslab.org) for QOA audio manage
59*
60*
61*   LICENSE: zlib/libpng
62*
63*   raylib is licensed under an unmodified zlib/libpng license, which is an OSI-certified,
64*   BSD-like license that allows static linking with closed source software:
65*
66*   Copyright (c) 2013-2024 Ramon Santamaria (@raysan5)
67*
68*   This software is provided "as-is", without any express or implied warranty. In no event
69*   will the authors be held liable for any damages arising from the use of this software.
70*
71*   Permission is granted to anyone to use this software for any purpose, including commercial
72*   applications, and to alter it and redistribute it freely, subject to the following restrictions:
73*
74*     1. The origin of this software must not be misrepresented; you must not claim that you
75*     wrote the original software. If you use this software in a product, an acknowledgment
76*     in the product documentation would be appreciated but is not required.
77*
78*     2. Altered source versions must be plainly marked as such, and must not be misrepresented
79*     as being the original software.
80*
81*     3. This notice may not be removed or altered from any source distribution.
82*
83**********************************************************************************************/
84
85use libc::{c_char, c_double, c_float, c_int, c_uchar, c_uint, c_void};
86
87use crate::{
88    audio::{AudioCallback, AudioStream, Music, Sound, Wave},
89    camera::Camera2D,
90    color::Color,
91    consts::{
92        ConfigFlag, GamepadAxis, GamepadButton, Gesture, KeyboardKey, MouseButton, MouseCursor,
93        TextureFilter, TextureWrap,
94    },
95    math::{Rectangle, Vector2},
96    texture::{Image, RenderTexture, RenderTexture2D, Texture},
97};
98
99// Window-related functions
100unsafe extern "C" {
101    /// Initialize window and OpenGL context
102    #[link_name = "InitWindow"]
103    pub fn init_window(width: c_int, height: c_int, title: *const c_char);
104    /// Close window and unload OpenGL context
105    #[link_name = "CloseWindow"]
106    pub fn close_window();
107    /// Check if application should close (KEY_ESCAPE pressed or windows close icon clicked)
108    #[link_name = "WindowShouldClose"]
109    pub fn window_should_close() -> bool;
110    /// Check if window has been initialized successfully
111    #[link_name = "IsWindowReady"]
112    pub fn is_window_ready() -> bool;
113    /// Check if window is currently fullscreen
114    #[link_name = "IsWindowFullscreen"]
115    pub fn is_window_fullscreen() -> bool;
116    /// Check if window is currently hidden
117    #[link_name = "IsWindowHidden"]
118    pub fn is_window_hidden() -> bool;
119    /// Check if window is currently minimized
120    #[link_name = "IsWindowMinimized"]
121    pub fn is_window_minimized() -> bool;
122    /// Check if window is currently maximized
123    #[link_name = "IsWindowMaximized"]
124    pub fn is_window_maximized() -> bool;
125    /// Check if window is currently focused
126    #[link_name = "IsWindowFocused"]
127    pub fn is_window_focused() -> bool;
128    /// Check if window has been resized last frame
129    #[link_name = "IsWindowResized"]
130    pub fn is_window_resized() -> bool;
131    /// Check if one specific window flag is enabled
132    ///
133    /// Flags should be of values defined in [ConfigFlag].
134    ///
135    /// Use this value as a bitmask.
136    ///
137    /// # Examples
138    /// ```no_run
139    /// use rustyray_sys::{ffi::is_window_state, consts::ConfigFlag};
140    ///
141    /// unsafe { is_window_state(ConfigFlag::VsyncHint) };
142    /// ```
143    #[link_name = "IsWindowState"]
144    pub fn is_window_state(flags: ConfigFlag) -> bool;
145    /// Set window configuration state using flags
146    ///
147    /// Flags should be of values defined in [ConfigFlag].
148    ///
149    /// Use this value as a bitmask.
150    ///
151    /// # Examples
152    /// ```no_run
153    /// use rustyray_sys::{ffi::set_window_state, consts::ConfigFlag};
154    ///
155    /// unsafe { set_window_state(ConfigFlag::VsyncHint); }
156    /// ```
157    #[link_name = "SetWindowState"]
158    pub fn set_window_state(flags: ConfigFlag);
159    /// Clear window configuration state flags
160    ///
161    /// Flags should be of values defined in [ConfigFlag].
162    ///
163    /// Use this value as a bitmask.
164    ///
165    /// # Examples
166    /// ```no_run
167    /// use rustyray_sys::{ffi::clear_window_state, consts::ConfigFlag};
168    ///
169    /// unsafe { clear_window_state(ConfigFlag::VsyncHint); }
170    /// ```
171    #[link_name = "ClearWindowState"]
172    pub fn clear_window_state(flags: ConfigFlag);
173    /// Toggle window state: fullscreen/windowed, resizes monitor to match window resolution
174    #[link_name = "ToggleFullscreen"]
175    pub fn toggle_fullscreen();
176    /// Toggle window state: borderless windowed, resizes window to match monitor resolution
177    #[link_name = "ToggleBorderlessWindowed"]
178    pub fn toggle_borderless_windowed();
179    /// Set window state: maximized, if resizable
180    #[link_name = "MaximizeWindow"]
181    pub fn maximize_window();
182    /// Set window state: minimized, if resizable
183    #[link_name = "MinimizeWindow"]
184    pub fn minimize_window();
185    /// Set window state: not minimized/maximized
186    #[link_name = "RestoreWindow"]
187    pub fn restore_window();
188    /// Set icon for window (single image, RGBA 32bit)
189    #[link_name = "SetWindowIcon"]
190    pub fn set_window_icon(image: Image);
191    /// Set icon for window (multiple images, RGBA 32bit)
192    #[link_name = "SetWindowIcons"]
193    pub fn set_window_icons(images: *const Image);
194    /// Set title for window
195    #[link_name = "SetWindowTitle"]
196    pub fn set_window_title(title: *const c_char);
197    /// Set window position on screen
198    #[link_name = "SetWindowPosition"]
199    pub fn set_window_position(x: c_int, y: c_int);
200    /// Set monitor for the current window
201    #[link_name = "SetWindowMonitor"]
202    pub fn set_window_monitor(monitor: c_int);
203    /// Set window minimum dimensions (for [ConfigFlag::WindowResizable])
204    #[link_name = "SetWindowMinSize"]
205    pub fn set_window_min_size(width: c_int, height: c_int);
206    /// Set window maximum dimensions (for [ConfigFlag::WindowResizable])
207    #[link_name = "SetWindowMaxSize"]
208    pub fn set_window_max_size(width: c_int, height: c_int);
209    /// Set window dimension
210    #[link_name = "SetWindowSize"]
211    pub fn set_window_size(width: c_int, height: c_int);
212    /// Set window opacity [0.0..1.0]
213    #[link_name = "SetWindowOpacity"]
214    pub fn set_window_opacity(opacity: c_float);
215    /// Set window focused
216    #[link_name = "SetWindowFocused"]
217    pub fn set_window_focused();
218    /// Get current screen width
219    #[link_name = "GetScreenWidth"]
220    pub fn get_screen_width() -> c_int;
221    /// Get current screen height
222    #[link_name = "GetScreenHeight"]
223    pub fn get_screen_height() -> c_int;
224    /// Get current render width (it considers HiDPI)
225    #[link_name = "GetRenderWidth"]
226    pub fn get_render_width() -> c_int;
227    /// Get current render height (it considers HiDPI)
228    #[link_name = "GetRenderHeight"]
229    pub fn get_render_height() -> c_int;
230    /// Get number of connected monitors
231    #[link_name = "GetMonitorCount"]
232    pub fn get_monitor_count() -> c_int;
233    /// Get current monitor where window is placed
234    #[link_name = "GetCurrentMonitor"]
235    pub fn get_current_monitor() -> c_int;
236    /// Get specified monitor position
237    #[link_name = "GetMonitorPosition"]
238    pub fn get_monitor_position(monitor: c_int) -> Vector2;
239    /// Get specified monitor width (current video mode used by monitor)
240    #[link_name = "GetMonitorWidth"]
241    pub fn get_monitor_width(monitor: c_int) -> c_int;
242    /// Get specified monitor height (current video mode used by monitor)
243    #[link_name = "GetMonitorHeight"]
244    pub fn get_monitor_height(monitor: c_int) -> c_int;
245    /// Get specified monitor physical width in millimetres
246    #[link_name = "GetMonitorPhysicalWidth"]
247    pub fn get_monitor_physical_width(monitor: c_int) -> c_int;
248    /// Get specified monitor physical height in millimetres
249    #[link_name = "GetMonitorPhysicalHeight"]
250    pub fn get_monitor_physical_height(monitor: c_int) -> c_int;
251    /// Get specified monitor refresh rate
252    #[link_name = "GetMonitorRefreshRate"]
253    pub fn get_monitor_refresh_rate(monitor: c_int) -> c_int;
254    /// Get position XY on monitor
255    #[link_name = "GetWindowPosition"]
256    pub fn get_window_position() -> Vector2;
257    /// Get window scale DPI factor
258    #[link_name = "GetWindowScaleDPI"]
259    pub fn get_window_scale_dpi() -> Vector2;
260    /// Get the human-readable, UTF-8 encoded name of the specified monitor
261    #[link_name = "GetMonitorName"]
262    pub fn get_monitor_name(monitor: c_int) -> *const c_char;
263    /// Set clipboard text content
264    #[link_name = "SetClipboardText"]
265    pub fn set_clipboard_text(text: *const c_char);
266    /// Get clipboard text content
267    #[link_name = "GetClipboardText"]
268    pub fn get_clipboard_text() -> *const c_char;
269    /// Get clipboard image content
270    #[link_name = "GetClipboardImage"]
271    pub fn get_clipboard_image() -> Image;
272    /// Enable waiting for events on [end_drawing], no automatic event polling
273    #[link_name = "EnableEventWaiting"]
274    pub fn enable_event_waiting();
275    /// Disable waiting for events on [end_drawing], automatic event polling
276    #[link_name = "DisableEventWaiting"]
277    pub fn disable_event_waiting();
278}
279
280// Cursor-related functions
281unsafe extern "C" {
282    /// Shows cursor
283    #[link_name = "ShowCursor"]
284    pub fn show_cursor();
285    /// Hides cursor
286    #[link_name = "HideCursor"]
287    pub fn hide_cursor();
288    /// Check if cursor is not visible
289    #[link_name = "IsCursorHidden"]
290    pub fn is_cursor_hidden() -> bool;
291    /// Enables cursor (unlock cursor)
292    #[link_name = "EnableCursor"]
293    pub fn enable_cursor();
294    /// Disabled cursor (lock cursor)
295    #[link_name = "DisableCursor"]
296    pub fn disable_cursor();
297    /// Check if cursor is on the screen
298    #[link_name = "IsCursorOnScreen"]
299    pub fn is_cursor_on_screen() -> bool;
300}
301
302// Drawing related functions
303unsafe extern "C" {
304    /// Set background color (framebuffer clear color)
305    #[link_name = "ClearBackground"]
306    pub fn clear_background(color: Color);
307    /// Setup canvas (framebuffer) to start drawing
308    #[link_name = "BeginDrawing"]
309    pub fn begin_drawing();
310    /// End canvas drawing and swap buffers (double buffering)
311    #[link_name = "EndDrawing"]
312    pub fn end_drawing();
313    /// Begin 2D mode with custom camera (2D)
314    #[link_name = "BeginMode2D"]
315    pub fn begin_mode_2d(camera: Camera2D);
316    /// Ends 2D mode with custom camera
317    #[link_name = "EndMode2D"]
318    pub fn end_mode_2d();
319    /// Begin drawing to render texture
320    #[link_name = "BeginTextureMode"]
321    pub fn begin_texture_mode(render_texture: RenderTexture2D);
322    /// Ends drawing to render texture
323    #[link_name = "EndTextureMode"]
324    pub fn end_texture_mode();
325}
326
327// Image loading functions
328unsafe extern "C" {
329    /// Load image from memory buffer, fileType refers to extension: i.e. '.png'
330    #[link_name = "LoadImageFromMemory"]
331    pub fn load_image_from_memory(
332        file_type: *const c_char,
333        file_data: *const c_uchar,
334        data_size: c_int,
335    ) -> Image;
336}
337
338// Texture loading functions
339// Note: These function require GPU access
340unsafe extern "C" {
341    /// Load texture from file into GPU memory (VRAM)
342    #[link_name = "LoadTexture"]
343    pub fn load_texture(path: *const c_char) -> Texture;
344    /// Load texture from image data
345    #[link_name = "LoadTextureFromImage"]
346    pub fn load_texture_from_image(image: Image) -> Texture;
347    /// Load texture for rendering (framebuffer)
348    #[link_name = "LoadRenderTexture"]
349    pub fn load_render_texture(width: c_int, height: c_int) -> RenderTexture;
350    /// Check if a texture is valid (loaded in GPU)
351    #[link_name = "IsTextureValid"]
352    pub fn is_texture_valid(texture: Texture) -> bool;
353    /// Unload texture from GPU memory (VRAM)
354    #[link_name = "UnloadTexture"]
355    pub fn unload_texture(texture: Texture);
356    /// Check if a render texture is valid (loaded in GPU)
357    #[link_name = "IsRenderTextureValid"]
358    pub fn is_render_texture_valid(target: RenderTexture) -> bool;
359    /// Unload render texture from GPU memory (VRAM)
360    #[link_name = "UnloadRenderTexture"]
361    pub fn unload_render_texture(render_texture: RenderTexture);
362    /// Update GPU texture with new data
363    #[link_name = "UpdateTexture"]
364    pub fn update_texture(texture: Texture, pixels: *const c_void);
365    /// Update GPU texture rectangle with new data
366    #[link_name = "UpdateTextureRec"]
367    pub fn update_texture_rec(texture: Texture, rec: Rectangle, pixels: *const c_void);
368}
369
370// Texture configuration function
371unsafe extern "C" {
372    /// Generate GPU mipmaps for a texture
373    #[link_name = "GenTextureMipmaps"]
374    pub fn gen_texture_mipmaps(texture: *mut Texture);
375    /// Set texture scaling filter mode
376    #[link_name = "SetTextureFilter"]
377    pub fn set_texture_filter(texture: Texture, filter: TextureFilter);
378    /// Set texture wrapping mode
379    #[link_name = "SetTextureWrap"]
380    pub fn set_texture_wrap(texture: Texture, wrap: TextureWrap);
381}
382
383// Texture drawing functions
384unsafe extern "C" {
385    /// Draw a [Texture]
386    #[link_name = "DrawTexture"]
387    pub fn draw_texture(texture: Texture, pos_x: c_int, pos_y: c_int, tint: Color);
388    /// Draw a [Texture] with position defined as [Vector2]
389    #[link_name = "DrawTextureV"]
390    pub fn draw_texture_v(texture: Texture, pos: Vector2, tint: Color);
391    /// Draw a [Texture] with extended parameters
392    #[link_name = "DrawTextureEx"]
393    pub fn draw_texture_ex(
394        texture: Texture,
395        pos: Vector2,
396        rotation: c_float,
397        scale: c_float,
398        tint: Color,
399    );
400    /// Draw a part of a [Texture] defined by a [Rectangle]
401    #[link_name = "DrawTextureRec"]
402    pub fn draw_texture_rec(texture: Texture, source: Rectangle, position: Vector2, tint: Color);
403    /// Draw a part of a [Texture] defined by a [Rectangle] with 'pro' parameters
404    #[link_name = "DrawTexturePro"]
405    pub fn draw_texture_pro(
406        texture: Texture,
407        source: Rectangle,
408        dest: Rectangle,
409        origin: Vector2,
410        rotation: c_float,
411        tint: Color,
412    );
413    // TODO: Add draw_texture_npatch when NPatchInfo is implemented
414}
415
416// Text drawing functions
417unsafe extern "C" {
418    /// Draw current FPS
419    #[link_name = "DrawFPS"]
420    pub fn draw_fps(pos_x: c_int, pos_y: c_int);
421    /// Draw text (using default font)
422    #[link_name = "DrawText"]
423    pub fn draw_text(
424        text: *const c_char,
425        pos_x: c_int,
426        pos_y: c_int,
427        font_size: c_int,
428        color: Color,
429    );
430}
431
432// Text font info functions
433unsafe extern "C" {
434    /// Measure string width for default font
435    #[link_name = "MeasureText"]
436    pub fn measure_text(text: *const c_char, font_size: c_int);
437}
438
439// Basic shapes drawing functions
440unsafe extern "C" {
441    /// Draw a line
442    #[link_name = "DrawLine"]
443    pub fn draw_line(start_x: c_int, start_y: c_int, end_x: c_int, end_y: c_int, color: Color);
444    /// Draw a line (using gl lines)
445    #[link_name = "DrawLineV"]
446    pub fn draw_line_v(start: Vector2, end: Vector2, color: Color);
447    /// Draw a line (using triangles/quads)
448    #[link_name = "DrawLineEx"]
449    pub fn draw_line_ex(start: Vector2, end: Vector2, thick: c_float, color: Color);
450    /// Draw lines sequence (using gl lines)
451    #[link_name = "DrawLineStrip"]
452    pub fn draw_line_strip(points: *const Vector2, num_points: c_int, color: Color);
453    /// Draw line segment cubic-bezier in-out interpolation
454    #[link_name = "DrawLineBezier"]
455    pub fn draw_line_bezier(start: Vector2, end: Vector2, thick: c_float, color: Color);
456    /// Draw a color-filled circle
457    #[link_name = "DrawCircle"]
458    pub fn draw_circle(center_x: c_int, center_y: c_int, radius: c_float, color: Color);
459    /// Draw a color-filled circle (Vector version)
460    #[link_name = "DrawCircleV"]
461    pub fn draw_circle_v(center: Vector2, radius: c_float, color: Color);
462    /// Draw circle outline
463    #[link_name = "DrawCircleLines"]
464    pub fn draw_circle_lines(center_x: c_int, center_y: c_int, radius: c_float, color: Color);
465    /// Draw a color-filled circle (Vector version)
466    #[link_name = "DrawEllipse"]
467    pub fn draw_ellipse(
468        center_x: c_int,
469        center_y: c_int,
470        radius_x: c_float,
471        radius_y: c_float,
472        color: Color,
473    );
474    /// Draw a color-filled rectangle
475    #[link_name = "DrawRectangleRec"]
476    pub fn draw_rectangle_rec(rec: Rectangle, color: Color);
477    /// Draw a color-filled rectangle with pro parameters
478    #[link_name = "DrawRectanglePro"]
479    pub fn draw_rectangle_pro(rec: Rectangle, origin: Vector2, rotation: f32, color: Color);
480    /// Draw rectangle outline
481    #[link_name = "DrawRectangleLines"]
482    pub fn draw_rectangle_lines(
483        pos_x: c_int,
484        pos_y: c_int,
485        width: c_int,
486        height: c_int,
487        color: Color,
488    );
489    #[link_name = "DrawRectangleLinesEx"]
490    pub fn draw_rectangle_lines_ex(rect: Rectangle, line_thickness: c_float, color: Color);
491    #[link_name = "DrawTriangle"]
492    pub fn draw_triangle(v1: Vector2, v2: Vector2, v3: Vector2, color: Color);
493    #[link_name = "DrawTriangleLines"]
494    pub fn draw_triangle_lines(v1: Vector2, v2: Vector2, v3: Vector2, color: Color);
495}
496
497// Input-related functions: keyboard
498unsafe extern "C" {
499    /// Check if a key has been pressed once
500    #[link_name = "IsKeyPressed"]
501    pub fn is_key_pressed(key: KeyboardKey) -> bool;
502    /// Check if a key has been pressed again
503    #[link_name = "IsKeyPressedRepeat"]
504    pub fn is_key_pressed_repeat(key: KeyboardKey) -> bool;
505    /// Check if a key is being pressed
506    #[link_name = "IsKeyDown"]
507    pub fn is_key_down(key: KeyboardKey) -> bool;
508    /// Check if a key has been released once
509    #[link_name = "IsKeyReleased"]
510    pub fn is_key_released(key: KeyboardKey) -> bool;
511    /// Check if a key is **NOT** being pressed
512    #[link_name = "IsKeyUp"]
513    pub fn is_key_up(key: KeyboardKey) -> bool;
514    /// Get key pressed (keycode), call it multiple times for keys queued, returns 0 when the queue is empty
515    #[link_name = "GetKeyPressed"]
516    pub fn get_key_pressed() -> c_int;
517    /// Get char pressed (unicode), call it multiple times for chars queued, return s0 when the queue is empty
518    #[link_name = "GetCharPressed"]
519    pub fn get_char_pressed() -> c_int;
520    /// Set a custom key to exit program (default is [KeyboardKey::Escape])
521    #[link_name = "SetExitKey"]
522    pub fn set_exit_key(key: KeyboardKey);
523}
524
525// Input-related functions: gamepads
526unsafe extern "C" {
527    /// Check if a gamepad is available
528    #[link_name = "IsGamepadAvailable"]
529    pub fn is_gamepad_available(gamepad: c_int) -> bool;
530    /// Get gamepad internal name id
531    #[link_name = "GetGamepadName"]
532    pub fn get_gamepad_name(gamepad: c_int) -> *const c_char;
533    /// Check if a gamepad button has been pressed once
534    #[link_name = "IsGamepadButtonPressed"]
535    pub fn is_gamepad_button_pressed(gamepad: c_int, button: GamepadButton) -> bool;
536    /// Check if a gamepad button is being pressed
537    #[link_name = "IsGamepadButtonDown"]
538    pub fn is_gamepad_button_down(gamepad: c_int, button: GamepadButton) -> bool;
539    /// Check if a gamepad button has been released once
540    #[link_name = "IsGamepadButtonReleased"]
541    pub fn is_gamepad_button_released(gamepad: c_int, button: GamepadButton) -> bool;
542    /// Check if a gamepad button is **NOT** being pressed
543    #[link_name = "IsGamepadButtonUp"]
544    pub fn is_gamepad_button_up(gamepad: c_int, button: GamepadButton) -> bool;
545    /// Get the last gamepad button pressed
546    #[link_name = "GetGamepadButtonPressed"]
547    pub fn get_gamepad_button_pressed(gamepad: c_int) -> GamepadButton;
548    /// Get gamepad axis count for a gamepad
549    #[link_name = "GetGamepadAxisCount"]
550    pub fn get_gamepad_axis_count(gamepad: c_int) -> c_int;
551    /// Get axis movement value for a gamepad axis
552    #[link_name = "GetGamepadAxisMovement"]
553    pub fn get_gamepad_axis_movement(gamepad: c_int, axis: GamepadAxis) -> c_float;
554    /// Set gamepad vibration for both motors (duration in seconds)
555    #[link_name = "SetGamepadVibration"]
556    pub fn set_gamepad_vibration(
557        gamepad: c_int,
558        left_motor: c_float,
559        right_motor: c_float,
560        duration: c_float,
561    );
562}
563
564// Input-related functions: mouse
565unsafe extern "C" {
566    /// Check if a [MouseButton] has been pressed once
567    #[link_name = "IsMouseButtonPressed"]
568    pub fn is_mouse_button_pressed(button: MouseButton) -> bool;
569    /// Check if a [MouseButton] is beening pressed
570    #[link_name = "IsMouseButtonDown"]
571    pub fn is_mouse_button_down(button: MouseButton) -> bool;
572    /// Check if a [MouseButton] has been released once
573    #[link_name = "IsMouseButtonReleased"]
574    pub fn is_mouse_button_released(button: MouseButton) -> bool;
575    /// Check if a [MouseButton] is **NOT** being pressed
576    #[link_name = "IsMouseButtonUp"]
577    pub fn is_mouse_button_up(button: MouseButton) -> bool;
578    /// Get mouse position X
579    #[link_name = "GetMouseX"]
580    pub fn get_mouse_x() -> c_int;
581    /// Get mouse position Y
582    #[link_name = "GetMouseY"]
583    pub fn get_mouse_y() -> c_int;
584    /// Get mouse position XY
585    #[link_name = "GetMousePosition"]
586    pub fn get_mouse_position() -> Vector2;
587    /// Get mouse delta between frames
588    #[link_name = "GetMouseDelta"]
589    pub fn get_mouse_delta() -> Vector2;
590    /// Set mouse position XY
591    #[link_name = "SetMousePosition"]
592    pub fn set_mouse_position(x: c_int, y: c_int);
593    /// Set mouse offset
594    #[link_name = "SetMouseOffset"]
595    pub fn set_mouse_offset(offset_x: c_int, offset_y: c_int);
596    /// Set mouse scaling
597    #[link_name = "SetMouseScale"]
598    pub fn set_mouse_scale(scale_x: c_int, scale_y: c_int);
599    /// Get mouse wheel movement for X or Y, whichever is larger
600    #[link_name = "GetMouseWheelMove"]
601    pub fn get_mouse_wheel_move() -> c_float;
602    /// Get mouse wheel movement for both X or Y
603    #[link_name = "GetMouseWheelMoveV"]
604    pub fn get_mouse_wheel_move_v() -> Vector2;
605    /// Set mouse cursor
606    #[link_name = "SetMouseCursor"]
607    pub fn set_mouse_cursor(cursor: MouseCursor);
608}
609
610// Input-related functions: touch
611unsafe extern "C" {
612    /// Get touch position X for touch point 0 (relative to screen size)
613    #[link_name = "GetTouchX"]
614    pub fn get_touch_x() -> c_int;
615    /// Get touch position Y for touch point 0 (relative to screen size)
616    #[link_name = "GetTouchY"]
617    pub fn get_touch_y() -> c_int;
618    /// Get touch position XY for a touch point index (relative to screen size)
619    #[link_name = "GetTouchPosition"]
620    pub fn get_touch_position(index: c_int) -> Vector2;
621    /// Get touch point identifier for given index
622    #[link_name = "GetTouchPointId"]
623    pub fn get_touch_point_id(index: c_int) -> c_int;
624    /// Get number of touch points
625    #[link_name = "GetTouchPointCount"]
626    pub fn get_touch_point_count() -> c_int;
627}
628// Gestures and Touch handling functions
629unsafe extern "C" {
630    /// Enable a set of [Gesture] using flags
631    #[link_name = "SetGesturesEnabled"]
632    pub fn set_gestures_enabled(flags: Gesture);
633    /// Check if a [Gesture] have been detected
634    #[link_name = "IsGestureDetected"]
635    pub fn is_gesture_detected(gesture: Gesture);
636    /// Get latest detected [Gesture]
637    #[link_name = "GetGestureDetected"]
638    pub fn get_gesture_detected() -> Gesture;
639    /// Get [Gesture] hold time in seconds
640    #[link_name = "GetGestureHoldDuration"]
641    pub fn get_gesture_hold_duration() -> c_int;
642    /// Get [Gesture] drag [Vector2]
643    #[link_name = "GetGestureDragVector"]
644    pub fn get_gesture_drag_vector() -> Vector2;
645    /// Get [Gesture] drag angle
646    #[link_name = "GetGestureDragAngle"]
647    pub fn get_gesture_drag_angle() -> c_float;
648    /// Get [Gesture] pinch delta
649    #[link_name = "GetGesturePinchVector"]
650    pub fn get_gesture_pinch_vector() -> Vector2;
651    /// Get [Gesture] pinch angle
652    #[link_name = "GetGesturePinchAngle"]
653    pub fn get_gesture_pinch_angle() -> c_float;
654}
655
656// Timing-related functions
657unsafe extern "C" {
658    /// Set target FPS (maximum)
659    #[link_name = "SetTargetFPS"]
660    pub fn set_target_fps(fps: c_int);
661    /// Get time in seconds for last frame drawn (delta time)
662    #[link_name = "GetFrameTime"]
663    pub fn get_frame_time() -> c_float;
664    /// Get elapsed time in seconds since InitWindow()
665    #[link_name = "GetTime"]
666    pub fn get_time() -> c_double;
667    /// Get current FPS
668    #[link_name = "GetFPS"]
669    pub fn get_fps() -> c_int;
670}
671
672// Misc functions
673unsafe extern "C" {
674    /// Takes a screenshot of current screen (filename extension defines format)
675    #[link_name = "TakeScreenshot"]
676    pub fn take_screenshot(file_name: *const c_char);
677    /// Setup init configuration flags (view FLAGS)
678    ///
679    /// Flags should be of values defined in [ConfigFlag].
680    ///
681    /// Use this value as a bitmask.
682    ///
683    /// # Examples
684    /// ```no_run
685    /// use rustyray_sys::{ffi::set_config_flags, consts::ConfigFlag};
686    ///
687    /// unsafe { set_config_flags(ConfigFlag::VsyncHint) }
688    /// ```
689    #[link_name = "SetConfigFlags"]
690    pub fn set_config_flags(flags: ConfigFlag);
691    /// Open URL with default system browser (if available)
692    #[link_name = "OpenURL"]
693    pub fn open_url(url: *const c_char);
694}
695
696// Audio device management functions
697unsafe extern "C" {
698    /// Initialize audio device and context
699    #[link_name = "InitAudioDevice"]
700    pub fn init_audio_device();
701    /// Close the audio device and context
702    #[link_name = "CloseAudioDevice"]
703    pub fn close_audio_device();
704    /// Check if audio device has been initialized successfully
705    #[link_name = "IsAudioDeviceReady"]
706    pub fn is_audio_device_ready() -> bool;
707    /// Set master volume (listener)
708    #[link_name = "SetMasterVolume"]
709    pub fn set_master_volume(volume: c_float);
710    /// Get master volume (listener)
711    #[link_name = "GetMasterVolume"]
712    pub fn get_master_volume() -> c_float;
713}
714
715// Wave/Sound loading/unloading functions
716unsafe extern "C" {
717    /// Load wave data from file
718    #[link_name = "LoadWave"]
719    pub fn load_wave(file_name: *const c_char) -> Wave;
720    /// Load wave from memory buffer, file_type refers to extension: i.e. `.wav`
721    #[link_name = "LoadWaveFromMemory"]
722    pub fn load_wave_from_memory(
723        file_type: *const c_char,
724        file_data: *const c_uchar,
725        data_size: c_int,
726    ) -> Wave;
727    /// Checks if wave data is valid (data loaded and parameters)
728    #[link_name = "IsWaveValid"]
729    pub fn is_wave_valid(wave: Wave) -> bool;
730    /// Load sound from file
731    #[link_name = "LoadSound"]
732    pub fn load_sound(file_name: *const c_char) -> Sound;
733    /// Load sound from wave data
734    #[link_name = "LoadSoundFromWave"]
735    pub fn load_sound_from_wave(wave: Wave) -> Sound;
736    /// Create a new sound that shares the same sample data as the source sound, does not own the sound data
737    #[link_name = "LoadSoundAlias"]
738    pub fn load_sound_alias(source: Sound) -> Sound;
739    /// Checks if sound is valid (data loaded and buffers initialized)
740    #[link_name = "IsSoundValid"]
741    pub fn is_sound_valid(sound: Sound) -> bool;
742    /// Update sound buffer with new data
743    #[link_name = "UpdateSound"]
744    pub fn update_sound(sound: Sound, data: *const c_void, sample_count: c_int);
745    /// Unload wave data
746    #[link_name = "UnloadWave"]
747    pub fn unload_wave(wave: Wave);
748    /// Unload sound
749    #[link_name = "UnloadSound"]
750    pub fn unload_sound(sound: Sound);
751    /// Unload a sound alias (does not deallocate sample data)
752    #[link_name = "UnloadSoundAlias"]
753    pub fn unload_sound_alias(alias: Sound);
754    /// Export wave data to file, returns true on success
755    #[link_name = "ExportWave"]
756    pub fn export_wave(wave: Wave, file_name: *const c_char) -> bool;
757    /// Export wave sample data to code (.h), returns true on success
758    #[link_name = "ExportWaveAsCode"]
759    pub fn export_wave_as_code(wave: Wave, file_name: *const c_char) -> bool;
760}
761
762// Wave/Sound management functions
763unsafe extern "C" {
764    /// Play a sound
765    #[link_name = "PlaySound"]
766    pub fn play_sound(sound: Sound);
767    /// Stop playing a sound
768    #[link_name = "StopSound"]
769    pub fn stop_sound(sound: Sound);
770    /// Pause a sound
771    #[link_name = "PauseSound"]
772    pub fn pause_sound(sound: Sound);
773    /// Resume a paused sound
774    #[link_name = "ResumeSound"]
775    pub fn resume_sound(sound: Sound);
776    /// Check if a sound is currently playing
777    #[link_name = "IsSoundPlaying"]
778    pub fn is_sound_playing(sound: Sound) -> bool;
779    /// Set volume for a sound (1.0 is max level)
780    #[link_name = "SetSoundVolume"]
781    pub fn set_sound_volume(sound: Sound, volume: c_float);
782    /// Set pitch for a sound (1.0 is base level)
783    #[link_name = "SetSoundPitch"]
784    pub fn set_sound_pitch(sound: Sound, pitch: c_float);
785    /// Set pan for a sound (0.5 is center)
786    #[link_name = "SetSoundPan"]
787    pub fn set_sound_pan(sound: Sound, pan: c_float);
788    /// Copy the wave to a new wave
789    #[link_name = "WaveCopy"]
790    pub fn wave_copy(wave: Wave);
791    /// Crop a wave to defined frames range
792    #[link_name = "WaveCrop"]
793    pub fn wave_crop(wave: *mut Wave, init_frame: c_int, final_frame: c_int);
794    /// Convert wave data to desired format
795    #[link_name = "WaveFormat"]
796    pub fn wave_format(wave: *mut Wave, sample_rate: c_int, sample_size: c_int, channels: c_int);
797    /// Load samples data from wave as a 32bit float data array
798    #[link_name = "LoadWaveSamples"]
799    pub fn load_wave_samples(wave: Wave) -> *const c_float;
800    /// Unload samples data loaded with LoadWaveSamples()
801    #[link_name = "UnloadWaveSamples"]
802    pub fn unload_wave_samples(samples: *const c_float);
803}
804
805unsafe extern "C" {
806    /// Load music stream from file
807    #[link_name = "LoadMusicStream"]
808    pub fn load_music_stream(file_name: *const c_char) -> Music;
809    /// Load music stream from file
810    #[link_name = "LoadMusicStreamFromMemory"]
811    pub fn load_music_stream_from_memory(
812        file_type: *const c_char,
813        data: *const c_uchar,
814        data_size: c_int,
815    ) -> Music;
816    /// Checks if a music stream is valid (context and buffers initialized)
817    #[link_name = "IsMusicValid"]
818    pub fn is_music_valid(music: Music) -> bool;
819    /// Unload music stream
820    #[link_name = "UnloadMusicStream"]
821    pub fn unload_music_stream(music: Music);
822    /// Start music playing
823    #[link_name = "PlayMusicStream"]
824    pub fn play_music_stream(music: Music);
825    /// Checks if music is playing
826    #[link_name = "IsMusicStreamPlaying"]
827    pub fn is_music_stream_playing(music: Music) -> bool;
828    /// Updates buffers for music streaming
829    #[link_name = "UpdateMusicStream"]
830    pub fn update_music_stream(music: Music);
831    /// Stop music playing
832    #[link_name = "StopMusicStream"]
833    pub fn stop_music_stream(music: Music);
834    /// Pause music playing
835    #[link_name = "PauseMusicStream"]
836    pub fn pause_music_stream(music: Music);
837    /// Resume playing paused music
838    #[link_name = "ResumeMusicStream"]
839    pub fn resume_music_stream(music: Music);
840    /// Seek music to a position (in seconds)
841    #[link_name = "SeekMusicStream"]
842    pub fn seek_music_stream(music: Music, position: c_float);
843    /// Set volume for music (1.0 is max level)
844    #[link_name = "SetMusicVolume"]
845    pub fn set_music_volume(music: Music, volume: c_float);
846    /// Set pitch for music (1.0 is base level)
847    #[link_name = "SetMusicPitch"]
848    pub fn set_music_pitch(music: Music, pitch: c_float);
849    /// Set pan for music (0.5 is center)
850    #[link_name = "SetMusicPan"]
851    pub fn set_music_pan(music: Music, pan: c_float);
852    /// Get music time length (in seconds)
853    #[link_name = "GetMusicTimeLength"]
854    pub fn get_music_time_length(music: Music) -> c_float;
855    /// Get current music time played (in seconds)
856    #[link_name = "GetMusicTimePlayed"]
857    pub fn get_music_time_played(music: Music) -> c_float;
858}
859
860// AudioStream management functions
861unsafe extern "C" {
862    /// Load audio stream (to stream raw audio pcm data)
863    #[link_name = "LoadAudioStream"]
864    pub fn load_audio_stream(
865        sample_rate: c_uint,
866        sample_size: c_uint,
867        channels: c_uint,
868    ) -> AudioStream;
869    /// Checks if an audio stream is valid (buffers initialized)
870    #[link_name = "IsAudioStreamValid"]
871    pub fn is_audio_stream_valid(stream: AudioStream) -> bool;
872    /// Unload audio stream and free memory
873    #[link_name = "UnloadStreamValid"]
874    pub fn unload_stream_valid(stream: AudioStream);
875    /// Update audio stream buffers with data
876    #[link_name = "UpdateStreamValid"]
877    pub fn update_stream_valid(stream: AudioStream, data: *const c_void, frame_count: c_int);
878    /// Check if any audio stream buffers requires refill
879    #[link_name = "IsAudioStreamProcessed"]
880    pub fn is_audio_stream_processed(stream: AudioStream) -> bool;
881    /// Play audio stream
882    #[link_name = "PlayAudioStream"]
883    pub fn play_audio_stream(stream: AudioStream);
884    /// Pause audio stream
885    #[link_name = "PauseAudioStream"]
886    pub fn pause_audio_stream(stream: AudioStream);
887    /// Resume audio stream
888    #[link_name = "ResumeAudioStream"]
889    pub fn resume_audio_stream(stream: AudioStream);
890    /// Check if audio stream is playing
891    #[link_name = "IsAudioStreamPlaying"]
892    pub fn is_audio_stream_playing(stream: AudioStream) -> bool;
893    /// Stop audio stream
894    #[link_name = "StopAudioStream"]
895    pub fn stop_audio_stream(stream: AudioStream);
896    /// Set volume for audio stream (1.0 is max level)
897    #[link_name = "SetAudioStreamVolume"]
898    pub fn set_audio_stream_volume(stream: AudioStream, volume: c_float);
899    /// Set pitch for audio stream (1.0 is base level)
900    #[link_name = "SetAudioStreamPitch"]
901    pub fn set_audio_stream_pitch(stream: AudioStream, pitch: c_float);
902    /// Set pan for audio stream (0.5 is centered)
903    #[link_name = "SetAudioStreamPan"]
904    pub fn set_audio_stream_pan(stream: AudioStream, pan: c_float);
905    /// Default size for new audio streams
906    #[link_name = "SetAudioStreamBufferSizeDefault"]
907    pub fn set_audio_stream_buffer_size_default(size: c_int);
908    /// Audio thread callback to request new data
909    #[link_name = "SetAudioStreamCallback"]
910    pub fn set_audio_stream_callback(stream: AudioStream, callback: AudioCallback);
911
912    /// Attach audio stream processor to stream, receives the samples as 'float'
913    #[link_name = "AttachAudioStreamProcessor"]
914    pub fn attach_audio_stream_processor(stream: AudioStream, processor: AudioCallback);
915    /// Detach audio stream processor from stream
916    #[link_name = "DetachAudioStreamProcessor"]
917    pub fn detach_audio_stream_processor(stream: AudioStream, processor: AudioCallback);
918    /// Attach audio stream processor to the entire audio pipeline, receives the samples as 'float'
919    #[link_name = "AttachAudioMixedProcessor"]
920    pub fn attach_audio_mixed_processor(processor: AudioCallback);
921    /// Detach audio stream processor from the entire audio pipeline
922    #[link_name = "DetachAudioMixedProcessor"]
923    pub fn detach_audio_mixed_processor(processor: AudioCallback);
924}
925
926// Basic shapes collision detection functions
927unsafe extern "C" {
928    /// Check collision between two rectangles
929    #[link_name = "CheckCollisionRecs"]
930    pub fn check_collision_recs(rec1: Rectangle, rec2: Rectangle) -> bool;
931    /// Check collision between two circles
932    #[link_name = "CheckCollisionCircles"]
933    pub fn check_collision_circles(
934        center1: Vector2,
935        radius1: f32,
936        center2: Vector2,
937        radius2: f32,
938    ) -> bool;
939    /// Check collision between circle and rectangle
940    #[link_name = "CheckCollisionCircleRec"]
941    pub fn check_collision_circle_rec(center1: Vector2, radius1: c_float, rec: Rectangle) -> bool;
942    /// Check if circle collides with a line created betweeen two points [p1] and [p2]
943    #[link_name = "CheckCollisionCircleLine"]
944    pub fn check_collision_circle_line(
945        center: Vector2,
946        radius: f32,
947        p1: Vector2,
948        p2: Vector2,
949    ) -> bool;
950    /// Check if point is inside rectangle
951    #[link_name = "CheckCollisionPointRec"]
952    pub fn check_collision_point_rec(point: Vector2, rec: Rectangle) -> bool;
953    /// Check if point is inside circle
954    #[link_name = "CheckCollisionPointCircle"]
955    pub fn check_collision_point_circle(point: Vector2, center: Vector2, radius: c_float) -> bool;
956    /// Check if point is inside triangle
957    #[link_name = "CheckCollisionPointTriangle"]
958    pub fn check_collision_point_triangle(
959        point: Vector2,
960        p1: Vector2,
961        p2: Vector2,
962        p3: Vector2,
963    ) -> bool;
964    /// Check if point belongs to line created between two points [p1] and [p2] with defined margin in pixels [threshold]
965    #[link_name = "CheckCollisionPointLine"]
966    pub fn check_collision_point_line(
967        point: Vector2,
968        p1: Vector2,
969        p2: Vector2,
970        treshold: c_float,
971    ) -> bool;
972    /// Check if point is within a polygon described by array of vertices
973    #[link_name = "CheckCollisionPointPoly"]
974    pub fn check_collision_point_poly(
975        point: Vector2,
976        p1: *const Vector2,
977        point_count: c_int,
978    ) -> bool;
979    /// Get collision rectangle for two rectangles collision
980    #[link_name = "GetCollisionRec"]
981    pub fn get_collision_rec(rec1: Rectangle, rec2: Rectangle) -> Rectangle;
982}
983
984// Logging
985pub type TraceLogCallback = extern "C" fn(log_level: i32, text: *const c_char, args: *mut c_void);
986
987unsafe extern "C" {
988    #[link_name = "SetTraceLogCallback"]
989    pub fn set_trace_log_callback(callback: TraceLogCallback);
990}