Preliminary preview for selected laser
This commit is contained in:
parent
e291ab480a
commit
a364a9daad
1 changed files with 102 additions and 22 deletions
|
@ -263,6 +263,16 @@ fn model(app: &App) -> GuiModel {
|
|||
.build()
|
||||
.unwrap();
|
||||
|
||||
let w_id_laserpreview = app
|
||||
.new_window()
|
||||
.size(1024, 1024)
|
||||
// .key_pressed(key_pressed)
|
||||
// .mouse_wheel(canvas_zoom)
|
||||
.mouse_pressed(laser_preview_mouse_pressed)
|
||||
.view(view_laser_preview)
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
// Initialise the state that we want to live on the laser thread and spawn the stream.
|
||||
let laser_settings = LaserSettings::default();
|
||||
let laser_model = LaserModel::new();
|
||||
|
@ -347,28 +357,6 @@ fn model(app: &App) -> GuiModel {
|
|||
fn laser_frame_producer(model: &mut LaserModel, frame: &mut laser::Frame){
|
||||
|
||||
let current_points: LaserPoints = (&model.current_lines).into();
|
||||
// let points = LaserPoints { points: vec!(
|
||||
// laser::Point{
|
||||
// position:[ 9.4, 7.2],
|
||||
// color: [1.,1.,0.],
|
||||
// weight: 0,
|
||||
// },
|
||||
// laser::Point{
|
||||
// position:[ 12.4, 7.2],
|
||||
// color: [1.,1.,0.],
|
||||
// weight: 0,
|
||||
// },
|
||||
// laser::Point{
|
||||
// position:[ 12.4, 4.2],
|
||||
// color: [1.,1.,0.],
|
||||
// weight: 0,
|
||||
// },
|
||||
// laser::Point{
|
||||
// position:[ 9.4, 4.2],
|
||||
// color: [1.,1.,0.],
|
||||
// weight: 0,
|
||||
// },
|
||||
// ), space: CoordinateSpace::World };
|
||||
let space = &model.current_lines.space;
|
||||
|
||||
// check which source should be used, and get points accordingly.
|
||||
|
@ -795,6 +783,98 @@ fn view_line_canvas(app: &App, model: &GuiModel, frame: Frame) {
|
|||
}
|
||||
|
||||
|
||||
fn view_laser_preview(app: &App, model: &GuiModel, frame: Frame) {
|
||||
// get canvas to draw on
|
||||
let draw = app.draw();
|
||||
|
||||
|
||||
draw.background().color(DARKGRAY);
|
||||
|
||||
let win = app.window_rect();
|
||||
|
||||
let w = 1024.;
|
||||
let h = 1024.;
|
||||
let hh = h / 2.;
|
||||
let hw = w / 2.;
|
||||
|
||||
let thickness = 2.0;
|
||||
|
||||
let win_rect = app.main_window().rect().pad(20.0);
|
||||
|
||||
match &model.selected_stream {
|
||||
None => {
|
||||
draw.text("Select a stream to preview")
|
||||
.color(WHITE)
|
||||
.font_size(24)
|
||||
.wh(win_rect.wh());
|
||||
},
|
||||
Some(dac_id) => {
|
||||
let stream_config: & StreamConfig = model.laser_streams.get(&dac_id).expect("Selected stream not found in configs");
|
||||
|
||||
draw.text(&format!("{:?}", dac_id))
|
||||
.h(win_rect.h())
|
||||
.font_size(10)
|
||||
.align_text_bottom()
|
||||
.left_justify()
|
||||
.color(WHITE)
|
||||
.w(win_rect.w());
|
||||
|
||||
|
||||
let current_points: LaserPoints = (&model.current_lines).into();
|
||||
let space = &model.current_lines.space;
|
||||
|
||||
// check which source should be used, and get points accordingly.
|
||||
// potentially ignoring the points coming from the stream
|
||||
let points = stream_config.config.source.get_shape(current_points);
|
||||
|
||||
let pointno = points.points.len();
|
||||
|
||||
let new_points = stream_config.config.filters.apply(&points);
|
||||
|
||||
// similar to map code:
|
||||
|
||||
let vertices = new_points.points.iter().map(|p| {
|
||||
let color = srgba(p.color[0], p.color[1], p.color[0], 1.);
|
||||
|
||||
let pos = [p.position[0] * hw, p.position[1] * hh];
|
||||
(pos, color)
|
||||
});
|
||||
|
||||
draw.polyline()
|
||||
.weight(thickness)
|
||||
.join_round()
|
||||
.points_colored(vertices);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
draw.to_frame(app, &frame).unwrap();
|
||||
|
||||
}
|
||||
|
||||
fn laser_preview_mouse_pressed(app: &App, _model: &mut GuiModel, button: MouseButton) {
|
||||
if button != MouseButton::Left {
|
||||
// ignore
|
||||
return;
|
||||
}
|
||||
|
||||
let half_w = (1024 / 2) as f32;
|
||||
let half_h = (1024 / 2) as f32;
|
||||
|
||||
let x = app.mouse.x / half_w;
|
||||
let y = app.mouse.y / half_h;
|
||||
|
||||
if x > 1. || x < -1. || y > 1. || y < -1. {
|
||||
println!("Click outside of canvas: {} {}", x, y);
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
fn draw_grid(draw: &Draw, win: &Rect, step: f32, weight: f32) {
|
||||
let step_by = || (0..).map(|i| i as f32 * step);
|
||||
let r_iter = step_by().take_while(|&f| f < win.right());
|
||||
|
|
Loading…
Reference in a new issue