use crate::{
Colour,
texture::Texture,
text::{Scale,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,V,I>(&mut self,object:&O)->Option<usize>
where
O:DependentObject<
Vertex2D,
u8,
Vertices=V,
Indices=I
>,
V:AsRef<[Vertex2D]>,
I:AsRef<[u8]>
{
self.simple.push_object(object)
}
#[inline(always)]
pub fn remove_last_simple_object(&mut self){
self.simple.remove_last_object();
}
#[inline(always)]
pub fn remove_all_simple_objects(&mut self){
self.simple.clear_object_array()
}
#[inline(always)]
pub fn get_simple_object_colour(&mut self,index:usize)->&mut Colour{
self.simple.object_colour(index)
}
#[inline(always)]
pub fn get_simple_object_primitive_type(&mut self,index:usize)->&mut PrimitiveType{
self.simple.object_primitive_type(index)
}
#[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_texture(&mut self,texture:Texture)->usize{
self.texture.add_texture(texture)
}
#[inline(always)]
pub fn remove_last_texture(&mut self){
self.texture.remove_last_texture()
}
#[inline(always)]
pub fn remove_all_textures(&mut self){
self.texture.remove_all_textures()
}
#[inline(always)]
pub fn add_textured_object<O,V,I>(
&mut self,
object:&O,
texture:usize
)->Option<usize>
where
O:DependentObject<
TexturedVertex2D,
u8,
Vertices=V,
Indices=I
>,
V:AsRef<[TexturedVertex2D]>,
I:AsRef<[u8]>
{
self.texture.push_object(object,texture)
}
#[inline(always)]
pub fn remove_last_textured_object(&mut self){
self.texture.remove_last_object();
}
#[inline(always)]
pub fn removes_all_textured_objects(&mut self){
self.texture.clear_object_array()
}
#[inline(always)]
pub fn get_textured_object_colour(&mut self,index:usize)->&mut Colour{
self.texture.object_colour(index)
}
#[inline(always)]
pub fn get_textured_object_texture(&mut self,index:usize)->&mut Texture{
self.texture.object_texture(index)
}
#[inline(always)]
pub fn get_textured_object_primitive_type(&mut self,index:usize)->&mut PrimitiveType{
self.texture.object_primitive_type(index)
}
#[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)->usize{
self.text.push_font(cached_font)
}
#[inline(always)]
pub fn remove_last_font(&mut self){
self.text.remove_last_font()
}
#[inline(always)]
pub fn remove_all_fonts(&mut self){
self.text.remove_all_fonts()
}
#[inline(always)]
pub fn get_font(&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 remove_last_text_object(&mut self){
self.text.remove_last_object();
}
#[inline(always)]
pub fn remove_all_text_objects(&mut self){
self.text.clear_object_array()
}
#[inline(always)]
pub fn get_text_object_text(&mut self,index:usize)->&mut String{
self.text.object_text(index)
}
#[inline(always)]
pub fn get_text_object_colour(&mut self,index:usize)->&mut Colour{
self.text.object_colour(index)
}
#[inline(always)]
pub fn get_text_object_font(&mut self,index:usize)->&mut usize{
self.text.object_font(index)
}
#[inline(always)]
pub fn get_text_object_scale(&mut self,index:usize)->&mut Scale{
self.text.object_scale(index)
}
#[inline(always)]
pub fn get_text_object_position(&mut self,index:usize)->&mut [f32;2]{
self.text.object_position(index)
}
}