diff --git a/src/sdl2/pixels.rs b/src/sdl2/pixels.rs index 9b9cff8d..8a4b6cb2 100644 --- a/src/sdl2/pixels.rs +++ b/src/sdl2/pixels.rs @@ -157,6 +157,19 @@ impl From for Color { } } + +impl From<(u8, u8, u8)> for Color { + fn from((r, g, b): (u8, u8, u8)) -> Color { + Color::RGB(r, g, b) + } +} + +impl From<(u8, u8, u8, u8)> for Color { + fn from((r, g, b, a): (u8, u8, u8, u8)) -> Color { + Color::RGBA(r, g, b, a) + } +} + impl rand::Rand for Color { fn rand(rng: &mut R) -> Color { if rng.gen() { Color::RGBA(rng.gen(), rng.gen(), rng.gen(), rng.gen()) } diff --git a/src/sdl2/render.rs b/src/sdl2/render.rs index 48fa44a5..a8f41540 100644 --- a/src/sdl2/render.rs +++ b/src/sdl2/render.rs @@ -902,8 +902,8 @@ impl Canvas { } /// Sets the color used for drawing operations (Rect, Line and Clear). - pub fn set_draw_color(&mut self, color: pixels::Color) { - let (r, g, b, a) = color.rgba(); + pub fn set_draw_color>(&mut self, color: C) { + let (r, g, b, a) = color.into().rgba(); let ret = unsafe { sys::SDL_SetRenderDrawColor(self.raw, r, g, b, a) }; // Should only fail on an invalid renderer if ret != 0 {