From 0f054314214a909b9ab541825e16d7a403445a59 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 7 Nov 2026 14:34:47 -0800 Subject: [PATCH] The DraftCraft logo in the app - crates/ui-egui/src/brand.rs: the app icon (the compass on its blueprint tile) as a texture, decoded once per size, with a DC tile only if it can't be drawn. - The application button shows the logo instead of the DC letters; the Start page and the About window show it beside the name; About adds "DraftCraft and the DraftCraft logo are trademarks of WithShalom Studios." (Italian and Chinese added). The Windows title bar uses the same module. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01F67Rss9szchwv8emEAdE9m --- crates/ui-egui/src/brand.rs | 72 ++++++++++++++++++++++++++++++ crates/ui-egui/src/chrome.rs | 6 ++- crates/ui-egui/src/dialogs.rs | 13 +++++- crates/ui-egui/src/i18n/it.tsv | 1 + crates/ui-egui/src/i18n/zh.tsv | 1 + crates/ui-egui/src/lib.rs | 1 + crates/ui-egui/src/ribbon.rs | 12 ++--- crates/ui-egui/src/window_frame.rs | 27 ++--------- 8 files changed, 100 insertions(+), 33 deletions(-) create mode 100644 crates/ui-egui/src/brand.rs diff --git a/crates/ui-egui/src/brand.rs b/crates/ui-egui/src/brand.rs new file mode 100644 index 00000000..047673ce --- /dev/null +++ b/crates/ui-egui/src/brand.rs @@ -0,0 +1,72 @@ +//! The DraftCraft logo in the interface: the app icon (a drafting compass and the arc it drew on a +//! blueprint-blue tile, `assets/app-icon/`), drawn on the application button, the Start page, the About +//! window and DraftCraft's own title bar. The icon is WithShalom Studios' mark, used by agreement +//! (`docs/brand/LICENSE-brand.txt`). + +use egui::{Align2, Color32, FontId, Rect, pos2}; + +/// The icon at 64 px, for marks up to about 32 px tall. +const ICON_SMALL: &[u8] = include_bytes!("../../../assets/app-icon/hicolor/64x64/apps/dev.skryx.draftcraft.png"); +/// The icon at 256 px, for larger marks. +const ICON_LARGE: &[u8] = include_bytes!("../../../assets/app-icon/draftcraft-256.png"); + +/// DraftCraft's blueprint blue, behind the fallback mark. +const BLUEPRINT: Color32 = Color32::from_rgb(0x0e, 0x34, 0x63); + +/// The icon as a texture sized for marks of `height` points, decoded once per context. `None` if it +/// doesn't decode. +pub fn texture(ctx: &egui::Context, height: f32) -> Option { + let large = height * ctx.pixels_per_point() > 64.0; + let (bytes, key, name) = + if large { (ICON_LARGE, "dc_logo_large", "draftcraft-logo-256") } else { (ICON_SMALL, "dc_logo_small", "draftcraft-logo-64") }; + let id = egui::Id::unique(key); + if let Some(tex) = ctx.data(|d| d.get_temp::(id)) { + return Some(tex); + } + let img = image::load_from_memory_with_format(bytes, image::ImageFormat::Png).ok()?.to_rgba8(); + let size = [usize::try_from(img.width()).ok()?, usize::try_from(img.height()).ok()?]; + let tex = ctx.load_texture(name, egui::ColorImage::from_rgba_unmultiplied(size, img.as_raw()), egui::TextureOptions::LINEAR); + ctx.data_mut(|d| d.insert_temp(id, tex.clone())); + Some(tex) +} + +/// Paint the logo filling `r` (a square); a blueprint-blue DC tile if the icon can't be drawn. +pub fn paint(p: &egui::Painter, r: Rect) { + if let Some(tex) = texture(p.ctx(), r.height()) { + p.image(tex.id(), r, Rect::from_min_max(pos2(0.0, 0.0), pos2(1.0, 1.0)), Color32::WHITE); + return; + } + p.rect_filled(r, r.height() * 0.18, BLUEPRINT); + p.text(r.center(), Align2::CENTER_CENTER, "DC", FontId::proportional(r.height() * 0.5), Color32::WHITE); +} + +/// The logo as a widget of `size` points (square). +pub fn show(ui: &mut egui::Ui, size: f32) -> egui::Response { + let (r, response) = ui.allocate_exact_size(egui::vec2(size, size), egui::Sense::hover()); + paint(ui.painter(), r); + response +} + +#[cfg(test)] +mod tests { + #[test] + fn both_icon_sizes_decode() { + for (bytes, px) in [(super::ICON_SMALL, 64), (super::ICON_LARGE, 256)] { + let img = image::load_from_memory_with_format(bytes, image::ImageFormat::Png).unwrap(); + assert_eq!((img.width(), img.height()), (px, px)); + } + } + + #[test] + fn the_texture_is_made_once_per_size() { + let ctx = egui::Context::default(); + let mut out = ctx.run_ui(Default::default(), |ui| { + let a = super::texture(ui.ctx(), 22.0).unwrap(); + let b = super::texture(ui.ctx(), 22.0).unwrap(); + assert_eq!(a.id(), b.id()); + let big = super::texture(ui.ctx(), 96.0).unwrap(); + assert_ne!(a.id(), big.id()); + }); + out.textures_delta.clear(); + } +} diff --git a/crates/ui-egui/src/chrome.rs b/crates/ui-egui/src/chrome.rs index dae663eb..46775aa6 100644 --- a/crates/ui-egui/src/chrome.rs +++ b/crates/ui-egui/src/chrome.rs @@ -380,15 +380,17 @@ pub fn start_page(app: &mut CadApp, ui: &mut egui::Ui) { let left = Rect::from_min_size(r.min, vec2(300.0, r.height())); p.rect_filled(left, 0.0, t.chrome_dark); p.rect_filled(Rect::from_min_max(pos2(left.right(), r.top()), r.max), 0.0, t.chrome); + // The DraftCraft logo beside the name and version. + crate::brand::paint(&p, Rect::from_min_size(pos2(left.left() + 30.0, left.top() + 56.0), vec2(56.0, 56.0))); p.text( - pos2(left.left() + 34.0, left.top() + 70.0), + pos2(left.left() + 98.0, left.top() + 70.0), egui::Align2::LEFT_CENTER, crate::tl!("DraftCraft"), egui::FontId::proportional(28.0), t.text, ); p.text( - pos2(left.left() + 34.0, left.top() + 98.0), + pos2(left.left() + 98.0, left.top() + 98.0), egui::Align2::LEFT_CENTER, crate::tf!("Version {version}", version = env!("CARGO_PKG_VERSION")), crate::theme::small(), diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index c5757663..6aa66f0b 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -328,14 +328,23 @@ fn about(ctx: &egui::Context, open: &mut bool) { .resizable(false) .collapsible(false) .show(ctx, |ui| { - ui.heading(crate::tl!("DraftCraft")); - ui.label(crate::tf!("Version {version}", version = env!("CARGO_PKG_VERSION"))); + ui.horizontal(|ui| { + crate::brand::show(ui, 64.0); + ui.vertical(|ui| { + ui.add_space(8.0); + ui.heading(crate::tl!("DraftCraft")); + ui.label(crate::tf!("Version {version}", version = env!("CARGO_PKG_VERSION"))); + }); + }); ui.label(crate::tl!("Computer-aided design and drafting: an open-source, clean-room CAD application written in pure Rust.")); ui.add_space(6.0); ui.hyperlink_to("github.com/SkryxDev/DraftCraft", "https://github.com/SkryxDev/DraftCraft"); ui.hyperlink_to("Discord", "https://discord.gg/YgRK8Eww9x"); ui.add_space(6.0); ui.label(RichText::new(crate::tl!("MIT OR Apache-2.0. Not affiliated with Autodesk, Inc.")).small().color(t.text_faint)); + ui.label( + RichText::new(crate::tl!("DraftCraft and the DraftCraft logo are trademarks of WithShalom Studios.")).small().color(t.text_faint), + ); }); } diff --git a/crates/ui-egui/src/i18n/it.tsv b/crates/ui-egui/src/i18n/it.tsv index 64e9f396..0df17ba9 100644 --- a/crates/ui-egui/src/i18n/it.tsv +++ b/crates/ui-egui/src/i18n/it.tsv @@ -517,6 +517,7 @@ menu Modify Edita Lock/Unlock Blocca/Sblocca Loft Loft MIT OR Apache-2.0. Not affiliated with Autodesk, Inc. MIT OR Apache-2.0. Non affiliata ad Autodesk, Inc. + DraftCraft and the DraftCraft logo are trademarks of WithShalom Studios. DraftCraft e il logo DraftCraft sono marchi di WithShalom Studios. MODEL MODELLO MText TestoM Magenta Magenta diff --git a/crates/ui-egui/src/i18n/zh.tsv b/crates/ui-egui/src/i18n/zh.tsv index 115057ae..968f0333 100644 --- a/crates/ui-egui/src/i18n/zh.tsv +++ b/crates/ui-egui/src/i18n/zh.tsv @@ -420,6 +420,7 @@ Lock/Unlock 锁定/解锁 Loft 放样 MIT OR Apache-2.0. Not affiliated with Autodesk, Inc. MIT 或 Apache-2.0。与 Autodesk, Inc. 无关。 + DraftCraft and the DraftCraft logo are trademarks of WithShalom Studios. DraftCraft 和 DraftCraft 标志是 WithShalom Studios 的商标。 MODEL 模型 MText 多行文字 Magenta 品红 diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 81099895..a8651bdd 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -22,6 +22,7 @@ pub mod aliasdlg; pub mod animation; pub mod autosave; pub mod bedit; +pub mod brand; pub mod canvas; pub mod capture; pub mod chrome; diff --git a/crates/ui-egui/src/ribbon.rs b/crates/ui-egui/src/ribbon.rs index bb6a92a1..1dc4a44e 100644 --- a/crates/ui-egui/src/ribbon.rs +++ b/crates/ui-egui/src/ribbon.rs @@ -910,13 +910,15 @@ struct Out { typed: Option, } -/// The application's own mark (not any other product's logo). +/// The application button: the DraftCraft logo ([`crate::brand`]) and the menu arrow. fn paint_app_button(p: &egui::Painter, r: Rect, hovered: bool) { - let fill = if hovered { Color32::from_rgb(0x2f, 0x7d, 0xf0) } else { Color32::from_rgb(0x1f, 0x6a, 0xd8) }; + let t = Tokens::get(); let mark = Rect::from_min_size(r.min, vec2(r.height(), r.height())); - p.rect_filled(mark, 3.0, fill); - p.text(mark.center(), Align2::CENTER_CENTER, "DC", FontId::proportional(r.height() * 0.5), Color32::WHITE); - arrow(p, pos2(mark.right() + 7.0, r.center().y), Tokens::get().text_dim); + if hovered { + p.rect_filled(r.expand(2.0), 4.0, t.hover); + } + crate::brand::paint(p, mark); + arrow(p, pos2(mark.right() + 7.0, r.center().y), t.text_dim); } /// Application bar, ribbon tabs and the active tab's panels. diff --git a/crates/ui-egui/src/window_frame.rs b/crates/ui-egui/src/window_frame.rs index acb05af1..87801a2a 100644 --- a/crates/ui-egui/src/window_frame.rs +++ b/crates/ui-egui/src/window_frame.rs @@ -8,7 +8,7 @@ //! `DRAFTCRAFT_TITLEBAR=app` draws this frame on any desktop (to try it). macOS keeps its own //! integrated title bar and Linux the desktop's. -use egui::{Align2, Color32, CursorIcon, FontId, Rect, ResizeDirection, Sense, Stroke, StrokeKind, ViewportCommand, pos2, vec2}; +use egui::{Color32, CursorIcon, FontId, Rect, ResizeDirection, Sense, Stroke, StrokeKind, ViewportCommand, pos2, vec2}; use crate::CadApp; use crate::theme::Tokens; @@ -76,30 +76,9 @@ pub fn title_bar(app: &mut CadApp, ui: &mut egui::Ui) { } } -/// The app icon, 64 px, drawn in the title bar. -const ICON_PNG: &[u8] = include_bytes!("../../../assets/app-icon/hicolor/64x64/apps/dev.skryx.draftcraft.png"); - -/// The app icon as a texture, decoded once per context. `None` if it doesn't decode. -fn icon_texture(ctx: &egui::Context) -> Option { - let id = egui::Id::unique("dc_window_icon"); - if let Some(tex) = ctx.data(|d| d.get_temp::(id)) { - return Some(tex); - } - let img = image::load_from_memory_with_format(ICON_PNG, image::ImageFormat::Png).ok()?.to_rgba8(); - let size = [usize::try_from(img.width()).ok()?, usize::try_from(img.height()).ok()?]; - let tex = ctx.load_texture("window-icon", egui::ColorImage::from_rgba_unmultiplied(size, img.as_raw()), egui::TextureOptions::LINEAR); - ctx.data_mut(|d| d.insert_temp(id, tex.clone())); - Some(tex) -} - -/// The app icon, small; a DC tile if the icon can't be drawn. +/// The app icon, small, drawn in the title bar. fn paint_logo(p: &egui::Painter, r: Rect) { - if let Some(tex) = icon_texture(p.ctx()) { - p.image(tex.id(), r, Rect::from_min_max(pos2(0.0, 0.0), pos2(1.0, 1.0)), Color32::WHITE); - return; - } - p.rect_filled(r, 4.0, Color32::from_rgb(0x0e, 0x34, 0x63)); - p.text(r.center(), Align2::CENTER_CENTER, "DC", FontId::proportional(r.height() * 0.5), Color32::WHITE); + crate::brand::paint(p, r); } fn caption_buttons(ui: &mut egui::Ui, area: Rect) {