mirror of
https://github.com/storytold/texturecraft.git
synced 2026-11-23 16:00:45 +01:00
2D view: draw the brush outline under the pointer while painting
Fixes #179 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9dc33d894e
commit
e0404360e4
2 files changed
+71
No files matched your search
@@ -1056,6 +1056,20 @@ fn view_2d(app: &mut TextureCraftApp, ui: &mut Ui, rect: Rect, sync: &mut Pendin
|
||||
painter.circle_stroke(hover, r, Stroke::new(1.0, Color32::from_white_alpha(200)));
|
||||
}
|
||||
}
|
||||
// Brush cursor: the stamp's size and hardness at the pointer, as in the 3D view.
|
||||
let cursor_mode = app.ui.mode == crate::state::Mode::Painting && !alt && !v_held;
|
||||
if cursor_mode
|
||||
&& !path_tool
|
||||
&& brush_tool(app.session.tool.tool)
|
||||
&& !resp.dragged_by(PointerButton::Middle)
|
||||
// While a Ctrl+drag changes the brush, its cursor stays where the drag began.
|
||||
&& let Some(hp) = if adjusting { ui.input(|i| i.pointer.press_origin()) } else { resp.hover_pos().or_else(|| resp.interact_pointer_pos()) }
|
||||
{
|
||||
// A UV brush stamp has a radius of twice the brush size, as in `continue_stroke_uv`.
|
||||
let r = (to(app.session.tool.brush.size * 2.0, 0.0).x - to(0.0, 0.0).x).abs().max(1.5);
|
||||
ui.ctx().set_cursor_icon(egui::CursorIcon::None);
|
||||
brush_cursor_2d(&painter, hp, r, app.session.tool.brush.hardness);
|
||||
}
|
||||
brush_readout(app, ui, &resp, adjusting);
|
||||
view_header(app, ui, rect, "v2d");
|
||||
axis_gizmo(ui, rect, app, true);
|
||||
@@ -1064,6 +1078,22 @@ fn view_2d(app: &mut TextureCraftApp, ui: &mut Ui, rect: Rect, sync: &mut Pendin
|
||||
let _ = (RichText::new(""), Channel::BaseColor);
|
||||
}
|
||||
|
||||
/// The brush outline (and its hardness ring) as screen circles around `c`, radius `r` in points.
|
||||
fn brush_cursor_2d(p: &egui::Painter, c: egui::Pos2, r: f32, hardness: f32) {
|
||||
p.circle_stroke(c, r, Stroke::new(2.5, Color32::from_black_alpha(140)));
|
||||
p.circle_stroke(c, r, Stroke::new(1.2, Color32::from_white_alpha(230)));
|
||||
if hardness > 0.05 {
|
||||
let inner: Vec<egui::Pos2> = (0..=48)
|
||||
.map(|k| {
|
||||
let a = k as f32 / 48.0 * std::f32::consts::TAU;
|
||||
c + vec2(a.cos(), a.sin()) * r * hardness
|
||||
})
|
||||
.collect();
|
||||
p.add(egui::Shape::dashed_line(&inner, Stroke::new(1.0, Color32::from_white_alpha(120)), 3.0, 3.0));
|
||||
}
|
||||
p.circle_filled(c, 1.5, Color32::WHITE);
|
||||
}
|
||||
|
||||
/// Paint the skew map under the pointer in the 2D view (a click is one dab, a drag a stroke).
|
||||
fn skew_input(app: &mut TextureCraftApp, ui: &Ui, resp: &egui::Response, to_uv: &dyn Fn(egui::Pos2) -> Vec2) {
|
||||
let last = ui.scope_id().with("skew_last");
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
//! The 2D view hides the system pointer and draws the brush outline under it while painting.
|
||||
|
||||
use egui::CursorIcon;
|
||||
use egui_kittest::Harness;
|
||||
use texturecraft_ui_egui::TextureCraftApp;
|
||||
use texturecraft_ui_egui::state::{Mode, ViewLayout};
|
||||
|
||||
fn harness() -> Harness<'static, TextureCraftApp> {
|
||||
let session = texturecraft_engine::sample_session(256, 64).unwrap();
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1600.0, 960.0)).build_eframe(|cc| TextureCraftApp::new(cc, session));
|
||||
h.state_mut().ui.layout = ViewLayout::Only2D;
|
||||
h.run_steps(4);
|
||||
h
|
||||
}
|
||||
|
||||
fn cursor(h: &Harness<'_, TextureCraftApp>) -> CursorIcon {
|
||||
h.output().platform_output.cursor_icon
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn painting_in_the_2d_view_replaces_the_pointer_with_the_brush_outline() {
|
||||
let mut h = harness();
|
||||
let c = egui::pos2(800.0, 480.0);
|
||||
h.hover_at(c);
|
||||
h.run_steps(3);
|
||||
assert_eq!(cursor(&h), CursorIcon::None, "the brush outline replaces the pointer");
|
||||
h.hover_at(egui::pos2(2.0, 2.0));
|
||||
h.run_steps(3);
|
||||
assert_ne!(cursor(&h), CursorIcon::None, "outside the view the pointer is back");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn outside_painting_the_2d_view_keeps_the_normal_pointer() {
|
||||
let mut h = harness();
|
||||
h.state_mut().ui.mode = Mode::Baking;
|
||||
h.run_steps(3);
|
||||
let c = egui::pos2(800.0, 480.0);
|
||||
h.hover_at(c);
|
||||
h.run_steps(3);
|
||||
assert_ne!(cursor(&h), CursorIcon::None);
|
||||
}
|
||||
Reference in new issue
Block a user