Merge pull request #737 from vangel76/gap-copy-frame-clipboard
#730: Composition ▸ Copy Frame to Clipboard
This commit is contained in:
@@ -400,6 +400,7 @@ const SIMPLIFIED_CHINESE: &[(&str, &str, &str)] = &[
|
||||
("comp.saveFrameAs", "File...", "文件..."),
|
||||
("comp.saveFrameAsPsd", "Photoshop Layers...", "Photoshop 图层..."),
|
||||
("comp.saveFrameAsExr", "ProEXR...", "ProEXR..."),
|
||||
("comp.copyFrame", "Copy Frame to Clipboard", "将帧复制到剪贴板"),
|
||||
("render.preRender", "Pre-render...", "预渲染..."),
|
||||
("render.saveCurrentPreview", "Save Current Preview...", "保存当前预览..."),
|
||||
("comp.openInEssentialGraphics", "Open in Essential Graphics", "在基本图形中打开"),
|
||||
@@ -1024,6 +1025,7 @@ const TRADITIONAL_CHINESE: &[(&str, &str, &str)] = &[
|
||||
("comp.saveFrameAs", "File...", "檔案..."),
|
||||
("comp.saveFrameAsPsd", "Photoshop Layers...", "Photoshop 圖層..."),
|
||||
("comp.saveFrameAsExr", "ProEXR...", "ProEXR..."),
|
||||
("comp.copyFrame", "Copy Frame to Clipboard", "將影格拷貝到剪貼簿"),
|
||||
("render.preRender", "Pre-render...", "預先渲染..."),
|
||||
("render.saveCurrentPreview", "Save Current Preview...", "儲存目前預覽..."),
|
||||
("comp.openInEssentialGraphics", "Open in Essential Graphics", "在基本圖形中開啟"),
|
||||
@@ -1645,6 +1647,7 @@ const JAPANESE: &[(&str, &str, &str)] = &[
|
||||
("comp.saveFrameAs", "File...", "ファイル..."),
|
||||
("comp.saveFrameAsPsd", "Photoshop Layers...", "Photoshopレイヤー..."),
|
||||
("comp.saveFrameAsExr", "ProEXR...", "ProEXR..."),
|
||||
("comp.copyFrame", "Copy Frame to Clipboard", "フレームをクリップボードにコピー"),
|
||||
("render.preRender", "Pre-render...", "プリレンダリング..."),
|
||||
("render.saveCurrentPreview", "Save Current Preview...", "現在のプレビューを保存..."),
|
||||
("comp.openInEssentialGraphics", "Open in Essential Graphics", "エッセンシャルグラフィックスで開く"),
|
||||
@@ -2269,6 +2272,7 @@ const UKRAINIAN: &[(&str, &str, &str)] = &[
|
||||
("comp.saveFrameAs", "File...", "Файл..."),
|
||||
("comp.saveFrameAsPsd", "Photoshop Layers...", "Шари Photoshop..."),
|
||||
("comp.saveFrameAsExr", "ProEXR...", "ProEXR..."),
|
||||
("comp.copyFrame", "Copy Frame to Clipboard", "Копіювати кадр у буфер обміну"),
|
||||
("render.preRender", "Pre-render...", "Попередній рендеринг..."),
|
||||
("render.saveCurrentPreview", "Save Current Preview...", "Зберегти поточний попередній перегляд..."),
|
||||
("comp.openInEssentialGraphics", "Open in Essential Graphics", "Відкрити в основній графіці"),
|
||||
@@ -2894,6 +2898,7 @@ const SPANISH: &[(&str, &str, &str)] = &[
|
||||
("comp.saveFrameAs", "File...", "Archivo..."),
|
||||
("comp.saveFrameAsPsd", "Photoshop Layers...", "Capas de Photoshop..."),
|
||||
("comp.saveFrameAsExr", "ProEXR...", "ProEXR..."),
|
||||
("comp.copyFrame", "Copy Frame to Clipboard", "Copiar fotograma al portapapeles"),
|
||||
("render.preRender", "Pre-render...", "Preprocesar..."),
|
||||
("render.saveCurrentPreview", "Save Current Preview...", "Guardar la previsualización actual..."),
|
||||
("comp.openInEssentialGraphics", "Open in Essential Graphics", "Abrir en Gráficos esenciales"),
|
||||
@@ -3517,6 +3522,7 @@ const PORTUGUESE: &[(&str, &str, &str)] = &[
|
||||
("comp.saveFrameAs", "File...", "Arquivo..."),
|
||||
("comp.saveFrameAsPsd", "Photoshop Layers...", "Camadas do Photoshop..."),
|
||||
("comp.saveFrameAsExr", "ProEXR...", "ProEXR..."),
|
||||
("comp.copyFrame", "Copy Frame to Clipboard", "Copiar quadro para a área de transferência"),
|
||||
("render.preRender", "Pre-render...", "Pré-renderização..."),
|
||||
("render.saveCurrentPreview", "Save Current Preview...", "Salvar pré-visualização atual..."),
|
||||
("comp.openInEssentialGraphics", "Open in Essential Graphics", "Abrir em Gráficos essenciais"),
|
||||
|
||||
@@ -1555,6 +1555,11 @@ impl EffectcraftApp {
|
||||
}
|
||||
}
|
||||
effectcraft_engine::Event::PurgeCaches => self.frames.clear(),
|
||||
effectcraft_engine::Event::CopyImage { width, height, rgba } => {
|
||||
if let Err(e) = copy_image(ctx, width, height, &rgba) {
|
||||
self.ui.status = e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1875,6 +1880,18 @@ pub(crate) fn tick_playback(app: &mut EffectcraftApp, ctx: &egui::Context, scale
|
||||
app.advance_playback(ctx, scale);
|
||||
}
|
||||
|
||||
/// Put `width` × `height` straight-alpha RGBA8 pixels on the system clipboard (Composition ▸ Copy
|
||||
/// Frame to Clipboard). The pixel count is checked first: egui's image constructor panics on a
|
||||
/// size that doesn't match its buffer.
|
||||
fn copy_image(ctx: &egui::Context, width: u32, height: u32, rgba: &[u8]) -> Result<(), String> {
|
||||
let (w, h) = (width as usize, height as usize);
|
||||
if w == 0 || h == 0 || w.checked_mul(h).and_then(|n| n.checked_mul(4)) != Some(rgba.len()) {
|
||||
return Err(format!("cannot copy a malformed {width}×{height} image to the clipboard"));
|
||||
}
|
||||
ctx.copy_image(egui::ColorImage::from_rgba_unmultiplied([w, h], rgba));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Maximize a first window that doesn't fit the screen, which fits it to the space beside the
|
||||
/// taskbar or dock. The 1680 × 1020 window on a smaller screen is only shrunk to the monitor's
|
||||
/// size, so with its title bar it ran under the taskbar and cut menus off at the bottom of the
|
||||
@@ -1908,6 +1925,55 @@ mod fit_window_tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod copy_frame_tests {
|
||||
use super::*;
|
||||
|
||||
fn copied(output: &egui::FullOutput) -> Vec<&egui::ColorImage> {
|
||||
output
|
||||
.platform_output
|
||||
.commands
|
||||
.iter()
|
||||
.filter_map(|c| match c {
|
||||
egui::OutputCommand::CopyImage(image) => Some(image),
|
||||
_ => None,
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Composition ▸ Copy Frame to Clipboard puts the rendered frame on the system clipboard.
|
||||
#[test]
|
||||
fn copy_frame_puts_the_frame_on_the_clipboard() {
|
||||
let mut session = Session::default();
|
||||
session.execute("comp.new", json!({"name": "Copy", "width": 8, "height": 6, "duration": 1})).unwrap();
|
||||
session.execute("layer.newSolid", json!({"color": "#ff0000"})).unwrap();
|
||||
let mut app = EffectcraftApp::new(session);
|
||||
let ctx = egui::Context::default();
|
||||
let mut output = ctx.run_ui(egui::RawInput::default(), |ui| {
|
||||
crate::menus::invoke(&mut app, ui.ctx(), "comp.copyFrame", json!({})).unwrap();
|
||||
app.handle_events(ui.ctx());
|
||||
});
|
||||
output.textures_delta.clear();
|
||||
let images = copied(&output);
|
||||
assert_eq!(images.len(), 1);
|
||||
assert_eq!(images[0].size, [8, 6]);
|
||||
assert!(images[0].pixels.iter().all(|p| *p == egui::Color32::from_rgb(255, 0, 0)));
|
||||
}
|
||||
|
||||
/// A malformed image never reaches egui's panicking constructor.
|
||||
#[test]
|
||||
fn a_malformed_image_is_an_error_not_a_crash() {
|
||||
let ctx = egui::Context::default();
|
||||
let mut output = ctx.run_ui(egui::RawInput::default(), |ui| {
|
||||
assert!(copy_image(ui.ctx(), 4, 4, &[0; 10]).is_err());
|
||||
assert!(copy_image(ui.ctx(), 0, 4, &[]).is_err());
|
||||
assert!(copy_image(ui.ctx(), u32::MAX, u32::MAX, &[0; 4]).is_err());
|
||||
});
|
||||
output.textures_delta.clear();
|
||||
assert!(copied(&output).is_empty());
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod gpu_failure_tests {
|
||||
use super::*;
|
||||
|
||||
@@ -1113,6 +1113,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
let context_layers: Vec<u64> =
|
||||
app.session.state.selected_layers.iter().filter(|id| comp.layer(**id).is_some_and(|l| !l.switches.locked)).map(|id| id.0).collect();
|
||||
let mut context_actions = Vec::new();
|
||||
let copy_frame = crate::i18n::label(app, "comp.copyFrame", "Copy Frame to Clipboard");
|
||||
resp.context_menu(|ui| {
|
||||
let hits = ui.data(|d| d.get_temp::<Vec<(u64, String)>>(menu_hits_id)).unwrap_or_default();
|
||||
if !hits.is_empty() {
|
||||
@@ -1133,6 +1134,11 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
} else {
|
||||
super::timeline::layer_menu(ui, &context_layers, &mut context_actions);
|
||||
}
|
||||
ui.separator();
|
||||
if ui.button(copy_frame).clicked() {
|
||||
context_actions.push(("comp.copyFrame".to_owned(), serde_json::json!({"comp": cid.0})));
|
||||
ui.close();
|
||||
}
|
||||
});
|
||||
for (id, params) in context_actions {
|
||||
if let Err(e) = crate::menus::invoke(app, &ctx, &id, params) {
|
||||
|
||||
Reference in New Issue
Block a user