event system needs some thinkin

This commit is contained in:
2020-08-11 00:09:58 -07:00
parent 9eed836083
commit 2e33c9c75e
9 changed files with 202 additions and 157 deletions

View File

@@ -8,16 +8,17 @@ use winit::event::{DeviceEvent, MouseButton, ElementState, Event, WindowEvent};
///
#[derive(Debug, Clone)]
pub struct Sprite {
pub position: (f32, f32),
pub size: (f32, f32),
depth: f32,
texture_handle: Arc<CanvasTextureHandle>,
}
/// Container class which implements drawable.
impl Sprite {
fn generate_verts(window_size: (u32, u32), position: (f32, f32), size: (f32, f32), depth: f32) -> Vec<TextureVertex3D> {
fn generate_verts(
window_size: (u32, u32),
position: (f32, f32),
size: (f32, f32),
depth: f32,
) -> Vec<TextureVertex3D> {
let ss_position = (
position.0 / window_size.0 as f32 - 1.0,
position.1 / window_size.1 as f32 - 1.0
@@ -57,28 +58,27 @@ impl Sprite {
}
///
pub fn new(position: (f32, f32),
size: (f32, f32),
depth: u32,
texture_handle: Arc<CanvasTextureHandle>) -> Sprite {
let normalized_depth = (depth as f32 / 255.0);
pub fn new(texture_handle: Arc<CanvasTextureHandle>) -> Sprite {
Sprite {
position: position,
size: size,
depth: normalized_depth,
texture_handle: texture_handle.clone(),
}
}
}
impl Drawable for Sprite {
fn get(&self, window_size: (u32, u32)) -> Vec<VertexTypeContainer> {
fn get(&self,
window_size: (u32, u32),
position: (f32, f32),
rotation: f32,
size: (f32, f32),
depth: f32,
) -> Vec<VertexTypeContainer> {
let normalized_depth = (depth / 255.0);
vec![
VertexTypeContainer::TextureType(
Sprite::generate_verts(window_size, self.position, self.size, self.depth),
Sprite::generate_verts(window_size, position, size, normalized_depth),
self.texture_handle.clone())
]
}
@@ -91,7 +91,7 @@ impl<T> Eventable<T> for Sprite {
match button {
MouseButton::Left => {
if *state == ElementState::Pressed {
self.position = (self.position.0, self.position.1 + 0.1);
}
}
_ => {}
@@ -103,7 +103,5 @@ impl<T> Eventable<T> for Sprite {
}
impl Updatable for Sprite {
fn update(&mut self, delta_time: f32) -> () {
}
fn update(&mut self, delta_time: f32) -> () {}
}