Skip to content

Commit

Permalink
apply rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthieu Casanova committed Jun 16, 2024
1 parent 5f096c8 commit 44c6135
Show file tree
Hide file tree
Showing 14 changed files with 930 additions and 486 deletions.
2 changes: 1 addition & 1 deletion src/bios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ use rust_embed::RustEmbed;

#[derive(RustEmbed)]
#[folder = "bios"]
pub(crate) struct Bios;
pub(crate) struct Bios;
16 changes: 4 additions & 12 deletions src/data_input_stream.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::{fs, io};
use std::path::Path;
use std::{fs, io};

use crate::int;

Expand All @@ -12,15 +12,8 @@ pub(crate) struct DataInputStream {
impl DataInputStream {
pub(crate) fn new(file: &Path) -> io::Result<DataInputStream> {
match fs::read(file) {
Ok(bytes) => {
Ok(DataInputStream {
bytes,
pos: 0,
})
}
Err(e) => {
Err(e)
}
Ok(bytes) => Ok(DataInputStream { bytes, pos: 0 }),
Err(e) => Err(e),
}
}

Expand All @@ -30,8 +23,7 @@ impl DataInputStream {
b as int
}


pub fn len(&self) -> usize {
self.bytes.len()
}
}
}
54 changes: 41 additions & 13 deletions src/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ use std::sync::mpsc::{Receiver, Sender};

use log::error;
use speedy2d::dimen::{UVec2, Vec2};
use speedy2d::Graphics2D;
use speedy2d::image::ImageDataType::RGB;
use speedy2d::image::ImageHandle;
use speedy2d::image::ImageSmoothingMode::NearestNeighbor;
use speedy2d::window::{KeyScancode, ModifiersState, VirtualKeyCode, WindowHandler, WindowHelper};
use speedy2d::Graphics2D;

use crate::hardware::keyboard::vkey::map_virtual_key_code;
use crate::hardware::screen::{DEFAULT_PIXEL_SIZE, HEIGHT, WIDTH};
Expand All @@ -21,11 +21,14 @@ pub(crate) struct Gui {
}

impl Gui {
pub(crate) fn new(user_input_sender: Sender<UserInput>, image_data_receiver: Receiver<Vec<u8>>) -> Self {
pub(crate) fn new(
user_input_sender: Sender<UserInput>,
image_data_receiver: Receiver<Vec<u8>>,
) -> Self {
Gui {
image: None,
user_input_sender,
image_data_receiver
image_data_receiver,
}
}
}
Expand All @@ -37,12 +40,19 @@ impl WindowHandler for Gui {
let image = graphics.create_image_from_raw_pixels(
RGB,
NearestNeighbor,
UVec2::new((DEFAULT_PIXEL_SIZE * WIDTH) as u32, (DEFAULT_PIXEL_SIZE * HEIGHT) as u32),
raw);
UVec2::new(
(DEFAULT_PIXEL_SIZE * WIDTH) as u32,
(DEFAULT_PIXEL_SIZE * HEIGHT) as u32,
),
raw,
);
if image.is_ok() {
self.image = Some(image.unwrap());
} else {
error!("Error creating image from raw pixels {:?}", image.err().unwrap());
error!(
"Error creating image from raw pixels {:?}",
image.err().unwrap()
);
}
}

Expand All @@ -53,11 +63,22 @@ impl WindowHandler for Gui {
helper.request_redraw();
}

fn on_key_down(&mut self, _: &mut WindowHelper<()>, virtual_key_code: Option<VirtualKeyCode>, scancode: KeyScancode) {
fn on_key_down(
&mut self,
_: &mut WindowHelper<()>,
virtual_key_code: Option<VirtualKeyCode>,
scancode: KeyScancode,
) {
match virtual_key_code {
Some(VirtualKeyCode::F2) => {self.user_input_sender.send(OpenK7File).ok();}
Some(VirtualKeyCode::F7) => {self.user_input_sender.send(SoftReset).ok();}
Some(VirtualKeyCode::F8) => {self.user_input_sender.send(HardReset).ok();}
Some(VirtualKeyCode::F2) => {
self.user_input_sender.send(OpenK7File).ok();
}
Some(VirtualKeyCode::F7) => {
self.user_input_sender.send(SoftReset).ok();
}
Some(VirtualKeyCode::F8) => {
self.user_input_sender.send(HardReset).ok();
}
_ => {
if let Some(vk) = map_virtual_key_code(virtual_key_code, scancode) {
self.user_input_sender.send(UserInput::KeyDown(vk)).ok();
Expand All @@ -66,13 +87,20 @@ impl WindowHandler for Gui {
}
}

fn on_key_up(&mut self, _: &mut WindowHelper<()>, virtual_key_code: Option<VirtualKeyCode>, scancode: KeyScancode) {
fn on_key_up(
&mut self,
_: &mut WindowHelper<()>,
virtual_key_code: Option<VirtualKeyCode>,
scancode: KeyScancode,
) {
if let Some(vk) = map_virtual_key_code(virtual_key_code, scancode) {
self.user_input_sender.send(UserInput::KeyUp(vk)).ok();
}
}

fn on_keyboard_modifiers_changed(&mut self, _: &mut WindowHelper<()>, state: ModifiersState) {
self.user_input_sender.send(UserInput::KeyboardModifierChanged(state)).ok();
self.user_input_sender
.send(UserInput::KeyboardModifierChanged(state))
.ok();
}
}
}
Loading

0 comments on commit 44c6135

Please sign in to comment.