From 2c2ba24e6bf5200402f5da52613f0ca6a631701a Mon Sep 17 00:00:00 2001 From: gered Date: Sat, 21 May 2022 20:09:27 -0400 Subject: [PATCH] add method to create Palettes with specific initial color RGB value for all colors, instead of always initializing new palettes to black --- libretrogd/src/graphics/palette.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libretrogd/src/graphics/palette.rs b/libretrogd/src/graphics/palette.rs index 5c3480c..ac9ee32 100644 --- a/libretrogd/src/graphics/palette.rs +++ b/libretrogd/src/graphics/palette.rs @@ -202,6 +202,14 @@ impl Palette { } } + /// Creates a new Palette with all initial colors having the RGB values specified. + pub fn new_with_default(r: u8, g: u8, b: u8) -> Palette { + let rgb = to_rgb32(r, g, b); + Palette { + colors: [rgb; NUM_COLORS], + } + } + /// Creates a new Palette, pre-loaded with the default VGA BIOS colors. pub fn new_vga_palette() -> Result { Palette::load_from_bytes(&mut Cursor::new(VGA_PALETTE_BYTES), PaletteFormat::Vga)