Mask drawing + removing points. TODO: applying clip mask
This commit is contained in:
parent
e3fe78ec5c
commit
fa3dc1d104
2 changed files with 32 additions and 47 deletions
|
@ -15,6 +15,7 @@ use serde_json::Result;
|
|||
use trap_rust::trap::filters::PointFilters;
|
||||
use trap_rust::trap::laser::{shape_rect, LaserPoints, LaserSpace, StreamSource, STREAM_SOURCES, TMP_DESK_CLUBMAX, Corner};
|
||||
use trap_rust::trap::tracks::CoordinateSpace;
|
||||
use trap_rust::trap::utils::closest_edge;
|
||||
use trap_rust::trap::{laser::{python_cv_h_into_mat3, LaserModel, TMP_PYTHON_LASER_H, DacConfig}, tracks::{RenderableLines}};
|
||||
use zmq::Socket;
|
||||
use std::sync::{mpsc, Arc};
|
||||
|
@ -928,7 +929,7 @@ fn view_laser_preview(app: &App, model: &GuiModel, frame: Frame) {
|
|||
let draw = app.draw();
|
||||
|
||||
|
||||
draw.background().color(DARKGRAY);
|
||||
draw.background().color(BLACK);
|
||||
|
||||
let win = app.window_rect();
|
||||
|
||||
|
@ -973,12 +974,12 @@ fn view_laser_preview(app: &App, model: &GuiModel, frame: Frame) {
|
|||
// TODO: does not work?
|
||||
draw.ellipse()
|
||||
.x_y(point[0], point[1])
|
||||
.radius(1.)
|
||||
.color(BLACK);
|
||||
.radius(5.)
|
||||
.stroke(WHITE);
|
||||
}
|
||||
|
||||
draw.polygon()
|
||||
.color(srgba(1.,1.,1.,0.))
|
||||
.color(srgba(1.,1.,1.,3.))
|
||||
.stroke(PINK)
|
||||
.stroke_weight(thickness)
|
||||
.join_round()
|
||||
|
@ -1025,11 +1026,6 @@ fn laser_preview_mouse_pressed(app: &App, model: &mut GuiModel, button: MouseBut
|
|||
Some(d) => d,
|
||||
};
|
||||
|
||||
if button != MouseButton::Left {
|
||||
// ignore
|
||||
// TODO: right click remove point within Margin
|
||||
return;
|
||||
}
|
||||
|
||||
let config = model.per_laser_config.get_mut(&dac_id).expect("Dac config unavailable");
|
||||
|
||||
|
@ -1061,53 +1057,41 @@ fn laser_preview_mouse_pressed(app: &App, model: &mut GuiModel, button: MouseBut
|
|||
|
||||
// match_distance is in pixelspace. Convert to laser-space
|
||||
if dist_sq.sqrt() <= (MATCH_DISTANCE / half_w) {
|
||||
// 2a. if closest is within MATCH_DISTANCE. Select point for dragging
|
||||
model.preview_dragging_point = Some(idx.clone());
|
||||
// println!("Closest point {:?} is within distance: {}", closest_point, dist_sq.sqrt());
|
||||
if button == MouseButton::Left {
|
||||
model.preview_dragging_point = Some(*idx);
|
||||
}
|
||||
if button == MouseButton::Right {
|
||||
// require minimum of three corners for clipping
|
||||
// (makes calculations/assumptions easier)
|
||||
// so don't remove if too little
|
||||
if config.filters.clip.mask.len() > 3 {
|
||||
config.filters.clip.mask.remove(*idx);
|
||||
}
|
||||
}
|
||||
|
||||
// 2a. if closest is within MATCH_DISTANCE. Select point for dragging
|
||||
} else {
|
||||
// 2b. if not, if close point is found, if point has neighbours (i.e. len of vec > 1), and find which of neighbours is closest. Insert point between these. Select new point
|
||||
let prev_point = point_distances.get((idx + point_distances.len() -1) % point_distances.len()).expect("No prev neighbour?");
|
||||
let next_point = point_distances.get((idx+1) % point_distances.len()).expect("No next neighbour");
|
||||
|
||||
// select closest of prev/next
|
||||
let (idx2, _, _closest_point2) = if prev_point.1 < next_point.1 {
|
||||
prev_point
|
||||
} else {
|
||||
next_point
|
||||
};
|
||||
if button == MouseButton::Left {
|
||||
// 2b. if not, find closest edge
|
||||
let insert_at = match closest_edge(&config.filters.clip.mask, [laser_x, laser_y]) {
|
||||
Some(idx) => (idx + 1) % config.filters.clip.mask.len(),
|
||||
None => return,
|
||||
};
|
||||
|
||||
|
||||
// insert point
|
||||
let instert_at = *min(idx, idx2);
|
||||
// insert point
|
||||
// let instert_at = *min(idx, idx2);
|
||||
|
||||
let new_point = [laser_x, laser_y];
|
||||
let new_point = [laser_x, laser_y];
|
||||
config.filters.clip.mask.insert(insert_at % config.filters.clip.mask.len(), new_point);
|
||||
model.preview_dragging_point = Some(insert_at);
|
||||
}
|
||||
|
||||
config.filters.clip.mask.insert(instert_at, new_point);
|
||||
model.preview_dragging_point = Some(instert_at);
|
||||
|
||||
// println!("Closest point {:?} is too far: {}", closest_point, dist_sq.sqrt());
|
||||
}
|
||||
|
||||
|
||||
|
||||
// if (app.mouse.x - c[0]).abs() < MATCH_DISTANCE && (app.mouse.y - c[1]).abs() < MATCH_DISTANCE {
|
||||
// dbg!("close to corner! {:?}", &c);
|
||||
// match i {
|
||||
// 0 => selected = Some(Corner::TopLeft),
|
||||
// 1 => selected = Some(Corner::TopRight),
|
||||
// 2 => selected = Some(Corner::BottomRight),
|
||||
// 3 => selected = Some(Corner::BottomLeft),
|
||||
// _ => selected = None,
|
||||
// }
|
||||
// break;
|
||||
// }
|
||||
// 2a. if closest point is within selection margin, select that item.
|
||||
// 2b. if not, if close point is found, if point has neighbours (i.e. len of vec > 1), and find which of neighbours is closest. Insert point between these. Select new point
|
||||
// 2c. if no closest point is found (thus Vec is empty), create a point under cursor. Select that new point.
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -11,3 +11,4 @@ pub mod shapes;
|
|||
|
||||
pub mod laser;
|
||||
pub mod filters;
|
||||
pub mod utils;
|
Loading…
Reference in a new issue