Skip to main content

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