Remove explicit event handling to fix resize issue
This commit is contained in:
parent
ed8abb74e6
commit
0bfe5f1a12
59
src/main.rs
59
src/main.rs
@ -5,11 +5,6 @@ use std::process;
|
||||
|
||||
use clap::Parser;
|
||||
|
||||
use piston::EventLoop;
|
||||
use piston::EventSettings;
|
||||
use piston::Events;
|
||||
use piston::RenderEvent;
|
||||
|
||||
use piston_window as pw;
|
||||
use piston_window::PistonWindow;
|
||||
use piston_window::WindowSettings;
|
||||
@ -70,43 +65,39 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
||||
[1600, 800],
|
||||
)
|
||||
.exit_on_esc(true)
|
||||
.vsync(true)
|
||||
.build()?;
|
||||
|
||||
let mut events = Events::new(EventSettings::new().ups(cli.frame_rate));
|
||||
|
||||
let x_size = cli.cols;
|
||||
let y_size = cli.rows;
|
||||
while let Some(event) = events.next(&mut window) {
|
||||
if let Some(args) = event.render_args() {
|
||||
window.draw_2d(&event, |context, graphics, _device| {
|
||||
// let [vsx, vsy] = context.get_view_size();
|
||||
let [vsx, vsy] = args.viewport().window_size;
|
||||
while let Some(event) = window.next() {
|
||||
window.draw_2d(&event, |context, graphics, _device| {
|
||||
let [vsx, vsy] = context.get_view_size();
|
||||
|
||||
// Compute cell size
|
||||
let csx = vsx / (x_size as f64);
|
||||
let csy = vsy / (y_size as f64);
|
||||
let cs = csx.min(csy);
|
||||
// Compute cell size
|
||||
let csx = (vsx as f64) / (x_size as f64);
|
||||
let csy = (vsy as f64) / (y_size as f64);
|
||||
let cs = csx.min(csy);
|
||||
|
||||
pw::clear([0.0, 0.0, 0.0, 1.0], graphics);
|
||||
pw::clear([0.5, 0.5, 0.5, 1.0], graphics);
|
||||
|
||||
stdout.read_exact(&mut buffer).expect("pipe read failed");
|
||||
if cli.debug >= 3 {
|
||||
eprintln!("Received frame {}", frame_count);
|
||||
stdout.read_exact(&mut buffer).expect("pipe read failed");
|
||||
if cli.debug >= 3 {
|
||||
eprintln!("Received frame {}", frame_count);
|
||||
}
|
||||
|
||||
for y in 0..y_size {
|
||||
for x in 0..x_size {
|
||||
let i = colors * (y * x_size + x);
|
||||
let r = f32::from(buffer[i + 0]) / 255.0;
|
||||
let g = f32::from(buffer[i + 1]) / 255.0;
|
||||
let b = f32::from(buffer[i + 2]) / 255.0;
|
||||
let color = [r, g, b, 1.0];
|
||||
let rectangle = [(x as f64) * cs, (y as f64) * cs, cs, cs];
|
||||
pw::rectangle(color, rectangle, context.transform, graphics);
|
||||
}
|
||||
|
||||
for y in 0..y_size {
|
||||
for x in 0..x_size {
|
||||
let i = colors * (y * x_size + x);
|
||||
let r = f32::from(buffer[i + 0]) / 255.0;
|
||||
let g = f32::from(buffer[i + 1]) / 255.0;
|
||||
let b = f32::from(buffer[i + 2]) / 255.0;
|
||||
let color = [r, g, b, 1.0];
|
||||
let rectangle = [(x as f64) * cs, (y as f64) * cs, cs, cs];
|
||||
pw::rectangle(color, rectangle, context.transform, graphics);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
frame_count += 1;
|
||||
}
|
||||
child.kill()?;
|
||||
|
Loading…
Reference in New Issue
Block a user