From 18bd1c6829d233f525a58bf4f363ffd12153afbd Mon Sep 17 00:00:00 2001 From: Addison <63932310+addiment@users.noreply.github.com> Date: Mon, 14 Oct 2024 14:09:10 -0400 Subject: [PATCH 1/2] Tweak some comments and add a new `from_hex_alpha` function --- .gitignore | 39 +++++++++++++++++++++++++++++++++++++-- src/color.rs | 19 +++++++++++++++++++ src/time.rs | 6 +++--- 3 files changed, 59 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 69369904..85558e62 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,38 @@ -/target -**/*.rs.bk +# Generated by Cargo +# will have compiled files and executables +debug/ +target/ + +# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries +# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html Cargo.lock + +# These are backup files generated by rustfmt +**/*.rs.bk + +# MSVC Windows builds of rustc generate these, which store debugging information +*.pdb + +# Some JetBrains IDE ignores + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Editor-based Rest Client +.idea/httpRequests \ No newline at end of file diff --git a/src/color.rs b/src/color.rs index e5f4bdf7..0a6c9823 100644 --- a/src/color.rs +++ b/src/color.rs @@ -131,6 +131,25 @@ impl Color { Self::from_rgba(bytes[1], bytes[2], bytes[3], 255) } + /// Build a color from a hexadecimal u32 and an accompanying u8 alpha value. + /// + /// # Example + /// + /// ``` + /// use macroquad::prelude::*; + /// + /// let light_blue = Color::from_hex_alpha(0x3CA7D5, 0x80); + /// assert_eq!(light_blue.r, 0.23529412); + /// assert_eq!(light_blue.g, 0.654902); + /// assert_eq!(light_blue.b, 0.8352941); + /// assert_eq!(light_blue.a, 0.5019608); + /// ``` + pub fn from_hex_alpha(hex: u32, alpha: u8) -> Color { + let bytes: [u8; 4] = hex.to_be_bytes(); + + Self::from_rgba(bytes[1], bytes[2], bytes[3], alpha) + } + /// Create a vec4 of red, green, blue, and alpha components. pub fn to_vec(&self) -> glam::Vec4 { glam::Vec4::new(self.r, self.g, self.b, self.a) diff --git a/src/time.rs b/src/time.rs index cb688f3d..d53ad41e 100644 --- a/src/time.rs +++ b/src/time.rs @@ -1,4 +1,4 @@ -//! Cross platform system time access and FPS counters. +//! Cross-platform system time access and FPS counters. use crate::get_context; @@ -9,7 +9,7 @@ pub fn get_fps() -> i32 { (1. / context.frame_time) as i32 } -/// Returns duration in seconds of the last frame drawn +/// Returns duration in seconds of the last frame drawn, the "delta time." pub fn get_frame_time() -> f32 { let context = get_context(); @@ -23,7 +23,7 @@ pub fn get_frame_time() -> f32 { /// Returns elapsed wall-clock time in seconds since start /// /// Note that as real world time progresses during computation, -/// the value returned will change. Therefore if you want +/// the value returned will change. Therefore, if you want /// your game logic update to happen at the same *in-game* time /// for all game objects, you should call this function once /// save the value and reuse it throughout your code. From 21afbcb3e331351b343a1b2a2ea8bac350d1860b Mon Sep 17 00:00:00 2001 From: Addison <63932310+addiment@users.noreply.github.com> Date: Tue, 15 Oct 2024 02:04:13 -0400 Subject: [PATCH 2/2] Update .gitignore Undid tweaks to the gitignore to RustRover usage easier, by request --- .gitignore | 39 ++------------------------------------- 1 file changed, 2 insertions(+), 37 deletions(-) diff --git a/.gitignore b/.gitignore index 85558e62..69369904 100644 --- a/.gitignore +++ b/.gitignore @@ -1,38 +1,3 @@ -# Generated by Cargo -# will have compiled files and executables -debug/ -target/ - -# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries -# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html -Cargo.lock - -# These are backup files generated by rustfmt +/target **/*.rs.bk - -# MSVC Windows builds of rustc generate these, which store debugging information -*.pdb - -# Some JetBrains IDE ignores - -# User-specific stuff -.idea/**/workspace.xml -.idea/**/tasks.xml -.idea/**/usage.statistics.xml -.idea/**/dictionaries -.idea/**/shelf - -# Generated files -.idea/**/contentModel.xml - -# Sensitive or high-churn files -.idea/**/dataSources/ -.idea/**/dataSources.ids -.idea/**/dataSources.local.xml -.idea/**/sqlDataSources.xml -.idea/**/dynamic.xml -.idea/**/uiDesigner.xml -.idea/**/dbnavigator.xml - -# Editor-based Rest Client -.idea/httpRequests \ No newline at end of file +Cargo.lock