Support multiple frames
This commit is contained in:
57
src/main.rs
57
src/main.rs
@@ -51,9 +51,10 @@ fn main() {
|
|||||||
.expect("Invalid count specified");
|
.expect("Invalid count specified");
|
||||||
|
|
||||||
// Get the image path
|
// Get the image path
|
||||||
let image_path = matches
|
let image_paths = matches
|
||||||
.value_of("image")
|
.values_of("image")
|
||||||
.expect("Please specify an image path");
|
.expect("Please specify an image paths")
|
||||||
|
.collect();
|
||||||
|
|
||||||
// Get the width and height
|
// Get the width and height
|
||||||
let width = matches
|
let width = matches
|
||||||
@@ -82,7 +83,7 @@ fn main() {
|
|||||||
// Start
|
// Start
|
||||||
start(
|
start(
|
||||||
host,
|
host,
|
||||||
image_path,
|
image_paths,
|
||||||
count,
|
count,
|
||||||
(width, height),
|
(width, height),
|
||||||
(offset_x, offset_y)
|
(offset_x, offset_y)
|
||||||
@@ -108,10 +109,11 @@ fn parse_args<'a>() -> ArgMatches<'a> {
|
|||||||
.takes_value(true))
|
.takes_value(true))
|
||||||
.arg(Arg::with_name("image")
|
.arg(Arg::with_name("image")
|
||||||
.short("i")
|
.short("i")
|
||||||
.long("image")
|
.long("images")
|
||||||
.value_name("PATH")
|
.value_name("PATH")
|
||||||
.help("Path of the image to print")
|
.help("Paths of the images to print")
|
||||||
.required(true)
|
.required(true)
|
||||||
|
.multiple(true)
|
||||||
.takes_value(true))
|
.takes_value(true))
|
||||||
.arg(Arg::with_name("width")
|
.arg(Arg::with_name("width")
|
||||||
.short("w")
|
.short("w")
|
||||||
@@ -143,7 +145,7 @@ fn parse_args<'a>() -> ArgMatches<'a> {
|
|||||||
/// Start the client.
|
/// Start the client.
|
||||||
fn start(
|
fn start(
|
||||||
host: &str,
|
host: &str,
|
||||||
image_path: &str,
|
image_paths: Vec<&str>,
|
||||||
count: usize,
|
count: usize,
|
||||||
size: (u32, u32),
|
size: (u32, u32),
|
||||||
offset: (u32, u32)
|
offset: (u32, u32)
|
||||||
@@ -152,13 +154,20 @@ fn start(
|
|||||||
println!("Starting...");
|
println!("Starting...");
|
||||||
|
|
||||||
// Create a new pixelflut canvas
|
// Create a new pixelflut canvas
|
||||||
PixCanvas::new(host, image_path, count, size, offset);
|
// TODO: Remove this image path here, fully move it to the manager
|
||||||
|
let mut canvas = PixCanvas::new(host, image_paths[0], count, size, offset);
|
||||||
|
|
||||||
// Load the image manager
|
// Load the image manager
|
||||||
let image_manager = ImageManager::load(vec![image_path], &size);
|
let mut image_manager = ImageManager::load(image_paths, &size);
|
||||||
|
|
||||||
// Sleep this thread
|
// Animate images
|
||||||
thread::sleep(Duration::new(99999999, 0));
|
loop {
|
||||||
|
// Tick to use the next image
|
||||||
|
image_manager.tick(&mut canvas);
|
||||||
|
|
||||||
|
// Sleep until we need to show the next image
|
||||||
|
thread::sleep(Duration::new(1, 0));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a stream to talk to the pixelflut server.
|
/// Create a stream to talk to the pixelflut server.
|
||||||
@@ -198,6 +207,7 @@ fn load_image(path: &str, size: &(u32, u32)) -> DynamicImage {
|
|||||||
/// A manager that manages all images to print.
|
/// A manager that manages all images to print.
|
||||||
struct ImageManager {
|
struct ImageManager {
|
||||||
images: Vec<DynamicImage>,
|
images: Vec<DynamicImage>,
|
||||||
|
index: isize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ImageManager {
|
impl ImageManager {
|
||||||
@@ -205,6 +215,7 @@ impl ImageManager {
|
|||||||
pub fn from(images: Vec<DynamicImage>) -> ImageManager {
|
pub fn from(images: Vec<DynamicImage>) -> ImageManager {
|
||||||
ImageManager {
|
ImageManager {
|
||||||
images,
|
images,
|
||||||
|
index: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -217,6 +228,25 @@ impl ImageManager {
|
|||||||
.collect()
|
.collect()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Tick the image
|
||||||
|
pub fn tick(&mut self, canvas: &mut PixCanvas) {
|
||||||
|
// Get the image index bound
|
||||||
|
let bound = self.images.len();
|
||||||
|
|
||||||
|
// Get the image to use
|
||||||
|
let image = &mut self.images[
|
||||||
|
self.index as usize % bound
|
||||||
|
];
|
||||||
|
|
||||||
|
// Push the image to all painter threads
|
||||||
|
for handle in canvas.painter_handles() {
|
||||||
|
handle.update_image(image);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Increase the index
|
||||||
|
self.index += 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -346,6 +376,11 @@ impl PixCanvas {
|
|||||||
handle.update_image(image);
|
handle.update_image(image);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Borrow the painter handles vector.
|
||||||
|
pub fn painter_handles(&mut self) -> &Vec<PainterHandle> {
|
||||||
|
&self.painter_handles
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user