Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions crates/ui-egui/src/brand.rs
Original file line number Diff line number Diff line change
@@ -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<egui::TextureHandle> {
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::<egui::TextureHandle>(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();
}
}
6 changes: 4 additions & 2 deletions crates/ui-egui/src/chrome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
13 changes: 11 additions & 2 deletions crates/ui-egui/src/dialogs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
);
});
}

Expand Down
1 change: 1 addition & 0 deletions crates/ui-egui/src/i18n/it.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions crates/ui-egui/src/i18n/zh.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -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 品红
Expand Down
1 change: 1 addition & 0 deletions crates/ui-egui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 7 additions & 5 deletions crates/ui-egui/src/ribbon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -910,13 +910,15 @@ struct Out {
typed: Option<String>,
}

/// 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.
Expand Down
27 changes: 3 additions & 24 deletions crates/ui-egui/src/window_frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<egui::TextureHandle> {
let id = egui::Id::unique("dc_window_icon");
if let Some(tex) = ctx.data(|d| d.get_temp::<egui::TextureHandle>(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) {
Expand Down