mirror of
https://github.com/kaesaecracker/servicepoint-simulator.git
synced 2025-01-18 10:30:14 +01:00
add more colors
This commit is contained in:
parent
e3d80204a6
commit
7cdbd41dea
23
src/gui.rs
23
src/gui.rs
|
@ -2,10 +2,10 @@ use std::sync::mpsc::Sender;
|
|||
use std::sync::RwLock;
|
||||
|
||||
use log::{info, warn};
|
||||
use pixels::wgpu::TextureFormat;
|
||||
use pixels::{Pixels, PixelsBuilder, SurfaceTexture};
|
||||
use pixels::wgpu::TextureFormat;
|
||||
use servicepoint2::{
|
||||
ByteGrid, PixelGrid, PIXEL_HEIGHT, PIXEL_WIDTH, TILE_SIZE,
|
||||
ByteGrid, PIXEL_HEIGHT, PIXEL_WIDTH, PixelGrid, TILE_SIZE,
|
||||
};
|
||||
use winit::application::ApplicationHandler;
|
||||
use winit::dpi::{LogicalSize, Size};
|
||||
|
@ -13,13 +13,15 @@ use winit::event::WindowEvent;
|
|||
use winit::event_loop::ActiveEventLoop;
|
||||
use winit::window::{Window, WindowId};
|
||||
|
||||
use crate::Cli;
|
||||
|
||||
pub struct App<'t> {
|
||||
display: &'t RwLock<PixelGrid>,
|
||||
luma: &'t RwLock<ByteGrid>,
|
||||
window: Option<Window>,
|
||||
pixels: Option<Pixels>,
|
||||
stop_udp_tx: Sender<()>,
|
||||
spacers: bool,
|
||||
cli: &'t Cli,
|
||||
}
|
||||
|
||||
const SPACER_HEIGHT: u16 = 4;
|
||||
|
@ -35,7 +37,7 @@ impl<'t> App<'t> {
|
|||
display: &'t RwLock<PixelGrid>,
|
||||
luma: &'t RwLock<ByteGrid>,
|
||||
stop_udp_tx: Sender<()>,
|
||||
spacers: bool,
|
||||
cli: &'t Cli,
|
||||
) -> Self {
|
||||
App {
|
||||
display,
|
||||
|
@ -43,14 +45,14 @@ impl<'t> App<'t> {
|
|||
stop_udp_tx,
|
||||
pixels: None,
|
||||
window: None,
|
||||
spacers,
|
||||
cli,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ApplicationHandler<AppEvents> for App<'_> {
|
||||
fn resumed(&mut self, event_loop: &ActiveEventLoop) {
|
||||
let height = if self.spacers {
|
||||
let height = if self.cli.spacers {
|
||||
let num_spacers = (PIXEL_HEIGHT / TILE_SIZE) - 1;
|
||||
PIXEL_HEIGHT + num_spacers * SPACER_HEIGHT
|
||||
} else {
|
||||
|
@ -122,7 +124,7 @@ impl ApplicationHandler<AppEvents> for App<'_> {
|
|||
let luma = self.luma.read().unwrap();
|
||||
|
||||
for y in 0..PIXEL_HEIGHT as usize {
|
||||
if self.spacers && y != 0 && y % TILE_SIZE as usize == 0 {
|
||||
if self.cli.spacers && y != 0 && y % TILE_SIZE as usize == 0 {
|
||||
// cannot just frame.skip(PIXEL_WIDTH as usize * SPACER_HEIGHT as usize) because of typing
|
||||
for _ in 0..PIXEL_WIDTH as usize * SPACER_HEIGHT as usize {
|
||||
frame.next().unwrap();
|
||||
|
@ -135,7 +137,12 @@ impl ApplicationHandler<AppEvents> for App<'_> {
|
|||
luma.get(x / TILE_SIZE as usize, y / TILE_SIZE as usize);
|
||||
|
||||
let color = if is_set {
|
||||
[0u8, brightness, 0, 255]
|
||||
[
|
||||
if self.cli.red { brightness } else { 0u8 },
|
||||
if self.cli.green { brightness } else { 0u8 },
|
||||
if self.cli.blue { brightness } else { 0u8 },
|
||||
255,
|
||||
]
|
||||
} else {
|
||||
[0u8, 0, 0, 255]
|
||||
};
|
||||
|
|
31
src/main.rs
31
src/main.rs
|
@ -23,19 +23,28 @@ mod gui;
|
|||
|
||||
#[derive(Parser, Debug)]
|
||||
struct Cli {
|
||||
#[arg(short, long, default_value = "0.0.0.0:2342")]
|
||||
#[arg(long, default_value = "0.0.0.0:2342")]
|
||||
bind: String,
|
||||
#[arg(short, long, default_value_t = false)]
|
||||
spacers: bool,
|
||||
#[arg(short, long, default_value_t = false)]
|
||||
red: bool,
|
||||
#[arg(short, long, default_value_t = false)]
|
||||
green: bool,
|
||||
#[arg(short, long, default_value_t = false)]
|
||||
blue: bool,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
env_logger::init();
|
||||
|
||||
let cli = Cli::parse();
|
||||
info!("starting with args: {:?}", &cli);
|
||||
let mut cli = Cli::parse();
|
||||
if !(cli.red || cli.blue || cli.green) {
|
||||
cli.green = true;
|
||||
}
|
||||
|
||||
let socket = UdpSocket::bind(cli.bind).expect("could not bind socket");
|
||||
info!("starting with args: {:?}", &cli);
|
||||
let socket = UdpSocket::bind(&cli.bind).expect("could not bind socket");
|
||||
socket
|
||||
.set_nonblocking(true)
|
||||
.expect("could not enter non blocking mode");
|
||||
|
@ -46,16 +55,24 @@ fn main() {
|
|||
PIXEL_WIDTH as usize,
|
||||
PIXEL_HEIGHT as usize,
|
||||
));
|
||||
let display_ref = &display;
|
||||
|
||||
let mut luma = ByteGrid::new(TILE_WIDTH as usize, TILE_HEIGHT as usize);
|
||||
luma.fill(u8::MAX);
|
||||
let luma = RwLock::new(luma);
|
||||
let luma_ref = &luma;
|
||||
|
||||
run(&display, &luma, socket, font, &cli);
|
||||
}
|
||||
|
||||
fn run(
|
||||
display_ref: &RwLock<PixelGrid>,
|
||||
luma_ref: &RwLock<ByteGrid>,
|
||||
socket: UdpSocket,
|
||||
font: BitmapFont,
|
||||
cli: &Cli,
|
||||
) {
|
||||
let (stop_udp_tx, stop_udp_rx) = mpsc::channel();
|
||||
|
||||
let mut app = App::new(display_ref, luma_ref, stop_udp_tx, cli.spacers);
|
||||
let mut app = App::new(display_ref, luma_ref, stop_udp_tx, cli);
|
||||
|
||||
let event_loop = EventLoop::with_user_event()
|
||||
.build()
|
||||
|
|
Loading…
Reference in a new issue