event work + mulling over sprite containers and event notification

This commit is contained in:
2020-07-31 23:39:25 -07:00
parent 55899f26ad
commit 8da810f23a
10 changed files with 149 additions and 75 deletions

View File

@@ -53,7 +53,7 @@ impl CompuSprite {
}
impl Drawable for CompuSprite {
fn get(&self) -> VertexTypes {
self.verts.clone()
fn get(&self) -> Vec<VertexTypes> {
vec![self.verts.clone()]
}
}

View File

@@ -61,8 +61,8 @@ impl Polygon {
}
}
impl Drawable for Polygon {
fn get(&self) -> VertexTypes {
self.verts.clone()
fn get(&self) -> Vec<VertexTypes> {
vec![self.verts.clone()]
}
}

View File

@@ -50,8 +50,8 @@ impl Rect {
}
}
impl Drawable for Rect {
fn get(&self) -> VertexTypes {
self.verts.clone()
fn get(&self) -> Vec<VertexTypes> {
vec![self.verts.clone()]
}
}

View File

@@ -18,9 +18,7 @@ pub struct Sprite {
/// Container class which implements drawable.
impl Sprite {
fn generate_verts(position: (f32, f32), size: (f32, f32), depth: f32,) -> Vec<TextureVertex3D> {
fn generate_verts(position: (f32, f32), size: (f32, f32), depth: f32) -> Vec<TextureVertex3D> {
vec![
TextureVertex3D {
v_position: [position.0, position.1, depth], // top left
@@ -54,7 +52,6 @@ impl Sprite {
size: (f32, f32),
depth: u32,
texture_handle: Arc<CanvasTextureHandle>) -> Sprite {
let normalized_depth = (depth as f32 / 255.0);
Sprite {
@@ -68,24 +65,26 @@ impl Sprite {
}
impl Drawable for Sprite {
fn get(&self) -> VertexTypes {
VertexTypes::TextureType(Sprite::generate_verts(self.position, self.size, self.depth), self.texture_handle.clone())
fn get(&self) -> Vec<VertexTypes> {
vec![
VertexTypes::TextureType(
Sprite::generate_verts(self.position, self.size, self.depth),
self.texture_handle.clone())
]
}
}
impl<T> Eventable<T> for Sprite {
fn notify(&mut self, event: &Event<T>) -> () {
match event {
Event::WindowEvent { event: WindowEvent::MouseInput{ device_id, state, button, modifiers }, .. } => {
Event::WindowEvent { event: WindowEvent::MouseInput { device_id, state, button, modifiers }, .. } => {
match button {
MouseButton::Left => {
if *state == ElementState::Pressed {
self.position = (self.position.0, self.position.1 + 0.1);
}
},
_ => {
}
_ => {}
}
}
_ => {}

View File

@@ -137,7 +137,7 @@ impl Text {
}
impl Drawable for Text {
fn get(&self) -> VertexTypes {
self.verts.clone()
fn get(&self) -> Vec<VertexTypes> {
vec![self.verts.clone()]
}
}