From 63ec587d0832ae7caa61a279637ca837cfe550e3 Mon Sep 17 00:00:00 2001 From: Lucas Schumacher Date: Tue, 7 May 2024 19:23:27 -0400 Subject: [PATCH] Increase waterfall size and have it fill the screen --- src/app.rs | 62 +++++++++++++++++++++----------------------- src/app/waterfall.rs | 4 ++- 2 files changed, 32 insertions(+), 34 deletions(-) diff --git a/src/app.rs b/src/app.rs index 283205c..f6cad43 100644 --- a/src/app.rs +++ b/src/app.rs @@ -20,6 +20,8 @@ mod deadbeef_rand { } use deadbeef_rand::rand; +const WF_SIZE: usize = 1024; + /// We derive Deserialize/Serialize so we can persist app state on shutdown. pub struct TemplateApp { // Example stuff: @@ -49,7 +51,7 @@ impl TemplateApp { // Example stuff: label: "Hello World!".to_owned(), value: 2.7, - waterfall: Arc::new(Mutex::new(Waterfall::new(gl, 300, 300, rx))), + waterfall: Arc::new(Mutex::new(Waterfall::new(gl, WF_SIZE, WF_SIZE, rx))), fft_sender: tx, } } @@ -115,41 +117,35 @@ impl eframe::App for TemplateApp { ui.label(" (OpenGL)."); }); - egui::Frame::canvas(ui.style()).show(ui, |ui| { - let (rect, response) = - ui.allocate_exact_size(egui::Vec2::splat(300.0), egui::Sense::drag()); - - let _angle = response.drag_motion().x * 0.01; - - let mut new_data = vec![0_u8; 300]; - for data in new_data.iter_mut() { - *data = rand(); - } - self.fft_sender.send(new_data).unwrap(); - - // Clone locals so we can move them into the paint callback: - let waterfall = self.waterfall.clone(); - - let callback = egui::PaintCallback { - rect, - callback: std::sync::Arc::new(egui_glow::CallbackFn::new( - move |_info, painter| { - waterfall.lock().paint(painter.gl(), _angle); - }, - )), - }; - ui.painter().add(callback); - }); - ui.separator(); - - ui.add(egui::github_link_file!( - "https://github.com/emilk/eframe_template/blob/main/", - "Source code." - )); - ui.with_layout(egui::Layout::bottom_up(egui::Align::LEFT), |ui| { powered_by_egui_and_eframe(ui); egui::warn_if_debug_build(ui); + egui::Frame::canvas(ui.style()).show(ui, |ui| { + let available_space = ui.available_size(); + let (rect, response) = + ui.allocate_exact_size(available_space, egui::Sense::drag()); + + let _angle = response.drag_motion().x * 0.01; + + let mut new_data = vec![0_u8; WF_SIZE]; + for data in new_data.iter_mut() { + *data = rand(); + } + self.fft_sender.send(new_data).unwrap(); + + // Clone locals so we can move them into the paint callback: + let waterfall = self.waterfall.clone(); + + let callback = egui::PaintCallback { + rect, + callback: std::sync::Arc::new(egui_glow::CallbackFn::new( + move |_info, painter| { + waterfall.lock().paint(painter.gl(), _angle); + }, + )), + }; + ui.painter().add(callback); + }); }); }); } diff --git a/src/app/waterfall.rs b/src/app/waterfall.rs index e902432..7ebccd6 100644 --- a/src/app/waterfall.rs +++ b/src/app/waterfall.rs @@ -119,8 +119,10 @@ impl Waterfall { // Generate something to put into the texture Buffer let mut buffer = vec![0; width * height]; // Add some stripes to the texture + let stripes = 8; + let slen = width / stripes; for (i, val) in buffer.iter_mut().enumerate() { - *val = if i % 50 < 25 { 255 } else { 0 }; + *val = if i % slen < slen / 2 { 255 } else { 0 }; //*val = 255; }