added slider thing, broke rendering somehow though
This commit is contained in:
@@ -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<VertexTypes>;
|
||||
fn get(&self) -> Vec<VertexType>;
|
||||
}
|
||||
|
||||
/// 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
|
||||
#[derive(Default)]
|
||||
pub struct CanvasFrame {
|
||||
pub map: Vec<VertexTypes>,
|
||||
pub map: Vec<VertexType>,
|
||||
}
|
||||
|
||||
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::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);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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)]
|
||||
|
||||
@@ -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))
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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<VertexTypes> {
|
||||
fn get(&self) -> Vec<VertexType> {
|
||||
vec![self.verts.clone()]
|
||||
}
|
||||
}
|
||||
@@ -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<VertexTypes> {
|
||||
fn get(&self) -> Vec<VertexType> {
|
||||
vec![self.verts.clone()]
|
||||
}
|
||||
|
||||
|
||||
@@ -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<VertexTypes> {
|
||||
fn get(&self) -> Vec<VertexType> {
|
||||
vec![self.verts.clone()]
|
||||
}
|
||||
|
||||
|
||||
@@ -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<VertexTypes> {
|
||||
fn get(&self) -> Vec<VertexType> {
|
||||
vec![
|
||||
VertexTypes::TextureType(
|
||||
VertexType::TextureType(
|
||||
Sprite::generate_verts(self.position, self.size, self.depth),
|
||||
self.texture_handle.clone())
|
||||
]
|
||||
|
||||
@@ -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<VertexTypes> {
|
||||
fn get(&self) -> Vec<VertexType> {
|
||||
vec![self.verts.clone()]
|
||||
}
|
||||
}
|
||||
|
||||
60
src/main.rs
60
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<GuiElements>,
|
||||
handle : Rect,
|
||||
guide : Vec<Rect>,
|
||||
|
||||
scaler: u32,
|
||||
position: (f32, f32),
|
||||
size: (f32, f32),
|
||||
value: u16,
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
|
||||
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<VertexTypes> {
|
||||
|
||||
self.sprites.into()
|
||||
// self.sprites.iter().map(|v| {
|
||||
//
|
||||
// })
|
||||
|
||||
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 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);
|
||||
|
||||
@@ -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<TextureVertex3D>, Arc<CanvasTextureHandle>),
|
||||
ImageType(Vec<ImageVertex3D>, Arc<CanvasImageHandle>),
|
||||
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::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;
|
||||
|
||||
Reference in New Issue
Block a user