55 lines
1.2 KiB
Rust
55 lines
1.2 KiB
Rust
|
use std::ffi::{c_char,CString};
|
||
|
|
||
|
#[repr(C)]
|
||
|
pub struct Color(pub u8, pub u8, pub u8, pub u8);
|
||
|
|
||
|
#[link(name = "raylib")]
|
||
|
extern {
|
||
|
fn InitWindow(width: u32, height: u32, title: *const c_char);
|
||
|
fn WindowShouldClose() -> bool;
|
||
|
fn BeginDrawing();
|
||
|
fn EndDrawing();
|
||
|
fn DrawRectangle(pos_x: u32, pos_y: u32, width: u32, height: u32, color: Color);
|
||
|
fn IsKeyPressed(key: u32) -> bool;
|
||
|
}
|
||
|
|
||
|
#[derive(Copy, Clone)]
|
||
|
pub enum Key {
|
||
|
Z = 89,
|
||
|
}
|
||
|
|
||
|
pub fn init_window(width: u32, height: u32, title: &str) {
|
||
|
unsafe {
|
||
|
let title = CString::new(title).unwrap();
|
||
|
InitWindow(width, height, title.as_ptr());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
pub fn window_should_close() -> bool {
|
||
|
unsafe { WindowShouldClose() }
|
||
|
}
|
||
|
|
||
|
pub fn begin_drawing() {
|
||
|
unsafe { BeginDrawing(); }
|
||
|
}
|
||
|
|
||
|
pub fn end_drawing() {
|
||
|
unsafe { EndDrawing(); }
|
||
|
}
|
||
|
|
||
|
pub fn draw_rect(pos_x: u32, pos_y: u32, width:u32, height: u32, color: Color) {
|
||
|
unsafe { DrawRectangle(pos_x, pos_y, width, height, color); }
|
||
|
}
|
||
|
|
||
|
pub fn is_key_pressed(key: Key) -> bool {
|
||
|
let key = key as u32;
|
||
|
unsafe {
|
||
|
let ret = IsKeyPressed(key);
|
||
|
if ret {
|
||
|
println!("is_key_pressed({key})");
|
||
|
}
|
||
|
ret
|
||
|
}
|
||
|
}
|
||
|
|