diff --git a/src/canvas/canvas_frame.rs b/src/canvas/canvas_frame.rs index ad9b5a52..86a2f9c0 100644 --- a/src/canvas/canvas_frame.rs +++ b/src/canvas/canvas_frame.rs @@ -6,12 +6,12 @@ use crate::canvas::managed::shader::dynamic_vertex::RuntimeVertexDef; use crate::canvas::managed::handles::{CanvasTextureHandle, CanvasImageHandle, CanvasFontHandle, Handle}; use vulkano::pipeline::vertex::Vertex; use std::any::Any; -use crate::VertexTypes; +use crate::VertexType; use winit::event::Event; /// Trait which may be inherited by objects that wish to be drawn to the screen pub trait Drawable { - fn get(&self) -> Vec; + fn get(&self) -> Vec; } /// Trait which may be inherited by objects that wish to receive events @@ -22,7 +22,7 @@ pub trait Eventable { /// Accumulator for Vectors of VertexTypes #[derive(Default)] pub struct CanvasFrame { - pub map: Vec, + pub map: Vec, } impl CanvasFrame { diff --git a/src/canvas/canvas_state.rs b/src/canvas/canvas_state.rs index 45d7acc0..120e4953 100644 --- a/src/canvas/canvas_state.rs +++ b/src/canvas/canvas_state.rs @@ -31,7 +31,7 @@ use crate::canvas::managed::handles::{CanvasTextureHandle, CanvasImageHandle, Ca use crate::canvas::managed::gpu_buffers::{CanvasImage, CanvasTexture, CanvasFont}; use crate::canvas::managed::shader::shader_common::CompiledShader; use crate::canvas::managed::shader::generic_shader::GenericShader; -use crate::VertexTypes; +use crate::VertexType; use crate::util::vertex::{TextVertex3D, TextureVertex3D, ImageVertex3D, ColorVertex3D, CanvasFrameAllocation}; use shade_runner::Input; use winit::window::Window; @@ -395,19 +395,19 @@ impl CanvasState { for value in canvas_frame.map { match value { - VertexTypes::TextureType(vertices, handle) => { + VertexType::TextureType(vertices, handle) => { textured_vertex_buffer.entry(handle).or_insert(vertices.clone()).extend(vertices); } - VertexTypes::ImageType(vertices, handle) => { + VertexType::ImageType(vertices, handle) => { image_vertex_buffer.entry(handle).or_insert(vertices.clone()).extend(vertices); } - VertexTypes::ColorType(vertices) => { + VertexType::ColorType(vertices) => { colored_vertex_buffer.extend(vertices); } - VertexTypes::ThreeDType(vertices) => { + VertexType::ThreeDType(vertices) => { } - VertexTypes::TextType(vertices) => { + VertexType::TextType(vertices) => { text_vertex_buffer.extend(vertices); } }; diff --git a/src/canvas/managed/shader/generic_shader.rs b/src/canvas/managed/shader/generic_shader.rs index 0d8de92b..9e156daf 100644 --- a/src/canvas/managed/shader/generic_shader.rs +++ b/src/canvas/managed/shader/generic_shader.rs @@ -18,7 +18,7 @@ use crate::canvas::managed::shader::shader_common::{ShaderType, CompiledShaderRe use crate::canvas::managed::handles::CompiledShaderHandle; use crate::canvas::managed::shader::dynamic_vertex::RuntimeVertexDef; use crate::canvas::managed::ShaderSpecializationConstants; -use crate::util::vertex::{VertexTypes, ColorVertex3D}; +use crate::util::vertex::{VertexType, ColorVertex3D}; /// CanvasShader holds the pipeline and render pass for the input shader source #[derive(Clone)] diff --git a/src/compute/compu_frame.rs b/src/compute/compu_frame.rs index 9620dcd0..ecd9265a 100644 --- a/src/compute/compu_frame.rs +++ b/src/compute/compu_frame.rs @@ -3,7 +3,7 @@ use crate::canvas::managed::handles::{CanvasImageHandle}; use crate::compute::managed::handles::{CompuKernelHandle, CompuBufferHandle}; use crate::drawables::compu_sprite::CompuSprite; use crate::canvas::canvas_frame::Drawable; -use crate::util::vertex::VertexTypes; +use crate::util::vertex::VertexType; pub struct CompuFrame { // Vec<(Buffer, Kernel)> @@ -57,7 +57,7 @@ impl CompuFrame { let compu_sprites = sprite.get(); if compu_sprites.len() == 1 { - if let VertexTypes::ImageType(a, b) = compu_sprites.first().unwrap() { + if let VertexType::ImageType(a, b) = compu_sprites.first().unwrap() { self.swapped_to_image.push((buffer, b.clone(), kernel)) }; } diff --git a/src/drawables/compu_sprite.rs b/src/drawables/compu_sprite.rs index 3ba684b4..21cf65c8 100644 --- a/src/drawables/compu_sprite.rs +++ b/src/drawables/compu_sprite.rs @@ -1,11 +1,11 @@ use std::sync::Arc; use crate::canvas::managed::handles::{CanvasImageHandle, CanvasTextureHandle}; use crate::canvas::canvas_frame::Drawable; -use crate::util::vertex::{VertexTypes, ImageVertex3D}; +use crate::util::vertex::{VertexType, ImageVertex3D}; pub struct CompuSprite { - pub verts: VertexTypes, + pub verts: VertexType, position: (f32, f32), size: (f32, f32), @@ -44,7 +44,7 @@ impl CompuSprite { ]; CompuSprite { - verts: VertexTypes::ImageType(verts, image_handle.clone()), + verts: VertexType::ImageType(verts, image_handle.clone()), position: position, size: size, color: (0.0, 0.0, 0.0, 0.0), @@ -53,7 +53,7 @@ impl CompuSprite { } impl Drawable for CompuSprite { - fn get(&self) -> Vec { + fn get(&self) -> Vec { vec![self.verts.clone()] } } \ No newline at end of file diff --git a/src/drawables/polygon.rs b/src/drawables/polygon.rs index 6535478a..22610a91 100644 --- a/src/drawables/polygon.rs +++ b/src/drawables/polygon.rs @@ -2,14 +2,14 @@ use std::sync::Arc; use crate::canvas::*; use crate::canvas::managed::handles::{CanvasFontHandle, CanvasImageHandle, CanvasTextureHandle, Handle}; use crate::canvas::canvas_frame::{Drawable}; -use crate::util::vertex::{VertexTypes, TextureVertex3D, Vertex3D, ColorVertex3D}; +use crate::util::vertex::{VertexType, TextureVertex3D, Vertex3D, ColorVertex3D}; use crate::drawables::sprite::Sprite; /// Convex multi verticy polygon #[derive(Debug, Clone)] pub struct Polygon { - pub verts: VertexTypes, + pub verts: VertexType, position: (f32, f32), size: (f32, f32), @@ -54,14 +54,14 @@ impl Polygon { Polygon { - verts: VertexTypes::ColorType(verts), + verts: VertexType::ColorType(verts), position: position, size: size, } } } impl Drawable for Polygon { - fn get(&self) -> Vec { + fn get(&self) -> Vec { vec![self.verts.clone()] } diff --git a/src/drawables/rect.rs b/src/drawables/rect.rs index 54043751..dc76274c 100644 --- a/src/drawables/rect.rs +++ b/src/drawables/rect.rs @@ -1,11 +1,11 @@ use crate::canvas::canvas_frame::Drawable; -use crate::util::vertex::{VertexTypes, ColorVertex3D}; +use crate::util::vertex::{VertexType, ColorVertex3D}; /// #[derive(Debug, Clone)] pub struct Rect { - pub verts: VertexTypes, + pub verts: VertexType, position: (f32, f32), size: (f32, f32), @@ -43,14 +43,14 @@ impl Rect { ]; Rect { - verts: VertexTypes::ColorType(verts), + verts: VertexType::ColorType(verts), position: position, size: size, } } } impl Drawable for Rect { - fn get(&self) -> Vec { + fn get(&self) -> Vec { vec![self.verts.clone()] } diff --git a/src/drawables/sprite.rs b/src/drawables/sprite.rs index 27a40067..25bb1b75 100644 --- a/src/drawables/sprite.rs +++ b/src/drawables/sprite.rs @@ -2,13 +2,13 @@ use std::sync::Arc; use crate::canvas::*; use crate::canvas::managed::handles::{CanvasFontHandle, CanvasImageHandle, CanvasTextureHandle, Handle}; use crate::canvas::canvas_frame::{Drawable, Eventable}; -use crate::util::vertex::{VertexTypes, TextureVertex3D, Vertex3D}; +use crate::util::vertex::{VertexType, TextureVertex3D, Vertex3D}; use winit::event::{DeviceEvent, MouseButton, ElementState, Event, WindowEvent}; /// #[derive(Debug, Clone)] pub struct Sprite { - verts: VertexTypes, + verts: VertexType, position: (f32, f32), size: (f32, f32), @@ -55,7 +55,7 @@ impl Sprite { let normalized_depth = (depth as f32 / 255.0); Sprite { - verts: VertexTypes::TextureType(Sprite::generate_verts(position, size, normalized_depth), texture_handle.clone()), + verts: VertexType::TextureType(Sprite::generate_verts(position, size, normalized_depth), texture_handle.clone()), position: position, size: size, depth: normalized_depth, @@ -65,9 +65,9 @@ impl Sprite { } impl Drawable for Sprite { - fn get(&self) -> Vec { + fn get(&self) -> Vec { vec![ - VertexTypes::TextureType( + VertexType::TextureType( Sprite::generate_verts(self.position, self.size, self.depth), self.texture_handle.clone()) ] diff --git a/src/drawables/text.rs b/src/drawables/text.rs index b6a26f11..ead2ca39 100644 --- a/src/drawables/text.rs +++ b/src/drawables/text.rs @@ -1,10 +1,10 @@ use crate::canvas::canvas_frame::Drawable; -use crate::util::vertex::{VertexTypes, ColorVertex3D}; +use crate::util::vertex::{VertexType, ColorVertex3D}; /// #[derive(Debug, Clone)] pub struct Text { - pub verts: VertexTypes, + pub verts: VertexType, position: (f32, f32), size: (f32, f32), @@ -129,7 +129,7 @@ impl Text { }; Text { - verts: VertexTypes::TextType(verts), + verts: VertexType::TextType(verts), position: position, size: size, } @@ -137,7 +137,7 @@ impl Text { } impl Drawable for Text { - fn get(&self) -> Vec { + fn get(&self) -> Vec { vec![self.verts.clone()] } } diff --git a/src/main.rs b/src/main.rs index be334e9e..300dae3b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -33,11 +33,12 @@ use crate::drawables::sprite::Sprite; use crate::drawables::text::Text; use crate::util::load_raw; use crate::util::timer::Timer; -use crate::util::vertex::{TextureVertex3D, VertexTypes}; +use crate::util::vertex::{TextureVertex3D, VertexType}; use crate::vkprocessor::VkProcessor; use std::path::Path; use gilrs::{Gilrs, Button, Event as GilEvent, GamepadId, Gamepad}; use crate::util::tr_event::TrEvent; +use crate::button_m::Slider; pub mod util; pub mod vkprocessor; @@ -50,27 +51,49 @@ pub mod button_m { use crate::drawables::sprite::Sprite; use std::collections::HashSet; use crate::canvas::canvas_frame::Drawable; - use crate::util::vertex::VertexTypes; - - // Should I force these to be drawables - // or better, how do I force these to be drawables - enum GuiElements { - HANDLE(Rect), - GUIDE(Sprite) - } + use crate::util::vertex::VertexType; pub struct Slider { - sprites: HashSet, + handle : Rect, + guide : Vec, + + scaler: u32, + position: (f32, f32), + size: (f32, f32), + value: u16, } - impl Drawable for Slider { - fn get(&self) -> Vec { + impl Slider { + pub fn new(size: (f32, f32), position : (f32, f32), value: u16) -> Slider { + + // render the guide first + + let left_guide_bar = Rect::new((position.0 as f32, position.1 as f32), (0.1, 0.1), 1); + let right_guide_bar = Rect::new((position.0 + size.0 as f32, position.1 as f32), (0.1, 0.1), 1); + let line = Rect::new((position.0 as f32, position.1 - (size.1 / 2.0) as f32), (0.1, 0.1), 1); + + 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); - self.sprites.into() - // self.sprites.iter().map(|v| { - // - // }) + Slider { + handle: handle, + guide: vec![left_guide_bar, right_guide_bar, line], + scaler: 255, + position, + size, + value + } + } + } + + impl Drawable for Slider { + fn get(&self) -> Vec { + let mut vertices = vec![self.handle.verts.clone()]; + vertices.extend_from_slice(self.guide.iter() + .map(|x| x.clone().verts).collect::>().as_slice() + ); + vertices } } @@ -149,6 +172,8 @@ pub fn main() { 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); + // how do i register a sprite to get events... // explicit is much easier @@ -235,6 +260,7 @@ pub fn main() { canvas_frame.draw(&funky_sprite); canvas_frame.draw(&text_sprite); canvas_frame.draw(&compu_sprite1); +// canvas_frame.draw(&slider); let mut compu_frame = CompuFrame::new(); compu_frame.add_with_image_swap(compute_buffer.clone(), compute_kernel.clone(), &compu_sprite1); diff --git a/src/util/vertex.rs b/src/util/vertex.rs index a6871ef3..68c10149 100644 --- a/src/util/vertex.rs +++ b/src/util/vertex.rs @@ -51,7 +51,7 @@ vulkano::impl_vertex!(GlyphInstance, screen_position, atlas_position, atlas_size // ============================================================================== #[derive(Debug, Clone)] -pub enum VertexTypes { +pub enum VertexType { TextureType(Vec, Arc), ImageType(Vec, Arc), ColorType(Vec), diff --git a/src/vkprocessor.rs b/src/vkprocessor.rs index 6c5edf4f..3cb6acfe 100644 --- a/src/vkprocessor.rs +++ b/src/vkprocessor.rs @@ -19,7 +19,7 @@ use crate::canvas::managed::shader::generic_shader::GenericShader; use crate::canvas::managed::shader::text_shader::TextShader; use crate::canvas::managed::handles::{CanvasTextureHandle, CompiledShaderHandle, CanvasFontHandle, CanvasImageHandle}; use crate::compute::managed::handles::{CompuKernelHandle, CompuBufferHandle}; -use crate::util::vertex::{VertexTypes, ColorVertex3D, TextVertex3D, TextureVertex3D, ImageVertex3D}; +use crate::util::vertex::{VertexType, ColorVertex3D, TextVertex3D, TextureVertex3D, ImageVertex3D}; use vulkano_text::DrawText; use winit::window::{Window, WindowBuilder}; use vulkano::instance::debug::DebugCallback;