-
-
Notifications
You must be signed in to change notification settings - Fork 342
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tweak some comments and add a new from_hex_alpha
function
#841
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not have very strong opinion here, but it looks like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oops-- totally forgot that 32 bits has room for alpha. Will patch that in, stupid oversight on my part. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It got room, the problem is that |
||
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) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sneaked into the PR by accident, right? :) Could you please rebase it out?