use super::{
Colour,
graphics::{
Graphics,
TexturedVertex2D,
DependentObject,
},
};
mod texture;
pub use texture::{Texture,TextureCreationResult};
use glium::{
DrawError,
draw_parameters::DrawParameters,
index::PrimitiveType,
};
#[derive(Clone)]
pub struct ImageBase{
pub x1:f32,
pub y1:f32,
pub x2:f32,
pub y2:f32,
pub colour_filter:Colour,
}
impl ImageBase{
pub fn new(colour_filter:Colour,rect:[f32;4])->ImageBase{
Self{
x1:rect[0],
y1:rect[1],
x2:rect[0]+rect[2],
y2:rect[1]+rect[3],
colour_filter,
}
}
pub fn set_rect(&mut self,rect:[f32;4]){
self.x1=rect[0];
self.y1=rect[1];
self.x2=rect[0]+rect[2];
self.y2=rect[1]+rect[3];
}
pub fn shift(&mut self,[dx,dy]:[f32;2]){
self.x1+=dx;
self.y1+=dy;
self.x2+=dx;
self.y2+=dy;
}
#[cfg(feature="texture_graphics")]
#[inline(always)]
pub fn draw(
&self,
texture:&Texture,
draw_parameters:&mut DrawParameters,
graphics:&mut Graphics
)->Result<(),DrawError>{
graphics.draw_texture(self,texture,draw_parameters)
}
#[cfg(feature="texture_graphics")]
#[inline(always)]
pub fn draw_shift(
&self,
texture:&Texture,
shift:[f32;2],
draw_parameters:&mut DrawParameters,
graphics:&mut Graphics
)->Result<(),DrawError>{
graphics.draw_shift_texture(self,texture,shift,draw_parameters)
}
#[cfg(feature="texture_graphics")]
#[inline(always)]
pub fn draw_rotate(
&self,
texture:&Texture,
rotation_center:[f32;2],
angle:f32,
draw_parameters:&mut DrawParameters,
graphics:&mut Graphics
)->Result<(),DrawError>{
graphics.draw_rotate_texture(self,texture,rotation_center,angle,draw_parameters)
}
}
impl<'o> DependentObject<'o,TexturedVertex2D,u8> for ImageBase{
type Vertices=[TexturedVertex2D;4];
type Indices=[u8;1];
fn colour(&self)->Colour{
self.colour_filter
}
fn vertices(&self)->Self::Vertices{
[
TexturedVertex2D::new([self.x1,self.y1],[0.0,1.0]),
TexturedVertex2D::new([self.x1,self.y2],[0.0,0.0]),
TexturedVertex2D::new([self.x2,self.y1],[1.0,1.0]),
TexturedVertex2D::new([self.x2,self.y2],[1.0,0.0])
]
}
fn indices(&self)->Option<Self::Indices>{
None
}
fn primitive_type(&self)->PrimitiveType{
PrimitiveType::TriangleStrip
}
}