use crate::{
Colour,
texture::Texture,
text::CachedFont,
};
#[cfg(feature="text_graphics")]
use crate::text::{TextBase};
use super::{
GraphicsSettings,
DependentObject
};
mod objects;
pub (crate) use objects::{
SimpleObject2D,
TexturedObject2D,
TextObject2D,
};
pub use objects::{Vertex2D,TexturedVertex2D};
mod simple_graphics;
pub (crate) use simple_graphics::SimpleGraphics;
mod texture_graphics;
pub (crate) use texture_graphics::TextureGraphics;
#[cfg(feature="text_graphics")]
mod text_graphics;
#[cfg(feature="text_graphics")]
pub (crate) use text_graphics::TextGraphics;
use glium::{
index::PrimitiveType,
Display,
};
pub struct Graphics2D{
#[cfg(feature="texture_graphics")]
pub (crate) texture:TextureGraphics,
#[cfg(feature="simple_graphics")]
pub (crate) simple:SimpleGraphics,
#[cfg(feature="text_graphics")]
pub (crate) text:TextGraphics,
}
impl Graphics2D{
pub (crate) fn new(window:&Display,settings:GraphicsSettings,glsl:u16)->Graphics2D{
Self{
#[cfg(feature="texture_graphics")]
texture:TextureGraphics::new(window,settings.texture,glsl),
#[cfg(feature="simple_graphics")]
simple:SimpleGraphics::new(window,settings.simple,glsl),
#[cfg(feature="text_graphics")]
text:TextGraphics::new(window,settings.text,glsl),
}
}
}
#[cfg(feature="simple_graphics")]
impl Graphics2D{
#[inline(always)]
pub fn add_simple_object<'o,O,V,I>(&mut self,object:&'o O)->Option<usize>
where
O:DependentObject<
'o,
Vertex2D,
u8,
Vertices=V,
Indices=I
>,
V:AsRef<[Vertex2D]>+'o,
I:AsRef<[u8]>+'o
{
self.simple.push_object(object)
}
#[inline(always)]
pub fn delete_last_simple_object(&mut self){
self.simple.delete_last_object();
}
#[inline(always)]
pub fn clear_simple_object_array(&mut self){
self.simple.clear_object_array()
}
#[inline(always)]
pub fn get_simple_object_colour(&mut self,index:usize)->&mut Colour{
self.simple.get_object_colour(index)
}
#[inline(always)]
pub fn set_simple_object_colour(&mut self,index:usize,colour:Colour){
self.simple.set_object_colour(index,colour)
}
#[inline(always)]
pub fn set_simple_object_primitive_type(&mut self,index:usize,primitive_type:PrimitiveType){
self.simple.set_object_primitive_type(index,primitive_type)
}
#[inline(always)]
pub fn rewrite_simple_object_vertices(&mut self,index:usize,vertices:&[Vertex2D]){
self.simple.rewrite_object_vertices(index,vertices)
}
#[inline(always)]
pub fn rewrite_simple_object_indices(&mut self,index:usize,indices:&[u8]){
self.simple.rewrite_object_indices(index,indices)
}
}
#[cfg(feature="texture_graphics")]
impl Graphics2D{
#[inline(always)]
pub fn add_textured_object<'o,O,V,I>(
&mut self,
object:&'o O,
texture:Texture
)->Option<usize>
where
O:DependentObject<
'o,
TexturedVertex2D,
u8,
Vertices=V,
Indices=I
>,
V:AsRef<[TexturedVertex2D]>+'o,
I:AsRef<[u8]>+'o
{
self.texture.push_object(object,texture)
}
#[inline(always)]
pub fn delete_last_textured_object(&mut self){
self.texture.delete_last_object();
}
#[inline(always)]
pub fn clear_textured_object_array(&mut self){
self.texture.clear_object_array()
}
#[inline(always)]
pub fn get_textured_object_colour(&mut self,index:usize)->&mut Colour{
self.texture.get_object_colour(index)
}
#[inline(always)]
pub fn get_textured_object_texture(&mut self,index:usize)->&mut Texture{
self.texture.get_object_texture(index)
}
#[inline(always)]
pub fn set_textured_object_colour(&mut self,index:usize,colour:Colour){
self.texture.set_object_colour(index,colour)
}
#[inline(always)]
pub fn set_textured_object_primitive_type(&mut self,index:usize,primitive_type:PrimitiveType){
self.texture.set_object_primitive_type(index,primitive_type)
}
#[inline(always)]
pub fn rewrite_textured_object_vertices(&mut self,index:usize,vertices:&[TexturedVertex2D]){
self.texture.rewrite_object_vertices(index,vertices)
}
#[inline(always)]
pub fn rewrite_textured_object_indices(&mut self,index:usize,indices:&[u8]){
self.texture.rewrite_object_indices(index,indices)
}
}
#[cfg(feature="text_graphics")]
impl Graphics2D{
#[inline(always)]
pub fn add_font(
&mut self,
cached_font:CachedFont,
)->Option<usize>{
self.text.push_font(cached_font)
}
#[inline(always)]
pub fn get_glyph_cache(&self,index:usize)->&CachedFont{
self.text.get_font(index)
}
#[inline(always)]
pub fn add_text_object(
&mut self,
text:String,
text_base:&TextBase,
font:usize,
)->Option<usize>{
self.text.push_object(
text,
text_base.position,
text_base.scale,
text_base.colour,
font
)
}
#[inline(always)]
pub fn delete_last_text_object(&mut self){
self.text.delete_last_object();
}
}