From 9d0d7238dd1c0eac87aacb598236cf751adf12fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Vis=C3=A9e?= Date: Sat, 30 Dec 2017 13:24:45 +0100 Subject: [PATCH] Start working on image manager, for multiple image support --- src/main.rs | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 724b16f..3d2f17e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -151,6 +151,9 @@ fn start( // Create a new pixelflut canvas PixCanvas::new(host, image_path, count, size, offset); + // Load the image manager + let image_manager = ImageManager::load(vec![image_path], &size); + // Sleep this thread thread::sleep(Duration::new(99999999, 0)); } @@ -189,6 +192,32 @@ fn load_image(path: &str, size: &(u32, u32)) -> DynamicImage { +/// A manager that manages all images to print. +struct ImageManager { + images: Vec, +} + +impl ImageManager { + /// Intantiate the image manager. + pub fn from(images: Vec) -> ImageManager { + ImageManager { + images, + } + } + + /// Instantiate the image manager, and load the images from the given paths. + pub fn load(paths: Vec<&str>, size: &(u32, u32)) -> ImageManager { + // Load the images from the paths + ImageManager::from( + paths.iter() + .map(|path| load_image(path, &size)) + .collect() + ) + } +} + + + /// A pixflut instance struct PixCanvas { host: String, @@ -308,10 +337,10 @@ impl PixCanvas { } // Update the image that is being rendered for all painters. - pub fn update_image(&self, image: DynamicImage) { + pub fn update_image(&mut self, image: &mut DynamicImage) { // Update the image for each specific painter handle - for handle in self.painter_handles { - handle.update_image(&image); + for handle in &self.painter_handles { + handle.update_image(image); } } }