events are coming in. But my dual box thingy is not gonna be the way to go here. I guess it copied the data and they no longer link. Bummer

a-star
mitchellhansen 4 years ago
parent 9719675465
commit 28565652c0

@ -8,6 +8,7 @@ use vulkano::pipeline::vertex::Vertex;
use std::any::Any; use std::any::Any;
use crate::{VertexTypeContainer, Move, Geom}; use crate::{VertexTypeContainer, Move, Geom};
use winit::event::Event; use winit::event::Event;
use crate::util::tr_event::TrEvent;
/// Trait which may be inherited by objects that wish to be drawn to the screen /// Trait which may be inherited by objects that wish to be drawn to the screen
pub trait Drawable { pub trait Drawable {
@ -22,7 +23,7 @@ pub trait Drawable {
/// Trait which may be inherited by objects that wish to receive events /// Trait which may be inherited by objects that wish to receive events
pub trait Eventable<T> { pub trait Eventable<T> {
fn notify(&mut self, event: &Event<T>) -> (); fn notify(&mut self, event: &TrEvent<T>) -> ();
} }
/// Trait which may be inherited by objects that wish to be updated /// Trait which may be inherited by objects that wish to be updated

@ -1,11 +1,12 @@
use std::collections::HashSet; use std::collections::HashSet;
use winit::event::Event; use winit::event::{Event, ElementState, MouseButton};
use crate::canvas::canvas_frame::{Drawable, Eventable}; use crate::canvas::canvas_frame::{Drawable, Eventable};
use crate::drawables::rect::Rect; use crate::drawables::rect::Rect;
use crate::drawables::sprite::Sprite; use crate::drawables::sprite::Sprite;
use crate::util::vertex::VertexTypeContainer; use crate::util::vertex::VertexTypeContainer;
use crate::util::tr_event::{TrEvent, TrWindowEvent};
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Slider { pub struct Slider {
@ -43,6 +44,26 @@ impl Slider {
value, value,
} }
} }
pub fn update(&mut self) {
// render the guide first
let red = (1.0, 0.0, 0.0, 0.0);
let green = (0.0, 1.0, 0.0, 0.0);
let blue = (0.0, 1.0, 1.0, 0.0);
let rg = (1.0, 1.0, 0.0, 0.0);
let left_guide_bar = Rect::new((self.position.0, self.position.1), (2.0, self.size.1), 1, red);
let right_guide_bar = Rect::new((self.position.0 + self.size.0, self.position.1), (2.0, self.size.1), 1, blue);
let line = Rect::new((self.position.0, self.position.1 - (self.size.1 / 2.0)), (self.size.0, 2.0), 1, green);
let scale = self.value as f32 / u16::max_value() as f32;
let handle = Rect::new((self.position.0 + (self.size.0 * scale), self.position.1), (15.0, self.size.1), 1, rg);
self.handle = handle;
self.guide = vec![left_guide_bar, right_guide_bar, line];
self.scaler = 255;
}
} }
impl Drawable for Slider { impl Drawable for Slider {
@ -85,7 +106,24 @@ impl Drawable for Slider {
} }
impl<T> Eventable<T> for Slider { impl<T> Eventable<T> for Slider {
fn notify(&mut self, event: &Event<T>) -> () { fn notify(&mut self, event: &TrEvent<T>) -> () {
unimplemented!() match event {
TrEvent::WindowEvent { event: TrWindowEvent::MouseInput { device_id, state, button, modifiers }, .. } => {
match button {
MouseButton::Left => {
if *state == ElementState::Pressed {
self.position.0 += 30.0;
self.value += 10;
self.update()
}
}
_ => {}
}
}
_ => {}
}
} }
} }

@ -4,6 +4,7 @@ use crate::canvas::managed::handles::{CanvasFontHandle, CanvasImageHandle, Canva
use crate::canvas::canvas_frame::{Drawable, Eventable, Updatable}; use crate::canvas::canvas_frame::{Drawable, Eventable, Updatable};
use crate::util::vertex::{VertexTypeContainer, TextureVertex3D, Vertex3D}; use crate::util::vertex::{VertexTypeContainer, TextureVertex3D, Vertex3D};
use winit::event::{DeviceEvent, MouseButton, ElementState, Event, WindowEvent}; use winit::event::{DeviceEvent, MouseButton, ElementState, Event, WindowEvent};
use crate::util::tr_event::{TrEvent, TrWindowEvent};
/// ///
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
@ -85,9 +86,9 @@ impl Drawable for Sprite {
} }
impl<T> Eventable<T> for Sprite { impl<T> Eventable<T> for Sprite {
fn notify(&mut self, event: &Event<T>) -> () { fn notify(&mut self, event: &TrEvent<T>) -> () {
match event { match event {
Event::WindowEvent { event: WindowEvent::MouseInput { device_id, state, button, modifiers }, .. } => { TrEvent::WindowEvent { event: TrWindowEvent::MouseInput { device_id, state, button, modifiers }, .. } => {
match button { match button {
MouseButton::Left => { MouseButton::Left => {
if *state == ElementState::Pressed { if *state == ElementState::Pressed {

@ -141,11 +141,14 @@ impl<'a> System<'a> for EventSystem {
WriteStorage<'a, Draws>, WriteStorage<'a, Draws>,
Write<'a, PersistentState>, Write<'a, PersistentState>,
Write<'a, VkProcessor>, Write<'a, VkProcessor>,
Write<'a, Vec<TrEvent<TrEventExtension>>>
); );
fn run(&mut self, (mut draw, mut state, mut vk_processor): Self::SystemData) { fn run(&mut self, (mut draw, mut state, mut vk_processor, event_stack): Self::SystemData) {
for draw_data in (&draw).join() { for draw_data in (&mut draw).join() {
//draw_data.1.notify() for event in event_stack.iter() {
draw_data.1.notify(event)
}
} }
} }
} }
@ -259,7 +262,8 @@ pub fn main() {
// call the run method for the following systems & deps // call the run method for the following systems & deps
let mut dispatcher = DispatcherBuilder::new() let mut dispatcher = DispatcherBuilder::new()
// .with(SysA, "sys_a", &[]) // .with(SysA, "sys_a", &[])
.with(RenderSystem, "render_s", &[]).build(); .with(EventSystem, "event_s", &[])
.with(RenderSystem, "render_s", &["event_s"]).build();
let event_loop_proxy = events_loop.create_proxy(); let event_loop_proxy = events_loop.create_proxy();
@ -306,12 +310,22 @@ pub fn main() {
world.write_resource::<PersistentState>() world.write_resource::<PersistentState>()
.window_size = surface.window().inner_size().into(); .window_size = surface.window().inner_size().into();
} else { } else {
// println!("{}", world.write_resource::<Vec<TrEvent<TrEventExtension>>>().len());
world.write_resource::<Vec<TrEvent<TrEventExtension>>>().clear(); world.write_resource::<Vec<TrEvent<TrEventExtension>>>().clear();
} }
} }
Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => { Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => {
*control_flow = ControlFlow::Exit *control_flow = ControlFlow::Exit
} }
Event::WindowEvent { event: WindowEvent::MouseInput { device_id, state, button, modifiers }, .. } => {
match button {
MouseButton::Left => {
if state == ElementState::Pressed {
}
}
_ => {}
}
}
Event::WindowEvent { event: WindowEvent::Resized(new_size), .. } => { Event::WindowEvent { event: WindowEvent::Resized(new_size), .. } => {
world.write_resource::<VkProcessor>() world.write_resource::<VkProcessor>()
.swapchain_recreate_needed = true; .swapchain_recreate_needed = true;

@ -16,7 +16,7 @@ pub enum TrEventExtension {
}, },
} }
#[derive(Clone)] #[derive(Clone, Debug)]
pub enum TrEvent<T> { pub enum TrEvent<T> {
/// Custom events here /// Custom events here

Loading…
Cancel
Save