mod button;
mod sprite;
mod text;
pub use self::button::{Button, ButtonState, Flat, Image};
pub use self::sprite::Sprite;
pub use self::text::Label;
use std::any::Any;
use super::resources::*;
pub enum ControlType {
Button,
Label,
Sprite,
}
pub struct ControlState {
pub mouse_pos: (i32, i32),
pub mouse_down: bool,
}
impl ControlState {
pub fn mouse_collision(&self, pos: (i32, i32), size: (i32, i32)) -> bool {
self.mouse_pos.0 >= pos.0
&& self.mouse_pos.1 >= pos.1
&& self.mouse_pos.0 < pos.0 + size.0
&& self.mouse_pos.1 < pos.1 + size.1
}
}
impl Default for ControlState {
fn default() -> Self {
ControlState {
mouse_pos: (0, 0),
mouse_down: false,
}
}
}
pub trait Control {
fn update(&mut self, args: &ControlState, res: &Resources);
fn draw(&self, buffer: &mut Vec<u32>, buffer_width: usize, res: &Resources);
fn control_type(&self) -> ControlType;
fn as_any(&self) -> &dyn Any;
fn as_any_mut(&mut self) -> &mut dyn Any;
}