mirror of
https://github.com/kaesaecracker/servicepoint-simulator.git
synced 2025-01-29 17:00:13 +01:00
press c to clear screen
This commit is contained in:
parent
4f19e27ab5
commit
8690e052bd
|
@ -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;
|
||||
|
|
49
src/gui.rs
49
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<AppEvents> 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<AppEvents> 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<AppEvents> 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();
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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};
|
||||
|
|
Loading…
Reference in a new issue