Start working on image manager, for multiple image support

This commit is contained in:
Tim Visée
2017-12-30 13:24:45 +01:00
parent 00af76a472
commit 9d0d7238dd

View File

@@ -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<DynamicImage>,
}
impl ImageManager {
/// Intantiate the image manager.
pub fn from(images: Vec<DynamicImage>) -> 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);
}
}
}