From 8690e052bd637447b22b96b30f7843560f9baaac Mon Sep 17 00:00:00 2001 From: Vinzenz Schroeter Date: Mon, 20 May 2024 17:52:33 +0200 Subject: [PATCH] press c to clear screen --- .envrc | 1 + src/execute_command.rs | 2 +- src/gui.rs | 49 +++++++++++++++++++++++------------------- src/main.rs | 4 ++-- 4 files changed, 31 insertions(+), 25 deletions(-) create mode 100644 .envrc diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..1d953f4 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use nix diff --git a/src/execute_command.rs b/src/execute_command.rs index e0ef5b9..0734e9e 100644 --- a/src/execute_command.rs +++ b/src/execute_command.rs @@ -2,7 +2,7 @@ use std::sync::{RwLock, RwLockWriteGuard}; use log::{debug, error, info, warn}; use servicepoint2::{ - ByteGrid, Command, Origin, PIXEL_COUNT, PIXEL_WIDTH, PixelGrid, TILE_SIZE, + ByteGrid, Command, Origin, PixelGrid, PIXEL_COUNT, PIXEL_WIDTH, TILE_SIZE, }; use crate::font::BitmapFont; diff --git a/src/gui.rs b/src/gui.rs index 32372d2..295507f 100644 --- a/src/gui.rs +++ b/src/gui.rs @@ -2,15 +2,16 @@ use std::sync::mpsc::Sender; use std::sync::RwLock; use log::{info, warn}; -use pixels::{Pixels, PixelsBuilder, SurfaceTexture}; use pixels::wgpu::TextureFormat; +use pixels::{Pixels, PixelsBuilder, SurfaceTexture}; use servicepoint2::{ - ByteGrid, PIXEL_HEIGHT, PIXEL_WIDTH, PixelGrid, TILE_SIZE, + ByteGrid, PixelGrid, PIXEL_HEIGHT, PIXEL_WIDTH, TILE_SIZE, }; use winit::application::ApplicationHandler; -use winit::dpi::{LogicalSize, Size}; +use winit::dpi::LogicalSize; use winit::event::WindowEvent; use winit::event_loop::ActiveEventLoop; +use winit::keyboard::KeyCode::KeyC; use winit::window::{Window, WindowId}; use crate::Cli; @@ -95,32 +96,29 @@ impl ApplicationHandler for App<'_> { PIXEL_HEIGHT + num_spacers * SPACER_HEIGHT } else { PIXEL_HEIGHT - } as f64; + }; - let size = Size::from(LogicalSize::new(PIXEL_WIDTH as f64, height)); + let size = LogicalSize::new(PIXEL_WIDTH, height); let attributes = Window::default_attributes() .with_title("servicepoint-simulator") - .with_inner_size(size); + .with_inner_size(size) + .with_transparent(false); let window = event_loop.create_window(attributes).unwrap(); self.window = Some(window); let window = self.window.as_ref().unwrap(); - self.pixels = Some({ - let window_size = window.inner_size(); - PixelsBuilder::new( - window_size.width, - window_size.height, - SurfaceTexture::new( - window_size.width, - window_size.height, - &window, - ), - ) - .render_texture_format(TextureFormat::Bgra8UnormSrgb) - .build() - .expect("could not create pixels") - }); + let window_size = window.inner_size(); + let pixels = PixelsBuilder::new( + size.width as u32, + size.height as u32, + SurfaceTexture::new(window_size.width, window_size.height, &window), + ) + .render_texture_format(TextureFormat::Bgra8UnormSrgb) + .build() + .expect("could not create pixels"); + + self.pixels = Some(pixels); } fn user_event(&mut self, event_loop: &ActiveEventLoop, event: AppEvents) { @@ -145,7 +143,7 @@ impl ApplicationHandler for App<'_> { ) { match event { WindowEvent::CloseRequested => { - warn!("window event cloe requested"); + warn!("window event close requested"); self.window = None; let _ = self.stop_udp_tx.send(()); // try to stop udp thread event_loop.exit(); @@ -153,6 +151,13 @@ impl ApplicationHandler for App<'_> { WindowEvent::RedrawRequested => { self.draw(); } + WindowEvent::KeyboardInput { event, .. } + if event.physical_key == KeyC && !event.repeat => + { + self.display.write().unwrap().fill(false); + self.luma.write().unwrap().fill(u8::MAX); + self.window.as_ref().unwrap().request_redraw(); + } _ => {} } } diff --git a/src/main.rs b/src/main.rs index 751ebec..8e74d2a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,9 +6,9 @@ use std::sync::{mpsc, RwLock}; use std::time::Duration; use clap::Parser; -use log::{info, LevelFilter, warn}; +use log::{info, warn, LevelFilter}; use servicepoint2::{ - ByteGrid, Command, PIXEL_HEIGHT, PIXEL_WIDTH, PixelGrid, TILE_HEIGHT, + ByteGrid, Command, PixelGrid, PIXEL_HEIGHT, PIXEL_WIDTH, TILE_HEIGHT, TILE_WIDTH, }; use winit::event_loop::{ControlFlow, EventLoop};