slider rendering
This commit is contained in:
@@ -29,7 +29,9 @@ impl CanvasFrame {
|
|||||||
|
|
||||||
/// Push this drawable onto the back of the accumulator
|
/// Push this drawable onto the back of the accumulator
|
||||||
pub fn draw(&mut self, drawable: &dyn Drawable) {
|
pub fn draw(&mut self, drawable: &dyn Drawable) {
|
||||||
drawable.get().iter().map(|x| {self.map.push(x.clone())});
|
for i in drawable.get() {
|
||||||
|
self.map.push(i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,29 +17,30 @@ impl Rect {
|
|||||||
///
|
///
|
||||||
pub fn new(position: (f32, f32),
|
pub fn new(position: (f32, f32),
|
||||||
size: (f32, f32),
|
size: (f32, f32),
|
||||||
depth: u32) -> Rect {
|
depth: u32,
|
||||||
|
color: (f32, f32, f32, f32)) -> Rect {
|
||||||
|
|
||||||
let normalized_depth = (depth as f32 / 255.0);
|
let normalized_depth = (depth as f32 / 255.0);
|
||||||
|
|
||||||
let verts = vec![
|
let verts = vec![
|
||||||
ColorVertex3D{
|
ColorVertex3D{
|
||||||
v_position: [position.0, position.1, normalized_depth], // top left
|
v_position: [position.0, position.1, normalized_depth], // top left
|
||||||
color: [0.0, 1.0, 1.0, 0.5] },
|
color: [color.0, color.1, color.2, color.3] },
|
||||||
ColorVertex3D{
|
ColorVertex3D{
|
||||||
v_position: [position.0, position.1 + size.1, normalized_depth], // bottom left
|
v_position: [position.0, position.1 + size.1, normalized_depth], // bottom left
|
||||||
color: [1.0, 1.0, 1.0, 1.0] },
|
color: [color.0, color.1, color.2, color.3] },
|
||||||
ColorVertex3D{
|
ColorVertex3D{
|
||||||
v_position: [position.0 + size.0, position.1 + size.1, normalized_depth], // bottom right
|
v_position: [position.0 + size.0, position.1 + size.1, normalized_depth], // bottom right
|
||||||
color: [1.0, 1.0, 1.0, 1.0] },
|
color: [color.0, color.1, color.2, color.3] },
|
||||||
ColorVertex3D{
|
ColorVertex3D{
|
||||||
v_position: [position.0, position.1, normalized_depth], // top left
|
v_position: [position.0, position.1, normalized_depth], // top left
|
||||||
color: [1.0, 1.0, 1.0, 1.0] },
|
color: [color.0, color.1, color.2, color.3] },
|
||||||
ColorVertex3D{
|
ColorVertex3D{
|
||||||
v_position: [position.0 + size.0, position.1 + size.1, normalized_depth], // bottom right
|
v_position: [position.0 + size.0, position.1 + size.1, normalized_depth], // bottom right
|
||||||
color: [1.0, 1.0, 1.0, 1.0] },
|
color: [color.0, color.1, color.2, color.3] },
|
||||||
ColorVertex3D{
|
ColorVertex3D{
|
||||||
v_position: [position.0 + size.0, position.1, normalized_depth], // top right
|
v_position: [position.0 + size.0, position.1, normalized_depth], // top right
|
||||||
color: [1.0, 1.0, 1.0, 1.0] },
|
color: [color.0, color.1, color.2, color.3] },
|
||||||
];
|
];
|
||||||
|
|
||||||
Rect {
|
Rect {
|
||||||
|
|||||||
100
src/main.rs
100
src/main.rs
@@ -50,8 +50,9 @@ pub mod button_m {
|
|||||||
use crate::drawables::rect::Rect;
|
use crate::drawables::rect::Rect;
|
||||||
use crate::drawables::sprite::Sprite;
|
use crate::drawables::sprite::Sprite;
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use crate::canvas::canvas_frame::Drawable;
|
use crate::canvas::canvas_frame::{Drawable, Eventable};
|
||||||
use crate::util::vertex::VertexType;
|
use crate::util::vertex::VertexType;
|
||||||
|
use winit::event::Event;
|
||||||
|
|
||||||
pub struct Slider {
|
pub struct Slider {
|
||||||
handle : Rect,
|
handle : Rect,
|
||||||
@@ -68,12 +69,17 @@ pub mod button_m {
|
|||||||
|
|
||||||
// render the guide first
|
// render the guide first
|
||||||
|
|
||||||
let left_guide_bar = Rect::new((position.0 as f32, position.1 as f32), (0.1, 0.1), 1);
|
let red = (1.0, 0.0, 0.0, 0.0);
|
||||||
let right_guide_bar = Rect::new((position.0 + size.0 as f32, position.1 as f32), (0.1, 0.1), 1);
|
let green = (0.0, 1.0, 0.0, 0.0);
|
||||||
let line = Rect::new((position.0 as f32, position.1 - (size.1 / 2.0) as f32), (0.1, 0.1), 1);
|
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((position.0 as f32, position.1 as f32), (0.01, size.1), 1, red);
|
||||||
|
let right_guide_bar = Rect::new((position.0 + size.0 as f32, position.1 as f32), (0.01, size.1), 1, blue);
|
||||||
|
let line = Rect::new((position.0 as f32, position.1 - (size.1 / 2.0) as f32), (size.0, 0.01), 1, green);
|
||||||
|
|
||||||
let scale = value as f32 / u16::max_value() as f32;
|
let scale = value as f32 / u16::max_value() as f32;
|
||||||
let handle = Rect::new((position.0 + (size.0 * scale) as f32, position.1 as f32), (0.3, 0.3), 1);
|
let handle = Rect::new((position.0 + (size.0 * scale) as f32, position.1 as f32), (0.03, size.1), 1, rg);
|
||||||
|
|
||||||
|
|
||||||
Slider {
|
Slider {
|
||||||
@@ -97,6 +103,12 @@ pub mod button_m {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Eventable for Slider {
|
||||||
|
fn notify(&mut self, event: &Event<'a, _>) -> () {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
hprof::start_frame();
|
hprof::start_frame();
|
||||||
@@ -170,15 +182,15 @@ pub fn main() {
|
|||||||
|
|
||||||
let mut funky_sprite = Sprite::new((0.0, 0.5), (0.5, 0.5), 0, funky_handle.clone());
|
let mut funky_sprite = Sprite::new((0.0, 0.5), (0.5, 0.5), 0, funky_handle.clone());
|
||||||
let sfml_sprite = Sprite::new((0.0, -0.5), (0.5, 0.5), 1, sfml_handle.clone());
|
let sfml_sprite = Sprite::new((0.0, -0.5), (0.5, 0.5), 1, sfml_handle.clone());
|
||||||
let rect = Rect::new((-0.5, -0.5), (0.5, 0.5), 1);
|
|
||||||
|
|
||||||
// let slider = button_m::Slider::new((0.5, 0.1), (0.1,0.1), 30000);
|
|
||||||
|
let slider = button_m::Slider::new((0.3, 0.04), (-0.5,-0.3), 30000);
|
||||||
|
|
||||||
// how do i register a sprite to get events...
|
// how do i register a sprite to get events...
|
||||||
// explicit is much easier
|
// explicit is much easier
|
||||||
|
|
||||||
//let sfml_sprite = Sprite::new((0.0, -0.5), (0.5, 0.5), 1, sfml_handle.clone());
|
//let sfml_sprite = Sprite::new((0.0, -0.5), (0.5, 0.5), 1, sfml_handle.clone());
|
||||||
let text_sprite = Text::new((-0.1, -0.1), (10.0, 10.0), 1);
|
// let text_sprite = Text::new((-0.1, -0.1), (10.0, 10.0), 1);
|
||||||
//let test_polygon = Poly::new_with_color((-0.5, -0.5), (0.5, 0.5), 1, (1.0,0.0,0.0,0.0));
|
//let test_polygon = Poly::new_with_color((-0.5, -0.5), (0.5, 0.5), 1, (1.0,0.0,0.0,0.0));
|
||||||
|
|
||||||
drop(q2);
|
drop(q2);
|
||||||
@@ -188,40 +200,40 @@ pub fn main() {
|
|||||||
|
|
||||||
let event_loop_proxy = events_loop.create_proxy();
|
let event_loop_proxy = events_loop.create_proxy();
|
||||||
|
|
||||||
std::thread::spawn(move || {
|
// std::thread::spawn(move || {
|
||||||
|
//
|
||||||
let mut gilrs = Gilrs::new().unwrap();
|
// let mut gilrs = Gilrs::new().unwrap();
|
||||||
// Iterate over all connected gamepads
|
// // Iterate over all connected gamepads
|
||||||
let mut gamepad : Option<Gamepad> = None;
|
// let mut gamepad : Option<Gamepad> = None;
|
||||||
for (_id, gamepad_) in gilrs.gamepads() {
|
// for (_id, gamepad_) in gilrs.gamepads() {
|
||||||
if gamepad_.name() == "PS4" {
|
// if gamepad_.name() == "PS4" {
|
||||||
gamepad = Some(gamepad_);
|
// gamepad = Some(gamepad_);
|
||||||
}
|
// }
|
||||||
println!("{} is {:?} {:?}", gamepad_.name(), gamepad_.power_info(), gamepad_.id());
|
// println!("{} is {:?} {:?}", gamepad_.name(), gamepad_.power_info(), gamepad_.id());
|
||||||
}
|
// }
|
||||||
let mut active_gamepad = None;
|
// let mut active_gamepad = None;
|
||||||
|
//
|
||||||
loop {
|
// loop {
|
||||||
|
//
|
||||||
while let Some(GilEvent { id, event, time }) = gilrs.next_event() {
|
// while let Some(GilEvent { id, event, time }) = gilrs.next_event() {
|
||||||
println!("{:?} New event from {}: {:?}", time, id, event);
|
// println!("{:?} New event from {}: {:?}", time, id, event);
|
||||||
active_gamepad = Some(id);
|
// active_gamepad = Some(id);
|
||||||
event_loop_proxy.send_event(TrEvent::GamepadEvent {
|
// event_loop_proxy.send_event(TrEvent::GamepadEvent {
|
||||||
gil_event: GilEvent {id, event, time}
|
// gil_event: GilEvent {id, event, time}
|
||||||
}).ok();
|
// }).ok();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
// // You can also use cached gamepad state
|
// // // You can also use cached gamepad state
|
||||||
// if let Some(gamepad) = active_gamepad.map(|id| gilrs.gamepad(id)) {
|
// // if let Some(gamepad) = active_gamepad.map(|id| gilrs.gamepad(id)) {
|
||||||
// if gamepad.is_pressed(Button::South) {
|
// // if gamepad.is_pressed(Button::South) {
|
||||||
// println!("Button South is pressed (XBox - A, PS - X)");
|
// // println!("Button South is pressed (XBox - A, PS - X)");
|
||||||
// }
|
// // }
|
||||||
// }
|
// // }
|
||||||
|
//
|
||||||
std::thread::sleep(std::time::Duration::from_millis(50));
|
// std::thread::sleep(std::time::Duration::from_millis(50));
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
|
|
||||||
// Events loop is borrowed from the surface
|
// Events loop is borrowed from the surface
|
||||||
events_loop.run(move |event, _, control_flow| {
|
events_loop.run(move |event, _, control_flow| {
|
||||||
@@ -258,9 +270,9 @@ pub fn main() {
|
|||||||
|
|
||||||
let mut canvas_frame = CanvasFrame::default();
|
let mut canvas_frame = CanvasFrame::default();
|
||||||
canvas_frame.draw(&funky_sprite);
|
canvas_frame.draw(&funky_sprite);
|
||||||
canvas_frame.draw(&text_sprite);
|
// canvas_frame.draw(&text_sprite);
|
||||||
canvas_frame.draw(&compu_sprite1);
|
canvas_frame.draw(&compu_sprite1);
|
||||||
// canvas_frame.draw(&slider);
|
canvas_frame.draw(&slider);
|
||||||
|
|
||||||
let mut compu_frame = CompuFrame::new();
|
let mut compu_frame = CompuFrame::new();
|
||||||
compu_frame.add_with_image_swap(compute_buffer.clone(), compute_kernel.clone(), &compu_sprite1);
|
compu_frame.add_with_image_swap(compute_buffer.clone(), compute_kernel.clone(), &compu_sprite1);
|
||||||
|
|||||||
Reference in New Issue
Block a user