use crate::canvas::{CanvasImageHandle, Drawable, CanvasTextureHandle};
use std::sync::Arc;

pub struct CompuSprite {
    vertices: [(f32, f32); 6],
    position: (f32, f32),
    size: (f32, f32),
    color: (f32, f32, f32, f32),
    image_handle: Arc<CanvasImageHandle>,
}

impl CompuSprite {
    pub fn new(position: (f32, f32),
               size: (f32, f32),
               image_handle: Arc<CanvasImageHandle>) -> CompuSprite {
        let fsize = (size.0 as f32, size.1 as f32);

        CompuSprite {
            vertices: [
                (position.0, position.1),                     // top left
                (position.0, position.1 + fsize.1),           // bottom left
                (position.0 + fsize.0, position.1 + fsize.1), // bottom right
                (position.0, position.1),                     // top left
                (position.0 + fsize.0, position.1 + fsize.1), // bottom right
                (position.0 + fsize.0, position.1),           // top right
            ],

            position: position,
            size: size,
            color: (0.0, 0.0, 0.0, 0.0),
            image_handle: image_handle.clone(),
        }
    }
}

impl Drawable for CompuSprite {
    fn get_vertices(&self) -> Vec<(f32, f32)> {
        self.vertices.to_vec()
    }

    fn get_color(&self) -> (f32, f32, f32, f32) {
        self.color
    }

    fn get_texture_handle(&self) -> Option<Arc<CanvasTextureHandle>> {
        None
    }

    fn get_image_handle(&self) -> Option<Arc<CanvasImageHandle>> {
        Some(self.image_handle.clone())
    }
}