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
use crate::core::texture::Image;
use crate::core::{RaylibHandle, RaylibThread};
use crate::ffi;
use std::ffi::{CStr, CString};
pub fn get_random_value(min: i32, max: i32) -> i32 {
unsafe { ffi::GetRandomValue(min, max) }
}
pub fn open_url(url: &str) {
let s = CString::new(url).expect("Not a string");
unsafe {
ffi::OpenURL(s.as_ptr());
}
}
impl RaylibHandle {
pub fn get_screen_data(&mut self, _: &RaylibThread) -> Image {
unsafe { Image(ffi::GetScreenData()) }
}
pub fn take_screenshot(&mut self, _: &RaylibThread, filename: &str) {
let c_filename = CString::new(filename).unwrap();
unsafe {
ffi::TakeScreenshot(c_filename.as_ptr());
}
}
}
#[inline]
pub fn load_text(filename: &str) -> String {
let c_filename = CString::new(filename).unwrap();
unsafe {
let text = ffi::LoadText(c_filename.as_ptr());
let safe_text = CStr::from_ptr(text).to_str().unwrap().to_owned();
libc::free(text as *mut libc::c_void);
safe_text
}
}