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 crate::{VertexTypeContainer, Move, Geom};
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
pub trait Drawable {
@ -22,7 +23,7 @@ pub trait Drawable {
/// Trait which may be inherited by objects that wish to receive events
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

@ -1,11 +1,12 @@
use std::collections::HashSet;
use winit::event::Event;
use winit::event::{Event, ElementState, MouseButton};
use crate::canvas::canvas_frame::{Drawable, Eventable};
use crate::drawables::rect::Rect;
use crate::drawables::sprite::Sprite;
use crate::util::vertex::VertexTypeContainer;
use crate::util::tr_event::{TrEvent, TrWindowEvent};
#[derive(Debug, Clone)]
pub struct Slider {
@ -43,6 +44,26 @@ impl Slider {
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 {
@ -85,7 +106,24 @@ impl Drawable for Slider {
}
impl<T> Eventable<T> for Slider {
fn notify(&mut self, event: &Event<T>) -> () {
unimplemented!()
fn notify(&mut self, event: &TrEvent<T>) -> () {
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::util::vertex::{VertexTypeContainer, TextureVertex3D, Vertex3D};
use winit::event::{DeviceEvent, MouseButton, ElementState, Event, WindowEvent};
use crate::util::tr_event::{TrEvent, TrWindowEvent};
///
#[derive(Debug, Clone)]
@ -85,9 +86,9 @@ impl Drawable for Sprite {
}
impl<T> Eventable<T> for Sprite {
fn notify(&mut self, event: &Event<T>) -> () {
fn notify(&mut self, event: &TrEvent<T>) -> () {
match event {
Event::WindowEvent { event: WindowEvent::MouseInput { device_id, state, button, modifiers }, .. } => {
TrEvent::WindowEvent { event: TrWindowEvent::MouseInput { device_id, state, button, modifiers }, .. } => {
match button {
MouseButton::Left => {
if *state == ElementState::Pressed {

@ -141,11 +141,14 @@ impl<'a> System<'a> for EventSystem {
WriteStorage<'a, Draws>,
Write<'a, PersistentState>,
Write<'a, VkProcessor>,
Write<'a, Vec<TrEvent<TrEventExtension>>>
);
fn run(&mut self, (mut draw, mut state, mut vk_processor): Self::SystemData) {
for draw_data in (&draw).join() {
//draw_data.1.notify()
fn run(&mut self, (mut draw, mut state, mut vk_processor, event_stack): Self::SystemData) {
for draw_data in (&mut draw).join() {
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
let mut dispatcher = DispatcherBuilder::new()
// .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();
@ -306,12 +310,22 @@ pub fn main() {
world.write_resource::<PersistentState>()
.window_size = surface.window().inner_size().into();
} else {
// println!("{}", world.write_resource::<Vec<TrEvent<TrEventExtension>>>().len());
world.write_resource::<Vec<TrEvent<TrEventExtension>>>().clear();
}
}
Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => {
*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), .. } => {
world.write_resource::<VkProcessor>()
.swapchain_recreate_needed = true;

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

Loading…
Cancel
Save