use std::time::Duration;
#[derive(Debug, Clone)]
pub struct MouseEvent {
pub button: MouseButton,
pub state: ElementState,
pub position: Vec2,
}
#[derive(Debug, Clone)]
pub enum ElementState {
Pressed,
Released,
}
#[derive(Debug, Clone)]
pub struct KeyboardInput {
pub state: ElementState,
}
#[derive(Debug, Clone)]
pub struct Vec2 {
pub x: f32,
pub y: f32,
}
impl Vec2 {
pub fn new(x: f32, y: f32) -> Self {
Self { x, y }
}
}
#[derive(Debug, Clone)]
pub enum MouseButton {
Left,
Right,
Middle,
Other(u16), }
#[derive(Debug, Clone)]
pub struct Texture {
pub width: u32,
pub height: u32,
pub format: TextureFormat,
pub data: Vec<u8>,
}
impl Texture {
pub fn buffer_size(&self) -> usize {
self.width as usize * self.height as usize * self.format.n_channels()
}
}
#[derive(Debug, Clone, PartialEq)]
pub enum TextureFormat {
Rgb8,
Rgba8,
}
impl TextureFormat {
pub fn n_channels(&self) -> usize {
match self {
TextureFormat::Rgb8 => 3,
TextureFormat::Rgba8 => 4,
}
}
}
pub enum TickMode {
Immediate,
WaitFor(Duration),
PeriodicWait(PeriodicWait),
}
impl TickMode {
pub fn wait(duration: Duration) -> Self {
Self::WaitFor(duration)
}
pub fn periodic_60hz(duration: Duration) -> Self {
Self::periodic(
duration,
Duration::from_micros(((1000.0 / 60.) * 1000.0) as u64),
)
}
pub fn periodic(duration: Duration, tick_interval: Duration) -> Self {
Self::PeriodicWait(PeriodicWait {
duration,
tick_interval,
})
}
}
pub struct PeriodicWait {
pub duration: Duration,
pub tick_interval: Duration,
}
#[derive(Clone, Debug)]
pub struct WindowSize {
pub width: u32,
pub height: u32,
}
impl WindowSize {
pub fn new(width: u32, height: u32) -> Self {
WindowSize { width, height }
}
}
impl Default for WindowSize {
fn default() -> Self {
Self {
width: 800,
height: 600,
}
}
}