mirror of
https://github.com/storytold/texturecraft.git
synced 2026-11-30 10:03:56 +01:00
Layers: the R + click list comes before an armed point or focus pick, and its closing press paints nothing in 2D
This commit is contained in:
1 parent
9a188f4077
commit
4b2729ee71
3 files changed
+88
-6
No files matched your search
@@ -557,12 +557,13 @@ pub fn shortcuts(app: &mut TextureCraftApp, ctx: &egui::Context) {
|
||||
// The open list or export input handles the key
|
||||
} else if app.picking_color.is_some() && input.consume_key(Modifiers::NONE, Key::Escape) {
|
||||
app.picking_color = None;
|
||||
} else if escape_is_free && app.layer_pick_list.is_some() && input.consume_key(Modifiers::NONE, Key::Escape) {
|
||||
// The list opens over an armed point pick, so it closes first
|
||||
app.layer_pick_list = None;
|
||||
} else if point_pick_armed && input.consume_key(Modifiers::NONE, Key::Escape) {
|
||||
cancel_point_pick = true;
|
||||
} else if !escape_is_free {
|
||||
// The picker window handles the key
|
||||
} else if app.layer_pick_list.is_some() && input.consume_key(Modifiers::NONE, Key::Escape) {
|
||||
app.layer_pick_list = None;
|
||||
} else if app.properties_popup.is_some() && input.consume_key(Modifiers::NONE, Key::Escape) {
|
||||
app.properties_popup = None;
|
||||
} else if crate::rail_popup::is_visible(app) && input.consume_key(Modifiers::NONE, Key::Escape) {
|
||||
|
||||
@@ -920,14 +920,15 @@ fn view_3d(app: &mut TextureCraftApp, ui: &mut Ui, rect: Rect, sync: &mut Pendin
|
||||
crate::layer_pick_list::click(app, pointer, local(pointer), rect);
|
||||
}
|
||||
|
||||
// R + click and the list it opens come before an armed point or focus pick, including the press that closes the list
|
||||
let layer_pick_takes_click = r_held || crate::layer_pick_list::blocks_view_input(app);
|
||||
|
||||
// A 3D generator's armed point pick: a click sets the point there instead of painting
|
||||
let point_pick = crate::generator_point_pick::armed_on(ui.ctx(), &app.session);
|
||||
if let Some(pick) = point_pick {
|
||||
ui.ctx().set_cursor_icon(egui::CursorIcon::Crosshair);
|
||||
|
||||
// R + click still picks a layer while a pick is armed
|
||||
if !alt
|
||||
&& !r_held
|
||||
&& !layer_pick_takes_click
|
||||
&& response.clicked_by(PointerButton::Primary)
|
||||
&& let Some(pointer) = response.interact_pointer_pos()
|
||||
{
|
||||
@@ -947,7 +948,7 @@ fn view_3d(app: &mut TextureCraftApp, ui: &mut Ui, rect: Rect, sync: &mut Pendin
|
||||
if picking_focus_distance {
|
||||
ui.ctx().set_cursor_icon(egui::CursorIcon::Crosshair);
|
||||
if !alt
|
||||
&& !r_held
|
||||
&& !layer_pick_takes_click
|
||||
&& response.clicked_by(PointerButton::Primary)
|
||||
&& let Some(pointer) = response.interact_pointer_pos()
|
||||
{
|
||||
@@ -2319,6 +2320,7 @@ fn view_2d(app: &mut TextureCraftApp, ui: &mut Ui, rect: Rect, sync: &mut Pendin
|
||||
let painting = tool_acts(app)
|
||||
&& !projection_hint
|
||||
&& app.properties_popup.is_none()
|
||||
&& !crate::layer_pick_list::blocks_view_input(app)
|
||||
&& !crate::rail_popup::blocks_paint_input(app, ui.ctx())
|
||||
&& !crate::color_picker::blocks_view_press(ui.ctx())
|
||||
&& !alt
|
||||
|
||||
@@ -841,3 +841,82 @@ fn r_and_a_click_on_the_model_list_the_layers_there_and_a_row_selects_one_withou
|
||||
assert!(h.state().layer_pick_list.is_none(), "Escape closes the list");
|
||||
assert_eq!(h.state().session.selected_layer(), Some(upper), "and selects nothing");
|
||||
}
|
||||
|
||||
/// Two fills over the whole model, so R + click opens the list; returns the 3D view
|
||||
fn two_fills(h: &mut Harness<'_, TextureCraftApp>) -> egui::Rect {
|
||||
for name in ["Lower fill", "Upper fill"] {
|
||||
execute(&mut h.state_mut().session, "layer.add.fill", &json!({"name": name, "color": "#aa3322"})).unwrap();
|
||||
}
|
||||
h.run_steps(SETTLE_FRAMES);
|
||||
h.state().viewport_rect
|
||||
}
|
||||
|
||||
/// R + click at the middle of the 3D view
|
||||
fn open_pick_list(h: &mut Harness<'_, TextureCraftApp>) {
|
||||
let middle = h.state().viewport_rect.center();
|
||||
let key = |pressed| egui::Event::Key { key: egui::Key::R, physical_key: None, pressed, repeat: false, modifiers: egui::Modifiers::NONE };
|
||||
h.event(key(true));
|
||||
h.hover_at(middle);
|
||||
h.run_steps(1);
|
||||
click(h, middle);
|
||||
h.event(key(false));
|
||||
h.run_steps(SETTLE_FRAMES);
|
||||
assert!(h.state().layer_pick_list.is_some(), "the list is open");
|
||||
}
|
||||
|
||||
/// The list opened over an armed point pick is the innermost thing: Escape closes it first, and a press that closes it sets no point
|
||||
#[test]
|
||||
fn the_layer_pick_list_takes_escape_and_its_closing_press_before_an_armed_point_pick() {
|
||||
let (mut h, _) = harness();
|
||||
let view = two_fills(&mut h);
|
||||
execute(&mut h.state_mut().session, "mask.add.black", &Value::Null).unwrap();
|
||||
let effect = id(execute(&mut h.state_mut().session, "effect.add.generator", &json!({"generator": "3dDistance"})).unwrap(), "effect");
|
||||
h.run_steps(SETTLE_FRAMES);
|
||||
let generator = |h: &Harness<'_, TextureCraftApp>| h.state().session.doc.project.effect(LayerId(effect)).unwrap().1.kind.clone();
|
||||
let armed =
|
||||
|h: &Harness<'_, TextureCraftApp>| h.get_by_label("Pick 3D Position on the mesh").accesskit_node().toggled() == Some(egui::accesskit::Toggled::True);
|
||||
h.get_by_label("Pick 3D Position on the mesh").click();
|
||||
h.run_steps(SETTLE_FRAMES);
|
||||
assert!(armed(&h), "the pick is armed");
|
||||
let before = generator(&h);
|
||||
|
||||
open_pick_list(&mut h);
|
||||
h.key_press(egui::Key::Escape);
|
||||
h.run_steps(SETTLE_FRAMES);
|
||||
|
||||
assert!(h.state().layer_pick_list.is_none(), "Escape closes the list");
|
||||
assert!(armed(&h), "and leaves the point pick armed");
|
||||
|
||||
open_pick_list(&mut h);
|
||||
click(&mut h, view.center() - egui::vec2(60.0, 40.0));
|
||||
h.run_steps(SETTLE_FRAMES);
|
||||
|
||||
assert!(h.state().layer_pick_list.is_none(), "a press outside closes the list");
|
||||
assert_eq!(generator(&h), before, "and sets no point");
|
||||
assert!(armed(&h));
|
||||
}
|
||||
|
||||
/// In the split view, a press on the 2D view that closes the list paints nothing there
|
||||
#[test]
|
||||
fn a_press_on_the_2d_view_that_closes_the_layer_pick_list_does_not_paint() {
|
||||
let (mut h, _) = harness();
|
||||
two_fills(&mut h);
|
||||
execute(&mut h.state_mut().session, "layer.add.paint", &Value::Null).unwrap();
|
||||
h.state_mut().ui.layout = texturecraft_ui_egui::state::ViewLayout::Split;
|
||||
h.run_steps(SETTLE_FRAMES);
|
||||
let view = h.state().viewport_rect;
|
||||
let over_2d = egui::pos2(view.right() + view.width() * 0.5, view.center().y);
|
||||
let steps = h.state().session.history_labels().len();
|
||||
open_pick_list(&mut h);
|
||||
|
||||
click(&mut h, over_2d);
|
||||
h.run_steps(SETTLE_FRAMES);
|
||||
|
||||
assert!(h.state().layer_pick_list.is_none(), "the press closes the list");
|
||||
assert_eq!(h.state().session.history_labels().len(), steps, "and paints no stroke");
|
||||
|
||||
click(&mut h, over_2d);
|
||||
h.run_steps(SETTLE_FRAMES);
|
||||
|
||||
assert!(h.state().session.history_labels().len() > steps, "the next press paints there");
|
||||
}
|
||||
Reference in new issue
Block a user