event work + mulling over sprite containers and event notification
This commit is contained in:
@@ -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()]
|
||||
}
|
||||
}
|
||||
@@ -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()]
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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()]
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
|
||||
@@ -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()]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user