toggle to show input as bytes or text
This commit is contained in:
parent
34fb5f1dd2
commit
e9b03b937b
2 changed files with 51 additions and 17 deletions
|
@ -435,17 +435,47 @@ impl Editor {
|
||||||
|
|
||||||
draw_usize(d, textures, self.machine.step_count(), 420, 4, 5, 2);
|
draw_usize(d, textures, self.machine.step_count(), 420, 4, 5, 2);
|
||||||
|
|
||||||
let mut input_text = String::from_utf8_lossy(self.machine.input()).to_string();
|
d.draw_text("input:", 523, 8, 10, Color::WHITE);
|
||||||
|
if simple_button(d, 520, 20, 35, 15) {
|
||||||
|
self.input_as_text = !self.input_as_text
|
||||||
|
}
|
||||||
|
let input_mode_text = if self.input_as_text { "text" } else { "bytes" };
|
||||||
|
d.draw_text(input_mode_text, 523, 23, 10, Color::WHITE);
|
||||||
|
|
||||||
|
let input_x = 560;
|
||||||
let width = d.get_screen_width();
|
let width = d.get_screen_width();
|
||||||
d.draw_text("input:", width - 260, 10, 20, Color::WHITE);
|
if self.input_as_text {
|
||||||
if text_input(
|
let mut input_text = String::from_utf8_lossy(self.machine.input()).to_string();
|
||||||
d,
|
if text_input(
|
||||||
Rectangle::new(width as f32 - 205., 5., 200., 30.),
|
d,
|
||||||
&mut input_text,
|
Rectangle::new(input_x as f32, 5., (width - input_x - 5) as f32, 30.),
|
||||||
&mut self.input_text_selected,
|
&mut input_text,
|
||||||
self.level.is_sandbox(),
|
&mut self.input_text_selected,
|
||||||
) {
|
self.level.is_sandbox(),
|
||||||
self.machine.set_input(input_text.into_bytes());
|
) {
|
||||||
|
self.machine.set_input(input_text.into_bytes());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
let input_cell_width = 43;
|
||||||
|
let input_cells = (d.get_screen_width() - input_x) as usize / input_cell_width as usize;
|
||||||
|
|
||||||
|
let input_start = self.machine.input_index().saturating_sub(input_cells);
|
||||||
|
let input_end = input_start + input_cells;
|
||||||
|
for (box_index, index) in (input_start..input_end).enumerate() {
|
||||||
|
let x = input_x + input_cell_width * box_index as i32;
|
||||||
|
let byte = self.machine.input().get(index);
|
||||||
|
d.draw_rectangle(x, 5, input_cell_width - 5, 30, Color::DIMGRAY);
|
||||||
|
let color = if index < self.machine.input_index() {
|
||||||
|
d.draw_rectangle(x + 4, 25, input_cell_width - 13, 8, Color::LIME);
|
||||||
|
Color::LIGHTGREEN
|
||||||
|
} else {
|
||||||
|
Color::WHITE
|
||||||
|
};
|
||||||
|
if let Some(&byte) = byte {
|
||||||
|
let top_text = format!("{}", byte);
|
||||||
|
d.draw_text(&top_text, x + 2, 5, 20, color);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -520,7 +550,7 @@ impl Editor {
|
||||||
|
|
||||||
let output_x = 370;
|
let output_x = 370;
|
||||||
let output_cell_width = 43;
|
let output_cell_width = 43;
|
||||||
let output_cells = (d.get_screen_width() - output_x) as usize / 43;
|
let output_cells = (d.get_screen_width() - output_x) as usize / output_cell_width as usize;
|
||||||
|
|
||||||
let y = footer_top as i32 + 5;
|
let y = footer_top as i32 + 5;
|
||||||
if simple_button(d, output_x, y + 70, 65, 15) {
|
if simple_button(d, output_x, y + 70, 65, 15) {
|
||||||
|
@ -552,8 +582,8 @@ impl Editor {
|
||||||
(Color::DARKGRAY, Color::DIMGRAY)
|
(Color::DARKGRAY, Color::DIMGRAY)
|
||||||
};
|
};
|
||||||
|
|
||||||
d.draw_rectangle(x, y, 38, 30, top_color);
|
d.draw_rectangle(x, y, output_cell_width - 5, 30, top_color);
|
||||||
d.draw_rectangle(x, y + 35, 38, 30, bottom_color);
|
d.draw_rectangle(x, y + 35, output_cell_width - 5, 30, bottom_color);
|
||||||
if let Some(&expected_byte) = expected_byte {
|
if let Some(&expected_byte) = expected_byte {
|
||||||
let top_text = if self.output_as_text
|
let top_text = if self.output_as_text
|
||||||
&& (expected_byte.is_ascii_graphic() || expected_byte.is_ascii_whitespace())
|
&& (expected_byte.is_ascii_graphic() || expected_byte.is_ascii_whitespace())
|
||||||
|
@ -674,10 +704,10 @@ impl Editor {
|
||||||
Tool::SelectArea(_, _) => (),
|
Tool::SelectArea(_, _) => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if d.is_mouse_button_down(MouseButton::MOUSE_BUTTON_LEFT) {
|
if d.is_mouse_button_down(MouseButton::MOUSE_BUTTON_LEFT)
|
||||||
if self.active_tool == Tool::Erase {
|
&& self.active_tool == Tool::Erase
|
||||||
self.set_tile(tile_pos.into(), Tile::Blank)
|
{
|
||||||
}
|
self.set_tile(tile_pos.into(), Tile::Blank)
|
||||||
}
|
}
|
||||||
if let Tool::SelectArea(selection, is_selecting) = &mut self.active_tool {
|
if let Tool::SelectArea(selection, is_selecting) = &mut self.active_tool {
|
||||||
if d.is_mouse_button_down(MouseButton::MOUSE_BUTTON_LEFT) {
|
if d.is_mouse_button_down(MouseButton::MOUSE_BUTTON_LEFT) {
|
||||||
|
|
|
@ -58,6 +58,10 @@ impl Machine {
|
||||||
&self.input
|
&self.input
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn input_index(&self) -> usize {
|
||||||
|
self.input_index
|
||||||
|
}
|
||||||
|
|
||||||
pub fn step_count(&self) -> usize {
|
pub fn step_count(&self) -> usize {
|
||||||
self.steps
|
self.steps
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue