added color swatch picking. Need to align it to the slewed image

master
mitchellhansen 6 years ago
parent c3a2c45e21
commit 942ff4035d

@ -46,12 +46,17 @@ mod timer;
mod input; mod input;
mod vkprocessor; mod vkprocessor;
// What next?
// Second sprite for rendering paths at x10 or so resolution
// color bucketing
fn main() { fn main() {
let instance = Instance::new(None, &InstanceExtensions::none(), None).unwrap(); let instance = Instance::new(None, &InstanceExtensions::none(), None).unwrap();
let mut processor = vkprocessor::VkProcessor::new(&instance); let mut processor = vkprocessor::VkProcessor::new(&instance);
processor.compile_kernel(String::from("simple-edge.compute")); processor.compile_kernel(String::from("simple-edge.compute"));
processor.load_buffers(String::from("test2.png")); processor.load_buffers(String::from("funky-bird.jpg"));
processor.run_kernel(); processor.run_kernel();
processor.read_image(); processor.read_image();
processor.save_image(); processor.save_image();
@ -78,7 +83,7 @@ fn main() {
let mut slider = Slider::new(40.0, None); let mut slider = Slider::new(40.0, None);
let mut selected_colors = Vec::new(); let mut selected_colors = Vec::new();
selected_colors.push(RectangleShape::with_size(Vector2f::new(30.0, 30.0)));
let step_size: f32 = 0.005; let step_size: f32 = 0.005;
let mut elapsed_time: f32; let mut elapsed_time: f32;
@ -99,7 +104,22 @@ fn main() {
} }
}, },
Event::MouseButtonPressed { button, x, y} => { Event::MouseButtonPressed { button, x, y} => {
let x = x as u32;
let y = y as u32;
mouse_xy = mouse::desktop_position(); mouse_xy = mouse::desktop_position();
let r = processor.image_buffer[((processor.xy.0 * y + x) * 4 + 0) as usize] as u8;
let g = processor.image_buffer[((processor.xy.0 * y + x) * 4 + 1) as usize] as u8;
let b = processor.image_buffer[((processor.xy.0 * y + x) * 4 + 2) as usize] as u8;
let a = processor.image_buffer[((processor.xy.0 * y + x) * 4 + 3) as usize] as u8;
selected_colors.push(
RectangleShape::with_size(Vector2f::new(30.0, 30.0))
);
let mut x_position = 45.0 * selected_colors.len() as f32;
selected_colors.last_mut().unwrap().set_position(Vector2f::new(x_position, 80.0));
selected_colors.last_mut().unwrap().set_fill_color(&Color::rgba(r,g,b,a));
}, },
Event::MouseWheelScrolled { wheel, delta, x, y } => { Event::MouseWheelScrolled { wheel, delta, x, y } => {
if delta > 0.0 { if delta > 0.0 {
@ -113,12 +133,10 @@ fn main() {
input.ingest(&event) input.ingest(&event)
} }
if input.is_mousebutton_held(Button::Left) { // Dragging by middle click
if input.is_mousebutton_held(Button::Middle) {
let delta = mouse_xy - mouse::desktop_position(); let delta = mouse_xy - mouse::desktop_position();
mouse_xy = mouse::desktop_position(); mouse_xy = mouse::desktop_position();
println!("{:?}", delta);
background_sprite.set_position( background_sprite.set_position(
background_sprite.position() - Vector2f::new(delta.x as f32, delta.y as f32) background_sprite.position() - Vector2f::new(delta.x as f32, delta.y as f32)
); );
@ -142,6 +160,9 @@ fn main() {
window.draw(&slider); window.draw(&slider);
for i in &selected_colors {
window.draw(i);
}
window.display(); window.display();
} }

Loading…
Cancel
Save