1

reorg a bit

This commit is contained in:
Evan Pratten 2022-12-09 11:11:54 -05:00
parent 964a5c8ec1
commit eb84151e46
7 changed files with 77 additions and 27 deletions

View File

@ -1,13 +1,13 @@
[package]
name = "raylib-ffi"
name = "renderkit"
version = "4.2.0"
authors = ["Evan Pratten <ewpratten@gmail.com>"]
edition = "2021"
description = "Automatic raw Rust bindings to raylib"
documentation = "https://docs.rs/raylib-ffi"
documentation = "https://docs.rs/renderkit"
readme = "README.md"
homepage = "https://github.com/ewpratten/raylib-ffi"
repository = "https://github.com/ewpratten/raylib-ffi"
homepage = "https://github.com/ewpratten/renderkit"
repository = "https://github.com/ewpratten/renderkit"
license = "GPL-3.0"
keywords = ["raylib", "graphics"]
categories = ["external-ffi-bindings", "graphics", "multimedia", "rendering"]
@ -18,6 +18,10 @@ exclude = [
"third_party/raylib/projects/*"
]
[dependencies]
rgb = "^0.8.34"
[build-dependencies]
bindgen = "^0.63.0"
cmake = "^0.1.49"

View File

@ -1,7 +1,7 @@
pub fn main() {
unsafe {
// Create a window
raylib_ffi::InitWindow(
renderkit::raylib::ffi::InitWindow(
800,
450,
"raylib-ffi example - basic window\0".as_ptr() as *const i8,
@ -10,38 +10,28 @@ pub fn main() {
// Render the window
loop {
// Close the window if requested
if raylib_ffi::WindowShouldClose() {
if renderkit::raylib::ffi::WindowShouldClose() {
break;
}
// Begin a draw call
raylib_ffi::BeginDrawing();
renderkit::raylib::ffi::BeginDrawing();
// Render text and a background
raylib_ffi::ClearBackground(raylib_ffi::Color {
r: 255,
g: 255,
b: 255,
a: 255,
});
raylib_ffi::DrawText(
renderkit::raylib::ffi::ClearBackground(rgb::RGB::new(255, 255, 255).into());
renderkit::raylib::ffi::DrawText(
"Congrats! You created your first window!\0".as_ptr() as *const i8,
190,
200,
20,
raylib_ffi::Color {
r: 0,
g: 0,
b: 0,
a: 255,
},
rgb::RGB::new(0, 0, 0).into(),
);
// End the draw call
raylib_ffi::EndDrawing();
renderkit::raylib::ffi::EndDrawing();
}
// Clean up
raylib_ffi::CloseWindow();
renderkit::raylib::ffi::CloseWindow();
}
}

View File

@ -1,7 +1,3 @@
#![doc = include_str!("../README.md")]
#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
// Include the generated bindings
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
pub mod raylib;

8
src/raylib/ffi.rs Normal file
View File

@ -0,0 +1,8 @@
//! Bindings to raylib's C API
#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
// Include the generated bindings
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));

4
src/raylib/mod.rs Normal file
View File

@ -0,0 +1,4 @@
//! Bindings and helpers for interfacing with raylib
pub mod xlat;
pub mod ffi;

4
src/raylib/xlat/mod.rs Normal file
View File

@ -0,0 +1,4 @@
//! Translations between well-known Rust libraries and raylib
pub mod rgb;

44
src/raylib/xlat/rgb.rs Normal file
View File

@ -0,0 +1,44 @@
//! Conversions between the `rgb` crate and the `Color` type.
impl From<crate::raylib::ffi::Color> for rgb::RGBA8 {
fn from(color: crate::raylib::ffi::Color) -> Self {
Self {
r: color.r,
g: color.g,
b: color.b,
a: color.a,
}
}
}
impl Into<crate::raylib::ffi::Color> for rgb::RGBA8 {
fn into(self) -> crate::raylib::ffi::Color {
crate::raylib::ffi::Color {
r: self.r,
g: self.g,
b: self.b,
a: self.a,
}
}
}
impl From<crate::raylib::ffi::Color> for rgb::RGB8 {
fn from(color: crate::raylib::ffi::Color) -> Self {
Self {
r: color.r,
g: color.g,
b: color.b,
}
}
}
impl Into<crate::raylib::ffi::Color> for rgb::RGB8 {
fn into(self) -> crate::raylib::ffi::Color {
crate::raylib::ffi::Color {
r: self.r,
g: self.g,
b: self.b,
a: 255,
}
}
}