Stroke a path instead of drawing many circles

This commit is contained in:
Enrico Lumetti 2020-05-04 16:52:04 +02:00
parent 56a2ef9c97
commit 33fdcfbfaf
1 changed files with 10 additions and 4 deletions

View File

@ -42,10 +42,16 @@ fn main() {
let state = &*state_clone_1.borrow(); let state = &*state_clone_1.borrow();
for pt in &state.point_buffer { if state.point_buffer.len() > 0 {
let (x, y) = state.point_buffer[0];
cr.move_to(x - wa.x as f64, y - wa.y as f64);
for pt in &state.point_buffer[1..] {
cr.line_to(pt.0 - wa.x as f64, pt.1 - wa.y as f64);
}
cr.set_source_rgb(1.0, 0.0, 0.0); cr.set_source_rgb(1.0, 0.0, 0.0);
cr.arc(pt.0 - wa.x as f64, pt.1 - wa.y as f64, 3., 0., 2.*std::f64::consts::PI); cr.set_line_width(3.);
cr.fill(); cr.stroke();
} }
println!("{} points drawn", state.point_buffer.len()); println!("{} points drawn", state.point_buffer.len());
@ -72,7 +78,7 @@ fn main() {
let state_clone_3 = Rc::clone(&app_state); let state_clone_3 = Rc::clone(&app_state);
let win_clone = Rc::clone(&window); let win_clone = Rc::clone(&window);
clear_button.connect_clicked(move |widget| { clear_button.connect_clicked(move |_| {
state_clone_3.borrow_mut().point_buffer.clear(); state_clone_3.borrow_mut().point_buffer.clear();
win_clone.queue_draw(); win_clone.queue_draw();
}); });