Move painter modules to sub module
This commit is contained in:
48
src/painter/handle.rs
Normal file
48
src/painter/handle.rs
Normal file
@@ -0,0 +1,48 @@
|
||||
extern crate image;
|
||||
|
||||
use std::sync::mpsc::Sender;
|
||||
use std::thread::JoinHandle;
|
||||
|
||||
use image::DynamicImage;
|
||||
|
||||
use rect::Rect;
|
||||
|
||||
|
||||
|
||||
/// A handle to a painter thread.
|
||||
///
|
||||
/// This also holds a channel to the painter thread,
|
||||
/// to allow image updates to be pushed to the thread.
|
||||
pub struct Handle {
|
||||
#[allow(dead_code)]
|
||||
thread: JoinHandle<u32>,
|
||||
area: Rect,
|
||||
image_sender: Sender<DynamicImage>,
|
||||
}
|
||||
|
||||
impl Handle {
|
||||
/// Create a new handle from the given properties.
|
||||
pub fn new(thread: JoinHandle<u32>, area: Rect, image_sender: Sender<DynamicImage>) -> Handle {
|
||||
Handle {
|
||||
thread,
|
||||
area,
|
||||
image_sender,
|
||||
}
|
||||
}
|
||||
|
||||
/// Push an image update.
|
||||
pub fn update_image(&self, full_image: &mut DynamicImage) {
|
||||
// Crop the image to the area
|
||||
let image = full_image.crop(
|
||||
self.area.x,
|
||||
self.area.y,
|
||||
self.area.w,
|
||||
self.area.h,
|
||||
);
|
||||
|
||||
// Push a new image to the thread
|
||||
// TODO: return this result
|
||||
self.image_sender.send(image)
|
||||
.expect("Failed to send image update to painter");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user