use super::{ImageOrientation, LiveImageConsumer, ScalingFilter};
use crate::geometry::Rect;
use crate::image_geometry::oriented_crop;
#[derive(Debug, Clone, Copy, PartialEq)]
#[non_exhaustive]
pub struct LiveImageDraw {
pub content: Rect,
pub clip: Rect,
pub filter: ScalingFilter,
pub orientation: ImageOrientation,
pub paused: bool,
pub pixel_snap: bool,
}
impl LiveImageDraw {
pub fn new(content: Rect, clip: Rect) -> Self {
Self {
content,
clip,
filter: ScalingFilter::default(),
orientation: ImageOrientation::default(),
paused: false,
pixel_snap: true,
}
}
pub fn filter(mut self, filter: ScalingFilter) -> Self {
self.filter = filter;
self
}
pub fn orientation(mut self, orientation: ImageOrientation) -> Self {
self.orientation = orientation;
self
}
pub fn paused(mut self, paused: bool) -> Self {
self.paused = paused;
self
}
pub fn pixel_snap(mut self, on: bool) -> Self {
self.pixel_snap = on;
self
}
}
#[derive(Debug, Clone, PartialEq)]
#[non_exhaustive]
pub struct LiveImageQuad {
pub consumer: LiveImageConsumer,
pub screen: [f32; 4],
pub uv: [[f32; 2]; 4],
pub filter: ScalingFilter,
pub painted: Option<(u32, u32)>,
pub paused: bool,
pub pixel_snap: bool,
}
impl LiveImageQuad {
pub(crate) fn new(consumer: &LiveImageConsumer, draw: &LiveImageDraw) -> Self {
let meta = consumer.layout_meta();
let live = meta.status == super::LiveImageStatus::Live;
let (screen, uv, painted) = match oriented_crop(draw.content, draw.clip, draw.orientation) {
Some((rect, uv)) => (rect.to_array(), uv, if live { meta.size } else { None }),
None => ([draw.clip.x, draw.clip.y, 0.0, 0.0], [[0.0; 2]; 4], None),
};
Self {
consumer: consumer.clone(),
screen,
uv,
filter: draw.filter,
painted,
paused: draw.paused,
pixel_snap: draw.pixel_snap,
}
}
pub(crate) fn offset(&mut self, dx: f32, dy: f32) {
self.screen[0] += dx;
self.screen[1] += dy;
}
}