Icone du projet (DT dedouble) : .ico, avatar, apercu social ; integree a l'exe et a la fenetre du launcher

- tools/make_icon.py genere assets/icon/ (police Bangers, aucune image du jeu)
- launcher/build.rs compile dtr.rc avec rc.exe du SDK Windows (sans dependance)
- la fenetre du launcher prend dtr-256.png au lieu du curseur du jeu

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
linkatplugandClaude Opus 5.5 committed 2026-12-05 06:03:54 +01:00
1 parent de55ddbfc6
commit 61d5806492
10 files changed
+213 -33

No files matched your search

+58
View File
@@ -0,0 +1,58 @@
//! Icône de l'exécutable : compile assets/icon/dtr.rc avec rc.exe du SDK Windows (installé avec les
//! Build Tools) et lie la ressource. Sans rc.exe, le launcher se compile quand même, sans icône.
use std::path::{Path, PathBuf};
use std::process::Command;
fn find_rc() -> Option<PathBuf> {
if let Some(p) = std::env::var_os("RC").map(PathBuf::from).filter(|p| p.is_file()) {
return Some(p);
}
let arch = if cfg!(target_arch = "aarch64") { "arm64" } else { "x64" };
for base in ["ProgramFiles(x86)", "ProgramFiles"] {
let Some(b) = std::env::var_os(base) else { continue };
let bin = Path::new(&b).join("Windows Kits").join("10").join("bin");
let Ok(rd) = std::fs::read_dir(&bin) else { continue };
// la version la plus récente qui contient rc.exe
let mut found: Vec<PathBuf> = rd
.flatten()
.map(|e| e.path().join(arch).join("rc.exe"))
.filter(|p| p.is_file())
.collect();
found.sort();
if let Some(p) = found.pop() {
return Some(p);
}
}
None
}
fn main() {
let icon_dir = Path::new(env!("CARGO_MANIFEST_DIR")).join("..").join("assets").join("icon");
println!("cargo:rerun-if-changed={}", icon_dir.join("dtr.rc").display());
println!("cargo:rerun-if-changed={}", icon_dir.join("dtr.ico").display());
if std::env::var("CARGO_CFG_TARGET_OS").as_deref() != Ok("windows")
|| std::env::var("CARGO_CFG_TARGET_ENV").as_deref() != Ok("msvc")
{
return;
}
let Some(rc) = find_rc() else {
println!("cargo:warning=rc.exe introuvable (SDK Windows) : launcher sans icone d'executable");
return;
};
let res = PathBuf::from(std::env::var("OUT_DIR").unwrap()).join("dtr.res");
let ok = Command::new(&rc)
.current_dir(&icon_dir)
.arg("/nologo")
.arg("/fo")
.arg(&res)
.arg("dtr.rc")
.status()
.map(|s| s.success())
.unwrap_or(false);
if ok {
println!("cargo:rustc-link-arg-bins={}", res.display());
} else {
println!("cargo:warning=echec de rc.exe : launcher sans icone d'executable");
}
}
-28
View File
@@ -333,34 +333,6 @@ pub fn logo(dir: &Path) -> Option<Rgba> {
Some(img.to_rgba(x, y, w, h, |_, c| (lum(c) as u32 * 4).min(255) as u8))
}
/// icône : premier curseur de POINTER.PCX (fond = couleur du coin bas droit), agrandi en 32×32
pub fn icon(dir: &Path) -> Option<Rgba> {
let img = decode_pcx(&read(dir, "POINTER.PCX")?)?;
let bg = img.px[img.w * img.h - 1];
// premier sprite : en haut à gauche, jusqu'à la première ligne vide
let mut h = 0;
while h < img.h && img.px[h * img.w..h * img.w + 24.min(img.w)].iter().any(|&p| p != bg) {
h += 1;
}
let sub = Indexed { w: img.w, h: h.max(1), px: img.px[..img.w * h.max(1)].to_vec(), pal: img.pal };
let (x, y, w, h) = bbox(&sub, |i, _| i != bg)?;
let side = w.max(h);
let src = sub.to_rgba(x, y, w, h, |i, _| if i == bg { 0 } else { 255 });
let n = 32;
let mut px = vec![0u8; n * n * 4];
let (ox, oy) = ((side - w) / 2, (side - h) / 2);
for ty in 0..n {
for tx in 0..n {
let (sx, sy) = (tx * side / n, ty * side / n);
if sx >= ox && sy >= oy && sx - ox < w && sy - oy < h {
let s = ((sy - oy) * w + (sx - ox)) * 4;
px[(ty * n + tx) * 4..][..4].copy_from_slice(&src.px[s..s + 4]);
}
}
}
Some(Rgba { w: n, h: n, px })
}
#[cfg(test)]
mod tests {
#[test]
+10 -4
View File
@@ -700,10 +700,6 @@ impl App {
.map(|(i, b)| self.ctx.load_texture(format!("backdrop{i}"), to_image(b), opts))
.collect();
self.art.logo = art::logo(&dir).map(|l| self.ctx.load_texture("logo", to_image(&l), opts));
if let Some(ic) = art::icon(&dir) {
let data = egui::IconData { rgba: ic.px, width: ic.w as u32, height: ic.h as u32 };
self.ctx.send_viewport_cmd(egui::ViewportCommand::Icon(Some(Arc::new(data))));
}
}
fn mods_dir(&self) -> Option<PathBuf> {
@@ -1749,6 +1745,15 @@ impl eframe::App for App {
}
}
/// icône de la fenêtre : assets/icon/dtr-256.png (tools/make_icon.py), intégrée à l'exécutable
fn window_icon() -> egui::IconData {
let png = include_bytes!("../../assets/icon/dtr-256.png");
match mods::decode_png(std::io::Cursor::new(&png[..])) {
Some(i) => egui::IconData { rgba: i.px, width: i.w as u32, height: i.h as u32 },
None => egui::IconData::default(),
}
}
fn main() -> eframe::Result {
let cfg = Config::load();
let size = if cfg.win_w >= 760 && cfg.win_h >= 600 {
@@ -1761,6 +1766,7 @@ fn main() -> eframe::Result {
.with_title("DoubleTroubleRecomp")
.with_inner_size(size)
.with_maximized(cfg.maximized)
.with_icon(window_icon())
.with_min_inner_size([760.0, 600.0]),
..Default::default()
};
+5 -1
View File
@@ -117,7 +117,11 @@ pub fn hd_image(mods: &[Mod], disabled: &[String], pcx: &str) -> Option<PathBuf>
/// PNG → RGBA 8 bits
pub fn load_png(path: &Path) -> Option<crate::art::Rgba> {
let f = std::io::BufReader::new(std::fs::File::open(path).ok()?);
decode_png(std::io::BufReader::new(std::fs::File::open(path).ok()?))
}
/// PNG (lecteur quelconque) → RGBA 8 bits
pub fn decode_png<R: std::io::BufRead + std::io::Seek>(f: R) -> Option<crate::art::Rgba> {
let mut dec = png::Decoder::new(f);
dec.set_transformations(png::Transformations::normalize_to_color8());
let mut reader = dec.read_info().ok()?;