Skip to content

Commit

Permalink
Merge pull request Rust-SDL2#965 from KenSuenobu/master
Browse files Browse the repository at this point in the history
Added invert method for color, and added common color names.
  • Loading branch information
Cobrand authored Jan 31, 2020
2 parents 9c85f4d + eab1d45 commit cebf36f
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/sdl2/pixels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ impl Color {
Color::RGBA(r, g, b, a)
}

pub fn invert(self) -> Color {
Color::RGBA(255 - self.r, 255 - self.g, 255 - self.b, 255 - self.a)
}

#[inline]
pub const fn rgb(self) -> (u8, u8, u8) {
(self.r, self.g, self.b)
Expand All @@ -139,6 +143,18 @@ impl Color {
const fn raw(self) -> sys::SDL_Color {
sys::SDL_Color { r: self.r, g: self.g, b: self.b, a: self.a }
}

pub const WHITE: Color = Color::RGBA(255, 255, 255, 255);
pub const BLACK: Color = Color::RGBA(0, 0, 0, 255);
pub const GRAY: Color = Color::RGBA(128, 128, 128, 255);
pub const GREY: Color = Color::GRAY;
pub const RED: Color = Color::RGBA(255, 0, 0, 255);
pub const GREEN: Color = Color::RGBA(0, 255, 0, 255);
pub const BLUE: Color = Color::RGBA(0, 0, 255, 255);
pub const MAGENTA: Color = Color::RGBA(255, 0, 255, 255);
pub const YELLOW: Color = Color::RGBA(255, 255, 0, 255);
pub const CYAN: Color = Color::RGBA(0, 255, 255, 255);

}

impl Into<sys::SDL_Color> for Color {
Expand Down

0 comments on commit cebf36f

Please sign in to comment.