use crate::draw::Rgb;
use crate::runtime::SkinRuntime;
const SHEET: &str = "genex.bmp";
pub const GENEX_COLORS: usize = 24;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(usize)]
pub enum GenexColor {
ItemBg,
ItemFg,
WindowBg,
ButtonFg,
WindowFg,
Hilite,
SelColor,
ListHeaderBg,
ListHeaderFont,
ListHeaderFrameTop,
ListHeaderFrameMiddle,
ListHeaderFrameBottom,
ListHeaderEmptyBg,
ScrollbarFg,
ScrollbarBg,
ScrollbarInvFg,
ScrollbarInvBg,
ScrollbarDeadArea,
SelbarFg,
SelbarBg,
InactSelbarFg,
InactSelbarBg,
ItemBg2,
ItemFg2,
}
const DEFAULTS: [u32; GENEX_COLORS] = [
0x000000, 0x00ff00, 0x24243c, 0x393842, 0xffffff, 0x8494a5, 0x0000c6, 0x484878, 0xffffff,
0x6c6cb4, 0x24243c, 0x12121e, 0x24243c, 0x24243c, 0x24243c, 0x798296, 0x4e586e, 0x24243c,
0xffffff, 0x0000b4, 0x00ff00, 0x000080, 0x000000, 0x00ff00,
];
pub(crate) fn colors(row: Option<&[u32]>) -> [Rgb; GENEX_COLORS] {
let at = |x: usize| row.and_then(|r| r.get(x)).map(|p| p & 0x00ff_ffff);
let marker = at(111);
let mut out = [Rgb(0); GENEX_COLORS];
for i in 0..GENEX_COLORS {
let px = at(48 + 2 * i);
let unset = px.is_none() || px == Some(0x00c6ff) || px == marker;
out[i] = match (unset, i) {
(false, _) => Rgb(px.unwrap_or(0)),
(true, 18 | 20) => out[GenexColor::WindowFg as usize],
(true, 19) => out[GenexColor::SelColor as usize],
(true, 21) => Rgb(half(out[GenexColor::WindowBg as usize].0)
+ half(out[GenexColor::SelColor as usize].0)),
(true, 22) => out[GenexColor::ItemBg as usize],
(true, 23) => out[GenexColor::ItemFg as usize],
(true, _) => Rgb(DEFAULTS[i]),
};
}
out
}
fn half(c: u32) -> u32 {
(c / 2) & 0x007f_7f7f
}
impl SkinRuntime {
pub fn classic_genex_colors(&mut self) -> [Rgb; GENEX_COLORS] {
let sheet = self.classic_sheet(SHEET);
let width = self.image_size(&sheet).map_or(0, |s| s.0);
let row = (width > 0)
.then(|| self.host.pixels(&sheet, 0, 0, width, 1))
.flatten();
colors(row.as_deref())
}
}
#[cfg(test)]
mod tests {
use super::{colors, GenexColor, DEFAULTS, GENEX_COLORS};
use crate::draw::Rgb;
#[test]
fn colors_come_from_every_second_pixel_from_48() {
let mut row = vec![0xff00_0000u32; 130];
for i in 0..GENEX_COLORS {
row[48 + 2 * i] = 0xff00_0000 | (0x10 + i as u32);
}
row[111] = 0xff12_3456;
let c = colors(Some(&row));
assert_eq!(c[GenexColor::ItemBg as usize], Rgb(0x10));
assert_eq!(c[GenexColor::ItemFg2 as usize], Rgb(0x10 + 23));
}
#[test]
fn unset_pixels_follow_the_media_librarys_rules() {
let mut row = vec![0xff00_c6ffu32; 60];
row[48] = 0xff11_1111; row[50] = 0xff22_2222; row[52] = 0xff44_4444; row[56] = 0xff66_6666; let c = colors(Some(&row));
assert_eq!(c[3], Rgb(DEFAULTS[3]), "button fg: cyan is unset");
assert_eq!(c[6], Rgb(DEFAULTS[6]), "past the edge");
assert_eq!(c[18], Rgb(0x666666), "selbar fg = window fg");
assert_eq!(c[19], c[6], "selbar bg = sel color");
assert_eq!(
c[21],
Rgb(0x222222 + 0x000063),
"half window bg + half sel color"
);
assert_eq!(c[22], Rgb(0x111111));
assert_eq!(c[23], Rgb(0x222222));
}
#[test]
fn no_sheet_gives_the_media_librarys_colors_and_its_derived_ones() {
let c = colors(None);
assert_eq!(c[0], Rgb(DEFAULTS[0]));
assert_eq!(c[18], Rgb(DEFAULTS[4]));
}
}