use crate::engine::d2::animation::AnimatedFloat;
use super::{Graphics, Sprite};
#[derive(Default, Clone, Debug)]
pub struct FillSprite {
pub inner: Sprite,
pub color: i32,
pub width: AnimatedFloat,
pub height: AnimatedFloat,
}
impl FillSprite {
pub fn new(color: i32, width: f32, height: f32) -> Self {
Self {
inner: Sprite::new(),
color,
width: AnimatedFloat::new(width, None),
height: AnimatedFloat::new(height, None),
}
}
pub fn draw(&self, gfx: &Box<dyn Graphics>) {
gfx.fill_rect(self.color, 0.0, 0.0, self.width.get(), self.height.get());
}
pub fn natural_width(&self) -> f32 {
self.width.get()
}
pub fn natural_height(&self) -> f32 {
self.height.get()
}
pub fn set_size(&mut self, width: f32, height: f32) -> &Self {
self.width.set(width);
self.height.set(height);
self
}
pub fn on_update(&mut self, dt: f32) {
self.inner.on_update(dt);
self.width.update(dt);
self.height.update(dt);
}
}
impl AsRef<Sprite> for FillSprite {
fn as_ref(&self) -> &Sprite {
&self.inner
}
}