added slider thing, broke rendering somehow though

master
mitchellhansen 4 years ago
parent 8da810f23a
commit f3a3be1d99

@ -6,12 +6,12 @@ use crate::canvas::managed::shader::dynamic_vertex::RuntimeVertexDef;
use crate::canvas::managed::handles::{CanvasTextureHandle, CanvasImageHandle, CanvasFontHandle, Handle}; use crate::canvas::managed::handles::{CanvasTextureHandle, CanvasImageHandle, CanvasFontHandle, Handle};
use vulkano::pipeline::vertex::Vertex; use vulkano::pipeline::vertex::Vertex;
use std::any::Any; use std::any::Any;
use crate::VertexTypes; use crate::VertexType;
use winit::event::Event; use winit::event::Event;
/// 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 {
fn get(&self) -> Vec<VertexTypes>; fn get(&self) -> Vec<VertexType>;
} }
/// Trait which may be inherited by objects that wish to receive events /// Trait which may be inherited by objects that wish to receive events
@ -22,7 +22,7 @@ pub trait Eventable<T> {
/// Accumulator for Vectors of VertexTypes /// Accumulator for Vectors of VertexTypes
#[derive(Default)] #[derive(Default)]
pub struct CanvasFrame { pub struct CanvasFrame {
pub map: Vec<VertexTypes>, pub map: Vec<VertexType>,
} }
impl CanvasFrame { impl CanvasFrame {

@ -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::gpu_buffers::{CanvasImage, CanvasTexture, CanvasFont};
use crate::canvas::managed::shader::shader_common::CompiledShader; use crate::canvas::managed::shader::shader_common::CompiledShader;
use crate::canvas::managed::shader::generic_shader::GenericShader; use crate::canvas::managed::shader::generic_shader::GenericShader;
use crate::VertexTypes; use crate::VertexType;
use crate::util::vertex::{TextVertex3D, TextureVertex3D, ImageVertex3D, ColorVertex3D, CanvasFrameAllocation}; use crate::util::vertex::{TextVertex3D, TextureVertex3D, ImageVertex3D, ColorVertex3D, CanvasFrameAllocation};
use shade_runner::Input; use shade_runner::Input;
use winit::window::Window; use winit::window::Window;
@ -395,19 +395,19 @@ impl CanvasState {
for value in canvas_frame.map { for value in canvas_frame.map {
match value { match value {
VertexTypes::TextureType(vertices, handle) => { VertexType::TextureType(vertices, handle) => {
textured_vertex_buffer.entry(handle).or_insert(vertices.clone()).extend(vertices); 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); image_vertex_buffer.entry(handle).or_insert(vertices.clone()).extend(vertices);
} }
VertexTypes::ColorType(vertices) => { VertexType::ColorType(vertices) => {
colored_vertex_buffer.extend(vertices); colored_vertex_buffer.extend(vertices);
} }
VertexTypes::ThreeDType(vertices) => { VertexType::ThreeDType(vertices) => {
} }
VertexTypes::TextType(vertices) => { VertexType::TextType(vertices) => {
text_vertex_buffer.extend(vertices); text_vertex_buffer.extend(vertices);
} }
}; };

@ -18,7 +18,7 @@ use crate::canvas::managed::shader::shader_common::{ShaderType, CompiledShaderRe
use crate::canvas::managed::handles::CompiledShaderHandle; use crate::canvas::managed::handles::CompiledShaderHandle;
use crate::canvas::managed::shader::dynamic_vertex::RuntimeVertexDef; use crate::canvas::managed::shader::dynamic_vertex::RuntimeVertexDef;
use crate::canvas::managed::ShaderSpecializationConstants; 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 /// CanvasShader holds the pipeline and render pass for the input shader source
#[derive(Clone)] #[derive(Clone)]

@ -3,7 +3,7 @@ use crate::canvas::managed::handles::{CanvasImageHandle};
use crate::compute::managed::handles::{CompuKernelHandle, CompuBufferHandle}; use crate::compute::managed::handles::{CompuKernelHandle, CompuBufferHandle};
use crate::drawables::compu_sprite::CompuSprite; use crate::drawables::compu_sprite::CompuSprite;
use crate::canvas::canvas_frame::Drawable; use crate::canvas::canvas_frame::Drawable;
use crate::util::vertex::VertexTypes; use crate::util::vertex::VertexType;
pub struct CompuFrame { pub struct CompuFrame {
// Vec<(Buffer, Kernel)> // Vec<(Buffer, Kernel)>
@ -57,7 +57,7 @@ impl CompuFrame {
let compu_sprites = sprite.get(); let compu_sprites = sprite.get();
if compu_sprites.len() == 1 { 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)) self.swapped_to_image.push((buffer, b.clone(), kernel))
}; };
} }

@ -1,11 +1,11 @@
use std::sync::Arc; use std::sync::Arc;
use crate::canvas::managed::handles::{CanvasImageHandle, CanvasTextureHandle}; use crate::canvas::managed::handles::{CanvasImageHandle, CanvasTextureHandle};
use crate::canvas::canvas_frame::Drawable; use crate::canvas::canvas_frame::Drawable;
use crate::util::vertex::{VertexTypes, ImageVertex3D}; use crate::util::vertex::{VertexType, ImageVertex3D};
pub struct CompuSprite { pub struct CompuSprite {
pub verts: VertexTypes, pub verts: VertexType,
position: (f32, f32), position: (f32, f32),
size: (f32, f32), size: (f32, f32),
@ -44,7 +44,7 @@ impl CompuSprite {
]; ];
CompuSprite { CompuSprite {
verts: VertexTypes::ImageType(verts, image_handle.clone()), verts: VertexType::ImageType(verts, image_handle.clone()),
position: position, position: position,
size: size, size: size,
color: (0.0, 0.0, 0.0, 0.0), color: (0.0, 0.0, 0.0, 0.0),
@ -53,7 +53,7 @@ impl CompuSprite {
} }
impl Drawable for CompuSprite { impl Drawable for CompuSprite {
fn get(&self) -> Vec<VertexTypes> { fn get(&self) -> Vec<VertexType> {
vec![self.verts.clone()] vec![self.verts.clone()]
} }
} }

@ -2,14 +2,14 @@ use std::sync::Arc;
use crate::canvas::*; use crate::canvas::*;
use crate::canvas::managed::handles::{CanvasFontHandle, CanvasImageHandle, CanvasTextureHandle, Handle}; use crate::canvas::managed::handles::{CanvasFontHandle, CanvasImageHandle, CanvasTextureHandle, Handle};
use crate::canvas::canvas_frame::{Drawable}; 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; use crate::drawables::sprite::Sprite;
/// Convex multi verticy polygon /// Convex multi verticy polygon
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Polygon { pub struct Polygon {
pub verts: VertexTypes, pub verts: VertexType,
position: (f32, f32), position: (f32, f32),
size: (f32, f32), size: (f32, f32),
@ -54,14 +54,14 @@ impl Polygon {
Polygon { Polygon {
verts: VertexTypes::ColorType(verts), verts: VertexType::ColorType(verts),
position: position, position: position,
size: size, size: size,
} }
} }
} }
impl Drawable for Polygon { impl Drawable for Polygon {
fn get(&self) -> Vec<VertexTypes> { fn get(&self) -> Vec<VertexType> {
vec![self.verts.clone()] vec![self.verts.clone()]
} }

@ -1,11 +1,11 @@
use crate::canvas::canvas_frame::Drawable; use crate::canvas::canvas_frame::Drawable;
use crate::util::vertex::{VertexTypes, ColorVertex3D}; use crate::util::vertex::{VertexType, ColorVertex3D};
/// ///
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Rect { pub struct Rect {
pub verts: VertexTypes, pub verts: VertexType,
position: (f32, f32), position: (f32, f32),
size: (f32, f32), size: (f32, f32),
@ -43,14 +43,14 @@ impl Rect {
]; ];
Rect { Rect {
verts: VertexTypes::ColorType(verts), verts: VertexType::ColorType(verts),
position: position, position: position,
size: size, size: size,
} }
} }
} }
impl Drawable for Rect { impl Drawable for Rect {
fn get(&self) -> Vec<VertexTypes> { fn get(&self) -> Vec<VertexType> {
vec![self.verts.clone()] vec![self.verts.clone()]
} }

@ -2,13 +2,13 @@ use std::sync::Arc;
use crate::canvas::*; use crate::canvas::*;
use crate::canvas::managed::handles::{CanvasFontHandle, CanvasImageHandle, CanvasTextureHandle, Handle}; use crate::canvas::managed::handles::{CanvasFontHandle, CanvasImageHandle, CanvasTextureHandle, Handle};
use crate::canvas::canvas_frame::{Drawable, Eventable}; 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}; use winit::event::{DeviceEvent, MouseButton, ElementState, Event, WindowEvent};
/// ///
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Sprite { pub struct Sprite {
verts: VertexTypes, verts: VertexType,
position: (f32, f32), position: (f32, f32),
size: (f32, f32), size: (f32, f32),
@ -55,7 +55,7 @@ impl Sprite {
let normalized_depth = (depth as f32 / 255.0); let normalized_depth = (depth as f32 / 255.0);
Sprite { 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, position: position,
size: size, size: size,
depth: normalized_depth, depth: normalized_depth,
@ -65,9 +65,9 @@ impl Sprite {
} }
impl Drawable for Sprite { impl Drawable for Sprite {
fn get(&self) -> Vec<VertexTypes> { fn get(&self) -> Vec<VertexType> {
vec![ vec![
VertexTypes::TextureType( VertexType::TextureType(
Sprite::generate_verts(self.position, self.size, self.depth), Sprite::generate_verts(self.position, self.size, self.depth),
self.texture_handle.clone()) self.texture_handle.clone())
] ]

@ -1,10 +1,10 @@
use crate::canvas::canvas_frame::Drawable; use crate::canvas::canvas_frame::Drawable;
use crate::util::vertex::{VertexTypes, ColorVertex3D}; use crate::util::vertex::{VertexType, ColorVertex3D};
/// ///
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Text { pub struct Text {
pub verts: VertexTypes, pub verts: VertexType,
position: (f32, f32), position: (f32, f32),
size: (f32, f32), size: (f32, f32),
@ -129,7 +129,7 @@ impl Text {
}; };
Text { Text {
verts: VertexTypes::TextType(verts), verts: VertexType::TextType(verts),
position: position, position: position,
size: size, size: size,
} }
@ -137,7 +137,7 @@ impl Text {
} }
impl Drawable for Text { impl Drawable for Text {
fn get(&self) -> Vec<VertexTypes> { fn get(&self) -> Vec<VertexType> {
vec![self.verts.clone()] vec![self.verts.clone()]
} }
} }

@ -33,11 +33,12 @@ use crate::drawables::sprite::Sprite;
use crate::drawables::text::Text; use crate::drawables::text::Text;
use crate::util::load_raw; use crate::util::load_raw;
use crate::util::timer::Timer; use crate::util::timer::Timer;
use crate::util::vertex::{TextureVertex3D, VertexTypes}; use crate::util::vertex::{TextureVertex3D, VertexType};
use crate::vkprocessor::VkProcessor; use crate::vkprocessor::VkProcessor;
use std::path::Path; use std::path::Path;
use gilrs::{Gilrs, Button, Event as GilEvent, GamepadId, Gamepad}; use gilrs::{Gilrs, Button, Event as GilEvent, GamepadId, Gamepad};
use crate::util::tr_event::TrEvent; use crate::util::tr_event::TrEvent;
use crate::button_m::Slider;
pub mod util; pub mod util;
pub mod vkprocessor; pub mod vkprocessor;
@ -50,27 +51,49 @@ pub mod button_m {
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;
use crate::util::vertex::VertexTypes; use crate::util::vertex::VertexType;
// Should I force these to be drawables
// or better, how do I force these to be drawables
enum GuiElements {
HANDLE(Rect),
GUIDE(Sprite)
}
pub struct Slider { pub struct Slider {
sprites: HashSet<GuiElements>, handle : Rect,
guide : Vec<Rect>,
scaler: u32,
position: (f32, f32),
size: (f32, f32),
value: u16,
} }
impl Drawable for Slider { impl Slider {
fn get(&self) -> Vec<VertexTypes> { pub fn new(size: (f32, f32), position : (f32, f32), value: u16) -> Slider {
self.sprites.into() // render the guide first
// self.sprites.iter().map(|v| {
// 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);
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<VertexType> {
let mut vertices = vec![self.handle.verts.clone()];
vertices.extend_from_slice(self.guide.iter()
.map(|x| x.clone().verts).collect::<Vec<VertexType>>().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 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 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... // how do i register a sprite to get events...
// explicit is much easier // explicit is much easier
@ -235,6 +260,7 @@ pub fn main() {
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);
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);

@ -51,7 +51,7 @@ vulkano::impl_vertex!(GlyphInstance, screen_position, atlas_position, atlas_size
// ============================================================================== // ==============================================================================
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub enum VertexTypes { pub enum VertexType {
TextureType(Vec<TextureVertex3D>, Arc<CanvasTextureHandle>), TextureType(Vec<TextureVertex3D>, Arc<CanvasTextureHandle>),
ImageType(Vec<ImageVertex3D>, Arc<CanvasImageHandle>), ImageType(Vec<ImageVertex3D>, Arc<CanvasImageHandle>),
ColorType(Vec<ColorVertex3D>), ColorType(Vec<ColorVertex3D>),

@ -19,7 +19,7 @@ use crate::canvas::managed::shader::generic_shader::GenericShader;
use crate::canvas::managed::shader::text_shader::TextShader; use crate::canvas::managed::shader::text_shader::TextShader;
use crate::canvas::managed::handles::{CanvasTextureHandle, CompiledShaderHandle, CanvasFontHandle, CanvasImageHandle}; use crate::canvas::managed::handles::{CanvasTextureHandle, CompiledShaderHandle, CanvasFontHandle, CanvasImageHandle};
use crate::compute::managed::handles::{CompuKernelHandle, CompuBufferHandle}; 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 vulkano_text::DrawText;
use winit::window::{Window, WindowBuilder}; use winit::window::{Window, WindowBuilder};
use vulkano::instance::debug::DebugCallback; use vulkano::instance::debug::DebugCallback;

Loading…
Cancel
Save