2021-10-22 04:55:27 +00:00
|
|
|
|
|
|
|
use crate::error::Error;
|
2021-11-07 04:44:25 +00:00
|
|
|
use crate::host::keys::Key;
|
2021-10-22 04:55:27 +00:00
|
|
|
|
2021-10-31 18:00:14 +00:00
|
|
|
#[derive(Copy, Clone, Debug, PartialEq)]
|
|
|
|
pub enum JoystickDevice {
|
|
|
|
A,
|
|
|
|
B,
|
|
|
|
C,
|
|
|
|
D,
|
|
|
|
}
|
2021-10-22 04:55:27 +00:00
|
|
|
|
|
|
|
pub trait Host {
|
2021-10-23 02:36:05 +00:00
|
|
|
//fn create_pty(&self) -> Result<Box<dyn Tty>, Error>;
|
2021-11-07 04:44:25 +00:00
|
|
|
fn add_window(&mut self, updater: Box<dyn WindowUpdater>) -> Result<(), Error>;
|
2021-11-13 19:39:20 +00:00
|
|
|
fn register_joystick(&mut self, _device: JoystickDevice, _input: Box<dyn JoystickUpdater>) -> Result<(), Error> { Err(Error::new("Not supported")) }
|
|
|
|
fn register_keyboard(&mut self, _input: Box<dyn KeyboardUpdater>) -> Result<(), Error> { Err(Error::new("Not supported")) }
|
2021-10-22 04:55:27 +00:00
|
|
|
}
|
|
|
|
|
2021-10-23 02:36:05 +00:00
|
|
|
pub trait Tty {
|
|
|
|
fn device_name(&self) -> String;
|
|
|
|
fn read(&mut self) -> Option<u8>;
|
|
|
|
fn write(&mut self, output: u8) -> bool;
|
2021-10-22 04:55:27 +00:00
|
|
|
}
|
|
|
|
|
2021-10-23 02:36:05 +00:00
|
|
|
pub trait WindowUpdater: Send {
|
2021-11-11 17:52:18 +00:00
|
|
|
fn get_size(&mut self) -> (u32, u32);
|
2021-10-23 02:36:05 +00:00
|
|
|
fn update_frame(&mut self, width: u32, height: u32, bitmap: &mut [u32]);
|
2021-10-22 04:55:27 +00:00
|
|
|
}
|
|
|
|
|
2021-10-31 18:00:14 +00:00
|
|
|
pub trait JoystickUpdater: Send {
|
|
|
|
fn update_joystick(&mut self, modifiers: u16);
|
|
|
|
}
|
|
|
|
|
2021-11-07 04:44:25 +00:00
|
|
|
pub trait KeyboardUpdater: Send {
|
|
|
|
fn update_keyboard(&mut self, key: Key, state: bool);
|
|
|
|
}
|
|
|
|
|
2021-10-28 04:01:18 +00:00
|
|
|
pub trait BlitableSurface {
|
|
|
|
fn set_size(&mut self, width: u32, height: u32);
|
|
|
|
fn blit<B: Iterator<Item=u32>>(&mut self, pos_x: u32, pos_y: u32, bitmap: B, width: u32, height: u32);
|
2021-11-07 04:44:25 +00:00
|
|
|
fn clear(&mut self, value: u32);
|
2021-10-28 04:01:18 +00:00
|
|
|
}
|
|
|
|
|
2021-10-31 18:00:14 +00:00
|
|
|
|