1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
use crate::{drawing::DrawHandle, ffi, math::Vector2, texture::Image};

use std::{
    ffi::{CStr, CString},
    time::Duration, sync::atomic::{AtomicBool, Ordering}, marker::PhantomData,
};

pub use ffi::{
    ConfigFlags, GamepadAxis, GamepadButton, Gesture, KeyboardKey, MouseButton, MouseCursor,
};

static INITIALIZED: AtomicBool = AtomicBool::new(false);

/// Main raylib handle
#[derive(Debug)]
pub struct Raylib(PhantomData<*const ()>);

impl Raylib {
    /// Initialize window and OpenGL context
    #[inline]
    pub fn init_window(width: u32, height: u32, title: &str) -> Option<Self> {
        if !INITIALIZED.load(Ordering::Relaxed) {
            let title = CString::new(title).unwrap();

            unsafe {
                ffi::InitWindow(width as _, height as _, title.as_ptr());
            }

            if unsafe { ffi::IsWindowReady() } {
                INITIALIZED.store(true, Ordering::Relaxed);
                
                Some(Self(PhantomData))
            } else {
                None
            }
        } else {
            None
        }
    }

    /// Initialize window and OpenGL context with config flags
    #[inline]
    pub fn init_window_ex(
        width: u32,
        height: u32,
        title: &str,
        flags: ConfigFlags,
    ) -> Option<Self> {
        unsafe {
            ffi::SetConfigFlags(flags.bits());
        }

        Self::init_window(width, height, title)
    }

    /// Check if Escape key or Close icon is pressed
    #[inline]
    pub fn window_should_close(&self) -> bool {
        unsafe { ffi::WindowShouldClose() }
    }

    /// Close window and unload OpenGL context
    #[inline]
    pub fn close_window(self) {
        drop(self)
    }

    /// Check if window is currently fullscreen
    #[inline]
    pub fn is_window_fullscreen(&self) -> bool {
        unsafe { ffi::IsWindowFullscreen() }
    }

    /// Check if window is currently hidden (only PLATFORM_DESKTOP)
    #[inline]
    pub fn is_window_hidden(&self) -> bool {
        unsafe { ffi::IsWindowHidden() }
    }

    /// Check if window is currently minimized (only PLATFORM_DESKTOP)
    #[inline]
    pub fn is_window_minimized(&self) -> bool {
        unsafe { ffi::IsWindowMinimized() }
    }

    /// Check if window is currently maximized (only PLATFORM_DESKTOP)
    #[inline]
    pub fn is_window_maximized(&self) -> bool {
        unsafe { ffi::IsWindowMaximized() }
    }

    /// Check if window is currently focused (only PLATFORM_DESKTOP)
    #[inline]
    pub fn is_window_focused(&self) -> bool {
        unsafe { ffi::IsWindowFocused() }
    }

    /// Check if window has been resized last frame
    #[inline]
    pub fn is_window_resized(&self) -> bool {
        unsafe { ffi::IsWindowResized() }
    }

    /// Check if one specific window flag is enabled
    #[inline]
    pub fn is_window_state(&self, flag: ConfigFlags) -> bool {
        unsafe { ffi::IsWindowState(flag.bits()) }
    }

    /// Set window configuration state using flags (only PLATFORM_DESKTOP)
    #[inline]
    pub fn set_window_state(&mut self, flags: ConfigFlags) {
        unsafe { ffi::SetWindowState(flags.bits()) }
    }

    /// Clear window configuration state flags
    #[inline]
    pub fn clear_window_state(&mut self, flags: ConfigFlags) {
        unsafe { ffi::ClearWindowState(flags.bits()) }
    }

    /// Toggle window state: fullscreen/windowed (only PLATFORM_DESKTOP)
    #[inline]
    pub fn toggle_fullscreen(&mut self) {
        unsafe { ffi::ToggleFullscreen() }
    }

    /// Set window state: maximized, if resizable (only PLATFORM_DESKTOP)
    #[inline]
    pub fn maximize_window(&mut self) {
        unsafe { ffi::MaximizeWindow() }
    }

    /// Set window state: minimized, if resizable (only PLATFORM_DESKTOP)
    #[inline]
    pub fn minimize_window(&mut self) {
        unsafe { ffi::MinimizeWindow() }
    }

    /// Set window state: not minimized/maximized (only PLATFORM_DESKTOP)
    #[inline]
    pub fn restore_window(&mut self) {
        unsafe { ffi::RestoreWindow() }
    }

    /// Set icon for window (single image, RGBA 32bit, only PLATFORM_DESKTOP)
    #[inline]
    pub fn set_window_icon(&mut self, image: &Image) {
        unsafe { ffi::SetWindowIcon(image.raw.clone()) }
    }

    /// Set icon for window (multiple images, RGBA 32bit, only PLATFORM_DESKTOP)
    #[inline]
    pub fn set_window_icons(&mut self, images: &[&Image]) {
        let mut images: Vec<_> = images.iter().map(|img| img.raw.clone()).collect();

        unsafe { ffi::SetWindowIcons(images.as_mut_ptr(), images.len() as _) }
    }

    /// Set title for window (only PLATFORM_DESKTOP)
    #[inline]
    pub fn set_window_title(&mut self, title: &str) {
        let title = CString::new(title).unwrap();

        unsafe { ffi::SetWindowTitle(title.as_ptr()) }
    }

    /// Set window position on screen (only PLATFORM_DESKTOP)
    #[inline]
    pub fn set_window_position(&mut self, x: i32, y: i32) {
        unsafe { ffi::SetWindowPosition(x, y) }
    }

    /// Set monitor for the current window (fullscreen mode)
    #[inline]
    pub fn set_window_monitor(&mut self, monitor: u32) {
        unsafe { ffi::SetWindowMonitor(monitor as _) }
    }

    /// Set window minimum dimensions (for FLAG_WINDOW_RESIZABLE)
    #[inline]
    pub fn set_window_min_size(&mut self, width: u32, height: u32) {
        unsafe { ffi::SetWindowMinSize(width as _, height as _) }
    }

    /// Set window dimensions
    #[inline]
    pub fn set_window_size(&mut self, width: u32, height: u32) {
        unsafe { ffi::SetWindowSize(width as _, height as _) }
    }

    /// Set window opacity [0.0f..1.0f] (only PLATFORM_DESKTOP)
    #[inline]
    pub fn set_window_opacity(&mut self, opacity: f32) {
        unsafe { ffi::SetWindowOpacity(opacity) }
    }

    /// Get native window handle
    #[inline]
    pub fn get_window_handle(&self) -> *mut core::ffi::c_void {
        unsafe { ffi::GetWindowHandle() }
    }

    /// Get current screen width
    #[inline]
    pub fn get_screen_width(&self) -> u32 {
        unsafe { ffi::GetScreenWidth() as _ }
    }

    /// Get current screen height
    #[inline]
    pub fn get_screen_height(&self) -> u32 {
        unsafe { ffi::GetScreenHeight() as _ }
    }

    /// Get current render width (it considers HiDPI)
    #[inline]
    pub fn get_render_width(&self) -> u32 {
        unsafe { ffi::GetRenderWidth() as _ }
    }

    /// Get current render height (it considers HiDPI)
    #[inline]
    pub fn get_render_height(&self) -> u32 {
        unsafe { ffi::GetRenderHeight() as _ }
    }

    /// Get number of connected monitors
    #[inline]
    pub fn get_monitor_count(&self) -> u32 {
        unsafe { ffi::GetMonitorCount() as _ }
    }

    /// Get current connected monitor
    #[inline]
    pub fn get_current_monitor(&self) -> u32 {
        unsafe { ffi::GetCurrentMonitor() as _ }
    }

    /// Get specified monitor position
    #[inline]
    pub fn get_monitor_position(&self, monitor: u32) -> Vector2 {
        unsafe { ffi::GetMonitorPosition(monitor as _).into() }
    }

    /// Get specified monitor width (current video mode used by monitor)
    #[inline]
    pub fn get_monitor_width(&self, monitor: u32) -> u32 {
        unsafe { ffi::GetMonitorWidth(monitor as _) as _ }
    }

    /// Get specified monitor height (current video mode used by monitor)
    #[inline]
    pub fn get_monitor_height(&self, monitor: u32) -> u32 {
        unsafe { ffi::GetMonitorHeight(monitor as _) as _ }
    }

    /// Get specified monitor physical width in millimetres
    #[inline]
    pub fn get_monitor_physical_width(&self, monitor: u32) -> u32 {
        unsafe { ffi::GetMonitorPhysicalWidth(monitor as _) as _ }
    }

    /// Get specified monitor physical height in millimetres
    #[inline]
    pub fn get_monitor_physical_height(&self, monitor: u32) -> u32 {
        unsafe { ffi::GetMonitorPhysicalHeight(monitor as _) as _ }
    }

    /// Get specified monitor refresh rate
    #[inline]
    pub fn get_monitor_refresh_rate(&self, monitor: u32) -> u32 {
        unsafe { ffi::GetMonitorRefreshRate(monitor as _) as _ }
    }

    /// Get window position XY on monitor
    #[inline]
    pub fn get_window_position(&self) -> Vector2 {
        unsafe { ffi::GetWindowPosition().into() }
    }

    /// Get window scale DPI factor
    #[inline]
    pub fn get_window_scale_dpi(&self) -> Vector2 {
        unsafe { ffi::GetWindowScaleDPI().into() }
    }

    /// Get the human-readable, UTF-8 encoded name of the primary monitor
    #[inline]
    pub fn get_monitor_name(&self, monitor: u32) -> String {
        let name = unsafe { ffi::GetMonitorName(monitor as _) };

        if name.is_null() {
            String::new()
        } else {
            unsafe { CStr::from_ptr(name) }
                .to_string_lossy()
                .into_owned()
        }
    }

    /// Set clipboard text content
    #[inline]
    pub fn set_clipboard_text(&mut self, text: &str) {
        let text = CString::new(text).unwrap();

        unsafe { ffi::SetClipboardText(text.as_ptr()) }
    }

    /// Get clipboard text content
    #[inline]
    pub fn get_clipboard_text(&self) -> String {
        let text = unsafe { ffi::GetClipboardText() };

        if text.is_null() {
            String::new()
        } else {
            unsafe { CStr::from_ptr(text) }
                .to_string_lossy()
                .into_owned()
        }
    }

    /// Enable waiting for events on EndDrawing(), no automatic event polling
    #[inline]
    pub fn enable_event_waiting(&mut self) {
        unsafe { ffi::EnableEventWaiting() }
    }

    /// Disable waiting for events on EndDrawing(), automatic events polling
    #[inline]
    pub fn disable_event_waiting(&mut self) {
        unsafe { ffi::DisableEventWaiting() }
    }

    /// Swap back buffer with front buffer (screen drawing)
    /// NOTE: Those functions are intended for advance users that want full control over the frame processing
    #[inline]
    pub fn swap_screen_buffer(&mut self) {
        unsafe { ffi::SwapScreenBuffer() }
    }

    /// Register all input events
    /// NOTE: Those functions are intended for advance users that want full control over the frame processing
    #[inline]
    pub fn poll_input_events(&mut self) {
        unsafe { ffi::PollInputEvents() }
    }

    /// Wait for some time (halt program execution)
    /// NOTE: Those functions are intended for advance users that want full control over the frame processing
    #[inline]
    pub fn wait_time(&mut self, duration: Duration) {
        unsafe { ffi::WaitTime(duration.as_secs_f64()) }
    }

    /// Shows cursor
    #[inline]
    pub fn show_cursor(&mut self) {
        unsafe { ffi::ShowCursor() }
    }

    /// Hides cursor
    #[inline]
    pub fn hide_cursor(&mut self) {
        unsafe { ffi::HideCursor() }
    }

    /// Check if cursor is not visible
    #[inline]
    pub fn is_cursor_hidden(&self) -> bool {
        unsafe { ffi::IsCursorHidden() }
    }

    /// Enables cursor (unlock cursor)
    #[inline]
    pub fn enable_cursor(&mut self) {
        unsafe { ffi::EnableCursor() }
    }

    /// Disables cursor (lock cursor)
    #[inline]
    pub fn disable_cursor(&mut self) {
        unsafe { ffi::DisableCursor() }
    }

    /// Check if cursor is on the screen
    #[inline]
    pub fn is_cursor_on_screen(&self) -> bool {
        unsafe { ffi::IsCursorOnScreen() }
    }

    /// Set target FPS (maximum)
    #[inline]
    pub fn set_target_fps(&mut self, fps: u32) {
        unsafe { ffi::SetTargetFPS(fps as _) }
    }

    /// Get current FPS
    #[inline]
    pub fn get_fps(&self) -> u32 {
        unsafe { ffi::GetFPS() as _ }
    }

    /// Get time for last frame drawn (delta time)
    #[inline]
    pub fn get_frame_time(&self) -> Duration {
        Duration::from_secs_f32(unsafe { ffi::GetFrameTime() })
    }

    /// Get elapsed time since InitWindow()
    #[inline]
    pub fn get_time(&self) -> Duration {
        Duration::from_secs_f64(unsafe { ffi::GetTime() })
    }

    /// Get a random value between min and max (both included)
    #[inline]
    pub fn get_random_value(&self, min: i32, max: i32) -> i32 {
        unsafe { ffi::GetRandomValue(min, max) }
    }

    /// Set the seed for the random number generator
    #[inline]
    pub fn set_random_seed(&mut self, seed: u32) {
        unsafe { ffi::SetRandomSeed(seed) }
    }

    /// Takes a screenshot of current screen (file_name extension defines format)
    #[inline]
    pub fn take_screenshot(&mut self, file_name: &str) {
        let file_name = CString::new(file_name).unwrap();

        unsafe { ffi::TakeScreenshot(file_name.as_ptr()) }
    }

    /// Open URL with default system browser (if available)
    #[inline]
    pub fn open_url(&self, url: &str) {
        let url = CString::new(url).unwrap();

        unsafe { ffi::OpenURL(url.as_ptr()) }
    }

    /// Check if a file has been dropped into window
    #[inline]
    pub fn is_file_dropped(&self) -> bool {
        unsafe { ffi::IsFileDropped() }
    }

    /// Load dropped filepaths
    #[inline]
    pub fn get_dropped_files(&self) -> Vec<String> {
        let path_list = unsafe { ffi::LoadDroppedFiles() };
        let mut paths = Vec::new();

        for i in 0..(path_list.count as usize) {
            let path = unsafe { CStr::from_ptr(path_list.paths.add(i).read()) };

            paths.push(path.to_string_lossy().into_owned());
        }

        unsafe {
            ffi::UnloadDroppedFiles(path_list);
        }

        paths
    }

    /// Check if a key has been pressed once
    #[inline]
    pub fn is_key_pressed(&self, key: KeyboardKey) -> bool {
        unsafe { ffi::IsKeyPressed(key as _) }
    }

    /// Check if a key is being pressed
    #[inline]
    pub fn is_key_down(&self, key: KeyboardKey) -> bool {
        unsafe { ffi::IsKeyDown(key as _) }
    }

    /// Check if a key has been released once
    #[inline]
    pub fn is_key_released(&self, key: KeyboardKey) -> bool {
        unsafe { ffi::IsKeyReleased(key as _) }
    }

    /// Check if a key is NOT being pressed
    #[inline]
    pub fn is_key_up(&self, key: KeyboardKey) -> bool {
        unsafe { ffi::IsKeyUp(key as _) }
    }

    /// Set a custom key to exit program (default is ESC)
    #[inline]
    pub fn set_exit_key(&mut self, key: KeyboardKey) {
        unsafe { ffi::SetExitKey(key as _) }
    }

    /// Get key pressed (keycode), call it multiple times for keys queued, returns [`KeyboardKey::Null`] when the queue is empty
    #[inline]
    pub fn get_key_pressed(&self) -> KeyboardKey {
        unsafe { std::mem::transmute(ffi::GetKeyPressed()) }
    }

    /// Get char pressed (unicode), call it multiple times for chars queued, returns `None` when the queue is empty
    #[inline]
    pub fn get_char_pressed(&self) -> Option<char> {
        let ch = unsafe { ffi::GetCharPressed() as u32 };

        if ch != 0 {
            char::from_u32(ch)
        } else {
            None
        }
    }

    /// Check if a gamepad is available
    #[inline]
    pub fn is_gamepad_available(&self, gamepad: u32) -> bool {
        unsafe { ffi::IsGamepadAvailable(gamepad as _) }
    }

    /// Get gamepad internal name id
    #[inline]
    pub fn get_gamepad_name(&self, gamepad: u32) -> String {
        let name = unsafe { ffi::GetGamepadName(gamepad as _) };

        if !name.is_null() {
            let name = unsafe { CStr::from_ptr(name) };

            name.to_string_lossy().into_owned()
        } else {
            String::new()
        }
    }

    /// Check if a gamepad button has been pressed once
    #[inline]
    pub fn is_gamepad_button_pressed(&self, gamepad: u32, button: GamepadButton) -> bool {
        unsafe { ffi::IsGamepadButtonPressed(gamepad as _, button as _) }
    }

    /// Check if a gamepad button is being pressed
    #[inline]
    pub fn is_gamepad_button_down(&self, gamepad: u32, button: GamepadButton) -> bool {
        unsafe { ffi::IsGamepadButtonDown(gamepad as _, button as _) }
    }

    /// Check if a gamepad button has been released once
    #[inline]
    pub fn is_gamepad_button_released(&self, gamepad: u32, button: GamepadButton) -> bool {
        unsafe { ffi::IsGamepadButtonReleased(gamepad as _, button as _) }
    }

    /// Check if a gamepad button is NOT being pressed
    #[inline]
    pub fn is_gamepad_button_up(&self, gamepad: u32, button: GamepadButton) -> bool {
        unsafe { ffi::IsGamepadButtonUp(gamepad as _, button as _) }
    }

    /// Get the last gamepad button pressed
    #[inline]
    pub fn get_gamepad_button_pressed(&self) -> GamepadButton {
        unsafe { std::mem::transmute(ffi::GetGamepadButtonPressed()) }
    }

    /// Get gamepad axis count for a gamepad
    #[inline]
    pub fn get_gamepad_axis_count(&self, gamepad: u32) -> u32 {
        unsafe { ffi::GetGamepadAxisCount(gamepad as _) as _ }
    }

    /// Get axis movement value for a gamepad axis
    #[inline]
    pub fn get_gamepad_axis_movement(&self, gamepad: u32, axis: GamepadAxis) -> f32 {
        unsafe { ffi::GetGamepadAxisMovement(gamepad as _, axis as _) }
    }

    /// Set internal gamepad mappings (SDL_GameControllerDB)
    #[inline]
    pub fn set_gamepad_mappings(&mut self, mappings: &str) -> i32 {
        let mappings = CString::new(mappings).unwrap();

        unsafe { ffi::SetGamepadMappings(mappings.as_ptr()) }
    }

    /// Check if a mouse button has been pressed once
    #[inline]
    pub fn is_mouse_button_pressed(&self, button: MouseButton) -> bool {
        unsafe { ffi::IsMouseButtonPressed(button as _) }
    }

    /// Check if a mouse button is being pressed
    #[inline]
    pub fn is_mouse_button_down(&self, button: MouseButton) -> bool {
        unsafe { ffi::IsMouseButtonDown(button as _) }
    }

    /// Check if a mouse button has been released once
    #[inline]
    pub fn is_mouse_button_released(&self, button: MouseButton) -> bool {
        unsafe { ffi::IsMouseButtonReleased(button as _) }
    }

    /// Check if a mouse button is NOT being pressed
    #[inline]
    pub fn is_mouse_button_up(&self, button: MouseButton) -> bool {
        unsafe { ffi::IsMouseButtonUp(button as _) }
    }

    /// Get mouse position X
    #[inline]
    pub fn get_mouse_x(&self) -> i32 {
        unsafe { ffi::GetMouseX() }
    }

    /// Get mouse position Y
    #[inline]
    pub fn get_mouse_y(&self) -> i32 {
        unsafe { ffi::GetMouseY() }
    }

    /// Get mouse position XY
    #[inline]
    pub fn get_mouse_position(&self) -> Vector2 {
        unsafe { ffi::GetMousePosition().into() }
    }

    /// Get mouse delta between frames
    #[inline]
    pub fn get_mouse_delta(&self) -> Vector2 {
        unsafe { ffi::GetMouseDelta().into() }
    }

    /// Set mouse position XY
    #[inline]
    pub fn set_mouse_position(&mut self, x: i32, y: i32) {
        unsafe { ffi::SetMousePosition(x, y) }
    }

    /// Set mouse offset
    #[inline]
    pub fn set_mouse_offset(&mut self, offset_x: i32, offset_y: i32) {
        unsafe { ffi::SetMouseOffset(offset_x, offset_y) }
    }

    /// Set mouse scaling
    #[inline]
    pub fn set_mouse_scale(&mut self, scale_x: f32, scale_y: f32) {
        unsafe { ffi::SetMouseScale(scale_x, scale_y) }
    }

    /// Get mouse wheel movement for X or Y, whichever is larger
    #[inline]
    pub fn get_mouse_wheel_move(&self) -> f32 {
        unsafe { ffi::GetMouseWheelMove() }
    }

    /// Get mouse wheel movement for both X and Y
    #[inline]
    pub fn get_mouse_wheel_move_vec(&self) -> Vector2 {
        unsafe { ffi::GetMouseWheelMoveV().into() }
    }

    /// Set mouse cursor
    #[inline]
    pub fn set_mouse_cursor(&mut self, cursor: MouseCursor) {
        unsafe { ffi::SetMouseCursor(cursor as _) }
    }

    /// Get touch position X for touch point 0 (relative to screen size)
    #[inline]
    pub fn get_touch_x(&self) -> i32 {
        unsafe { ffi::GetTouchX() }
    }

    /// Get touch position Y for touch point 0 (relative to screen size)
    #[inline]
    pub fn get_touch_y(&self) -> i32 {
        unsafe { ffi::GetTouchY() }
    }

    /// Get touch position XY for a touch point index (relative to screen size)
    #[inline]
    pub fn get_touch_position(&self, index: u32) -> Vector2 {
        unsafe { ffi::GetTouchPosition(index as _).into() }
    }

    /// Get touch point identifier for given index
    #[inline]
    pub fn get_touch_point_id(&self, index: u32) -> u32 {
        unsafe { ffi::GetTouchPointId(index as _) as _ }
    }

    /// Get number of touch points
    #[inline]
    pub fn get_touch_point_count(&self) -> u32 {
        unsafe { ffi::GetTouchPointCount() as _ }
    }

    /// Enable a set of gestures using flags
    #[inline]
    pub fn set_gestures_enabled(&mut self, flags: Gesture) {
        unsafe { ffi::SetGesturesEnabled(flags.bits()) }
    }

    /// Check if a gesture have been detected
    #[inline]
    pub fn is_gesture_detected(&self, gesture: Gesture) -> bool {
        unsafe { ffi::IsGestureDetected(gesture.bits() as _) }
    }

    /// Get latest detected gesture
    #[inline]
    pub fn get_gesture_detected(&self) -> Gesture {
        unsafe { Gesture(ffi::GetGestureDetected() as _) }
    }

    /// Get gesture hold time
    #[inline]
    pub fn get_gesture_hold_duration(&self) -> Duration {
        Duration::from_micros(unsafe { ffi::GetGestureHoldDuration() * 1000. } as u64)
    }

    /// Get gesture drag vector
    #[inline]
    pub fn get_gesture_drag_vector(&self) -> Vector2 {
        unsafe { ffi::GetGestureDragVector().into() }
    }

    /// Get gesture drag angle
    #[inline]
    pub fn get_gesture_drag_angle(&self) -> f32 {
        unsafe { ffi::GetGestureDragAngle() }
    }

    /// Get gesture pinch delta
    #[inline]
    pub fn get_gesture_pinch_vector(&self) -> Vector2 {
        unsafe { ffi::GetGesturePinchVector().into() }
    }

    /// Get gesture pinch angle
    #[inline]
    pub fn get_gesture_pinch_angle(&self) -> f32 {
        unsafe { ffi::GetGesturePinchAngle() }
    }

    /// Setup canvas (framebuffer) to start drawing
    #[inline]
    pub fn begin_drawing(&mut self) -> DrawHandle {
        unsafe {
            ffi::BeginDrawing();
        }

        DrawHandle(self)
    }
}

impl Drop for Raylib {
    #[inline]
    fn drop(&mut self) {
        unsafe { ffi::CloseWindow() }
    }
}