Move painter modules to sub module

This commit is contained in:
Tim Visée
2017-12-31 00:09:46 +01:00
parent 82d4eeb0f3
commit 60ffaeaae3
6 changed files with 28 additions and 25 deletions

View File

@@ -6,7 +6,6 @@ mod arg_handler;
mod color; mod color;
mod image_manager; mod image_manager;
mod painter; mod painter;
mod painter_handle;
mod pix; mod pix;
mod rect; mod rect;

View File

@@ -13,17 +13,17 @@ use rect::Rect;
/// ///
/// This also holds a channel to the painter thread, /// This also holds a channel to the painter thread,
/// to allow image updates to be pushed to the thread. /// to allow image updates to be pushed to the thread.
pub struct PainterHandle { pub struct Handle {
#[allow(dead_code)] #[allow(dead_code)]
thread: JoinHandle<u32>, thread: JoinHandle<u32>,
area: Rect, area: Rect,
image_sender: Sender<DynamicImage>, image_sender: Sender<DynamicImage>,
} }
impl PainterHandle { impl Handle {
/// Create a new handle from the given properties. /// Create a new handle from the given properties.
pub fn new(thread: JoinHandle<u32>, area: Rect, image_sender: Sender<DynamicImage>) -> PainterHandle { pub fn new(thread: JoinHandle<u32>, area: Rect, image_sender: Sender<DynamicImage>) -> Handle {
PainterHandle { Handle {
thread, thread,
area, area,
image_sender, image_sender,

3
src/painter/mod.rs Normal file
View File

@@ -0,0 +1,3 @@
// Re-export modules
pub mod painter;
pub mod handle;

View File

@@ -6,8 +6,8 @@ use std::thread;
use image::DynamicImage; use image::DynamicImage;
use painter::Painter; use painter::painter::Painter;
use painter_handle::PainterHandle; use painter::handle::Handle;
use pix::client::Client; use pix::client::Client;
use rect::Rect; use rect::Rect;
@@ -16,8 +16,8 @@ use rect::Rect;
/// A pixflut instance /// A pixflut instance
pub struct Canvas { pub struct Canvas {
host: String, host: String,
painter_count: usize, painter_count: usize,
painter_handles: Vec<PainterHandle>, painter_handles: Vec<Handle>,
size: (u32, u32), size: (u32, u32),
offset: (u32, u32), offset: (u32, u32),
} }
@@ -33,14 +33,14 @@ impl Canvas {
// Initialize the object // Initialize the object
let mut canvas = Canvas { let mut canvas = Canvas {
host: host.to_string(), host: host.to_string(),
painter_count, painter_count,
painter_handles: Vec::with_capacity(painter_count), painter_handles: Vec::with_capacity(painter_count),
size, size,
offset, offset,
}; };
// Show a status message // Show a status message
println!("Starting painter threads..."); println!("Starting painter threads...");
// Spawn some painters // Spawn some painters
canvas.spawn_painters(); canvas.spawn_painters();
@@ -53,19 +53,19 @@ impl Canvas {
fn spawn_painters(&mut self) { fn spawn_painters(&mut self) {
// Spawn some painters // Spawn some painters
for i in 0..self.painter_count { for i in 0..self.painter_count {
// Determine the slice width // Determine the slice width
let width = self.size.0 / (self.painter_count as u32); let width = self.size.0 / (self.painter_count as u32);
// Define the area to paint per thread // Define the area to paint per thread
let painter_area = Rect::from( let painter_area = Rect::from(
(i as u32) * width, (i as u32) * width,
0, 0,
width, width,
self.size.1, self.size.1,
); );
// Spawn the painter // Spawn the painter
self.spawn_painter(painter_area); self.spawn_painter(painter_area);
} }
} }
@@ -113,7 +113,7 @@ impl Canvas {
// Create a new painter handle, pust it to the list // Create a new painter handle, pust it to the list
self.painter_handles.push( self.painter_handles.push(
PainterHandle::new( Handle::new(
thread, thread,
area, area,
tx, tx,

View File

@@ -1,2 +1,3 @@
// Re-export modules
pub mod canvas; pub mod canvas;
pub mod client; pub mod client;