iv/src/io.rs
Steins7 e3fdbb142c Got the Controller working
* reworked iput system again
+ added test functions
2021-01-18 10:29:08 +01:00

85 lines
2.9 KiB
Rust

#[allow(unused_imports)]
use log::{debug, error, info, trace, warn};
use std::time::Duration;
use raw_window_handle::HasRawWindowHandle;
use crate::utils::Rect;
pub mod winit_window;
pub use self::winit_window::WinitWindow;
//--Output trait------------------------------------------------------------------------------------
/// A trait for the ability of a type to be used as an output by the engine.
///
/// The `Output` trait defines functions to be used by different components of the engine. This
/// allows to display with any window manager as long as the trait is defined for it.
///
/// Types that implement the `Output` trait should manage the underlying window and settings.
///
/// Implementation : the ID and size stored by the type implementing this trait don't need to be
/// initialized to anything specific as the engine will take care of it.
pub trait Output<W>
where
W: HasRawWindowHandle,
{
/// Return the ID stored internally. Used to select the right swapchain by the render engine.
/// For internal use only.
fn get_id(&self) -> usize;
/// Store the given ID internally. For internal use only.
fn set_id(&mut self, id: usize);
//TODO clean that
/// Give mutable acces to the size of the output. The size is a simple rectangle containing the
/// width and height of the `Output`.
fn size(&mut self) -> &mut Rect<i32>;
/// Give reference acces to the underlying window. This is used by the engine during setup to
/// create the revelant ressources.
fn window(&self) -> &W;
}
//--Input trait-------------------------------------------------------------------------------------
/// A trait for the ability of a type to be used as an input by the engine
///
/// The `Input` trait defines functions used by different components of the engine. The allow to
/// read inputs from any window manzger as long as the is defined for it.
///
/// Types that implement the `Input` trait should manage the EventLoop. This can be done in any way
/// (polling, interrupt, synchronous, asynchronous, ...) depending on how the input should be
/// handled.
pub trait Input {
/// Return the next input available or a ReadError if an error occured of the timeout duration
/// was reached. How inputs are handled depends on the implementation.
//TODO change timeout
fn read(&self, timeout: Duration) -> Result<Key, ReadError>;
fn write(&self, signal: Signal);
}
//--Key enum----------------------------------------------------------------------------------------
#[derive(Debug)]
pub enum Key {
Close,
Closed,
Test,
MouseMove { x: f64, y: f64 },
}
//--Signal enum-------------------------------------------------------------------------------------
#[derive(Debug)]
pub enum Signal {
Exit,
Test,
}
//--ReadError enum----------------------------------------------------------------------------------
#[derive(Debug)]
pub enum ReadError {
Timeout,
}