|
|
|
@ -1,10 +1,11 @@
|
|
|
|
|
use crate::canvas::canvas_state::{Drawable, CanvasTextureHandle, CanvasImageHandle, DrawableTest};
|
|
|
|
|
use crate::canvas::canvas_state::{Drawable, CanvasTextureHandle, CanvasImageHandle, DrawableTest, CanvasFontHandle};
|
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
use crate::canvas::shader::text_shader::GlyphInstance;
|
|
|
|
|
use crate::canvas::canvas_buffer::CanvasFont;
|
|
|
|
|
use crate::util::vertex_3d::Vertex3D;
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
pub struct Sprite {
|
|
|
|
|
|
|
|
|
|
pub vertices: [(f32, f32, f32); 6],
|
|
|
|
|
pub ti_position: [(f32, f32); 6],
|
|
|
|
|
|
|
|
|
@ -20,7 +21,6 @@ pub struct Sprite {
|
|
|
|
|
|
|
|
|
|
/// Container class which implements drawable.
|
|
|
|
|
impl Sprite {
|
|
|
|
|
|
|
|
|
|
pub fn new(position: (f32, f32), size: (f32, f32)) -> Sprite {
|
|
|
|
|
Sprite::new_with_color(position, size, 0, (0., 0., 0., 0.))
|
|
|
|
|
}
|
|
|
|
@ -29,7 +29,6 @@ impl Sprite {
|
|
|
|
|
size: (f32, f32),
|
|
|
|
|
depth: u32,
|
|
|
|
|
color: (f32, f32, f32, f32)) -> Sprite {
|
|
|
|
|
|
|
|
|
|
let normalized_depth = (depth as f32 / 255.0);
|
|
|
|
|
|
|
|
|
|
Sprite {
|
|
|
|
@ -59,8 +58,8 @@ impl Sprite {
|
|
|
|
|
screen_position: (0.0, 0.0),
|
|
|
|
|
atlas_position: (0.0, 0.0),
|
|
|
|
|
atlas_size: (0.0, 0.0),
|
|
|
|
|
scale: 0.0
|
|
|
|
|
}
|
|
|
|
|
scale: 0.0,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -69,7 +68,6 @@ impl Sprite {
|
|
|
|
|
size: (f32, f32),
|
|
|
|
|
depth: u32,
|
|
|
|
|
texture_handle: Arc<CanvasTextureHandle>) -> Sprite {
|
|
|
|
|
|
|
|
|
|
let normalized_depth = (depth as f32 / 255.0);
|
|
|
|
|
|
|
|
|
|
Sprite {
|
|
|
|
@ -93,17 +91,15 @@ impl Sprite {
|
|
|
|
|
size: size,
|
|
|
|
|
color: (1.0, 0.0, 0.0, 1.0),
|
|
|
|
|
textured: true,
|
|
|
|
|
texture_handle: Some(texture_handle.clone())
|
|
|
|
|
texture_handle: Some(texture_handle.clone()),
|
|
|
|
|
value: Default::default(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<V, H> DrawableTest<V, H> for Sprite {
|
|
|
|
|
fn get_vertices(&self) -> Vec<V> {
|
|
|
|
|
|
|
|
|
|
unimplemented!()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn get_handle(&self) -> Vec<H> {
|
|
|
|
@ -112,7 +108,6 @@ impl<V, H> DrawableTest<V, H> for Sprite {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Drawable for Sprite {
|
|
|
|
|
|
|
|
|
|
fn get_vertices(&self) -> Vec<(f32, f32, f32)> {
|
|
|
|
|
self.vertices.to_vec()
|
|
|
|
|
}
|
|
|
|
@ -129,7 +124,7 @@ impl Drawable for Sprite {
|
|
|
|
|
match self.textured {
|
|
|
|
|
true => {
|
|
|
|
|
self.texture_handle.clone()
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
false => None,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -142,7 +137,6 @@ impl Drawable for Sprite {
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
pub struct Poly {
|
|
|
|
|
|
|
|
|
|
pub vertices: Vec<(f32, f32, f32)>,
|
|
|
|
|
pub ti_position: Vec<(f32, f32)>,
|
|
|
|
|
|
|
|
|
@ -154,13 +148,10 @@ pub struct Poly {
|
|
|
|
|
texture_handle: Option<Arc<CanvasTextureHandle>>,
|
|
|
|
|
|
|
|
|
|
// ==================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Container class which implements drawable.
|
|
|
|
|
impl Poly {
|
|
|
|
|
|
|
|
|
|
pub fn new(position: (f32, f32), size: (f32, f32)) -> Poly {
|
|
|
|
|
Poly::new_with_color(position, size, 0, (0., 0., 0., 0.))
|
|
|
|
|
}
|
|
|
|
@ -169,7 +160,6 @@ impl Poly {
|
|
|
|
|
size: (f32, f32),
|
|
|
|
|
depth: u32,
|
|
|
|
|
color: (f32, f32, f32, f32)) -> Poly {
|
|
|
|
|
|
|
|
|
|
let normalized_depth = (depth as f32 / 255.0);
|
|
|
|
|
|
|
|
|
|
Poly {
|
|
|
|
@ -177,31 +167,24 @@ impl Poly {
|
|
|
|
|
(-0.5, -0.5, normalized_depth),
|
|
|
|
|
(-1.0, 1.0, normalized_depth),
|
|
|
|
|
(-0.25, 0.0, normalized_depth),
|
|
|
|
|
|
|
|
|
|
(-0.25, 0.0, normalized_depth),
|
|
|
|
|
(-1.0, 1.0, normalized_depth),
|
|
|
|
|
(0.0, 0.5, normalized_depth),
|
|
|
|
|
|
|
|
|
|
(0.25, 0.0, normalized_depth),
|
|
|
|
|
(-1.0, 1.0, normalized_depth),
|
|
|
|
|
(0.0, 0.5, normalized_depth),
|
|
|
|
|
|
|
|
|
|
(0.5, -0.5, normalized_depth),
|
|
|
|
|
(-1.0, 1.0, normalized_depth),
|
|
|
|
|
(0.25, 0.0, normalized_depth),
|
|
|
|
|
|
|
|
|
|
(0.25, -0.5, normalized_depth),
|
|
|
|
|
(-1.0, 1.0, normalized_depth),
|
|
|
|
|
(0.5, -0.5, normalized_depth),
|
|
|
|
|
|
|
|
|
|
(0.25, -0.5, normalized_depth),
|
|
|
|
|
(-1.0, 1.0, normalized_depth),
|
|
|
|
|
(0.0, -0.1, normalized_depth),
|
|
|
|
|
|
|
|
|
|
(-0.25, -0.5, normalized_depth),
|
|
|
|
|
(-1.0, 1.0, normalized_depth),
|
|
|
|
|
(0.0, -0.1, normalized_depth),
|
|
|
|
|
|
|
|
|
|
(-0.5, -0.5, normalized_depth),
|
|
|
|
|
(-1.0, 1.0, normalized_depth),
|
|
|
|
|
(-0.25, -0.5, normalized_depth),
|
|
|
|
@ -237,13 +220,12 @@ impl Poly {
|
|
|
|
|
size: size,
|
|
|
|
|
color: color,
|
|
|
|
|
textured: false,
|
|
|
|
|
texture_handle: None
|
|
|
|
|
texture_handle: None,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Drawable for Poly {
|
|
|
|
|
|
|
|
|
|
fn get_vertices(&self) -> Vec<(f32, f32, f32)> {
|
|
|
|
|
self.vertices.to_vec()
|
|
|
|
|
}
|
|
|
|
@ -260,7 +242,7 @@ impl Drawable for Poly {
|
|
|
|
|
match self.textured {
|
|
|
|
|
true => {
|
|
|
|
|
self.texture_handle.clone()
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
false => None,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -272,74 +254,43 @@ impl Drawable for Poly {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
pub struct Poly {
|
|
|
|
|
|
|
|
|
|
pub vertices: Vec<(f32, f32, f32)>,
|
|
|
|
|
pub ti_position: Vec<(f32, f32)>,
|
|
|
|
|
|
|
|
|
|
position: (f32, f32),
|
|
|
|
|
size: (f32, f32),
|
|
|
|
|
pub struct Text {
|
|
|
|
|
position: (f32, f32, f32),
|
|
|
|
|
scale: f32,
|
|
|
|
|
color: (f32, f32, f32, f32),
|
|
|
|
|
|
|
|
|
|
textured: bool,
|
|
|
|
|
texture_handle: Option<Arc<CanvasTextureHandle>>,
|
|
|
|
|
|
|
|
|
|
// ==================================
|
|
|
|
|
|
|
|
|
|
text_handle: Arc<CanvasFontHandle>,
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Container class which implements drawable.
|
|
|
|
|
impl Poly {
|
|
|
|
|
|
|
|
|
|
pub fn new(position: (f32, f32), size: (f32, f32)) -> Poly {
|
|
|
|
|
Poly::new_with_color(position, size, 0, (0.,0.,0.,0.))
|
|
|
|
|
impl Text {
|
|
|
|
|
pub fn new(position: (f32, f32), size: (f32, f32), font_handle: Arc<CanvasFontHandle>) -> Text {
|
|
|
|
|
Text::new_with_color(position, size, 0, (0., 0., 0., 0.), font_handle)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn new_with_color(position: (f32, f32),
|
|
|
|
|
size: (f32, f32),
|
|
|
|
|
depth: u32,
|
|
|
|
|
color: (f32, f32, f32, f32)) -> Poly {
|
|
|
|
|
|
|
|
|
|
color: (f32, f32, f32, f32),
|
|
|
|
|
handle: Arc<CanvasFontHandle>) -> Text {
|
|
|
|
|
let normalized_depth = (depth as f32 / 255.0);
|
|
|
|
|
|
|
|
|
|
Poly {
|
|
|
|
|
vertices: vec![],
|
|
|
|
|
|
|
|
|
|
position: position,
|
|
|
|
|
ti_position: vec![],
|
|
|
|
|
size: size,
|
|
|
|
|
color: color,
|
|
|
|
|
textured: false,
|
|
|
|
|
texture_handle: None
|
|
|
|
|
Text {
|
|
|
|
|
position: (position.0, position.1, normalized_depth),
|
|
|
|
|
scale: 0.0,
|
|
|
|
|
color,
|
|
|
|
|
text_handle: handle,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Drawable for Poly {
|
|
|
|
|
|
|
|
|
|
fn get_vertices(&self) -> Vec<(f32,f32,f32)> {
|
|
|
|
|
self.vertices.to_vec()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn get_color(&self) -> (f32, f32, f32, f32) {
|
|
|
|
|
self.color.clone()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn get_ti_coords(&self) -> Vec<(f32, f32)> {
|
|
|
|
|
self.ti_position.to_vec()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn get_texture_handle(&self) -> Option<Arc<CanvasTextureHandle>> {
|
|
|
|
|
match self.textured {
|
|
|
|
|
true => {
|
|
|
|
|
self.texture_handle.clone()
|
|
|
|
|
},
|
|
|
|
|
false => None,
|
|
|
|
|
}
|
|
|
|
|
impl<V, H> DrawableTest<V, H> for Text {
|
|
|
|
|
fn get_vertices(&self) -> Vec<V> {
|
|
|
|
|
unimplemented!()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn get_image_handle(&self) -> Option<Arc<CanvasImageHandle>> {
|
|
|
|
|
None
|
|
|
|
|
fn get_handle(&self) -> Vec<H> {
|
|
|
|
|
unimplemented!()
|
|
|
|
|
}
|
|
|
|
|
}
|