Move pix modules to sub module

This commit is contained in:
Tim Visée
2017-12-31 00:05:37 +01:00
parent c113a9ebaf
commit 82d4eeb0f3
6 changed files with 39 additions and 19 deletions

View File

@@ -1,9 +1,11 @@
use std::path::Path; use std::path::Path;
use std::thread::sleep;
use std::time::Duration;
use image; use image;
use image::{DynamicImage, FilterType}; use image::{DynamicImage, FilterType};
use pix_canvas::PixCanvas; use pix::canvas::Canvas;
@@ -41,7 +43,7 @@ impl ImageManager {
} }
/// Tick the image /// Tick the image
pub fn tick(&mut self, canvas: &mut PixCanvas) { pub fn tick(&mut self, canvas: &mut Canvas) {
// Get the image index bound // Get the image index bound
let bound = self.images.len(); let bound = self.images.len();
@@ -56,6 +58,23 @@ impl ImageManager {
// Increase the index // Increase the index
self.index += 1; self.index += 1;
} }
/// Start working in the image manager.
///
/// This will start walking through all image frames,
/// and pushes each frame to all painters,
/// with the specified frames per second.
pub fn work(&mut self, canvas: &mut Canvas, fps: u32) {
loop {
// Tick to use the next image
self.tick(canvas);
// Sleep until we need to show the next image
sleep(Duration::from_millis(
(1000f32 / (fps as f32)) as u64
));
}
}
} }

View File

@@ -7,13 +7,12 @@ mod color;
mod image_manager; mod image_manager;
mod painter; mod painter;
mod painter_handle; mod painter_handle;
mod pix_canvas; mod pix;
mod pix_client;
mod rect; mod rect;
use arg_handler::ArgHandler; use arg_handler::ArgHandler;
use image_manager::ImageManager; use image_manager::ImageManager;
use pix_canvas::PixCanvas; use pix::canvas::Canvas;
@@ -32,7 +31,7 @@ fn start<'a>(arg_handler: &ArgHandler<'a>) {
println!("Starting..."); println!("Starting...");
// Create a new pixelflut canvas // Create a new pixelflut canvas
let mut canvas = PixCanvas::new( let mut canvas = Canvas::new(
arg_handler.host(), arg_handler.host(),
arg_handler.count(), arg_handler.count(),
arg_handler.size(), arg_handler.size(),

View File

@@ -6,14 +6,14 @@ use image::{DynamicImage, Pixel};
use app::PAINTER_IMAGE_WAIT_DELAY_MILLIS; use app::PAINTER_IMAGE_WAIT_DELAY_MILLIS;
use color::Color; use color::Color;
use pix_client::PixClient; use pix::client::Client;
use rect::Rect; use rect::Rect;
/// A painter that paints on a pixelflut panel. /// A painter that paints on a pixelflut panel.
pub struct Painter { pub struct Painter {
client: PixClient, client: Client,
area: Rect, area: Rect,
offset: (u32, u32), offset: (u32, u32),
image: Option<DynamicImage>, image: Option<DynamicImage>,
@@ -21,7 +21,7 @@ pub struct Painter {
impl Painter { impl Painter {
/// Create a new painter. /// Create a new painter.
pub fn new(client: PixClient, area: Rect, offset: (u32, u32), image: Option<DynamicImage>) -> Painter { pub fn new(client: Client, area: Rect, offset: (u32, u32), image: Option<DynamicImage>) -> Painter {
Painter { Painter {
client, client,
area, area,

View File

@@ -8,13 +8,13 @@ use image::DynamicImage;
use painter::Painter; use painter::Painter;
use painter_handle::PainterHandle; use painter_handle::PainterHandle;
use pix_client::PixClient; use pix::client::Client;
use rect::Rect; use rect::Rect;
/// A pixflut instance /// A pixflut instance
pub struct PixCanvas { pub struct Canvas {
host: String, host: String,
painter_count: usize, painter_count: usize,
painter_handles: Vec<PainterHandle>, painter_handles: Vec<PainterHandle>,
@@ -22,16 +22,16 @@ pub struct PixCanvas {
offset: (u32, u32), offset: (u32, u32),
} }
impl PixCanvas { impl Canvas {
/// Create a new pixelflut canvas. /// Create a new pixelflut canvas.
pub fn new( pub fn new(
host: &str, host: &str,
painter_count: usize, painter_count: usize,
size: (u32, u32), size: (u32, u32),
offset: (u32, u32), offset: (u32, u32),
) -> PixCanvas { ) -> Canvas {
// Initialize the object // Initialize the object
let mut canvas = PixCanvas { 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),
@@ -88,7 +88,7 @@ impl PixCanvas {
.expect("failed to open stream to pixelflut"); .expect("failed to open stream to pixelflut");
// Create a new client // Create a new client
let client = PixClient::new(stream); let client = Client::new(stream);
// Create a painter // Create a painter
let mut painter = Painter::new( let mut painter = Painter::new(

View File

@@ -17,14 +17,14 @@ use color::Color;
/// ///
/// The client provides an interface for other logic to easily talk /// The client provides an interface for other logic to easily talk
/// to the pixelflut panel. /// to the pixelflut panel.
pub struct PixClient { pub struct Client {
stream: BufStream<TcpStream>, stream: BufStream<TcpStream>,
} }
impl PixClient { impl Client {
/// Create a new client instance. /// Create a new client instance.
pub fn new(stream: TcpStream) -> PixClient { pub fn new(stream: TcpStream) -> Client {
PixClient { Client {
stream: BufStream::new(stream), stream: BufStream::new(stream),
} }
} }

2
src/pix/mod.rs Normal file
View File

@@ -0,0 +1,2 @@
pub mod canvas;
pub mod client;