press c to clear screen

This commit is contained in:
Vinzenz Schroeter 2024-05-20 17:52:33 +02:00
parent 4f19e27ab5
commit 8690e052bd
4 changed files with 31 additions and 25 deletions

1
.envrc Normal file
View file

@ -0,0 +1 @@
use nix

View file

@ -2,7 +2,7 @@ use std::sync::{RwLock, RwLockWriteGuard};
use log::{debug, error, info, warn}; use log::{debug, error, info, warn};
use servicepoint2::{ 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; use crate::font::BitmapFont;

View file

@ -2,15 +2,16 @@ use std::sync::mpsc::Sender;
use std::sync::RwLock; use std::sync::RwLock;
use log::{info, warn}; use log::{info, warn};
use pixels::{Pixels, PixelsBuilder, SurfaceTexture};
use pixels::wgpu::TextureFormat; use pixels::wgpu::TextureFormat;
use pixels::{Pixels, PixelsBuilder, SurfaceTexture};
use servicepoint2::{ use servicepoint2::{
ByteGrid, PIXEL_HEIGHT, PIXEL_WIDTH, PixelGrid, TILE_SIZE, ByteGrid, PixelGrid, PIXEL_HEIGHT, PIXEL_WIDTH, TILE_SIZE,
}; };
use winit::application::ApplicationHandler; use winit::application::ApplicationHandler;
use winit::dpi::{LogicalSize, Size}; use winit::dpi::LogicalSize;
use winit::event::WindowEvent; use winit::event::WindowEvent;
use winit::event_loop::ActiveEventLoop; use winit::event_loop::ActiveEventLoop;
use winit::keyboard::KeyCode::KeyC;
use winit::window::{Window, WindowId}; use winit::window::{Window, WindowId};
use crate::Cli; use crate::Cli;
@ -95,32 +96,29 @@ impl ApplicationHandler<AppEvents> for App<'_> {
PIXEL_HEIGHT + num_spacers * SPACER_HEIGHT PIXEL_HEIGHT + num_spacers * SPACER_HEIGHT
} else { } else {
PIXEL_HEIGHT 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() let attributes = Window::default_attributes()
.with_title("servicepoint-simulator") .with_title("servicepoint-simulator")
.with_inner_size(size); .with_inner_size(size)
.with_transparent(false);
let window = event_loop.create_window(attributes).unwrap(); let window = event_loop.create_window(attributes).unwrap();
self.window = Some(window); self.window = Some(window);
let window = self.window.as_ref().unwrap(); let window = self.window.as_ref().unwrap();
self.pixels = Some({ let window_size = window.inner_size();
let window_size = window.inner_size(); let pixels = PixelsBuilder::new(
PixelsBuilder::new( size.width as u32,
window_size.width, size.height as u32,
window_size.height, SurfaceTexture::new(window_size.width, window_size.height, &window),
SurfaceTexture::new( )
window_size.width, .render_texture_format(TextureFormat::Bgra8UnormSrgb)
window_size.height, .build()
&window, .expect("could not create pixels");
),
) self.pixels = Some(pixels);
.render_texture_format(TextureFormat::Bgra8UnormSrgb)
.build()
.expect("could not create pixels")
});
} }
fn user_event(&mut self, event_loop: &ActiveEventLoop, event: AppEvents) { fn user_event(&mut self, event_loop: &ActiveEventLoop, event: AppEvents) {
@ -145,7 +143,7 @@ impl ApplicationHandler<AppEvents> for App<'_> {
) { ) {
match event { match event {
WindowEvent::CloseRequested => { WindowEvent::CloseRequested => {
warn!("window event cloe requested"); warn!("window event close requested");
self.window = None; self.window = None;
let _ = self.stop_udp_tx.send(()); // try to stop udp thread let _ = self.stop_udp_tx.send(()); // try to stop udp thread
event_loop.exit(); event_loop.exit();
@ -153,6 +151,13 @@ impl ApplicationHandler<AppEvents> for App<'_> {
WindowEvent::RedrawRequested => { WindowEvent::RedrawRequested => {
self.draw(); 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();
}
_ => {} _ => {}
} }
} }

View file

@ -6,9 +6,9 @@ use std::sync::{mpsc, RwLock};
use std::time::Duration; use std::time::Duration;
use clap::Parser; use clap::Parser;
use log::{info, LevelFilter, warn}; use log::{info, warn, LevelFilter};
use servicepoint2::{ use servicepoint2::{
ByteGrid, Command, PIXEL_HEIGHT, PIXEL_WIDTH, PixelGrid, TILE_HEIGHT, ByteGrid, Command, PixelGrid, PIXEL_HEIGHT, PIXEL_WIDTH, TILE_HEIGHT,
TILE_WIDTH, TILE_WIDTH,
}; };
use winit::event_loop::{ControlFlow, EventLoop}; use winit::event_loop::{ControlFlow, EventLoop};