Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

Pen: Alt breaks a handle while drawing, and close-drag pulls out the first anchor's handles (#3306) (#3314)

Valentin Kleinbd3be487859c
diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs
index b7676386b..1f5310388 100644
--- a/crates/ui-egui/src/canvas.rs
+++ b/crates/ui-egui/src/canvas.rs
@@ -4194,6 +4194,9 @@ fn tool_move(app: &mut PhotocraftApp, x: f64, y: f64, pressure: f32, mods: egui:
if tool.is_type() && app.drag.is_none() {
crate::type_tool::pointer_move(app, x, y);
}
+ if tool == Tool::Pen && mods.alt {
+ crate::vector_ui::pen_break_handle(app);
+ }
if tool == Tool::Pen {
crate::vector_ui::pen_move(app, x, y);
} else if tool == Tool::CurvaturePen {
@@ -4469,7 +4472,9 @@ pub fn tool_event(app: &mut PhotocraftApp, ev: ToolEvent, mods: egui::Modifiers)
}
match tool {
Tool::Pen => {
- crate::vector_ui::pen_down(app, x, y);
+ if !(mods.alt && crate::vector_ui::pen_grab_handle(app, x, y)) {
+ crate::vector_ui::pen_down(app, x, y);
+ }
return;
}
Tool::CurvaturePen => {
diff --git a/crates/ui-egui/src/i18n/cs.tsv b/crates/ui-egui/src/i18n/cs.tsv
index 2360fe1ed..94a46f6f2 100644
--- a/crates/ui-egui/src/i18n/cs.tsv
+++ b/crates/ui-egui/src/i18n/cs.tsv
@@ -915,6 +915,7 @@
Click to zoom in · {key}-click to zoom out · drag right/left to zoom in/out Kliknutím přiblížíte · {key}+kliknutím oddálíte · tažením doprava/doleva přiblížíte/oddálíte
Click with the Note tool to add a note. Poznámku přidáte kliknutím nástrojem poznámka.
Click: corner · Drag: smooth · Click first point: close · {key} finish · Esc cancel Kliknutí: roh · tažení: hladký bod · kliknutí na první bod: uzavřít · {key} dokončit · Esc zrušit
+ Click: corner · Drag: smooth · {alt}-drag: break handle · Click or drag first point: close · {key} finish · Esc cancel Kliknutí: roh · tažení: hladký bod · {alt}+tažení: rozdělit úchyt · kliknutí nebo tažení na první bod: uzavřít · {key} dokončit · Esc zrušit
Clip to layer below Oříznout podle vrstvy pod
Clipped Oříznuto
Close Style Options Zavřít možnosti stylu
diff --git a/crates/ui-egui/src/i18n/de.tsv b/crates/ui-egui/src/i18n/de.tsv
index c0ae347a5..7d6d9e8cf 100644
--- a/crates/ui-egui/src/i18n/de.tsv
+++ b/crates/ui-egui/src/i18n/de.tsv
@@ -893,6 +893,7 @@
Click to zoom in · {key}-click to zoom out · drag right/left to zoom in/out Klicken vergrößert · {key}-Klick verkleinert · nach rechts/links ziehen zoomt rein/raus
Click with the Note tool to add a note. Klicke mit dem Notiz-Werkzeug, um eine Notiz hinzuzufügen.
Click: corner · Drag: smooth · Click first point: close · {key} finish · Esc cancel Klick: Ecke · Ziehen: weich · Ersten Punkt klicken: schließen · {key} fertig · Esc abbrechen
+ Click: corner · Drag: smooth · {alt}-drag: break handle · Click or drag first point: close · {key} finish · Esc cancel Klick: Ecke · Ziehen: weich · {alt}-Ziehen: Griff trennen · Ersten Punkt klicken oder ziehen: schließen · {key} fertig · Esc abbrechen
Clip to layer below Auf darunterliegende Ebene begrenzen
Clipped Beschnitten
Close Style Options Stiloptionen schließen
diff --git a/crates/ui-egui/src/i18n/el.tsv b/crates/ui-egui/src/i18n/el.tsv
index d6423dba6..8556f6b5c 100644
--- a/crates/ui-egui/src/i18n/el.tsv
+++ b/crates/ui-egui/src/i18n/el.tsv
@@ -2124,6 +2124,7 @@
Click to sample the foreground colour · {key}-click for background Κλικ για δειγματοληψία χρώματος προσκηνίου · {key}-κλικ για φόντο
Click to zoom in · {key}-click to zoom out · drag right/left to zoom in/out Κλικ για μεγέθυνση · {key}-κλικ για σμίκρυνση · σύρσιμο δεξιά/αριστερά για αλλαγή μεγέθυνσης
Click: corner · Drag: smooth · Click first point: close · {key} finish · Esc cancel Κλικ: γωνία · Σύρσιμο: εξομάλυνση · Κλικ στο πρώτο σημείο: κλείσιμο · {key}: τέλος · Esc: ακύρωση
+ Click: corner · Drag: smooth · {alt}-drag: break handle · Click or drag first point: close · {key} finish · Esc cancel Κλικ: γωνία · Σύρσιμο: εξομάλυνση · {alt}+σύρσιμο: διάσπαση λαβής · Κλικ ή σύρσιμο στο πρώτο σημείο: κλείσιμο · {key}: τέλος · Esc: ακύρωση
Click: select anchor · Drag: move anchor, handle or segment · {shift}-click: add · {alt}-click: whole subpath Κλικ: επιλογή σημείου αγκύρωσης · Σύρσιμο: μετακίνηση σημείου, λαβής ή τμήματος · {shift}-κλικ: προσθήκη · {alt}-κλικ: ολόκληρη υποδιαδρομή
Clip to layer below Περικοπή στο υποκείμενο επίπεδο
Clipped Περικομμένο
diff --git a/crates/ui-egui/src/i18n/es.tsv b/crates/ui-egui/src/i18n/es.tsv
index 103f70af3..8d4327e8a 100644
--- a/crates/ui-egui/src/i18n/es.tsv
+++ b/crates/ui-egui/src/i18n/es.tsv
@@ -901,6 +901,7 @@
Click to zoom in · {key}-click to zoom out · drag right/left to zoom in/out Clic para acercar · {key}-clic para alejar · arrastre a la derecha/izquierda para acercar/alejar
Click with the Note tool to add a note. Haga clic con la herramienta Nota para añadir una nota.
Click: corner · Drag: smooth · Click first point: close · {key} finish · Esc cancel Clic: esquina · Arrastrar: suavizar · Clic en el primer punto: cerrar · {key}: terminar · Esc: cancelar
+ Click: corner · Drag: smooth · {alt}-drag: break handle · Click or drag first point: close · {key} finish · Esc cancel Clic: esquina · Arrastrar: suavizar · {alt}+arrastrar: romper manejador · Clic o arrastrar en el primer punto: cerrar · {key}: terminar · Esc: cancelar
Clip to layer below Recortar a la capa inferior
Clipped Recortado
Close Style Options Cerrar opciones de estilo
diff --git a/crates/ui-egui/src/i18n/fr.tsv b/crates/ui-egui/src/i18n/fr.tsv
index bab23e8c1..559c0989e 100644
--- a/crates/ui-egui/src/i18n/fr.tsv
+++ b/crates/ui-egui/src/i18n/fr.tsv
@@ -889,6 +889,7 @@
Click to zoom in · {key}-click to zoom out · drag right/left to zoom in/out Cliquez pour zoomer · {key}-clic pour dézoomer · faites glisser vers la droite/gauche pour zoomer/dézoomer
Click with the Note tool to add a note. Cliquez avec l'outil Note pour ajouter une note.
Click: corner · Drag: smooth · Click first point: close · {key} finish · Esc cancel Clic : angle · Glisser : lisse · Clic sur le premier point : fermer · {key} : terminer · Échap : annuler
+ Click: corner · Drag: smooth · {alt}-drag: break handle · Click or drag first point: close · {key} finish · Esc cancel Clic : angle · Glisser : lisse · {alt}+glisser : briser la poignée · Clic ou glisser sur le premier point : fermer · {key} : terminer · Échap : annuler
Clip to layer below Découper selon le calque inférieur
Clipped Découpé
Close Style Options Fermer les options de style
diff --git a/crates/ui-egui/src/i18n/id.tsv b/crates/ui-egui/src/i18n/id.tsv
index d4b4da499..094fdd1f4 100644
--- a/crates/ui-egui/src/i18n/id.tsv
+++ b/crates/ui-egui/src/i18n/id.tsv
@@ -883,6 +883,7 @@
Click to zoom in · {key}-click to zoom out · drag right/left to zoom in/out Klik untuk zoom in · {key}-klik untuk zoom out · seret kanan/kiri untuk zoom in/out
Click with the Note tool to add a note. Klik dengan alat Catatan untuk menambah catatan.
Click: corner · Drag: smooth · Click first point: close · {key} finish · Esc cancel Klik: sudut · Seret: halus · Klik titik pertama: tutup · {key} selesai · Esc batal
+ Click: corner · Drag: smooth · {alt}-drag: break handle · Click or drag first point: close · {key} finish · Esc cancel Klik: sudut · Seret: halus · {alt}+seret: pisahkan pegangan · Klik atau seret titik pertama: tutup · {key} selesai · Esc batal
Clip to layer below Klip ke layer di bawah
Clipped Terklip
Close Style Options Tutup Opsi Gaya
diff --git a/crates/ui-egui/src/i18n/it.tsv b/crates/ui-egui/src/i18n/it.tsv
index 89aa9ff90..fce4454fc 100644
--- a/crates/ui-egui/src/i18n/it.tsv
+++ b/crates/ui-egui/src/i18n/it.tsv
@@ -900,6 +900,7 @@
Click to zoom in · {key}-click to zoom out · drag right/left to zoom in/out Click per ingrandire · {key}-click per ridurre · trascina dx/sx per zoom
Click with the Note tool to add a note. Fai click con lo strumento Nota per aggiungere una nota.
Click: corner · Drag: smooth · Click first point: close · {key} finish · Esc cancel Click: angolo · Trascina: morbido · Click primo punto: chiudi · {key} termina · Esc annulla
+ Click: corner · Drag: smooth · {alt}-drag: break handle · Click or drag first point: close · {key} finish · Esc cancel Click: angolo · Trascina: morbido · {alt}+trascina: spezza maniglia · Click o trascina sul primo punto: chiudi · {key} termina · Esc annulla
Clip to layer below Ritaglia al livello sotto
Clipped Ritagliato
Close Style Options Chiudi opzioni stile
diff --git a/crates/ui-egui/src/i18n/ja.tsv b/crates/ui-egui/src/i18n/ja.tsv
index 6a9ae4e33..13de62b97 100644
--- a/crates/ui-egui/src/i18n/ja.tsv
+++ b/crates/ui-egui/src/i18n/ja.tsv
@@ -902,6 +902,7 @@
Click to zoom in · {key}-click to zoom out · drag right/left to zoom in/out クリックで拡大 · {key}+クリックで縮小 · 右/左にドラッグで拡大/縮小
Click with the Note tool to add a note. 注釈ツールでクリックすると注釈を追加できます。
Click: corner · Drag: smooth · Click first point: close · {key} finish · Esc cancel クリック: 角 · ドラッグ: 滑らか · 最初の点をクリック: 閉じる · {key} 完了 · Esc キャンセル
+ Click: corner · Drag: smooth · {alt}-drag: break handle · Click or drag first point: close · {key} finish · Esc cancel クリック: 角 · ドラッグ: 滑らか · {alt}+ドラッグ: ハンドルを分割 · 最初の点をクリックまたはドラッグ: 閉じる · {key} 完了 · Esc キャンセル
Clip to layer below 下のレイヤーでクリッピング
Clipped クリッピング済み
Close Style Options スタイルオプションを閉じる
diff --git a/crates/ui-egui/src/i18n/ko.tsv b/crates/ui-egui/src/i18n/ko.tsv
index 3e7c6c246..735241f8a 100644
--- a/crates/ui-egui/src/i18n/ko.tsv
+++ b/crates/ui-egui/src/i18n/ko.tsv
@@ -875,6 +875,7 @@
Click to zoom in · {key}-click to zoom out · drag right/left to zoom in/out 클릭하여 확대 · {key} 키를 누른 채 클릭하여 축소 · 오른쪽/왼쪽으로 드래그하여 확대/축소
Click with the Note tool to add a note. 메모 도구로 클릭하여 메모를 추가하세요.
Click: corner · Drag: smooth · Click first point: close · {key} finish · Esc cancel 클릭: 모서리 · 드래그: 곡선 · 첫 점 클릭: 닫기 · {key}: 완료 · Esc: 취소
+ Click: corner · Drag: smooth · {alt}-drag: break handle · Click or drag first point: close · {key} finish · Esc cancel 클릭: 모서리 · 드래그: 곡선 · {alt}+드래그: 핸들 분리 · 첫 점 클릭 또는 드래그: 닫기 · {key}: 완료 · Esc: 취소
Clip to layer below 아래 레이어에 클리핑
Clipped 클리핑됨
Close Style Options 스타일 옵션 닫기
diff --git a/crates/ui-egui/src/i18n/nl.tsv b/crates/ui-egui/src/i18n/nl.tsv
index e300169af..d85de7216 100644
--- a/crates/ui-egui/src/i18n/nl.tsv
+++ b/crates/ui-egui/src/i18n/nl.tsv
@@ -883,6 +883,7 @@
Click to zoom in · {key}-click to zoom out · drag right/left to zoom in/out Klik om in te zoomen · {key}-klik om uit te zoomen · sleep naar rechts/links om in/uit te zoomen
Click with the Note tool to add a note. Klik met het notitiegereedschap om een notitie toe te voegen.
Click: corner · Drag: smooth · Click first point: close · {key} finish · Esc cancel Klik: hoek · Slepen: vloeiend · Klik op eerste punt: sluiten · {key} voltooien · Esc annuleren
+ Click: corner · Drag: smooth · {alt}-drag: break handle · Click or drag first point: close · {key} finish · Esc cancel Klik: hoek · Slepen: vloeiend · {alt}-slepen: greep breken · Klik of sleep op eerste punt: sluiten · {key} voltooien · Esc annuleren
Clip to layer below Uitknippen naar laag eronder
Clipped Uitgeknipt
Close Style Options Stijlopties sluiten
diff --git a/crates/ui-egui/src/i18n/pl.tsv b/crates/ui-egui/src/i18n/pl.tsv
index a651de28a..2fdfa368d 100644
--- a/crates/ui-egui/src/i18n/pl.tsv
+++ b/crates/ui-egui/src/i18n/pl.tsv
@@ -899,6 +899,7 @@
Click to zoom in · {key}-click to zoom out · drag right/left to zoom in/out Kliknij, aby powiększyć · kliknij z {key}, aby pomniejszyć · przeciągnij w prawo/lewo, aby powiększyć/pomniejszyć
Click with the Note tool to add a note. Kliknij narzędziem Notatka, aby dodać notatkę.
Click: corner · Drag: smooth · Click first point: close · {key} finish · Esc cancel Klik: narożnik · Przeciągnięcie: gładki · Klik w pierwszy punkt: zamknij · {key} zakończ · Esc anuluj
+ Click: corner · Drag: smooth · {alt}-drag: break handle · Click or drag first point: close · {key} finish · Esc cancel Klik: narożnik · Przeciągnięcie: gładki · {alt}+przeciągnięcie: rozdziel uchwyt · Klik lub przeciągnięcie pierwszego punktu: zamknij · {key} zakończ · Esc anuluj
Clip to layer below Przytnij do warstwy poniżej
Clipped Przycięta
Close Style Options Zamknij opcje stylu
diff --git a/crates/ui-egui/src/i18n/pt-br.tsv b/crates/ui-egui/src/i18n/pt-br.tsv
index 7223b18ba..d0289601a 100644
--- a/crates/ui-egui/src/i18n/pt-br.tsv
+++ b/crates/ui-egui/src/i18n/pt-br.tsv
@@ -885,6 +885,7 @@
Click to zoom in · {key}-click to zoom out · drag right/left to zoom in/out Clique para aumentar o zoom · {key}-clique para diminuir · arraste para a direita/esquerda para aumentar/diminuir
Click with the Note tool to add a note. Clique com a ferramenta Anotação para adicionar uma anotação.
Click: corner · Drag: smooth · Click first point: close · {key} finish · Esc cancel Clique: canto · Arrastar: suave · Clique no primeiro ponto: fechar · {key}: concluir · Esc: cancelar
+ Click: corner · Drag: smooth · {alt}-drag: break handle · Click or drag first point: close · {key} finish · Esc cancel Clique: canto · Arrastar: suave · {alt}+arrastar: quebrar alça · Clique ou arraste no primeiro ponto: fechar · {key}: concluir · Esc: cancelar
Clip to layer below Recortar na camada abaixo
Clipped Recortado
Close Style Options Fechar opções de estilo
diff --git a/crates/ui-egui/src/i18n/ru.tsv b/crates/ui-egui/src/i18n/ru.tsv
index 3a7309bcd..998678c04 100644
--- a/crates/ui-egui/src/i18n/ru.tsv
+++ b/crates/ui-egui/src/i18n/ru.tsv
@@ -1516,6 +1516,7 @@
Click to add a point · drag off or {key}-click or Delete to remove Щёлкните, чтобы добавить точку · уведите или {key}-клик, либо Delete — удалить
Click to apply, {key}-click to clear overrides, double-click for Style Options Щёлкните, чтобы применить · {key}-клик сбрасывает переопределения · двойной клик — параметры стиля
Click: corner · Drag: smooth · Click first point: close · {key} finish · Esc cancel Клик: угол · перетаскивание: гладкая · клик по первой точке: замкнуть · {key} завершить · Esc отмена
+ Click: corner · Drag: smooth · {alt}-drag: break handle · Click or drag first point: close · {key} finish · Esc cancel Клик: угол · перетаскивание: гладкая · {alt}+перетаскивание: разбить маркер · клик или перетаскивание первой точки: замкнуть · {key} завершить · Esc отмена
Commit Perspective Warp ({key}) Принять перспективную деформацию ({key})
Commit Puppet Warp ({key}) Принять кукольную деформацию ({key})
Commit any current edits ({key}) Принять все текущие правки ({key})
diff --git a/crates/ui-egui/src/i18n/uk.tsv b/crates/ui-egui/src/i18n/uk.tsv
index 0ec4edd09..eaf6d1df9 100644
--- a/crates/ui-egui/src/i18n/uk.tsv
+++ b/crates/ui-egui/src/i18n/uk.tsv
@@ -1497,6 +1497,7 @@
Click to add a point · drag off or {key}-click or Delete to remove Клацніть, щоб додати точку · перетягніть за межі, натисніть {key} і клацніть або натисніть Delete, щоб вилучити
Click to apply, {key}-click to clear overrides, double-click for Style Options Клацніть, щоб застосувати, {key}+клацання, щоб очистити перевизначення, подвійне клацання для параметрів стилю
Click: corner · Drag: smooth · Click first point: close · {key} finish · Esc cancel Клацання: кут · Перетягування: плавна точка · Клацання першої точки: замкнути · {key}: завершити · Esc: скасувати
+ Click: corner · Drag: smooth · {alt}-drag: break handle · Click or drag first point: close · {key} finish · Esc cancel Клацання: кут · Перетягування: плавна точка · {alt}+перетягування: розбити маркер · Клацання або перетягування першої точки: замкнути · {key}: завершити · Esc: скасувати
Commit Perspective Warp ({key}) Підтвердити перспективну деформацію ({key})
Commit Puppet Warp ({key}) Підтвердити маріонеткову деформацію ({key})
Commit any current edits ({key}) Підтвердити поточні зміни ({key})
diff --git a/crates/ui-egui/src/i18n/zh-hans.tsv b/crates/ui-egui/src/i18n/zh-hans.tsv
index 90753bc24..0b8c594e5 100644
--- a/crates/ui-egui/src/i18n/zh-hans.tsv
+++ b/crates/ui-egui/src/i18n/zh-hans.tsv
@@ -2083,6 +2083,7 @@ cameraRaw Blending 混合
Click to apply, {key}-click to clear overrides, double-click for Style Options 单击应用,按 {key} 单击清除覆盖设置,双击打开样式选项
Click to zoom in · {key}-click to zoom out · drag right/left to zoom in/out 单击放大 · 按 {key} 单击缩小 · 向右或向左拖动以放大或缩小
Click: corner · Drag: smooth · Click first point: close · {key} finish · Esc cancel 单击:角点 · 拖动:平滑点 · 单击起点:闭合 · {key} 完成 · Esc 取消
+ Click: corner · Drag: smooth · {alt}-drag: break handle · Click or drag first point: close · {key} finish · Esc cancel 单击:角点 · 拖动:平滑点 · {alt}+拖动:断开手柄 · 单击或拖动起点:闭合 · {key} 完成 · Esc 取消
Commit Perspective Warp ({key}) 应用透视变形({key})
Commit Puppet Warp ({key}) 应用操控变形({key})
Commit any current edits ({key}) 应用当前所有编辑({key})
diff --git a/crates/ui-egui/src/i18n/zh-hant.tsv b/crates/ui-egui/src/i18n/zh-hant.tsv
index 3dffcbc3e..338897961 100644
--- a/crates/ui-egui/src/i18n/zh-hant.tsv
+++ b/crates/ui-egui/src/i18n/zh-hant.tsv
@@ -906,6 +906,7 @@
Click to zoom in · {key}-click to zoom out · drag right/left to zoom in/out 按一下放大 · {key}+按一下縮小 · 向右/向左拖曳以放大/縮小
Click with the Note tool to add a note. 使用註解工具按一下以新增註解。
Click: corner · Drag: smooth · Click first point: close · {key} finish · Esc cancel 按一下:轉角 · 拖曳:平滑 · 按一下第一點:閉合 · {key} 完成 · Esc 取消
+ Click: corner · Drag: smooth · {alt}-drag: break handle · Click or drag first point: close · {key} finish · Esc cancel 按一下:轉角 · 拖曳:平滑 · {alt}+拖曳:分離控制點 · 按一下或拖曳第一點:閉合 · {key} 完成 · Esc 取消
Clip to layer below 剪裁至下方圖層
Clipped 已剪裁
Close Style Options 關閉樣式選項
diff --git a/crates/ui-egui/src/pen_draw_tests.rs b/crates/ui-egui/src/pen_draw_tests.rs
new file mode 100644
index 000000000..229d69995
--- /dev/null
+++ b/crates/ui-egui/src/pen_draw_tests.rs
@@ -0,0 +1,151 @@
+//! The Pen's modifiers while drawing, through the real canvas (#3306): ⌥/Alt breaks the handle
+//! being pulled out and grabs the last anchor's outgoing handle alone, and dragging on the first
+//! anchor closes the path with that anchor's handles pulled out.
+
+use egui::{Key, Modifiers, PointerButton, Pos2, vec2};
+use egui_kittest::Harness;
+use serde_json::json;
+
+use crate::PhotocraftApp;
+use crate::canvas::ViewXform;
+use crate::state::Tool;
+
+fn harness() -> Harness<'static, PhotocraftApp> {
+ let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
+ app.run("file.new", json!({"width": 200, "height": 150})).unwrap();
+ app.sync_views();
+ app.ui.tool = Tool::Pen;
+ let mut h = Harness::builder().with_size(vec2(900.0, 600.0)).build_ui_state(
+ |ui, app: &mut PhotocraftApp| {
+ let ctx = ui.ctx().clone();
+ if !ctx.fonts(|f| f.families().contains(&egui::FontFamily::Name("medium".into()))) {
+ return;
+ }
+ crate::shortcuts::handle(app, &ctx);
+ egui::CentralPanel::default().show(ui, |ui| crate::canvas::document_area(app, ui));
+ },
+ app,
+ );
+ PhotocraftApp::setup_context(&h.ctx, crate::theme::ThemeKind::ALL[0]);
+ h.run_steps(4);
+ let v = &mut h.state_mut().ui.views[0];
+ v.zoom = 1.0;
+ v.center = [100.0, 75.0];
+ v.fit_pending = false;
+ h.run_steps(2);
+ h
+}
+
+fn screen(h: &Harness<'static, PhotocraftApp>, p: [f32; 2]) -> Pos2 {
+ let app = h.state();
+ let v = &app.ui.views[0];
+ let xf = ViewXform {
+ rect: crate::rulers::content_rect(app, app.last_canvas_rect),
+ zoom: v.zoom,
+ center: v.center,
+ flip: app.ui.view.flip_horizontal,
+ rotation: v.rotation,
+ aspect: app.ui.view.display_aspect(),
+ };
+ xf.to_screen(p[0], p[1])
+}
+
+fn mods(h: &mut Harness<'static, PhotocraftApp>, m: Modifiers) {
+ h.event(egui::Event::ModifiersChanged(m));
+ h.run_steps(1);
+}
+
+fn button(h: &mut Harness<'static, PhotocraftApp>, p: Pos2, down: bool, m: Modifiers) {
+ h.event(egui::Event::PointerButton { pos: p, button: PointerButton::Primary, pressed: down, modifiers: m });
+ h.run_steps(1);
+}
+
+fn move_to(h: &mut Harness<'static, PhotocraftApp>, from: [f32; 2], to: [f32; 2]) {
+ for i in 1..=6 {
+ let t = i as f32 / 6.0;
+ let q = screen(h, [from[0] + (to[0] - from[0]) * t, from[1] + (to[1] - from[1]) * t]);
+ h.event(egui::Event::PointerMoved(q));
+ h.run_steps(1);
+ }
+}
+
+/// A drag from `pts[0]` through the other points; `alt_from` is the index of the point from
+/// which ⌥/Alt is held (`Some(0)`: before the press).
+fn drag(h: &mut Harness<'static, PhotocraftApp>, pts: &[[f32; 2]], alt_from: Option<usize>) {
+ let held = |i: usize| if alt_from.is_some_and(|a| i >= a) { Modifiers::ALT } else { Modifiers::NONE };
+ let p = screen(h, pts[0]);
+ mods(h, held(0));
+ h.event(egui::Event::PointerMoved(p));
+ h.run_steps(1);
+ button(h, p, true, held(0));
+ for (i, w) in pts.windows(2).enumerate() {
+ mods(h, held(i + 1));
+ move_to(h, w[0], w[1]);
+ }
+ let end = *pts.last().unwrap();
+ button(h, screen(h, end), false, held(pts.len() - 1));
+ mods(h, Modifiers::NONE);
+ h.run_steps(1);
+}
+
+fn click(h: &mut Harness<'static, PhotocraftApp>, p: [f32; 2]) {
+ drag(h, &[p], None);
+}
+
+fn near(a: [f64; 2], b: [f64; 2]) -> bool {
+ (a[0] - b[0]).abs() < 0.05 && (a[1] - b[1]).abs() < 0.05
+}
+
+#[test]
+fn alt_breaks_the_handle_being_dragged_and_grabs_the_last_outgoing_handle() {
+ let mut h = harness();
+ click(&mut h, [20.0, 20.0]);
+ // Drag out a smooth anchor, then hold ⌥ halfway: the incoming handle stays where it was.
+ drag(&mut h, &[[100.0, 20.0], [120.0, 40.0], [100.0, 60.0]], Some(2));
+ let pen = h.state().ui.pen.clone().unwrap();
+ let k = pen.knots[1];
+ assert!(near(k[1], [80.0, 0.0]), "incoming handle stayed put: {k:?}");
+ assert!(near(k[2], [100.0, 60.0]), "outgoing handle followed the pointer: {k:?}");
+
+ // ⌥-drag the outgoing handle's end: it turns alone and no anchor is added.
+ drag(&mut h, &[[100.0, 60.0], [140.0, 20.0]], Some(0));
+ let pen = h.state().ui.pen.clone().unwrap();
+ assert_eq!(pen.knots.len(), 2, "no new anchor on the handle");
+ assert!(near(pen.knots[1][1], [80.0, 0.0]) && near(pen.knots[1][2], [140.0, 20.0]), "{:?}", pen.knots[1]);
+
+ click(&mut h, [150.0, 120.0]);
+ h.key_press(Key::Enter);
+ h.run_steps(2);
+ let doc = &h.state().session.active().unwrap().doc;
+ let k = &doc.work_path.as_ref().unwrap().subpaths[0].knots[1];
+ assert!(!k.smooth, "the broken handle is a cusp in the work path");
+ assert!(near([k.out_ctrl.x, k.out_ctrl.y], [140.0, 20.0]));
+}
+
+#[test]
+fn dragging_on_the_first_anchor_closes_with_its_handles_in_one_step() {
+ let mut h = harness();
+ let before = h.state().session.active().unwrap().history.past_len();
+ for p in [[20.0, 20.0], [120.0, 20.0], [120.0, 100.0]] {
+ click(&mut h, p);
+ }
+ drag(&mut h, &[[20.0, 20.0], [40.0, 0.0]], None);
+ assert!(h.state().ui.pen.is_none(), "the path is finished");
+ let st = h.state().session.active().unwrap();
+ assert_eq!(st.history.past_len(), before + 1, "one History step");
+ let sp = &st.doc.work_path.as_ref().unwrap().subpaths[0];
+ assert!(sp.closed && sp.knots.len() == 3, "closed, without an extra anchor: {sp:?}");
+ let k = &sp.knots[0];
+ assert!(near([k.in_ctrl.x, k.in_ctrl.y], [0.0, 40.0]) && near([k.out_ctrl.x, k.out_ctrl.y], [40.0, 0.0]), "{k:?}");
+ assert!(k.smooth);
+
+ // A plain click on a smooth first anchor closes without touching its handles.
+ drag(&mut h, &[[20.0, 20.0], [40.0, 20.0]], None);
+ click(&mut h, [120.0, 20.0]);
+ click(&mut h, [120.0, 100.0]);
+ click(&mut h, [20.0, 20.0]);
+ let sp = h.state().session.active().unwrap().doc.work_path.clone().unwrap().subpaths.remove(0);
+ let k = &sp.knots[0];
+ assert!(sp.closed && sp.knots.len() == 3);
+ assert!(near([k.in_ctrl.x, k.in_ctrl.y], [0.0, 20.0]) && near([k.out_ctrl.x, k.out_ctrl.y], [40.0, 20.0]), "{k:?}");
+}
diff --git a/crates/ui-egui/src/vector_ui.rs b/crates/ui-egui/src/vector_ui.rs
index 22ecf1bd2..1487ac787 100644
--- a/crates/ui-egui/src/vector_ui.rs
+++ b/crates/ui-egui/src/vector_ui.rs
@@ -179,6 +179,11 @@ pub fn draw_shape_preview(app: &PhotocraftApp, painter: &egui::Painter, xf: &Vie
// Pen
fn pen_to_json(pen: &PenPath, closed: bool) -> Value {
+ let folded = fold_close(pen);
+ let (pen, closed) = match &folded {
+ Some(p) => (p, true),
+ None => (pen, closed),
+ };
json!({"subpaths": [{"closed": closed, "knots": pen.knots.iter().enumerate().map(|(i, k)| json!({"anchor": k[0], "in": k[1], "out": k[2], "smooth": !pen.unlinked.contains(&i) && (k[1] != k[0] || k[2] != k[0])})).collect::<Vec<_>>()}]})
}
@@ -191,7 +196,11 @@ pub fn pen_down(app: &mut PhotocraftApp, x: f64, y: f64) {
&& pen.knots.len() >= 2
&& (first[0] - x).hypot(first[1] - y) < tol
{
- pen_commit(app, true);
+ // Pressing the first anchor closes the path on release. Until then a stand-in for it
+ // takes the drag, which pulls out that anchor's handles (close-drag, #3306).
+ pen.knots.push([first; 3]);
+ pen.dragging = true;
+ pen.adjusting_last = false;
return;
}
// Clicking the last anchor breaks its outgoing handle without throwing away the incoming
@@ -250,10 +259,76 @@ pub fn pen_undo_last_point(app: &mut PhotocraftApp) -> bool {
}
pub fn pen_up(app: &mut PhotocraftApp) {
- if let Some(pen) = app.ui.pen.as_mut() {
- pen.dragging = false;
- pen.adjusting_last = false;
+ let jitter = 2.0 / f64::from(app.point_zoom().max(0.01));
+ let Some(pen) = app.ui.pen.as_mut() else { return };
+ pen.dragging = false;
+ pen.adjusting_last = false;
+ if closing(pen) {
+ // A click on the first anchor closes the path and leaves that anchor's handles alone.
+ if let Some(k) = pen.knots.last_mut()
+ && (k[2][0] - k[0][0]).hypot(k[2][1] - k[0][1]) < jitter
+ {
+ k[1] = k[0];
+ k[2] = k[0];
+ }
+ pen_commit(app, true);
+ }
+}
+
+/// ⌥/Alt during a Pen drag breaks the pair of handles being pulled out: from then on only the
+/// outgoing handle follows the pointer and the incoming curve stays as it is (#3306).
+pub fn pen_break_handle(app: &mut PhotocraftApp) {
+ let Some(pen) = app.ui.pen.as_mut().filter(|p| p.dragging && !p.adjusting_last) else { return };
+ let Some(i) = pen.knots.len().checked_sub(1) else { return };
+ if !pen.unlinked.contains(&i) {
+ pen.unlinked.push(i);
}
+ pen.adjusting_last = true;
+}
+
+/// ⌥/Alt-press on the last anchor's outgoing handle while drawing grabs that handle alone: the
+/// drag turns it and the incoming curve stays put (#3306). False when the press misses it.
+pub fn pen_grab_handle(app: &mut PhotocraftApp, x: f64, y: f64) -> bool {
+ let tol = 6.0 / f64::from(app.point_zoom().max(0.01));
+ let Some(pen) = app.ui.pen.as_mut() else { return false };
+ let Some((i, k)) = pen.knots.len().checked_sub(1).zip(pen.knots.last()) else { return false };
+ let dist = |p: [f64; 2]| (p[0] - x).hypot(p[1] - y);
+ if k[2] == k[0] || dist(k[2]) >= tol || dist(k[2]) >= dist(k[0]) {
+ return false;
+ }
+ if !pen.unlinked.contains(&i) {
+ pen.unlinked.push(i);
+ }
+ pen.dragging = true;
+ pen.adjusting_last = true;
+ true
+}
+
+/// Is a close-drag in progress: does the path end in the stand-in for its first anchor?
+fn closing(pen: &PenPath) -> bool {
+ pen.knots.len() >= 3 && pen.knots.first().map(|k| k[0]) == pen.knots.last().map(|k| k[0])
+}
+
+/// The path with a close-drag's stand-in folded into the first knot, which takes the dragged
+/// handles (smooth, or a cusp after ⌥/Alt); `None` when no close-drag is in progress.
+fn fold_close(pen: &PenPath) -> Option<PenPath> {
+ if !closing(pen) {
+ return None;
+ }
+ let mut p = pen.clone();
+ let stand_in = p.knots.pop()?;
+ let broken = p.unlinked.contains(&p.knots.len());
+ p.unlinked.retain(|&i| i < p.knots.len());
+ if stand_in[1] != stand_in[0] || stand_in[2] != stand_in[0] {
+ let first = p.knots.first_mut()?;
+ first[1] = stand_in[1];
+ first[2] = stand_in[2];
+ p.unlinked.retain(|&i| i != 0);
+ if broken {
+ p.unlinked.push(0);
+ }
+ }
+ Some(p)
}
/// Finish the pen path: a work path (Path mode) or a new shape layer (Shape mode).
@@ -625,7 +700,16 @@ pub fn draw_overlay(app: &PhotocraftApp, painter: &egui::Painter, xf: &ViewXform
// Pen path in progress, with handles of the last knot and a rubber band to the pointer.
if let Some(pen) = &app.ui.pen {
let mut pts = Vec::new();
- for w in pen.knots.windows(2) {
+ // A close-drag shows the first segment bending with the handle being pulled out.
+ let mut knots = pen.knots.clone();
+ if closing(pen)
+ && let Some(&[a, _, out]) = pen.knots.last()
+ && out != a
+ && let Some(first) = knots.first_mut()
+ {
+ first[2] = out;
+ }
+ for w in knots.windows(2) {
for k in 0..=16 {
pts.push(to_scr(bezier(w[0][0], w[0][2], w[1][1], w[1][0], k as f64 / 16.0)));
}
@@ -731,7 +815,13 @@ pub fn options_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui, tool: Tool) -> bo
&[("key", &enter)],
),
),
- _ => lbl(ui, &crate::i18n::fmt(tl!("Click: corner · Drag: smooth · Click first point: close · {key} finish · Esc cancel"), &[("key", &enter)])),
+ _ => lbl(
+ ui,
+ &crate::i18n::fmt(
+ tl!("Click: corner · Drag: smooth · {alt}-drag: break handle · Click or drag first point: close · {key} finish · Esc cancel"),
+ &[("alt", &crate::shortcuts::pretty("Alt")), ("key", &enter)],
+ ),
+ ),
}
return true;
}
@@ -1560,6 +1650,7 @@ mod tests {
pen_move(&mut app, 140.0, 140.0); // smooth knot
pen_up(&mut app);
pen_down(&mut app, 20.5, 20.5); // click the first anchor: close
+ pen_up(&mut app);
assert!(app.ui.pen.is_none());
let wp = app.session.active().unwrap().doc.work_path.clone().unwrap();
assert!(wp.subpaths[0].closed && wp.subpaths[0].knots.len() == 3);
@@ -1629,6 +1720,7 @@ mod tests {
pen_up(&mut app);
}
pen_down(&mut app, 20.5, 20.5);
+ pen_up(&mut app);
assert_eq!(app.ui.selected_path.as_deref(), Some("work"));
let wp = app.session.active().unwrap().doc.work_path.clone().unwrap();
app.run("select.rect", json!({"x": 150, "y": 150, "width": 20, "height": 20})).unwrap();
@@ -1852,6 +1944,10 @@ mod tests {
#[path = "path_selection_tests.rs"]
mod path_selection_tests;
+#[cfg(test)]
+#[path = "pen_draw_tests.rs"]
+mod pen_draw_tests;
+
#[cfg(test)]
#[path = "vector_paint_tests.rs"]
mod paint_tests;
diff --git a/docs/scorecard.md b/docs/scorecard.md
index 93d4bdf9d..06c959740 100644
--- a/docs/scorecard.md
+++ b/docs/scorecard.md
@@ -154,7 +154,7 @@ Corpus floors (`crates/io/tests/corpus.rs`): the enforced minimums; the corpus t
| TOOL-214-7 | Content-Aware Scale through the Free Transform box with a live proxy preview | partial | [#214](https://github.com/storytold/photocraft/issues/214) | edit.contentAwareScale (edit_menu_cmds.rs:899) behind a parameter dialog |
| TOOL-214-8 | A measured ruler angle prefills Image Rotation > Arbitrary (0.01 deg) | done | [#214](https://github.com/storytold/photocraft/issues/214) | analysis_ui.rs: image.rotation.arbitrary opens seeded with the ruler angle and the direction that straightens it; arbitrary_rotation_starts_at_the_ruler_angle checks 5.7106 deg within 1e-3 and cw/ccw for three measured lines |
| TOOL-214-9 | Crop: W x H x Resolution with units, saved crop presets, Straighten in the options bar | done | [#214](https://github.com/storytold/photocraft/issues/214) | Ratio dropdown and fields, Straighten (TOOL-214-21); W x H x Resolution with units, built-in size presets and Front Image (crop_size.rs, image.crop targetWidth/targetHeight/resolution, #2443); New / Delete Crop Preset save and delete crop tool presets (crop_presets.rs, tool.presets.* with tool crop, persisted with the preferences) |
-| TOOL-214-10 | Pen: Alt breaks a handle, Shift 45 deg, Ctrl direct-selects, Backspace, close-drag handle | partial | [#214](https://github.com/storytold/photocraft/issues/214) | Ctrl/Cmd = Direct Selection and Alt = Convert Point on existing paths (direct_select.rs, #790); no Shift 45 deg, Backspace or Alt while drawing |
+| TOOL-214-10 | Pen: Alt breaks a handle, Shift 45 deg, Ctrl direct-selects, Backspace, close-drag handle | partial | [#214](https://github.com/storytold/photocraft/issues/214) | Ctrl/Cmd = Direct Selection and Alt = Convert Point on existing paths (direct_select.rs, #790); Backspace/Delete retracts the last point while drawing (#1466); Alt during a drag breaks the handle pair, Alt-drag turns the last anchor's outgoing handle alone, and dragging on the first anchor closes with that anchor's handles (vector_ui.rs, #3306); no Shift 45 deg |
| TOOL-214-11 | Stroke Path dialog: pick any brush-based tool, Simulate Pressure | partial | [#214](https://github.com/storytold/photocraft/issues/214) | path.stroke brush, pencil, eraser (vector_cmds.rs:1170); brush-only button, no dialog |
| TOOL-214-12 | Shapes: on-canvas corner radius handles, shape feather, selection to shape with tolerance | partial | [#214](https://github.com/storytold/photocraft/issues/214) | select.convertToShape with tolerance (vector_cmds.rs:1256); radius as a field only |
| TOOL-214-13 | Mask Properties: Density and Feather controls | partial | [#214](https://github.com/storytold/photocraft/issues/214) | Vector-mask density/feather in the engine (vector_cmds.rs:948); no UI controls |
diff --git a/scorecard/tools.toml b/scorecard/tools.toml
index ba5620420..51e377192 100644
--- a/scorecard/tools.toml
+++ b/scorecard/tools.toml
@@ -178,7 +178,7 @@ id = "TOOL-214-10"
target = "Pen: Alt breaks a handle, Shift 45 deg, Ctrl direct-selects, Backspace, close-drag handle"
status = "partial"
issue = 214
-note = "Ctrl/Cmd = Direct Selection and Alt = Convert Point on existing paths (direct_select.rs, #790); no Shift 45 deg, Backspace or Alt while drawing"
+note = "Ctrl/Cmd = Direct Selection and Alt = Convert Point on existing paths (direct_select.rs, #790); Backspace/Delete retracts the last point while drawing (#1466); Alt during a drag breaks the handle pair, Alt-drag turns the last anchor's outgoing handle alone, and dragging on the first anchor closes with that anchor's handles (vector_ui.rs, #3306); no Shift 45 deg"
[[item]]
id = "TOOL-214-11"