Reformat using cargofmt
This commit is contained in:
@@ -1,16 +1,14 @@
|
||||
use std::sync::mpsc;
|
||||
use std::sync::mpsc::{Sender, Receiver};
|
||||
use std::sync::mpsc::{Receiver, Sender};
|
||||
use std::thread;
|
||||
|
||||
use image::DynamicImage;
|
||||
|
||||
use painter::painter::Painter;
|
||||
use painter::handle::Handle;
|
||||
use painter::painter::Painter;
|
||||
use pix::client::Client;
|
||||
use rect::Rect;
|
||||
|
||||
|
||||
|
||||
/// A pixflut instance
|
||||
pub struct Canvas {
|
||||
host: String,
|
||||
@@ -22,12 +20,7 @@ pub struct Canvas {
|
||||
|
||||
impl Canvas {
|
||||
/// Create a new pixelflut canvas.
|
||||
pub fn new(
|
||||
host: &str,
|
||||
painter_count: usize,
|
||||
size: (u32, u32),
|
||||
offset: (u32, u32),
|
||||
) -> Canvas {
|
||||
pub fn new(host: &str, painter_count: usize, size: (u32, u32), offset: (u32, u32)) -> Canvas {
|
||||
// Initialize the object
|
||||
let mut canvas = Canvas {
|
||||
host: host.to_string(),
|
||||
@@ -51,19 +44,14 @@ impl Canvas {
|
||||
fn spawn_painters(&mut self) {
|
||||
// Spawn some painters
|
||||
for i in 0..self.painter_count {
|
||||
// Determine the slice width
|
||||
let width = self.size.0 / (self.painter_count as u32);
|
||||
// Determine the slice width
|
||||
let width = self.size.0 / (self.painter_count as u32);
|
||||
|
||||
// Define the area to paint per thread
|
||||
let painter_area = Rect::from(
|
||||
(i as u32) * width,
|
||||
0,
|
||||
width,
|
||||
self.size.1,
|
||||
);
|
||||
// Define the area to paint per thread
|
||||
let painter_area = Rect::from((i as u32) * width, 0, width, self.size.1);
|
||||
|
||||
// Spawn the painter
|
||||
self.spawn_painter(painter_area);
|
||||
// Spawn the painter
|
||||
self.spawn_painter(painter_area);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,38 +64,24 @@ impl Canvas {
|
||||
let offset = (self.offset.0, self.offset.1);
|
||||
|
||||
// Create a channel to push new images
|
||||
let (tx, rx): (Sender<DynamicImage>, Receiver<DynamicImage>)
|
||||
= mpsc::channel();
|
||||
let (tx, rx): (Sender<DynamicImage>, Receiver<DynamicImage>) = mpsc::channel();
|
||||
|
||||
// Create the painter thread
|
||||
let thread = thread::spawn(move || {
|
||||
// Create a new client
|
||||
let client = Client::connect(host)
|
||||
.expect("failed to open stream to pixelflut");
|
||||
let client = Client::connect(host).expect("failed to open stream to pixelflut");
|
||||
|
||||
// Create a painter
|
||||
let mut painter = Painter::new(
|
||||
client,
|
||||
area,
|
||||
offset,
|
||||
None,
|
||||
);
|
||||
let mut painter = Painter::new(client, area, offset, None);
|
||||
|
||||
// Do some work
|
||||
loop {
|
||||
painter.work(&rx)
|
||||
.expect("Painter failed to perform work");
|
||||
painter.work(&rx).expect("Painter failed to perform work");
|
||||
}
|
||||
});
|
||||
|
||||
// Create a new painter handle, pust it to the list
|
||||
self.painter_handles.push(
|
||||
Handle::new(
|
||||
thread,
|
||||
area,
|
||||
tx,
|
||||
)
|
||||
);
|
||||
self.painter_handles.push(Handle::new(thread, area, tx));
|
||||
}
|
||||
|
||||
// Update the image that is being rendered for all painters.
|
||||
|
||||
Reference in New Issue
Block a user