1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use crate::drawing::Renderable;
use crate::image::Image;
use crate::Graphics;
use graphics_shapes::coord::Coord;

pub struct RenderableImage {
    image: Image,
    xy: Coord,
}

impl RenderableImage {
    pub fn new(image: Image, xy: Coord) -> Self {
        Self { image, xy }
    }
}

impl RenderableImage {
    pub fn set_position<P: Into<Coord>>(&mut self, new_position: P) {
        self.xy = new_position.into();
    }

    pub fn update_position<P: Into<Coord>>(&mut self, delta: P) {
        self.xy = self.xy + delta.into();
    }
}

impl Renderable for RenderableImage {
    fn render(&self, graphics: &mut Graphics) {
        graphics.draw_image(self.xy, &self.image);
    }
}