this is a week or so worth of brainstorming. Looking at pulling everything sprite related into it's own little struct. And also doing a message everything arch

This commit is contained in:
2020-09-14 21:27:00 -07:00
parent a42d23e5f9
commit 369a305817
13 changed files with 242 additions and 188 deletions

View File

@@ -1,15 +1,31 @@
use std::sync::Arc;
use crate::canvas::*;
use crate::canvas::managed::handles::{CanvasFontHandle, CanvasImageHandle, CanvasTextureHandle, Handle};
use crate::canvas::canvas_frame::{Drawable, Eventable, Updatable};
use crate::canvas::canvas_frame::{Drawable};
use crate::util::vertex::{VertexTypeContainer, TextureVertex3D, Vertex3D};
use winit::event::{DeviceEvent, MouseButton, ElementState, Event, WindowEvent};
use crate::util::tr_event::{TrEvent, TrWindowEvent};
use crate::util::tr_event::{TrEvent, TrWindowEvent, TrUIEvent};
pub struct Geometry {
pos_x: f32,
pos_y: f32,
size_x: f32,
size_y: f32,
rotation: f32,
depth: f32,
}
pub struct Velocity {
vel_x: f32,
vel_y: f32,
vel_r: f32,
}
///
#[derive(Debug, Clone)]
pub struct Sprite {
texture_handle: Arc<CanvasTextureHandle>,
geometry: Geometry,
velocity: Velocity,
}
/// Container class which implements drawable.
@@ -62,18 +78,31 @@ impl Sprite {
pub fn new(texture_handle: Arc<CanvasTextureHandle>) -> Sprite {
Sprite {
texture_handle: texture_handle.clone(),
geometry: Geometry {
pos_x: 0.0,
pos_y: 0.0,
size_x: 0.0,
size_y: 0.0,
rotation: 0.0,
depth: 0.0
},
velocity: Velocity {
vel_x: 0.0,
vel_y: 0.0,
vel_r: 0.0
}
}
}
}
impl Drawable for Sprite {
fn get(&self,
window_size: (u32, u32),
position: (f32, f32),
rotation: f32,
size: (f32, f32),
depth: f32,
fn render(&self,
window_size: (u32, u32),
position: (f32, f32),
rotation: f32,
size: (f32, f32),
depth: f32,
) -> Vec<VertexTypeContainer> {
let normalized_depth = (depth / 255.0);
@@ -83,11 +112,13 @@ impl Drawable for Sprite {
self.texture_handle.clone())
]
}
}
impl<T> Eventable<T> for Sprite {
fn notify(&mut self, event: &TrEvent<T>) -> () {
match event {
fn update<T>(&self, delta_time: f32) -> Vec<TrUIEvent<T>> {
Vec::new()
}
fn notify<Y, T>(&self, tr_event: Vec<TrEvent<Y>>, ui_events: Vec<TrUIEvent<T>>) -> Vec<TrUIEvent<T>> {
match tr_event {
TrEvent::WindowEvent { event: TrWindowEvent::MouseInput { device_id, state, button, modifiers }, .. } => {
match button {
MouseButton::Left => {
@@ -100,9 +131,6 @@ impl<T> Eventable<T> for Sprite {
}
_ => {}
}
Vec::new()
}
}
impl Updatable for Sprite {
fn update(&mut self, delta_time: f32) -> () {}
}