From eb84151e46e662be7a7daf412cbedcd3650dcb80 Mon Sep 17 00:00:00 2001 From: Evan Pratten Date: Fri, 9 Dec 2022 11:11:54 -0500 Subject: [PATCH] reorg a bit --- Cargo.toml | 12 ++++++++---- examples/basic.rs | 26 ++++++++----------------- src/lib.rs | 6 +----- src/raylib/ffi.rs | 8 ++++++++ src/raylib/mod.rs | 4 ++++ src/raylib/xlat/mod.rs | 4 ++++ src/raylib/xlat/rgb.rs | 44 ++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 77 insertions(+), 27 deletions(-) create mode 100644 src/raylib/ffi.rs create mode 100644 src/raylib/mod.rs create mode 100644 src/raylib/xlat/mod.rs create mode 100644 src/raylib/xlat/rgb.rs diff --git a/Cargo.toml b/Cargo.toml index 80fd058..0c7a30b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,13 +1,13 @@ [package] -name = "raylib-ffi" +name = "renderkit" version = "4.2.0" authors = ["Evan Pratten "] 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" diff --git a/examples/basic.rs b/examples/basic.rs index 2aa5b9c..599d9b9 100644 --- a/examples/basic.rs +++ b/examples/basic.rs @@ -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(); } } diff --git a/src/lib.rs b/src/lib.rs index 23a4bca..e7c0b7b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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")); \ No newline at end of file +pub mod raylib; \ No newline at end of file diff --git a/src/raylib/ffi.rs b/src/raylib/ffi.rs new file mode 100644 index 0000000..34eb356 --- /dev/null +++ b/src/raylib/ffi.rs @@ -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")); \ No newline at end of file diff --git a/src/raylib/mod.rs b/src/raylib/mod.rs new file mode 100644 index 0000000..99a45b8 --- /dev/null +++ b/src/raylib/mod.rs @@ -0,0 +1,4 @@ +//! Bindings and helpers for interfacing with raylib + +pub mod xlat; +pub mod ffi; \ No newline at end of file diff --git a/src/raylib/xlat/mod.rs b/src/raylib/xlat/mod.rs new file mode 100644 index 0000000..18bb989 --- /dev/null +++ b/src/raylib/xlat/mod.rs @@ -0,0 +1,4 @@ +//! Translations between well-known Rust libraries and raylib + + +pub mod rgb; \ No newline at end of file diff --git a/src/raylib/xlat/rgb.rs b/src/raylib/xlat/rgb.rs new file mode 100644 index 0000000..b48adc1 --- /dev/null +++ b/src/raylib/xlat/rgb.rs @@ -0,0 +1,44 @@ +//! Conversions between the `rgb` crate and the `Color` type. + +impl From 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 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 for rgb::RGB8 { + fn from(color: crate::raylib::ffi::Color) -> Self { + Self { + r: color.r, + g: color.g, + b: color.b, + } + } +} + +impl Into 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, + } + } +}