add experimental null char handling
This commit is contained in:
		
							parent
							
								
									c3b9ecf402
								
							
						
					
					
						commit
						5dcdd0f311
					
				
					 3 changed files with 34 additions and 11 deletions
				
			
		|  | @ -22,6 +22,11 @@ pub struct Cli { | |||
|         help = "Set default log level lower. You can also change this via the RUST_LOG environment variable." | ||||
|     )] | ||||
|     pub verbose: bool, | ||||
|     #[arg(
 | ||||
|         long, | ||||
|         help = "When receiving a null byte as a char in the CharGridCommand, do not overwrite any pixels instead of clearing all pixels." | ||||
|     )] | ||||
|     pub experimental_null_char_handling: bool, | ||||
| } | ||||
| 
 | ||||
| #[derive(Parser, Debug)] | ||||
|  |  | |||
|  | @ -22,6 +22,7 @@ pub struct CommandExecutionContext<'t> { | |||
|     luma: &'t RwLock<BrightnessGrid>, | ||||
|     cp437_font: Cp437Font, | ||||
|     font_renderer: FontRenderer8x8, | ||||
|     experimental_null_char_handling: bool, | ||||
| } | ||||
| 
 | ||||
| #[must_use] | ||||
|  | @ -193,20 +194,30 @@ impl CommandExecute for CharGridCommand { | |||
|         for char_y in 0usize..grid.height() { | ||||
|             for char_x in 0usize..grid.width() { | ||||
|                 let char = grid.get(char_x, char_y); | ||||
|                 trace!("drawing {char}"); | ||||
| 
 | ||||
|                 let mut bitmap_window = { | ||||
|                     let pixel_x = (char_x + x) * TILE_SIZE; | ||||
|                     let pixel_y = (char_y + y) * TILE_SIZE; | ||||
| 
 | ||||
|                 if let Err(e) = context.font_renderer.render( | ||||
|                     char, | ||||
|                     &mut display | ||||
|                     display | ||||
|                         .window_mut( | ||||
|                             pixel_x..pixel_x + TILE_SIZE, | ||||
|                             pixel_y..pixel_y + TILE_SIZE, | ||||
|                         ) | ||||
|                         .unwrap(), | ||||
|                 ) { | ||||
|                         .unwrap() | ||||
|                 }; | ||||
| 
 | ||||
|                 if char == '\0' { | ||||
|                     if context.experimental_null_char_handling { | ||||
|                         trace!("skipping {char:?}"); | ||||
|                     } else { | ||||
|                         bitmap_window.fill(false); | ||||
|                     } | ||||
|                     continue; | ||||
|                 } | ||||
| 
 | ||||
|                 trace!("drawing {char}"); | ||||
|                 if let Err(e) = | ||||
|                     context.font_renderer.render(char, &mut bitmap_window) | ||||
|                 { | ||||
|                     error!( | ||||
|                         "stopping drawing text because char draw failed: {e}" | ||||
|                     ); | ||||
|  | @ -256,12 +267,14 @@ impl<'t> CommandExecutionContext<'t> { | |||
|         display: &'t RwLock<Bitmap>, | ||||
|         luma: &'t RwLock<BrightnessGrid>, | ||||
|         font_renderer: FontRenderer8x8, | ||||
|         experimental_null_char_handling: bool, | ||||
|     ) -> Self { | ||||
|         CommandExecutionContext { | ||||
|             display, | ||||
|             luma, | ||||
|             font_renderer, | ||||
|             cp437_font: Cp437Font::default(), | ||||
|             experimental_null_char_handling, | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -39,7 +39,12 @@ fn main() { | |||
|         .font | ||||
|         .map(FontRenderer8x8::from_name) | ||||
|         .unwrap_or_else(FontRenderer8x8::default); | ||||
|     let context = CommandExecutionContext::new(&display, &luma, font_renderer); | ||||
|     let context = CommandExecutionContext::new( | ||||
|         &display, | ||||
|         &luma, | ||||
|         font_renderer, | ||||
|         cli.experimental_null_char_handling, | ||||
|     ); | ||||
|     let mut udp_server = UdpServer::new( | ||||
|         cli.bind, | ||||
|         stop_udp_rx, | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Vinzenz Schroeter
						Vinzenz Schroeter